ASoC: Add device tree binding for WM8903
Subsystems (5)
PATCH 1/1 ASoC: Add device tree binding for WM8903
From: John Bonesio <bones-s3s/[email protected]>
This patch makes it so the wm8903 is initialized from it's device tree node.
v2: (swarren) Significantly reworked based on review feedback.
v1: (swarren) Applied the following modifications relative to John's code:
* Cleaned up DT parsing code
* Documented DT binding
* Set up wm8903->gpio_chip.of_node, extracted from another patch by John.
--- Documentation/devicetree/bindings/sound/wm8903.txt | 44 ++++++++ sound/soc/codecs/wm8903.c | 113 ++++++++++++++++---- 2 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/wm8903.txt
Documentation/devicetree/bindings/sound/wm8903.txt new file +44 -0
@@ -0,0 +1,44 @@ +WM89033 audio CODEC + +This device supports I2C only. + +Required properties: + + - compatible : "wlf,wm8903" + + - reg : the I2C address of the device. + + - gpio-controller : Indicates this device is a GPIO controller. + + - #gpio-cells : Should be two. The first cell is the pin number and the + second cell is used to specify optional parameters (currently unused). + +Optional properties: + + - interrupts : The interrupt line the codec is connected to. + + - micdet-cfg : Default register value for R6 (Mic Bias). If absent, the + default is 0. + + - micdet-delay : The debounce delay for microphone detection in mS. If + absent, the default is 100. + + - gpio-cfg : A list of GPIO pin mux register values. The list must be 5 + entries long. If absent, no configuration of these registers is + performed. If any entry has the value 0xffffffff, that GPIO's + configuration will not be modified. + +Example: + +codec: wm8903@1a { + compatible = "wlf,wm8903"; + reg = <0x1a>; + interrupts = < 347 >; + + gpio-controller; + #gpio-cells = <2>; + + micdet-cfg = <0>; + micdet-delay = <100>; + gpio-cfg = < 0xffffffff 0xffffffff 0 0xffffffff 0xffffffff >; +};
sound/soc/codecs/wm8903.c +92 -21
193 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Quoted 5 lines · Stephen Warren
v2: (swarren) Significantly reworked based on review feedback.
v1: (swarren) Applied the following modifications relative to John's code:
* Cleaned up DT parsing code
* Documented DT binding
* Set upwm8903->gpio_chip.of_node, extracted from another patch by John.
Don't put stuff like this in the changelog. "Significantly reworked" isn't going to help anyone reading the logs...
Documentation/devicetree/bindings/sound/wm8903.txt line 43
Quoted 3 lines
Documentation/devicetree/bindings/sound/wm8903.txt new file +3
-0+ micdet-cfg = <0>; + micdet-delay = <100>; + gpio-cfg = < 0xffffffff 0xffffffff 0 0xffffffff 0xffffffff >;
Better to have sane examples for gpio-cfg.
sound/soc/codecs/wm8903.c static struct gpio_chip wm8903_template_chip = { · line 1869
Quoted 4 lines
sound/soc/codecs/wm8903.c +2
-1-static void wm8903_init_gpio (struct snd_soc_codec *codec) +static void wm8903_init_gpio (struct snd_soc_codec *codec, +int gpio_base) {
Can you do this restructuring separately please? The diff is *much* larger than I'd expect and stuff liket his isn't helping.
sound/soc/codecs/wm8903.c static struct gpio_chip wm8903_template_chip = { · line 1880
Quoted 3 lines
sound/soc/codecs/wm8903.c +3
-0+#ifdef CONFIG_OF_GPIO + wm8903->gpio_chip.of_node = codec->dev->of_node; +#endif
Ick, ifdefs mid code :(
Quoted 7 lines
sound/soc/codecs/wm8903.c +1
-1@@ -1931,18 +1942,65 @@ static int wm8903_probe(struct snd_soc_codec *codec)wm8903_reset (codec); -/* Set up GPIOs and microphone detection */ +/* Get configuration from platform data, or device tree */
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 1954
Quoted 10 lines
sound/soc/codecs/wm8903.c +8
-1if (pdata) { -bool mic_gpio = false; + have_pdata = true; + gpio_base = pdata->gpio_base; + irq_active_low = pdata->irq_active_low; + micdet_cfg = pdata->micdet_cfg; + wm8903->mic_delay = pdata->micdet_delay; + gpio_cfg = &pdata->gpio_cfg[0 ]; + }else if (codec->dev->of_node) { + have_pdata = true;
This all seems really complicated and invasive, especially the have_pdata flag. Why not just always have a platform data structure and fill it in from the device tree?
Quoted 13 lines
sound/soc/codecs/wm8903.c +13
-0+if (wm8903->irq) { + irq_data =irq_get_irq_data (wm8903->irq); +if (!irq_data) { +dev_err (codec->dev,"Invalid IRQ: %d\n" , + wm8903->irq); +return -EINVAL ; + } + trigger =irqd_get_trigger_type (irq_data); +switch (trigger) { +case IRQ_TYPE_NONE : +case IRQ_TYPE_LEVEL_HIGH : + irq_active_low = false; +break ;
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 1980
Quoted 10 lines
sound/soc/codecs/wm8903.c +10
-0+case IRQ_TYPE_LEVEL_LOW : + irq_active_low = true; +break ; +default : +dev_err (codec->dev, +"Unsupported IRQ trigger: %x\n" , + trigger); +return -EINVAL ; + } + }
This stuff isn't device tree specific.
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 2001
Quoted 9 lines
sound/soc/codecs/wm8903.c +5
-1+/* Set up GPIOs */ +if (gpio_cfg) { +for (i =0 ; i <WM8903_NUM_GPIO ; i++) { +if (gpio_cfg[i] >0x7fff )continue ;snd_soc_write (codec,WM8903_GPIO_CONTROL_1 + i, - pdata->gpio_cfg[i] &0xffff ); + gpio_cfg[i] &0x7fff );
This is a separate change to the semantics and should be split out.
sound/soc/codecs/wm8903.c static __devexit int wm8903_i2c_remove(struct i2c_client *client) · line 2171
Quoted 10 lines
sound/soc/codecs/wm8903.c +10
-0+#ifdef CONFIG_OF +/* Match table for of_platform binding */ +static const struct of_device_id wm8903_of_match[]__devinitconst = { + { .compatible ="wlf,wm8903" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, wm8903_of_match); +#else +#define wm8903_of_match NULL +#endif
If you're going to do this then go through and consistently add the defines. I'd also be inclined to drop the comment.
Documentation/devicetree/bindings/sound/wm8903.txt line 1
Quoted 4 lines · Stephen Warren
Documentation/devicetree/bindings/sound/wm8903.txt new file +1
-0@@ -0,0 +1,44 @@ +WM89033 audio CODEC
Just a nitpick. s/WM89033/WM8903/
Signature · 2 lines
Best regards, Dmitry "MAD" Artamonow
Mark Brown wrote at Thursday, December 01, 2011 6:26 AM:
Quoted 10 lines · Stephen Warren
Quoted 6 lines
v2: (swarren) Significantly reworked based on review feedback.
v1: (swarren) Applied the following modifications relative to John's code:
* Cleaned up DT parsing code
* Documented DT binding
* Set upwm8903->gpio_chip.of_node, extracted from another patch by John.Don't put stuff like this in the changelog. "Significantly reworked" isn't going to help anyone reading the logs...
Sorry, I forgot to move it this time.
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/wm8903.c +0
-0@@ -1931,18 +1942,65 @@ static int wm8903_probe(struct snd_soc_codec *codec)wm8903_reset (codec);
Quoted 16 lines
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 1954
Quoted 12 lines
sound/soc/codecs/wm8903.c +9
-2-/* Set up GPIOs and microphone detection */ +/* Get configuration from platform data, or device tree */ if (pdata) { -bool mic_gpio = false; + have_pdata = true; + gpio_base = pdata->gpio_base; + irq_active_low = pdata->irq_active_low; + micdet_cfg = pdata->micdet_cfg; + wm8903->mic_delay = pdata->micdet_delay; + gpio_cfg = &pdata->gpio_cfg[0 ]; + }else if (codec->dev->of_node) { + have_pdata = true;This all seems really complicated and invasive, especially the
have_pdataflag. Why not just always have a platform data structure and fill it in from the device tree?
The first patch set did that, and you objected to how it was structured...
Quoted 17 lines
Quoted 17 lines
sound/soc/codecs/wm8903.c +17
-0+if (wm8903->irq) { + irq_data =irq_get_irq_data (wm8903->irq); +if (!irq_data) { +dev_err (codec->dev,"Invalid IRQ: %d\n" , + wm8903->irq); +return -EINVAL ; + } + trigger =irqd_get_trigger_type (irq_data); +switch (trigger) { +case IRQ_TYPE_NONE : +case IRQ_TYPE_LEVEL_HIGH : + irq_active_low = false; +break ; +case IRQ_TYPE_LEVEL_LOW : + irq_active_low = true; +break ; +default :
Quoted 8 lines
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 1980
Quoted 6 lines
sound/soc/codecs/wm8903.c +6
-0+dev_err (codec->dev, +"Unsupported IRQ trigger: %x\n" , + trigger); +return -EINVAL ; + } + }This stuff isn't device tree specific.
OK, I could remove the platform data's irq_active_low flag, and determine the IRQ polarity this way in all cases. Do you want that? I avoided doing it this time around since it'd affect non-device-tree users of the codec too, and I aimed for complete backwards compatibility (although that said, the only in-tree user is the Tegra machines, and they don't set this flag, so the impact would be minimal in-tree)
Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/wm8903.c +5
-0+#ifdef CONFIG_OF +/* Match table for of_platform binding */ +static const struct of_device_id wm8903_of_match[]__devinitconst = { + { .compatible ="wlf,wm8903" , }, + {},
Quoted 8 lines
sound/soc/codecs/wm8903.c static __devexit int wm8903_i2c_remove(struct i2c_client *client) · line 2171
Quoted 5 lines
sound/soc/codecs/wm8903.c +5
-0+}; +MODULE_DEVICE_TABLE (of, wm8903_of_match); +#else +#define wm8903_of_match NULL +#endif If you're going to do this then go through and consistently add the defines. I'd also be inclined to drop the comment.
I'll just drop the ifdefs; looking at all the other codecs, they don't have ifdefs anyway - I thought I added the ifdefs to be consistent, but I must have checked something other than ASoC codecs...
Signature · 1 line
nvpublic
Quoted 7 lines · Stephen Warren
Mark Brown wrote at Thursday, December 01, 2011 6:26 AM:
Quoted 3 lines
This all seems really complicated and invasive, especially the
have_pdataflag. Why not just always have a platform data structure and fill it in from the device tree?The first patch set did that, and you objected to how it was structured...
No, that's what I asked you to do first time round (or at least what we discussed on IRC). The problem with the first version was that you had two unrelated places where the defaults were specified, the problem with this version is that you copy everything into new variables which makes the diff really big and noisy. I'd *really* expect the device tree data to just be a different way of supplying platform data.
Quoted 10 lines
Quoted 3 lines
sound/soc/codecs/wm8903.c static int wm8903_probe(struct snd_soc_codec *codec) · line 1965
Quoted 1 line
sound/soc/codecs/wm8903.c +1
-0+ trigger =irqd_get_trigger_type (irq_data);This stuff isn't device tree specific.
OK, I could remove the platform data's
irq_active_lowflag, and determine the IRQ polarity this way in all cases. Do you want that? I avoided doing it this time around since it'd affect non-device-tree users of the codec too, and I aimed for complete backwards compatibility (although that said, the only in-tree user is the Tegra machines, and they don't set this flag, so the impact would be minimal in-tree)
As a first step I'd use this code to set the default if the platform data doesn't set the flag.