aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/ab8500-codec.c
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2012-07-27 03:50:05 -0400
committerLee Jones <lee.jones@linaro.org>2012-09-20 03:10:57 -0400
commitdb5c811d4044b5bd2ef923c7466bd2720eee0887 (patch)
treefbde5cef6ff2b2518d2a7b5ec29f4c79b3ef59fd /sound/soc/codecs/ab8500-codec.c
parent49731c23bee88fd76af8cd57b915547b2175a26a (diff)
ASoC: codecs: Enable AB8500 CODEC for Device Tree
We continue to allow the AB8500 CODEC to be registered via the AB8500 Multi Functional Device API, only this time we extract its configuration from the Device Tree binary. Acked-by: Ola Lilja <ola.o.lilja@stericsson.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'sound/soc/codecs/ab8500-codec.c')
-rw-r--r--sound/soc/codecs/ab8500-codec.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index 23b40186f9b8..07abd09e0b1d 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -34,6 +34,7 @@
34#include <linux/mfd/abx500/ab8500-sysctrl.h> 34#include <linux/mfd/abx500/ab8500-sysctrl.h>
35#include <linux/mfd/abx500/ab8500-codec.h> 35#include <linux/mfd/abx500/ab8500-codec.h>
36#include <linux/regulator/consumer.h> 36#include <linux/regulator/consumer.h>
37#include <linux/of.h>
37 38
38#include <sound/core.h> 39#include <sound/core.h>
39#include <sound/pcm.h> 40#include <sound/pcm.h>
@@ -2394,9 +2395,65 @@ struct snd_soc_dai_driver ab8500_codec_dai[] = {
2394 } 2395 }
2395}; 2396};
2396 2397
2398static void ab8500_codec_of_probe(struct device *dev, struct device_node *np,
2399 struct ab8500_codec_platform_data *codec)
2400{
2401 u32 value;
2402
2403 if (of_get_property(np, "stericsson,amic1-type-single-ended", NULL))
2404 codec->amics.mic1_type = AMIC_TYPE_SINGLE_ENDED;
2405 else
2406 codec->amics.mic1_type = AMIC_TYPE_DIFFERENTIAL;
2407
2408 if (of_get_property(np, "stericsson,amic2-type-single-ended", NULL))
2409 codec->amics.mic2_type = AMIC_TYPE_SINGLE_ENDED;
2410 else
2411 codec->amics.mic2_type = AMIC_TYPE_DIFFERENTIAL;
2412
2413 /* Has a non-standard Vamic been requested? */
2414 if (of_get_property(np, "stericsson,amic1a-bias-vamic2", NULL))
2415 codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC2;
2416 else
2417 codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC1;
2418
2419 if (of_get_property(np, "stericsson,amic1b-bias-vamic2", NULL))
2420 codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC2;
2421 else
2422 codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC1;
2423
2424 if (of_get_property(np, "stericsson,amic2-bias-vamic1", NULL))
2425 codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC1;
2426 else
2427 codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC2;
2428
2429 if (!of_property_read_u32(np, "stericsson,earpeice-cmv", &value)) {
2430 switch (value) {
2431 case 950 :
2432 codec->ear_cmv = EAR_CMV_0_95V;
2433 break;
2434 case 1100 :
2435 codec->ear_cmv = EAR_CMV_1_10V;
2436 break;
2437 case 1270 :
2438 codec->ear_cmv = EAR_CMV_1_27V;
2439 break;
2440 case 1580 :
2441 codec->ear_cmv = EAR_CMV_1_58V;
2442 break;
2443 default :
2444 codec->ear_cmv = EAR_CMV_UNKNOWN;
2445 dev_err(dev, "Unsuitable earpiece voltage found in DT\n");
2446 }
2447 } else {
2448 dev_warn(dev, "No earpiece voltage found in DT - using default\n");
2449 codec->ear_cmv = EAR_CMV_0_95V;
2450 }
2451}
2452
2397static int ab8500_codec_probe(struct snd_soc_codec *codec) 2453static int ab8500_codec_probe(struct snd_soc_codec *codec)
2398{ 2454{
2399 struct device *dev = codec->dev; 2455 struct device *dev = codec->dev;
2456 struct device_node *np = dev->of_node;
2400 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev); 2457 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
2401 struct ab8500_platform_data *pdata; 2458 struct ab8500_platform_data *pdata;
2402 struct filter_control *fc; 2459 struct filter_control *fc;
@@ -2410,6 +2467,30 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2410 /* Inform SoC Core that we have our own I/O arrangements. */ 2467 /* Inform SoC Core that we have our own I/O arrangements. */
2411 codec->control_data = (void *)true; 2468 codec->control_data = (void *)true;
2412 2469
2470 if (np) {
2471 if (!pdata)
2472 pdata = devm_kzalloc(dev,
2473 sizeof(struct ab8500_platform_data),
2474 GFP_KERNEL);
2475
2476 if (pdata && !pdata->codec)
2477 pdata->codec
2478 = devm_kzalloc(dev,
2479 sizeof(struct ab8500_codec_platform_data),
2480 GFP_KERNEL);
2481
2482 if (!(pdata && pdata->codec))
2483 return -ENOMEM;
2484
2485 ab8500_codec_of_probe(dev, np, pdata->codec);
2486
2487 } else {
2488 if (!(pdata && pdata->codec)) {
2489 dev_err(dev, "No codec platform data or DT found\n");
2490 return -EINVAL;
2491 }
2492 }
2493
2413 status = ab8500_audio_setup_mics(codec, &pdata->codec->amics); 2494 status = ab8500_audio_setup_mics(codec, &pdata->codec->amics);
2414 if (status < 0) { 2495 if (status < 0) {
2415 pr_err("%s: Failed to setup mics (%d)!\n", __func__, status); 2496 pr_err("%s: Failed to setup mics (%d)!\n", __func__, status);