aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8903.c
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 /sound/soc/codecs/wm8903.c
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>
Diffstat (limited to 'sound/soc/codecs/wm8903.c')
-rw-r--r--sound/soc/codecs/wm8903.c49
1 files changed, 49 insertions, 0 deletions
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);