linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: STEricsson_nomadik_linux@list.st.com,
	linus.walleij@stericsson.com, arnd@arndb.de,
	broonie@opensource.wolfsonmicro.com, ola.o.lilja@stericsson.com,
	roger.xr.nilsson@stericsson.com, alsa-devel@alsa-project.org,
	Lee Jones <lee.jones@linaro.org>
Subject: [PATCH 04/17] ASoC: codecs: Enable AB8500 CODEC for Device Tree
Date: Fri, 24 Aug 2012 15:01:40 +0100	[thread overview]
Message-ID: <1345816913-4113-5-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1345816913-4113-1-git-send-email-lee.jones@linaro.org>

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.

CC: alsa-devel@alsa-project.org
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>
---
 include/linux/mfd/abx500/ab8500-codec.h |    6 ++-
 sound/soc/codecs/ab8500-codec.c         |   81 +++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/include/linux/mfd/abx500/ab8500-codec.h b/include/linux/mfd/abx500/ab8500-codec.h
index dc65292..d707941 100644
--- a/include/linux/mfd/abx500/ab8500-codec.h
+++ b/include/linux/mfd/abx500/ab8500-codec.h
@@ -23,7 +23,8 @@ enum amic_type {
 /* Mic-biases */
 enum amic_micbias {
 	AMIC_MICBIAS_VAMIC1,
-	AMIC_MICBIAS_VAMIC2
+	AMIC_MICBIAS_VAMIC2,
+	AMIC_MICBIAS_UNKNOWN
 };
 
 /* Bias-voltage */
@@ -31,7 +32,8 @@ enum ear_cm_voltage {
 	EAR_CMV_0_95V,
 	EAR_CMV_1_10V,
 	EAR_CMV_1_27V,
-	EAR_CMV_1_58V
+	EAR_CMV_1_58V,
+	EAR_CMV_UNKNOWN
 };
 
 /* Analog microphone settings */
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index 23b4018..99dffcf 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -34,6 +34,7 @@
 #include <linux/mfd/abx500/ab8500-sysctrl.h>
 #include <linux/mfd/abx500/ab8500-codec.h>
 #include <linux/regulator/consumer.h>
+#include <linux/of.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -2394,9 +2395,65 @@ struct snd_soc_dai_driver ab8500_codec_dai[] = {
 	}
 };
 
+static void ab8500_codec_of_probe(struct device *dev, struct device_node *np,
+				struct ab8500_codec_platform_data *codec)
+{
+	u32 value;
+
+	if (of_get_property(np, "stericsson,amic1-type-single-ended", NULL))
+		codec->amics.mic1_type = AMIC_TYPE_SINGLE_ENDED;
+	else
+		codec->amics.mic1_type = AMIC_TYPE_DIFFERENTIAL;
+
+	if (of_get_property(np, "stericsson,amic2-type-single-ended", NULL))
+		codec->amics.mic2_type = AMIC_TYPE_SINGLE_ENDED;
+	else
+		codec->amics.mic2_type = AMIC_TYPE_DIFFERENTIAL;
+
+	/* Has a non-standard Vamic been requested? */
+	if (of_get_property(np, "stericsson,amic1a-bias-vamic2", NULL))
+		codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC2;
+	else
+		codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC1;
+
+	if (of_get_property(np, "stericsson,amic1b-bias-vamic2", NULL))
+		codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC2;
+	else
+		codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC1;
+
+	if (of_get_property(np, "stericsson,amic2-bias-vamic1", NULL))
+		codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC1;
+	else
+		codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC2;
+
+	if (!of_property_read_u32(np, "stericsson,earpeice-cmv", &value)) {
+		switch (value) {
+		case 950 :
+			codec->ear_cmv = EAR_CMV_0_95V;
+			break;
+		case 1100 :
+			codec->ear_cmv = EAR_CMV_1_10V;
+			break;
+		case 1270 :
+			codec->ear_cmv = EAR_CMV_1_27V;
+			break;
+		case 1580 :
+			codec->ear_cmv = EAR_CMV_1_58V;
+			break;
+		default :
+			codec->ear_cmv = EAR_CMV_UNKNOWN;
+			dev_err(dev, "Unsuitable earpiece voltage found in DT\n");
+		}
+	} else {
+		dev_warn(dev, "No earpiece voltage found in DT - using default\n");
+		codec->ear_cmv = EAR_CMV_0_95V;
+	}
+}
+
 static int ab8500_codec_probe(struct snd_soc_codec *codec)
 {
 	struct device *dev = codec->dev;
+	struct device_node *np = dev->of_node;
 	struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
 	struct ab8500_platform_data *pdata;
 	struct filter_control *fc;
@@ -2407,6 +2464,30 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
 	/* Setup AB8500 according to board-settings */
 	pdata = (struct ab8500_platform_data *)dev_get_platdata(dev->parent);
 
+	if (np) {
+		if (!pdata)
+			pdata = devm_kzalloc(dev,
+					sizeof(struct ab8500_platform_data),
+					GFP_KERNEL);
+
+		if (pdata && !pdata->codec)
+			pdata->codec
+				= devm_kzalloc(dev,
+					sizeof(struct ab8500_codec_platform_data),
+					GFP_KERNEL);
+
+		if (!(pdata && pdata->codec))
+			return -ENOMEM;
+
+		ab8500_codec_of_probe(dev, np, pdata->codec);
+
+	} else {
+		if (!(pdata && pdata->codec)) {
+			dev_err(dev, "No codec platform data or DT found\n");
+			return -EINVAL;
+		}
+	}
+
 	/* Inform SoC Core that we have our own I/O arrangements. */
 	codec->control_data = (void *)true;
 
-- 
1.7.9.5


  parent reply	other threads:[~2012-08-24 14:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-24 14:01 [PATCH 00/17] MOP500 Audio fix-ups and DT enablement Lee Jones
2012-08-24 14:01 ` [PATCH 01/17] ASoC: Ux500: Move MSP pinctrl setup into the MSP driver Lee Jones
2012-08-30 23:46   ` Linus Walleij
2012-09-10 16:46   ` Lee Jones
2012-09-11  9:28     ` Ola Lilja
2012-08-24 14:01 ` [PATCH 02/17] ASoC: Ux500: Enable MOP500 driver for Device Tree Lee Jones
2012-08-24 14:01 ` [PATCH 03/17] ASoC: Ux500: Enable ux500 MSP " Lee Jones
2012-08-24 14:01 ` Lee Jones [this message]
2012-08-24 14:01 ` [PATCH 05/17] ASoC: Ux500: Minor coding layout changes Lee Jones
2012-09-10 16:44   ` Lee Jones
2012-09-11  0:27     ` Mark Brown
2012-09-11  9:03     ` Ola Lilja
2012-08-24 14:01 ` [PATCH 06/17] Documentation: Define the MOP500 Audio Machine Driver Device Tree bindings Lee Jones
2012-09-10 16:44   ` Lee Jones
2012-09-11  9:06     ` Ola Lilja
2012-09-11  9:08       ` Mark Brown
2012-09-14 10:02       ` Lee Jones
2012-08-24 14:01 ` [PATCH 07/17] Documentation: Define the MSP " Lee Jones
2012-09-10 16:43   ` Lee Jones
2012-09-11  9:08     ` Ola Lilja
2012-09-14  9:57       ` Lee Jones
2012-08-24 14:01 ` [PATCH 08/17] ARM: ux500: Clean-up MSP platform code Lee Jones
2012-08-24 14:01 ` [PATCH 09/17] ARM: ux500: Add AB8500 CODEC node to DB8500 Device Tree Lee Jones
2012-08-30 23:50   ` Linus Walleij
2012-08-24 14:01 ` [PATCH 10/17] ARM: ux500: Fork MSP platform registration for step-by-step DT enablement Lee Jones
2012-08-24 14:01 ` [PATCH 11/17] ARM: ux500: Pass MSP DMA platform data though AUXDATA Lee Jones
2012-08-24 14:01 ` [PATCH 12/17] ARM: ux500: Stop registering the MOP500 Audio driver from platform code Lee Jones
2012-08-24 14:01 ` [PATCH 13/17] ARM: ux500: Remove platform registration of MSP devices Lee Jones
2012-08-24 14:01 ` [PATCH 14/17] ARM: ux500: Rename MSP board file to something more meaningful Lee Jones
2012-08-24 15:05   ` [alsa-devel] " Hebbar, Gururaja
2012-08-24 15:08     ` Lee Jones
2012-08-24 15:14     ` Lee Jones
2012-08-24 15:16       ` Hebbar, Gururaja
2012-08-24 14:01 ` [PATCH 15/17] ARM: ux500: Add nodes for the MSP into Device Tree Lee Jones
2012-08-24 14:01 ` [PATCH 16/17] ARM: ux500: Add all encompassing sound node to the Snowball " Lee Jones
2012-08-24 14:01 ` [PATCH 17/17] Documentation: Add the AB8500 CODEC device to the MFD AB8500 doc Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345816913-4113-5-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=STEricsson_nomadik_linux@list.st.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ola.o.lilja@stericsson.com \
    --cc=roger.xr.nilsson@stericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).