Skip to content

Commit 737379e

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: dapm: Add component level pin switches
The core currently supports pin switches for source/sink widgets, but only at the card level. SDCA components specify the fabric at the level of the individual components, to support this add helpers to allow component level pin switches. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev> Link: https://patch.msgid.link/20250516131011.221310-5-ckeepax@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3849c95 commit 737379e

File tree

2 files changed

+74
-14
lines changed

2 files changed

+74
-14
lines changed

include/sound/soc-dapm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
445445
struct snd_ctl_elem_value *uncontrol);
446446
int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
447447
struct snd_ctl_elem_value *uncontrol);
448+
int snd_soc_dapm_get_component_pin_switch(struct snd_kcontrol *kcontrol,
449+
struct snd_ctl_elem_value *uncontrol);
450+
int snd_soc_dapm_put_component_pin_switch(struct snd_kcontrol *kcontrol,
451+
struct snd_ctl_elem_value *uncontrol);
448452
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
449453
const struct snd_soc_dapm_widget *widget, unsigned int num);
450454
struct snd_soc_dapm_widget *snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,

sound/soc/soc-dapm.c

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,52 +3626,108 @@ int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
36263626
}
36273627
EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
36283628

3629+
static int __snd_soc_dapm_get_pin_switch(struct snd_soc_dapm_context *dapm,
3630+
const char *pin,
3631+
struct snd_ctl_elem_value *ucontrol)
3632+
{
3633+
snd_soc_dapm_mutex_lock(dapm);
3634+
ucontrol->value.integer.value[0] = snd_soc_dapm_get_pin_status(dapm, pin);
3635+
snd_soc_dapm_mutex_unlock(dapm);
3636+
3637+
return 0;
3638+
}
3639+
36293640
/**
36303641
* snd_soc_dapm_get_pin_switch - Get information for a pin switch
36313642
*
36323643
* @kcontrol: mixer control
36333644
* @ucontrol: Value
3645+
*
3646+
* Callback to provide information for a pin switch added at the card
3647+
* level.
36343648
*/
36353649
int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
36363650
struct snd_ctl_elem_value *ucontrol)
36373651
{
36383652
struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
36393653
const char *pin = (const char *)kcontrol->private_value;
36403654

3641-
snd_soc_dapm_mutex_lock(card);
3655+
return __snd_soc_dapm_get_pin_switch(&card->dapm, pin, ucontrol);
3656+
}
3657+
EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
36423658

3643-
ucontrol->value.integer.value[0] =
3644-
snd_soc_dapm_get_pin_status(&card->dapm, pin);
3659+
/**
3660+
* snd_soc_dapm_get_component_pin_switch - Get information for a pin switch
3661+
*
3662+
* @kcontrol: mixer control
3663+
* @ucontrol: Value
3664+
*
3665+
* Callback to provide information for a pin switch added at the component
3666+
* level.
3667+
*/
3668+
int snd_soc_dapm_get_component_pin_switch(struct snd_kcontrol *kcontrol,
3669+
struct snd_ctl_elem_value *ucontrol)
3670+
{
3671+
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3672+
const char *pin = (const char *)kcontrol->private_value;
36453673

3646-
snd_soc_dapm_mutex_unlock(card);
3674+
return __snd_soc_dapm_get_pin_switch(&component->dapm, pin, ucontrol);
3675+
}
3676+
EXPORT_SYMBOL_GPL(snd_soc_dapm_get_component_pin_switch);
36473677

3648-
return 0;
3678+
static int __snd_soc_dapm_put_pin_switch(struct snd_soc_dapm_context *dapm,
3679+
const char *pin,
3680+
struct snd_ctl_elem_value *ucontrol)
3681+
{
3682+
int ret;
3683+
3684+
snd_soc_dapm_mutex_lock(dapm);
3685+
ret = __snd_soc_dapm_set_pin(dapm, pin, !!ucontrol->value.integer.value[0]);
3686+
snd_soc_dapm_mutex_unlock(dapm);
3687+
3688+
snd_soc_dapm_sync(dapm);
3689+
3690+
return ret;
36493691
}
3650-
EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
36513692

36523693
/**
36533694
* snd_soc_dapm_put_pin_switch - Set information for a pin switch
36543695
*
36553696
* @kcontrol: mixer control
36563697
* @ucontrol: Value
3698+
*
3699+
* Callback to provide information for a pin switch added at the card
3700+
* level.
36573701
*/
36583702
int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
36593703
struct snd_ctl_elem_value *ucontrol)
36603704
{
36613705
struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
36623706
const char *pin = (const char *)kcontrol->private_value;
3663-
int ret;
3664-
3665-
snd_soc_dapm_mutex_lock(card);
3666-
ret = __snd_soc_dapm_set_pin(&card->dapm, pin,
3667-
!!ucontrol->value.integer.value[0]);
3668-
snd_soc_dapm_mutex_unlock(card);
36693707

3670-
snd_soc_dapm_sync(&card->dapm);
3671-
return ret;
3708+
return __snd_soc_dapm_put_pin_switch(&card->dapm, pin, ucontrol);
36723709
}
36733710
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
36743711

3712+
/**
3713+
* snd_soc_dapm_put_component_pin_switch - Set information for a pin switch
3714+
*
3715+
* @kcontrol: mixer control
3716+
* @ucontrol: Value
3717+
*
3718+
* Callback to provide information for a pin switch added at the component
3719+
* level.
3720+
*/
3721+
int snd_soc_dapm_put_component_pin_switch(struct snd_kcontrol *kcontrol,
3722+
struct snd_ctl_elem_value *ucontrol)
3723+
{
3724+
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3725+
const char *pin = (const char *)kcontrol->private_value;
3726+
3727+
return __snd_soc_dapm_put_pin_switch(&component->dapm, pin, ucontrol);
3728+
}
3729+
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_component_pin_switch);
3730+
36753731
struct snd_soc_dapm_widget *
36763732
snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
36773733
const struct snd_soc_dapm_widget *widget)

0 commit comments

Comments
 (0)