2016-11-28 17:34:08

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 0/5] ASoC/arizona: Ensure pin searches use widget name prefix

The name of a codec pin can have an optional prefix string, which is
defined by the audio machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

This patch chain adds new helper functions that take a non-prefixed name
for a specific ASoC component and internally add that component's prefix.
The other patches update the arizona drivers to use these new functions.

Richard Fitzgerald (5):
ASoC: core: Add component pin control functions
ASoC: arizona: Use component pin control functions
regulator: arizona-micsupp: Use SoC component pin control functions
extcon: arizona: Use SoC component pin control functions
Input: arizona-haptics - Use SoC component pin control functions

drivers/extcon/extcon-arizona.c | 8 +-
drivers/input/misc/arizona-haptics.c | 13 ++-
drivers/regulator/arizona-micsupp.c | 6 +-
include/sound/soc.h | 25 +++++
sound/soc/codecs/arizona.c | 13 ++-
sound/soc/codecs/cs47l24.c | 2 +-
sound/soc/codecs/wm5102.c | 2 +-
sound/soc/codecs/wm5110.c | 2 +-
sound/soc/codecs/wm8998.c | 2 +-
sound/soc/soc-utils.c | 199 +++++++++++++++++++++++++++++++++++
10 files changed, 254 insertions(+), 18 deletions(-)

--
1.9.1


2016-11-28 17:33:13

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 2/5] ASoC: arizona: Use component pin control functions

We need to modify the state of some of our own pins and are currently
not taking account that the pin name may have a name_prefix applied
to it.

Replace the snd_soc_dapm_x_pin functions with the equivalent
snd_soc_component_x_pin functions so that any name_prefix will be
handled automatically.

Signed-off-by: Richard Fitzgerald <[email protected]>
---
sound/soc/codecs/arizona.c | 13 ++++++++-----
sound/soc/codecs/cs47l24.c | 2 +-
sound/soc/codecs/wm5102.c | 2 +-
sound/soc/codecs/wm5110.c | 2 +-
sound/soc/codecs/wm8998.c | 2 +-
5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index ca5ca9e..01f6ec7 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -256,7 +256,7 @@ int arizona_init_mono(struct snd_soc_codec *codec)

int arizona_init_gpio(struct snd_soc_codec *codec)
{
- struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
+ struct snd_soc_component *component = &codec->component;
struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
struct arizona *arizona = priv->arizona;
int i;
@@ -264,21 +264,24 @@ int arizona_init_gpio(struct snd_soc_codec *codec)
switch (arizona->type) {
case WM5110:
case WM8280:
- snd_soc_dapm_disable_pin(dapm, "DRC2 Signal Activity");
+ snd_soc_component_disable_pin(component,
+ "DRC2 Signal Activity");
break;
default:
break;
}

- snd_soc_dapm_disable_pin(dapm, "DRC1 Signal Activity");
+ snd_soc_component_disable_pin(component, "DRC1 Signal Activity");

for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) {
case ARIZONA_GP_FN_DRC1_SIGNAL_DETECT:
- snd_soc_dapm_enable_pin(dapm, "DRC1 Signal Activity");
+ snd_soc_component_enable_pin(component,
+ "DRC1 Signal Activity");
break;
case ARIZONA_GP_FN_DRC2_SIGNAL_DETECT:
- snd_soc_dapm_enable_pin(dapm, "DRC2 Signal Activity");
+ snd_soc_component_enable_pin(component,
+ "DRC2 Signal Activity");
break;
default:
break;
diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c
index 1ed1329..275c58a 100644
--- a/sound/soc/codecs/cs47l24.c
+++ b/sound/soc/codecs/cs47l24.c
@@ -1138,7 +1138,7 @@ static int cs47l24_codec_probe(struct snd_soc_codec *codec)
if (ret)
goto err_adsp2_codec_probe;

- snd_soc_dapm_disable_pin(dapm, "HAPTICS");
+ snd_soc_component_disable_pin(&codec->component, "HAPTICS");

return 0;

diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 72ff291..aa590ed 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -1947,7 +1947,7 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
arizona_init_gpio(codec);
arizona_init_notifiers(codec);

- snd_soc_dapm_disable_pin(dapm, "HAPTICS");
+ snd_soc_component_disable_pin(&codec->component, "HAPTICS");

priv->core.arizona->dapm = dapm;

diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index a9a8bc9..45815b9 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -2295,7 +2295,7 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
if (ret)
goto err_adsp2_codec_probe;

- snd_soc_dapm_disable_pin(dapm, "HAPTICS");
+ snd_soc_component_disable_pin(&codec->component, "HAPTICS");

return 0;

diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c
index 1e1d9c1..7ccc931 100644
--- a/sound/soc/codecs/wm8998.c
+++ b/sound/soc/codecs/wm8998.c
@@ -1327,7 +1327,7 @@ static int wm8998_codec_probe(struct snd_soc_codec *codec)
arizona_init_gpio(codec);
arizona_init_notifiers(codec);

- snd_soc_dapm_disable_pin(dapm, "HAPTICS");
+ snd_soc_component_disable_pin(&codec->component, "HAPTICS");

return 0;
}
--
1.9.1

2016-11-28 17:33:29

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 4/5] extcon: arizona: Use SoC component pin control functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
---
drivers/extcon/extcon-arizona.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 56e6c4c..d836d4c 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -274,9 +274,10 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
struct arizona *arizona = info->arizona;
const char *widget = arizona_extcon_get_micbias(info);
struct snd_soc_dapm_context *dapm = arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
int ret;

- ret = snd_soc_dapm_force_enable_pin(dapm, widget);
+ ret = snd_soc_component_force_enable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev, "Failed to enable %s: %d\n",
widget, ret);
@@ -284,7 +285,7 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
snd_soc_dapm_sync(dapm);

if (!arizona->pdata.micd_force_micbias) {
- ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
+ ret = snd_soc_component_disable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev, "Failed to disable %s: %d\n",
widget, ret);
@@ -349,6 +350,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
struct arizona *arizona = info->arizona;
const char *widget = arizona_extcon_get_micbias(info);
struct snd_soc_dapm_context *dapm = arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
bool change;
int ret;

@@ -356,7 +358,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
ARIZONA_MICD_ENA, 0,
&change);

- ret = snd_soc_dapm_disable_pin(dapm, widget);
+ ret = snd_soc_component_disable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev,
"Failed to disable %s: %d\n",
--
1.9.1

2016-11-28 17:33:37

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 3/5] regulator: arizona-micsupp: Use SoC component pin control functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
---
drivers/regulator/arizona-micsupp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index fcb98db..1439462 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -45,6 +45,7 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
struct arizona_micsupp *micsupp =
container_of(work, struct arizona_micsupp, check_cp_work);
struct snd_soc_dapm_context *dapm = micsupp->arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
struct arizona *arizona = micsupp->arizona;
struct regmap *regmap = arizona->regmap;
unsigned int reg;
@@ -59,9 +60,10 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
if (dapm) {
if ((reg & (ARIZONA_CPMIC_ENA | ARIZONA_CPMIC_BYPASS)) ==
ARIZONA_CPMIC_ENA)
- snd_soc_dapm_force_enable_pin(dapm, "MICSUPP");
+ snd_soc_component_force_enable_pin(component,
+ "MICSUPP");
else
- snd_soc_dapm_disable_pin(dapm, "MICSUPP");
+ snd_soc_component_disable_pin(component, "MICSUPP");

snd_soc_dapm_sync(dapm);
}
--
1.9.1

2016-11-28 17:33:49

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 1/5] ASoC: core: Add component pin control functions

It's often the case that a codec driver will need to control its
own pins. However, if a name_prefix has been applied to this codec it
must be included in the name passed to any of the snd_soc_dapm_x_pin()
functions.

The behaviour of the existing pin control functions is reasonable, since
you may want to search for a fully-specified name within the scope of an
entire card. This means that we can't apply the prefix in these functions
because it will break card-scope searches.

Constructing a prefixed string "manually" in codec drivers leads to a lot
of repetition of the same code.

To make this tidier in codec drivers this patch adds a new set of
equivalent functions that take a struct snd_soc_component instead of a
dapm context and automatically add the component's name_prefix to the
given name. This makes it a simple change in codec drivers to be
prefix-safe.

The new functions are not quite trivial enough to be inlines and the
compiler won't be able to compile-away any part of them.

Although it looks somewhat inefficient to have to allocate a temporary
buffer and combine strings, the current design of the widget list
doesn't lend itself to a more optimized implementation - it's a single
list of all widgets on a card and is searched linearly for a matching
string. As pin state changes are generally low-frequency events it's
unlikely to be a significant issue - at least not enough to rewrite the
widget list handling just for this.

Signed-off-by: Richard Fitzgerald <[email protected]>
---
include/sound/soc.h | 25 +++++++
sound/soc/soc-utils.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 224 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 795e6c4..a46d0774 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1718,4 +1718,29 @@ static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
mutex_unlock(&dapm->card->dapm_mutex);
}

+extern int snd_soc_component_enable_pin(struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_enable_pin_unlocked(
+ struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_disable_pin(struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_disable_pin_unlocked(
+ struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_nc_pin(struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_nc_pin_unlocked(
+ struct snd_soc_component *component,
+ const char *pin);
+
+extern int snd_soc_component_get_pin_status(struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_force_enable_pin(
+ struct snd_soc_component *component,
+ const char *pin);
+extern int snd_soc_component_force_enable_pin_unlocked(
+ struct snd_soc_component *component,
+ const char *pin);
+
#endif
diff --git a/sound/soc/soc-utils.c b/sound/soc/soc-utils.c
index 393e8f0..644d9a9 100644
--- a/sound/soc/soc-utils.c
+++ b/sound/soc/soc-utils.c
@@ -58,6 +58,205 @@ int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
}
EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);

+int snd_soc_component_enable_pin(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_enable_pin(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_enable_pin(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
+
+int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_enable_pin_unlocked(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
+
+int snd_soc_component_disable_pin(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_disable_pin(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_disable_pin(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
+
+int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_disable_pin_unlocked(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
+
+int snd_soc_component_nc_pin(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_nc_pin(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_nc_pin(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
+
+int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_nc_pin_unlocked(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
+
+int snd_soc_component_get_pin_status(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_get_pin_status(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_get_pin_status(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
+
+int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_force_enable_pin(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_force_enable_pin(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
+
+int snd_soc_component_force_enable_pin_unlocked(
+ struct snd_soc_component *component,
+ const char *pin)
+{
+ struct snd_soc_dapm_context *dapm =
+ snd_soc_component_get_dapm(component);
+ char *full_name;
+ int ret;
+
+ if (!component->name_prefix)
+ return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
+
+ full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
+ if (!full_name)
+ return -ENOMEM;
+
+ ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, full_name);
+ kfree(full_name);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
+
static const struct snd_pcm_hardware dummy_dma_hardware = {
/* Random values to keep userspace happy when checking constraints */
.info = SNDRV_PCM_INFO_INTERLEAVED |
--
1.9.1

2016-11-28 17:33:59

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH 5/5] Input: arizona-haptics - Use SoC component pin control functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
---
drivers/input/misc/arizona-haptics.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
index 9829363..07ec465 100644
--- a/drivers/input/misc/arizona-haptics.c
+++ b/drivers/input/misc/arizona-haptics.c
@@ -37,6 +37,8 @@ static void arizona_haptics_work(struct work_struct *work)
struct arizona_haptics,
work);
struct arizona *arizona = haptics->arizona;
+ struct snd_soc_component *component =
+ snd_soc_dapm_to_component(arizona->dapm);
int ret;

if (!haptics->arizona->dapm) {
@@ -66,7 +68,7 @@ static void arizona_haptics_work(struct work_struct *work)
return;
}

- ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
+ ret = snd_soc_component_enable_pin(component, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
ret);
@@ -81,7 +83,7 @@ static void arizona_haptics_work(struct work_struct *work)
}
} else {
/* This disable sequence will be a noop if already enabled */
- ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
+ ret = snd_soc_component_disable_pin(component, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
ret);
@@ -140,11 +142,14 @@ static int arizona_haptics_play(struct input_dev *input, void *data,
static void arizona_haptics_close(struct input_dev *input)
{
struct arizona_haptics *haptics = input_get_drvdata(input);
+ struct snd_soc_component *component;

cancel_work_sync(&haptics->work);

- if (haptics->arizona->dapm)
- snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");
+ if (haptics->arizona->dapm) {
+ component = snd_soc_dapm_to_component(haptics->arizona->dapm);
+ snd_soc_component_disable_pin(component, "HAPTICS");
+ }
}

static int arizona_haptics_probe(struct platform_device *pdev)
--
1.9.1

2016-11-28 18:54:15

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 5/5] Input: arizona-haptics - Use SoC component pin control functions

Hi Richard,

On Mon, Nov 28, 2016 at 05:32:30PM +0000, Richard Fitzgerald wrote:
> The name of a codec pin can have an optional prefix string, which is
> defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
> take the fully-specified name including the prefix and so the existing
> code would fail to find the pin if the audio machine driver had added
> a prefix.
>
> Switch to using the snd_soc_component_x_pin equivalent functions that
> take a specified SoC component and automatically add the name prefix to
> the provided pin name.
>
> Signed-off-by: Richard Fitzgerald <[email protected]>

If ASOC folks are fine with this then I am otto. Please merge with the rest of
Arizona changes.

Acked-by: Dmitry Torokhov <[email protected]>

Thanks.

--
Dmitry

2016-11-29 09:22:38

by Charles Keepax

[permalink] [raw]
Subject: Re: [PATCH 1/5] ASoC: core: Add component pin control functions

On Mon, Nov 28, 2016 at 05:32:26PM +0000, Richard Fitzgerald wrote:
> It's often the case that a codec driver will need to control its
> own pins. However, if a name_prefix has been applied to this codec it
> must be included in the name passed to any of the snd_soc_dapm_x_pin()
> functions.
>
> The behaviour of the existing pin control functions is reasonable, since
> you may want to search for a fully-specified name within the scope of an
> entire card. This means that we can't apply the prefix in these functions
> because it will break card-scope searches.
>
> Constructing a prefixed string "manually" in codec drivers leads to a lot
> of repetition of the same code.
>
> To make this tidier in codec drivers this patch adds a new set of
> equivalent functions that take a struct snd_soc_component instead of a
> dapm context and automatically add the component's name_prefix to the
> given name. This makes it a simple change in codec drivers to be
> prefix-safe.
>
> The new functions are not quite trivial enough to be inlines and the
> compiler won't be able to compile-away any part of them.
>
> Although it looks somewhat inefficient to have to allocate a temporary
> buffer and combine strings, the current design of the widget list
> doesn't lend itself to a more optimized implementation - it's a single
> list of all widgets on a card and is searched linearly for a matching
> string. As pin state changes are generally low-frequency events it's
> unlikely to be a significant issue - at least not enough to rewrite the
> widget list handling just for this.
>
> Signed-off-by: Richard Fitzgerald <[email protected]>
> ---
> include/sound/soc.h | 25 +++++++
> sound/soc/soc-utils.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 224 insertions(+)
>
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index 795e6c4..a46d0774 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -1718,4 +1718,29 @@ static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
> mutex_unlock(&dapm->card->dapm_mutex);
> }
>
> +extern int snd_soc_component_enable_pin(struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_enable_pin_unlocked(
> + struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_disable_pin(struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_disable_pin_unlocked(
> + struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_nc_pin(struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_nc_pin_unlocked(
> + struct snd_soc_component *component,
> + const char *pin);
> +
> +extern int snd_soc_component_get_pin_status(struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_force_enable_pin(
> + struct snd_soc_component *component,
> + const char *pin);
> +extern int snd_soc_component_force_enable_pin_unlocked(
> + struct snd_soc_component *component,
> + const char *pin);
> +

I don't believe we need these extern's C defaults to external
linkage.

Thanks,
Charles

2016-11-29 09:24:39

by Charles Keepax

[permalink] [raw]
Subject: Re: [PATCH 2/5] ASoC: arizona: Use component pin control functions

On Mon, Nov 28, 2016 at 05:32:27PM +0000, Richard Fitzgerald wrote:
> We need to modify the state of some of our own pins and are currently
> not taking account that the pin name may have a name_prefix applied
> to it.
>
> Replace the snd_soc_dapm_x_pin functions with the equivalent
> snd_soc_component_x_pin functions so that any name_prefix will be
> handled automatically.
>
> Signed-off-by: Richard Fitzgerald <[email protected]>
> ---
> sound/soc/codecs/arizona.c | 13 ++++++++-----
> sound/soc/codecs/cs47l24.c | 2 +-
> sound/soc/codecs/wm5102.c | 2 +-
> sound/soc/codecs/wm5110.c | 2 +-
> sound/soc/codecs/wm8998.c | 2 +-
> 5 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
> index ca5ca9e..01f6ec7 100644
> --- a/sound/soc/codecs/arizona.c
> +++ b/sound/soc/codecs/arizona.c
> @@ -256,7 +256,7 @@ int arizona_init_mono(struct snd_soc_codec *codec)
>
> int arizona_init_gpio(struct snd_soc_codec *codec)
> {
> - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
> + struct snd_soc_component *component = &codec->component;

We should probably use snd_soc_dapm_to_component(dapm); here.

> struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
> struct arizona *arizona = priv->arizona;
> int i;
> @@ -264,21 +264,24 @@ int arizona_init_gpio(struct snd_soc_codec *codec)
> switch (arizona->type) {
> case WM5110:
> case WM8280:
> - snd_soc_dapm_disable_pin(dapm, "DRC2 Signal Activity");
> + snd_soc_component_disable_pin(component,
> + "DRC2 Signal Activity");
> break;
> default:
> break;
> }
>
> - snd_soc_dapm_disable_pin(dapm, "DRC1 Signal Activity");
> + snd_soc_component_disable_pin(component, "DRC1 Signal Activity");
>
> for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
> switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) {
> case ARIZONA_GP_FN_DRC1_SIGNAL_DETECT:
> - snd_soc_dapm_enable_pin(dapm, "DRC1 Signal Activity");
> + snd_soc_component_enable_pin(component,
> + "DRC1 Signal Activity");
> break;
> case ARIZONA_GP_FN_DRC2_SIGNAL_DETECT:
> - snd_soc_dapm_enable_pin(dapm, "DRC2 Signal Activity");
> + snd_soc_component_enable_pin(component,
> + "DRC2 Signal Activity");
> break;
> default:
> break;
> diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c
> index 1ed1329..275c58a 100644
> --- a/sound/soc/codecs/cs47l24.c
> +++ b/sound/soc/codecs/cs47l24.c
> @@ -1138,7 +1138,7 @@ static int cs47l24_codec_probe(struct snd_soc_codec *codec)
> if (ret)
> goto err_adsp2_codec_probe;
>
> - snd_soc_dapm_disable_pin(dapm, "HAPTICS");
> + snd_soc_component_disable_pin(&codec->component, "HAPTICS");

ditto for these calls as well.

>
> return 0;
>
> diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
> index 72ff291..aa590ed 100644
> --- a/sound/soc/codecs/wm5102.c
> +++ b/sound/soc/codecs/wm5102.c
> @@ -1947,7 +1947,7 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
> arizona_init_gpio(codec);
> arizona_init_notifiers(codec);
>
> - snd_soc_dapm_disable_pin(dapm, "HAPTICS");
> + snd_soc_component_disable_pin(&codec->component, "HAPTICS");
>
> priv->core.arizona->dapm = dapm;
>
> diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
> index a9a8bc9..45815b9 100644
> --- a/sound/soc/codecs/wm5110.c
> +++ b/sound/soc/codecs/wm5110.c
> @@ -2295,7 +2295,7 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
> if (ret)
> goto err_adsp2_codec_probe;
>
> - snd_soc_dapm_disable_pin(dapm, "HAPTICS");
> + snd_soc_component_disable_pin(&codec->component, "HAPTICS");
>
> return 0;
>
> diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c
> index 1e1d9c1..7ccc931 100644
> --- a/sound/soc/codecs/wm8998.c
> +++ b/sound/soc/codecs/wm8998.c
> @@ -1327,7 +1327,7 @@ static int wm8998_codec_probe(struct snd_soc_codec *codec)
> arizona_init_gpio(codec);
> arizona_init_notifiers(codec);
>
> - snd_soc_dapm_disable_pin(dapm, "HAPTICS");
> + snd_soc_component_disable_pin(&codec->component, "HAPTICS");
>
> return 0;
> }
> --
> 1.9.1

Thanks,
Charles

2016-12-01 21:46:19

by Mark Brown

[permalink] [raw]
Subject: Applied "extcon: arizona: Use SoC component pin control functions" to the asoc tree

The patch

extcon: arizona: Use SoC component pin control functions

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From efd95c71f4892ad5d0d33099db25085763f4c6c3 Mon Sep 17 00:00:00 2001
From: Richard Fitzgerald <[email protected]>
Date: Tue, 29 Nov 2016 15:44:41 +0000
Subject: [PATCH] extcon: arizona: Use SoC component pin control functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/extcon/extcon-arizona.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 56e6c4c7c60d..d836d4ce5ee4 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -274,9 +274,10 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
struct arizona *arizona = info->arizona;
const char *widget = arizona_extcon_get_micbias(info);
struct snd_soc_dapm_context *dapm = arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
int ret;

- ret = snd_soc_dapm_force_enable_pin(dapm, widget);
+ ret = snd_soc_component_force_enable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev, "Failed to enable %s: %d\n",
widget, ret);
@@ -284,7 +285,7 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
snd_soc_dapm_sync(dapm);

if (!arizona->pdata.micd_force_micbias) {
- ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
+ ret = snd_soc_component_disable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev, "Failed to disable %s: %d\n",
widget, ret);
@@ -349,6 +350,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
struct arizona *arizona = info->arizona;
const char *widget = arizona_extcon_get_micbias(info);
struct snd_soc_dapm_context *dapm = arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
bool change;
int ret;

@@ -356,7 +358,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
ARIZONA_MICD_ENA, 0,
&change);

- ret = snd_soc_dapm_disable_pin(dapm, widget);
+ ret = snd_soc_component_disable_pin(component, widget);
if (ret != 0)
dev_warn(arizona->dev,
"Failed to disable %s: %d\n",
--
2.10.2

2016-12-01 21:48:34

by Mark Brown

[permalink] [raw]
Subject: Applied "Input: arizona-haptics - Use SoC component pin control functions" to the asoc tree

The patch

Input: arizona-haptics - Use SoC component pin control functions

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 931afc4114c59b8fe8386db9fcdfe69a1322cae6 Mon Sep 17 00:00:00 2001
From: Richard Fitzgerald <[email protected]>
Date: Tue, 29 Nov 2016 15:44:42 +0000
Subject: [PATCH] Input: arizona-haptics - Use SoC component pin control
functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
Acked-by: Dmitry Torokhov <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/input/misc/arizona-haptics.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
index 982936334537..07ec465f1095 100644
--- a/drivers/input/misc/arizona-haptics.c
+++ b/drivers/input/misc/arizona-haptics.c
@@ -37,6 +37,8 @@ static void arizona_haptics_work(struct work_struct *work)
struct arizona_haptics,
work);
struct arizona *arizona = haptics->arizona;
+ struct snd_soc_component *component =
+ snd_soc_dapm_to_component(arizona->dapm);
int ret;

if (!haptics->arizona->dapm) {
@@ -66,7 +68,7 @@ static void arizona_haptics_work(struct work_struct *work)
return;
}

- ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
+ ret = snd_soc_component_enable_pin(component, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
ret);
@@ -81,7 +83,7 @@ static void arizona_haptics_work(struct work_struct *work)
}
} else {
/* This disable sequence will be a noop if already enabled */
- ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
+ ret = snd_soc_component_disable_pin(component, "HAPTICS");
if (ret != 0) {
dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
ret);
@@ -140,11 +142,14 @@ static int arizona_haptics_play(struct input_dev *input, void *data,
static void arizona_haptics_close(struct input_dev *input)
{
struct arizona_haptics *haptics = input_get_drvdata(input);
+ struct snd_soc_component *component;

cancel_work_sync(&haptics->work);

- if (haptics->arizona->dapm)
- snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");
+ if (haptics->arizona->dapm) {
+ component = snd_soc_dapm_to_component(haptics->arizona->dapm);
+ snd_soc_component_disable_pin(component, "HAPTICS");
+ }
}

static int arizona_haptics_probe(struct platform_device *pdev)
--
2.10.2

2016-12-15 22:06:50

by Mark Brown

[permalink] [raw]
Subject: Applied "regulator: arizona-micsupp: Use SoC component pin control functions" to the regulator tree

The patch

regulator: arizona-micsupp: Use SoC component pin control functions

has been applied to the regulator tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 98cf9965c09fc3fe6d8bd9760dba1dec53e387cc Mon Sep 17 00:00:00 2001
From: Richard Fitzgerald <[email protected]>
Date: Thu, 15 Dec 2016 14:43:49 +0000
Subject: [PATCH] regulator: arizona-micsupp: Use SoC component pin control
functions

The name of a codec pin can have an optional prefix string, which is
defined by the SoC machine driver. The snd_soc_dapm_x_pin functions
take the fully-specified name including the prefix and so the existing
code would fail to find the pin if the audio machine driver had added
a prefix.

Switch to using the snd_soc_component_x_pin equivalent functions that
take a specified SoC component and automatically add the name prefix to
the provided pin name.

Signed-off-by: Richard Fitzgerald <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/regulator/arizona-micsupp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index fcb98dbda837..143946215e23 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -45,6 +45,7 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
struct arizona_micsupp *micsupp =
container_of(work, struct arizona_micsupp, check_cp_work);
struct snd_soc_dapm_context *dapm = micsupp->arizona->dapm;
+ struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
struct arizona *arizona = micsupp->arizona;
struct regmap *regmap = arizona->regmap;
unsigned int reg;
@@ -59,9 +60,10 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
if (dapm) {
if ((reg & (ARIZONA_CPMIC_ENA | ARIZONA_CPMIC_BYPASS)) ==
ARIZONA_CPMIC_ENA)
- snd_soc_dapm_force_enable_pin(dapm, "MICSUPP");
+ snd_soc_component_force_enable_pin(component,
+ "MICSUPP");
else
- snd_soc_dapm_disable_pin(dapm, "MICSUPP");
+ snd_soc_component_disable_pin(component, "MICSUPP");

snd_soc_dapm_sync(dapm);
}
--
2.11.0