Add device tree binding support to WM8962 codec driver
Subsystems (4)
v2 cover Add device tree binding support to WM8962 codec driver
*** These two patch added devicetree binding support to WM8962 codec driver *** so that it can fetch pdata not only from old platform_data but also from *** newer dts binding.
---
ChangeLog:v1->v2:
* PATCH 1/2:
*** Embedded a copy of struct wm8962_pdata instead of its pointer *** Removed all 'if (pdata)' checking code as it is always valid.
* PATCH 2/2:
*** Dropped out-of-band value error msg by regarding it as default value.
Nicolin Chen (2):
ASoC: WM8962: Create default platform data structure
ASoC: WM8962: Add device tree binding
Documentation/devicetree/bindings/sound/wm8962.txt | 20 ++++ sound/soc/codecs/wm8962.c | 99 +++++++++++++------ 2 files changed, 88 insertions(+), 31 deletions(-)
PATCH v2 1/2 ASoC: WM8962: Create default platform data structure
Embed a copy of struct wm8962_pdata in stuct wm8962_priv so that there's no need to check validity of pdata any more.
--- sound/soc/codecs/wm8962.c | 66 ++++++++++++++++++++++++--------------------- 1 files changed, 35 insertions(+), 31 deletions(-)
sound/soc/codecs/wm8962.c +35 -31
@@ -51,6 +51,7 @@ static const char *wm8962_supply_names[WM8962_NUM_SUPPLIES] = {/* codec private data */ struct wm8962_priv { +struct wm8962_pdata pdata;struct regmap *regmap;struct snd_soc_codec *codec;
@@ -2345,12 +2346,13 @@ static const struct snd_soc_dapm_route wm8962_spk_stereo_intercon[] = {static int wm8962_add_widgets (struct snd_soc_codec *codec) { -struct wm8962_pdata *pdata =dev_get_platdata (codec->dev); +struct wm8962_priv *wm8962 =snd_soc_codec_get_drvdata (codec); +struct wm8962_pdata *pdata = &wm8962->pdata;struct snd_soc_dapm_context *dapm = &codec->dapm;snd_soc_add_codec_controls (codec, wm8962_snd_controls,ARRAY_SIZE (wm8962_snd_controls)); -if (pdata && pdata->spk_mono) +if (pdata->spk_mono)snd_soc_add_codec_controls (codec, wm8962_spk_mono_controls,ARRAY_SIZE (wm8962_spk_mono_controls));else
@@ -2360,7 +2362,7 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)snd_soc_dapm_new_controls (dapm, wm8962_dapm_widgets,ARRAY_SIZE (wm8962_dapm_widgets)); -if (pdata && pdata->spk_mono) +if (pdata->spk_mono)snd_soc_dapm_new_controls (dapm, wm8962_dapm_spk_mono_widgets,ARRAY_SIZE (wm8962_dapm_spk_mono_widgets));else
@@ -2369,7 +2371,7 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)snd_soc_dapm_add_routes (dapm, wm8962_intercon,ARRAY_SIZE (wm8962_intercon)); -if (pdata && pdata->spk_mono) +if (pdata->spk_mono)snd_soc_dapm_add_routes (dapm, wm8962_spk_mono_intercon,ARRAY_SIZE (wm8962_spk_mono_intercon));else
@@ -3333,14 +3335,14 @@ static struct gpio_chip wm8962_template_chip = {static void wm8962_init_gpio (struct snd_soc_codec *codec) {struct wm8962_priv *wm8962 =snd_soc_codec_get_drvdata (codec); -struct wm8962_pdata *pdata =dev_get_platdata (codec->dev); +struct wm8962_pdata *pdata = &wm8962->pdata;int ret; wm8962->gpio_chip = wm8962_template_chip; wm8962->gpio_chip.ngpio =WM8962_MAX_GPIO ; wm8962->gpio_chip.dev = codec->dev; -if (pdata && pdata->gpio_base) +if (pdata->gpio_base) wm8962->gpio_chip.base = pdata->gpio_base;else wm8962->gpio_chip.base =-1 ;
@@ -3373,7 +3375,7 @@ static int wm8962_probe(struct snd_soc_codec *codec) {int ret;struct wm8962_priv *wm8962 =snd_soc_codec_get_drvdata (codec); -struct wm8962_pdata *pdata =dev_get_platdata (codec->dev); +struct wm8962_pdata *pdata = &wm8962->pdata;u16 *reg_cache = codec->reg_cache;int i, trigger, irq_pol;bool dmicclk, dmicdat;
@@ -3421,30 +3423,28 @@ static int wm8962_probe(struct snd_soc_codec *codec)WM8962_OSC_ENA |WM8962_PLL2_ENA |WM8962_PLL3_ENA , 0); -if (pdata) { -/* Apply static configuration for GPIOs */ -for (i =0 ; i <ARRAY_SIZE (pdata->gpio_init); i++) -if (pdata->gpio_init[i]) { -wm8962_set_gpio_mode (codec, i +1 ); -snd_soc_write (codec,0x200 + i, - pdata->gpio_init[i] &0xffff ); - } +/* Apply static configuration for GPIOs */ +for (i =0 ; i <ARRAY_SIZE (pdata->gpio_init); i++) +if (pdata->gpio_init[i]) { +wm8962_set_gpio_mode (codec, i +1 ); +snd_soc_write (codec,0x200 + i, + pdata->gpio_init[i] &0xffff ); + } -/* Put the speakers into mono mode? */ -if (pdata->spk_mono) - reg_cache[WM8962_CLASS_D_CONTROL_2 ] - |=WM8962_SPK_MONO ; +/* Put the speakers into mono mode? */ +if (pdata->spk_mono) + reg_cache[WM8962_CLASS_D_CONTROL_2 ] + |=WM8962_SPK_MONO ; -/* Micbias setup, detection enable and detection -* threasholds. */ -if (pdata->mic_cfg) -snd_soc_update_bits (codec,WM8962_ADDITIONAL_CONTROL_4 , -WM8962_MICDET_ENA | -WM8962_MICDET_THR_MASK | -WM8962_MICSHORT_THR_MASK | -WM8962_MICBIAS_LVL , - pdata->mic_cfg); - } +/* Micbias setup, detection enable and detection +* threasholds. */ +if (pdata->mic_cfg) +snd_soc_update_bits (codec,WM8962_ADDITIONAL_CONTROL_4 , +WM8962_MICDET_ENA | +WM8962_MICDET_THR_MASK | +WM8962_MICSHORT_THR_MASK | +WM8962_MICBIAS_LVL , + pdata->mic_cfg);/* Latch volume update bits */ snd_soc_update_bits(codec, WM8962_LEFT_INPUT_VOLUME,
@@ -3506,7 +3506,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)wm8962_init_gpio (codec);if (wm8962->irq) { -if (pdata && pdata->irq_active_low) { +if (pdata->irq_active_low) { trigger =IRQF_TRIGGER_LOW ; irq_pol =WM8962_IRQ_POL ; }else {
@@ -3603,6 +3603,10 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,init_completion (&wm8962->fll_lock); wm8962->irq = i2c->irq; +/* If platform data was supplied, update the default data in priv */ +if (pdata) +memcpy (&wm8962->pdata, pdata,sizeof (struct wm8962_pdata )); +for (i =0 ; i <ARRAY_SIZE (wm8962->supplies); i++) wm8962->supplies[i].supply = wm8962_supply_names[i];
@@ -3666,7 +3670,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c, goto err_enable; } -if (pdata && pdata->in4_dc_measure) { +if (wm8962->pdata.in4_dc_measure) { ret =regmap_register_patch (wm8962->regmap, wm8962_dc_measure,ARRAY_SIZE (wm8962_dc_measure));
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): 7e99c1946386e241854a3d7659a7a6d4201a5b34.1370518627.git.b42378-KZfg59tc24xl57MIdRCFDg@public.gmane.org
Mark Brown
AppliedRe: [PATCH V2 1/2] ASoC: WM8962: Create default platform data structure
Quoted 2 lines · Nicolin Chen
Embed a copy of struct
wm8962_pdatain stuctwm8962_privso that there's no need to check validity of pdata any more.
Applied, thanks.
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
PATCH v2 2/2 ASoC: WM8962: Add device tree binding
In reply to Nicolin ChenDocument the device tree binding for the WM8962 codec, and modify the driver to extract platform data from the device tree, if present.
Based on work of WM8903 by Stephen Warren <[email protected]>
--- Documentation/devicetree/bindings/sound/wm8962.txt | 20 +++++++++++ sound/soc/codecs/wm8962.c | 35 +++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletions(-)
Documentation/devicetree/bindings/sound/wm8962.txt +20 -0
@@ -8,9 +8,29 @@ Required properties: - reg : the I2C address of the device. +Optional properties: + - spk-mono: Default register value for SPK_MONO of R51 (Class D Control 2). + + - mic-cfg : Default register value for R48 (Additional Control 4). + If absent, the default is 0. + + - gpio-cfg : A list of GPIO configuration register values. The list must + be 6 entries long. If absent, no configuration of these registers is + performed. And note that only the value within [0x0, 0xffff] is valid. + Any other value will be regarded as setting the GPIO register by its + default value 0x0. Example: codec: wm8962@1a { compatible = "wlf,wm8962"; reg = <0x1a>; + + gpio-cfg = < + 0x0000 /* 0:Default */ + 0x0000 /* 1:Default */ + 0x0013 /* 2:FN_DMICCLK */ + 0x0000 /* 3:Default */ + 0x8014 /* 4:FN_DMICCDAT */ + 0x0000 /* 5:Default */ + >; };
sound/soc/codecs/wm8962.c +34 -1
@@ -3584,6 +3584,34 @@ static const struct regmap_config wm8962_regmap = { .cache_type = REGCACHE_RBTREE, }; +static int wm8962_set_pdata_from_of (struct i2c_client *i2c, +struct wm8962_pdata *pdata) +{ +const struct device_node *np = i2c->dev.of_node; +u32 val32; +int i; + +if (of_property_read_bool (np,"spk-mono" )) + pdata->spk_mono = true; + +if (of_property_read_u32 (np,"mic-cfg" , &val32) >=0 ) + pdata->mic_cfg = val32; + +if (of_property_read_u32_array (np,"gpio-cfg" , pdata->gpio_init, +ARRAY_SIZE (pdata->gpio_init)) >=0 ) +for (i =0 ; i <ARRAY_SIZE (pdata->gpio_init); i++) { +/* +* The range of GPIO register value is [0x0, 0xffff] +* While the default value of each register is 0x0 +* Any other value will be regarded as default value +*/ +if (pdata->gpio_init[i] >0xffff ) + pdata->gpio_init[i] =0x0 ; + } + +return 0 ; +} +static int wm8962_i2c_probe (struct i2c_client *i2c,const struct i2c_device_id *id) {
@@ -3604,8 +3632,13 @@ static int wm8962_i2c_probe(struct i2c_client *i2c, wm8962->irq = i2c->irq;/* If platform data was supplied, update the default data in priv */ -if (pdata) +if (pdata) {memcpy (&wm8962->pdata, pdata,sizeof (struct wm8962_pdata )); + }else if (i2c->dev.of_node) { + ret =wm8962_set_pdata_from_of (i2c, &wm8962->pdata); +if (ret !=0 ) +return ret; + }for (i =0 ; i <ARRAY_SIZE (wm8962->supplies); i++) wm8962->supplies[i].supply = wm8962_supply_names[i];
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): a7acc6e603272a9d48324712f54da9bb1fa46889.1370518627.git.b42378-KZfg59tc24xl57MIdRCFDg@public.gmane.org
Re: [PATCH V2 2/2] ASoC: WM8962: Add device tree binding
Documentation/devicetree/bindings/sound/wm8962.txt Required properties: · line 12
Quoted 2 lines · Nicolin Chen
Documentation/devicetree/bindings/sound/wm8962.txt +2
-0+Optional properties: + - spk-mono: Default register value for SPK_MONO of R51 (Class D Control 2).
This doesn't correspond to the code. This is a boolean property, if it's present then that bit gets set indicating that the speaker is in mono mode.
Documentation/devicetree/bindings/sound/wm8962.txt Required properties: · line 15
Quoted 2 lines
Documentation/devicetree/bindings/sound/wm8962.txt +2
-0+ - mic-cfg : Default register value for R48 (Additional Control 4). + If absent, the default is 0.
Again if it's absent the default should be the register default.
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss