Skip to content

Commit d80f19f

Browse files
committed
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: Kay Sievers <kay.sievers@novell.com> Acked-by: Jaroslav Kysela <perex@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent ebf644c commit d80f19f

6 files changed

Lines changed: 37 additions & 30 deletions

File tree

‎include/sound/core.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct snd_card {
132132
int shutdown; /* this card is going down */
133133
int free_on_last_close; /* free in context of file_release */
134134
wait_queue_head_t shutdown_sleep;
135+
struct device *parent;
135136
struct device *dev;
136137

137138
#ifdef CONFIG_PM
@@ -187,13 +188,14 @@ struct snd_minor {
187188
int device; /* device number */
188189
const struct file_operations *f_ops; /* file operations */
189190
void *private_data; /* private data for f_ops->open */
190-
struct class_device *class_dev; /* class device for sysfs */
191+
struct device *dev; /* device for sysfs */
191192
};
192193

193194
/* sound.c */
194195

195196
extern int snd_major;
196197
extern int snd_ecards_limit;
198+
extern struct class *sound_class;
197199

198200
void snd_request_card(int card);
199201

@@ -203,7 +205,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
203205
int snd_unregister_device(int type, struct snd_card *card, int dev);
204206
void *snd_lookup_minor_data(unsigned int minor, int type);
205207
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
206-
const struct class_device_attribute *attr);
208+
struct device_attribute *attr);
207209

208210
#ifdef CONFIG_SND_OSSEMUL
209211
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);
255257
int snd_card_file_remove(struct snd_card *card, struct file *file);
256258

257259
#ifndef snd_card_set_dev
258-
#define snd_card_set_dev(card,devptr) ((card)->dev = (devptr))
260+
#define snd_card_set_dev(card,devptr) ((card)->parent = (devptr))
259261
#endif
260262

261263
/* device.c */

‎sound/core/init.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ static int snd_card_do_free(struct snd_card *card)
361361
snd_printk(KERN_WARNING "unable to free card info\n");
362362
/* Not fatal error */
363363
}
364+
if (card->dev)
365+
device_unregister(card->dev);
364366
kfree(card);
365367
return 0;
366368
}
@@ -495,6 +497,12 @@ int snd_card_register(struct snd_card *card)
495497
int err;
496498

497499
snd_assert(card != NULL, return -EINVAL);
500+
if (!card->dev) {
501+
card->dev = device_create(sound_class, card->parent, 0,
502+
"card%i", card->number);
503+
if (IS_ERR(card->dev))
504+
card->dev = NULL;
505+
}
498506
if ((err = snd_device_register_all(card)) < 0)
499507
return err;
500508
mutex_lock(&snd_card_mutex);

‎sound/core/pcm.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
910910
substream->pstr->substream_opened--;
911911
}
912912

913-
static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
913+
static ssize_t show_pcm_class(struct device *dev,
914+
struct device_attribute *attr, char *buf)
914915
{
915916
struct snd_pcm *pcm;
916917
const char *str;
@@ -921,15 +922,15 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
921922
[SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
922923
};
923924

924-
if (! (pcm = class_get_devdata(class_device)) ||
925+
if (! (pcm = dev_get_drvdata(dev)) ||
925926
pcm->dev_class > SNDRV_PCM_CLASS_LAST)
926927
str = "none";
927928
else
928929
str = strs[pcm->dev_class];
929930
return snprintf(buf, PAGE_SIZE, "%s\n", str);
930931
}
931932

932-
static struct class_device_attribute pcm_attrs =
933+
static struct device_attribute pcm_attrs =
933934
__ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
934935

935936
static int snd_pcm_dev_register(struct snd_device *device)

‎sound/core/sound.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ EXPORT_SYMBOL(snd_ecards_limit);
6161
static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
6262
static DEFINE_MUTEX(sound_mutex);
6363

64-
extern struct class *sound_class;
65-
66-
6764
#ifdef CONFIG_KMOD
6865

6966
/**
@@ -268,11 +265,10 @@ int snd_register_device(int type, struct snd_card *card, int dev,
268265
snd_minors[minor] = preg;
269266
if (card)
270267
device = card->dev;
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);
268+
preg->dev = device_create(sound_class, device, MKDEV(major, minor),
269+
"%s", name);
270+
if (preg->dev)
271+
dev_set_drvdata(preg->dev, private_data);
276272

277273
mutex_unlock(&sound_mutex);
278274
return 0;
@@ -320,7 +316,7 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
320316
return -EINVAL;
321317
}
322318

323-
class_device_destroy(sound_class, MKDEV(major, minor));
319+
device_destroy(sound_class, MKDEV(major, minor));
324320

325321
kfree(snd_minors[minor]);
326322
snd_minors[minor] = NULL;
@@ -331,15 +327,15 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
331327
EXPORT_SYMBOL(snd_unregister_device);
332328

333329
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
334-
const struct class_device_attribute *attr)
330+
struct device_attribute *attr)
335331
{
336332
int minor, ret = -EINVAL;
337-
struct class_device *cdev;
333+
struct device *d;
338334

339335
mutex_lock(&sound_mutex);
340336
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);
337+
if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL)
338+
ret = device_create_file(d, attr);
343339
mutex_unlock(&sound_mutex);
344340
return ret;
345341

‎sound/oss/soundcard.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,17 @@ static int __init oss_init(void)
557557
sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
558558

559559
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
560-
class_device_create(sound_class, NULL,
561-
MKDEV(SOUND_MAJOR, dev_list[i].minor),
562-
NULL, "%s", dev_list[i].name);
560+
device_create(sound_class, NULL,
561+
MKDEV(SOUND_MAJOR, dev_list[i].minor),
562+
"%s", dev_list[i].name);
563563

564564
if (!dev_list[i].num)
565565
continue;
566566

567567
for (j = 1; j < *dev_list[i].num; j++)
568-
class_device_create(sound_class, NULL,
569-
MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)),
570-
NULL, "%s%d", dev_list[i].name, j);
568+
device_create(sound_class, NULL,
569+
MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)),
570+
"%s%d", dev_list[i].name, j);
571571
}
572572

573573
if (sound_nblocks >= 1024)
@@ -581,11 +581,11 @@ static void __exit oss_cleanup(void)
581581
int i, j;
582582

583583
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
584-
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
584+
device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
585585
if (!dev_list[i].num)
586586
continue;
587587
for (j = 1; j < *dev_list[i].num; j++)
588-
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
588+
device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
589589
}
590590

591591
unregister_sound_special(1);

‎sound/sound_core.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
170170
else
171171
sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
172172

173-
class_device_create(sound_class, NULL, MKDEV(SOUND_MAJOR, s->unit_minor),
174-
dev, s->name+6);
173+
device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
174+
s->name+6);
175175
return r;
176176

177177
fail:
@@ -193,7 +193,7 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
193193
p = __sound_remove_unit(list, unit);
194194
spin_unlock(&sound_loader_lock);
195195
if (p) {
196-
class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
196+
device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
197197
kfree(p);
198198
}
199199
}

0 commit comments

Comments
 (0)