diff options
author | Takashi Iwai <tiwai@suse.de> | 2014-02-25 02:30:50 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-02-25 06:12:49 -0500 |
commit | caa751bad444268d756b48ca03d7cceda3430cc8 (patch) | |
tree | 1bca8a78c67dc2d54e6a83c3ec81dbcc302676d0 | |
parent | d01a838c86b60fdce4fbc9e51d5d14d6cfe0a902 (diff) |
ALSA: Create sysfs attribute files via groups
Instead of calling each time device_create_file(), create the groups
of sysfs attribute files at once in a normal way. Add a new helper
function, snd_get_device(), to return the associated device object,
so that we can handle the sysfs addition locally.
Since the sysfs file addition is done differently now,
snd_add_device_sysfs_file() helper function is removed.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | include/sound/core.h | 3 | ||||
-rw-r--r-- | include/sound/hwdep.h | 1 | ||||
-rw-r--r-- | sound/core/hwdep.c | 14 | ||||
-rw-r--r-- | sound/core/pcm.c | 30 | ||||
-rw-r--r-- | sound/core/sound.c | 23 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.c | 16 | ||||
-rw-r--r-- | sound/pci/hda/hda_hwdep.c | 110 | ||||
-rw-r--r-- | sound/pci/hda/hda_local.h | 18 |
8 files changed, 112 insertions, 103 deletions
diff --git a/include/sound/core.h b/include/sound/core.h index a3e3e89b63b6..9c1187334195 100644 --- a/include/sound/core.h +++ b/include/sound/core.h | |||
@@ -248,8 +248,7 @@ static inline int snd_register_device(int type, struct snd_card *card, int dev, | |||
248 | 248 | ||
249 | int snd_unregister_device(int type, struct snd_card *card, int dev); | 249 | int snd_unregister_device(int type, struct snd_card *card, int dev); |
250 | void *snd_lookup_minor_data(unsigned int minor, int type); | 250 | void *snd_lookup_minor_data(unsigned int minor, int type); |
251 | int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, | 251 | struct device *snd_get_device(int type, struct snd_card *card, int dev); |
252 | struct device_attribute *attr); | ||
253 | 252 | ||
254 | #ifdef CONFIG_SND_OSSEMUL | 253 | #ifdef CONFIG_SND_OSSEMUL |
255 | int snd_register_oss_device(int type, struct snd_card *card, int dev, | 254 | int snd_register_oss_device(int type, struct snd_card *card, int dev, |
diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h index 6233eb092d0a..193a3c57ed25 100644 --- a/include/sound/hwdep.h +++ b/include/sound/hwdep.h | |||
@@ -68,6 +68,7 @@ struct snd_hwdep { | |||
68 | wait_queue_head_t open_wait; | 68 | wait_queue_head_t open_wait; |
69 | void *private_data; | 69 | void *private_data; |
70 | void (*private_free) (struct snd_hwdep *hwdep); | 70 | void (*private_free) (struct snd_hwdep *hwdep); |
71 | const struct attribute_group **groups; | ||
71 | 72 | ||
72 | struct mutex open_mutex; | 73 | struct mutex open_mutex; |
73 | int used; /* reference counter */ | 74 | int used; /* reference counter */ |
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index 8c778659fa03..99f7e8515ba1 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c | |||
@@ -436,6 +436,20 @@ static int snd_hwdep_dev_register(struct snd_device *device) | |||
436 | mutex_unlock(®ister_mutex); | 436 | mutex_unlock(®ister_mutex); |
437 | return err; | 437 | return err; |
438 | } | 438 | } |
439 | |||
440 | if (hwdep->groups) { | ||
441 | struct device *d = snd_get_device(SNDRV_DEVICE_TYPE_HWDEP, | ||
442 | hwdep->card, hwdep->device); | ||
443 | if (d) { | ||
444 | err = sysfs_create_groups(&d->kobj, hwdep->groups); | ||
445 | if (err < 0) | ||
446 | dev_warn(card->dev, | ||
447 | "hwdep %d:%d: cannot create sysfs groups\n", | ||
448 | card->number, hwdep->device); | ||
449 | put_device(d); | ||
450 | } | ||
451 | } | ||
452 | |||
439 | #ifdef CONFIG_SND_OSSEMUL | 453 | #ifdef CONFIG_SND_OSSEMUL |
440 | hwdep->ossreg = 0; | 454 | hwdep->ossreg = 0; |
441 | if (hwdep->oss_type >= 0) { | 455 | if (hwdep->oss_type >= 0) { |
diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 9defdaef520b..43932e8dce66 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c | |||
@@ -1018,8 +1018,20 @@ static ssize_t show_pcm_class(struct device *dev, | |||
1018 | return snprintf(buf, PAGE_SIZE, "%s\n", str); | 1018 | return snprintf(buf, PAGE_SIZE, "%s\n", str); |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | static struct device_attribute pcm_attrs = | 1021 | static DEVICE_ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL); |
1022 | __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL); | 1022 | static struct attribute *pcm_dev_attrs[] = { |
1023 | &dev_attr_pcm_class.attr, | ||
1024 | NULL | ||
1025 | }; | ||
1026 | |||
1027 | static struct attribute_group pcm_dev_attr_group = { | ||
1028 | .attrs = pcm_dev_attrs, | ||
1029 | }; | ||
1030 | |||
1031 | static const struct attribute_group *pcm_dev_attr_groups[] = { | ||
1032 | &pcm_dev_attr_group, | ||
1033 | NULL | ||
1034 | }; | ||
1023 | 1035 | ||
1024 | static int snd_pcm_dev_register(struct snd_device *device) | 1036 | static int snd_pcm_dev_register(struct snd_device *device) |
1025 | { | 1037 | { |
@@ -1069,8 +1081,18 @@ static int snd_pcm_dev_register(struct snd_device *device) | |||
1069 | mutex_unlock(®ister_mutex); | 1081 | mutex_unlock(®ister_mutex); |
1070 | return err; | 1082 | return err; |
1071 | } | 1083 | } |
1072 | snd_add_device_sysfs_file(devtype, pcm->card, pcm->device, | 1084 | |
1073 | &pcm_attrs); | 1085 | dev = snd_get_device(devtype, pcm->card, pcm->device); |
1086 | if (dev) { | ||
1087 | err = sysfs_create_groups(&dev->kobj, | ||
1088 | pcm_dev_attr_groups); | ||
1089 | if (err < 0) | ||
1090 | dev_warn(dev, | ||
1091 | "pcm %d:%d: cannot create sysfs groups\n", | ||
1092 | pcm->card->number, pcm->device); | ||
1093 | put_device(dev); | ||
1094 | } | ||
1095 | |||
1074 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) | 1096 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) |
1075 | snd_pcm_timer_init(substream); | 1097 | snd_pcm_timer_init(substream); |
1076 | } | 1098 | } |
diff --git a/sound/core/sound.c b/sound/core/sound.c index 60ab9b1f44b9..38ad1a0dd3f7 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c | |||
@@ -355,22 +355,25 @@ int snd_unregister_device(int type, struct snd_card *card, int dev) | |||
355 | 355 | ||
356 | EXPORT_SYMBOL(snd_unregister_device); | 356 | EXPORT_SYMBOL(snd_unregister_device); |
357 | 357 | ||
358 | int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, | 358 | /* get the assigned device to the given type and device number; |
359 | struct device_attribute *attr) | 359 | * the caller needs to release it via put_device() after using it |
360 | */ | ||
361 | struct device *snd_get_device(int type, struct snd_card *card, int dev) | ||
360 | { | 362 | { |
361 | int minor, ret = -EINVAL; | 363 | int minor; |
362 | struct device *d; | 364 | struct device *d = NULL; |
363 | 365 | ||
364 | mutex_lock(&sound_mutex); | 366 | mutex_lock(&sound_mutex); |
365 | minor = find_snd_minor(type, card, dev); | 367 | minor = find_snd_minor(type, card, dev); |
366 | if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL) | 368 | if (minor >= 0) { |
367 | ret = device_create_file(d, attr); | 369 | d = snd_minors[minor]->dev; |
370 | if (d) | ||
371 | get_device(d); | ||
372 | } | ||
368 | mutex_unlock(&sound_mutex); | 373 | mutex_unlock(&sound_mutex); |
369 | return ret; | 374 | return d; |
370 | |||
371 | } | 375 | } |
372 | 376 | EXPORT_SYMBOL(snd_get_device); | |
373 | EXPORT_SYMBOL(snd_add_device_sysfs_file); | ||
374 | 377 | ||
375 | #ifdef CONFIG_PROC_FS | 378 | #ifdef CONFIG_PROC_FS |
376 | /* | 379 | /* |
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 115502783b64..51360d916e6b 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -852,21 +852,6 @@ static int snd_hda_bus_dev_free(struct snd_device *device) | |||
852 | return snd_hda_bus_free(bus); | 852 | return snd_hda_bus_free(bus); |
853 | } | 853 | } |
854 | 854 | ||
855 | #ifdef CONFIG_SND_HDA_HWDEP | ||
856 | static int snd_hda_bus_dev_register(struct snd_device *device) | ||
857 | { | ||
858 | struct hda_bus *bus = device->device_data; | ||
859 | struct hda_codec *codec; | ||
860 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
861 | snd_hda_hwdep_add_sysfs(codec); | ||
862 | snd_hda_hwdep_add_power_sysfs(codec); | ||
863 | } | ||
864 | return 0; | ||
865 | } | ||
866 | #else | ||
867 | #define snd_hda_bus_dev_register NULL | ||
868 | #endif | ||
869 | |||
870 | /** | 855 | /** |
871 | * snd_hda_bus_new - create a HDA bus | 856 | * snd_hda_bus_new - create a HDA bus |
872 | * @card: the card entry | 857 | * @card: the card entry |
@@ -882,7 +867,6 @@ int snd_hda_bus_new(struct snd_card *card, | |||
882 | struct hda_bus *bus; | 867 | struct hda_bus *bus; |
883 | int err; | 868 | int err; |
884 | static struct snd_device_ops dev_ops = { | 869 | static struct snd_device_ops dev_ops = { |
885 | .dev_register = snd_hda_bus_dev_register, | ||
886 | .dev_free = snd_hda_bus_dev_free, | 870 | .dev_free = snd_hda_bus_dev_free, |
887 | }; | 871 | }; |
888 | 872 | ||
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 53c961992d0c..53eef6a01589 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c | |||
@@ -124,6 +124,8 @@ static void hwdep_free(struct snd_hwdep *hwdep) | |||
124 | clear_hwdep_elements(hwdep->private_data); | 124 | clear_hwdep_elements(hwdep->private_data); |
125 | } | 125 | } |
126 | 126 | ||
127 | static const struct attribute_group *snd_hda_dev_attr_groups[]; | ||
128 | |||
127 | int snd_hda_create_hwdep(struct hda_codec *codec) | 129 | int snd_hda_create_hwdep(struct hda_codec *codec) |
128 | { | 130 | { |
129 | char hwname[16]; | 131 | char hwname[16]; |
@@ -140,6 +142,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec) | |||
140 | hwdep->private_data = codec; | 142 | hwdep->private_data = codec; |
141 | hwdep->private_free = hwdep_free; | 143 | hwdep->private_free = hwdep_free; |
142 | hwdep->exclusive = 1; | 144 | hwdep->exclusive = 1; |
145 | hwdep->groups = snd_hda_dev_attr_groups; | ||
143 | 146 | ||
144 | hwdep->ops.open = hda_hwdep_open; | 147 | hwdep->ops.open = hda_hwdep_open; |
145 | hwdep->ops.ioctl = hda_hwdep_ioctl; | 148 | hwdep->ops.ioctl = hda_hwdep_ioctl; |
@@ -176,21 +179,8 @@ static ssize_t power_off_acct_show(struct device *dev, | |||
176 | return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct)); | 179 | return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct)); |
177 | } | 180 | } |
178 | 181 | ||
179 | static struct device_attribute power_attrs[] = { | 182 | static DEVICE_ATTR_RO(power_on_acct); |
180 | __ATTR_RO(power_on_acct), | 183 | static DEVICE_ATTR_RO(power_off_acct); |
181 | __ATTR_RO(power_off_acct), | ||
182 | }; | ||
183 | |||
184 | int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec) | ||
185 | { | ||
186 | struct snd_hwdep *hwdep = codec->hwdep; | ||
187 | int i; | ||
188 | |||
189 | for (i = 0; i < ARRAY_SIZE(power_attrs); i++) | ||
190 | snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card, | ||
191 | hwdep->device, &power_attrs[i]); | ||
192 | return 0; | ||
193 | } | ||
194 | #endif /* CONFIG_PM */ | 184 | #endif /* CONFIG_PM */ |
195 | 185 | ||
196 | #ifdef CONFIG_SND_HDA_RECONFIG | 186 | #ifdef CONFIG_SND_HDA_RECONFIG |
@@ -568,44 +558,21 @@ static ssize_t user_pin_configs_store(struct device *dev, | |||
568 | return count; | 558 | return count; |
569 | } | 559 | } |
570 | 560 | ||
571 | #define CODEC_ATTR_RW(type) \ | 561 | static DEVICE_ATTR_RW(vendor_id); |
572 | __ATTR(type, 0644, type##_show, type##_store) | 562 | static DEVICE_ATTR_RW(subsystem_id); |
573 | #define CODEC_ATTR_RO(type) \ | 563 | static DEVICE_ATTR_RW(revision_id); |
574 | __ATTR_RO(type) | 564 | static DEVICE_ATTR_RO(afg); |
575 | #define CODEC_ATTR_WO(type) \ | 565 | static DEVICE_ATTR_RO(mfg); |
576 | __ATTR(type, 0200, NULL, type##_store) | 566 | static DEVICE_ATTR_RW(vendor_name); |
577 | 567 | static DEVICE_ATTR_RW(chip_name); | |
578 | static struct device_attribute codec_attrs[] = { | 568 | static DEVICE_ATTR_RW(modelname); |
579 | CODEC_ATTR_RW(vendor_id), | 569 | static DEVICE_ATTR_RW(init_verbs); |
580 | CODEC_ATTR_RW(subsystem_id), | 570 | static DEVICE_ATTR_RW(hints); |
581 | CODEC_ATTR_RW(revision_id), | 571 | static DEVICE_ATTR_RO(init_pin_configs); |
582 | CODEC_ATTR_RO(afg), | 572 | static DEVICE_ATTR_RW(user_pin_configs); |
583 | CODEC_ATTR_RO(mfg), | 573 | static DEVICE_ATTR_RO(driver_pin_configs); |
584 | CODEC_ATTR_RW(vendor_name), | 574 | static DEVICE_ATTR_WO(reconfig); |
585 | CODEC_ATTR_RW(chip_name), | 575 | static DEVICE_ATTR_WO(clear); |
586 | CODEC_ATTR_RW(modelname), | ||
587 | CODEC_ATTR_RW(init_verbs), | ||
588 | CODEC_ATTR_RW(hints), | ||
589 | CODEC_ATTR_RO(init_pin_configs), | ||
590 | CODEC_ATTR_RW(user_pin_configs), | ||
591 | CODEC_ATTR_RO(driver_pin_configs), | ||
592 | CODEC_ATTR_WO(reconfig), | ||
593 | CODEC_ATTR_WO(clear), | ||
594 | }; | ||
595 | |||
596 | /* | ||
597 | * create sysfs files on hwdep directory | ||
598 | */ | ||
599 | int snd_hda_hwdep_add_sysfs(struct hda_codec *codec) | ||
600 | { | ||
601 | struct snd_hwdep *hwdep = codec->hwdep; | ||
602 | int i; | ||
603 | |||
604 | for (i = 0; i < ARRAY_SIZE(codec_attrs); i++) | ||
605 | snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card, | ||
606 | hwdep->device, &codec_attrs[i]); | ||
607 | return 0; | ||
608 | } | ||
609 | 576 | ||
610 | /* | 577 | /* |
611 | * Look for hint string | 578 | * Look for hint string |
@@ -884,3 +851,40 @@ int snd_hda_load_patch(struct hda_bus *bus, size_t fw_size, const void *fw_buf) | |||
884 | } | 851 | } |
885 | EXPORT_SYMBOL_GPL(snd_hda_load_patch); | 852 | EXPORT_SYMBOL_GPL(snd_hda_load_patch); |
886 | #endif /* CONFIG_SND_HDA_PATCH_LOADER */ | 853 | #endif /* CONFIG_SND_HDA_PATCH_LOADER */ |
854 | |||
855 | /* | ||
856 | * sysfs entries | ||
857 | */ | ||
858 | static struct attribute *hda_dev_attrs[] = { | ||
859 | #ifdef CONFIG_PM | ||
860 | &dev_attr_power_on_acct.attr, | ||
861 | &dev_attr_power_off_acct.attr, | ||
862 | #endif | ||
863 | #ifdef CONFIG_SND_HDA_RECONFIG | ||
864 | &dev_attr_vendor_id.attr, | ||
865 | &dev_attr_subsystem_id.attr, | ||
866 | &dev_attr_revision_id.attr, | ||
867 | &dev_attr_afg.attr, | ||
868 | &dev_attr_mfg.attr, | ||
869 | &dev_attr_vendor_name.attr, | ||
870 | &dev_attr_chip_name.attr, | ||
871 | &dev_attr_modelname.attr, | ||
872 | &dev_attr_init_verbs.attr, | ||
873 | &dev_attr_hints.attr, | ||
874 | &dev_attr_init_pin_configs.attr, | ||
875 | &dev_attr_user_pin_configs.attr, | ||
876 | &dev_attr_driver_pin_configs.attr, | ||
877 | &dev_attr_reconfig.attr, | ||
878 | &dev_attr_clear.attr, | ||
879 | #endif | ||
880 | NULL | ||
881 | }; | ||
882 | |||
883 | static struct attribute_group hda_dev_attr_group = { | ||
884 | .attrs = hda_dev_attrs, | ||
885 | }; | ||
886 | |||
887 | static const struct attribute_group *snd_hda_dev_attr_groups[] = { | ||
888 | &hda_dev_attr_group, | ||
889 | NULL | ||
890 | }; | ||
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index da80c5bd7fd4..31545923f6ac 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h | |||
@@ -597,24 +597,6 @@ int snd_hda_create_hwdep(struct hda_codec *codec); | |||
597 | static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } | 597 | static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } |
598 | #endif | 598 | #endif |
599 | 599 | ||
600 | #if defined(CONFIG_PM) && defined(CONFIG_SND_HDA_HWDEP) | ||
601 | int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec); | ||
602 | #else | ||
603 | static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec) | ||
604 | { | ||
605 | return 0; | ||
606 | } | ||
607 | #endif | ||
608 | |||
609 | #ifdef CONFIG_SND_HDA_RECONFIG | ||
610 | int snd_hda_hwdep_add_sysfs(struct hda_codec *codec); | ||
611 | #else | ||
612 | static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec) | ||
613 | { | ||
614 | return 0; | ||
615 | } | ||
616 | #endif | ||
617 | |||
618 | #ifdef CONFIG_SND_HDA_RECONFIG | 600 | #ifdef CONFIG_SND_HDA_RECONFIG |
619 | const char *snd_hda_get_hint(struct hda_codec *codec, const char *key); | 601 | const char *snd_hda_get_hint(struct hda_codec *codec, const char *key); |
620 | int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key); | 602 | int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key); |