Skip to contentSkip to conversation

ASoC: Add support for GPIOs driven amplifiers

PATCH Superseded Herve Codina 4 participants 20 messages Mar 30 – Apr 10

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: Add support for GPIOs driven amplifiers

On some embedded system boards, audio amplifiers are designed using discrete components such as op-amp, several resistors and switches to either adjust the gain (switching resistors) or fully switch the audio signal path (mute and/or bypass features).

Those switches are usually driven by simple GPIOs.

This kind of amplifiers are not handled in ASoC and the fallback is to let the user-space handle those GPIOs out of the ALSA world.

In order to have those kind of amplifiers fully integrated in the audio stack, this series introduces the audio-gpio-amp to handle them.

This new ASoC component allows to have the amplifiers seen as ASoC auxiliarty devices and so it allows to control them through audio mixer controls.

Best regards,
Hervé

Herve Codina (4):
of: Introduce of_property_read_s32_index()
ASoC: dt-bindings: Add support for the GPIOs driven amplifier
ASoC: codecs: Add support for the GPIOs driven amplifier
MAINTAINERS: Add the ASoC gpio amplifier entry

 .../bindings/sound/audio-gpio-amp.yaml        | 309 +++++++
 MAINTAINERS                                   |   7 +
 include/linux/of.h                            |   7 +
 sound/soc/codecs/Kconfig                      |  12 +
 sound/soc/codecs/Makefile                     |   2 +
 sound/soc/codecs/audio-gpio-amp.c             | 765 ++++++++++++++++++
 6 files changed, 1102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml
 create mode 100644 sound/soc/codecs/audio-gpio-amp.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/4 of: Introduce of_property_read_s32_index()

Signed integers can be read from single value properties using of_property_read_s32() but nothing exist to read signed integers from multi-value properties.

Fix this lack adding of_property_read_s32_index().

---
 include/linux/of.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/of.h +7 -0
index be6ec4916adf..526c1ee819cd 100644
@@ -1457,6 +1457,13 @@ static inline int of_property_read_s32(const struct device_node *np,
 	return of_property_read_u32(np, propname, (u32*) out_value);
 }
 
+static inline int of_property_read_s32_index(const struct device_node *np,
+					     const char *propname, u32 index,
+					     s32 *out_value)
+{
+	return of_property_read_u32_index(np, propname, index, (u32 *)out_value);
+}
+
 #define of_for_each_phandle(it, err, np, ln, cn, cc)			\
 	for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)),	\
 	     err = of_phandle_iterator_next(it);			\
Signature · 1 line
2.53.0
maintainer Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] of: Introduce of_property_read_s32_index()

Quoted 11 lines · Herve Codina

Signed integers can be read from single value properties using of_property_read_s32() but nothing exist to read signed integers from multi-value properties.

Fix this lack adding of_property_read_s32_index().

---
 include/linux/of.h | 7 +++++++
 1 file changed, 7 insertions(+)
#3 lore raw

PATCH 2/4 ASoC: dt-bindings: Add support for the GPIOs driven amplifier

In reply to Herve Codina

Some amplifiers based on analog switches and op-amps can be present in the audio path and can be driven by GPIOs in order to control their gain value, their mute and/or bypass functions.

Those components needs to be viewed as audio components in order to be fully integrated in the audio path.

audio-gpio-amplifier allows to consider these GPIO driven amplifiers as auxiliary audio devices.

---
 .../bindings/sound/audio-gpio-amp.yaml        | 309 ++++++++++++++++++
 1 file changed, 309 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +309 -0
new file mode 100644
index 000000000000..15dc898f8574
@@ -0,0 +1,309 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/audio-gpio-amp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Audio amplifier driven by GPIOs
+
+maintainers:
+  - Herve Codina <[email protected]>
+
+description: |
+  Audio GPIO amplifiers are driven by GPIO in order to control the gain value
+  of the amplifier, its mute function and/or its bypass function.
+
+  Those amplifiers are based on discrete components (analog switches, op-amps
+  and more) where some of them, mostly analog switches, are controlled by GPIOs
+  to adjust the gain value of the whole amplifier and/or to control
+  the mute and/or bypass function.
+
+  For instance, the following piece of hardware is a GPIO amplifier
+
+                                         +5VA
+                                           ^
+                                        |\ |
+                                        | \
+        Vin >---------------------------|+ \
+                                        |   +-------+-----> Vout
+                .--\/\/\/--+------------|- /        |
+                |          |            | /         |
+                v          |            |/ |        |
+               GND         o               v        |
+                            \             GND       |
+       gpio >----------->    \                      |
+                         o    o                     |
+                         |    |                     |
+                         |    '--\/\/\/--.          |
+                         |               +--\/\/\/--'
+                         '---------------'
+
+  A GPIO driven amplifier can work in several mode depending on the electronic
+  design.
+    - points defined:
+        The values of GPIOs used to control gain set a specific gain value
+        without any specific relationship between each value. For instance,
+        using 2 GPIOS:
+          0b00 <-> -10.0 dB
+          0b01 <-> +3.0 dB
+          0b10 <-> 0 dB
+          0b11 <-> +6.0 dB
+
+        This can be described using the gain-points property.
+
+    - range defined:
+        The values of GPIOs used to control gain set a specific gain value
+        following a linear dB range from a minimum dB value to a maximum dB
+        value. For instance, using 2 GPIOS:
+          0b00 <-> -3.0 dB
+          0b01 <-> 0 db
+          0b10 <-> +3.0 dB
+          0b11 <-> +6.0 dB
+
+        This can be described using the gain-range property.
+
+    - labels defined:
+        Some electronic design are not meant to a specific dB gain value. In
+        that case it is relevant to use labels to describe them. For instance,
+        using 2 GPIOS:
+          0b00 <-> Low boost
+          0b01 <-> Middle boost
+          0b10 <-> High boost
+          0b11 <-> Max boost
+
+        This can be described using the gain-labels property
+
+properties:
+  compatible:
+    const: audio-gpio-amp
+
+  vdd-supply:
+    description: Main power supply of the amplifier
+
+  vddio-supply:
+    description: Power supply related to the control path
+
+  vdda1-supply:
+    description: Analog power supply
+
+  vdda2-supply:
+    description: Additional analog power supply
+
+  mute-gpios:
+    description: GPIO to control the mute function
+    maxItems: 1
+
+  bypass-gpios:
+    description: GPIO to control the bypass function
+    maxItems: 1
+
+  gain-gpios:
+    description: |
+      GPIOs to control the amplifier gain
+
+      The gain value is computed from GPIOs value from 0 to 2^N-1 with N the
+      number of GPIO described. The first GPIO described is the lsb of the gain
+      value.
+
+      For instance assuming 2 gpios
+         gain-gpios = <&gpio1 GPIO_ACTIVE_HIGH> <&gpio2 GPIO_ACTIVE_HIGH>;
+      The gain value will be the following:
+
+          gpio1 | gpio2 | gain
+          ------+-------+-----
+            0   |    0  | 0b00 -> 0
+            1   |    0  | 0b01 -> 1
+            0   |    1  | 0b10 -> 2
+            1   |    1  | 0b11 -> 3
+          ------+-------+-----
+
+      Note: The gain value, bits set to 1 or 0, indicate the state active (bit
+            set) or the state inactive (bit unset) of the related GPIO. The
+            physical voltage corresponding to this active/inactive state is
+            given by the GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags.
+
+    minItems: 1
+    maxItems: 32
+
+  gain-points:
+    $ref: /schemas/types.yaml#/definitions/int32-matrix
+    items:
+      items:
+        - description: The GPIOs value
+        - description: The related amplifier gain in 0.01 dB unit
+    minItems: 2
+    description: |
+      List of the GPIOs value / Gain value in dB pair defining the gain
+      set on each GPIOs value.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that GPIOs values set the hardware gains according to the
+      following table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | -10.0 dB
+           1   | +3.0 dB
+           2   | 0 dB
+           3   | +6.0 dB
+         ------+--------------
+
+      The description using gain points can be:
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+
+  gain-range:
+    $ref: /schemas/types.yaml#/definitions/int32-array
+    items:
+      - description: Gain in 0.01 dB unit when all GPIOs are inactive
+      - description: Gain in 0.01 dB unit when all GPIOs are active
+    description: |
+      Gains (in 0.01 dB unit) set by the extremum (minimal and maximum) value
+      of GPIOs. The following formula must be satisfied.
+
+               gain-range[1] - gain-range[0]
+      Gain  = ------------------------------- x GPIO_value + gain-range[0]
+                        2^N - 1
+
+      With N, the number of GPIOs used to control the gain and Gain computed in
+      0.01 dB unit.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware 1    | Hardware 2
+         value | amplification | amplification
+         ------+---------------+---------------
+           0   | -3.0 dB       |  +10.0 dB
+           1   | 0 dB          |  +5.0 dB
+           2   | +3.0 dB       |  0 dB
+           3   | +6.0 dB       |  -5.0 dB
+         ------+---------------+---------------
+
+      The description for hardware 1 using a gain range can be:
+        gain-range = <(-300) 600>;
+
+      The description for hardware 2 using a gain range can be:
+        gain-range = <1000 (-500)>;
+
+  gain-labels:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description: |
+      List of the gain labels attached to the combination of GPIOs controlling
+      the gain. The first label is related to the gain value 0, the second label
+      is related to the gain value 1 and so on.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | Low
+           1   | Middle
+           2   | High
+           3   | Max
+         ------+--------------
+
+      The description using gain labels can be:
+        gain-labels = "Low", "Middle", "High", "Max";
+
+dependencies:
+  gain-points: [ gain-gpios ]
+  gain-range: [ gain-gpios ]
+  gain-labels: [ gain-gpios ]
+
+required:
+  - compatible
+  - vdd-supply
+
+anyOf:
+  - required:
+      - gain-gpios
+  - required:
+      - mute-gpios
+  - required:
+      - bypass-gpios
+
+allOf:
+  - $ref: dai-common.yaml#
+  - if:
+      required:
+        - gain-points
+    then:
+      properties:
+        gain-range: false
+        gain-labels: false
+  - if:
+      required:
+        - gain-range
+    then:
+      properties:
+        gain-points: false
+        gain-labels: false
+  - if:
+      required:
+        - gain-labels
+    then:
+      properties:
+        gain-points: false
+        gain-range: false
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    /* Gain controlled by gpios */
+    amplifier0 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+    };
+
+    /* Gain controlled by gpio using range */
+    amplifier1 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-range = <(-300) 600>;
+    };
+
+    /* Gain controlled by gpio using points */
+    amplifier2 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+    };
+
+    /* Gain controlled by gpio with labels */
+    amplifier3 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+        gain-labels = "Low", "High";
+    };
+
+    /* A mutable amplifier without any gain control */
+    amplifier4 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        mute-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+    };
+
+    /*  Several supplies, gain controlled using range, mute and bypass */
+    amplifier5 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        vddio-supply = <&regulator1>;
+        vdda1-supply = <&regulator2>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-range = <(-300) 600>;
+        mute-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
+        bypass-gpios = <&gpio 3 GPIO_ACTIVE_HIGH>;
+    };
+...
Signature · 1 line
2.53.0
maintainer
#4 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Quoted 90 lines · Herve Codina

Some amplifiers based on analog switches and op-amps can be present in the audio path and can be driven by GPIOs in order to control their gain value, their mute and/or bypass functions.

Those components needs to be viewed as audio components in order to be fully integrated in the audio path.

audio-gpio-amplifier allows to consider these GPIO driven amplifiers as auxiliary audio devices.

---
 .../bindings/sound/audio-gpio-amp.yaml        | 309 ++++++++++++++++++
 1 file changed, 309 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +68 -0
new file mode 100644
index 000000000000..15dc898f8574
@@ -0,0 +1,309 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/audio-gpio-amp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Audio amplifier driven by GPIOs
+
+maintainers:
+  - Herve Codina <[email protected]>
+
+description: |
+  Audio GPIO amplifiers are driven by GPIO in order to control the gain value
+  of the amplifier, its mute function and/or its bypass function.
+
+  Those amplifiers are based on discrete components (analog switches, op-amps
+  and more) where some of them, mostly analog switches, are controlled by GPIOs
+  to adjust the gain value of the whole amplifier and/or to control
+  the mute and/or bypass function.
+
+  For instance, the following piece of hardware is a GPIO amplifier
+
+                                         +5VA
+                                           ^
+                                        |\ |
+                                        | \
+        Vin >---------------------------|+ \
+                                        |   +-------+-----> Vout
+                .--\/\/\/--+------------|- /        |
+                |          |            | /         |
+                v          |            |/ |        |
+               GND         o               v        |
+                            \             GND       |
+       gpio >----------->    \                      |
+                         o    o                     |
+                         |    |                     |
+                         |    '--\/\/\/--.          |
+                         |               +--\/\/\/--'
+                         '---------------'
+
+  A GPIO driven amplifier can work in several mode depending on the electronic
+  design.
+    - points defined:
+        The values of GPIOs used to control gain set a specific gain value
+        without any specific relationship between each value. For instance,
+        using 2 GPIOS:
+          0b00 <-> -10.0 dB
+          0b01 <-> +3.0 dB
+          0b10 <-> 0 dB
+          0b11 <-> +6.0 dB
+
+        This can be described using the gain-points property.
+
+    - range defined:
+        The values of GPIOs used to control gain set a specific gain value
+        following a linear dB range from a minimum dB value to a maximum dB
+        value. For instance, using 2 GPIOS:
+          0b00 <-> -3.0 dB
+          0b01 <-> 0 db
+          0b10 <-> +3.0 dB
+          0b11 <-> +6.0 dB
+
+        This can be described using the gain-range property.
+
+    - labels defined:
+        Some electronic design are not meant to a specific dB gain value. In
+        that case it is relevant to use labels to describe them. For instance,
+        using 2 GPIOS:

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+          0b00 <-> Low boost
+          0b01 <-> Middle boost
+          0b10 <-> High boost
+          0b11 <-> Max boost
+
+        This can be described using the gain-labels property
+
+properties:
+  compatible:
+    const: audio-gpio-amp

To be consistent with other GPIO controlled devices: gpio-audio-amp

Quoted 38 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +38 -0
+
+  vdd-supply:
+    description: Main power supply of the amplifier
+
+  vddio-supply:
+    description: Power supply related to the control path
+
+  vdda1-supply:
+    description: Analog power supply
+
+  vdda2-supply:
+    description: Additional analog power supply
+
+  mute-gpios:
+    description: GPIO to control the mute function
+    maxItems: 1
+
+  bypass-gpios:
+    description: GPIO to control the bypass function
+    maxItems: 1
+
+  gain-gpios:
+    description: |
+      GPIOs to control the amplifier gain
+
+      The gain value is computed from GPIOs value from 0 to 2^N-1 with N the
+      number of GPIO described. The first GPIO described is the lsb of the gain
+      value.
+
+      For instance assuming 2 gpios
+         gain-gpios = <&gpio1 GPIO_ACTIVE_HIGH> <&gpio2 GPIO_ACTIVE_HIGH>;
+      The gain value will be the following:
+
+          gpio1 | gpio2 | gain
+          ------+-------+-----
+            0   |    0  | 0b00 -> 0
+            1   |    0  | 0b01 -> 1
+            0   |    1  | 0b10 -> 2

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 126

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+            1   |    1  | 0b11 -> 3
+          ------+-------+-----
+
+      Note: The gain value, bits set to 1 or 0, indicate the state active (bit
+            set) or the state inactive (bit unset) of the related GPIO. The
+            physical voltage corresponding to this active/inactive state is
+            given by the GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags.
+
+    minItems: 1
+    maxItems: 32

2^32 levels? Seems like a bit much. Also, unless you can change the values of all the GPIOs atomically, aren't you going to get some artifacts while the gain is being changed? Unless you mute I guess.

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 132

Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+  gain-points:
+    $ref: /schemas/types.yaml#/definitions/int32-matrix
+    items:
+      items:
+        - description: The GPIOs value

Can't this just be the index?

If not, then gain-range could be expressed using gain-points instead.

Quoted 49 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +49 -0
+        - description: The related amplifier gain in 0.01 dB unit
+    minItems: 2
+    description: |
+      List of the GPIOs value / Gain value in dB pair defining the gain
+      set on each GPIOs value.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that GPIOs values set the hardware gains according to the
+      following table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | -10.0 dB
+           1   | +3.0 dB
+           2   | 0 dB
+           3   | +6.0 dB
+         ------+--------------
+
+      The description using gain points can be:
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+
+  gain-range:
+    $ref: /schemas/types.yaml#/definitions/int32-array
+    items:
+      - description: Gain in 0.01 dB unit when all GPIOs are inactive
+      - description: Gain in 0.01 dB unit when all GPIOs are active
+    description: |
+      Gains (in 0.01 dB unit) set by the extremum (minimal and maximum) value
+      of GPIOs. The following formula must be satisfied.
+
+               gain-range[1] - gain-range[0]
+      Gain  = ------------------------------- x GPIO_value + gain-range[0]
+                        2^N - 1
+
+      With N, the number of GPIOs used to control the gain and Gain computed in
+      0.01 dB unit.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware 1    | Hardware 2
+         value | amplification | amplification
+         ------+---------------+---------------
+           0   | -3.0 dB       |  +10.0 dB
+           1   | 0 dB          |  +5.0 dB
+           2   | +3.0 dB       |  0 dB
+           3   | +6.0 dB       |  -5.0 dB

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 191

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+         ------+---------------+---------------
+
+      The description for hardware 1 using a gain range can be:
+        gain-range = <(-300) 600>;
+
+      The description for hardware 2 using a gain range can be:
+        gain-range = <1000 (-500)>;
+
+  gain-labels:
+    $ref: /schemas/types.yaml#/definitions/string-array

minItems: 2
maxItems: 0x100000000

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+    description: |
+      List of the gain labels attached to the combination of GPIOs controlling
+      the gain. The first label is related to the gain value 0, the second label
+      is related to the gain value 1 and so on.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 211

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+         value | amplification
+         ------+--------------
+           0   | Low
+           1   | Middle
+           2   | High
+           3   | Max
+         ------+--------------
+
+      The description using gain labels can be:
+        gain-labels = "Low", "Middle", "High", "Max";

Do we need to allow these to be anything? It's going to get hard to come up with 2^32 names.

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 216

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+
+dependencies:
+  gain-points: [ gain-gpios ]
+  gain-range: [ gain-gpios ]
+  gain-labels: [ gain-gpios ]

gain-gpios is really optional?

Quoted 35 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +35 -0
+
+required:
+  - compatible
+  - vdd-supply
+
+anyOf:
+  - required:
+      - gain-gpios
+  - required:
+      - mute-gpios
+  - required:
+      - bypass-gpios
+
+allOf:
+  - $ref: dai-common.yaml#
+  - if:
+      required:
+        - gain-points
+    then:
+      properties:
+        gain-range: false
+        gain-labels: false
+  - if:
+      required:
+        - gain-range
+    then:
+      properties:
+        gain-points: false
+        gain-labels: false
+  - if:
+      required:
+        - gain-labels
+    then:
+      properties:
+        gain-points: false

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 261

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+        gain-range: false
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    /* Gain controlled by gpios */
+    amplifier0 {

amplifier-0

Quoted 24 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +24 -0
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+    };
+
+    /* Gain controlled by gpio using range */
+    amplifier1 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-range = <(-300) 600>;
+    };
+
+    /* Gain controlled by gpio using points */
+    amplifier2 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+    };
+
+    /* Gain controlled by gpio with labels */
+    amplifier3 {
+        compatible = "audio-gpio-amp";

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 295

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +10 -0
+        vdd-supply = <&regulator>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+        gain-labels = "Low", "High";
+    };
+
+    /* A mutable amplifier without any gain control */
+    amplifier4 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        mute-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;

This case is just simple-amplifier...

Quoted 17 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +14 -0
+    };
+
+    /*  Several supplies, gain controlled using range, mute and bypass */
+    amplifier5 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        vddio-supply = <&regulator1>;
+        vdda1-supply = <&regulator2>;
+        gain-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>, <&gpio 1 GPIO_ACTIVE_HIGH>;
+        gain-range = <(-300) 600>;
+        mute-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
+        bypass-gpios = <&gpio 3 GPIO_ACTIVE_HIGH>;
+    };
+...
Signature · 1 line
2.53.0
maintainer
#5 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Quoted 8 lines · Rob Herring

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 216

Quoted 4 lines · Herve Codina
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +4 -0
+dependencies:
+  gain-points: [ gain-gpios ]
+  gain-range: [ gain-gpios ]
+  gain-labels: [ gain-gpios ]

gain-gpios is really optional?

You've still got mute control, and power up/down - each feature should be optional.

#6 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

In reply to Rob Herring

Hi Rob, Mark,

On Wed, 8 Apr 2026 07:29:01 -0500
Rob Herring <[email protected]> wrote:

...

Quoted 5 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 78

Quoted 3 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +3 -0
+properties:
+  compatible:
+    const: audio-gpio-amp  

To be consistent with other GPIO controlled devices: gpio-audio-amp

Ok.

Mark suggested to merge this gpio-audio-amp with simple-amplifier. This leads to the following question:

Should I keep the 'gpio-audio-amp' compatible string ?

Should I keep two bindings (this one and the simple-audio-amplifier.yaml) or should I merge bindings?

...

Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +23 -0
+  gain-gpios:
+    description: |
+      GPIOs to control the amplifier gain
+
+      The gain value is computed from GPIOs value from 0 to 2^N-1 with N the
+      number of GPIO described. The first GPIO described is the lsb of the gain
+      value.
+
+      For instance assuming 2 gpios
+         gain-gpios = <&gpio1 GPIO_ACTIVE_HIGH> <&gpio2 GPIO_ACTIVE_HIGH>;
+      The gain value will be the following:
+
+          gpio1 | gpio2 | gain
+          ------+-------+-----
+            0   |    0  | 0b00 -> 0
+            1   |    0  | 0b01 -> 1
+            0   |    1  | 0b10 -> 2
+            1   |    1  | 0b11 -> 3
+          ------+-------+-----
+
+      Note: The gain value, bits set to 1 or 0, indicate the state active (bit
+            set) or the state inactive (bit unset) of the related GPIO. The
+            physical voltage corresponding to this active/inactive state is
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 126

Quoted 4 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +4 -0
+            given by the GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags.
+
+    minItems: 1
+    maxItems: 32  

2^32 levels? Seems like a bit much. Also, unless you can change the values of all the GPIOs atomically, aren't you going to get some artifacts while the gain is being changed? Unless you mute I guess.

I didn't want to set a particular limit related to the number of GPIOs used for thje gain value. Of course 2^32 is obviously a lot.

What do you think about 16 for maxItems?

Related to Artifacts, yes they can probably be there. Also the mute feature is not required. Some hardware use only one GPIO and doesn't implement mute feature. In that case no artifacts can be present.

If mute is implemented, it is the application responsibility to handle mute / unmute while changing the gain value. I don't think we can do anything at driver level to avoid those artifacts if any.

Quoted 9 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 132

Quoted 7 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+  gain-points:
+    $ref: /schemas/types.yaml#/definitions/int32-matrix
+    items:
+      items:
+        - description: The GPIOs value  

Can't this just be the index?

Some GPIOs value can be skipped if they don't make any sense in the hardware design. With the index, this is not possible.

gpios:
0b00 -3dB
0b01 0dB
0b10 Reserved, should not be used
0b11 +3dB

With just the index, the reserved 0b10 value cannot be skipped. I would like to handle this kind of cases.

Quoted 2 lines

If not, then gain-range could be expressed using gain-points instead.

Do you have in mind something like the following?
gain-range = <0 (-300)>, <3 600>;

defining the range from -3dB to +6dB with GPIOs value 0 for -3dB and 3 for +6dB.

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +54 -0
+        - description: The related amplifier gain in 0.01 dB unit
+    minItems: 2
+    description: |
+      List of the GPIOs value / Gain value in dB pair defining the gain
+      set on each GPIOs value.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that GPIOs values set the hardware gains according to the
+      following table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | -10.0 dB
+           1   | +3.0 dB
+           2   | 0 dB
+           3   | +6.0 dB
+         ------+--------------
+
+      The description using gain points can be:
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+
+  gain-range:
+    $ref: /schemas/types.yaml#/definitions/int32-array
+    items:
+      - description: Gain in 0.01 dB unit when all GPIOs are inactive
+      - description: Gain in 0.01 dB unit when all GPIOs are active
+    description: |
+      Gains (in 0.01 dB unit) set by the extremum (minimal and maximum) value
+      of GPIOs. The following formula must be satisfied.
+
+               gain-range[1] - gain-range[0]
+      Gain  = ------------------------------- x GPIO_value + gain-range[0]
+                        2^N - 1
+
+      With N, the number of GPIOs used to control the gain and Gain computed in
+      0.01 dB unit.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware 1    | Hardware 2
+         value | amplification | amplification
+         ------+---------------+---------------
+           0   | -3.0 dB       |  +10.0 dB
+           1   | 0 dB          |  +5.0 dB
+           2   | +3.0 dB       |  0 dB
+           3   | +6.0 dB       |  -5.0 dB
+         ------+---------------+---------------
+
+      The description for hardware 1 using a gain range can be:
+        gain-range = <(-300) 600>;
+
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 191

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+      The description for hardware 2 using a gain range can be:
+        gain-range = <1000 (-500)>;
+
+  gain-labels:
+    $ref: /schemas/types.yaml#/definitions/string-array  

minItems: 2
maxItems: 0x100000000

Ok, I will adjust maxItems according to the max number of GPIO supported.

For my curiosity, is there a way to express maxItems with a computation based on some other properties value ?

What could be relevant here is
maxitems: 2^(number of items available in the gpio-gain properties)

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +15 -0
+    description: |
+      List of the gain labels attached to the combination of GPIOs controlling
+      the gain. The first label is related to the gain value 0, the second label
+      is related to the gain value 1 and so on.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | Low
+           1   | Middle
+           2   | High
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 211

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+           3   | Max
+         ------+--------------
+
+      The description using gain labels can be:
+        gain-labels = "Low", "Middle", "High", "Max";  

Do we need to allow these to be anything? It's going to get hard to come up with 2^32 names.

Well, "Normal" / "Boost" can make sense on some hardware.

I don't think we need to restrict labels to a list of known label here.

Of course 2^32 names is obviously a lot. What could be the limit?

Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 216

Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+
+dependencies:
+  gain-points: [ gain-gpios ]
+  gain-range: [ gain-gpios ]
+  gain-labels: [ gain-gpios ]  

gain-gpios is really optional?

Yes, we can have an amplifier without any possibility to change the gain value but with a gpio allowing to mute or bypass the amplifier.

...

Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 261

Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    /* Gain controlled by gpios */
+    amplifier0 {  

amplifier-0

Ok, it will be update in the next iteration as well as other node names available in this example part.

...

Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 295

Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+    /* A mutable amplifier without any gain control */
+    amplifier4 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        mute-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;  

This case is just simple-amplifier...

No, simple-amplifier uses 'enable' and not 'mute'.

We can have the amplifier enabled ('enable' GPIO active) as it is used and a switch driven by an other GPIO to mute / un-mute the amplifier output.

Best regards,
Hervé

maintainer
#7 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Quoted 12 lines · Herve Codina

Hi Rob, Mark,

On Wed, 8 Apr 2026 07:29:01 -0500
Rob Herring <[email protected]> wrote:

...

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +3 -0
+properties:
+  compatible:
+    const: audio-gpio-amp
Quoted 5 lines
Quoted 1 line

To be consistent with other GPIO controlled devices: gpio-audio-amp

Ok.

Mark suggested to merge this gpio-audio-amp with simple-amplifier.

Merging driver and merging binding are separate questions.

Quoted 3 lines

This leads to the following question:

Should I keep the 'gpio-audio-amp' compatible string ?

Yes. 'cause this binding isn't simple...

And I don't care for any compatible with 'simple' (or generic) in it. Not sure why I agreed to that one. But I'm all for generic/common drivers.

Quoted 2 lines

Should I keep two bindings (this one and the simple-audio-amplifier.yaml) or should I merge bindings?

2 bindings. There's no overlap in property names.

Quoted 33 lines

...

Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +23 -0
+  gain-gpios:
+    description: |
+      GPIOs to control the amplifier gain
+
+      The gain value is computed from GPIOs value from 0 to 2^N-1 with N the
+      number of GPIO described. The first GPIO described is the lsb of the gain
+      value.
+
+      For instance assuming 2 gpios
+         gain-gpios = <&gpio1 GPIO_ACTIVE_HIGH> <&gpio2 GPIO_ACTIVE_HIGH>;
+      The gain value will be the following:
+
+          gpio1 | gpio2 | gain
+          ------+-------+-----
+            0   |    0  | 0b00 -> 0
+            1   |    0  | 0b01 -> 1
+            0   |    1  | 0b10 -> 2
+            1   |    1  | 0b11 -> 3
+          ------+-------+-----
+
+      Note: The gain value, bits set to 1 or 0, indicate the state active (bit
+            set) or the state inactive (bit unset) of the related GPIO. The
+            physical voltage corresponding to this active/inactive state is
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 126

Quoted 4 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +4 -0
+            given by the GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags.
+
+    minItems: 1
+    maxItems: 32

2^32 levels? Seems like a bit much. Also, unless you can change the values of all the GPIOs atomically, aren't you going to get some artifacts while the gain is being changed? Unless you mute I guess.

Quoted 4 lines

I didn't want to set a particular limit related to the number of GPIOs used for thje gain value. Of course 2^32 is obviously a lot.

What do you think about 16 for maxItems?

What is the most you are aware of? Take that and double it.

Seems to me 256 levels would be way more than a human ear could distinguish.

Quoted 21 lines

Related to Artifacts, yes they can probably be there. Also the mute feature is not required. Some hardware use only one GPIO and doesn't implement mute feature. In that case no artifacts can be present.

If mute is implemented, it is the application responsibility to handle mute / unmute while changing the gain value. I don't think we can do anything at driver level to avoid those artifacts if any.

Quoted 9 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 132

Quoted 7 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+  gain-points:
+    $ref: /schemas/types.yaml#/definitions/int32-matrix
+    items:
+      items:
+        - description: The GPIOs value

Can't this just be the index?

Some GPIOs value can be skipped if they don't make any sense in the hardware design. With the index, this is not possible.

Quoted 8 lines

gpios:
0b00 -3dB
0b01 0dB
0b10 Reserved, should not be used
0b11 +3dB

With just the index, the reserved 0b10 value cannot be skipped. I would like to handle this kind of cases.

Okay.

Quoted 6 lines
Quoted 1 line

If not, then gain-range could be expressed using gain-points instead.

Do you have in mind something like the following?
gain-range = <0 (-300)>, <3 600>;

defining the range from -3dB to +6dB with GPIOs value 0 for -3dB and 3 for +6dB.

Yes, but since you can have reserved values, that won't work.

Quoted 63 lines
Quoted 54 lines
Quoted 54 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +54 -0
+        - description: The related amplifier gain in 0.01 dB unit
+    minItems: 2
+    description: |
+      List of the GPIOs value / Gain value in dB pair defining the gain
+      set on each GPIOs value.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that GPIOs values set the hardware gains according to the
+      following table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | -10.0 dB
+           1   | +3.0 dB
+           2   | 0 dB
+           3   | +6.0 dB
+         ------+--------------
+
+      The description using gain points can be:
+        gain-points = <0 (-1000)>, <1 300>, <2 0>, <3 600>;
+
+  gain-range:
+    $ref: /schemas/types.yaml#/definitions/int32-array
+    items:
+      - description: Gain in 0.01 dB unit when all GPIOs are inactive
+      - description: Gain in 0.01 dB unit when all GPIOs are active
+    description: |
+      Gains (in 0.01 dB unit) set by the extremum (minimal and maximum) value
+      of GPIOs. The following formula must be satisfied.
+
+               gain-range[1] - gain-range[0]
+      Gain  = ------------------------------- x GPIO_value + gain-range[0]
+                        2^N - 1
+
+      With N, the number of GPIOs used to control the gain and Gain computed in
+      0.01 dB unit.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware 1    | Hardware 2
+         value | amplification | amplification
+         ------+---------------+---------------
+           0   | -3.0 dB       |  +10.0 dB
+           1   | 0 dB          |  +5.0 dB
+           2   | +3.0 dB       |  0 dB
+           3   | +6.0 dB       |  -5.0 dB
+         ------+---------------+---------------
+
+      The description for hardware 1 using a gain range can be:
+        gain-range = <(-300) 600>;
+
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 191

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+      The description for hardware 2 using a gain range can be:
+        gain-range = <1000 (-500)>;
+
+  gain-labels:
+    $ref: /schemas/types.yaml#/definitions/string-array

minItems: 2
maxItems: 0x100000000

Quoted 4 lines

Ok, I will adjust maxItems according to the max number of GPIO supported.

For my curiosity, is there a way to express maxItems with a computation based on some other properties value ?

No, there isn't.

Quoted 29 lines

What could be relevant here is
maxitems: 2^(number of items available in the gpio-gain properties)

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +15 -0
+    description: |
+      List of the gain labels attached to the combination of GPIOs controlling
+      the gain. The first label is related to the gain value 0, the second label
+      is related to the gain value 1 and so on.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | Low
+           1   | Middle
+           2   | High
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 211

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+           3   | Max
+         ------+--------------
+
+      The description using gain labels can be:
+        gain-labels = "Low", "Middle", "High", "Max";

Do we need to allow these to be anything? It's going to get hard to come up with 2^32 names.

Quoted 3 lines

Well, "Normal" / "Boost" can make sense on some hardware.

I don't think we need to restrict labels to a list of known label here.

As long as the names are meaningless to software.

Quoted 2 lines

Of course 2^32 names is obviously a lot. What could be the limit?

I would guess at 8 or more, it's just going to be gain1, gain2, etc. or something similar constructed from the gain values.

Quoted 9 lines

...

Quoted 7 lines
Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+    /* A mutable amplifier without any gain control */
+    amplifier4 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        mute-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
Quoted 3 lines
Quoted 1 line

This case is just simple-amplifier...

No, simple-amplifier uses 'enable' and not 'mute'.

Yes, I know...

Quoted 3 lines

We can have the amplifier enabled ('enable' GPIO active) as it is used and a switch driven by an other GPIO to mute / un-mute the amplifier output.

But you have no 'enable' GPIO here. To me, enable just looks like inverted mute. If there's some electrical difference, I can't tell what that is from either binding.

I guess my point was that really we could deprecate simple-amplifier binding because this one can handle it and more. But I'm not suggesting we do that yet.

Rob

maintainer
#8 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Quoted 5 lines · Rob Herring
Quoted 1 line · Herve Codina

Mark suggested to merge this gpio-audio-amp with simple-amplifier.

Merging driver and merging binding are separate questions.

Yes, my comments were purely about the driver.

Quoted 8 lines
Quoted 4 lines

I didn't want to set a particular limit related to the number of GPIOs used for thje gain value. Of course 2^32 is obviously a lot.

What do you think about 16 for maxItems?

What is the most you are aware of? Take that and double it.

Seems to me 256 levels would be way more than a human ear could distinguish.

There's plenty of gain controls with way more than 256 bits of resolution, though I'm not aware of any that are configured via GPIO. The step size and absolute values you want can vary dramatically depending on application, possibly in the same system (eg, a DAC that can be connected to both headphones or speakers) so you often end up making practical adjustments in a small subset of the available range but that subset can vary a lot for the same part.

Quoted 3 lines

I guess my point was that really we could deprecate simple-amplifier binding because this one can handle it and more. But I'm not suggesting we do that yet.

That's my thinking.

#9 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Hi Mark, Rob,

Quoted 9 lines · On Thu, 9 Apr 2026 16:26:25 +0100 Mark Brown <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines

I didn't want to set a particular limit related to the number of GPIOs used for thje gain value. Of course 2^32 is obviously a lot.

What do you think about 16 for maxItems?

What is the most you are aware of? Take that and double it.

Seems to me 256 levels would be way more than a human ear could distinguish.

Quoted 7 lines

There's plenty of gain controls with way more than 256 bits of resolution, though I'm not aware of any that are configured via GPIO. The step size and absolute values you want can vary dramatically depending on application, possibly in the same system (eg, a DAC that can be connected to both headphones or speakers) so you often end up making practical adjustments in a small subset of the available range but that subset can vary a lot for the same part.

Mark, do you think that max 16 GPIOs could be an acceptable limit?

IMHO, this value is large enough to be used as the limit.

Quoted 6 lines
Quoted 4 lines

I guess my point was that really we could deprecate simple-amplifier binding because this one can handle it and more. But I'm not suggesting we do that yet.

That's my thinking.

Fine for me to, at the end, deprecate the simple-amplifier.

maintainer
#10 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

Quoted 19 lines · Herve Codina
Quoted 9 lines · Mark Brown
Quoted 8 lines
Quoted 4 lines

I didn't want to set a particular limit related to the number of GPIOs used for thje gain value. Of course 2^32 is obviously a lot.

What do you think about 16 for maxItems?

What is the most you are aware of? Take that and double it.

Seems to me 256 levels would be way more than a human ear could distinguish.

Quoted 7 lines

There's plenty of gain controls with way more than 256 bits of resolution, though I'm not aware of any that are configured via GPIO. The step size and absolute values you want can vary dramatically depending on application, possibly in the same system (eg, a DAC that can be connected to both headphones or speakers) so you often end up making practical adjustments in a small subset of the available range but that subset can vary a lot for the same part.

Quoted 3 lines

Mark, do you think that max 16 GPIOs could be an acceptable limit?

IMHO, this value is large enough to be used as the limit.

That does seem larger than any real system would ever need.

#11 lore raw

Re: [PATCH 2/4] ASoC: dt-bindings: Add support for the GPIOs driven amplifier

In reply to Rob Herring

Hi Rob, Mark,

On Thu, 9 Apr 2026 10:00:55 -0500
Rob Herring <[email protected]> wrote:

...

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

If not, then gain-range could be expressed using gain-points instead.

Do you have in mind something like the following?
gain-range = <0 (-300)>, <3 600>;

defining the range from -3dB to +6dB with GPIOs value 0 for -3dB and 3 for +6dB.

Yes, but since you can have reserved values, that won't work.

In that case gpio-points can be used.

The other solution will be to allow multiple ranges:

gpios Gain
0b000 -> -6dB
0b001 -> -3dB
0b010 -> 0dB
0b011 -> Reserved
0b100 -> +3dB
0b101 -> +6dB
other -> Reserved

This could be described as
gain-ranges = <0 (-600)>, <2 0>,

                <4 300>, <5 600>;

As a side note, this will probably add quite a lot of complexity to handle multiple ranges in the driver. If too complex, the driver will handle only one range and returns -ENOTSUPP if multiple ranges (more than one) are used.

Is that something acceptable?

...

Quoted 28 lines
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +15 -0
+    description: |
+      List of the gain labels attached to the combination of GPIOs controlling
+      the gain. The first label is related to the gain value 0, the second label
+      is related to the gain value 1 and so on.
+
+      With 2 GPIOs controlling the gain, GPIOs value can be 0, 1, 2 and 3.
+      Assuming that gain value set the hardware according to the following
+      table:
+
+         GPIOs | Hardware
+         value | amplification
+         ------+--------------
+           0   | Low
+           1   | Middle
+           2   | High
Quoted 8 lines

Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml line 211

Quoted 5 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +5 -0
+           3   | Max
+         ------+--------------
+
+      The description using gain labels can be:
+        gain-labels = "Low", "Middle", "High", "Max";  

Do we need to allow these to be anything? It's going to get hard to come up with 2^32 names.

Quoted 3 lines

Well, "Normal" / "Boost" can make sense on some hardware.

I don't think we need to restrict labels to a list of known label here.

Quoted 7 lines

As long as the names are meaningless to software.

Quoted 2 lines

Of course 2^32 names is obviously a lot. What could be the limit?

I would guess at 8 or more, it's just going to be gain1, gain2, etc. or something similar constructed from the gain values.

I suppose that gpio-points or gpio-ranges are going to be used instead of labels at 8 or more.

With a lot number of GPIOs involved, I am not sure that using labels makes sense even from the hardware point of view.

The 3 possible descriptions (gpio-points, gpio-range(s), gpio-labels) are mutually exclusive. Depending on the hardware designed, one of them has to be chosen.

Of course, you can describe 256 labels but does it make sense in that case with alternative available ?

Quoted 16 lines
Quoted 10 lines

...

Quoted 7 lines
Quoted 6 lines
Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml new file +6 -0
+
+    /* A mutable amplifier without any gain control */
+    amplifier4 {
+        compatible = "audio-gpio-amp";
+        vdd-supply = <&regulator>;
+        mute-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;  
Quoted 3 lines
Quoted 1 line

This case is just simple-amplifier...

No, simple-amplifier uses 'enable' and not 'mute'.

Yes, I know...

Quoted 7 lines
Quoted 3 lines

We can have the amplifier enabled ('enable' GPIO active) as it is used and a switch driven by an other GPIO to mute / un-mute the amplifier output.

But you have no 'enable' GPIO here. To me, enable just looks like inverted mute. If there's some electrical difference, I can't tell what that is from either binding.

A known physical component handle by simple-amplifier is the dio2125.

According to its datasheet:
Pop-free power up is ensured by keeping the EN (shutdown pin) low during power down. The EN pin should be kept low EN pin high to achieve pop-less power up

The 'enable' gpio should be used when power is established or remove.

The mute gpio handle an output switch:

           +---------+   op-amp output
           | dio2125 +-------------------o
           |         |                        o---- Amplifier feature output
 enable ---+         |                ,--o  ^
           |         |                |     |
           +---------+                v     |
                                     GND    |
                                            |

mute --------------------------------------'

The mute signal switches on/off the dio2125 output while the dio2125 is active (powered uup) and so its enable pin is driven high.

I can add an 'enable' GPIO here to handle it in the same way as it is handled in the simple-amplifier (dio2125 use case).

Quoted 5 lines

I guess my point was that really we could deprecate simple-amplifier binding because this one can handle it and more. But I'm not suggesting we do that yet.

Best regards,
Hervé

#12 lore raw

PATCH 3/4 ASoC: codecs: Add support for the GPIOs driven amplifier

In reply to Herve Codina

Some amplifiers driven by GPIOs can be present in the audio path.

In order to be fully integrated in the audio path and to have audio mixer items available to control those amplifiers, an audio component is needed.

This support allows to handle those GPIO driven amplifiers as auxiliary audio devices and so control them using audio mixer controls.

---
 sound/soc/codecs/Kconfig          |  12 +
 sound/soc/codecs/Makefile         |   2 +
 sound/soc/codecs/audio-gpio-amp.c | 765 ++++++++++++++++++++++++++++++
 3 files changed, 779 insertions(+)
 create mode 100644 sound/soc/codecs/audio-gpio-amp.c
sound/soc/codecs/Kconfig +12 -0
index adb3fb923be3..9c51519d6eea 100644
@@ -52,6 +52,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_AK5558
 	imply SND_SOC_ALC5623
 	imply SND_SOC_ALC5632
+	imply SND_SOC_AUDIO_GPIO_AMP
 	imply SND_SOC_AUDIO_IIO_AUX
 	imply SND_SOC_AW8738
 	imply SND_SOC_AW87390
@@ -648,6 +649,17 @@ config SND_SOC_ALC5632
 	tristate
 	depends on I2C
 
+config SND_SOC_AUDIO_GPIO_AMP
+	tristate "Audio GPIO Amplifier"
+	select GPIOLIB
+	help
+	  Enable support for GPIO amplifier.
+	  This allows to have an amplifier driven by GPIOs in the audio path and
+	  controlled using mixer controls.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-soc-audio-gpio-amp.
+
 config SND_SOC_AUDIO_IIO_AUX
 	tristate "Audio IIO Auxiliary device"
 	depends on IIO
sound/soc/codecs/Makefile +2 -0
index 3ddee5298721..e1794a3368ab 100644
@@ -423,6 +423,7 @@ snd-soc-wsa883x-y := wsa883x.o
 snd-soc-wsa884x-y := wsa884x.o
 snd-soc-zl38060-y := zl38060.o
 # Amp
+snd-soc-audio-gpio-amp-y := audio-gpio-amp.o
 snd-soc-max9877-y := max9877.o
 snd-soc-max98504-y := max98504.o
 snd-soc-simple-amplifier-y := simple-amplifier.o
@@ -869,6 +870,7 @@ obj-$(CONFIG_SND_SOC_WSA884X)	+= snd-soc-wsa884x.o
 obj-$(CONFIG_SND_SOC_ZL38060)	+= snd-soc-zl38060.o
 
 # Amp
+obj-$(CONFIG_SND_SOC_AUDIO_GPIO_AMP)	+= snd-soc-audio-gpio-amp.o
 obj-$(CONFIG_SND_SOC_MAX9877)	+= snd-soc-max9877.o
 obj-$(CONFIG_SND_SOC_MAX98504)	+= snd-soc-max98504.o
 obj-$(CONFIG_SND_SOC_SIMPLE_AMPLIFIER)	+= snd-soc-simple-amplifier.o
sound/soc/codecs/audio-gpio-amp.c new file +765 -0

765 lines not on this page · raw message

Signature · 1 line
2.53.0
#13 lore raw

PATCH 4/4 MAINTAINERS: Add the ASoC gpio amplifier entry

In reply to Herve Codina

After contributing the component, add myself as the maintainer for the ASoC gpio amplifier component.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 55af015174a5..2546eb81f233 100644
@@ -24765,6 +24765,13 @@ F:	include/sound/dmaengine_pcm.h
 F:	sound/core/pcm_dmaengine.c
 F:	sound/soc/soc-generic-dmaengine-pcm.c
 
+SOUND - SOC LAYER / AUDIO GPIO AMPLIFIER
+M:	Herve Codina <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/sound/audio-gpio-amp.yaml
+F:	sound/soc/codecs/audio-gpio-amp.c
+
 SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEMENT (ASoC)
 M:	Liam Girdwood <[email protected]>
 M:	Mark Brown <[email protected]>
Signature · 1 line
2.53.0
maintainer
#14 lore raw
In reply to Herve Codina
Quoted 6 lines · Herve Codina

On some embedded system boards, audio amplifiers are designed using discrete components such as op-amp, several resistors and switches to either adjust the gain (switching resistors) or fully switch the audio signal path (mute and/or bypass features).

Those switches are usually driven by simple GPIOs.

This sounds a lot like simple-amplifier.c?

#15 lore raw
Quoted 9 lines · On Mon, 30 Mar 2026 16:08:47 +0100 Mark Brown <[email protected]> wrote:
Quoted 6 lines · Herve Codina

On some embedded system boards, audio amplifiers are designed using discrete components such as op-amp, several resistors and switches to either adjust the gain (switching resistors) or fully switch the audio signal path (mute and/or bypass features).

Those switches are usually driven by simple GPIOs.

This sounds a lot like simple-amplifier.c?

simple-amplifier.c doesn't handle amplifier driven by GPIOs. The only used GPIO in simple-amplifier.c is used to handle the enable pin the component.

simple-amplifier.c handles component such as dio2125 alone.

Here, we have op-amp but also several components around such as switches.

The gpio driven amplifier proposed is more generic and can handle more complex design. I.e. op-amp + resistor and/or line (mute, bypass) switching. Hardwares handled by this driver are a superset of just dio2125 and so simple-amplifier.c.

IMHO, it makes sense to have a specific driver for those kind of hardware design.

Best regards,
Hervé

maintainer
#16 lore raw
Quoted 11 lines · Herve Codina
Quoted 1 line · Mark Brown

This sounds a lot like simple-amplifier.c?

The gpio driven amplifier proposed is more generic and can handle more complex design. I.e. op-amp + resistor and/or line (mute, bypass) switching. Hardwares handled by this driver are a superset of just dio2125 and so simple-amplifier.c.

IMHO, it makes sense to have a specific driver for those kind of hardware design.

Right, and if it's a superset it feels like it should all be one driver rather than two separate ones.

#17 lore raw
Quoted 10 lines · On Mon, 30 Mar 2026 16:48:54 +0100 Mark Brown <[email protected]> wrote:
Quoted 8 lines · Herve Codina
Quoted 1 line · Mark Brown

This sounds a lot like simple-amplifier.c?

The gpio driven amplifier proposed is more generic and can handle more complex design. I.e. op-amp + resistor and/or line (mute, bypass) switching. Hardwares handled by this driver are a superset of just dio2125 and so simple-amplifier.c.

Quoted 5 lines
Quoted 2 lines

IMHO, it makes sense to have a specific driver for those kind of hardware design.

Right, and if it's a superset it feels like it should all be one driver rather than two separate ones.

Also, it is worth noting that simple-amplifier.c considered a stereo amplifier (left + right).

Considering the two op-amp available in dio2125 as just two op-amp used in two separated mono channel with additional component to switch related to resistors (independant switching for each channel) means that almost everything proposed in audio-gpio-amp have to be duplicated (gain, mute, bypass per channel) instead of just instantiate two audio-gpio-amps.

On the other hand, there is no reason to handle a stereo component in audio-gpio-amp. Further more with the hardware I have handling a stereo component doesn't make sense. Indeed, I only have independent mono lines with their own resistor switched amplification circuitry.

I could merge everything in one .c file but only a few part of source code will be common to simple-amplifier and audio-gpio-amp. IMHO the resulting merged code will look like two different drivers merged in one .c file.

Best regards,
Hervé

#18 lore raw

Hi Mark,

Le 30/03/2026 à 18:41, Herve Codina a écrit :

Quoted 28 lines
Quoted 10 lines · On Mon, 30 Mar 2026 16:48:54 +0100 Mark Brown <[email protected]> wrote:
Quoted 8 lines · Herve Codina
Quoted 1 line · Mark Brown

This sounds a lot like simple-amplifier.c?

The gpio driven amplifier proposed is more generic and can handle more complex design. I.e. op-amp + resistor and/or line (mute, bypass) switching. Hardwares handled by this driver are a superset of just dio2125 and so simple-amplifier.c.

Quoted 5 lines
Quoted 2 lines

IMHO, it makes sense to have a specific driver for those kind of hardware design.

Right, and if it's a superset it feels like it should all be one driver rather than two separate ones.

Also, it is worth noting that simple-amplifier.c considered a stereo amplifier (left + right).

Considering the two op-amp available in dio2125 as just two op-amp used in two separated mono channel with additional component to switch related to resistors (independant switching for each channel) means that almost everything proposed in audio-gpio-amp have to be duplicated (gain, mute, bypass per channel) instead of just instantiate two audio-gpio-amps.

Quoted 8 lines

On the other hand, there is no reason to handle a stereo component in audio-gpio-amp. Further more with the hardware I have handling a stereo component doesn't make sense. Indeed, I only have independent mono lines with their own resistor switched amplification circuitry.

I could merge everything in one .c file but only a few part of source code will be common to simple-amplifier and audio-gpio-amp. IMHO the resulting merged code will look like two different drivers merged in one .c file.

Following explanation from Herve I have the feeling that combining the two drivers into a single one will bring more complexity for little benefit.

Do you still think it is worth having a combined driver allthough they address quite different setups ?

Thanks
Christophe

maintainer
#19 lore raw
Quoted 11 lines · Christophe Leroy (CS GROUP)

Le 30/03/2026 à 18:41, Herve Codina a écrit :

Quoted 3 lines

I could merge everything in one .c file but only a few part of source code will be common to simple-amplifier and audio-gpio-amp. IMHO the resulting merged code will look like two different drivers merged in one .c file.

Following explanation from Herve I have the feeling that combining the two drivers into a single one will bring more complexity for little benefit.

Do you still think it is worth having a combined driver allthough they address quite different setups ?

Yes, it's just a difference in the binding not in the runtime stuff. The two will inevitably grow together over time, keeping them separate is just creating a long term bikeshedding problem wondering which to use for a given situation.