diff options
author | Mark Brown <broonie@kernel.org> | 2023-05-16 00:17:58 +0900 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2023-05-16 00:17:58 +0900 |
commit | fe0d5b9a4d6bb1781b462ab5f649d2085492643a (patch) | |
tree | f86811ac28bcb430b0195e97a59dd91d60c26ed4 | |
parent | 8d7c1a577598e4c709855b07c8df92b0c6fc4220 (diff) | |
parent | 95d06196c83c9dc1b6fd6cda07a1bac54ca2d568 (diff) |
ASoC: Factor out control notification support
Merge series from Charles Keepax <ckeepax@opensource.cirrus.com>:
This series introduces and uses a helper for notifying control changes
to userspace.
-rw-r--r-- | include/sound/soc-component.h | 4 | ||||
-rw-r--r-- | sound/soc/codecs/ak4118.c | 11 | ||||
-rw-r--r-- | sound/soc/codecs/wm_adsp.c | 20 | ||||
-rw-r--r-- | sound/soc/soc-component.c | 22 |
4 files changed, 29 insertions, 28 deletions
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 0814ed143864..0b47603c9db2 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -454,6 +454,10 @@ int snd_soc_component_force_enable_pin_unlocked( struct snd_soc_component *component, const char *pin); +/* component controls */ +int snd_soc_component_notify_control(struct snd_soc_component *component, + const char * const ctl); + /* component driver ops */ int snd_soc_component_open(struct snd_soc_component *component, struct snd_pcm_substream *substream); diff --git a/sound/soc/codecs/ak4118.c b/sound/soc/codecs/ak4118.c index ebcdc412e39c..e34e5533765c 100644 --- a/sound/soc/codecs/ak4118.c +++ b/sound/soc/codecs/ak4118.c @@ -264,8 +264,6 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data) struct ak4118_priv *ak4118 = data; struct snd_soc_component *component = ak4118->component; struct snd_kcontrol_new *kctl_new; - struct snd_kcontrol *kctl; - struct snd_ctl_elem_id *id; unsigned int i; if (!component) @@ -273,13 +271,8 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data) for (i = 0; i < ARRAY_SIZE(ak4118_iec958_controls); i++) { kctl_new = &ak4118_iec958_controls[i]; - kctl = snd_soc_card_get_kcontrol(component->card, - kctl_new->name); - if (!kctl) - continue; - id = &kctl->id; - snd_ctl_notify(component->card->snd_card, - SNDRV_CTL_EVENT_MASK_VALUE, id); + + snd_soc_component_notify_control(component, kctl_new->name); } return IRQ_HANDLED; diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 216120b68b64..6270cb2e9395 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -686,8 +686,6 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, { struct cs_dsp_coeff_ctl *cs_ctl = cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg); struct wm_coeff_ctl *ctl; - struct snd_kcontrol *kcontrol; - char ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; int ret; ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len); @@ -699,23 +697,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, ctl = cs_ctl->priv; - if (dsp->component->name_prefix) - snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s", - dsp->component->name_prefix, ctl->name); - else - snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s", - ctl->name); - - kcontrol = snd_soc_card_get_kcontrol(dsp->component->card, ctl_name); - if (!kcontrol) { - adsp_err(dsp, "Can't find kcontrol %s\n", ctl_name); - return -EINVAL; - } - - snd_ctl_notify(dsp->component->card->snd_card, - SNDRV_CTL_EVENT_MASK_VALUE, &kcontrol->id); - - return 0; + return snd_soc_component_notify_control(dsp->component, ctl->name); } EXPORT_SYMBOL_GPL(wm_adsp_write_ctl); diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index ff25718ff2e8..4356cc320fea 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -236,6 +236,28 @@ int snd_soc_component_force_enable_pin_unlocked( } EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); +int snd_soc_component_notify_control(struct snd_soc_component *component, + const char * const ctl) +{ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + struct snd_kcontrol *kctl; + + if (component->name_prefix) + snprintf(name, ARRAY_SIZE(name), "%s %s", component->name_prefix, ctl); + else + snprintf(name, ARRAY_SIZE(name), "%s", ctl); + + kctl = snd_soc_card_get_kcontrol(component->card, name); + if (!kctl) + return soc_component_ret(component, -EINVAL); + + snd_ctl_notify(component->card->snd_card, + SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_notify_control); + /** * snd_soc_component_set_jack - configure component jack. * @component: COMPONENTs |