Commit | Line | Data |
---|---|---|
6339d232 VA |
1 | /* |
2 | * Greybus audio driver | |
3 | * Copyright 2015-2016 Google Inc. | |
4 | * Copyright 2015-2016 Linaro Ltd. | |
5 | * | |
6 | * Released under the GPLv2 only. | |
7 | */ | |
8 | ||
9 | #include "audio_codec.h" | |
10 | #include "greybus_protocols.h" | |
11 | ||
12 | #define GBAUDIO_INVALID_ID 0xFF | |
13 | ||
14 | /* mixer control */ | |
15 | struct gb_mixer_control { | |
16 | int min, max; | |
17 | unsigned int reg, rreg, shift, rshift, invert; | |
18 | }; | |
19 | ||
20 | struct gbaudio_ctl_pvt { | |
21 | unsigned int ctl_id; | |
22 | unsigned int data_cport; | |
23 | unsigned int access; | |
24 | unsigned int vcount; | |
25 | struct gb_audio_ctl_elem_info *info; | |
26 | }; | |
27 | ||
6dd67645 VA |
28 | static struct gbaudio_module_info *find_gb_module( |
29 | struct gbaudio_codec_info *codec, | |
30 | char const *name) | |
31 | { | |
32 | int dev_id, ret; | |
33 | char begin[NAME_SIZE]; | |
34 | struct gbaudio_module_info *module; | |
35 | ||
36 | if (!name) | |
37 | return NULL; | |
38 | ||
39 | ret = sscanf(name, "%s %d", begin, &dev_id); | |
40 | dev_dbg(codec->dev, "%s:Find module#%d\n", __func__, dev_id); | |
41 | ||
42 | mutex_lock(&codec->lock); | |
43 | list_for_each_entry(module, &codec->module_list, list) { | |
44 | if (module->dev_id == dev_id) { | |
45 | mutex_unlock(&codec->lock); | |
46 | return module; | |
47 | } | |
48 | } | |
49 | mutex_unlock(&codec->lock); | |
02f1c12c VA |
50 | dev_warn(codec->dev, "%s: module#%d missing in codec list\n", name, |
51 | dev_id); | |
6dd67645 VA |
52 | return NULL; |
53 | } | |
54 | ||
55 | static const char *gbaudio_map_controlid(struct gbaudio_module_info *module, | |
e65579e3 | 56 | __u8 control_id, __u8 index) |
6339d232 VA |
57 | { |
58 | struct gbaudio_control *control; | |
59 | ||
60 | if (control_id == GBAUDIO_INVALID_ID) | |
61 | return NULL; | |
62 | ||
6dd67645 | 63 | list_for_each_entry(control, &module->ctl_list, list) { |
6339d232 VA |
64 | if (control->id == control_id) { |
65 | if (index == GBAUDIO_INVALID_ID) | |
66 | return control->name; | |
15c726ea VA |
67 | if (index >= control->items) |
68 | return NULL; | |
6339d232 VA |
69 | return control->texts[index]; |
70 | } | |
71 | } | |
6dd67645 | 72 | list_for_each_entry(control, &module->widget_ctl_list, list) { |
6339d232 VA |
73 | if (control->id == control_id) { |
74 | if (index == GBAUDIO_INVALID_ID) | |
75 | return control->name; | |
15c726ea VA |
76 | if (index >= control->items) |
77 | return NULL; | |
6339d232 VA |
78 | return control->texts[index]; |
79 | } | |
80 | } | |
81 | return NULL; | |
82 | } | |
83 | ||
e65579e3 VA |
84 | static int gbaudio_map_controlname(struct gbaudio_module_info *module, |
85 | const char *name) | |
86 | { | |
87 | struct gbaudio_control *control; | |
88 | ||
89 | list_for_each_entry(control, &module->ctl_list, list) { | |
90 | if (!strncmp(control->name, name, NAME_SIZE)) | |
91 | return control->id; | |
92 | } | |
93 | ||
94 | dev_warn(module->dev, "%s: missing in modules controls list\n", name); | |
95 | ||
96 | return -EINVAL; | |
97 | } | |
98 | ||
0c15a9e0 | 99 | static int gbaudio_map_wcontrolname(struct gbaudio_module_info *module, |
e65579e3 | 100 | const char *name) |
0c15a9e0 VA |
101 | { |
102 | struct gbaudio_control *control; | |
103 | ||
104 | list_for_each_entry(control, &module->widget_ctl_list, list) { | |
105 | if (!strncmp(control->wname, name, NAME_SIZE)) | |
106 | return control->id; | |
107 | } | |
108 | dev_warn(module->dev, "%s: missing in modules controls list\n", name); | |
109 | ||
110 | return -EINVAL; | |
111 | } | |
112 | ||
6dd67645 | 113 | static int gbaudio_map_widgetname(struct gbaudio_module_info *module, |
e65579e3 | 114 | const char *name) |
6339d232 VA |
115 | { |
116 | struct gbaudio_widget *widget; | |
a2a87b22 | 117 | |
6dd67645 VA |
118 | list_for_each_entry(widget, &module->widget_list, list) { |
119 | if (!strncmp(widget->name, name, NAME_SIZE)) | |
6339d232 VA |
120 | return widget->id; |
121 | } | |
bb296b48 VA |
122 | dev_warn(module->dev, "%s: missing in modules widgets list\n", name); |
123 | ||
6339d232 VA |
124 | return -EINVAL; |
125 | } | |
126 | ||
6dd67645 | 127 | static const char *gbaudio_map_widgetid(struct gbaudio_module_info *module, |
e65579e3 | 128 | __u8 widget_id) |
6339d232 VA |
129 | { |
130 | struct gbaudio_widget *widget; | |
131 | ||
6dd67645 | 132 | list_for_each_entry(widget, &module->widget_list, list) { |
6339d232 VA |
133 | if (widget->id == widget_id) |
134 | return widget->name; | |
135 | } | |
136 | return NULL; | |
137 | } | |
138 | ||
a0de502e VK |
139 | static const char **gb_generate_enum_strings(struct gbaudio_module_info *gb, |
140 | struct gb_audio_enumerated *gbenum) | |
e65579e3 VA |
141 | { |
142 | const char **strings; | |
143 | int i; | |
055fb9ce | 144 | unsigned int items; |
e65579e3 VA |
145 | __u8 *data; |
146 | ||
055fb9ce VA |
147 | items = le32_to_cpu(gbenum->items); |
148 | strings = devm_kzalloc(gb->dev, sizeof(char *) * items, GFP_KERNEL); | |
e65579e3 VA |
149 | data = gbenum->names; |
150 | ||
055fb9ce | 151 | for (i = 0; i < items; i++) { |
e65579e3 VA |
152 | strings[i] = (const char *)data; |
153 | while (*data != '\0') | |
154 | data++; | |
155 | data++; | |
156 | } | |
157 | ||
158 | return strings; | |
159 | } | |
160 | ||
6339d232 VA |
161 | static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol, |
162 | struct snd_ctl_elem_info *uinfo) | |
163 | { | |
164 | unsigned int max; | |
165 | const char *name; | |
166 | struct gbaudio_ctl_pvt *data; | |
167 | struct gb_audio_ctl_elem_info *info; | |
6dd67645 | 168 | struct gbaudio_module_info *module; |
6339d232 | 169 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
796fad44 | 170 | struct gbaudio_codec_info *gbcodec = snd_soc_codec_get_drvdata(codec); |
6339d232 | 171 | |
6dd67645 | 172 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
6339d232 VA |
173 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
174 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
175 | ||
176 | if (!info) { | |
7224a2a5 | 177 | dev_err(codec->dev, "NULL info for %s\n", uinfo->id.name); |
6339d232 VA |
178 | return -EINVAL; |
179 | } | |
180 | ||
181 | /* update uinfo */ | |
182 | uinfo->access = data->access; | |
183 | uinfo->count = data->vcount; | |
184 | uinfo->type = (snd_ctl_elem_type_t)info->type; | |
185 | ||
186 | switch (info->type) { | |
187 | case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: | |
188 | case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: | |
055fb9ce VA |
189 | uinfo->value.integer.min = le32_to_cpu(info->value.integer.min); |
190 | uinfo->value.integer.max = le32_to_cpu(info->value.integer.max); | |
6339d232 VA |
191 | break; |
192 | case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: | |
055fb9ce | 193 | max = le32_to_cpu(info->value.enumerated.items); |
6339d232 VA |
194 | uinfo->value.enumerated.items = max; |
195 | if (uinfo->value.enumerated.item > max - 1) | |
196 | uinfo->value.enumerated.item = max - 1; | |
6dd67645 VA |
197 | module = find_gb_module(gbcodec, kcontrol->id.name); |
198 | if (!module) | |
199 | return -EINVAL; | |
200 | name = gbaudio_map_controlid(module, data->ctl_id, | |
6339d232 VA |
201 | uinfo->value.enumerated.item); |
202 | strlcpy(uinfo->value.enumerated.name, name, NAME_SIZE); | |
203 | break; | |
204 | default: | |
205 | dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n", | |
206 | info->type, kcontrol->id.name); | |
207 | break; | |
208 | } | |
209 | return 0; | |
210 | } | |
211 | ||
212 | static int gbcodec_mixer_ctl_get(struct snd_kcontrol *kcontrol, | |
213 | struct snd_ctl_elem_value *ucontrol) | |
214 | { | |
215 | int ret; | |
216 | struct gb_audio_ctl_elem_info *info; | |
217 | struct gbaudio_ctl_pvt *data; | |
218 | struct gb_audio_ctl_elem_value gbvalue; | |
6dd67645 | 219 | struct gbaudio_module_info *module; |
6339d232 | 220 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
796fad44 | 221 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); |
6ba7fad4 | 222 | struct gb_bundle *bundle; |
6339d232 | 223 | |
6dd67645 VA |
224 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
225 | module = find_gb_module(gb, kcontrol->id.name); | |
226 | if (!module) | |
227 | return -EINVAL; | |
3994e0b1 | 228 | |
6339d232 VA |
229 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
230 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
6ba7fad4 DL |
231 | bundle = to_gb_bundle(module->dev); |
232 | ||
233 | ret = gb_pm_runtime_get_sync(bundle); | |
234 | if (ret) | |
235 | return ret; | |
6339d232 | 236 | |
6dd67645 | 237 | ret = gb_audio_gb_get_control(module->mgmt_connection, data->ctl_id, |
6339d232 | 238 | GB_AUDIO_INVALID_INDEX, &gbvalue); |
6ba7fad4 DL |
239 | |
240 | gb_pm_runtime_put_autosuspend(bundle); | |
241 | ||
6339d232 | 242 | if (ret) { |
c6722ab5 VA |
243 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, |
244 | __func__, kcontrol->id.name); | |
6339d232 VA |
245 | return ret; |
246 | } | |
247 | ||
248 | /* update ucontrol */ | |
249 | switch (info->type) { | |
250 | case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: | |
251 | case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: | |
252 | ucontrol->value.integer.value[0] = | |
055fb9ce | 253 | le32_to_cpu(gbvalue.value.integer_value[0]); |
6339d232 VA |
254 | if (data->vcount == 2) |
255 | ucontrol->value.integer.value[1] = | |
055fb9ce | 256 | le32_to_cpu(gbvalue.value.integer_value[1]); |
6339d232 VA |
257 | break; |
258 | case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: | |
259 | ucontrol->value.enumerated.item[0] = | |
055fb9ce | 260 | le32_to_cpu(gbvalue.value.enumerated_item[0]); |
6339d232 VA |
261 | if (data->vcount == 2) |
262 | ucontrol->value.enumerated.item[1] = | |
055fb9ce | 263 | le32_to_cpu(gbvalue.value.enumerated_item[1]); |
6339d232 VA |
264 | break; |
265 | default: | |
266 | dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n", | |
267 | info->type, kcontrol->id.name); | |
268 | ret = -EINVAL; | |
269 | break; | |
270 | } | |
271 | return ret; | |
272 | } | |
273 | ||
274 | static int gbcodec_mixer_ctl_put(struct snd_kcontrol *kcontrol, | |
275 | struct snd_ctl_elem_value *ucontrol) | |
276 | { | |
277 | int ret = 0; | |
278 | struct gb_audio_ctl_elem_info *info; | |
279 | struct gbaudio_ctl_pvt *data; | |
280 | struct gb_audio_ctl_elem_value gbvalue; | |
6dd67645 | 281 | struct gbaudio_module_info *module; |
6339d232 | 282 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
796fad44 | 283 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); |
6ba7fad4 | 284 | struct gb_bundle *bundle; |
6339d232 | 285 | |
6dd67645 VA |
286 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
287 | module = find_gb_module(gb, kcontrol->id.name); | |
288 | if (!module) | |
289 | return -EINVAL; | |
3994e0b1 | 290 | |
6339d232 VA |
291 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
292 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
6ba7fad4 | 293 | bundle = to_gb_bundle(module->dev); |
6339d232 VA |
294 | |
295 | /* update ucontrol */ | |
296 | switch (info->type) { | |
297 | case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: | |
298 | case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: | |
299 | gbvalue.value.integer_value[0] = | |
055fb9ce | 300 | cpu_to_le32(ucontrol->value.integer.value[0]); |
6339d232 VA |
301 | if (data->vcount == 2) |
302 | gbvalue.value.integer_value[1] = | |
055fb9ce | 303 | cpu_to_le32(ucontrol->value.integer.value[1]); |
6339d232 VA |
304 | break; |
305 | case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: | |
306 | gbvalue.value.enumerated_item[0] = | |
055fb9ce | 307 | cpu_to_le32(ucontrol->value.enumerated.item[0]); |
6339d232 VA |
308 | if (data->vcount == 2) |
309 | gbvalue.value.enumerated_item[1] = | |
055fb9ce | 310 | cpu_to_le32(ucontrol->value.enumerated.item[1]); |
6339d232 VA |
311 | break; |
312 | default: | |
313 | dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n", | |
314 | info->type, kcontrol->id.name); | |
315 | ret = -EINVAL; | |
316 | break; | |
317 | } | |
318 | ||
6ba7fad4 DL |
319 | if (ret) |
320 | return ret; | |
321 | ||
322 | ret = gb_pm_runtime_get_sync(bundle); | |
6339d232 VA |
323 | if (ret) |
324 | return ret; | |
325 | ||
6dd67645 | 326 | ret = gb_audio_gb_set_control(module->mgmt_connection, data->ctl_id, |
6339d232 | 327 | GB_AUDIO_INVALID_INDEX, &gbvalue); |
6ba7fad4 DL |
328 | |
329 | gb_pm_runtime_put_autosuspend(bundle); | |
330 | ||
6339d232 | 331 | if (ret) { |
c6722ab5 VA |
332 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, |
333 | __func__, kcontrol->id.name); | |
6339d232 VA |
334 | } |
335 | ||
336 | return ret; | |
337 | } | |
338 | ||
339 | #define SOC_MIXER_GB(xname, kcount, data) \ | |
340 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | |
341 | .count = kcount, .info = gbcodec_mixer_ctl_info, \ | |
342 | .get = gbcodec_mixer_ctl_get, .put = gbcodec_mixer_ctl_put, \ | |
343 | .private_value = (unsigned long)data } | |
344 | ||
345 | /* | |
346 | * although below callback functions seems redundant to above functions. | |
347 | * same are kept to allow provision for different handling in case | |
348 | * of DAPM related sequencing, etc. | |
349 | */ | |
350 | static int gbcodec_mixer_dapm_ctl_info(struct snd_kcontrol *kcontrol, | |
351 | struct snd_ctl_elem_info *uinfo) | |
352 | { | |
353 | int platform_max, platform_min; | |
354 | struct gbaudio_ctl_pvt *data; | |
355 | struct gb_audio_ctl_elem_info *info; | |
6dd67645 VA |
356 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
357 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | |
358 | struct snd_soc_codec *codec = widget->codec; | |
6339d232 | 359 | |
6dd67645 | 360 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
6339d232 VA |
361 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
362 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
363 | ||
364 | /* update uinfo */ | |
055fb9ce VA |
365 | platform_max = le32_to_cpu(info->value.integer.max); |
366 | platform_min = le32_to_cpu(info->value.integer.min); | |
6339d232 VA |
367 | |
368 | if (platform_max == 1 && | |
369 | !strnstr(kcontrol->id.name, " Volume", NAME_SIZE)) | |
370 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
371 | else | |
372 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
373 | ||
374 | uinfo->count = data->vcount; | |
84510052 VA |
375 | uinfo->value.integer.min = platform_min; |
376 | uinfo->value.integer.max = platform_max; | |
6339d232 VA |
377 | |
378 | return 0; | |
379 | } | |
380 | ||
381 | static int gbcodec_mixer_dapm_ctl_get(struct snd_kcontrol *kcontrol, | |
382 | struct snd_ctl_elem_value *ucontrol) | |
383 | { | |
384 | int ret; | |
385 | struct gb_audio_ctl_elem_info *info; | |
386 | struct gbaudio_ctl_pvt *data; | |
387 | struct gb_audio_ctl_elem_value gbvalue; | |
6dd67645 | 388 | struct gbaudio_module_info *module; |
6339d232 VA |
389 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
390 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | |
391 | struct snd_soc_codec *codec = widget->codec; | |
796fad44 | 392 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); |
6ba7fad4 | 393 | struct gb_bundle *bundle; |
6339d232 | 394 | |
6dd67645 VA |
395 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
396 | module = find_gb_module(gb, kcontrol->id.name); | |
397 | if (!module) | |
398 | return -EINVAL; | |
3994e0b1 | 399 | |
6339d232 VA |
400 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
401 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
6ba7fad4 | 402 | bundle = to_gb_bundle(module->dev); |
6339d232 VA |
403 | |
404 | if (data->vcount == 2) | |
405 | dev_warn(widget->dapm->dev, | |
406 | "GB: Control '%s' is stereo, which is not supported\n", | |
407 | kcontrol->id.name); | |
408 | ||
6ba7fad4 DL |
409 | ret = gb_pm_runtime_get_sync(bundle); |
410 | if (ret) | |
411 | return ret; | |
412 | ||
6dd67645 | 413 | ret = gb_audio_gb_get_control(module->mgmt_connection, data->ctl_id, |
6339d232 | 414 | GB_AUDIO_INVALID_INDEX, &gbvalue); |
6ba7fad4 DL |
415 | |
416 | gb_pm_runtime_put_autosuspend(bundle); | |
417 | ||
6339d232 | 418 | if (ret) { |
c6722ab5 VA |
419 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, |
420 | __func__, kcontrol->id.name); | |
6339d232 VA |
421 | return ret; |
422 | } | |
423 | /* update ucontrol */ | |
055fb9ce VA |
424 | ucontrol->value.integer.value[0] = |
425 | le32_to_cpu(gbvalue.value.integer_value[0]); | |
6339d232 VA |
426 | |
427 | return ret; | |
428 | } | |
429 | ||
430 | static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol, | |
431 | struct snd_ctl_elem_value *ucontrol) | |
432 | { | |
433 | int ret, wi, max, connect; | |
434 | unsigned int mask, val; | |
435 | struct gb_audio_ctl_elem_info *info; | |
436 | struct gbaudio_ctl_pvt *data; | |
437 | struct gb_audio_ctl_elem_value gbvalue; | |
6dd67645 | 438 | struct gbaudio_module_info *module; |
6339d232 VA |
439 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
440 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | |
441 | struct snd_soc_codec *codec = widget->codec; | |
796fad44 | 442 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); |
6ba7fad4 | 443 | struct gb_bundle *bundle; |
6339d232 | 444 | |
6dd67645 VA |
445 | dev_dbg(codec->dev, "Entered %s:%s\n", __func__, kcontrol->id.name); |
446 | module = find_gb_module(gb, kcontrol->id.name); | |
447 | if (!module) | |
448 | return -EINVAL; | |
3994e0b1 | 449 | |
6339d232 VA |
450 | data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; |
451 | info = (struct gb_audio_ctl_elem_info *)data->info; | |
6ba7fad4 | 452 | bundle = to_gb_bundle(module->dev); |
6339d232 VA |
453 | |
454 | if (data->vcount == 2) | |
455 | dev_warn(widget->dapm->dev, | |
456 | "GB: Control '%s' is stereo, which is not supported\n", | |
457 | kcontrol->id.name); | |
458 | ||
055fb9ce | 459 | max = le32_to_cpu(info->value.integer.max); |
6339d232 | 460 | mask = (1 << fls(max)) - 1; |
4f1cbe2a | 461 | val = ucontrol->value.integer.value[0] & mask; |
6339d232 VA |
462 | connect = !!val; |
463 | ||
464 | /* update ucontrol */ | |
465 | if (gbvalue.value.integer_value[0] != val) { | |
466 | for (wi = 0; wi < wlist->num_widgets; wi++) { | |
467 | widget = wlist->widgets[wi]; | |
468 | ||
469 | widget->value = val; | |
470 | widget->dapm->update = NULL; | |
471 | snd_soc_dapm_mixer_update_power(widget, kcontrol, | |
472 | connect); | |
473 | } | |
474 | gbvalue.value.integer_value[0] = | |
055fb9ce | 475 | cpu_to_le32(ucontrol->value.integer.value[0]); |
6ba7fad4 DL |
476 | |
477 | ret = gb_pm_runtime_get_sync(bundle); | |
478 | if (ret) | |
479 | return ret; | |
480 | ||
6dd67645 | 481 | ret = gb_audio_gb_set_control(module->mgmt_connection, |
6339d232 VA |
482 | data->ctl_id, |
483 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
6ba7fad4 DL |
484 | |
485 | gb_pm_runtime_put_autosuspend(bundle); | |
486 | ||
6339d232 | 487 | if (ret) { |
c6722ab5 VA |
488 | dev_err_ratelimited(codec->dev, |
489 | "%d:Error in %s for %s\n", ret, | |
490 | __func__, kcontrol->id.name); | |
7224a2a5 | 491 | return ret; |
6339d232 VA |
492 | } |
493 | } | |
494 | ||
7224a2a5 | 495 | return 0; |
6339d232 VA |
496 | } |
497 | ||
498 | #define SOC_DAPM_MIXER_GB(xname, kcount, data) \ | |
499 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | |
500 | .count = kcount, .info = gbcodec_mixer_dapm_ctl_info, \ | |
501 | .get = gbcodec_mixer_dapm_ctl_get, .put = gbcodec_mixer_dapm_ctl_put, \ | |
502 | .private_value = (unsigned long)data} | |
503 | ||
504 | static int gbcodec_event_spk(struct snd_soc_dapm_widget *w, | |
505 | struct snd_kcontrol *k, int event) | |
506 | { | |
507 | /* Ensure GB speaker is connected */ | |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
512 | static int gbcodec_event_hp(struct snd_soc_dapm_widget *w, | |
513 | struct snd_kcontrol *k, int event) | |
514 | { | |
515 | /* Ensure GB module supports jack slot */ | |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
520 | static int gbcodec_event_int_mic(struct snd_soc_dapm_widget *w, | |
521 | struct snd_kcontrol *k, int event) | |
522 | { | |
523 | /* Ensure GB module supports jack slot */ | |
524 | ||
525 | return 0; | |
526 | } | |
527 | ||
528 | static int gbaudio_validate_kcontrol_count(struct gb_audio_widget *w) | |
529 | { | |
530 | int ret = 0; | |
531 | ||
532 | switch (w->type) { | |
533 | case snd_soc_dapm_spk: | |
534 | case snd_soc_dapm_hp: | |
535 | case snd_soc_dapm_mic: | |
536 | case snd_soc_dapm_output: | |
537 | case snd_soc_dapm_input: | |
538 | if (w->ncontrols) | |
539 | ret = -EINVAL; | |
540 | break; | |
541 | case snd_soc_dapm_switch: | |
542 | case snd_soc_dapm_mux: | |
543 | if (w->ncontrols != 1) | |
544 | ret = -EINVAL; | |
545 | break; | |
546 | default: | |
547 | break; | |
548 | } | |
549 | ||
550 | return ret; | |
551 | } | |
552 | ||
e65579e3 VA |
553 | static int gbcodec_enum_ctl_get(struct snd_kcontrol *kcontrol, |
554 | struct snd_ctl_elem_value *ucontrol) | |
555 | { | |
556 | int ret, ctl_id; | |
557 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
558 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | |
559 | struct gb_audio_ctl_elem_value gbvalue; | |
560 | struct gbaudio_module_info *module; | |
561 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); | |
9d3717f7 | 562 | struct gb_bundle *bundle; |
e65579e3 VA |
563 | |
564 | module = find_gb_module(gb, kcontrol->id.name); | |
565 | if (!module) | |
566 | return -EINVAL; | |
567 | ||
568 | ctl_id = gbaudio_map_controlname(module, kcontrol->id.name); | |
569 | if (ctl_id < 0) | |
570 | return -EINVAL; | |
571 | ||
9d3717f7 DL |
572 | bundle = to_gb_bundle(module->dev); |
573 | ||
574 | ret = gb_pm_runtime_get_sync(bundle); | |
575 | if (ret) | |
576 | return ret; | |
577 | ||
e65579e3 VA |
578 | ret = gb_audio_gb_get_control(module->mgmt_connection, ctl_id, |
579 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
9d3717f7 DL |
580 | |
581 | gb_pm_runtime_put_autosuspend(bundle); | |
582 | ||
e65579e3 VA |
583 | if (ret) { |
584 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, | |
585 | __func__, kcontrol->id.name); | |
586 | return ret; | |
587 | } | |
588 | ||
055fb9ce VA |
589 | ucontrol->value.enumerated.item[0] = |
590 | le32_to_cpu(gbvalue.value.enumerated_item[0]); | |
e65579e3 VA |
591 | if (e->shift_l != e->shift_r) |
592 | ucontrol->value.enumerated.item[1] = | |
055fb9ce | 593 | le32_to_cpu(gbvalue.value.enumerated_item[1]); |
e65579e3 VA |
594 | |
595 | return 0; | |
596 | } | |
597 | ||
598 | static int gbcodec_enum_ctl_put(struct snd_kcontrol *kcontrol, | |
599 | struct snd_ctl_elem_value *ucontrol) | |
600 | { | |
601 | int ret, ctl_id; | |
602 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
603 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | |
604 | struct gb_audio_ctl_elem_value gbvalue; | |
605 | struct gbaudio_module_info *module; | |
606 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); | |
9d3717f7 | 607 | struct gb_bundle *bundle; |
e65579e3 VA |
608 | |
609 | module = find_gb_module(gb, kcontrol->id.name); | |
610 | if (!module) | |
611 | return -EINVAL; | |
612 | ||
613 | ctl_id = gbaudio_map_controlname(module, kcontrol->id.name); | |
614 | if (ctl_id < 0) | |
615 | return -EINVAL; | |
616 | ||
617 | if (ucontrol->value.enumerated.item[0] > e->max - 1) | |
618 | return -EINVAL; | |
055fb9ce VA |
619 | gbvalue.value.enumerated_item[0] = |
620 | cpu_to_le32(ucontrol->value.enumerated.item[0]); | |
e65579e3 VA |
621 | |
622 | if (e->shift_l != e->shift_r) { | |
623 | if (ucontrol->value.enumerated.item[1] > e->max - 1) | |
624 | return -EINVAL; | |
625 | gbvalue.value.enumerated_item[1] = | |
055fb9ce | 626 | cpu_to_le32(ucontrol->value.enumerated.item[1]); |
e65579e3 VA |
627 | } |
628 | ||
9d3717f7 DL |
629 | bundle = to_gb_bundle(module->dev); |
630 | ||
631 | ret = gb_pm_runtime_get_sync(bundle); | |
632 | if (ret) | |
633 | return ret; | |
634 | ||
e65579e3 VA |
635 | ret = gb_audio_gb_set_control(module->mgmt_connection, ctl_id, |
636 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
9d3717f7 DL |
637 | |
638 | gb_pm_runtime_put_autosuspend(bundle); | |
639 | ||
e65579e3 VA |
640 | if (ret) { |
641 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, | |
642 | __func__, kcontrol->id.name); | |
643 | } | |
644 | ||
645 | return ret; | |
646 | } | |
647 | ||
648 | static int gbaudio_tplg_create_enum_kctl(struct gbaudio_module_info *gb, | |
649 | struct snd_kcontrol_new *kctl, | |
650 | struct gb_audio_control *ctl) | |
651 | { | |
652 | struct soc_enum *gbe; | |
653 | struct gb_audio_enumerated *gb_enum; | |
654 | int i; | |
655 | ||
656 | gbe = devm_kzalloc(gb->dev, sizeof(*gbe), GFP_KERNEL); | |
657 | if (!gbe) | |
658 | return -ENOMEM; | |
659 | ||
660 | gb_enum = &ctl->info.value.enumerated; | |
661 | ||
662 | /* since count=1, and reg is dummy */ | |
055fb9ce | 663 | gbe->max = le32_to_cpu(gb_enum->items); |
e65579e3 VA |
664 | gbe->texts = gb_generate_enum_strings(gb, gb_enum); |
665 | ||
666 | /* debug enum info */ | |
055fb9ce VA |
667 | dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->max, |
668 | le16_to_cpu(gb_enum->names_length)); | |
669 | for (i = 0; i < gbe->max; i++) | |
e65579e3 VA |
670 | dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]); |
671 | ||
672 | *kctl = (struct snd_kcontrol_new) | |
673 | SOC_ENUM_EXT(ctl->name, *gbe, gbcodec_enum_ctl_get, | |
674 | gbcodec_enum_ctl_put); | |
675 | return 0; | |
676 | } | |
677 | ||
6dd67645 | 678 | static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb, |
6339d232 VA |
679 | struct snd_kcontrol_new *kctl, |
680 | struct gb_audio_control *ctl) | |
681 | { | |
e65579e3 | 682 | int ret = 0; |
6339d232 VA |
683 | struct gbaudio_ctl_pvt *ctldata; |
684 | ||
685 | switch (ctl->iface) { | |
686 | case SNDRV_CTL_ELEM_IFACE_MIXER: | |
e65579e3 VA |
687 | switch (ctl->info.type) { |
688 | case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: | |
689 | ret = gbaudio_tplg_create_enum_kctl(gb, kctl, ctl); | |
690 | break; | |
691 | default: | |
692 | ctldata = devm_kzalloc(gb->dev, | |
693 | sizeof(struct gbaudio_ctl_pvt), | |
694 | GFP_KERNEL); | |
695 | if (!ctldata) | |
696 | return -ENOMEM; | |
697 | ctldata->ctl_id = ctl->id; | |
055fb9ce | 698 | ctldata->data_cport = le16_to_cpu(ctl->data_cport); |
e65579e3 VA |
699 | ctldata->access = ctl->access; |
700 | ctldata->vcount = ctl->count_values; | |
701 | ctldata->info = &ctl->info; | |
702 | *kctl = (struct snd_kcontrol_new) | |
703 | SOC_MIXER_GB(ctl->name, ctl->count, ctldata); | |
704 | ctldata = NULL; | |
705 | break; | |
706 | } | |
6339d232 VA |
707 | break; |
708 | default: | |
709 | return -EINVAL; | |
710 | } | |
711 | ||
712 | dev_dbg(gb->dev, "%s:%d control created\n", ctl->name, ctl->id); | |
e65579e3 VA |
713 | return ret; |
714 | } | |
715 | ||
716 | static int gbcodec_enum_dapm_ctl_get(struct snd_kcontrol *kcontrol, | |
717 | struct snd_ctl_elem_value *ucontrol) | |
718 | { | |
719 | int ret, ctl_id; | |
720 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | |
721 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | |
722 | struct gbaudio_module_info *module; | |
723 | struct gb_audio_ctl_elem_value gbvalue; | |
724 | struct snd_soc_codec *codec = widget->codec; | |
725 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); | |
726 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | |
9d3717f7 | 727 | struct gb_bundle *bundle; |
e65579e3 VA |
728 | |
729 | module = find_gb_module(gb, kcontrol->id.name); | |
730 | if (!module) | |
731 | return -EINVAL; | |
732 | ||
733 | ctl_id = gbaudio_map_wcontrolname(module, kcontrol->id.name); | |
734 | if (ctl_id < 0) | |
735 | return -EINVAL; | |
736 | ||
9d3717f7 DL |
737 | bundle = to_gb_bundle(module->dev); |
738 | ||
739 | ret = gb_pm_runtime_get_sync(bundle); | |
740 | if (ret) | |
741 | return ret; | |
742 | ||
e65579e3 VA |
743 | ret = gb_audio_gb_get_control(module->mgmt_connection, ctl_id, |
744 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
9d3717f7 DL |
745 | |
746 | gb_pm_runtime_put_autosuspend(bundle); | |
747 | ||
e65579e3 VA |
748 | if (ret) { |
749 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, | |
750 | __func__, kcontrol->id.name); | |
751 | return ret; | |
752 | } | |
753 | ||
754 | ucontrol->value.enumerated.item[0] = gbvalue.value.enumerated_item[0]; | |
755 | if (e->shift_l != e->shift_r) | |
756 | ucontrol->value.enumerated.item[1] = | |
757 | gbvalue.value.enumerated_item[1]; | |
758 | ||
6339d232 VA |
759 | return 0; |
760 | } | |
761 | ||
e65579e3 VA |
762 | static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol, |
763 | struct snd_ctl_elem_value *ucontrol) | |
764 | { | |
765 | int ret, wi, ctl_id; | |
766 | unsigned int val, mux, change; | |
767 | unsigned int mask; | |
768 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | |
769 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | |
770 | struct gb_audio_ctl_elem_value gbvalue; | |
771 | struct gbaudio_module_info *module; | |
772 | struct snd_soc_codec *codec = widget->codec; | |
773 | struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec); | |
774 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | |
9d3717f7 | 775 | struct gb_bundle *bundle; |
e65579e3 VA |
776 | |
777 | if (ucontrol->value.enumerated.item[0] > e->max - 1) | |
778 | return -EINVAL; | |
779 | ||
780 | module = find_gb_module(gb, kcontrol->id.name); | |
781 | if (!module) | |
782 | return -EINVAL; | |
783 | ||
784 | ctl_id = gbaudio_map_wcontrolname(module, kcontrol->id.name); | |
785 | if (ctl_id < 0) | |
786 | return -EINVAL; | |
787 | ||
788 | change = 0; | |
9d3717f7 DL |
789 | bundle = to_gb_bundle(module->dev); |
790 | ||
791 | ret = gb_pm_runtime_get_sync(bundle); | |
792 | if (ret) | |
793 | return ret; | |
794 | ||
e65579e3 VA |
795 | ret = gb_audio_gb_get_control(module->mgmt_connection, ctl_id, |
796 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
9d3717f7 DL |
797 | |
798 | gb_pm_runtime_put_autosuspend(bundle); | |
799 | ||
e65579e3 VA |
800 | if (ret) { |
801 | dev_err_ratelimited(codec->dev, "%d:Error in %s for %s\n", ret, | |
802 | __func__, kcontrol->id.name); | |
803 | return ret; | |
804 | } | |
6339d232 | 805 | |
e65579e3 VA |
806 | mux = ucontrol->value.enumerated.item[0]; |
807 | val = mux << e->shift_l; | |
808 | mask = e->mask << e->shift_l; | |
6339d232 | 809 | |
e65579e3 VA |
810 | if (gbvalue.value.enumerated_item[0] != |
811 | ucontrol->value.enumerated.item[0]) { | |
812 | change = 1; | |
813 | gbvalue.value.enumerated_item[0] = | |
814 | ucontrol->value.enumerated.item[0]; | |
815 | } | |
816 | ||
817 | if (e->shift_l != e->shift_r) { | |
818 | if (ucontrol->value.enumerated.item[1] > e->max - 1) | |
819 | return -EINVAL; | |
820 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; | |
821 | mask |= e->mask << e->shift_r; | |
822 | if (gbvalue.value.enumerated_item[1] != | |
823 | ucontrol->value.enumerated.item[1]) { | |
824 | change = 1; | |
825 | gbvalue.value.enumerated_item[1] = | |
826 | ucontrol->value.enumerated.item[1]; | |
827 | } | |
828 | } | |
829 | ||
830 | if (change) { | |
9d3717f7 DL |
831 | ret = gb_pm_runtime_get_sync(bundle); |
832 | if (ret) | |
833 | return ret; | |
834 | ||
e65579e3 VA |
835 | ret = gb_audio_gb_set_control(module->mgmt_connection, ctl_id, |
836 | GB_AUDIO_INVALID_INDEX, &gbvalue); | |
9d3717f7 DL |
837 | |
838 | gb_pm_runtime_put_autosuspend(bundle); | |
839 | ||
e65579e3 VA |
840 | if (ret) { |
841 | dev_err_ratelimited(codec->dev, | |
842 | "%d:Error in %s for %s\n", ret, | |
843 | __func__, kcontrol->id.name); | |
844 | } | |
845 | for (wi = 0; wi < wlist->num_widgets; wi++) { | |
846 | widget = wlist->widgets[wi]; | |
847 | ||
848 | widget->value = val; | |
849 | widget->dapm->update = NULL; | |
850 | snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e); | |
851 | } | |
852 | } | |
853 | ||
854 | return change; | |
855 | } | |
6339d232 | 856 | |
6dd67645 | 857 | static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info *gb, |
6339d232 VA |
858 | struct snd_kcontrol_new *kctl, |
859 | struct gb_audio_control *ctl) | |
860 | { | |
e65579e3 VA |
861 | struct soc_enum *gbe; |
862 | struct gb_audio_enumerated *gb_enum; | |
863 | int i; | |
864 | ||
865 | gbe = devm_kzalloc(gb->dev, sizeof(*gbe), GFP_KERNEL); | |
866 | if (!gbe) | |
867 | return -ENOMEM; | |
6339d232 | 868 | |
e65579e3 VA |
869 | gb_enum = &ctl->info.value.enumerated; |
870 | ||
871 | /* since count=1, and reg is dummy */ | |
055fb9ce | 872 | gbe->max = le32_to_cpu(gb_enum->items); |
e65579e3 VA |
873 | gbe->texts = gb_generate_enum_strings(gb, gb_enum); |
874 | ||
875 | /* debug enum info */ | |
055fb9ce VA |
876 | dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->max, |
877 | le16_to_cpu(gb_enum->names_length)); | |
878 | for (i = 0; i < gbe->max; i++) | |
e65579e3 VA |
879 | dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]); |
880 | ||
881 | *kctl = (struct snd_kcontrol_new) | |
882 | SOC_DAPM_ENUM_EXT(ctl->name, *gbe, gbcodec_enum_dapm_ctl_get, | |
883 | gbcodec_enum_dapm_ctl_put); | |
6339d232 VA |
884 | return 0; |
885 | } | |
886 | ||
6dd67645 | 887 | static int gbaudio_tplg_create_mixer_ctl(struct gbaudio_module_info *gb, |
6339d232 VA |
888 | struct snd_kcontrol_new *kctl, |
889 | struct gb_audio_control *ctl) | |
890 | { | |
891 | struct gbaudio_ctl_pvt *ctldata; | |
892 | ||
893 | ctldata = devm_kzalloc(gb->dev, sizeof(struct gbaudio_ctl_pvt), | |
894 | GFP_KERNEL); | |
895 | if (!ctldata) | |
896 | return -ENOMEM; | |
897 | ctldata->ctl_id = ctl->id; | |
055fb9ce | 898 | ctldata->data_cport = le16_to_cpu(ctl->data_cport); |
6339d232 VA |
899 | ctldata->access = ctl->access; |
900 | ctldata->vcount = ctl->count_values; | |
901 | ctldata->info = &ctl->info; | |
902 | *kctl = (struct snd_kcontrol_new) | |
903 | SOC_DAPM_MIXER_GB(ctl->name, ctl->count, ctldata); | |
904 | ||
905 | return 0; | |
906 | } | |
907 | ||
6dd67645 | 908 | static int gbaudio_tplg_create_wcontrol(struct gbaudio_module_info *gb, |
6339d232 VA |
909 | struct snd_kcontrol_new *kctl, |
910 | struct gb_audio_control *ctl) | |
911 | { | |
912 | int ret; | |
913 | ||
914 | switch (ctl->iface) { | |
915 | case SNDRV_CTL_ELEM_IFACE_MIXER: | |
916 | switch (ctl->info.type) { | |
917 | case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: | |
918 | ret = gbaudio_tplg_create_enum_ctl(gb, kctl, ctl); | |
919 | break; | |
920 | default: | |
921 | ret = gbaudio_tplg_create_mixer_ctl(gb, kctl, ctl); | |
922 | break; | |
923 | } | |
924 | break; | |
925 | default: | |
926 | return -EINVAL; | |
927 | ||
928 | } | |
929 | ||
930 | dev_dbg(gb->dev, "%s:%d DAPM control created, ret:%d\n", ctl->name, | |
931 | ctl->id, ret); | |
932 | return ret; | |
933 | } | |
934 | ||
935 | static int gbaudio_widget_event(struct snd_soc_dapm_widget *w, | |
936 | struct snd_kcontrol *kcontrol, int event) | |
937 | { | |
938 | int wid; | |
939 | int ret; | |
940 | struct snd_soc_codec *codec = w->codec; | |
796fad44 | 941 | struct gbaudio_codec_info *gbcodec = snd_soc_codec_get_drvdata(codec); |
6dd67645 | 942 | struct gbaudio_module_info *module; |
6ba7fad4 | 943 | struct gb_bundle *bundle; |
6339d232 VA |
944 | |
945 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); | |
946 | ||
6dd67645 VA |
947 | /* Find relevant module */ |
948 | module = find_gb_module(gbcodec, w->name); | |
949 | if (!module) | |
950 | return -EINVAL; | |
951 | ||
6339d232 | 952 | /* map name to widget id */ |
6dd67645 | 953 | wid = gbaudio_map_widgetname(module, w->name); |
6339d232 VA |
954 | if (wid < 0) { |
955 | dev_err(codec->dev, "Invalid widget name:%s\n", w->name); | |
956 | return -EINVAL; | |
957 | } | |
958 | ||
6ba7fad4 DL |
959 | bundle = to_gb_bundle(module->dev); |
960 | ||
961 | ret = gb_pm_runtime_get_sync(bundle); | |
962 | if (ret) | |
963 | return ret; | |
964 | ||
6339d232 VA |
965 | switch (event) { |
966 | case SND_SOC_DAPM_PRE_PMU: | |
6dd67645 VA |
967 | ret = gb_audio_gb_enable_widget(module->mgmt_connection, wid); |
968 | if (!ret) | |
4ffca62a | 969 | ret = gbaudio_module_update(gbcodec, w, module, 1); |
6339d232 VA |
970 | break; |
971 | case SND_SOC_DAPM_POST_PMD: | |
6dd67645 VA |
972 | ret = gb_audio_gb_disable_widget(module->mgmt_connection, wid); |
973 | if (!ret) | |
4ffca62a | 974 | ret = gbaudio_module_update(gbcodec, w, module, 0); |
6339d232 VA |
975 | break; |
976 | } | |
977 | if (ret) | |
c6722ab5 VA |
978 | dev_err_ratelimited(codec->dev, |
979 | "%d: widget, event:%d failed:%d\n", wid, | |
980 | event, ret); | |
6ba7fad4 DL |
981 | |
982 | gb_pm_runtime_put_autosuspend(bundle); | |
983 | ||
6339d232 VA |
984 | return ret; |
985 | } | |
986 | ||
6dd67645 | 987 | static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, |
6339d232 | 988 | struct snd_soc_dapm_widget *dw, |
d4cd9daa | 989 | struct gb_audio_widget *w, int *w_size) |
6339d232 | 990 | { |
d4cd9daa | 991 | int i, ret, csize; |
6339d232 VA |
992 | struct snd_kcontrol_new *widget_kctls; |
993 | struct gb_audio_control *curr; | |
994 | struct gbaudio_control *control, *_control; | |
995 | size_t size; | |
6dd67645 | 996 | char temp_name[NAME_SIZE]; |
6339d232 VA |
997 | |
998 | ret = gbaudio_validate_kcontrol_count(w); | |
999 | if (ret) { | |
6dd67645 | 1000 | dev_err(module->dev, "Inavlid kcontrol count=%d for %s\n", |
6339d232 VA |
1001 | w->ncontrols, w->name); |
1002 | return ret; | |
1003 | } | |
1004 | ||
1005 | /* allocate memory for kcontrol */ | |
1006 | if (w->ncontrols) { | |
1007 | size = sizeof(struct snd_kcontrol_new) * w->ncontrols; | |
6dd67645 | 1008 | widget_kctls = devm_kzalloc(module->dev, size, GFP_KERNEL); |
6339d232 VA |
1009 | if (!widget_kctls) |
1010 | return -ENOMEM; | |
1011 | } | |
1012 | ||
d4cd9daa VA |
1013 | *w_size = sizeof(struct gb_audio_widget); |
1014 | ||
6339d232 | 1015 | /* create relevant kcontrols */ |
d4cd9daa | 1016 | curr = w->ctl; |
6339d232 | 1017 | for (i = 0; i < w->ncontrols; i++) { |
6dd67645 | 1018 | ret = gbaudio_tplg_create_wcontrol(module, &widget_kctls[i], |
6339d232 VA |
1019 | curr); |
1020 | if (ret) { | |
6dd67645 | 1021 | dev_err(module->dev, |
6339d232 VA |
1022 | "%s:%d type widget_ctl not supported\n", |
1023 | curr->name, curr->iface); | |
1024 | goto error; | |
1025 | } | |
6dd67645 | 1026 | control = devm_kzalloc(module->dev, |
6339d232 VA |
1027 | sizeof(struct gbaudio_control), |
1028 | GFP_KERNEL); | |
1029 | if (!control) { | |
1030 | ret = -ENOMEM; | |
1031 | goto error; | |
1032 | } | |
1033 | control->id = curr->id; | |
1034 | control->name = curr->name; | |
0c15a9e0 VA |
1035 | control->wname = w->name; |
1036 | ||
e65579e3 VA |
1037 | if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) { |
1038 | struct gb_audio_enumerated *gbenum = | |
1039 | &curr->info.value.enumerated; | |
1040 | ||
1041 | csize = offsetof(struct gb_audio_control, info); | |
1042 | csize += offsetof(struct gb_audio_ctl_elem_info, value); | |
1043 | csize += offsetof(struct gb_audio_enumerated, names); | |
055fb9ce | 1044 | csize += le16_to_cpu(gbenum->names_length); |
6339d232 | 1045 | control->texts = (const char * const *) |
e65579e3 | 1046 | gb_generate_enum_strings(module, gbenum); |
055fb9ce | 1047 | control->items = le32_to_cpu(gbenum->items); |
02ae32f7 | 1048 | } else { |
e65579e3 | 1049 | csize = sizeof(struct gb_audio_control); |
02ae32f7 CM |
1050 | } |
1051 | ||
d4cd9daa VA |
1052 | *w_size += csize; |
1053 | curr = (void *)curr + csize; | |
6dd67645 VA |
1054 | list_add(&control->list, &module->widget_ctl_list); |
1055 | dev_dbg(module->dev, "%s: control of type %d created\n", | |
6339d232 VA |
1056 | widget_kctls[i].name, widget_kctls[i].iface); |
1057 | } | |
1058 | ||
6dd67645 VA |
1059 | /* Prefix dev_id to widget control_name */ |
1060 | strlcpy(temp_name, w->name, NAME_SIZE); | |
1061 | snprintf(w->name, NAME_SIZE, "GB %d %s", module->dev_id, temp_name); | |
1062 | ||
6339d232 VA |
1063 | switch (w->type) { |
1064 | case snd_soc_dapm_spk: | |
1065 | *dw = (struct snd_soc_dapm_widget) | |
1066 | SND_SOC_DAPM_SPK(w->name, gbcodec_event_spk); | |
89de9a06 | 1067 | module->op_devices |= GBAUDIO_DEVICE_OUT_SPEAKER; |
6339d232 VA |
1068 | break; |
1069 | case snd_soc_dapm_hp: | |
1070 | *dw = (struct snd_soc_dapm_widget) | |
1071 | SND_SOC_DAPM_HP(w->name, gbcodec_event_hp); | |
89de9a06 VA |
1072 | module->op_devices |= (GBAUDIO_DEVICE_OUT_WIRED_HEADSET |
1073 | | GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE); | |
1074 | module->ip_devices |= GBAUDIO_DEVICE_IN_WIRED_HEADSET; | |
6339d232 VA |
1075 | break; |
1076 | case snd_soc_dapm_mic: | |
1077 | *dw = (struct snd_soc_dapm_widget) | |
1078 | SND_SOC_DAPM_MIC(w->name, gbcodec_event_int_mic); | |
89de9a06 | 1079 | module->ip_devices |= GBAUDIO_DEVICE_IN_BUILTIN_MIC; |
6339d232 VA |
1080 | break; |
1081 | case snd_soc_dapm_output: | |
1082 | *dw = (struct snd_soc_dapm_widget)SND_SOC_DAPM_OUTPUT(w->name); | |
1083 | break; | |
1084 | case snd_soc_dapm_input: | |
1085 | *dw = (struct snd_soc_dapm_widget)SND_SOC_DAPM_INPUT(w->name); | |
1086 | break; | |
1087 | case snd_soc_dapm_switch: | |
1088 | *dw = (struct snd_soc_dapm_widget) | |
1089 | SND_SOC_DAPM_SWITCH_E(w->name, SND_SOC_NOPM, 0, 0, | |
1090 | widget_kctls, gbaudio_widget_event, | |
1091 | SND_SOC_DAPM_PRE_PMU | | |
1092 | SND_SOC_DAPM_POST_PMD); | |
1093 | break; | |
1094 | case snd_soc_dapm_pga: | |
1095 | *dw = (struct snd_soc_dapm_widget) | |
1096 | SND_SOC_DAPM_PGA_E(w->name, SND_SOC_NOPM, 0, 0, NULL, 0, | |
1097 | gbaudio_widget_event, | |
1098 | SND_SOC_DAPM_PRE_PMU | | |
1099 | SND_SOC_DAPM_POST_PMD); | |
1100 | break; | |
1101 | case snd_soc_dapm_mixer: | |
1102 | *dw = (struct snd_soc_dapm_widget) | |
1103 | SND_SOC_DAPM_MIXER_E(w->name, SND_SOC_NOPM, 0, 0, NULL, | |
1104 | 0, gbaudio_widget_event, | |
1105 | SND_SOC_DAPM_PRE_PMU | | |
1106 | SND_SOC_DAPM_POST_PMD); | |
1107 | break; | |
1108 | case snd_soc_dapm_mux: | |
1109 | *dw = (struct snd_soc_dapm_widget) | |
1110 | SND_SOC_DAPM_MUX_E(w->name, SND_SOC_NOPM, 0, 0, | |
1111 | widget_kctls, gbaudio_widget_event, | |
1112 | SND_SOC_DAPM_PRE_PMU | | |
1113 | SND_SOC_DAPM_POST_PMD); | |
1114 | break; | |
1115 | case snd_soc_dapm_aif_in: | |
1116 | *dw = (struct snd_soc_dapm_widget) | |
1117 | SND_SOC_DAPM_AIF_IN_E(w->name, w->sname, 0, | |
1118 | SND_SOC_NOPM, | |
1119 | 0, 0, gbaudio_widget_event, | |
1120 | SND_SOC_DAPM_PRE_PMU | | |
1121 | SND_SOC_DAPM_POST_PMD); | |
1122 | break; | |
1123 | case snd_soc_dapm_aif_out: | |
1124 | *dw = (struct snd_soc_dapm_widget) | |
1125 | SND_SOC_DAPM_AIF_OUT_E(w->name, w->sname, 0, | |
1126 | SND_SOC_NOPM, | |
1127 | 0, 0, gbaudio_widget_event, | |
1128 | SND_SOC_DAPM_PRE_PMU | | |
1129 | SND_SOC_DAPM_POST_PMD); | |
1130 | break; | |
1131 | default: | |
1132 | ret = -EINVAL; | |
1133 | goto error; | |
1134 | } | |
1135 | ||
6dd67645 | 1136 | dev_dbg(module->dev, "%s: widget of type %d created\n", dw->name, |
6339d232 VA |
1137 | dw->id); |
1138 | return 0; | |
1139 | error: | |
6dd67645 | 1140 | list_for_each_entry_safe(control, _control, &module->widget_ctl_list, |
6339d232 VA |
1141 | list) { |
1142 | list_del(&control->list); | |
6dd67645 | 1143 | devm_kfree(module->dev, control); |
6339d232 VA |
1144 | } |
1145 | return ret; | |
1146 | } | |
1147 | ||
6dd67645 | 1148 | static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module, |
6339d232 VA |
1149 | struct gb_audio_control *controls) |
1150 | { | |
d4cd9daa | 1151 | int i, csize, ret; |
6339d232 VA |
1152 | struct snd_kcontrol_new *dapm_kctls; |
1153 | struct gb_audio_control *curr; | |
1154 | struct gbaudio_control *control, *_control; | |
1155 | size_t size; | |
6dd67645 | 1156 | char temp_name[NAME_SIZE]; |
6339d232 | 1157 | |
6dd67645 VA |
1158 | size = sizeof(struct snd_kcontrol_new) * module->num_controls; |
1159 | dapm_kctls = devm_kzalloc(module->dev, size, GFP_KERNEL); | |
6339d232 VA |
1160 | if (!dapm_kctls) |
1161 | return -ENOMEM; | |
1162 | ||
1163 | curr = controls; | |
6dd67645 VA |
1164 | for (i = 0; i < module->num_controls; i++) { |
1165 | ret = gbaudio_tplg_create_kcontrol(module, &dapm_kctls[i], | |
6339d232 VA |
1166 | curr); |
1167 | if (ret) { | |
6dd67645 | 1168 | dev_err(module->dev, "%s:%d type not supported\n", |
6339d232 VA |
1169 | curr->name, curr->iface); |
1170 | goto error; | |
1171 | } | |
6dd67645 | 1172 | control = devm_kzalloc(module->dev, sizeof(struct |
6339d232 VA |
1173 | gbaudio_control), |
1174 | GFP_KERNEL); | |
1175 | if (!control) { | |
1176 | ret = -ENOMEM; | |
1177 | goto error; | |
1178 | } | |
1179 | control->id = curr->id; | |
6dd67645 VA |
1180 | /* Prefix dev_id to widget_name */ |
1181 | strlcpy(temp_name, curr->name, NAME_SIZE); | |
1182 | snprintf(curr->name, NAME_SIZE, "GB %d %s", module->dev_id, | |
1183 | temp_name); | |
6339d232 | 1184 | control->name = curr->name; |
e65579e3 VA |
1185 | if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) { |
1186 | struct gb_audio_enumerated *gbenum = | |
1187 | &curr->info.value.enumerated; | |
1188 | ||
1189 | csize = offsetof(struct gb_audio_control, info); | |
1190 | csize += offsetof(struct gb_audio_ctl_elem_info, value); | |
1191 | csize += offsetof(struct gb_audio_enumerated, names); | |
055fb9ce | 1192 | csize += le16_to_cpu(gbenum->names_length); |
6339d232 | 1193 | control->texts = (const char * const *) |
e65579e3 | 1194 | gb_generate_enum_strings(module, gbenum); |
055fb9ce | 1195 | control->items = le32_to_cpu(gbenum->items); |
02ae32f7 | 1196 | } else { |
e65579e3 | 1197 | csize = sizeof(struct gb_audio_control); |
02ae32f7 | 1198 | } |
d4cd9daa | 1199 | |
6dd67645 VA |
1200 | list_add(&control->list, &module->ctl_list); |
1201 | dev_dbg(module->dev, "%d:%s created of type %d\n", curr->id, | |
6339d232 | 1202 | curr->name, curr->info.type); |
d4cd9daa | 1203 | curr = (void *)curr + csize; |
6339d232 | 1204 | } |
6dd67645 | 1205 | module->controls = dapm_kctls; |
6339d232 VA |
1206 | |
1207 | return 0; | |
1208 | error: | |
6dd67645 | 1209 | list_for_each_entry_safe(control, _control, &module->ctl_list, |
6339d232 VA |
1210 | list) { |
1211 | list_del(&control->list); | |
6dd67645 | 1212 | devm_kfree(module->dev, control); |
6339d232 | 1213 | } |
6dd67645 | 1214 | devm_kfree(module->dev, dapm_kctls); |
6339d232 VA |
1215 | return ret; |
1216 | } | |
1217 | ||
6dd67645 | 1218 | static int gbaudio_tplg_process_widgets(struct gbaudio_module_info *module, |
6339d232 VA |
1219 | struct gb_audio_widget *widgets) |
1220 | { | |
d4cd9daa | 1221 | int i, ret, w_size; |
6339d232 VA |
1222 | struct snd_soc_dapm_widget *dapm_widgets; |
1223 | struct gb_audio_widget *curr; | |
1224 | struct gbaudio_widget *widget, *_widget; | |
1225 | size_t size; | |
1226 | ||
6dd67645 VA |
1227 | size = sizeof(struct snd_soc_dapm_widget) * module->num_dapm_widgets; |
1228 | dapm_widgets = devm_kzalloc(module->dev, size, GFP_KERNEL); | |
6339d232 VA |
1229 | if (!dapm_widgets) |
1230 | return -ENOMEM; | |
1231 | ||
1232 | curr = widgets; | |
6dd67645 VA |
1233 | for (i = 0; i < module->num_dapm_widgets; i++) { |
1234 | ret = gbaudio_tplg_create_widget(module, &dapm_widgets[i], | |
d4cd9daa | 1235 | curr, &w_size); |
6339d232 | 1236 | if (ret) { |
6dd67645 | 1237 | dev_err(module->dev, "%s:%d type not supported\n", |
6339d232 VA |
1238 | curr->name, curr->type); |
1239 | goto error; | |
1240 | } | |
6dd67645 | 1241 | widget = devm_kzalloc(module->dev, sizeof(struct |
6339d232 VA |
1242 | gbaudio_widget), |
1243 | GFP_KERNEL); | |
1244 | if (!widget) { | |
1245 | ret = -ENOMEM; | |
1246 | goto error; | |
1247 | } | |
1248 | widget->id = curr->id; | |
1249 | widget->name = curr->name; | |
6dd67645 | 1250 | list_add(&widget->list, &module->widget_list); |
d4cd9daa | 1251 | curr = (void *)curr + w_size; |
6339d232 | 1252 | } |
6dd67645 | 1253 | module->dapm_widgets = dapm_widgets; |
6339d232 VA |
1254 | |
1255 | return 0; | |
1256 | ||
1257 | error: | |
6dd67645 | 1258 | list_for_each_entry_safe(widget, _widget, &module->widget_list, |
6339d232 VA |
1259 | list) { |
1260 | list_del(&widget->list); | |
6dd67645 | 1261 | devm_kfree(module->dev, widget); |
6339d232 | 1262 | } |
6dd67645 | 1263 | devm_kfree(module->dev, dapm_widgets); |
6339d232 VA |
1264 | return ret; |
1265 | } | |
1266 | ||
6dd67645 | 1267 | static int gbaudio_tplg_process_routes(struct gbaudio_module_info *module, |
6339d232 VA |
1268 | struct gb_audio_route *routes) |
1269 | { | |
1270 | int i, ret; | |
1271 | struct snd_soc_dapm_route *dapm_routes; | |
1272 | struct gb_audio_route *curr; | |
1273 | size_t size; | |
1274 | ||
6dd67645 VA |
1275 | size = sizeof(struct snd_soc_dapm_route) * module->num_dapm_routes; |
1276 | dapm_routes = devm_kzalloc(module->dev, size, GFP_KERNEL); | |
6339d232 VA |
1277 | if (!dapm_routes) |
1278 | return -ENOMEM; | |
1279 | ||
6dd67645 | 1280 | module->dapm_routes = dapm_routes; |
6339d232 VA |
1281 | curr = routes; |
1282 | ||
6dd67645 | 1283 | for (i = 0; i < module->num_dapm_routes; i++) { |
6339d232 | 1284 | dapm_routes->sink = |
6dd67645 | 1285 | gbaudio_map_widgetid(module, curr->destination_id); |
6339d232 | 1286 | if (!dapm_routes->sink) { |
6dd67645 | 1287 | dev_err(module->dev, "%d:%d:%d:%d - Invalid sink\n", |
6339d232 VA |
1288 | curr->source_id, curr->destination_id, |
1289 | curr->control_id, curr->index); | |
1290 | ret = -EINVAL; | |
1291 | goto error; | |
1292 | } | |
1293 | dapm_routes->source = | |
6dd67645 | 1294 | gbaudio_map_widgetid(module, curr->source_id); |
6339d232 | 1295 | if (!dapm_routes->source) { |
6dd67645 | 1296 | dev_err(module->dev, "%d:%d:%d:%d - Invalid source\n", |
6339d232 VA |
1297 | curr->source_id, curr->destination_id, |
1298 | curr->control_id, curr->index); | |
1299 | ret = -EINVAL; | |
1300 | goto error; | |
1301 | } | |
1302 | dapm_routes->control = | |
6dd67645 | 1303 | gbaudio_map_controlid(module, |
6339d232 VA |
1304 | curr->control_id, |
1305 | curr->index); | |
1306 | if ((curr->control_id != GBAUDIO_INVALID_ID) && | |
1307 | !dapm_routes->control) { | |
6dd67645 | 1308 | dev_err(module->dev, "%d:%d:%d:%d - Invalid control\n", |
6339d232 VA |
1309 | curr->source_id, curr->destination_id, |
1310 | curr->control_id, curr->index); | |
1311 | ret = -EINVAL; | |
1312 | goto error; | |
1313 | } | |
6dd67645 | 1314 | dev_dbg(module->dev, "Route {%s, %s, %s}\n", dapm_routes->sink, |
8a983614 | 1315 | (dapm_routes->control) ? dapm_routes->control : "NULL", |
6339d232 VA |
1316 | dapm_routes->source); |
1317 | dapm_routes++; | |
1318 | curr++; | |
1319 | } | |
1320 | ||
1321 | return 0; | |
1322 | ||
1323 | error: | |
6198f892 | 1324 | devm_kfree(module->dev, module->dapm_routes); |
6339d232 VA |
1325 | return ret; |
1326 | } | |
1327 | ||
6dd67645 | 1328 | static int gbaudio_tplg_process_header(struct gbaudio_module_info *module, |
6339d232 VA |
1329 | struct gb_audio_topology *tplg_data) |
1330 | { | |
1331 | /* fetch no. of kcontrols, widgets & routes */ | |
6dd67645 VA |
1332 | module->num_controls = tplg_data->num_controls; |
1333 | module->num_dapm_widgets = tplg_data->num_widgets; | |
1334 | module->num_dapm_routes = tplg_data->num_routes; | |
6339d232 VA |
1335 | |
1336 | /* update block offset */ | |
6dd67645 | 1337 | module->dai_offset = (unsigned long)&tplg_data->data; |
055fb9ce VA |
1338 | module->control_offset = module->dai_offset + |
1339 | le32_to_cpu(tplg_data->size_dais); | |
6dd67645 | 1340 | module->widget_offset = module->control_offset + |
055fb9ce | 1341 | le32_to_cpu(tplg_data->size_controls); |
6dd67645 | 1342 | module->route_offset = module->widget_offset + |
055fb9ce | 1343 | le32_to_cpu(tplg_data->size_widgets); |
6339d232 | 1344 | |
6dd67645 VA |
1345 | dev_dbg(module->dev, "DAI offset is 0x%lx\n", module->dai_offset); |
1346 | dev_dbg(module->dev, "control offset is %lx\n", | |
1347 | module->control_offset); | |
1348 | dev_dbg(module->dev, "widget offset is %lx\n", module->widget_offset); | |
1349 | dev_dbg(module->dev, "route offset is %lx\n", module->route_offset); | |
6339d232 VA |
1350 | |
1351 | return 0; | |
1352 | } | |
1353 | ||
6dd67645 | 1354 | int gbaudio_tplg_parse_data(struct gbaudio_module_info *module, |
6339d232 VA |
1355 | struct gb_audio_topology *tplg_data) |
1356 | { | |
1357 | int ret; | |
6339d232 VA |
1358 | struct gb_audio_control *controls; |
1359 | struct gb_audio_widget *widgets; | |
1360 | struct gb_audio_route *routes; | |
055fb9ce | 1361 | unsigned int jack_type; |
6339d232 VA |
1362 | |
1363 | if (!tplg_data) | |
1364 | return -EINVAL; | |
1365 | ||
6dd67645 | 1366 | ret = gbaudio_tplg_process_header(module, tplg_data); |
6339d232 | 1367 | if (ret) { |
6dd67645 | 1368 | dev_err(module->dev, "%d: Error in parsing topology header\n", |
6339d232 VA |
1369 | ret); |
1370 | return ret; | |
1371 | } | |
1372 | ||
1373 | /* process control */ | |
6dd67645 VA |
1374 | controls = (struct gb_audio_control *)module->control_offset; |
1375 | ret = gbaudio_tplg_process_kcontrols(module, controls); | |
6339d232 | 1376 | if (ret) { |
6dd67645 | 1377 | dev_err(module->dev, |
6339d232 VA |
1378 | "%d: Error in parsing controls data\n", ret); |
1379 | return ret; | |
1380 | } | |
6dd67645 | 1381 | dev_dbg(module->dev, "Control parsing finished\n"); |
6339d232 VA |
1382 | |
1383 | /* process widgets */ | |
6dd67645 VA |
1384 | widgets = (struct gb_audio_widget *)module->widget_offset; |
1385 | ret = gbaudio_tplg_process_widgets(module, widgets); | |
6339d232 | 1386 | if (ret) { |
6dd67645 | 1387 | dev_err(module->dev, |
6339d232 VA |
1388 | "%d: Error in parsing widgets data\n", ret); |
1389 | return ret; | |
1390 | } | |
6dd67645 | 1391 | dev_dbg(module->dev, "Widget parsing finished\n"); |
6339d232 VA |
1392 | |
1393 | /* process route */ | |
6dd67645 VA |
1394 | routes = (struct gb_audio_route *)module->route_offset; |
1395 | ret = gbaudio_tplg_process_routes(module, routes); | |
6339d232 | 1396 | if (ret) { |
6dd67645 | 1397 | dev_err(module->dev, |
6339d232 VA |
1398 | "%d: Error in parsing routes data\n", ret); |
1399 | return ret; | |
1400 | } | |
6dd67645 | 1401 | dev_dbg(module->dev, "Route parsing finished\n"); |
6339d232 | 1402 | |
847175e8 | 1403 | /* parse jack capabilities */ |
055fb9ce VA |
1404 | jack_type = le32_to_cpu(tplg_data->jack_type); |
1405 | if (jack_type) { | |
1406 | module->jack_mask = jack_type & GBCODEC_JACK_MASK; | |
1407 | module->button_mask = jack_type & GBCODEC_JACK_BUTTON_MASK; | |
847175e8 VA |
1408 | } |
1409 | ||
6339d232 VA |
1410 | return ret; |
1411 | } | |
1412 | ||
6dd67645 | 1413 | void gbaudio_tplg_release(struct gbaudio_module_info *module) |
6339d232 | 1414 | { |
6339d232 VA |
1415 | struct gbaudio_control *control, *_control; |
1416 | struct gbaudio_widget *widget, *_widget; | |
1417 | ||
6dd67645 | 1418 | if (!module->topology) |
6339d232 VA |
1419 | return; |
1420 | ||
1421 | /* release kcontrols */ | |
6dd67645 | 1422 | list_for_each_entry_safe(control, _control, &module->ctl_list, |
6339d232 VA |
1423 | list) { |
1424 | list_del(&control->list); | |
6dd67645 | 1425 | devm_kfree(module->dev, control); |
6339d232 | 1426 | } |
6dd67645 VA |
1427 | if (module->controls) |
1428 | devm_kfree(module->dev, module->controls); | |
6339d232 VA |
1429 | |
1430 | /* release widget controls */ | |
6dd67645 | 1431 | list_for_each_entry_safe(control, _control, &module->widget_ctl_list, |
6339d232 VA |
1432 | list) { |
1433 | list_del(&control->list); | |
6dd67645 | 1434 | devm_kfree(module->dev, control); |
6339d232 VA |
1435 | } |
1436 | ||
1437 | /* release widgets */ | |
6dd67645 | 1438 | list_for_each_entry_safe(widget, _widget, &module->widget_list, |
6339d232 VA |
1439 | list) { |
1440 | list_del(&widget->list); | |
6dd67645 | 1441 | devm_kfree(module->dev, widget); |
6339d232 | 1442 | } |
6dd67645 VA |
1443 | if (module->dapm_widgets) |
1444 | devm_kfree(module->dev, module->dapm_widgets); | |
6339d232 VA |
1445 | |
1446 | /* release routes */ | |
6dd67645 VA |
1447 | if (module->dapm_routes) |
1448 | devm_kfree(module->dev, module->dapm_routes); | |
6339d232 | 1449 | } |