diff options
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/pcm.c | 24 | ||||
-rw-r--r-- | sound/core/sound.c | 56 |
2 files changed, 68 insertions, 12 deletions
diff --git a/sound/core/pcm.c b/sound/core/pcm.c index ed3b09469560..bf8f412988b8 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c | |||
@@ -907,6 +907,28 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) | |||
907 | substream->pstr->substream_opened--; | 907 | substream->pstr->substream_opened--; |
908 | } | 908 | } |
909 | 909 | ||
910 | static ssize_t show_pcm_class(struct class_device *class_device, char *buf) | ||
911 | { | ||
912 | struct snd_pcm *pcm; | ||
913 | const char *str; | ||
914 | static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = { | ||
915 | [SNDRV_PCM_CLASS_GENERIC] = "generic", | ||
916 | [SNDRV_PCM_CLASS_MULTI] = "multi", | ||
917 | [SNDRV_PCM_CLASS_MODEM] = "modem", | ||
918 | [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer", | ||
919 | }; | ||
920 | |||
921 | if (! (pcm = class_get_devdata(class_device)) || | ||
922 | pcm->dev_class > SNDRV_PCM_CLASS_LAST) | ||
923 | str = "none"; | ||
924 | else | ||
925 | str = strs[pcm->dev_class]; | ||
926 | return snprintf(buf, PAGE_SIZE, "%s\n", str); | ||
927 | } | ||
928 | |||
929 | static struct class_device_attribute pcm_attrs = | ||
930 | __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL); | ||
931 | |||
910 | static int snd_pcm_dev_register(struct snd_device *device) | 932 | static int snd_pcm_dev_register(struct snd_device *device) |
911 | { | 933 | { |
912 | int cidx, err; | 934 | int cidx, err; |
@@ -945,6 +967,8 @@ static int snd_pcm_dev_register(struct snd_device *device) | |||
945 | mutex_unlock(®ister_mutex); | 967 | mutex_unlock(®ister_mutex); |
946 | return err; | 968 | return err; |
947 | } | 969 | } |
970 | snd_add_device_sysfs_file(devtype, pcm->card, pcm->device, | ||
971 | &pcm_attrs); | ||
948 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) | 972 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) |
949 | snd_pcm_timer_init(substream); | 973 | snd_pcm_timer_init(substream); |
950 | } | 974 | } |
diff --git a/sound/core/sound.c b/sound/core/sound.c index b4430db3fa4c..efa476c5210a 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c | |||
@@ -268,7 +268,11 @@ int snd_register_device(int type, struct snd_card *card, int dev, | |||
268 | snd_minors[minor] = preg; | 268 | snd_minors[minor] = preg; |
269 | if (card) | 269 | if (card) |
270 | device = card->dev; | 270 | device = card->dev; |
271 | class_device_create(sound_class, NULL, MKDEV(major, minor), device, "%s", name); | 271 | preg->class_dev = class_device_create(sound_class, NULL, |
272 | MKDEV(major, minor), | ||
273 | device, "%s", name); | ||
274 | if (preg->class_dev) | ||
275 | class_set_devdata(preg->class_dev, private_data); | ||
272 | 276 | ||
273 | mutex_unlock(&sound_mutex); | 277 | mutex_unlock(&sound_mutex); |
274 | return 0; | 278 | return 0; |
@@ -276,6 +280,24 @@ int snd_register_device(int type, struct snd_card *card, int dev, | |||
276 | 280 | ||
277 | EXPORT_SYMBOL(snd_register_device); | 281 | EXPORT_SYMBOL(snd_register_device); |
278 | 282 | ||
283 | /* find the matching minor record | ||
284 | * return the index of snd_minor, or -1 if not found | ||
285 | */ | ||
286 | static int find_snd_minor(int type, struct snd_card *card, int dev) | ||
287 | { | ||
288 | int cardnum, minor; | ||
289 | struct snd_minor *mptr; | ||
290 | |||
291 | cardnum = card ? card->number : -1; | ||
292 | for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) | ||
293 | if ((mptr = snd_minors[minor]) != NULL && | ||
294 | mptr->type == type && | ||
295 | mptr->card == cardnum && | ||
296 | mptr->device == dev) | ||
297 | return minor; | ||
298 | return -1; | ||
299 | } | ||
300 | |||
279 | /** | 301 | /** |
280 | * snd_unregister_device - unregister the device on the given card | 302 | * snd_unregister_device - unregister the device on the given card |
281 | * @type: the device type, SNDRV_DEVICE_TYPE_XXX | 303 | * @type: the device type, SNDRV_DEVICE_TYPE_XXX |
@@ -289,32 +311,42 @@ EXPORT_SYMBOL(snd_register_device); | |||
289 | */ | 311 | */ |
290 | int snd_unregister_device(int type, struct snd_card *card, int dev) | 312 | int snd_unregister_device(int type, struct snd_card *card, int dev) |
291 | { | 313 | { |
292 | int cardnum, minor; | 314 | int minor; |
293 | struct snd_minor *mptr; | ||
294 | 315 | ||
295 | cardnum = card ? card->number : -1; | ||
296 | mutex_lock(&sound_mutex); | 316 | mutex_lock(&sound_mutex); |
297 | for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) | 317 | minor = find_snd_minor(type, card, dev); |
298 | if ((mptr = snd_minors[minor]) != NULL && | 318 | if (minor < 0) { |
299 | mptr->type == type && | ||
300 | mptr->card == cardnum && | ||
301 | mptr->device == dev) | ||
302 | break; | ||
303 | if (minor == ARRAY_SIZE(snd_minors)) { | ||
304 | mutex_unlock(&sound_mutex); | 319 | mutex_unlock(&sound_mutex); |
305 | return -EINVAL; | 320 | return -EINVAL; |
306 | } | 321 | } |
307 | 322 | ||
308 | class_device_destroy(sound_class, MKDEV(major, minor)); | 323 | class_device_destroy(sound_class, MKDEV(major, minor)); |
309 | 324 | ||
325 | kfree(snd_minors[minor]); | ||
310 | snd_minors[minor] = NULL; | 326 | snd_minors[minor] = NULL; |
311 | mutex_unlock(&sound_mutex); | 327 | mutex_unlock(&sound_mutex); |
312 | kfree(mptr); | ||
313 | return 0; | 328 | return 0; |
314 | } | 329 | } |
315 | 330 | ||
316 | EXPORT_SYMBOL(snd_unregister_device); | 331 | EXPORT_SYMBOL(snd_unregister_device); |
317 | 332 | ||
333 | int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, | ||
334 | const struct class_device_attribute *attr) | ||
335 | { | ||
336 | int minor, ret = -EINVAL; | ||
337 | struct class_device *cdev; | ||
338 | |||
339 | mutex_lock(&sound_mutex); | ||
340 | minor = find_snd_minor(type, card, dev); | ||
341 | if (minor >= 0 && (cdev = snd_minors[minor]->class_dev) != NULL) | ||
342 | ret = class_device_create_file(cdev, attr); | ||
343 | mutex_unlock(&sound_mutex); | ||
344 | return ret; | ||
345 | |||
346 | } | ||
347 | |||
348 | EXPORT_SYMBOL(snd_add_device_sysfs_file); | ||
349 | |||
318 | #ifdef CONFIG_PROC_FS | 350 | #ifdef CONFIG_PROC_FS |
319 | /* | 351 | /* |
320 | * INFO PART | 352 | * INFO PART |