X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=sound%2Fcore%2Fsound.c;h=82a61c67cf3ae6a027bdd082ca11f56f87960b05;hb=51e6ed23fc95c3e710d8a98717924ccb2571aa66;hp=cd862728346cb03e74abe870f4a997c0e5fa6de7;hpb=fffcb480e4224f25c965b93fa65541bfc7dd732e;p=powerpc.git diff --git a/sound/core/sound.c b/sound/core/sound.c index cd86272834..82a61c67cf 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #define SNDRV_OS_MINORS 256 @@ -42,7 +41,6 @@ int snd_major; EXPORT_SYMBOL(snd_major); static int cards_limit = 1; -static int device_mode = S_IFCHR | S_IRUGO | S_IWUGO; MODULE_AUTHOR("Jaroslav Kysela "); MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards."); @@ -51,10 +49,6 @@ module_param(major, int, 0444); MODULE_PARM_DESC(major, "Major # for sound driver."); module_param(cards_limit, int, 0444); MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards."); -#ifdef CONFIG_DEVFS_FS -module_param(device_mode, int, 0444); -MODULE_PARM_DESC(device_mode, "Device file permission mask for devfs."); -#endif MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR); /* this one holds the actual max. card number currently available. @@ -67,9 +61,6 @@ EXPORT_SYMBOL(snd_ecards_limit); static struct snd_minor *snd_minors[SNDRV_OS_MINORS]; static DEFINE_MUTEX(sound_mutex); -extern struct class *sound_class; - - #ifdef CONFIG_KMOD /** @@ -247,10 +238,10 @@ int snd_register_device(int type, struct snd_card *card, int dev, { int minor; struct snd_minor *preg; - struct device *device = NULL; + struct device *device = snd_card_get_device_link(card); snd_assert(name, return -EINVAL); - preg = kmalloc(sizeof(struct snd_minor) + strlen(name) + 1, GFP_KERNEL); + preg = kmalloc(sizeof *preg, GFP_KERNEL); if (preg == NULL) return -ENOMEM; preg->type = type; @@ -258,7 +249,6 @@ int snd_register_device(int type, struct snd_card *card, int dev, preg->device = dev; preg->f_ops = f_ops; preg->private_data = private_data; - strcpy(preg->name, name); mutex_lock(&sound_mutex); #ifdef CONFIG_SND_DYNAMIC_MINORS minor = snd_find_free_minor(); @@ -273,11 +263,10 @@ int snd_register_device(int type, struct snd_card *card, int dev, return minor; } snd_minors[minor] = preg; - if (type != SNDRV_DEVICE_TYPE_CONTROL || preg->card >= cards_limit) - devfs_mk_cdev(MKDEV(major, minor), S_IFCHR | device_mode, "snd/%s", name); - if (card) - device = card->dev; - class_device_create(sound_class, NULL, MKDEV(major, minor), device, "%s", name); + preg->dev = device_create(sound_class, device, MKDEV(major, minor), + "%s", name); + if (preg->dev) + dev_set_drvdata(preg->dev, private_data); mutex_unlock(&sound_mutex); return 0; @@ -285,6 +274,24 @@ int snd_register_device(int type, struct snd_card *card, int dev, EXPORT_SYMBOL(snd_register_device); +/* find the matching minor record + * return the index of snd_minor, or -1 if not found + */ +static int find_snd_minor(int type, struct snd_card *card, int dev) +{ + int cardnum, minor; + struct snd_minor *mptr; + + cardnum = card ? card->number : -1; + for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) + if ((mptr = snd_minors[minor]) != NULL && + mptr->type == type && + mptr->card == cardnum && + mptr->device == dev) + return minor; + return -1; +} + /** * snd_unregister_device - unregister the device on the given card * @type: the device type, SNDRV_DEVICE_TYPE_XXX @@ -298,35 +305,42 @@ EXPORT_SYMBOL(snd_register_device); */ int snd_unregister_device(int type, struct snd_card *card, int dev) { - int cardnum, minor; - struct snd_minor *mptr; + int minor; - cardnum = card ? card->number : -1; mutex_lock(&sound_mutex); - for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) - if ((mptr = snd_minors[minor]) != NULL && - mptr->type == type && - mptr->card == cardnum && - mptr->device == dev) - break; - if (minor == ARRAY_SIZE(snd_minors)) { + minor = find_snd_minor(type, card, dev); + if (minor < 0) { mutex_unlock(&sound_mutex); return -EINVAL; } - if (mptr->type != SNDRV_DEVICE_TYPE_CONTROL || - mptr->card >= cards_limit) /* created in sound.c */ - devfs_remove("snd/%s", mptr->name); - class_device_destroy(sound_class, MKDEV(major, minor)); + device_destroy(sound_class, MKDEV(major, minor)); + kfree(snd_minors[minor]); snd_minors[minor] = NULL; mutex_unlock(&sound_mutex); - kfree(mptr); return 0; } EXPORT_SYMBOL(snd_unregister_device); +int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, + struct device_attribute *attr) +{ + int minor, ret = -EINVAL; + struct device *d; + + mutex_lock(&sound_mutex); + minor = find_snd_minor(type, card, dev); + if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL) + ret = device_create_file(d, attr); + mutex_unlock(&sound_mutex); + return ret; + +} + +EXPORT_SYMBOL(snd_add_device_sysfs_file); + #ifdef CONFIG_PROC_FS /* * INFO PART @@ -399,8 +413,7 @@ int __init snd_minor_info_init(void) int __exit snd_minor_info_done(void) { - if (snd_minor_info_entry) - snd_info_unregister(snd_minor_info_entry); + snd_info_free_entry(snd_minor_info_entry); return 0; } #endif /* CONFIG_PROC_FS */ @@ -411,24 +424,17 @@ int __exit snd_minor_info_done(void) static int __init alsa_sound_init(void) { - short controlnum; - snd_major = major; snd_ecards_limit = cards_limit; - devfs_mk_dir("snd"); if (register_chrdev(major, "alsa", &snd_fops)) { snd_printk(KERN_ERR "unable to register native major device number %d\n", major); - devfs_remove("snd"); return -EIO; } if (snd_info_init() < 0) { unregister_chrdev(major, "alsa"); - devfs_remove("snd"); return -ENOMEM; } snd_info_minor_register(); - for (controlnum = 0; controlnum < cards_limit; controlnum++) - devfs_mk_cdev(MKDEV(major, controlnum<<5), S_IFCHR | device_mode, "snd/controlC%d", controlnum); #ifndef MODULE printk(KERN_INFO "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"); #endif @@ -437,16 +443,10 @@ static int __init alsa_sound_init(void) static void __exit alsa_sound_exit(void) { - short controlnum; - - for (controlnum = 0; controlnum < cards_limit; controlnum++) - devfs_remove("snd/controlC%d", controlnum); - snd_info_minor_unregister(); snd_info_done(); if (unregister_chrdev(major, "alsa") != 0) snd_printk(KERN_ERR "unable to unregister major device number %d\n", major); - devfs_remove("snd"); } module_init(alsa_sound_init)