Skip to contentSkip to conversation

Add ZTE ZTE zx-aud96p22 audio codec driver

PATCH Superseded Shawn Guo 2 participants 12 messages Jun 17, 2017 – Jun 21, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

cover Add ZTE ZTE zx-aud96p22 audio codec driver

From: Shawn Guo <[email protected]>

This is a pick-up of Baoyou's zx-aud96p22 audio codec driver submission [1], with quite some significant rework as below.

- Instead of hard-coding the GPIO used to control external amplifier, use generic devm_gpiod_get_optional() call to retrieve the GPIO defined in device tree.
- Rather than directly using I2C bus calls, use REGMAP_I2C interface which is more common for accessing codec register via I2C bus.
- Use snd_kcontrol_new infrastructural for Volume and Mute control.
- Use DAPM widget and route for various power bits control.
- A lot of code cleanups

[1] https://lkml.org/lkml/2017/2/15/170

Baoyou Xie (2):
ASoC: add bindings for ZTE zx-aud96p22 audio codec
ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

 .../devicetree/bindings/sound/zte,zx-aud96p22.txt  |  28 ++
 sound/soc/codecs/Kconfig                           |   5 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/zx_aud96p22.c                     | 425 +++++++++++++++++++++
 4 files changed, 460 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/zte,zx-aud96p22.txt
 create mode 100644 sound/soc/codecs/zx_aud96p22.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 ASoC: add bindings for ZTE zx-aud96p22 audio codec

From: Baoyou Xie <[email protected]>

It adds dt-bindings document for ZTE zx-aud96p22 audio codec.

---
 .../devicetree/bindings/sound/zte,zx-aud96p22.txt  | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/zte,zx-aud96p22.txt
Documentation/devicetree/bindings/sound/zte,zx-aud96p22.txt new file +28 -0
new file mode 100644
index 000000000000..cb211a295cad
@@ -0,0 +1,28 @@
+ZTE ZX AUD96P22 Audio Codec
+
+Required properties:
+ - compatible: Must be "zte,zx-aud96p22"
+ - #sound-dai-cells: Should be 0
+ - reg: I2C bus slave address of AUD96P22
+
+Optional properties:
+ - zte,pa-gpios: The GPIO to enable external power amplifier
+
+Example:
+
+	i2c0: i2c at 1486000 {
+		compatible = "zte,zx296718-i2c";
+		reg = <0x01486000 0x1000>;
+		interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		clocks = <&audiocrm AUDIO_I2C0_WCLK>;
+		clock-frequency = <1600000>;
+
+		aud96p22: codec at 22 {
+			compatible = "zte,zx-aud96p22";
+			#sound-dai-cells = <0>;
+			reg = <0x22>;
+			zte,pa-gpios = <&bgpio4 0 GPIO_ACTIVE_HIGH>;
+		};
+	};
Signature · 1 line
1.9.1
author
#6 lore raw

PATCH 2/2 ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

In reply to Shawn Guo

From: Baoyou Xie <[email protected]>

It adds ASoC driver for AUD96P22 stereo audio codec integrated on ZTE ZX family SoCs. The driver includes the support for a number of volume and mute controls, and power bits for various playback and recording components.

Due to that the board for testing only supports playback, recording support is untested.

---
 sound/soc/codecs/Kconfig       |   5 +
 sound/soc/codecs/Makefile      |   2 +
 sound/soc/codecs/zx_aud96p22.c | 425 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 432 insertions(+)
 create mode 100644 sound/soc/codecs/zx_aud96p22.c
sound/soc/codecs/Kconfig +5 -0
index 883ed4c8a551..3425bbcea2d1 100644
@@ -1114,6 +1114,11 @@ config SND_SOC_WM9713
 	tristate
 	select REGMAP_AC97
 
+config SND_SOC_ZX_AUD96P22
+	tristate "ZTE ZX AUD96P22 CODEC"
+	depends on I2C
+	select REGMAP_I2C
+
 # Amp
 config SND_SOC_LM4857
 	tristate
sound/soc/codecs/Makefile +2 -0
index 28a63fdaf982..d9858be7796a 100644
@@ -224,6 +224,7 @@ snd-soc-wm9705-objs := wm9705.o
 snd-soc-wm9712-objs := wm9712.o
 snd-soc-wm9713-objs := wm9713.o
 snd-soc-wm-hubs-objs := wm_hubs.o
+snd-soc-zx-aud96p22-objs := zx_aud96p22.o
 # Amp
 snd-soc-dio2125-objs := dio2125.o
 snd-soc-max9877-objs := max9877.o
@@ -455,6 +456,7 @@ obj-$(CONFIG_SND_SOC_WM9712)	+= snd-soc-wm9712.o
 obj-$(CONFIG_SND_SOC_WM9713)	+= snd-soc-wm9713.o
 obj-$(CONFIG_SND_SOC_WM_ADSP)	+= snd-soc-wm-adsp.o
 obj-$(CONFIG_SND_SOC_WM_HUBS)	+= snd-soc-wm-hubs.o
+obj-$(CONFIG_SND_SOC_ZX_AUD96P22) += snd-soc-zx-aud96p22.o
 
 # Amp
 obj-$(CONFIG_SND_SOC_DIO2125)	+= snd-soc-dio2125.o
sound/soc/codecs/zx_aud96p22.c new file +425 -0

425 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH 1/2] ASoC: add bindings for ZTE zx-aud96p22 audio codec

In reply to Shawn Guo
Quoted 2 lines · Shawn Guo

+Optional properties:
+ - zte,pa-gpios: The GPIO to enable external power amplifier

If there's an external power amplifier this is a separate chip to this
CODEC and should therefore be separately controlled and integrated as
part of the machine integration.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170619/b2ff6e53/attachment.sig>

maintainer
#7 lore raw

Re: [PATCH 2/2] ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

In reply to Shawn Guo

sound/soc/codecs/zx_aud96p22.c line 95

Quoted 3 lines · Shawn Guo
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Mute control */
+	SOC_DOUBLE("Playback Master Mute", AUD96P22_MUTE_2, 0, 1, 1, 0),
+	SOC_DOUBLE("Headset Mute", AUD96P22_MUTE_2, 4, 5, 1, 0),

As covered in ControlNames.txt mute and other on/off controls should be named ending in Switch so UIs know what to do with them.

sound/soc/codecs/zx_aud96p22.c line 309

Quoted 8 lines
sound/soc/codecs/zx_aud96p22.c new file +8 -0
+static int aud96p22_startup(struct snd_pcm_substream *substream,
+			    struct snd_soc_dai *dai)
+{
+	struct aud96p22_priv *priv = snd_soc_codec_get_drvdata(dai->codec);
+	struct regmap *regmap = priv->regmap;
+
+	/* Overall power-up */
+	regmap_update_bits(regmap, AUD96P22_PD_0, PD_0_PDZ, PD_0_PDZ);

Why is this not done with DAPM?

sound/soc/codecs/zx_aud96p22.c line 313

Quoted 3 lines
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Reset ADC and DAC path */
+	regmap_write(regmap, AUD96P22_RESET, 0x0);
+	regmap_write(regmap, AUD96P22_RESET, 0x3);

What does this mean?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170619/43a45f64/attachment.sig>

author
#3 lore raw

Re: [PATCH 1/2] ASoC: add bindings for ZTE zx-aud96p22 audio codec

In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 2 lines · Shawn Guo

+Optional properties:
+ - zte,pa-gpios: The GPIO to enable external power amplifier

If there's an external power amplifier this is a separate chip to this CODEC and should therefore be separately controlled and integrated as part of the machine integration.

Yes, that should be the best. But we do not have a particular machine driver for our platform, and we are using simple-audio-card driver instead. I'm not sure if it's generic enough to patch simple-audio-card driver support this pa-gpios, so chose to fold this quick change in the codec driver.

Should I patch simple-audio-card driver to support pa-gpios property and create a DAPM widget with event for it? I'm currently using SND_SOC_DAPM_OUT_DRV_E. Is it the correct one?

Shawn

author
#8 lore raw

Re: [PATCH 2/2] ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

In reply to Mark Brown

Hi Mark,

Thanks for the reviewing.

Quoted 8 lines · Mark Brown

sound/soc/codecs/zx_aud96p22.c line 95

Quoted 3 lines · Shawn Guo
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Mute control */
+	SOC_DOUBLE("Playback Master Mute", AUD96P22_MUTE_2, 0, 1, 1, 0),
+	SOC_DOUBLE("Headset Mute", AUD96P22_MUTE_2, 4, 5, 1, 0),

As covered in ControlNames.txt mute and other on/off controls should be named ending in Switch so UIs know what to do with them.

Oh, thanks for the info. I did not know that before.

Quoted 11 lines

sound/soc/codecs/zx_aud96p22.c line 309

Quoted 9 lines
sound/soc/codecs/zx_aud96p22.c new file +8 -0
+static int aud96p22_startup(struct snd_pcm_substream *substream,
+			    struct snd_soc_dai *dai)
+{
+	struct aud96p22_priv *priv = snd_soc_codec_get_drvdata(dai->codec);
+	struct regmap *regmap = priv->regmap;
+
+	/* Overall power-up */
+	regmap_update_bits(regmap, AUD96P22_PD_0, PD_0_PDZ, PD_0_PDZ);

Why is this not done with DAPM?

As this is a overall power bit, which is not for any specific component. I'm not sure which DAPM widget should be used for it, and how it should be arranged in the widget route. Any suggestion or example will be appreciated.

Quoted 6 lines

sound/soc/codecs/zx_aud96p22.c line 313

Quoted 4 lines
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Reset ADC and DAC path */
+	regmap_write(regmap, AUD96P22_RESET, 0x0);
+	regmap_write(regmap, AUD96P22_RESET, 0x3);

What does this mean?

It's a de-assert/assert of ADC and DAC reset. I will add proper defines for the bits to make this clear.

Shawn

maintainer
#9 lore raw

Re: [PATCH 2/2] ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

Quoted 8 lines · Shawn Guo
Quoted 6 lines · Mark Brown

sound/soc/codecs/zx_aud96p22.c line 309

Quoted 2 lines · Shawn Guo
sound/soc/codecs/zx_aud96p22.c new file +2 -0
+	/* Overall power-up */
+	regmap_update_bits(regmap, AUD96P22_PD_0, PD_0_PDZ, PD_0_PDZ);

Why is this not done with DAPM?

Quoted 4 lines

As this is a overall power bit, which is not for any specific component. I'm not sure which DAPM widget should be used for it, and how it should be arranged in the widget route. Any suggestion or example will be appreciated.

Sounds like a fairly standard use for a supply widget.

Quoted 8 lines
Quoted 5 lines

sound/soc/codecs/zx_aud96p22.c line 313

Quoted 3 lines
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Reset ADC and DAC path */
+	regmap_write(regmap, AUD96P22_RESET, 0x0);
+	regmap_write(regmap, AUD96P22_RESET, 0x3);

What does this mean?

It's a de-assert/assert of ADC and DAC reset. I will add proper defines for the bits to make this clear.

Why are we resetting these - won't this loose settings? And if it's
just something to be done as part of starting the DAC and ADC why isn't
it done via DAPM?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170620/6b593e76/attachment-0001.sig>

maintainer
#4 lore raw

Re: [PATCH 1/2] ASoC: add bindings for ZTE zx-aud96p22 audio codec

In reply to Shawn Guo
Quoted 8 lines · Shawn Guo
Quoted 3 lines · Mark Brown

If there's an external power amplifier this is a separate chip to this CODEC and should therefore be separately controlled and integrated as part of the machine integration.

Yes, that should be the best. But we do not have a particular machine driver for our platform, and we are using simple-audio-card driver

You should be switching to the of-graph card now.

Quoted 3 lines

instead. I'm not sure if it's generic enough to patch simple-audio-card driver support this pa-gpios, so chose to fold this quick change in the codec driver.

Having a separate amplifier is a completely normal thing, and no matter how unusual something is it's obviously not OK to hack one driver to support a completely different device.

Quoted 3 lines

Should I patch simple-audio-card driver to support pa-gpios property and create a DAPM widget with event for it? I'm currently using SND_SOC_DAPM_OUT_DRV_E. Is it the correct one?

Should be fine.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170620/75386a12/attachment.sig>

author
#5 lore raw

Re: [PATCH 1/2] ASoC: add bindings for ZTE zx-aud96p22 audio codec

Quoted 11 lines · Mark Brown
Quoted 8 lines · Shawn Guo
Quoted 3 lines · Mark Brown

If there's an external power amplifier this is a separate chip to this CODEC and should therefore be separately controlled and integrated as part of the machine integration.

Yes, that should be the best. But we do not have a particular machine driver for our platform, and we are using simple-audio-card driver

You should be switching to the of-graph card now.

Thanks for the info. Will do.

Quoted 7 lines
Quoted 3 lines

instead. I'm not sure if it's generic enough to patch simple-audio-card driver support this pa-gpios, so chose to fold this quick change in the codec driver.

Having a separate amplifier is a completely normal thing, and no matter how unusual something is it's obviously not OK to hack one driver to support a completely different device.

Okay, I will drop it from codec driver, and try to support it in audio-graph-card with separate patch later.

Shawn

author
#10 lore raw

Re: [PATCH 2/2] ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 7 lines · Shawn Guo
Quoted 6 lines · Mark Brown

sound/soc/codecs/zx_aud96p22.c line 309

Quoted 2 lines · Shawn Guo
sound/soc/codecs/zx_aud96p22.c new file +2 -0
+	/* Overall power-up */
+	regmap_update_bits(regmap, AUD96P22_PD_0, PD_0_PDZ, PD_0_PDZ);

Why is this not done with DAPM?

Quoted 6 lines
Quoted 4 lines

As this is a overall power bit, which is not for any specific component. I'm not sure which DAPM widget should be used for it, and how it should be arranged in the widget route. Any suggestion or example will be appreciated.

Sounds like a fairly standard use for a supply widget.

Yes, it can be a supply widget. But it's a bit that controls device overall power rather than any particular component power. Since every single operation of the device will need this power bit to be on, I think it makes sense to configure the bit in .startup/.shutdown hooks, rather than creating a widget for it and attaches the widget to a bunch of components.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

sound/soc/codecs/zx_aud96p22.c line 313

Quoted 4 lines
sound/soc/codecs/zx_aud96p22.c new file +3 -0
+	/* Reset ADC and DAC path */
+	regmap_write(regmap, AUD96P22_RESET, 0x0);
+	regmap_write(regmap, AUD96P22_RESET, 0x3);

What does this mean?

It's a de-assert/assert of ADC and DAC reset. I will add proper defines for the bits to make this clear.

Why are we resetting these - won't this loose settings?

It only resets some hardware internal states, and software settings won't be affected.

Quoted 3 lines

And if it's
just something to be done as part of starting the DAC and ADC why isn't it done via DAPM?

Yes, it sounds like a better approach. Will try to do that.

Shawn

maintainer
#11 lore raw

Re: [PATCH 2/2] ASoC: zx_aud96p22: add ZTE ZX AUD96P22 codec driver

Quoted 10 lines · Shawn Guo
Quoted 1 line · Mark Brown

Sounds like a fairly standard use for a supply widget.

Yes, it can be a supply widget. But it's a bit that controls device overall power rather than any particular component power. Since every single operation of the device will need this power bit to be on, I think it makes sense to configure the bit in .startup/.shutdown hooks, rather than creating a widget for it and attaches the widget to a bunch of components.

Do it with DAPM - this means any analogue paths will work and there's no
possibility of refcounting issues. You will need to create a bunch of
links but that's pretty easy and it's all data rather than code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170621/0d62222a/attachment.sig>