Skip to contentSkip to conversation

ASoC: codecs: ak4619: Add PDN pin handling

PATCH In review Alexander Koch 3 participants 5 messages Sep 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: codecs: ak4619: Add PDN pin handling

The AK4619 datasheet describes the functionality of the power down (PDN) pin as follows (p. 39, 'Power-up/down Sequence'):

The AK4619 should be powered up when the PDN pin = "L". The PDN pin should be set "H" after all power supplies have ramped up. At that point, the reference voltage generator block (REFBLK) and LDO (AVDRV) circuit are powered up and the control registers are initialized. Control register settings should be no less than 10ms after PDN pin = "H".

The current implementation of the driver does not operate the PDN pin in any way, it seems to rely on external control of the pin.

Improve this by adding a device tree binding to enable the driver to set the pin 'high' during probe. Make it optional to keep the behaviour for existing device trees unchanged.

Tested on an i.MX8MM board with the AK4619 connected to GPIO1 and SSI3.

Changed in v2:
- Fix typo in bindings update subject
- Fix missing #include in example block for dt binding YAML
- Improve property description in binding YAML
- Switch property name to commonly used 'powerdown-gpios'
- Invert GPIO logic to avoid confusion (the pin is called 'power down' but when driven high the chip is powered _up_)
- Fix power leak on error after GPIO is acquired by turning the codec off again

Alexander Koch (2):
ASoC: codecs: ak4619: Add optional powerdown GPIO
ASoC: dt-bindings: asahi-kasei,ak4619: Add powerdown GPIO

 .../bindings/sound/asahi-kasei,ak4619.yaml          | 10 ++++++++++
 sound/soc/codecs/ak4619.c                           | 13 +++++++++++++
 2 files changed, 23 insertions(+)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/2 ASoC: codecs: ak4619: Add optional powerdown GPIO

Add optional device tree binding that enables operation of the 'PDN' pin during initialization:

    codec@10 {
        compatible = "asahi-kasei,ak4619";
        reg = <0x10>;
        powerdown-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;  // <--
        #sound-dai-cells = <0>;
    };

If defined, PDN is set high during driver probe, followed by a 10 ms delay as required before first register access [1].

If no 'powerdown-gpios' is defined, the behaviour is unchanged.

[1] AK4619 datasheet, sec. 2 'Power-up/down Sequence', page 39

---
 sound/soc/codecs/ak4619.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
sound/soc/codecs/ak4619.c +13 -0
index d9c9f6b20028..c4f0db1e51c8 100644
@@ -152,6 +152,7 @@
 struct ak4619_priv {
 	struct regmap *regmap;
 	struct snd_pcm_hw_constraint_list constraint;
+	struct gpio_desc *pdn_gpio;
 	int deemph_en;
 	unsigned int playback_rate;
 	unsigned int sysclk;
@@ -875,10 +876,20 @@ static int ak4619_i2c_probe(struct i2c_client *i2c)
 
 	i2c_set_clientdata(i2c, ak4619);
 
+	ak4619->pdn_gpio = devm_gpiod_get_optional(dev, "powerdown",
+		GPIOD_OUT_LOW);
+	if (IS_ERR(ak4619->pdn_gpio))
+		return dev_err_probe(dev, PTR_ERR(ak4619->pdn_gpio),
+			"powerdown GPIO request failed\n");
+	if (ak4619->pdn_gpio)
+		msleep(10);
+
 	ak4619->regmap = devm_regmap_init_i2c(i2c, &ak4619_regmap_cfg);
 	if (IS_ERR(ak4619->regmap)) {
 		ret = PTR_ERR(ak4619->regmap);
 		dev_err(dev, "regmap_init() failed: %d\n", ret);
+		if (ak4619->pdn_gpio)
+			gpiod_set_value_cansleep(ak4619->pdn_gpio, 1);
 		return ret;
 	}
 
@@ -887,6 +898,8 @@ static int ak4619_i2c_probe(struct i2c_client *i2c)
 	if (ret < 0) {
 		dev_err(dev, "Failed to register ak4619 component: %d\n",
 			ret);
+		if (ak4619->pdn_gpio)
+			gpiod_set_value_cansleep(ak4619->pdn_gpio, 1);
 		return ret;
 	}
 
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v2 1/2] ASoC: codecs: ak4619: Add optional powerdown GPIO

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] ASoC: ak4619: missing power-down GPIO assertion on unbind - [Low] ASoC: ak4619: missing…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] ASoC: ak4619: missing power-down GPIO assertion on unbind
- [Low] ASoC: ak4619: missing inclusion of <linux/delay.h> for msleep()
--

commit 1a6c5d3bb52b0196ff6b96586fdeceef456751a9
Author: Alexander Koch <[email protected]>

ASoC: codecs: ak4619: Add optional powerdown GPIO

This commit adds an optional 'powerdown-gpios' device tree binding. If defined, the PDN pin is configured during probe with a delay prior to register access.

Quoted 4 lines
sound/soc/codecs/ak4619.c +0 -0
index d9c9f6b200284..c4f0db1e51c8d 100644

[ ... ]

sound/soc/codecs/ak4619.c static int ak4619_i2c_probe(struct i2c_client *i2c) · line 885

Quoted 11 lines
sound/soc/codecs/ak4619.c +7 -0
@@ -875,10 +876,20 @@ static int ak4619_i2c_probe(struct i2c_client *i2c)
 
 	i2c_set_clientdata(i2c, ak4619);
 
+	ak4619->pdn_gpio = devm_gpiod_get_optional(dev, "powerdown",
+		GPIOD_OUT_LOW);
+	if (IS_ERR(ak4619->pdn_gpio))
+		return dev_err_probe(dev, PTR_ERR(ak4619->pdn_gpio),
+			"powerdown GPIO request failed\n");
+	if (ak4619->pdn_gpio)
+		msleep(10);

[Severity: Low]
Does this code rely on transitive header inclusions for msleep()? It appears that <linux/delay.h> is not explicitly included in this file, which might cause build failures if core headers are refactored.

[ ... ]

sound/soc/codecs/ak4619.c static int ak4619_i2c_probe(struct i2c_client *i2c) · line 905

Quoted 9 lines
sound/soc/codecs/ak4619.c +2 -0
@@ -887,6 +898,8 @@ static int ak4619_i2c_probe(struct i2c_client *i2c)
 	if (ret < 0) {
 		dev_err(dev, "Failed to register ak4619 component: %d\n",
 			ret);
+		if (ak4619->pdn_gpio)
+			gpiod_set_value_cansleep(ak4619->pdn_gpio, 1);
 		return ret;
 	}
 

[Severity: Medium]
Will the device remain permanently powered on if the module is unloaded or unbound? The probe error paths correctly revert the GPIO state to 1 to power down the device, but ak4619_i2c_driver lacks a .remove callback to handle the unbind path.

Could this state leak be addressed by using devm_add_action_or_reset() during ak4619_i2c_probe() to ensure teardown symmetry when the device is unbound?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v2 2/2 ASoC: dt-bindings: asahi-kasei,ak4619: Add powerdown GPIO

In reply to Alexander Koch

Add documentation for an optional property that enables operation of the 'PDN' (powerdown) pin during initialization:

    codec@10 {
        compatible = "asahi-kasei,ak4619";
        reg = <0x10>;
        powerdown-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;  // <--
        #sound-dai-cells = <0>;
    };
---
 .../devicetree/bindings/sound/asahi-kasei,ak4619.yaml  | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/sound/asahi-kasei,ak4619.yaml +10 -0
index d412531ef9a2..86e0b8cbfc29 100644
@@ -34,6 +34,12 @@ properties:
     $ref: audio-graph-port.yaml#
     unevaluatedProperties: false
 
+  powerdown-gpios:
+    maxItems: 1
+    description:
+      GPIO connected to the 'PDN' pin, if any. Needs to be set low to
+      power down the codec, hence the GPIO must be GPIO_ACTIVE_LOW.
+
 required:
   - compatible
   - reg
@@ -42,6 +48,8 @@ unevaluatedProperties: false
 
 examples:
   - |
+    #include <dt-bindings/gpio/gpio.h>
+
     i2c {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -49,6 +57,8 @@ examples:
             compatible = "asahi-kasei,ak4619";
             reg = <0x10>;
 
+            powerdown-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
+
             clocks = <&rcar_sound>;
             clock-names = "mclk";
 
Signature · 1 line
2.55.0
maintainer
#4 lore raw
In reply to Alexander Koch
Quoted 5 lines · Alexander Koch

ASoC: codecs: ak4619: Add PDN pin handling

The AK4619 datasheet describes the functionality of the power down (PDN) pin as follows (p. 39, 'Power-up/down Sequence'):

Quoted 8 lines

The AK4619 should be powered up when the PDN pin = "L". The PDN pin should be set "H" after all power supplies have ramped up. At that point, the reference voltage generator block (REFBLK) and LDO (AVDRV) circuit are powered up and the control registers are initialized. Control register settings should be no less than 10ms after PDN pin = "H".

[...]

Applied to

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

Thanks!

[1/2] ASoC: codecs: ak4619: Add optional powerdown GPIO

      https://git.kernel.org/broonie/sound/c/f38638f5181a
[2/2] ASoC: dt-bindings: asahi-kasei,ak4619: Add powerdown GPIO
      https://git.kernel.org/broonie/sound/c/b224c8932773

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