diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-01-30 14:16:37 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-02-02 15:02:42 -0500 |
commit | d29697dc3b92cb12a80632a5ade4fa26fd98225e (patch) | |
tree | 1e829f0bacff5d5f2130ed13731f91e60f683c6b /sound/soc/soc-core.c | |
parent | 97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff) |
ASoC: Add sysfs entries via static attribute groups
Instead of calling device_create_file() manually, assign the static
attribute group entries at the device registration. This simplifies
the error handling and avoids the possible races.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r-- | sound/soc/soc-core.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 985052b3fbed..54925dc84a96 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -191,6 +191,39 @@ static ssize_t pmdown_time_set(struct device *dev, | |||
191 | 191 | ||
192 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); | 192 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
193 | 193 | ||
194 | static struct attribute *soc_dev_attrs[] = { | ||
195 | &dev_attr_codec_reg.attr, | ||
196 | &dev_attr_pmdown_time.attr, | ||
197 | NULL | ||
198 | }; | ||
199 | |||
200 | static umode_t soc_dev_attr_is_visible(struct kobject *kobj, | ||
201 | struct attribute *attr, int idx) | ||
202 | { | ||
203 | struct device *dev = kobj_to_dev(kobj); | ||
204 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); | ||
205 | |||
206 | if (attr == &dev_attr_pmdown_time.attr) | ||
207 | return attr->mode; /* always visible */ | ||
208 | return rtd->codec ? attr->mode : 0; /* enabled only with codec */ | ||
209 | } | ||
210 | |||
211 | static const struct attribute_group soc_dapm_dev_group = { | ||
212 | .attrs = soc_dapm_dev_attrs, | ||
213 | .is_visible = soc_dev_attr_is_visible, | ||
214 | }; | ||
215 | |||
216 | static const struct attribute_group soc_dev_roup = { | ||
217 | .attrs = soc_dev_attrs, | ||
218 | .is_visible = soc_dev_attr_is_visible, | ||
219 | }; | ||
220 | |||
221 | static const struct attribute_group *soc_dev_attr_groups[] = { | ||
222 | &soc_dapm_dev_group, | ||
223 | &soc_dev_roup, | ||
224 | NULL | ||
225 | }; | ||
226 | |||
194 | #ifdef CONFIG_DEBUG_FS | 227 | #ifdef CONFIG_DEBUG_FS |
195 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, | 228 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
196 | size_t count, loff_t *ppos) | 229 | size_t count, loff_t *ppos) |
@@ -949,8 +982,6 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) | |||
949 | 982 | ||
950 | /* unregister the rtd device */ | 983 | /* unregister the rtd device */ |
951 | if (rtd->dev_registered) { | 984 | if (rtd->dev_registered) { |
952 | device_remove_file(rtd->dev, &dev_attr_pmdown_time); | ||
953 | device_remove_file(rtd->dev, &dev_attr_codec_reg); | ||
954 | device_unregister(rtd->dev); | 985 | device_unregister(rtd->dev); |
955 | rtd->dev_registered = 0; | 986 | rtd->dev_registered = 0; |
956 | } | 987 | } |
@@ -1120,6 +1151,7 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, | |||
1120 | device_initialize(rtd->dev); | 1151 | device_initialize(rtd->dev); |
1121 | rtd->dev->parent = rtd->card->dev; | 1152 | rtd->dev->parent = rtd->card->dev; |
1122 | rtd->dev->release = rtd_release; | 1153 | rtd->dev->release = rtd_release; |
1154 | rtd->dev->groups = soc_dev_attr_groups; | ||
1123 | dev_set_name(rtd->dev, "%s", name); | 1155 | dev_set_name(rtd->dev, "%s", name); |
1124 | dev_set_drvdata(rtd->dev, rtd); | 1156 | dev_set_drvdata(rtd->dev, rtd); |
1125 | mutex_init(&rtd->pcm_mutex); | 1157 | mutex_init(&rtd->pcm_mutex); |
@@ -1136,23 +1168,6 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, | |||
1136 | return ret; | 1168 | return ret; |
1137 | } | 1169 | } |
1138 | rtd->dev_registered = 1; | 1170 | rtd->dev_registered = 1; |
1139 | |||
1140 | if (rtd->codec) { | ||
1141 | /* add DAPM sysfs entries for this codec */ | ||
1142 | ret = snd_soc_dapm_sys_add(rtd->dev); | ||
1143 | if (ret < 0) | ||
1144 | dev_err(rtd->dev, | ||
1145 | "ASoC: failed to add codec dapm sysfs entries: %d\n", | ||
1146 | ret); | ||
1147 | |||
1148 | /* add codec sysfs entries */ | ||
1149 | ret = device_create_file(rtd->dev, &dev_attr_codec_reg); | ||
1150 | if (ret < 0) | ||
1151 | dev_err(rtd->dev, | ||
1152 | "ASoC: failed to add codec sysfs files: %d\n", | ||
1153 | ret); | ||
1154 | } | ||
1155 | |||
1156 | return 0; | 1171 | return 0; |
1157 | } | 1172 | } |
1158 | 1173 | ||
@@ -1308,11 +1323,6 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) | |||
1308 | } | 1323 | } |
1309 | #endif | 1324 | #endif |
1310 | 1325 | ||
1311 | ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); | ||
1312 | if (ret < 0) | ||
1313 | dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", | ||
1314 | ret); | ||
1315 | |||
1316 | if (cpu_dai->driver->compress_dai) { | 1326 | if (cpu_dai->driver->compress_dai) { |
1317 | /*create compress_device"*/ | 1327 | /*create compress_device"*/ |
1318 | ret = soc_new_compress(rtd, num); | 1328 | ret = soc_new_compress(rtd, num); |