Skip to contentSkip to conversation

Make genaral and simple for new sof machine driver

PATCH In review David Lin 3 participants 9 messages Oct 27, 2021 – Oct 28, 2021

Subsystems (2)
lore
Share & tools
lore

David Lin

author
#0 lore raw

cover Make genaral and simple for new sof machine driver

The series of features will make general and simple for new sof machine driver.

David Lin (3):
ASoC: nau8825: add set_jack coponment support
ASoC: nau8825: add disable jack detection support
ASoC: nau8825: add clock management for power saving

 sound/soc/codecs/nau8825.c | 49 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)
author
#1 lore raw

PATCH 1/3 ASoC: nau8825: add set_jack coponment support

Use set_jack ops to set jack for new machine drivers. Meanwhile, the old machine drivers can still call previous export function "nau8825_enable_jack_detect".

---
 sound/soc/codecs/nau8825.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +7 -0
index 67de0e49ccf4..c845f19b7c41 100644
@@ -2416,6 +2416,12 @@ static int __maybe_unused nau8825_resume(struct snd_soc_component *component)
 	return 0;
 }
 
+static int nau8825_set_jack(struct snd_soc_component *component,
+			    struct snd_soc_jack *jack, void *data)
+{
+	return nau8825_enable_jack_detect(component, jack);
+}
+
 static const struct snd_soc_component_driver nau8825_component_driver = {
 	.probe			= nau8825_component_probe,
 	.remove			= nau8825_component_remove,
@@ -2430,6 +2436,7 @@ static const struct snd_soc_component_driver nau8825_component_driver = {
 	.num_dapm_widgets	= ARRAY_SIZE(nau8825_dapm_widgets),
 	.dapm_routes		= nau8825_dapm_routes,
 	.num_dapm_routes	= ARRAY_SIZE(nau8825_dapm_routes),
+	.set_jack		= nau8825_set_jack,
 	.suspend_bias_off	= 1,
 	.idle_bias_on		= 1,
 	.use_pmdown_time	= 1,
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/3] ASoC: nau8825: add set_jack coponment support

typo in commit subject:
coponment -> component

please use scripts/checkpatch.pl --strict --codespell

Quoted 16 lines · David Lin

Use set_jack ops to set jack for new machine drivers. Meanwhile, the old machine drivers can still call previous export function "nau8825_enable_jack_detect".

---
 sound/soc/codecs/nau8825.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +0 -0
index 67de0e49ccf4..c845f19b7c41 100644

sound/soc/codecs/nau8825.c static int __maybe_unused nau8825_resume(struct snd_soc_component *component) · line 2424

Quoted 9 lines
sound/soc/codecs/nau8825.c +6 -0
@@ -2416,6 +2416,12 @@ static int __maybe_unused nau8825_resume(struct snd_soc_component *component)
 	return 0;
 }
 
+static int nau8825_set_jack(struct snd_soc_component *component,
+			    struct snd_soc_jack *jack, void *data)
+{
+	return nau8825_enable_jack_detect(component, jack);
+}
+

in some cases, this function can be called with a NULL jack argument. See other codec drivers, e.g.

int arizona_jack_set_jack(struct snd_soc_component *component,
struct snd_soc_jack *jack, void *data)

{
	struct arizona_priv *info = snd_soc_component_get_drvdata(component);

	if (jack)
		return arizona_jack_enable_jack_detect(info, jack);
	else
		return arizona_jack_disable_jack_detect(info);
}
#3 lore raw

Re: [PATCH 1/3] ASoC: nau8825: add set_jack coponment support

Quoted 4 lines · Pierre-Louis Bossart

typo in commit subject:
coponment -> component

please use scripts/checkpatch.pl --strict --codespell

I will be more carefully for next. I appreciate your kindly guide.

Quoted 32 lines · David Lin
Quoted 16 lines

Use set_jack ops to set jack for new machine drivers. Meanwhile, the old machine drivers can still call previous export function "nau8825_enable_jack_detect".

---
  sound/soc/codecs/nau8825.c | 7 +++++++
  1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +0 -0
index 67de0e49ccf4..c845f19b7c41 100644

sound/soc/codecs/nau8825.c static int __maybe_unused nau8825_resume(struct snd_soc_component *component) · line 2424

Quoted 9 lines
sound/soc/codecs/nau8825.c +6 -0
@@ -2416,6 +2416,12 @@ static int __maybe_unused nau8825_resume(struct snd_soc_component *component)
     return 0;
  }
 
+static int nau8825_set_jack(struct snd_soc_component *component,
+                        struct snd_soc_jack *jack, void *data)
+{
+    return nau8825_enable_jack_detect(component, jack);
+}
+

in some cases, this function can be called with a NULL jack argument. See other codec drivers, e.g.

int arizona_jack_set_jack(struct snd_soc_component *component,
struct snd_soc_jack *jack, void *data)

Quoted 8 lines
{
      struct arizona_priv *info = snd_soc_component_get_drvdata(component);

      if (jack)
              return arizona_jack_enable_jack_detect(info, jack);
      else
              return arizona_jack_disable_jack_detect(info);
}

I have caught these information from some codec driver, even sof machine driver also use snd_soc_component_set_jack to replace previous export function for jack setting.

Quoted 1 line

________________________________
________________________________
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

author
#4 lore raw

PATCH 2/3 ASoC: nau8825: add disable jack detection support

In reply to David Lin

A feature for disabling jack detection support.

---
 sound/soc/codecs/nau8825.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +7 -0
index c845f19b7c41..a356f26735bd 100644
@@ -1434,6 +1434,13 @@ int nau8825_enable_jack_detect(struct snd_soc_component *component,
 
 	nau8825->jack = jack;
 
+	if (!nau8825->jack) {
+		regmap_update_bits(regmap, NAU8825_REG_HSD_CTRL,
+				   NAU8825_HSD_AUTO_MODE | NAU8825_SPKR_DWN1R |
+				   NAU8825_SPKR_DWN1L, 0);
+		return 0;
+	}
+
 	/* Ground HP Outputs[1:0], needed for headset auto detection
 	 * Enable Automatic Mic/Gnd switching reading on insert interrupt[6]
 	 */
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH 2/3] ASoC: nau8825: add disable jack detection support

Quoted 14 lines · David Lin

A feature for disabling jack detection support.

---
 sound/soc/codecs/nau8825.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +0 -0
index c845f19b7c41..a356f26735bd 100644

sound/soc/codecs/nau8825.c int nau8825_enable_jack_detect(struct snd_soc_component *component, · line 1443

Quoted 10 lines
sound/soc/codecs/nau8825.c +7 -0
@@ -1434,6 +1434,13 @@ int nau8825_enable_jack_detect(struct snd_soc_component *component,
 
 	nau8825->jack = jack;
 
+	if (!nau8825->jack) {
+		regmap_update_bits(regmap, NAU8825_REG_HSD_CTRL,
+				   NAU8825_HSD_AUTO_MODE | NAU8825_SPKR_DWN1R |
+				   NAU8825_SPKR_DWN1L, 0);
+		return 0;
+	}
+

oh, so you've addressed my comment from the first patch but it might be clearer to follow the flow from other codec drivers and test the jack argument at a higher level, then you have an enable/disable parameter.

Quoted 4 lines
sound/soc/codecs/nau8825.c +0 -0
 	/* Ground HP Outputs[1:0], needed for headset auto detection
 	 * Enable Automatic Mic/Gnd switching reading on insert interrupt[6]
 	 */
#6 lore raw

Re: [PATCH 2/3] ASoC: nau8825: add disable jack detection support

Quoted 19 lines · Pierre-Louis Bossart
Quoted 17 lines · David Lin

A feature for disabling jack detection support.

---
  sound/soc/codecs/nau8825.c | 7 +++++++
  1 file changed, 7 insertions(+)
sound/soc/codecs/nau8825.c +0 -0
index c845f19b7c41..a356f26735bd 100644
@@ -1434,6 +1434,13 @@ int nau8825_enable_jack_detect(struct snd_soc_component *component,
 
     nau8825->jack = jack;
 
Quoted 10 lines

sound/soc/codecs/nau8825.c int nau8825_enable_jack_detect(struct snd_soc_component *component, · line 1443

Quoted 7 lines
sound/soc/codecs/nau8825.c +7 -0
+    if (!nau8825->jack) {
+            regmap_update_bits(regmap, NAU8825_REG_HSD_CTRL,
+                               NAU8825_HSD_AUTO_MODE | NAU8825_SPKR_DWN1R |
+                               NAU8825_SPKR_DWN1L, 0);
+            return 0;
+    }
+

oh, so you've addressed my comment from the first patch but it might be clearer to follow the flow from other codec drivers and test the jack argument at a higher level, then you have an enable/disable parameter.

Yes, I understand your thinking. You consider more clearly logic and readable for overall code.

Your suggestion make me with one target follow. I can do more plan for next.

Quoted 4 lines

sound/soc/codecs/nau8825.c int nau8825_enable_jack_detect(struct snd_soc_component *component, · line 1446

Quoted 4 lines
sound/soc/codecs/nau8825.c +0 -0
     /* Ground HP Outputs[1:0], needed for headset auto detection
      * Enable Automatic Mic/Gnd switching reading on insert interrupt[6]
      */

________________________________
________________________________
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

author
#7 lore raw

PATCH 3/3 ASoC: nau8825: add clock management for power saving

In reply to David Lin

Adjust dapm widget to manage clock from power event for power saving.

---
 sound/soc/codecs/nau8825.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
sound/soc/codecs/nau8825.c +33 -2
index a356f26735bd..eed017d5df4b 100644
@@ -47,6 +47,7 @@
 
 static int nau8825_configure_sysclk(struct nau8825 *nau8825,
 		int clk_id, unsigned int freq);
+static bool nau8825_is_jack_inserted(struct regmap *regmap);
 
 struct nau8825_fll {
 	int mclk_src;
@@ -981,6 +982,31 @@ static int nau8825_output_dac_event(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int system_clock_control(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *k, int  event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component);
+	struct regmap *regmap = nau8825->regmap;
+
+	if (SND_SOC_DAPM_EVENT_OFF(event)) {
+		dev_dbg(nau8825->dev, "system clock control : POWER OFF\n");
+		/* Set clock source to disable or internal clock before the
+		 * playback or capture end. Codec needs clock for Jack
+		 * detection and button press if jack inserted; otherwise,
+		 * the clock should be closed.
+		 */
+		if (nau8825_is_jack_inserted(regmap)) {
+			nau8825_configure_sysclk(nau8825,
+						 NAU8825_CLK_INTERNAL, 0);
+		} else {
+			nau8825_configure_sysclk(nau8825, NAU8825_CLK_DIS, 0);
+		}
+	}
+
+	return 0;
+}
+
 static int nau8825_biq_coeff_get(struct snd_kcontrol *kcontrol,
 				     struct snd_ctl_elem_value *ucontrol)
 {
@@ -1094,6 +1120,9 @@ static const struct snd_kcontrol_new nau8825_dacr_mux =
 static const struct snd_soc_dapm_widget nau8825_dapm_widgets[] = {
 	SND_SOC_DAPM_AIF_OUT("AIFTX", "Capture", 0, NAU8825_REG_I2S_PCM_CTRL2,
 		15, 1),
+	SND_SOC_DAPM_AIF_IN("AIFRX", "Playback", 0, SND_SOC_NOPM, 0, 0),
+	SND_SOC_DAPM_SUPPLY("System Clock", SND_SOC_NOPM, 0, 0,
+			    system_clock_control, SND_SOC_DAPM_POST_PMD),
 
 	SND_SOC_DAPM_INPUT("MIC"),
 	SND_SOC_DAPM_MICBIAS("MICBIAS", NAU8825_REG_MIC_BIAS, 8, 0),
@@ -1182,9 +1211,11 @@ static const struct snd_soc_dapm_route nau8825_dapm_routes[] = {
 	{"ADC", NULL, "ADC Clock"},
 	{"ADC", NULL, "ADC Power"},
 	{"AIFTX", NULL, "ADC"},
+	{"AIFTX", NULL, "System Clock"},
 
-	{"DDACL", NULL, "Playback"},
-	{"DDACR", NULL, "Playback"},
+	{"AIFRX", NULL, "System Clock"},
+	{"DDACL", NULL, "AIFRX"},
+	{"DDACR", NULL, "AIFRX"},
 	{"DDACL", NULL, "DDAC Clock"},
 	{"DDACR", NULL, "DDAC Clock"},
 	{"DACL Mux", "DACL", "DDACL"},
Signature · 1 line
2.25.1
maintainer
#8 lore raw
In reply to David Lin
Quoted 8 lines · David Lin

The series of features will make general and simple for new sof machine driver.

David Lin (3):
ASoC: nau8825: add set_jack coponment support
ASoC: nau8825: add disable jack detection support
ASoC: nau8825: add clock management for power saving

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: nau8825: add set_jack coponment support

      commit: c6167e10e76fb97d37613004046e66027b3a569b
[2/3] ASoC: nau8825: add disable jack detection support
      (no commit info)
[3/3] ASoC: nau8825: add clock management for power saving
      commit: 6133148ca08a097ed8c57d7f5a7826723273049b

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