From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
To: lee.jones@linaro.org
Cc: sameo@linux.intel.com, rob.herring@calxeda.com,
pawel.moll@arm.com, mark.rutland@arm.com, swarren@wwwdotorg.org,
ijc+devicetree@hellion.org.uk, rob@landley.net,
broonie@kernel.org, patches@opensource.wolfsonmicro.com,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Subject: [PATCH 4/5] mfd: arizona: Add micdet ranges and polarity device tree bindings
Date: Mon, 23 Sep 2013 19:30:42 +0100 [thread overview]
Message-ID: <1379961043-23762-4-git-send-email-ckeepax@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1379961043-23762-1-git-send-email-ckeepax@opensource.wolfsonmicro.com>
Add device tree bindings for the pdata that configures the microphone
button detection and microphone detection polarity configurations.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
Documentation/devicetree/bindings/mfd/arizona.txt | 26 +++++
drivers/mfd/arizona-core.c | 116 +++++++++++++++++++++
2 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/Documentation/devicetree/bindings/mfd/arizona.txt b/Documentation/devicetree/bindings/mfd/arizona.txt
index 3ee659d..09e384c 100644
--- a/Documentation/devicetree/bindings/mfd/arizona.txt
+++ b/Documentation/devicetree/bindings/mfd/arizona.txt
@@ -49,6 +49,20 @@ Optional properties:
milliseconds
- wlf,micd-force-micbias : Force MICBIAS continuously on during microphone
detection
+ - wlf,micd-ranges : Microphone detection level and key configuration, this
+ field can be of variable length but should always be a multiple of 2 cells
+ long, each two cell group represents one button configuration
+ The first cell is the maximum impedance for this button in ohms
+ The second cell the key that should be reported to the input layer
+ - wlf,micd-configs : Headset polarity configurations, the field can be of
+ variable length but should always be a multiple of 3 cells long, each two
+ cell group represents one polarity configration
+ The first cell is the accessory detection source as per the ACCDET_SRC bits
+ in the ACCESSORY_DETECT_MODE_1 register
+ The second cell represents the MICBIAS to be used as per the MICD_BIAS_SRC
+ bits in the MIC_DETECT_1 register
+ The third cell represents the value of the micd-pol-gpio pin, a non-zero
+ value indicates this should be on
- wlf,gpio-defaults : A list of GPIO configuration register values. If
absent, no configuration of these registers is performed. If any
@@ -79,6 +93,18 @@ codec: wm5102@1a {
wlf,micd-dbtime = <0x1>;
wlf,micd-timeout = <10>;
wlf,micd-force-micbias;
+ wlf,micd-ranges = <
+ 11 0x100
+ 28 0x101
+ 54 0x102
+ 100 0x103
+ 186 0x104
+ 430 0x105
+ >;
+ wlf,micd-configs = <
+ 0x1 1 0
+ 0x0 2 1
+ >;
wlf,gpio-defaults = <
0x00000000 /* AIF1TXLRCLK */
diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 1cc6aa0..c8f30c4 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -596,6 +596,119 @@ static int arizona_of_get_gpio_defaults(struct arizona *arizona,
return ret;
}
+static int arizona_of_get_u32_num_groups(struct arizona *arizona,
+ const char *prop,
+ int group_size)
+{
+ int len_prop;
+ int num_groups;
+
+ if (!of_get_property(arizona->dev->of_node, prop, &len_prop))
+ return -EINVAL;
+
+ num_groups = len_prop / (group_size * sizeof(u32));
+
+ if (num_groups * group_size * sizeof(u32) != len_prop) {
+ dev_err(arizona->dev,
+ "DT property %s is malformed: %d\n",
+ prop, -EOVERFLOW);
+ return -EOVERFLOW;
+ }
+
+ return num_groups;
+}
+
+static int arizona_of_get_micd_ranges(struct arizona *arizona,
+ const char *prop)
+{
+ int nranges;
+ int i, j;
+ int ret = 0;
+ u32 value;
+ struct arizona_micd_range *micd_ranges;
+
+ nranges = arizona_of_get_u32_num_groups(arizona, prop, 2);
+ if (nranges < 0)
+ return nranges;
+
+ micd_ranges = devm_kzalloc(arizona->dev,
+ nranges * sizeof(struct arizona_micd_range),
+ GFP_KERNEL);
+
+ for (i = 0, j = 0; i < nranges; ++i) {
+ ret = of_property_read_u32_index(arizona->dev->of_node,
+ prop, j++, &value);
+ if (ret < 0)
+ goto error;
+ micd_ranges[i].max = value;
+
+ ret = of_property_read_u32_index(arizona->dev->of_node,
+ prop, j++, &value);
+ if (ret < 0)
+ goto error;
+ micd_ranges[i].key = value;
+ }
+
+ arizona->pdata.micd_ranges = micd_ranges;
+ arizona->pdata.num_micd_ranges = nranges;
+
+ return ret;
+
+error:
+ devm_kfree(arizona->dev, micd_ranges);
+ dev_err(arizona->dev, "DT property %s is malformed: %d\n", prop, ret);
+ return ret;
+}
+
+static int arizona_of_get_micd_configs(struct arizona *arizona,
+ const char *prop)
+{
+ int nconfigs;
+ int i, j;
+ int ret = 0;
+ u32 value;
+ struct arizona_micd_config *micd_configs;
+
+ nconfigs = arizona_of_get_u32_num_groups(arizona, prop, 3);
+ if (nconfigs < 0)
+ return nconfigs;
+
+ micd_configs = devm_kzalloc(arizona->dev,
+ nconfigs *
+ sizeof(struct arizona_micd_config),
+ GFP_KERNEL);
+
+ for (i = 0, j = 0; i < nconfigs; ++i) {
+ ret = of_property_read_u32_index(arizona->dev->of_node,
+ prop, j++, &value);
+ if (ret < 0)
+ goto error;
+ micd_configs[i].src = value;
+
+ ret = of_property_read_u32_index(arizona->dev->of_node,
+ prop, j++, &value);
+ if (ret < 0)
+ goto error;
+ micd_configs[i].bias = value;
+
+ ret = of_property_read_u32_index(arizona->dev->of_node,
+ prop, j++, &value);
+ if (ret < 0)
+ goto error;
+ micd_configs[i].gpio = value;
+ }
+
+ arizona->pdata.micd_configs = micd_configs;
+ arizona->pdata.num_micd_configs = nconfigs;
+
+ return ret;
+
+error:
+ devm_kfree(arizona->dev, micd_configs);
+ dev_err(arizona->dev, "DT property %s is malformed: %d\n", prop, ret);
+ return ret;
+}
+
static int arizona_of_get_core_pdata(struct arizona *arizona)
{
struct arizona_pdata *pdata = &arizona->pdata;
@@ -625,6 +738,9 @@ static int arizona_of_get_core_pdata(struct arizona *arizona)
of_property_read_bool(arizona->dev->of_node,
"wlf,micd-force-micbias");
+ arizona_of_get_micd_ranges(arizona, "wlf,micd-ranges");
+ arizona_of_get_micd_configs(arizona, "wlf,micd-configs");
+
arizona_of_get_gpio_defaults(arizona, "wlf,gpio-defaults");
arizona_of_read_u32_array(arizona, "wlf,max-channels-clocked",
--
1.7.2.5
next prev parent reply other threads:[~2013-09-23 18:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-23 18:30 [PATCH 1/5] mfd: arizona: Add device tree helper functions Charles Keepax
2013-09-23 18:30 ` [PATCH 2/5] mfd: arizona: Add device tree binding for max_channels_clocked Charles Keepax
[not found] ` <1379961043-23762-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-09-23 21:38 ` Stephen Warren
2013-09-23 23:28 ` Mark Brown
[not found] ` <20130923232832.GM21013-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-09-24 9:58 ` Charles Keepax
[not found] ` <1379961043-23762-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-09-23 18:30 ` [PATCH 3/5] mfd: arizona: Add simple microphone detection device tree bindings Charles Keepax
2013-09-23 18:30 ` Charles Keepax [this message]
[not found] ` <1379961043-23762-4-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-09-23 21:41 ` [PATCH 4/5] mfd: arizona: Add micdet ranges and polarity " Stephen Warren
2013-09-23 22:25 ` Mark Brown
2013-09-23 18:30 ` [PATCH 5/5] mfd: arizona: Add device tree bindings for MICBIAS generators Charles Keepax
2013-09-23 21:43 ` Stephen Warren
[not found] ` <1379961043-23762-5-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-09-23 22:27 ` Mark Brown
2013-09-23 21:36 ` [PATCH 1/5] mfd: arizona: Add device tree helper functions Stephen Warren
[not found] ` <5240B464.2010903-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-09-24 9:49 ` Charles Keepax
2013-09-24 10:20 ` Mark Brown
[not found] ` <20130924094937.GN3635-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-09-24 22:58 ` Stephen Warren
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=1379961043-23762-4-git-send-email-ckeepax@opensource.wolfsonmicro.com \
--to=ckeepax@opensource.wolfsonmicro.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=patches@opensource.wolfsonmicro.com \
--cc=pawel.moll@arm.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
--cc=sameo@linux.intel.com \
--cc=swarren@wwwdotorg.org \
/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).