aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2012-09-10 06:46:32 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-22 11:18:33 -0400
commit2d6d649a2e0fa0268c0d03d5b1d330ca7907d33c (patch)
tree6fdf19b72c252eca685617723a74c8a4784e79c8 /sound/soc/codecs
parent182f73f6bbd6a2bf65cd7e15558aa8a651b8c9f7 (diff)
ASoC: twl4030: Support for DT booted kernel
When the kernel has been booted with DT blob the platform data is NULL for the driver. We need to construct the pdata based on the DT information for runtime use. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/twl4030.c55
1 files changed, 47 insertions, 8 deletions
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index b4d1a4e794d8..e7f608996c41 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -26,6 +26,8 @@
26#include <linux/pm.h> 26#include <linux/pm.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/of.h>
30#include <linux/of_gpio.h>
29#include <linux/i2c/twl.h> 31#include <linux/i2c/twl.h>
30#include <linux/slab.h> 32#include <linux/slab.h>
31#include <linux/gpio.h> 33#include <linux/gpio.h>
@@ -295,13 +297,57 @@ static inline void twl4030_reset_registers(struct snd_soc_codec *codec)
295 297
296} 298}
297 299
298static void twl4030_init_chip(struct snd_soc_codec *codec) 300static void twl4030_setup_pdata_of(struct twl4030_codec_data *pdata,
301 struct device_node *node)
302{
303 int value;
304
305 of_property_read_u32(node, "ti,digimic_delay",
306 &pdata->digimic_delay);
307 of_property_read_u32(node, "ti,ramp_delay_value",
308 &pdata->ramp_delay_value);
309 of_property_read_u32(node, "ti,offset_cncl_path",
310 &pdata->offset_cncl_path);
311 if (!of_property_read_u32(node, "ti,hs_extmute", &value))
312 pdata->hs_extmute = value;
313
314 pdata->hs_extmute_gpio = of_get_named_gpio(node,
315 "ti,hs_extmute_gpio", 0);
316 if (gpio_is_valid(pdata->hs_extmute_gpio))
317 pdata->hs_extmute = 1;
318}
319
320static struct twl4030_codec_data *twl4030_get_pdata(struct snd_soc_codec *codec)
299{ 321{
300 struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); 322 struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
323 struct device_node *twl4030_codec_node = NULL;
324
325 twl4030_codec_node = of_find_node_by_name(codec->dev->parent->of_node,
326 "codec");
327
328 if (!pdata && twl4030_codec_node) {
329 pdata = devm_kzalloc(codec->dev,
330 sizeof(struct twl4030_codec_data),
331 GFP_KERNEL);
332 if (!pdata) {
333 dev_err(codec->dev, "Can not allocate memory\n");
334 return NULL;
335 }
336 twl4030_setup_pdata_of(pdata, twl4030_codec_node);
337 }
338
339 return pdata;
340}
341
342static void twl4030_init_chip(struct snd_soc_codec *codec)
343{
344 struct twl4030_codec_data *pdata;
301 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 345 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
302 u8 reg, byte; 346 u8 reg, byte;
303 int i = 0; 347 int i = 0;
304 348
349 pdata = twl4030_get_pdata(codec);
350
305 if (pdata && pdata->hs_extmute && 351 if (pdata && pdata->hs_extmute &&
306 gpio_is_valid(pdata->hs_extmute_gpio)) { 352 gpio_is_valid(pdata->hs_extmute_gpio)) {
307 int ret; 353 int ret;
@@ -2290,13 +2336,6 @@ static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
2290 2336
2291static int __devinit twl4030_codec_probe(struct platform_device *pdev) 2337static int __devinit twl4030_codec_probe(struct platform_device *pdev)
2292{ 2338{
2293 struct twl4030_codec_data *pdata = pdev->dev.platform_data;
2294
2295 if (!pdata) {
2296 dev_err(&pdev->dev, "platform_data is missing\n");
2297 return -EINVAL;
2298 }
2299
2300 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030, 2339 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030,
2301 twl4030_dai, ARRAY_SIZE(twl4030_dai)); 2340 twl4030_dai, ARRAY_SIZE(twl4030_dai));
2302} 2341}