ASoC: da7213: Add DT support for codec
Subsystems (4)
v2 cover ASoC: da7213: Add DT support for codec
This patch set adds DT support to the codec driver, and supporting bindings documentation.
Patch set is based against v4.3-rc4
Changes in v2:
- Split mclk data support changes into separate patch
- Use of_match_ptr() for match table assignment
- Only call clk_prepare_enable/disable() if mclk data provided (not NULL).
- Add error checking for clk_prepare_enable() usage.
Adam Thomson (3):
ASoC: da7213: Add DT support to codec driver
ASoC: da7213: Add support to handle mclk data provided to driver
ASoC: da7213: Add bindings documentation for codec driver
Documentation/devicetree/bindings/sound/da7213.txt | 41 +++++ include/sound/da7213.h | 3 - sound/soc/codecs/da7213.c | 190 +++++++++++++++++++-- sound/soc/codecs/da7213.h | 8 +- 4 files changed, 221 insertions(+), 21 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/da7213.txt
--
1.9.3
PATCH v2 1/3 ASoC: da7213: Add DT support to codec driver
This patch adds support for DT bindings in the codec driver. As part of this support, the mclk data can now be provided and used to control the mclk during codec operation.
--- sound/soc/codecs/da7213.c | 123 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 5 deletions(-)
sound/soc/codecs/da7213.c +118 -5
@@ -1387,10 +1387,118 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,return 0 ; } +/* DT */ +static const struct of_device_id da7213_of_match[] = { + { .compatible ="dlg,da7213" , }, + { } +}; +MODULE_DEVICE_TABLE (of, da7213_of_match); + +static enum da7213_micbias_voltage +da7213_of_micbias_lvl (struct snd_soc_codec *codec,u32 val) +{ +switch (val) { +case 1600 : +return DA7213_MICBIAS_1_6V ; +case 2200 : +return DA7213_MICBIAS_2_2V ; +case 2500 : +return DA7213_MICBIAS_2_5V ; +case 3000 : +return DA7213_MICBIAS_3_0V ; +default : +dev_warn (codec->dev,"Invalid micbias level\n" ); +return DA7213_MICBIAS_2_2V ; + } +} + +static enum da7213_dmic_data_sel +da7213_of_dmic_data_sel (struct snd_soc_codec *codec,const char *str) +{ +if (!strcmp (str,"lrise_rfall" )) { +return DA7213_DMIC_DATA_LRISE_RFALL ; + }else if (!strcmp (str,"lfall_rrise" )) { +return DA7213_DMIC_DATA_LFALL_RRISE ; + }else { +dev_warn (codec->dev,"Invalid DMIC data select type\n" ); +return DA7213_DMIC_DATA_LRISE_RFALL ; + } +} + +static enum da7213_dmic_samplephase +da7213_of_dmic_samplephase (struct snd_soc_codec *codec,const char *str) +{ +if (!strcmp (str,"on_clkedge" )) { +return DA7213_DMIC_SAMPLE_ON_CLKEDGE ; + }else if (!strcmp (str,"between_clkedge" )) { +return DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE ; + }else { +dev_warn (codec->dev,"Invalid DMIC sample phase\n" ); +return DA7213_DMIC_SAMPLE_ON_CLKEDGE ; + } +} + +static enum da7213_dmic_clk_rate +da7213_of_dmic_clkrate (struct snd_soc_codec *codec,u32 val) +{ +switch (val) { +case 1500000 : +return DA7213_DMIC_CLK_1_5MHZ ; +case 3000000 : +return DA7213_DMIC_CLK_3_0MHZ ; +default : +dev_warn (codec->dev,"Invalid DMIC clock rate\n" ); +return DA7213_DMIC_CLK_1_5MHZ ; + } +} + +static struct da7213_platform_data + *da7213_of_to_pdata (struct snd_soc_codec *codec) +{ +struct device_node *np = codec->dev->of_node; +struct da7213_platform_data *pdata; +const char *of_str; +u32 of_val32; + + pdata =devm_kzalloc (codec->dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) { +dev_warn (codec->dev,"Failed to allocate memory for pdata\n" ); +return NULL ; + } + +if (of_property_read_u32 (np,"dlg,micbias1-lvl" , &of_val32) >=0 ) + pdata->micbias1_lvl =da7213_of_micbias_lvl (codec, of_val32); +else + pdata->micbias1_lvl =DA7213_MICBIAS_2_2V ; + +if (of_property_read_u32 (np,"dlg,micbias2-lvl" , &of_val32) >=0 ) + pdata->micbias2_lvl =da7213_of_micbias_lvl (codec, of_val32); +else + pdata->micbias2_lvl =DA7213_MICBIAS_2_2V ; + +if (!of_property_read_string (np,"dlg,dmic-data-sel" , &of_str)) + pdata->dmic_data_sel =da7213_of_dmic_data_sel (codec, of_str); +else + pdata->dmic_data_sel =DA7213_DMIC_DATA_LRISE_RFALL ; + +if (!of_property_read_string (np,"dlg,dmic-samplephase" , &of_str)) + pdata->dmic_samplephase = +da7213_of_dmic_samplephase (codec, of_str); +else + pdata->dmic_samplephase =DA7213_DMIC_SAMPLE_ON_CLKEDGE ; + +if (of_property_read_u32 (np,"dlg,dmic-clkrate" , &of_val32) >=0 ) + pdata->dmic_clk_rate =da7213_of_dmic_clkrate (codec, of_val32); +else + pdata->dmic_clk_rate =DA7213_DMIC_CLK_3_0MHZ ; + +return pdata; +} + +static int da7213_probe (struct snd_soc_codec *codec) {struct da7213_priv *da7213 =snd_soc_codec_get_drvdata (codec); -struct da7213_platform_data *pdata = da7213->pdata;/* Default to using ALC auto offset calibration mode. */ snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
@@ -1450,8 +1558,15 @@ static int da7213_probe(struct snd_soc_codec *codec)snd_soc_update_bits (codec,DA7213_LINE_CTRL ,DA7213_LINE_AMP_OE ,DA7213_LINE_AMP_OE ); +/* Handle DT/Platform data */ +if (codec->dev->of_node) + da7213->pdata =da7213_of_to_pdata (codec); +else + da7213->pdata =dev_get_platdata (codec->dev); +/* Set platform data values */ if (da7213->pdata) { +struct da7213_platform_data *pdata = da7213->pdata;u8 micbias_lvl =0 , dmic_cfg =0 ;/* Set Mic Bias voltages */
@@ -1507,6 +1622,7 @@ static int da7213_probe(struct snd_soc_codec *codec)/* Set MCLK squaring */ da7213->mclk_squarer_en = pdata->mclk_squaring; } +return 0 ; }
@@ -1537,7 +1653,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) {struct da7213_priv *da7213; -struct da7213_platform_data *pdata =dev_get_platdata (&i2c->dev);int ret; da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv),
@@ -1545,9 +1660,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c,if (!da7213)return -ENOMEM ; -if (pdata) - da7213->pdata = pdata; -i2c_set_clientdata (i2c, da7213); da7213->regmap =devm_regmap_init_i2c (i2c, &da7213_regmap_config);
@@ -1582,6 +1694,7 @@ MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);static struct i2c_driver da7213_i2c_driver = { .driver = { .name ="da7213" , + .of_match_table =of_match_ptr (da7213_of_match), }, .probe = da7213_i2c_probe, .remove = da7213_remove,
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 2/3 ASoC: da7213: Add support to handle mclk data provided to driver
In reply to Adam ThomsonDriver now can make use of mclk data, if provided, to set, enable and disable the clock source. As part of this, the choice to enable clock squaring is dealt with as part of dai_sysclk() call rather than as platform data.
--- include/sound/da7213.h | 3 --- sound/soc/codecs/da7213.c | 67 +++++++++++++++++++++++++++++++++++++++-------- sound/soc/codecs/da7213.h | 8 ++++-- 3 files changed, 62 insertions(+), 16 deletions(-)
include/sound/da7213.h +0 -3
@@ -44,9 +44,6 @@ struct da7213_platform_data {enum da7213_dmic_data_sel dmic_data_sel;enum da7213_dmic_samplephase dmic_samplephase; enum da7213_dmic_clk_rate dmic_clk_rate; - -/* MCLK squaring config */ - bool mclk_squaring; };#endif /* _DA7213_PDATA_H */
sound/soc/codecs/da7213.c +56 -11
112 lines not on this page · raw message
sound/soc/codecs/da7213.h +6 -2
@@ -13,6 +13,7 @@#ifndef _DA7213_H#define _DA7213_H +#include <linux/clk.h> #include <linux/regmap.h> #include <sound/da7213.h>
@@ -504,14 +505,17 @@#define DA7213_PLL_INDIV_20_40_MHZ_VAL 8#define DA7213_PLL_INDIV_40_54_MHZ_VAL 16 -enum clk_src { -DA7213_CLKSRC_MCLK +enum da7213_clk_src { +DA7213_CLKSRC_MCLK =0 , +DA7213_CLKSRC_MCLK_SQR , };/* Codec private data */ struct da7213_priv {struct regmap *regmap; +struct clk *mclk;unsigned int mclk_rate; +int clk_src;bool master;bool mclk_squarer_en;bool srm_en;
--
1.9.3
PATCH v2 3/3 ASoC: da7213: Add bindings documentation for codec driver
In reply to Adam Thomson--- Documentation/devicetree/bindings/sound/da7213.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/da7213.txt
Documentation/devicetree/bindings/sound/da7213.txt new file +41 -0
@@ -0,0 +1,41 @@ +Dialog Semiconductor DA7213 Audio Codec bindings + +====== + +Required properties: +- compatible : Should be "dlg,da7213" +- reg: Specifies the I2C slave address + +Optional properties: +- clocks : phandle and clock specifier for codec MCLK. +- clock-names : Clock name string for 'clocks' attribute, should be "mclk". + +- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1 + [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>] +- dlg,dmic-data-sel : DMIC channel select based on clock edge. + ["lrise_rfall", "lfall_rrise"] +- dlg,dmic-samplephase : When to sample audio from DMIC. + ["on_clkedge", "between_clkedge"] +- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>] + +====== + +Example: + + codec_i2c: da7213@1a { + compatible = "dlg,da7213"; + reg = <0x1a>; + + clocks = <&clks 201>; + clock-names = "mclk"; + + dlg,micbias1-lvl = <2500>; + dlg,micbias2-lvl = <2500>; + + dlg,dmic-data-sel = "lrise_rfall"; + dlg,dmic-samplephase = "between_clkedge"; + dlg,dmic-clkrate = <3000000>; + };
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/3] ASoC: da7213: Add bindings documentation for codec driver
Quoted 18 lines · Adam Thomson
Signed-off-by Adam Thomson <[email protected]>--- Documentation/devicetree/bindings/sound/da7213.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/da7213.txtDocumentation/devicetree/bindings/sound/da7213.txt new file +6
-0@@ -0,0 +1,41 @@ +Dialog Semiconductor DA7213 Audio Codec bindings + +====== + +Required properties: +- compatible : Should be "dlg,da7213"
Documentation/devicetree/bindings/sound/da7213.txt line 16
Quoted 10 lines
Documentation/devicetree/bindings/sound/da7213.txt new file +10
-0+- reg: Specifies the I2C slave address + +Optional properties: +- clocks : phandle and clock specifier for codec MCLK. +- clock-names : Clock name string for 'clocks' attribute, should be "mclk". + +- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1 + [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>]
Please append the units (-microvolt).
Documentation/devicetree/bindings/sound/da7213.txt line 20
Quoted 4 lines
Documentation/devicetree/bindings/sound/da7213.txt new file +4
-0+- dlg,dmic-data-sel : DMIC channel select based on clock edge. + ["lrise_rfall", "lfall_rrise"] +- dlg,dmic-samplephase : When to sample audio from DMIC. + ["on_clkedge", "between_clkedge"]
How about boolean for these two.
Documentation/devicetree/bindings/sound/da7213.txt line 22
Quoted 2 lines
Documentation/devicetree/bindings/sound/da7213.txt new file +2
-0+- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>]
So 1.5GHz or 3GHz?
Add units (-hz).
Quoted 20 lines
Documentation/devicetree/bindings/sound/da7213.txt new file +19
-1+ +====== + +Example: + + codec_i2c: da7213@1a { + compatible = "dlg,da7213"; + reg = <0x1a>; + + clocks = <&clks 201>; + clock-names = "mclk"; + + dlg,micbias1-lvl = <2500>; + dlg,micbias2-lvl = <2500>; + + dlg,dmic-data-sel = "lrise_rfall"; + dlg,dmic-samplephase = "between_clkedge"; + dlg,dmic-clkrate = <3000000>; + }; --
Quoted 2 lines
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v2 3/3] ASoC: da7213: Add bindings documentation for codec driver
Quoted 6 lines · Rob Herring
Documentation/devicetree/bindings/sound/da7213.txt line 16
Quoted 4 lines
+- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>]Please append the units (-microvolt).
Given that a user needs to read the bindings document to understand what is available, and what they're for, this seems a little unnecessary.
Quoted 7 lines
Documentation/devicetree/bindings/sound/da7213.txt line 20
Quoted 5 lines
+- dlg,dmic-data-sel : DMIC channel select based on clock edge.
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ ["lrise_rfall", "lfall_rrise"] +- dlg,dmic-samplephase : When to sample audio from DMIC. + ["on_clkedge", "between_clkedge"]How about boolean for these two.
Wanted these to be explicit, hence not choosing boolean. Would prefer to keep them as is.
Quoted 7 lines
Quoted 3 lines
+- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>]So 1.5GHz or 3GHz?
Add units (-hz).
Agreed, the description of MHz is misleading so will update to Hz. Thanks. Again though, I don't see what the suffix gives you, and would prefer to leave the binding as is.
Rob Herring
maintainerRe: [PATCH v2 3/3] ASoC: da7213: Add bindings documentation for codec driver
Quoted 11 lines · Opensource [Adam Thomson]
Quoted 6 lines · Rob Herring
Documentation/devicetree/bindings/sound/da7213.txt line 16
Quoted 4 lines
+- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>]Please append the units (-microvolt).
Given that a user needs to read the bindings document to understand what is available, and what they're for, this seems a little unnecessary.
You may think so, but it is standard practice.
Quoted 15 lines
Quoted 7 lines
Documentation/devicetree/bindings/sound/da7213.txt line 20
Quoted 5 lines
+- dlg,dmic-data-sel : DMIC channel select based on clock edge.
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ ["lrise_rfall", "lfall_rrise"] +- dlg,dmic-samplephase : When to sample audio from DMIC. + ["on_clkedge", "between_clkedge"]How about boolean for these two.
Wanted these to be explicit, hence not choosing boolean. Would prefer to keep them as is.
Quoted 4 lines
Quoted 3 lines
+- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>]
Quoted 7 lines
Quoted 3 lines
So 1.5GHz or 3GHz?
Add units (-hz).
Agreed, the description of MHz is misleading so will update to Hz. Thanks. Again though, I don't see what the suffix gives you, and would prefer to leave the binding as is.
It tells someone reading the dts what the units are without having to find the documentation and helps prevent people using properties with differing units.
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v2 3/3] ASoC: da7213: Add bindings documentation for codec driver
Quoted 11 lines · Rob Herring
Quoted 9 lines
Quoted 6 lines
Documentation/devicetree/bindings/sound/da7213.txt line 16
Quoted 4 lines
+- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>]Please append the units (-microvolt).
Given that a user needs to read the bindings document to understand what is available, and what they're for, this seems a little unnecessary.
You may think so, but it is standard practice.
I can find a number of situations in the kernel, where this just isn't followed, for device specific bindings. What percentage have to follow this for it to be 'standard'? Is this documented somewhere so it's clear for those writing drivers which need to use DT bindings? I had a quick look and couldn't find anything on this.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
+- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>]So 1.5GHz or 3GHz?
Add units (-hz).
Quoted 7 lines
Quoted 3 lines
Agreed, the description of MHz is misleading so will update to Hz. Thanks. Again though, I don't see what the suffix gives you, and would prefer to leave the binding as is.
It tells someone reading the dts what the units are without having to find the documentation and helps prevent people using properties with differing units.
For a lot of device specific bindings, you will need to read the associated documentation, and possibly the datasheet, to understand what it's for, and what values are valid. I don't see this suffix really saving you any time. For standard frameworks ok, but here it seems overkill.
Rob Herring
maintainerRe: [PATCH v2 3/3] ASoC: da7213: Add bindings documentation for codec driver
Quoted 40 lines · Opensource [Adam Thomson]
Quoted 11 lines · Rob Herring
Quoted 9 lines
Quoted 6 lines
Documentation/devicetree/bindings/sound/da7213.txt line 16
Quoted 4 lines
+- dlg,micbias1-lvl : Voltage (mV) for Mic Bias 1
Documentation/devicetree/bindings/sound/da7213.txt new file +3
-0+ [<1600>, <2200>, <2500>, <3000>] +- dlg,micbias2-lvl : Voltage (mV) for Mic Bias 2 + [<1600>, <2200>, <2500>, <3000>]Please append the units (-microvolt).
Given that a user needs to read the bindings document to understand what is available, and what they're for, this seems a little unnecessary.
You may think so, but it is standard practice.
I can find a number of situations in the kernel, where this just isn't followed, for device specific bindings. What percentage have to follow this for it to be 'standard'? Is this documented somewhere so it's clear for those writing drivers which need to use DT bindings? I had a quick look and couldn't find anything on this.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
+- dlg,dmic-clkrate : DMIC clock frequency (MHz). + [<1500000>, <3000000>]So 1.5GHz or 3GHz?
Add units (-hz).
Quoted 7 lines
Quoted 3 lines
Agreed, the description of MHz is misleading so will update to Hz. Thanks. Again though, I don't see what the suffix gives you, and would prefer to leave the binding as is.
It tells someone reading the dts what the units are without having to find the documentation and helps prevent people using properties with differing units.
For a lot of device specific bindings, you will need to read the associated documentation, and possibly the datasheet, to understand what it's for, and what values are valid. I don't see this suffix really saving you any time. For standard frameworks ok, but here it seems overkill.
Mark Brown
maintainerQuoted 4 lines · Adam Thomson
Adam Thomson (3):
ASoC: da7213: Add DT support to codec driver
ASoC: da7213: Add support to handle mclk data provided to driver
ASoC: da7213: Add bindings documentation for codec driver
Please remember to send the DT binding before the code as is normal, this helps review the code as we know in advance what the code is supposed to do.
T24gT2N0b2JlciAwNywgMjAxNSAxNToxMSwgTWFyayBCcm93biB3cm90ZToNCg0KPiA+IEFkYW0g VGhvbXNvbiAoMyk6DQo+ID4gICBBU29DOiBkYTcyMTM6IEFkZCBEVCBzdXBwb3J0IHRvIGNvZGVj IGRyaXZlcg0KPiA+ICAgQVNvQzogZGE3MjEzOiBBZGQgc3VwcG9ydCB0byBoYW5kbGUgbWNsayBk YXRhIHByb3ZpZGVkIHRvIGRyaXZlcg0KPiA+ICAgQVNvQzogZGE3MjEzOiBBZGQgYmluZGluZ3Mg ZG9jdW1lbnRhdGlvbiBmb3IgY29kZWMgZHJpdmVyDQo+IA0KPiBQbGVhc2UgcmVtZW1iZXIgdG8g c2VuZCB0aGUgRFQgYmluZGluZyBiZWZvcmUgdGhlIGNvZGUgYXMgaXMgbm9ybWFsLA0KPiB0aGlz IGhlbHBzIHJldmlldyB0aGUgY29kZSBhcyB3ZSBrbm93IGluIGFkdmFuY2Ugd2hhdCB0aGUgY29k ZSBpcw0KPiBzdXBwb3NlZCB0byBkby4NCg0KT2ssIHVuZGVyc3Rvb2QuIFdpbGwgbWFrZSBzdXJl IGluIHRoZSBmdXR1cmUgSSBvcmRlciB0aGVtIHRoaXMgd2F5LiBUaGFua3MuDQo= --
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html