Commit d80f19fa authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Driver core: convert sound core to use struct device

Converts from using struct "class_device" to "struct device" making
everything show up properly in /sys/devices/ with symlinks from the
/sys/class directory.

It also makes the struct sound_card to show up as a "real" device
where all the different sound class devices are placed as childs
and different card attribute files can hang off of. /sys/class/sound is
still a flat directory, but the symlink targets of all devices belonging
to the same card, point the the /sys/devices tree below the new card
device object.

Thanks to Kay for the updates to this patch.
Signed-off-by: default avatarKay Sievers <kay.sievers@novell.com>
Acked-by: default avatarJaroslav Kysela <perex@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ebf644c4
...@@ -132,6 +132,7 @@ struct snd_card { ...@@ -132,6 +132,7 @@ struct snd_card {
int shutdown; /* this card is going down */ int shutdown; /* this card is going down */
int free_on_last_close; /* free in context of file_release */ int free_on_last_close; /* free in context of file_release */
wait_queue_head_t shutdown_sleep; wait_queue_head_t shutdown_sleep;
struct device *parent;
struct device *dev; struct device *dev;
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -187,13 +188,14 @@ struct snd_minor { ...@@ -187,13 +188,14 @@ struct snd_minor {
int device; /* device number */ int device; /* device number */
const struct file_operations *f_ops; /* file operations */ const struct file_operations *f_ops; /* file operations */
void *private_data; /* private data for f_ops->open */ void *private_data; /* private data for f_ops->open */
struct class_device *class_dev; /* class device for sysfs */ struct device *dev; /* device for sysfs */
}; };
/* sound.c */ /* sound.c */
extern int snd_major; extern int snd_major;
extern int snd_ecards_limit; extern int snd_ecards_limit;
extern struct class *sound_class;
void snd_request_card(int card); void snd_request_card(int card);
...@@ -203,7 +205,7 @@ int snd_register_device(int type, struct snd_card *card, int dev, ...@@ -203,7 +205,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
int snd_unregister_device(int type, struct snd_card *card, int dev); int snd_unregister_device(int type, struct snd_card *card, int dev);
void *snd_lookup_minor_data(unsigned int minor, int type); void *snd_lookup_minor_data(unsigned int minor, int type);
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
const struct class_device_attribute *attr); struct device_attribute *attr);
#ifdef CONFIG_SND_OSSEMUL #ifdef CONFIG_SND_OSSEMUL
int snd_register_oss_device(int type, struct snd_card *card, int dev, int snd_register_oss_device(int type, struct snd_card *card, int dev,
...@@ -255,7 +257,7 @@ int snd_card_file_add(struct snd_card *card, struct file *file); ...@@ -255,7 +257,7 @@ int snd_card_file_add(struct snd_card *card, struct file *file);
int snd_card_file_remove(struct snd_card *card, struct file *file); int snd_card_file_remove(struct snd_card *card, struct file *file);
#ifndef snd_card_set_dev #ifndef snd_card_set_dev
#define snd_card_set_dev(card,devptr) ((card)->dev = (devptr)) #define snd_card_set_dev(card,devptr) ((card)->parent = (devptr))
#endif #endif
/* device.c */ /* device.c */
......
...@@ -361,6 +361,8 @@ static int snd_card_do_free(struct snd_card *card) ...@@ -361,6 +361,8 @@ static int snd_card_do_free(struct snd_card *card)
snd_printk(KERN_WARNING "unable to free card info\n"); snd_printk(KERN_WARNING "unable to free card info\n");
/* Not fatal error */ /* Not fatal error */
} }
if (card->dev)
device_unregister(card->dev);
kfree(card); kfree(card);
return 0; return 0;
} }
...@@ -495,6 +497,12 @@ int snd_card_register(struct snd_card *card) ...@@ -495,6 +497,12 @@ int snd_card_register(struct snd_card *card)
int err; int err;
snd_assert(card != NULL, return -EINVAL); snd_assert(card != NULL, return -EINVAL);
if (!card->dev) {
card->dev = device_create(sound_class, card->parent, 0,
"card%i", card->number);
if (IS_ERR(card->dev))
card->dev = NULL;
}
if ((err = snd_device_register_all(card)) < 0) if ((err = snd_device_register_all(card)) < 0)
return err; return err;
mutex_lock(&snd_card_mutex); mutex_lock(&snd_card_mutex);
......
...@@ -910,7 +910,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) ...@@ -910,7 +910,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
substream->pstr->substream_opened--; substream->pstr->substream_opened--;
} }
static ssize_t show_pcm_class(struct class_device *class_device, char *buf) static ssize_t show_pcm_class(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct snd_pcm *pcm; struct snd_pcm *pcm;
const char *str; const char *str;
...@@ -921,7 +922,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf) ...@@ -921,7 +922,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
[SNDRV_PCM_CLASS_DIGITIZER] = "digitizer", [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
}; };
if (! (pcm = class_get_devdata(class_device)) || if (! (pcm = dev_get_drvdata(dev)) ||
pcm->dev_class > SNDRV_PCM_CLASS_LAST) pcm->dev_class > SNDRV_PCM_CLASS_LAST)
str = "none"; str = "none";
else else
...@@ -929,7 +930,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf) ...@@ -929,7 +930,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
return snprintf(buf, PAGE_SIZE, "%s\n", str); return snprintf(buf, PAGE_SIZE, "%s\n", str);
} }
static struct class_device_attribute pcm_attrs = static struct device_attribute pcm_attrs =
__ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL); __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
static int snd_pcm_dev_register(struct snd_device *device) static int snd_pcm_dev_register(struct snd_device *device)
......
...@@ -61,9 +61,6 @@ EXPORT_SYMBOL(snd_ecards_limit); ...@@ -61,9 +61,6 @@ EXPORT_SYMBOL(snd_ecards_limit);
static struct snd_minor *snd_minors[SNDRV_OS_MINORS]; static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
static DEFINE_MUTEX(sound_mutex); static DEFINE_MUTEX(sound_mutex);
extern struct class *sound_class;
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
/** /**
...@@ -268,11 +265,10 @@ int snd_register_device(int type, struct snd_card *card, int dev, ...@@ -268,11 +265,10 @@ int snd_register_device(int type, struct snd_card *card, int dev,
snd_minors[minor] = preg; snd_minors[minor] = preg;
if (card) if (card)
device = card->dev; device = card->dev;
preg->class_dev = class_device_create(sound_class, NULL, preg->dev = device_create(sound_class, device, MKDEV(major, minor),
MKDEV(major, minor), "%s", name);
device, "%s", name); if (preg->dev)
if (preg->class_dev) dev_set_drvdata(preg->dev, private_data);
class_set_devdata(preg->class_dev, private_data);
mutex_unlock(&sound_mutex); mutex_unlock(&sound_mutex);
return 0; return 0;
...@@ -320,7 +316,7 @@ int snd_unregister_device(int type, struct snd_card *card, int dev) ...@@ -320,7 +316,7 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
return -EINVAL; return -EINVAL;
} }
class_device_destroy(sound_class, MKDEV(major, minor)); device_destroy(sound_class, MKDEV(major, minor));
kfree(snd_minors[minor]); kfree(snd_minors[minor]);
snd_minors[minor] = NULL; snd_minors[minor] = NULL;
...@@ -331,15 +327,15 @@ int snd_unregister_device(int type, struct snd_card *card, int dev) ...@@ -331,15 +327,15 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
EXPORT_SYMBOL(snd_unregister_device); EXPORT_SYMBOL(snd_unregister_device);
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
const struct class_device_attribute *attr) struct device_attribute *attr)
{ {
int minor, ret = -EINVAL; int minor, ret = -EINVAL;
struct class_device *cdev; struct device *d;
mutex_lock(&sound_mutex); mutex_lock(&sound_mutex);
minor = find_snd_minor(type, card, dev); minor = find_snd_minor(type, card, dev);
if (minor >= 0 && (cdev = snd_minors[minor]->class_dev) != NULL) if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL)
ret = class_device_create_file(cdev, attr); ret = device_create_file(d, attr);
mutex_unlock(&sound_mutex); mutex_unlock(&sound_mutex);
return ret; return ret;
......
...@@ -557,17 +557,17 @@ static int __init oss_init(void) ...@@ -557,17 +557,17 @@ static int __init oss_init(void)
sound_dmap_flag = (dmabuf > 0 ? 1 : 0); sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) { for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
class_device_create(sound_class, NULL, device_create(sound_class, NULL,
MKDEV(SOUND_MAJOR, dev_list[i].minor), MKDEV(SOUND_MAJOR, dev_list[i].minor),
NULL, "%s", dev_list[i].name); "%s", dev_list[i].name);
if (!dev_list[i].num) if (!dev_list[i].num)
continue; continue;
for (j = 1; j < *dev_list[i].num; j++) for (j = 1; j < *dev_list[i].num; j++)
class_device_create(sound_class, NULL, device_create(sound_class, NULL,
MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)), MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)),
NULL, "%s%d", dev_list[i].name, j); "%s%d", dev_list[i].name, j);
} }
if (sound_nblocks >= 1024) if (sound_nblocks >= 1024)
...@@ -581,11 +581,11 @@ static void __exit oss_cleanup(void) ...@@ -581,11 +581,11 @@ static void __exit oss_cleanup(void)
int i, j; int i, j;
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) { for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor)); device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
if (!dev_list[i].num) if (!dev_list[i].num)
continue; continue;
for (j = 1; j < *dev_list[i].num; j++) for (j = 1; j < *dev_list[i].num; j++)
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10))); device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
} }
unregister_sound_special(1); unregister_sound_special(1);
......
...@@ -170,8 +170,8 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati ...@@ -170,8 +170,8 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
else else
sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP); sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
class_device_create(sound_class, NULL, MKDEV(SOUND_MAJOR, s->unit_minor), device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
dev, s->name+6); s->name+6);
return r; return r;
fail: fail:
...@@ -193,7 +193,7 @@ static void sound_remove_unit(struct sound_unit **list, int unit) ...@@ -193,7 +193,7 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
p = __sound_remove_unit(list, unit); p = __sound_remove_unit(list, unit);
spin_unlock(&sound_loader_lock); spin_unlock(&sound_loader_lock);
if (p) { if (p) {
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor)); device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
kfree(p); kfree(p);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment