Commit 2f15d3ce authored by Mark Brown's avatar Mark Brown

ASoC: qcom: Parse "pin-switches" and "widgets" from DT

Merge series from Stephan Gerhold <stephan@gerhold.net>:

Some sound card setups might require extra pin switches to allow
turning off certain audio components. simple-card supports this
already using the "pin-switches" and "widgets" device tree property.
This series makes it possible to use the same properties for the Qcom
sound cards.

To implement that, the function that parses the "pin-switches" property
in simple-card-utils.c is first moved into the ASoC core. Then two
simple function calls are added to the common Qcom sound card DT parser.
Finally there is a small patch for the msm8916-wcd-analog codec to make
it possible to model sound card setups used in some MSM8916 smartphones.
(See PATCH 2/4 for an explanation of some real example use cases.)

Using pin switches rather than patching codec drivers with switches was
originally suggested by Mark Brown on a patch for the tfa989x codec:
https://lore.kernel.org/alsa-devel/YXaMVHo9drCIuD3u@sirena.org.uk/
parents 4e28491a 319a0533
...@@ -39,6 +39,14 @@ properties: ...@@ -39,6 +39,14 @@ properties:
$ref: /schemas/types.yaml#/definitions/string $ref: /schemas/types.yaml#/definitions/string
description: User visible long sound card name description: User visible long sound card name
pin-switches:
description: List of widget names for which pin switches should be created.
$ref: /schemas/types.yaml#/definitions/string-array
widgets:
description: User specified audio sound widgets.
$ref: /schemas/types.yaml#/definitions/non-unique-string-array
# Only valid for some compatibles (see allOf if below) # Only valid for some compatibles (see allOf if below)
reg: true reg: true
reg-names: true reg-names: true
...@@ -251,7 +259,15 @@ examples: ...@@ -251,7 +259,15 @@ examples:
reg-names = "mic-iomux", "spkr-iomux"; reg-names = "mic-iomux", "spkr-iomux";
model = "msm8916"; model = "msm8916";
widgets =
"Speaker", "Speaker",
"Headphone", "Headphones";
pin-switches = "Speaker";
audio-routing = audio-routing =
"Speaker", "Speaker Amp OUT",
"Speaker Amp IN", "HPH_R",
"Headphones", "HPH_L",
"Headphones", "HPH_R",
"AMIC1", "MIC BIAS Internal1", "AMIC1", "MIC BIAS Internal1",
"AMIC2", "MIC BIAS Internal2", "AMIC2", "MIC BIAS Internal2",
"AMIC3", "MIC BIAS Internal3"; "AMIC3", "MIC BIAS Internal3";
......
...@@ -1211,6 +1211,7 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card, ...@@ -1211,6 +1211,7 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card,
const char *propname); const char *propname);
int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
const char *propname); const char *propname);
int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop);
int snd_soc_of_get_slot_mask(struct device_node *np, int snd_soc_of_get_slot_mask(struct device_node *np,
const char *prop_name, const char *prop_name,
unsigned int *mask); unsigned int *mask);
......
...@@ -822,8 +822,8 @@ static const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = { ...@@ -822,8 +822,8 @@ static const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = {
{"EAR PA", NULL, "EAR CP"}, {"EAR PA", NULL, "EAR CP"},
/* Headset (RX MIX1 and RX MIX2) */ /* Headset (RX MIX1 and RX MIX2) */
{"HEADPHONE", NULL, "HPHL PA"}, {"HPH_L", NULL, "HPHL PA"},
{"HEADPHONE", NULL, "HPHR PA"}, {"HPH_R", NULL, "HPHR PA"},
{"HPHL DAC", NULL, "EAR_HPHL_CLK"}, {"HPHL DAC", NULL, "EAR_HPHL_CLK"},
{"HPHR DAC", NULL, "EAR_HPHR_CLK"}, {"HPHR DAC", NULL, "EAR_HPHR_CLK"},
...@@ -870,7 +870,8 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = { ...@@ -870,7 +870,8 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
SND_SOC_DAPM_INPUT("AMIC3"), SND_SOC_DAPM_INPUT("AMIC3"),
SND_SOC_DAPM_INPUT("AMIC2"), SND_SOC_DAPM_INPUT("AMIC2"),
SND_SOC_DAPM_OUTPUT("EAR"), SND_SOC_DAPM_OUTPUT("EAR"),
SND_SOC_DAPM_OUTPUT("HEADPHONE"), SND_SOC_DAPM_OUTPUT("HPH_L"),
SND_SOC_DAPM_OUTPUT("HPH_R"),
/* RX stuff */ /* RX stuff */
SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
......
...@@ -499,57 +499,14 @@ EXPORT_SYMBOL_GPL(asoc_simple_parse_widgets); ...@@ -499,57 +499,14 @@ EXPORT_SYMBOL_GPL(asoc_simple_parse_widgets);
int asoc_simple_parse_pin_switches(struct snd_soc_card *card, int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
char *prefix) char *prefix)
{ {
const unsigned int nb_controls_max = 16;
const char **strings, *control_name;
struct snd_kcontrol_new *controls;
struct device *dev = card->dev;
unsigned int i, nb_controls;
char prop[128]; char prop[128];
int ret;
if (!prefix) if (!prefix)
prefix = ""; prefix = "";
snprintf(prop, sizeof(prop), "%s%s", prefix, "pin-switches"); snprintf(prop, sizeof(prop), "%s%s", prefix, "pin-switches");
if (!of_property_read_bool(dev->of_node, prop)) return snd_soc_of_parse_pin_switches(card, prop);
return 0;
strings = devm_kcalloc(dev, nb_controls_max,
sizeof(*strings), GFP_KERNEL);
if (!strings)
return -ENOMEM;
ret = of_property_read_string_array(dev->of_node, prop,
strings, nb_controls_max);
if (ret < 0)
return ret;
nb_controls = (unsigned int)ret;
controls = devm_kcalloc(dev, nb_controls,
sizeof(*controls), GFP_KERNEL);
if (!controls)
return -ENOMEM;
for (i = 0; i < nb_controls; i++) {
control_name = devm_kasprintf(dev, GFP_KERNEL,
"%s Switch", strings[i]);
if (!control_name)
return -ENOMEM;
controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
controls[i].name = control_name;
controls[i].info = snd_soc_dapm_info_pin_switch;
controls[i].get = snd_soc_dapm_get_pin_switch;
controls[i].put = snd_soc_dapm_put_pin_switch;
controls[i].private_value = (unsigned long)strings[i];
}
card->controls = controls;
card->num_controls = nb_controls;
return 0;
} }
EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches); EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches);
......
...@@ -26,6 +26,12 @@ int qcom_snd_parse_of(struct snd_soc_card *card) ...@@ -26,6 +26,12 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
return ret; return ret;
} }
if (of_property_read_bool(dev->of_node, "widgets")) {
ret = snd_soc_of_parse_audio_simple_widgets(card, "widgets");
if (ret)
return ret;
}
/* DAPM routes */ /* DAPM routes */
if (of_property_read_bool(dev->of_node, "audio-routing")) { if (of_property_read_bool(dev->of_node, "audio-routing")) {
ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
...@@ -39,6 +45,10 @@ int qcom_snd_parse_of(struct snd_soc_card *card) ...@@ -39,6 +45,10 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
return ret; return ret;
} }
ret = snd_soc_of_parse_pin_switches(card, "pin-switches");
if (ret)
return ret;
ret = snd_soc_of_parse_aux_devs(card, "aux-devs"); ret = snd_soc_of_parse_aux_devs(card, "aux-devs");
if (ret) if (ret)
return ret; return ret;
......
...@@ -2823,6 +2823,56 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, ...@@ -2823,6 +2823,56 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
} }
EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop)
{
const unsigned int nb_controls_max = 16;
const char **strings, *control_name;
struct snd_kcontrol_new *controls;
struct device *dev = card->dev;
unsigned int i, nb_controls;
int ret;
if (!of_property_read_bool(dev->of_node, prop))
return 0;
strings = devm_kcalloc(dev, nb_controls_max,
sizeof(*strings), GFP_KERNEL);
if (!strings)
return -ENOMEM;
ret = of_property_read_string_array(dev->of_node, prop,
strings, nb_controls_max);
if (ret < 0)
return ret;
nb_controls = (unsigned int)ret;
controls = devm_kcalloc(dev, nb_controls,
sizeof(*controls), GFP_KERNEL);
if (!controls)
return -ENOMEM;
for (i = 0; i < nb_controls; i++) {
control_name = devm_kasprintf(dev, GFP_KERNEL,
"%s Switch", strings[i]);
if (!control_name)
return -ENOMEM;
controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
controls[i].name = control_name;
controls[i].info = snd_soc_dapm_info_pin_switch;
controls[i].get = snd_soc_dapm_get_pin_switch;
controls[i].put = snd_soc_dapm_put_pin_switch;
controls[i].private_value = (unsigned long)strings[i];
}
card->controls = controls;
card->num_controls = nb_controls;
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_pin_switches);
int snd_soc_of_get_slot_mask(struct device_node *np, int snd_soc_of_get_slot_mask(struct device_node *np,
const char *prop_name, const char *prop_name,
unsigned int *mask) unsigned int *mask)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment