* [PATCH v3 2/4] ASoC: soc-component: Add new snd_soc_component_get_kcontrol() helper
2024-08-01 10:04 [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Charles Keepax
@ 2024-08-01 10:04 ` Charles Keepax
2024-08-01 10:04 ` [PATCH v3 3/4] ASoC: cs35l45: Use " Charles Keepax
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2024-08-01 10:04 UTC (permalink / raw)
To: broonie, perex, tiwai; +Cc: lgirdwood, linux-sound, patches
Add a new helper function that returns a kcontrol by name, but will
factor in the components name_prefix, to handle situations where
multiple components are present with the same controls.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
No change since v2.
Thanks,
Charles
include/sound/soc-component.h | 2 ++
sound/soc/soc-component.c | 16 ++++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index ceca69b46a821..61534ac0edd1d 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -462,6 +462,8 @@ int snd_soc_component_force_enable_pin_unlocked(
const char *pin);
/* component controls */
+struct snd_kcontrol *snd_soc_component_get_kcontrol(struct snd_soc_component *component,
+ const char * const ctl);
int snd_soc_component_notify_control(struct snd_soc_component *component,
const char * const ctl);
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 4d7c2e3c929a9..1c0971823fb4d 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -236,11 +236,10 @@ 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)
+struct snd_kcontrol *snd_soc_component_get_kcontrol(struct snd_soc_component *component,
+ const char * const ctl)
{
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
- struct snd_kcontrol *kctl;
/* When updating, change also snd_soc_dapm_widget_name_cmp() */
if (component->name_prefix)
@@ -248,7 +247,16 @@ int snd_soc_component_notify_control(struct snd_soc_component *component,
else
snprintf(name, ARRAY_SIZE(name), "%s", ctl);
- kctl = snd_soc_card_get_kcontrol(component->card, name);
+ return snd_soc_card_get_kcontrol(component->card, name);
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_get_kcontrol);
+
+int snd_soc_component_notify_control(struct snd_soc_component *component,
+ const char * const ctl)
+{
+ struct snd_kcontrol *kctl;
+
+ kctl = snd_soc_component_get_kcontrol(component, ctl);
if (!kctl)
return soc_component_ret(component, -EINVAL);
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 3/4] ASoC: cs35l45: Use new snd_soc_component_get_kcontrol() helper
2024-08-01 10:04 [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Charles Keepax
2024-08-01 10:04 ` [PATCH v3 2/4] ASoC: soc-component: Add new snd_soc_component_get_kcontrol() helper Charles Keepax
@ 2024-08-01 10:04 ` Charles Keepax
2024-08-01 16:38 ` Mark Brown
2024-08-01 10:04 ` [PATCH v3 4/4] ASoC: cs42l43: Cache shutter IRQ control pointers Charles Keepax
2024-08-02 22:28 ` [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Mark Brown
3 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2024-08-01 10:04 UTC (permalink / raw)
To: broonie, perex, tiwai; +Cc: lgirdwood, linux-sound, patches
No longer any need to hard code the addition of the name prefix, use the
new helper.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
No change since v2.
Thanks,
Charles
sound/soc/codecs/cs35l45.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/sound/soc/codecs/cs35l45.c b/sound/soc/codecs/cs35l45.c
index 2392c6effed85..1fefdb80d758c 100644
--- a/sound/soc/codecs/cs35l45.c
+++ b/sound/soc/codecs/cs35l45.c
@@ -176,17 +176,10 @@ static int cs35l45_activate_ctl(struct snd_soc_component *component,
struct snd_kcontrol *kcontrol;
struct snd_kcontrol_volatile *vd;
unsigned int index_offset;
- char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
- if (component->name_prefix)
- snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s",
- component->name_prefix, ctl_name);
- else
- snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s", ctl_name);
-
- kcontrol = snd_soc_card_get_kcontrol_locked(component->card, name);
+ kcontrol = snd_soc_component_get_kcontrol_locked(component->card, ctl_name);
if (!kcontrol) {
- dev_err(component->dev, "Can't find kcontrol %s\n", name);
+ dev_err(component->dev, "Can't find kcontrol %s\n", ctl_name);
return -EINVAL;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 3/4] ASoC: cs35l45: Use new snd_soc_component_get_kcontrol() helper
2024-08-01 10:04 ` [PATCH v3 3/4] ASoC: cs35l45: Use " Charles Keepax
@ 2024-08-01 16:38 ` Mark Brown
2024-08-02 8:44 ` Charles Keepax
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2024-08-01 16:38 UTC (permalink / raw)
To: Charles Keepax; +Cc: perex, tiwai, lgirdwood, linux-sound, patches
[-- Attachment #1: Type: text/plain, Size: 472 bytes --]
On Thu, Aug 01, 2024 at 11:04:12AM +0100, Charles Keepax wrote:
> No longer any need to hard code the addition of the name prefix, use the
> new helper.
> - kcontrol = snd_soc_card_get_kcontrol_locked(component->card, name);
> + kcontrol = snd_soc_component_get_kcontrol_locked(component->card, ctl_name);
That's not the helper that the subject line references, nor the one
added by the prior patch - did you test this?
Please use cover letters for patch serieses too.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/4] ASoC: cs35l45: Use new snd_soc_component_get_kcontrol() helper
2024-08-01 16:38 ` Mark Brown
@ 2024-08-02 8:44 ` Charles Keepax
0 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2024-08-02 8:44 UTC (permalink / raw)
To: Mark Brown; +Cc: perex, tiwai, lgirdwood, linux-sound, patches
On Thu, Aug 01, 2024 at 05:38:32PM +0100, Mark Brown wrote:
> On Thu, Aug 01, 2024 at 11:04:12AM +0100, Charles Keepax wrote:
> > No longer any need to hard code the addition of the name prefix, use the
> > new helper.
>
> > - kcontrol = snd_soc_card_get_kcontrol_locked(component->card, name);
> > + kcontrol = snd_soc_component_get_kcontrol_locked(component->card, ctl_name);
>
> That's not the helper that the subject line references, nor the one
> added by the prior patch - did you test this?
>
> Please use cover letters for patch serieses too.
Well I thought I did but clearly not, apologies will check it and
send a new spin.
Thanks,
Charles
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 4/4] ASoC: cs42l43: Cache shutter IRQ control pointers
2024-08-01 10:04 [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Charles Keepax
2024-08-01 10:04 ` [PATCH v3 2/4] ASoC: soc-component: Add new snd_soc_component_get_kcontrol() helper Charles Keepax
2024-08-01 10:04 ` [PATCH v3 3/4] ASoC: cs35l45: Use " Charles Keepax
@ 2024-08-01 10:04 ` Charles Keepax
2024-08-02 22:28 ` [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Mark Brown
3 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2024-08-01 10:04 UTC (permalink / raw)
To: broonie, perex, tiwai; +Cc: lgirdwood, linux-sound, patches
The microphone/speaker privacy shutter ALSA control handlers need to
call pm_runtime_resume, since the hardware needs to be powered up to
check the hardware state of the shutter. The IRQ handler for the
shutters also needs to notify the ALSA control to inform user-space
the shutters updated. However this leads to a mutex inversion,
between the sdw_dev_lock and the controls_rwsem.
To avoid this mutex inversion cache the kctl pointers before the IRQ
handler, which avoids the need to lookup the control and take the
controls_rwsem.
Suggested-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
Changes since v2:
- Added DAI probe/remove for ASP as well
Thanks,
Charles
sound/soc/codecs/cs42l43.c | 73 +++++++++++++++++++++++++++++---------
sound/soc/codecs/cs42l43.h | 2 ++
2 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c
index 80825777048a6..5183b45864243 100644
--- a/sound/soc/codecs/cs42l43.c
+++ b/sound/soc/codecs/cs42l43.c
@@ -7,6 +7,7 @@
#include <linux/bitops.h>
#include <linux/bits.h>
+#include <linux/build_bug.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/err.h>
@@ -252,24 +253,20 @@ CS42L43_IRQ_COMPLETE(load_detect)
static irqreturn_t cs42l43_mic_shutter(int irq, void *data)
{
struct cs42l43_codec *priv = data;
- static const char * const controls[] = {
- "Decimator 1 Switch",
- "Decimator 2 Switch",
- "Decimator 3 Switch",
- "Decimator 4 Switch",
- };
- int i, ret;
+ struct snd_soc_component *component = priv->component;
+ int i;
dev_dbg(priv->dev, "Microphone shutter changed\n");
- if (!priv->component)
+ if (!component)
return IRQ_NONE;
- for (i = 0; i < ARRAY_SIZE(controls); i++) {
- ret = snd_soc_component_notify_control(priv->component,
- controls[i]);
- if (ret)
+ for (i = 1; i < ARRAY_SIZE(priv->kctl); i++) {
+ if (!priv->kctl[i])
return IRQ_NONE;
+
+ snd_ctl_notify(component->card->snd_card,
+ SNDRV_CTL_EVENT_MASK_VALUE, &priv->kctl[i]->id);
}
return IRQ_HANDLED;
@@ -278,18 +275,19 @@ static irqreturn_t cs42l43_mic_shutter(int irq, void *data)
static irqreturn_t cs42l43_spk_shutter(int irq, void *data)
{
struct cs42l43_codec *priv = data;
- int ret;
+ struct snd_soc_component *component = priv->component;
dev_dbg(priv->dev, "Speaker shutter changed\n");
- if (!priv->component)
+ if (!component)
return IRQ_NONE;
- ret = snd_soc_component_notify_control(priv->component,
- "Speaker Digital Switch");
- if (ret)
+ if (!priv->kctl[0])
return IRQ_NONE;
+ snd_ctl_notify(component->card->snd_card,
+ SNDRV_CTL_EVENT_MASK_VALUE, &priv->kctl[0]->id);
+
return IRQ_HANDLED;
}
@@ -590,7 +588,46 @@ static int cs42l43_asp_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mas
return 0;
}
+static int cs42l43_dai_probe(struct snd_soc_dai *dai)
+{
+ struct snd_soc_component *component = dai->component;
+ struct cs42l43_codec *priv = snd_soc_component_get_drvdata(component);
+ static const char * const controls[] = {
+ "Speaker Digital Switch",
+ "Decimator 1 Switch",
+ "Decimator 2 Switch",
+ "Decimator 3 Switch",
+ "Decimator 4 Switch",
+ };
+ int i;
+
+ static_assert(ARRAY_SIZE(controls) == ARRAY_SIZE(priv->kctl));
+
+ for (i = 0; i < ARRAY_SIZE(controls); i++) {
+ if (priv->kctl[i])
+ continue;
+
+ priv->kctl[i] = snd_soc_component_get_kcontrol(component, controls[i]);
+ }
+
+ return 0;
+}
+
+static int cs42l43_dai_remove(struct snd_soc_dai *dai)
+{
+ struct snd_soc_component *component = dai->component;
+ struct cs42l43_codec *priv = snd_soc_component_get_drvdata(component);
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(priv->kctl); i++)
+ priv->kctl[i] = NULL;
+
+ return 0;
+}
+
static const struct snd_soc_dai_ops cs42l43_asp_ops = {
+ .probe = cs42l43_dai_probe,
+ .remove = cs42l43_dai_remove,
.startup = cs42l43_startup,
.hw_params = cs42l43_asp_hw_params,
.set_fmt = cs42l43_asp_set_fmt,
@@ -611,6 +648,8 @@ static int cs42l43_sdw_hw_params(struct snd_pcm_substream *substream,
}
static const struct snd_soc_dai_ops cs42l43_sdw_ops = {
+ .probe = cs42l43_dai_probe,
+ .remove = cs42l43_dai_remove,
.startup = cs42l43_startup,
.set_stream = cs42l43_sdw_set_stream,
.hw_params = cs42l43_sdw_hw_params,
diff --git a/sound/soc/codecs/cs42l43.h b/sound/soc/codecs/cs42l43.h
index 9924c13e1eb53..9c144e129535f 100644
--- a/sound/soc/codecs/cs42l43.h
+++ b/sound/soc/codecs/cs42l43.h
@@ -100,6 +100,8 @@ struct cs42l43_codec {
struct delayed_work hp_ilimit_clear_work;
bool hp_ilimited;
int hp_ilimit_count;
+
+ struct snd_kcontrol *kctl[5];
};
#if IS_REACHABLE(CONFIG_SND_SOC_CS42L43_SDW)
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function
2024-08-01 10:04 [PATCH v3 1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function Charles Keepax
` (2 preceding siblings ...)
2024-08-01 10:04 ` [PATCH v3 4/4] ASoC: cs42l43: Cache shutter IRQ control pointers Charles Keepax
@ 2024-08-02 22:28 ` Mark Brown
3 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2024-08-02 22:28 UTC (permalink / raw)
To: perex, tiwai, Charles Keepax; +Cc: lgirdwood, linux-sound, patches
On Thu, 01 Aug 2024 11:04:10 +0100, Charles Keepax wrote:
>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/4] ASoC: cs42l43: Remove redundant semi-colon at end of function
commit: becfa08bfefa2cbb22c84d9e583e81387f2f3bf2
[2/4] ASoC: soc-component: Add new snd_soc_component_get_kcontrol() helper
(no commit info)
[3/4] ASoC: cs35l45: Use new snd_soc_component_get_kcontrol() helper
(no commit info)
[4/4] ASoC: cs42l43: Cache shutter IRQ control pointers
commit: 93afd028fb5f06a46a32375fd1f0473451eb1c5a
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
^ permalink raw reply [flat|nested] 7+ messages in thread