aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2011-12-02 17:08:41 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-06 05:29:22 -0500
commit5d680b3a84b3e870fc1ea01495935e58e17de7aa (patch)
tree796dd0a7d6310f366cd123389294acf467516d21
parent9d35f3e100eb5cfb91d777c8621fb585ad0327cd (diff)
ASoC: WM8903: Add device tree binding
Document the device tree binding for the WM8903 codec, and modify the driver to extract platform data from the device tree, if present. Based on work by John Bonesio, but significantly reworked since then. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--Documentation/devicetree/bindings/sound/wm8903.txt50
-rw-r--r--sound/soc/codecs/wm8903.c49
2 files changed, 99 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/wm8903.txt b/Documentation/devicetree/bindings/sound/wm8903.txt
new file mode 100644
index 000000000000..f102cbc42694
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/wm8903.txt
@@ -0,0 +1,50 @@
1WM8903 audio CODEC
2
3This device supports I2C only.
4
5Required properties:
6
7 - compatible : "wlf,wm8903"
8
9 - reg : the I2C address of the device.
10
11 - gpio-controller : Indicates this device is a GPIO controller.
12
13 - #gpio-cells : Should be two. The first cell is the pin number and the
14 second cell is used to specify optional parameters (currently unused).
15
16Optional properties:
17
18 - interrupts : The interrupt line the codec is connected to.
19
20 - micdet-cfg : Default register value for R6 (Mic Bias). If absent, the
21 default is 0.
22
23 - micdet-delay : The debounce delay for microphone detection in mS. If
24 absent, the default is 100.
25
26 - gpio-cfg : A list of GPIO configuration register values. The list must
27 be 5 entries long. If absent, no configuration of these registers is
28 performed. If any entry has the value 0xffffffff, that GPIO's
29 configuration will not be modified.
30
31Example:
32
33codec: wm8903@1a {
34 compatible = "wlf,wm8903";
35 reg = <0x1a>;
36 interrupts = < 347 >;
37
38 gpio-controller;
39 #gpio-cells = <2>;
40
41 micdet-cfg = <0>;
42 micdet-delay = <100>;
43 gpio-cfg = <
44 0x0600 /* DMIC_LR, output */
45 0x0680 /* DMIC_DAT, input */
46 0x0000 /* GPIO, output, low */
47 0x0200 /* Interrupt, output */
48 0x01a0 /* BCLK, input, active high */
49 >;
50};
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index b4f2c906b2f3..adfbefaaab21 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -2070,6 +2070,49 @@ static int wm8903_set_pdata_irq_trigger(struct i2c_client *i2c,
2070 return 0; 2070 return 0;
2071} 2071}
2072 2072
2073static int wm8903_set_pdata_from_of(struct i2c_client *i2c,
2074 struct wm8903_platform_data *pdata)
2075{
2076 const struct device_node *np = i2c->dev.of_node;
2077 u32 val32;
2078 int i;
2079
2080 if (of_property_read_u32(np, "micdet-cfg", &val32) >= 0)
2081 pdata->micdet_cfg = val32;
2082
2083 if (of_property_read_u32(np, "micdet-delay", &val32) >= 0)
2084 pdata->micdet_delay = val32;
2085
2086 if (of_property_read_u32_array(np, "gpio-cfg", pdata->gpio_cfg,
2087 ARRAY_SIZE(pdata->gpio_cfg)) >= 0) {
2088 /*
2089 * In device tree: 0 means "write 0",
2090 * 0xffffffff means "don't touch".
2091 *
2092 * In platform data: 0 means "don't touch",
2093 * 0x8000 means "write 0".
2094 *
2095 * Note: WM8903_GPIO_CONFIG_ZERO == 0x8000.
2096 *
2097 * Convert from DT to pdata representation here,
2098 * so no other code needs to change.
2099 */
2100 for (i = 0; i < ARRAY_SIZE(pdata->gpio_cfg); i++) {
2101 if (pdata->gpio_cfg[i] == 0) {
2102 pdata->gpio_cfg[i] = WM8903_GPIO_CONFIG_ZERO;
2103 } else if (pdata->gpio_cfg[i] == 0xffffffff) {
2104 pdata->gpio_cfg[i] = 0;
2105 } else if (pdata->gpio_cfg[i] > 0x7fff) {
2106 dev_err(&i2c->dev, "Invalid gpio-cfg[%d] %x\n",
2107 i, pdata->gpio_cfg[i]);
2108 return -EINVAL;
2109 }
2110 }
2111 }
2112
2113 return 0;
2114}
2115
2073static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, 2116static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2074 const struct i2c_device_id *id) 2117 const struct i2c_device_id *id)
2075{ 2118{
@@ -2111,6 +2154,12 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2111 if (ret != 0) 2154 if (ret != 0)
2112 return ret; 2155 return ret;
2113 } 2156 }
2157
2158 if (i2c->dev.of_node) {
2159 ret = wm8903_set_pdata_from_of(i2c, wm8903->pdata);
2160 if (ret != 0)
2161 return ret;
2162 }
2114 } 2163 }
2115 2164
2116 ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val); 2165 ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val);