3 * Copyright 2015-2016 Google Inc.
4 * Copyright 2015-2016 Linaro Ltd.
6 * Released under the GPLv2 only.
9 #include "audio_codec.h"
10 #include "greybus_protocols.h"
12 #define GBAUDIO_INVALID_ID 0xFF
15 struct gb_mixer_control
{
17 unsigned int reg
, rreg
, shift
, rshift
, invert
;
20 struct gbaudio_ctl_pvt
{
22 unsigned int data_cport
;
25 struct gb_audio_ctl_elem_info
*info
;
28 static struct gbaudio_module_info
*find_gb_module(
29 struct gbaudio_codec_info
*codec
,
33 char begin
[NAME_SIZE
];
34 struct gbaudio_module_info
*module
;
39 ret
= sscanf(name
, "%s %d", begin
, &dev_id
);
40 dev_dbg(codec
->dev
, "%s:Find module#%d\n", __func__
, dev_id
);
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
);
49 mutex_unlock(&codec
->lock
);
50 dev_warn(codec
->dev
, "%s: module#%d missing in codec list\n", name
,
55 static const char *gbaudio_map_controlid(struct gbaudio_module_info
*module
,
56 __u8 control_id
, __u8 index
)
58 struct gbaudio_control
*control
;
60 if (control_id
== GBAUDIO_INVALID_ID
)
63 list_for_each_entry(control
, &module
->ctl_list
, list
) {
64 if (control
->id
== control_id
) {
65 if (index
== GBAUDIO_INVALID_ID
)
67 if (index
>= control
->items
)
69 return control
->texts
[index
];
72 list_for_each_entry(control
, &module
->widget_ctl_list
, list
) {
73 if (control
->id
== control_id
) {
74 if (index
== GBAUDIO_INVALID_ID
)
76 if (index
>= control
->items
)
78 return control
->texts
[index
];
84 static int gbaudio_map_controlname(struct gbaudio_module_info
*module
,
87 struct gbaudio_control
*control
;
89 list_for_each_entry(control
, &module
->ctl_list
, list
) {
90 if (!strncmp(control
->name
, name
, NAME_SIZE
))
94 dev_warn(module
->dev
, "%s: missing in modules controls list\n", name
);
99 static int gbaudio_map_wcontrolname(struct gbaudio_module_info
*module
,
102 struct gbaudio_control
*control
;
104 list_for_each_entry(control
, &module
->widget_ctl_list
, list
) {
105 if (!strncmp(control
->wname
, name
, NAME_SIZE
))
108 dev_warn(module
->dev
, "%s: missing in modules controls list\n", name
);
113 static int gbaudio_map_widgetname(struct gbaudio_module_info
*module
,
116 struct gbaudio_widget
*widget
;
118 list_for_each_entry(widget
, &module
->widget_list
, list
) {
119 if (!strncmp(widget
->name
, name
, NAME_SIZE
))
122 dev_warn(module
->dev
, "%s: missing in modules widgets list\n", name
);
127 static const char *gbaudio_map_widgetid(struct gbaudio_module_info
*module
,
130 struct gbaudio_widget
*widget
;
132 list_for_each_entry(widget
, &module
->widget_list
, list
) {
133 if (widget
->id
== widget_id
)
139 static const char **gb_generate_enum_strings(struct gbaudio_module_info
*gb
,
140 struct gb_audio_enumerated
*gbenum
)
142 const char **strings
;
146 strings
= devm_kzalloc(gb
->dev
, sizeof(char *) * gbenum
->items
,
148 data
= gbenum
->names
;
150 for (i
= 0; i
< gbenum
->items
; i
++) {
151 strings
[i
] = (const char *)data
;
152 while (*data
!= '\0')
160 static int gbcodec_mixer_ctl_info(struct snd_kcontrol
*kcontrol
,
161 struct snd_ctl_elem_info
*uinfo
)
165 struct gbaudio_ctl_pvt
*data
;
166 struct gb_audio_ctl_elem_info
*info
;
167 struct gbaudio_module_info
*module
;
168 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
169 struct gbaudio_codec_info
*gbcodec
= snd_soc_codec_get_drvdata(codec
);
171 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
172 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
173 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
176 dev_err(codec
->dev
, "NULL info for %s\n", uinfo
->id
.name
);
181 uinfo
->access
= data
->access
;
182 uinfo
->count
= data
->vcount
;
183 uinfo
->type
= (snd_ctl_elem_type_t
)info
->type
;
185 switch (info
->type
) {
186 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN
:
187 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER
:
188 uinfo
->value
.integer
.min
= info
->value
.integer
.min
;
189 uinfo
->value
.integer
.max
= info
->value
.integer
.max
;
191 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
:
192 max
= info
->value
.enumerated
.items
;
193 uinfo
->value
.enumerated
.items
= max
;
194 if (uinfo
->value
.enumerated
.item
> max
- 1)
195 uinfo
->value
.enumerated
.item
= max
- 1;
196 module
= find_gb_module(gbcodec
, kcontrol
->id
.name
);
199 name
= gbaudio_map_controlid(module
, data
->ctl_id
,
200 uinfo
->value
.enumerated
.item
);
201 strlcpy(uinfo
->value
.enumerated
.name
, name
, NAME_SIZE
);
204 dev_err(codec
->dev
, "Invalid type: %d for %s:kcontrol\n",
205 info
->type
, kcontrol
->id
.name
);
211 static int gbcodec_mixer_ctl_get(struct snd_kcontrol
*kcontrol
,
212 struct snd_ctl_elem_value
*ucontrol
)
215 struct gb_audio_ctl_elem_info
*info
;
216 struct gbaudio_ctl_pvt
*data
;
217 struct gb_audio_ctl_elem_value gbvalue
;
218 struct gbaudio_module_info
*module
;
219 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
220 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
221 struct gb_bundle
*bundle
;
223 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
224 module
= find_gb_module(gb
, kcontrol
->id
.name
);
228 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
229 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
230 bundle
= to_gb_bundle(module
->dev
);
232 ret
= gb_pm_runtime_get_sync(bundle
);
236 ret
= gb_audio_gb_get_control(module
->mgmt_connection
, data
->ctl_id
,
237 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
239 gb_pm_runtime_put_autosuspend(bundle
);
242 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
243 __func__
, kcontrol
->id
.name
);
247 /* update ucontrol */
248 switch (info
->type
) {
249 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN
:
250 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER
:
251 ucontrol
->value
.integer
.value
[0] =
252 gbvalue
.value
.integer_value
[0];
253 if (data
->vcount
== 2)
254 ucontrol
->value
.integer
.value
[1] =
255 gbvalue
.value
.integer_value
[1];
257 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
:
258 ucontrol
->value
.enumerated
.item
[0] =
259 gbvalue
.value
.enumerated_item
[0];
260 if (data
->vcount
== 2)
261 ucontrol
->value
.enumerated
.item
[1] =
262 gbvalue
.value
.enumerated_item
[1];
265 dev_err(codec
->dev
, "Invalid type: %d for %s:kcontrol\n",
266 info
->type
, kcontrol
->id
.name
);
273 static int gbcodec_mixer_ctl_put(struct snd_kcontrol
*kcontrol
,
274 struct snd_ctl_elem_value
*ucontrol
)
277 struct gb_audio_ctl_elem_info
*info
;
278 struct gbaudio_ctl_pvt
*data
;
279 struct gb_audio_ctl_elem_value gbvalue
;
280 struct gbaudio_module_info
*module
;
281 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
282 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
283 struct gb_bundle
*bundle
;
285 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
286 module
= find_gb_module(gb
, kcontrol
->id
.name
);
290 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
291 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
292 bundle
= to_gb_bundle(module
->dev
);
294 /* update ucontrol */
295 switch (info
->type
) {
296 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN
:
297 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER
:
298 gbvalue
.value
.integer_value
[0] =
299 ucontrol
->value
.integer
.value
[0];
300 if (data
->vcount
== 2)
301 gbvalue
.value
.integer_value
[1] =
302 ucontrol
->value
.integer
.value
[1];
304 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
:
305 gbvalue
.value
.enumerated_item
[0] =
306 ucontrol
->value
.enumerated
.item
[0];
307 if (data
->vcount
== 2)
308 gbvalue
.value
.enumerated_item
[1] =
309 ucontrol
->value
.enumerated
.item
[1];
312 dev_err(codec
->dev
, "Invalid type: %d for %s:kcontrol\n",
313 info
->type
, kcontrol
->id
.name
);
321 ret
= gb_pm_runtime_get_sync(bundle
);
325 ret
= gb_audio_gb_set_control(module
->mgmt_connection
, data
->ctl_id
,
326 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
328 gb_pm_runtime_put_autosuspend(bundle
);
331 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
332 __func__
, kcontrol
->id
.name
);
338 #define SOC_MIXER_GB(xname, kcount, data) \
339 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
340 .count = kcount, .info = gbcodec_mixer_ctl_info, \
341 .get = gbcodec_mixer_ctl_get, .put = gbcodec_mixer_ctl_put, \
342 .private_value = (unsigned long)data }
345 * although below callback functions seems redundant to above functions.
346 * same are kept to allow provision for different handling in case
347 * of DAPM related sequencing, etc.
349 static int gbcodec_mixer_dapm_ctl_info(struct snd_kcontrol
*kcontrol
,
350 struct snd_ctl_elem_info
*uinfo
)
352 int platform_max
, platform_min
;
353 struct gbaudio_ctl_pvt
*data
;
354 struct gb_audio_ctl_elem_info
*info
;
355 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
356 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
357 struct snd_soc_codec
*codec
= widget
->codec
;
359 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
360 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
361 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
364 platform_max
= info
->value
.integer
.max
;
365 platform_min
= info
->value
.integer
.min
;
367 if (platform_max
== 1 &&
368 !strnstr(kcontrol
->id
.name
, " Volume", NAME_SIZE
))
369 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
371 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
373 uinfo
->count
= data
->vcount
;
374 uinfo
->value
.integer
.min
= 0;
375 if (info
->value
.integer
.min
< 0 &&
376 (uinfo
->type
== SNDRV_CTL_ELEM_TYPE_INTEGER
))
377 uinfo
->value
.integer
.max
= platform_max
- platform_min
;
379 uinfo
->value
.integer
.max
= platform_max
;
384 static int gbcodec_mixer_dapm_ctl_get(struct snd_kcontrol
*kcontrol
,
385 struct snd_ctl_elem_value
*ucontrol
)
388 struct gb_audio_ctl_elem_info
*info
;
389 struct gbaudio_ctl_pvt
*data
;
390 struct gb_audio_ctl_elem_value gbvalue
;
391 struct gbaudio_module_info
*module
;
392 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
393 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
394 struct snd_soc_codec
*codec
= widget
->codec
;
395 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
396 struct gb_bundle
*bundle
;
398 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
399 module
= find_gb_module(gb
, kcontrol
->id
.name
);
403 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
404 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
405 bundle
= to_gb_bundle(module
->dev
);
407 if (data
->vcount
== 2)
408 dev_warn(widget
->dapm
->dev
,
409 "GB: Control '%s' is stereo, which is not supported\n",
412 ret
= gb_pm_runtime_get_sync(bundle
);
416 ret
= gb_audio_gb_get_control(module
->mgmt_connection
, data
->ctl_id
,
417 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
419 gb_pm_runtime_put_autosuspend(bundle
);
422 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
423 __func__
, kcontrol
->id
.name
);
426 /* update ucontrol */
427 ucontrol
->value
.integer
.value
[0] = gbvalue
.value
.integer_value
[0];
432 static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol
*kcontrol
,
433 struct snd_ctl_elem_value
*ucontrol
)
435 int ret
, wi
, max
, connect
;
436 unsigned int mask
, val
;
437 struct gb_audio_ctl_elem_info
*info
;
438 struct gbaudio_ctl_pvt
*data
;
439 struct gb_audio_ctl_elem_value gbvalue
;
440 struct gbaudio_module_info
*module
;
441 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
442 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
443 struct snd_soc_codec
*codec
= widget
->codec
;
444 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
445 struct gb_bundle
*bundle
;
447 dev_dbg(codec
->dev
, "Entered %s:%s\n", __func__
, kcontrol
->id
.name
);
448 module
= find_gb_module(gb
, kcontrol
->id
.name
);
452 data
= (struct gbaudio_ctl_pvt
*)kcontrol
->private_value
;
453 info
= (struct gb_audio_ctl_elem_info
*)data
->info
;
454 bundle
= to_gb_bundle(module
->dev
);
456 if (data
->vcount
== 2)
457 dev_warn(widget
->dapm
->dev
,
458 "GB: Control '%s' is stereo, which is not supported\n",
461 max
= info
->value
.integer
.max
;
462 mask
= (1 << fls(max
)) - 1;
463 val
= ucontrol
->value
.integer
.value
[0] & mask
;
466 /* update ucontrol */
467 if (gbvalue
.value
.integer_value
[0] != val
) {
468 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
469 widget
= wlist
->widgets
[wi
];
472 widget
->dapm
->update
= NULL
;
473 snd_soc_dapm_mixer_update_power(widget
, kcontrol
,
476 gbvalue
.value
.integer_value
[0] =
477 ucontrol
->value
.integer
.value
[0];
479 ret
= gb_pm_runtime_get_sync(bundle
);
483 ret
= gb_audio_gb_set_control(module
->mgmt_connection
,
485 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
487 gb_pm_runtime_put_autosuspend(bundle
);
490 dev_err_ratelimited(codec
->dev
,
491 "%d:Error in %s for %s\n", ret
,
492 __func__
, kcontrol
->id
.name
);
500 #define SOC_DAPM_MIXER_GB(xname, kcount, data) \
501 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
502 .count = kcount, .info = gbcodec_mixer_dapm_ctl_info, \
503 .get = gbcodec_mixer_dapm_ctl_get, .put = gbcodec_mixer_dapm_ctl_put, \
504 .private_value = (unsigned long)data}
506 static int gbcodec_event_spk(struct snd_soc_dapm_widget
*w
,
507 struct snd_kcontrol
*k
, int event
)
509 /* Ensure GB speaker is connected */
514 static int gbcodec_event_hp(struct snd_soc_dapm_widget
*w
,
515 struct snd_kcontrol
*k
, int event
)
517 /* Ensure GB module supports jack slot */
522 static int gbcodec_event_int_mic(struct snd_soc_dapm_widget
*w
,
523 struct snd_kcontrol
*k
, int event
)
525 /* Ensure GB module supports jack slot */
530 static int gbaudio_validate_kcontrol_count(struct gb_audio_widget
*w
)
535 case snd_soc_dapm_spk
:
536 case snd_soc_dapm_hp
:
537 case snd_soc_dapm_mic
:
538 case snd_soc_dapm_output
:
539 case snd_soc_dapm_input
:
543 case snd_soc_dapm_switch
:
544 case snd_soc_dapm_mux
:
545 if (w
->ncontrols
!= 1)
555 static int gbcodec_enum_ctl_get(struct snd_kcontrol
*kcontrol
,
556 struct snd_ctl_elem_value
*ucontrol
)
559 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
560 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
561 struct gb_audio_ctl_elem_value gbvalue
;
562 struct gbaudio_module_info
*module
;
563 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
564 struct gb_bundle
*bundle
;
566 module
= find_gb_module(gb
, kcontrol
->id
.name
);
570 ctl_id
= gbaudio_map_controlname(module
, kcontrol
->id
.name
);
574 bundle
= to_gb_bundle(module
->dev
);
576 ret
= gb_pm_runtime_get_sync(bundle
);
580 ret
= gb_audio_gb_get_control(module
->mgmt_connection
, ctl_id
,
581 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
583 gb_pm_runtime_put_autosuspend(bundle
);
586 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
587 __func__
, kcontrol
->id
.name
);
591 ucontrol
->value
.enumerated
.item
[0] = gbvalue
.value
.enumerated_item
[0];
592 if (e
->shift_l
!= e
->shift_r
)
593 ucontrol
->value
.enumerated
.item
[1] =
594 gbvalue
.value
.enumerated_item
[1];
599 static int gbcodec_enum_ctl_put(struct snd_kcontrol
*kcontrol
,
600 struct snd_ctl_elem_value
*ucontrol
)
603 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
604 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
605 struct gb_audio_ctl_elem_value gbvalue
;
606 struct gbaudio_module_info
*module
;
607 struct gbaudio_codec_info
*gb
= snd_soc_codec_get_drvdata(codec
);
608 struct gb_bundle
*bundle
;
610 module
= find_gb_module(gb
, kcontrol
->id
.name
);
614 ctl_id
= gbaudio_map_controlname(module
, kcontrol
->id
.name
);
618 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
620 gbvalue
.value
.enumerated_item
[0] = ucontrol
->value
.enumerated
.item
[0];
622 if (e
->shift_l
!= e
->shift_r
) {
623 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
625 gbvalue
.value
.enumerated_item
[1] =
626 ucontrol
->value
.enumerated
.item
[1];
629 bundle
= to_gb_bundle(module
->dev
);
631 ret
= gb_pm_runtime_get_sync(bundle
);
635 ret
= gb_audio_gb_set_control(module
->mgmt_connection
, ctl_id
,
636 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
638 gb_pm_runtime_put_autosuspend(bundle
);
641 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
642 __func__
, kcontrol
->id
.name
);
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
)
652 struct soc_enum
*gbe
;
653 struct gb_audio_enumerated
*gb_enum
;
656 gbe
= devm_kzalloc(gb
->dev
, sizeof(*gbe
), GFP_KERNEL
);
660 gb_enum
= &ctl
->info
.value
.enumerated
;
662 /* since count=1, and reg is dummy */
663 gbe
->max
= gb_enum
->items
;
664 gbe
->texts
= gb_generate_enum_strings(gb
, gb_enum
);
666 /* debug enum info */
667 dev_dbg(gb
->dev
, "Max:%d, name_length:%d\n", gb_enum
->items
,
668 gb_enum
->names_length
);
669 for (i
= 0; i
< gb_enum
->items
; i
++)
670 dev_dbg(gb
->dev
, "src[%d]: %s\n", i
, gbe
->texts
[i
]);
672 *kctl
= (struct snd_kcontrol_new
)
673 SOC_ENUM_EXT(ctl
->name
, *gbe
, gbcodec_enum_ctl_get
,
674 gbcodec_enum_ctl_put
);
678 static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info
*gb
,
679 struct snd_kcontrol_new
*kctl
,
680 struct gb_audio_control
*ctl
)
683 struct gbaudio_ctl_pvt
*ctldata
;
685 switch (ctl
->iface
) {
686 case SNDRV_CTL_ELEM_IFACE_MIXER
:
687 switch (ctl
->info
.type
) {
688 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
:
689 ret
= gbaudio_tplg_create_enum_kctl(gb
, kctl
, ctl
);
692 ctldata
= devm_kzalloc(gb
->dev
,
693 sizeof(struct gbaudio_ctl_pvt
),
697 ctldata
->ctl_id
= ctl
->id
;
698 ctldata
->data_cport
= ctl
->data_cport
;
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
);
712 dev_dbg(gb
->dev
, "%s:%d control created\n", ctl
->name
, ctl
->id
);
716 static int gbcodec_enum_dapm_ctl_get(struct snd_kcontrol
*kcontrol
,
717 struct snd_ctl_elem_value
*ucontrol
)
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
;
727 struct gb_bundle
*bundle
;
729 module
= find_gb_module(gb
, kcontrol
->id
.name
);
733 ctl_id
= gbaudio_map_wcontrolname(module
, kcontrol
->id
.name
);
737 bundle
= to_gb_bundle(module
->dev
);
739 ret
= gb_pm_runtime_get_sync(bundle
);
743 ret
= gb_audio_gb_get_control(module
->mgmt_connection
, ctl_id
,
744 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
746 gb_pm_runtime_put_autosuspend(bundle
);
749 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
750 __func__
, kcontrol
->id
.name
);
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];
762 static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol
*kcontrol
,
763 struct snd_ctl_elem_value
*ucontrol
)
766 unsigned int val
, mux
, change
;
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
;
775 struct gb_bundle
*bundle
;
777 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
780 module
= find_gb_module(gb
, kcontrol
->id
.name
);
784 ctl_id
= gbaudio_map_wcontrolname(module
, kcontrol
->id
.name
);
789 bundle
= to_gb_bundle(module
->dev
);
791 ret
= gb_pm_runtime_get_sync(bundle
);
795 ret
= gb_audio_gb_get_control(module
->mgmt_connection
, ctl_id
,
796 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
798 gb_pm_runtime_put_autosuspend(bundle
);
801 dev_err_ratelimited(codec
->dev
, "%d:Error in %s for %s\n", ret
,
802 __func__
, kcontrol
->id
.name
);
806 mux
= ucontrol
->value
.enumerated
.item
[0];
807 val
= mux
<< e
->shift_l
;
808 mask
= e
->mask
<< e
->shift_l
;
810 if (gbvalue
.value
.enumerated_item
[0] !=
811 ucontrol
->value
.enumerated
.item
[0]) {
813 gbvalue
.value
.enumerated_item
[0] =
814 ucontrol
->value
.enumerated
.item
[0];
817 if (e
->shift_l
!= e
->shift_r
) {
818 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
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]) {
825 gbvalue
.value
.enumerated_item
[1] =
826 ucontrol
->value
.enumerated
.item
[1];
831 ret
= gb_pm_runtime_get_sync(bundle
);
835 ret
= gb_audio_gb_set_control(module
->mgmt_connection
, ctl_id
,
836 GB_AUDIO_INVALID_INDEX
, &gbvalue
);
838 gb_pm_runtime_put_autosuspend(bundle
);
841 dev_err_ratelimited(codec
->dev
,
842 "%d:Error in %s for %s\n", ret
,
843 __func__
, kcontrol
->id
.name
);
845 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
846 widget
= wlist
->widgets
[wi
];
849 widget
->dapm
->update
= NULL
;
850 snd_soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
857 static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info
*gb
,
858 struct snd_kcontrol_new
*kctl
,
859 struct gb_audio_control
*ctl
)
861 struct soc_enum
*gbe
;
862 struct gb_audio_enumerated
*gb_enum
;
865 gbe
= devm_kzalloc(gb
->dev
, sizeof(*gbe
), GFP_KERNEL
);
869 gb_enum
= &ctl
->info
.value
.enumerated
;
871 /* since count=1, and reg is dummy */
872 gbe
->max
= gb_enum
->items
;
873 gbe
->texts
= gb_generate_enum_strings(gb
, gb_enum
);
875 /* debug enum info */
876 dev_dbg(gb
->dev
, "Max:%d, name_length:%d\n", gb_enum
->items
,
877 gb_enum
->names_length
);
878 for (i
= 0; i
< gb_enum
->items
; i
++)
879 dev_dbg(gb
->dev
, "src[%d]: %s\n", i
, gbe
->texts
[i
]);
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
);
887 static int gbaudio_tplg_create_mixer_ctl(struct gbaudio_module_info
*gb
,
888 struct snd_kcontrol_new
*kctl
,
889 struct gb_audio_control
*ctl
)
891 struct gbaudio_ctl_pvt
*ctldata
;
893 ctldata
= devm_kzalloc(gb
->dev
, sizeof(struct gbaudio_ctl_pvt
),
897 ctldata
->ctl_id
= ctl
->id
;
898 ctldata
->data_cport
= ctl
->data_cport
;
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
);
908 static int gbaudio_tplg_create_wcontrol(struct gbaudio_module_info
*gb
,
909 struct snd_kcontrol_new
*kctl
,
910 struct gb_audio_control
*ctl
)
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
);
921 ret
= gbaudio_tplg_create_mixer_ctl(gb
, kctl
, ctl
);
930 dev_dbg(gb
->dev
, "%s:%d DAPM control created, ret:%d\n", ctl
->name
,
935 static int gbaudio_widget_event(struct snd_soc_dapm_widget
*w
,
936 struct snd_kcontrol
*kcontrol
, int event
)
940 struct snd_soc_codec
*codec
= w
->codec
;
941 struct gbaudio_codec_info
*gbcodec
= snd_soc_codec_get_drvdata(codec
);
942 struct gbaudio_module_info
*module
;
943 struct gb_bundle
*bundle
;
945 dev_dbg(codec
->dev
, "%s %s %d\n", __func__
, w
->name
, event
);
947 /* Find relevant module */
948 module
= find_gb_module(gbcodec
, w
->name
);
952 /* map name to widget id */
953 wid
= gbaudio_map_widgetname(module
, w
->name
);
955 dev_err(codec
->dev
, "Invalid widget name:%s\n", w
->name
);
959 bundle
= to_gb_bundle(module
->dev
);
961 ret
= gb_pm_runtime_get_sync(bundle
);
966 case SND_SOC_DAPM_PRE_PMU
:
967 ret
= gb_audio_gb_enable_widget(module
->mgmt_connection
, wid
);
969 ret
= gbaudio_module_update(gbcodec
, w
, module
, 1);
971 case SND_SOC_DAPM_POST_PMD
:
972 ret
= gb_audio_gb_disable_widget(module
->mgmt_connection
, wid
);
974 ret
= gbaudio_module_update(gbcodec
, w
, module
, 0);
978 dev_err_ratelimited(codec
->dev
,
979 "%d: widget, event:%d failed:%d\n", wid
,
982 gb_pm_runtime_put_autosuspend(bundle
);
987 static int gbaudio_tplg_create_widget(struct gbaudio_module_info
*module
,
988 struct snd_soc_dapm_widget
*dw
,
989 struct gb_audio_widget
*w
, int *w_size
)
992 struct snd_kcontrol_new
*widget_kctls
;
993 struct gb_audio_control
*curr
;
994 struct gbaudio_control
*control
, *_control
;
996 char temp_name
[NAME_SIZE
];
998 ret
= gbaudio_validate_kcontrol_count(w
);
1000 dev_err(module
->dev
, "Inavlid kcontrol count=%d for %s\n",
1001 w
->ncontrols
, w
->name
);
1005 /* allocate memory for kcontrol */
1007 size
= sizeof(struct snd_kcontrol_new
) * w
->ncontrols
;
1008 widget_kctls
= devm_kzalloc(module
->dev
, size
, GFP_KERNEL
);
1013 *w_size
= sizeof(struct gb_audio_widget
);
1015 /* create relevant kcontrols */
1017 for (i
= 0; i
< w
->ncontrols
; i
++) {
1018 ret
= gbaudio_tplg_create_wcontrol(module
, &widget_kctls
[i
],
1021 dev_err(module
->dev
,
1022 "%s:%d type widget_ctl not supported\n",
1023 curr
->name
, curr
->iface
);
1026 control
= devm_kzalloc(module
->dev
,
1027 sizeof(struct gbaudio_control
),
1033 control
->id
= curr
->id
;
1034 control
->name
= curr
->name
;
1035 control
->wname
= w
->name
;
1037 if (curr
->info
.type
== GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
) {
1038 struct gb_audio_enumerated
*gbenum
=
1039 &curr
->info
.value
.enumerated
;
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
);
1044 csize
+= gbenum
->names_length
;
1045 control
->texts
= (const char * const *)
1046 gb_generate_enum_strings(module
, gbenum
);
1047 control
->items
= gbenum
->items
;
1049 csize
= sizeof(struct gb_audio_control
);
1053 curr
= (void *)curr
+ csize
;
1054 list_add(&control
->list
, &module
->widget_ctl_list
);
1055 dev_dbg(module
->dev
, "%s: control of type %d created\n",
1056 widget_kctls
[i
].name
, widget_kctls
[i
].iface
);
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
);
1064 case snd_soc_dapm_spk
:
1065 *dw
= (struct snd_soc_dapm_widget
)
1066 SND_SOC_DAPM_SPK(w
->name
, gbcodec_event_spk
);
1067 module
->op_devices
|= GBAUDIO_DEVICE_OUT_SPEAKER
;
1069 case snd_soc_dapm_hp
:
1070 *dw
= (struct snd_soc_dapm_widget
)
1071 SND_SOC_DAPM_HP(w
->name
, gbcodec_event_hp
);
1072 module
->op_devices
|= (GBAUDIO_DEVICE_OUT_WIRED_HEADSET
1073 | GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE
);
1074 module
->ip_devices
|= GBAUDIO_DEVICE_IN_WIRED_HEADSET
;
1076 case snd_soc_dapm_mic
:
1077 *dw
= (struct snd_soc_dapm_widget
)
1078 SND_SOC_DAPM_MIC(w
->name
, gbcodec_event_int_mic
);
1079 module
->ip_devices
|= GBAUDIO_DEVICE_IN_BUILTIN_MIC
;
1081 case snd_soc_dapm_output
:
1082 *dw
= (struct snd_soc_dapm_widget
)SND_SOC_DAPM_OUTPUT(w
->name
);
1084 case snd_soc_dapm_input
:
1085 *dw
= (struct snd_soc_dapm_widget
)SND_SOC_DAPM_INPUT(w
->name
);
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
);
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
);
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
);
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
);
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,
1119 0, 0, gbaudio_widget_event
,
1120 SND_SOC_DAPM_PRE_PMU
|
1121 SND_SOC_DAPM_POST_PMD
);
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,
1127 0, 0, gbaudio_widget_event
,
1128 SND_SOC_DAPM_PRE_PMU
|
1129 SND_SOC_DAPM_POST_PMD
);
1136 dev_dbg(module
->dev
, "%s: widget of type %d created\n", dw
->name
,
1140 list_for_each_entry_safe(control
, _control
, &module
->widget_ctl_list
,
1142 list_del(&control
->list
);
1143 devm_kfree(module
->dev
, control
);
1148 static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info
*module
,
1149 struct gb_audio_control
*controls
)
1152 struct snd_kcontrol_new
*dapm_kctls
;
1153 struct gb_audio_control
*curr
;
1154 struct gbaudio_control
*control
, *_control
;
1156 char temp_name
[NAME_SIZE
];
1158 size
= sizeof(struct snd_kcontrol_new
) * module
->num_controls
;
1159 dapm_kctls
= devm_kzalloc(module
->dev
, size
, GFP_KERNEL
);
1164 for (i
= 0; i
< module
->num_controls
; i
++) {
1165 ret
= gbaudio_tplg_create_kcontrol(module
, &dapm_kctls
[i
],
1168 dev_err(module
->dev
, "%s:%d type not supported\n",
1169 curr
->name
, curr
->iface
);
1172 control
= devm_kzalloc(module
->dev
, sizeof(struct
1179 control
->id
= curr
->id
;
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
,
1184 control
->name
= curr
->name
;
1185 if (curr
->info
.type
== GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED
) {
1186 struct gb_audio_enumerated
*gbenum
=
1187 &curr
->info
.value
.enumerated
;
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
);
1192 csize
+= gbenum
->names_length
;
1193 control
->texts
= (const char * const *)
1194 gb_generate_enum_strings(module
, gbenum
);
1195 control
->items
= gbenum
->items
;
1197 csize
= sizeof(struct gb_audio_control
);
1200 list_add(&control
->list
, &module
->ctl_list
);
1201 dev_dbg(module
->dev
, "%d:%s created of type %d\n", curr
->id
,
1202 curr
->name
, curr
->info
.type
);
1203 curr
= (void *)curr
+ csize
;
1205 module
->controls
= dapm_kctls
;
1209 list_for_each_entry_safe(control
, _control
, &module
->ctl_list
,
1211 list_del(&control
->list
);
1212 devm_kfree(module
->dev
, control
);
1214 devm_kfree(module
->dev
, dapm_kctls
);
1218 static int gbaudio_tplg_process_widgets(struct gbaudio_module_info
*module
,
1219 struct gb_audio_widget
*widgets
)
1222 struct snd_soc_dapm_widget
*dapm_widgets
;
1223 struct gb_audio_widget
*curr
;
1224 struct gbaudio_widget
*widget
, *_widget
;
1227 size
= sizeof(struct snd_soc_dapm_widget
) * module
->num_dapm_widgets
;
1228 dapm_widgets
= devm_kzalloc(module
->dev
, size
, GFP_KERNEL
);
1233 for (i
= 0; i
< module
->num_dapm_widgets
; i
++) {
1234 ret
= gbaudio_tplg_create_widget(module
, &dapm_widgets
[i
],
1237 dev_err(module
->dev
, "%s:%d type not supported\n",
1238 curr
->name
, curr
->type
);
1241 widget
= devm_kzalloc(module
->dev
, sizeof(struct
1248 widget
->id
= curr
->id
;
1249 widget
->name
= curr
->name
;
1250 list_add(&widget
->list
, &module
->widget_list
);
1251 curr
= (void *)curr
+ w_size
;
1253 module
->dapm_widgets
= dapm_widgets
;
1258 list_for_each_entry_safe(widget
, _widget
, &module
->widget_list
,
1260 list_del(&widget
->list
);
1261 devm_kfree(module
->dev
, widget
);
1263 devm_kfree(module
->dev
, dapm_widgets
);
1267 static int gbaudio_tplg_process_routes(struct gbaudio_module_info
*module
,
1268 struct gb_audio_route
*routes
)
1271 struct snd_soc_dapm_route
*dapm_routes
;
1272 struct gb_audio_route
*curr
;
1275 size
= sizeof(struct snd_soc_dapm_route
) * module
->num_dapm_routes
;
1276 dapm_routes
= devm_kzalloc(module
->dev
, size
, GFP_KERNEL
);
1280 module
->dapm_routes
= dapm_routes
;
1283 for (i
= 0; i
< module
->num_dapm_routes
; i
++) {
1285 gbaudio_map_widgetid(module
, curr
->destination_id
);
1286 if (!dapm_routes
->sink
) {
1287 dev_err(module
->dev
, "%d:%d:%d:%d - Invalid sink\n",
1288 curr
->source_id
, curr
->destination_id
,
1289 curr
->control_id
, curr
->index
);
1293 dapm_routes
->source
=
1294 gbaudio_map_widgetid(module
, curr
->source_id
);
1295 if (!dapm_routes
->source
) {
1296 dev_err(module
->dev
, "%d:%d:%d:%d - Invalid source\n",
1297 curr
->source_id
, curr
->destination_id
,
1298 curr
->control_id
, curr
->index
);
1302 dapm_routes
->control
=
1303 gbaudio_map_controlid(module
,
1306 if ((curr
->control_id
!= GBAUDIO_INVALID_ID
) &&
1307 !dapm_routes
->control
) {
1308 dev_err(module
->dev
, "%d:%d:%d:%d - Invalid control\n",
1309 curr
->source_id
, curr
->destination_id
,
1310 curr
->control_id
, curr
->index
);
1314 dev_dbg(module
->dev
, "Route {%s, %s, %s}\n", dapm_routes
->sink
,
1315 (dapm_routes
->control
) ? dapm_routes
->control
:"NULL",
1316 dapm_routes
->source
);
1324 devm_kfree(module
->dev
, module
->dapm_routes
);
1328 static int gbaudio_tplg_process_header(struct gbaudio_module_info
*module
,
1329 struct gb_audio_topology
*tplg_data
)
1331 /* fetch no. of kcontrols, widgets & routes */
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
;
1336 /* update block offset */
1337 module
->dai_offset
= (unsigned long)&tplg_data
->data
;
1338 module
->control_offset
= module
->dai_offset
+ tplg_data
->size_dais
;
1339 module
->widget_offset
= module
->control_offset
+
1340 tplg_data
->size_controls
;
1341 module
->route_offset
= module
->widget_offset
+
1342 tplg_data
->size_widgets
;
1344 dev_dbg(module
->dev
, "DAI offset is 0x%lx\n", module
->dai_offset
);
1345 dev_dbg(module
->dev
, "control offset is %lx\n",
1346 module
->control_offset
);
1347 dev_dbg(module
->dev
, "widget offset is %lx\n", module
->widget_offset
);
1348 dev_dbg(module
->dev
, "route offset is %lx\n", module
->route_offset
);
1353 int gbaudio_tplg_parse_data(struct gbaudio_module_info
*module
,
1354 struct gb_audio_topology
*tplg_data
)
1357 struct gb_audio_control
*controls
;
1358 struct gb_audio_widget
*widgets
;
1359 struct gb_audio_route
*routes
;
1364 ret
= gbaudio_tplg_process_header(module
, tplg_data
);
1366 dev_err(module
->dev
, "%d: Error in parsing topology header\n",
1371 /* process control */
1372 controls
= (struct gb_audio_control
*)module
->control_offset
;
1373 ret
= gbaudio_tplg_process_kcontrols(module
, controls
);
1375 dev_err(module
->dev
,
1376 "%d: Error in parsing controls data\n", ret
);
1379 dev_dbg(module
->dev
, "Control parsing finished\n");
1381 /* process widgets */
1382 widgets
= (struct gb_audio_widget
*)module
->widget_offset
;
1383 ret
= gbaudio_tplg_process_widgets(module
, widgets
);
1385 dev_err(module
->dev
,
1386 "%d: Error in parsing widgets data\n", ret
);
1389 dev_dbg(module
->dev
, "Widget parsing finished\n");
1392 routes
= (struct gb_audio_route
*)module
->route_offset
;
1393 ret
= gbaudio_tplg_process_routes(module
, routes
);
1395 dev_err(module
->dev
,
1396 "%d: Error in parsing routes data\n", ret
);
1399 dev_dbg(module
->dev
, "Route parsing finished\n");
1401 /* parse jack capabilities */
1402 if (tplg_data
->jack_type
) {
1403 module
->jack_mask
= tplg_data
->jack_type
& GBCODEC_JACK_MASK
;
1404 module
->button_mask
= tplg_data
->jack_type
&
1405 GBCODEC_JACK_BUTTON_MASK
;
1411 void gbaudio_tplg_release(struct gbaudio_module_info
*module
)
1413 struct gbaudio_control
*control
, *_control
;
1414 struct gbaudio_widget
*widget
, *_widget
;
1416 if (!module
->topology
)
1419 /* release kcontrols */
1420 list_for_each_entry_safe(control
, _control
, &module
->ctl_list
,
1422 list_del(&control
->list
);
1423 devm_kfree(module
->dev
, control
);
1425 if (module
->controls
)
1426 devm_kfree(module
->dev
, module
->controls
);
1428 /* release widget controls */
1429 list_for_each_entry_safe(control
, _control
, &module
->widget_ctl_list
,
1431 list_del(&control
->list
);
1432 devm_kfree(module
->dev
, control
);
1435 /* release widgets */
1436 list_for_each_entry_safe(widget
, _widget
, &module
->widget_list
,
1438 list_del(&widget
->list
);
1439 devm_kfree(module
->dev
, widget
);
1441 if (module
->dapm_widgets
)
1442 devm_kfree(module
->dev
, module
->dapm_widgets
);
1444 /* release routes */
1445 if (module
->dapm_routes
)
1446 devm_kfree(module
->dev
, module
->dapm_routes
);