diff mbox series

[v2,3/5] ASoC: dt-bindings: wm8904: Add DMIC, GPIO, MIC and EQ support

Message ID 20250224155500.52462-4-francesco@dolcini.it (mailing list archive)
State New
Headers show
Series ASoC: wm8904: Add DMIC and DRC support | expand

Commit Message

Francesco Dolcini Feb. 24, 2025, 3:54 p.m. UTC
From: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>

Add two properties to select the IN1L/DMICDAT1 and IN2R/DMICDAT2
functionality:
- wlf,in1l-as-dmicdat1
- wlf,in1r-as-dmicdat2

Add a property to describe the GPIO configuration registers, that can be
used to set the four multifunction pins:
- wlf,gpio-cfg

Add a property to describe the mic bias control registers:
- wlf,mic-cfg

Add two properties to describe the Dynamic Range Controller (DRC),
allowing multiple named configurations where each config sets the 4 DRC
registers (R40-R43):
- wlf,drc-cfg-regs
- wlf,drc-cfg-names

Add three properties to describe the equalizer (ReTune Mobile), allowing
multiple named configurations (associated with a samplerate) that set
the 24 (R134-R157) EQ registers:
- wlf,retune-mobile-cfg-regs
- wlf,retune-mobile-cfg-names
- wlf,retune-mobile-cfg-rates

Datasheet: https://statics.cirrus.com/pubs/proDatasheet/WM8904_Rev4.1.pdf
Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
v2: Added an example of how to use the ReTune Mobile config properties
v1: https://lore.kernel.org/lkml/20250206163152.423199-4-francesco@dolcini.it/
---
 .../devicetree/bindings/sound/wlf,wm8904.yaml | 106 ++++++++++++++++++
 1 file changed, 106 insertions(+)

Comments

Rob Herring (Arm) Feb. 24, 2025, 5:19 p.m. UTC | #1
On Mon, 24 Feb 2025 16:54:58 +0100, Francesco Dolcini wrote:
> From: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
> 
> Add two properties to select the IN1L/DMICDAT1 and IN2R/DMICDAT2
> functionality:
> - wlf,in1l-as-dmicdat1
> - wlf,in1r-as-dmicdat2
> 
> Add a property to describe the GPIO configuration registers, that can be
> used to set the four multifunction pins:
> - wlf,gpio-cfg
> 
> Add a property to describe the mic bias control registers:
> - wlf,mic-cfg
> 
> Add two properties to describe the Dynamic Range Controller (DRC),
> allowing multiple named configurations where each config sets the 4 DRC
> registers (R40-R43):
> - wlf,drc-cfg-regs
> - wlf,drc-cfg-names
> 
> Add three properties to describe the equalizer (ReTune Mobile), allowing
> multiple named configurations (associated with a samplerate) that set
> the 24 (R134-R157) EQ registers:
> - wlf,retune-mobile-cfg-regs
> - wlf,retune-mobile-cfg-names
> - wlf,retune-mobile-cfg-rates
> 
> Datasheet: https://statics.cirrus.com/pubs/proDatasheet/WM8904_Rev4.1.pdf
> Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> ---
> v2: Added an example of how to use the ReTune Mobile config properties
> v1: https://lore.kernel.org/lkml/20250206163152.423199-4-francesco@dolcini.it/
> ---
>  .../devicetree/bindings/sound/wlf,wm8904.yaml | 106 ++++++++++++++++++
>  1 file changed, 106 insertions(+)
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:
./Documentation/devicetree/bindings/sound/wlf,wm8904.yaml:167:111: [warning] line too long (154 > 110 characters) (line-length)
./Documentation/devicetree/bindings/sound/wlf,wm8904.yaml:172:111: [warning] line too long (154 > 110 characters) (line-length)
./Documentation/devicetree/bindings/sound/wlf,wm8904.yaml:177:111: [warning] line too long (154 > 110 characters) (line-length)

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/sound/wlf,wm8904.example.dts:52.17-18 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:131: Documentation/devicetree/bindings/sound/wlf,wm8904.example.dtb] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1511: dt_binding_check] Error 2
make: *** [Makefile:251: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20250224155500.52462-4-francesco@dolcini.it

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.
Krzysztof Kozlowski Feb. 25, 2025, 8:41 a.m. UTC | #2
On Mon, Feb 24, 2025 at 04:54:58PM +0100, Francesco Dolcini wrote:
> +  wlf,drc-cfg-regs:
> +    $ref: /schemas/types.yaml#/definitions/uint16-array
> +    description:
> +      Default register values for R40/41/42/43 (DRC).
> +      The list must be 4 times the length of wlf,drc-cfg-names.
> +      If absent, DRC is disabled.
> +
> +  wlf,retune-mobile-cfg-names:
> +    $ref: /schemas/types.yaml#/definitions/string-array
> +    description:
> +      List of strings for the available retune modes.
> +      If absent, retune is disabled.

How is this retune supposed to be used? If by user-space I can easily
imagine that static DTS configuration won't be enough, because you need
to factor for example temperature or some other minor differences
between same boards.

> +
> +  wlf,retune-mobile-cfg-rates:
> +    $ref: /schemas/types.yaml#/definitions/uint32-array

Drop

> +    description:
> +      List of rates for the available retune modes.

Use standard property suffixes - hz or whatever is matching here.

> +      The list must be the same length as wlf,retune-mobile-cfg-names.
> +      If absent, retune is disabled.
> +
> +  wlf,retune-mobile-cfg-regs:
> +    $ref: /schemas/types.yaml#/definitions/uint16-array
> +    description:
> +      Default register values for R134/.../157 (EQ).
> +      The list must be 24 times the length of wlf,retune-mobile-cfg-names.
> +      If absent, retune is disabled.
> +
> +dependencies:
> +  wlf,drc-cfg-names: [ 'wlf,drc-cfg-regs' ]
> +  wlf,drc-cfg-regs: [ 'wlf,drc-cfg-names' ]
> +
> +  wlf,retune-mobile-cfg-names: [ 'wlf,retune-mobile-cfg-rates', 'wlf,retune-mobile-cfg-regs' ]
> +  wlf,retune-mobile-cfg-regs: [ 'wlf,retune-mobile-cfg-names', 'wlf,retune-mobile-cfg-rates' ]
> +  wlf,retune-mobile-cfg-rates: [ 'wlf,retune-mobile-cfg-names', 'wlf,retune-mobile-cfg-regs' ]
> +
>  required:
>    - compatible
>    - reg
> @@ -70,5 +138,43 @@ examples:
>              DBVDD-supply = <&reg_1p8v>;
>              DCVDD-supply = <&reg_1p8v>;
>              MICVDD-supply = <&reg_1p8v>;
> +
> +            wlf,drc-cfg-names = "default", "peaklimiter", "tradition", "soft", "music";
> +            wlf,drc-cfg-regs =
> +                /* coded default: KNEE_IP = KNEE_OP = 0, HI_COMP = LO_COMP = 1  */

Please follow DTS coding style - how you wrap, where to break lines.

> +                /bits/ 16 <0x01af 0x3248 0x0000 0x0000>,
> +                /* coded default: KNEE_IP = -24, KNEE_OP = -6, HI_COMP = 1/4, LO_COMP = 1 */
> +                /bits/ 16 <0x04af 0x324b 0x0010 0x0408>,
> +                /* coded default: KNEE_IP = -42, KNEE_OP = -3, HI_COMP = 0, LO_COMP = 1 */
> +                /bits/ 16 <0x04af 0x324b 0x0028 0x0704>,
> +                /* coded default: KNEE_IP = -45, KNEE_OP = -9, HI_COMP = 1/8, LO_COMP = 1 */
> +                /bits/ 16 <0x04af 0x324b 0x0018 0x078c>,
> +                /* coded default: KNEE_IP = -30, KNEE_OP = -10.5, HI_COMP = 1/4, LO_COMP = 1 */
> +                /bits/ 16 <0x04af 0x324b 0x0010 0x050e>;
> +
> +            wlf,gpio-cfg = <

There is almost never empty line after <

> +                0x0018 /* GPIO1 => DMIC_CLK */
> +                0xffff /* GPIO2 => don't touch */
> +                0xffff /* GPIO3 => don't touch */
> +                0xffff /* GPIO4 => don't touch */

Not mentioning this looks really incorrect or incomplete. No ending of
property.

> +
> +            wlf,retune-mobile-cfg-names = "bassboost", "bassboost", "treble";
> +            wlf,retune-mobile-cfg-rates = <48000 44100 48000>;
> +            wlf,retune-mobile-cfg-regs =
> +                /* bassboost: EQ_ENA = 1, +6 dB @ 100 Hz, +3 dB @ 300 Hz, 0 dB @ 875, 2400, 6900 Hz */
> +                /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
> +                /* default values for ReTune Mobile registers 140-157 */
> +                /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5 0xf145 0x0bd5 0x0075 0x1c58 0xf3d3 0x0a54 0x0568 0x168e 0xf829 0x07ad 0x1103 0x0564 0x0559 0x4000>,

See DTS coding style.

Best regards,
Krzysztof
Ernest Van Hoecke Feb. 27, 2025, 3:34 p.m. UTC | #3
On Tue, Feb 25, 2025 at 09:41:17AM +0100, Krzysztof Kozlowski wrote:
> On Mon, Feb 24, 2025 at 04:54:58PM +0100, Francesco Dolcini wrote:
> > +  wlf,drc-cfg-regs:
> > +    $ref: /schemas/types.yaml#/definitions/uint16-array
> > +    description:
> > +      Default register values for R40/41/42/43 (DRC).
> > +      The list must be 4 times the length of wlf,drc-cfg-names.
> > +      If absent, DRC is disabled.
> > +
> > +  wlf,retune-mobile-cfg-names:
> > +    $ref: /schemas/types.yaml#/definitions/string-array
> > +    description:
> > +      List of strings for the available retune modes.
> > +      If absent, retune is disabled.
> 
> How is this retune supposed to be used? If by user-space I can easily
> imagine that static DTS configuration won't be enough, because you need
> to factor for example temperature or some other minor differences
> between same boards.

This is intended for integrators to be able to specify some EQ options,
mirroring the previous behaviour that was possible via platform data.

I expect most users to use the first five Retune Mobile registers and
not care about the rest, which require a proprietary tool and are not
well documented. The example in the binding shows how some simple
static EQ can be configured. Anyone interested in the extended config
can also use it (statically).

If someone requires dynamic behaviour at runtime that could be a
separate patch that should not be hindered by this static config.

> > +
> > +  wlf,retune-mobile-cfg-rates:
> > +    $ref: /schemas/types.yaml#/definitions/uint32-array
> 
> Drop
> 
> > +    description:
> > +      List of rates for the available retune modes.
> 
> Use standard property suffixes - hz or whatever is matching here.

I will send a v3 later integrating your feedback, I have renamed this
property to wlf,retune-mobile-cfg-hz there, and dropped the "ref".

> > +
> > +            wlf,retune-mobile-cfg-names = "bassboost", "bassboost", "treble";
> > +            wlf,retune-mobile-cfg-rates = <48000 44100 48000>;
> > +            wlf,retune-mobile-cfg-regs =
> > +                /* bassboost: EQ_ENA = 1, +6 dB @ 100 Hz, +3 dB @ 300 Hz, 0 dB @ 875, 2400, 6900 Hz */
> > +                /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
> > +                /* default values for ReTune Mobile registers 140-157 */
> > +                /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5 0xf145 0x0bd5 0x0075 0x1c58 0xf3d3 0x0a54 0x0568 0x168e 0xf829 0x07ad 0x1103 0x0564 0x0559 0x4000>,
> 
> See DTS coding style.
> 
> Best regards,
> Krzysztof
> 

Would the following snippet be a good way to handle wrapping this?
To me the first six registers form an "item" since they are the most
important, followed by the next 18 which belong together, but I was
not sure about the common convention to handle wrapping such a long
item.

/*
 * Config registers per name, respectively:
 * EQ_ENA,  100 Hz,  300 Hz,  875 Hz, 2400 Hz, 6900 Hz
 *      1,   +6 dB,   +3 dB,    0 dB,    0 dB,    0 dB
 *      1,   +6 dB,   +3 dB,    0 dB,    0 dB,    0 dB
 *      1,   -2 dB,   -2 dB,    0 dB,    0 dB,   +3 dB
 * Each one uses the defaults for ReTune Mobile registers 140-157
 */
wlf,retune-mobile-cfg-regs = /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
                             /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5
                                        0xf145 0x0bd5 0x0075 0x1c58
                                        0xf3d3 0x0a54 0x0568 0x168e
                                        0xf829 0x07ad 0x1103 0x0564
                                        0x0559 0x4000>,

                             /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
                             /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5
                                        0xf145 0x0bd5 0x0075 0x1c58
                                        0xf3d3 0x0a54 0x0568 0x168e
                                        0xf829 0x07ad 0x1103 0x0564
                                        0x0559 0x4000>,

                             /bits/ 16 <0x1 0xa 0xa 0xc 0xc 0xf>,
                             /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5
                                        0xf145 0x0bd5 0x0075 0x1c58
                                        0xf3d3 0x0a54 0x0568 0x168e
                                        0xf829 0x07ad 0x1103 0x0564
                                        0x0559 0x4000>;

Apologies for sending the broken binding. I have integrated the rest of
your feedback into v3 which will be sent later. Thanks for taking the
time to review.

Kind regards,
Ernest
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/sound/wlf,wm8904.yaml b/Documentation/devicetree/bindings/sound/wlf,wm8904.yaml
index 329260cf0fa0..f4338efaee18 100644
--- a/Documentation/devicetree/bindings/sound/wlf,wm8904.yaml
+++ b/Documentation/devicetree/bindings/sound/wlf,wm8904.yaml
@@ -38,6 +38,74 @@  properties:
   DCVDD-supply: true
   MICVDD-supply: true
 
+  wlf,in1l-as-dmicdat1:
+    type: boolean
+    description:
+      Use IN1L/DMICDAT1 as DMICDAT1, enabling the DMIC input path.
+
+  wlf,in1r-as-dmicdat2:
+    type: boolean
+    description:
+      Use IN1R/DMICDAT2 as DMICDAT2, enabling the DMIC input path.
+
+  wlf,gpio-cfg:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 4
+    maxItems: 4
+    description:
+      Default register values for R121/122/123/124 (GPIO Control).
+      If any entry has the value 0xFFFF, the related register won't be set.
+    default: [0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF]
+
+  wlf,mic-cfg:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 2
+    maxItems: 2
+    description:
+      Default register values for R6/R7 (Mic Bias Control).
+    default: [0, 0]
+
+  wlf,drc-cfg-names:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description:
+      List of strings for the available DRC modes.
+      If absent, DRC is disabled.
+
+  wlf,drc-cfg-regs:
+    $ref: /schemas/types.yaml#/definitions/uint16-array
+    description:
+      Default register values for R40/41/42/43 (DRC).
+      The list must be 4 times the length of wlf,drc-cfg-names.
+      If absent, DRC is disabled.
+
+  wlf,retune-mobile-cfg-names:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description:
+      List of strings for the available retune modes.
+      If absent, retune is disabled.
+
+  wlf,retune-mobile-cfg-rates:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    description:
+      List of rates for the available retune modes.
+      The list must be the same length as wlf,retune-mobile-cfg-names.
+      If absent, retune is disabled.
+
+  wlf,retune-mobile-cfg-regs:
+    $ref: /schemas/types.yaml#/definitions/uint16-array
+    description:
+      Default register values for R134/.../157 (EQ).
+      The list must be 24 times the length of wlf,retune-mobile-cfg-names.
+      If absent, retune is disabled.
+
+dependencies:
+  wlf,drc-cfg-names: [ 'wlf,drc-cfg-regs' ]
+  wlf,drc-cfg-regs: [ 'wlf,drc-cfg-names' ]
+
+  wlf,retune-mobile-cfg-names: [ 'wlf,retune-mobile-cfg-rates', 'wlf,retune-mobile-cfg-regs' ]
+  wlf,retune-mobile-cfg-regs: [ 'wlf,retune-mobile-cfg-names', 'wlf,retune-mobile-cfg-rates' ]
+  wlf,retune-mobile-cfg-rates: [ 'wlf,retune-mobile-cfg-names', 'wlf,retune-mobile-cfg-regs' ]
+
 required:
   - compatible
   - reg
@@ -70,5 +138,43 @@  examples:
             DBVDD-supply = <&reg_1p8v>;
             DCVDD-supply = <&reg_1p8v>;
             MICVDD-supply = <&reg_1p8v>;
+
+            wlf,drc-cfg-names = "default", "peaklimiter", "tradition", "soft", "music";
+            wlf,drc-cfg-regs =
+                /* coded default: KNEE_IP = KNEE_OP = 0, HI_COMP = LO_COMP = 1  */
+                /bits/ 16 <0x01af 0x3248 0x0000 0x0000>,
+                /* coded default: KNEE_IP = -24, KNEE_OP = -6, HI_COMP = 1/4, LO_COMP = 1 */
+                /bits/ 16 <0x04af 0x324b 0x0010 0x0408>,
+                /* coded default: KNEE_IP = -42, KNEE_OP = -3, HI_COMP = 0, LO_COMP = 1 */
+                /bits/ 16 <0x04af 0x324b 0x0028 0x0704>,
+                /* coded default: KNEE_IP = -45, KNEE_OP = -9, HI_COMP = 1/8, LO_COMP = 1 */
+                /bits/ 16 <0x04af 0x324b 0x0018 0x078c>,
+                /* coded default: KNEE_IP = -30, KNEE_OP = -10.5, HI_COMP = 1/4, LO_COMP = 1 */
+                /bits/ 16 <0x04af 0x324b 0x0010 0x050e>;
+
+            wlf,gpio-cfg = <
+                0x0018 /* GPIO1 => DMIC_CLK */
+                0xffff /* GPIO2 => don't touch */
+                0xffff /* GPIO3 => don't touch */
+                0xffff /* GPIO4 => don't touch */
+
+            wlf,retune-mobile-cfg-names = "bassboost", "bassboost", "treble";
+            wlf,retune-mobile-cfg-rates = <48000 44100 48000>;
+            wlf,retune-mobile-cfg-regs =
+                /* bassboost: EQ_ENA = 1, +6 dB @ 100 Hz, +3 dB @ 300 Hz, 0 dB @ 875, 2400, 6900 Hz */
+                /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
+                /* default values for ReTune Mobile registers 140-157 */
+                /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5 0xf145 0x0bd5 0x0075 0x1c58 0xf3d3 0x0a54 0x0568 0x168e 0xf829 0x07ad 0x1103 0x0564 0x0559 0x4000>,
+
+                /* bassboost: EQ_ENA = 1, +6 dB @ 100 Hz, +3 dB @ 300 Hz, 0 dB @ 875, 2400, 6900 Hz */
+                /bits/ 16 <0x1 0x12 0xf 0xc 0xc 0xc>,
+                /* default values for ReTune Mobile registers 140-157 */
+                /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5 0xf145 0x0bd5 0x0075 0x1c58 0xf3d3 0x0a54 0x0568 0x168e 0xf829 0x07ad 0x1103 0x0564 0x0559 0x4000>,
+
+                /* treble: EQ_ENA = 1, -2 dB @ 100, 300 Hz, 0 dB @ 875, 2400 Hz, +3 dB @ 6900 Hz */
+                /bits/ 16 <0x1 0xa 0xa 0xc 0xc 0xf>,
+                /* default values for ReTune Mobile registers 140-157 */
+                /bits/ 16 <0x0fca 0x0400 0x00d8 0x1eb5 0xf145 0x0bd5 0x0075 0x1c58 0xf3d3 0x0a54 0x0568 0x168e 0xf829 0x07ad 0x1103 0x0564 0x0559 0x4000>;
+            >;
         };
     };