aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2011-12-02 17:08:40 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-06 05:29:22 -0500
commit9d35f3e100eb5cfb91d777c8621fb585ad0327cd (patch)
tree79c105d52fc1e7960e23452441212853501f5d91
parentdb81778409227a0dc46ab95b95e1c7184ae9ef48 (diff)
ASoC: WM8903: Get default irq_active_low from IRQ controller
If the WM8903 is hooked up to an interrupt, set the irq_active_low flag in the default platform data based on the IRQ's IRQ_TYPE. Map IRQ_TYPE_NONE (a lack of explicit configuration/restriction) to irq_active_low = false; the previous default. This code is mainly added to support device tree interrupt bindings, although will work perfectly well in a non device tree system too. Any interrupt controller that supports only a single IRQ_TYPE could set each IRQ's type based on that restriction. This applies equally with and without device tree. To cater for interrupt controllers that don't do this, for which irqd_get_trigger_type() will return IRQ_TYPE_NONE, the platform data irq_active_low field may be used in systems that don't use device tree. With device tree, every IRQ must have some IRQ_TYPE set. Controllers that support DT and multiple IRQ_TYPEs must define the interrupts property (as used in interrupt source nodes) such that it defines the IRQ_TYPE to use. When the core DT setup code initializes wm8903->irq, the interrupts property will be parsed, and as a side- effect, set the IRQ's IRQ_TYPE for the WM8903 probe() function to read. Controllers that support DT and a single IRQ_TYPE could arrange to set the IRQ_TYPE somehow during their initialization, or hard-code it during the processing of the child interrupts property. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--sound/soc/codecs/wm8903.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index b114468d6453..b4f2c906b2f3 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -25,6 +25,7 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/regmap.h> 26#include <linux/regmap.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/irq.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/jack.h> 30#include <sound/jack.h>
30#include <sound/pcm.h> 31#include <sound/pcm.h>
@@ -2036,6 +2037,39 @@ static const struct regmap_config wm8903_regmap = {
2036 .num_reg_defaults = ARRAY_SIZE(wm8903_reg_defaults), 2037 .num_reg_defaults = ARRAY_SIZE(wm8903_reg_defaults),
2037}; 2038};
2038 2039
2040static int wm8903_set_pdata_irq_trigger(struct i2c_client *i2c,
2041 struct wm8903_platform_data *pdata)
2042{
2043 struct irq_data *irq_data = irq_get_irq_data(i2c->irq);
2044 if (!irq_data) {
2045 dev_err(&i2c->dev, "Invalid IRQ: %d\n",
2046 i2c->irq);
2047 return -EINVAL;
2048 }
2049
2050 switch (irqd_get_trigger_type(irq_data)) {
2051 case IRQ_TYPE_NONE:
2052 /*
2053 * We assume the controller imposes no restrictions,
2054 * so we are able to select active-high
2055 */
2056 /* Fall-through */
2057 case IRQ_TYPE_LEVEL_HIGH:
2058 pdata->irq_active_low = false;
2059 break;
2060 case IRQ_TYPE_LEVEL_LOW:
2061 pdata->irq_active_low = true;
2062 break;
2063 default:
2064 dev_err(&i2c->dev,
2065 "Unsupported IRQ_TYPE %x\n",
2066 irqd_get_trigger_type(irq_data));
2067 return -EINVAL;
2068 }
2069
2070 return 0;
2071}
2072
2039static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, 2073static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2040 const struct i2c_device_id *id) 2074 const struct i2c_device_id *id)
2041{ 2075{
@@ -2071,6 +2105,12 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
2071 dev_err(&i2c->dev, "Failed to allocate pdata\n"); 2105 dev_err(&i2c->dev, "Failed to allocate pdata\n");
2072 return -ENOMEM; 2106 return -ENOMEM;
2073 } 2107 }
2108
2109 if (i2c->irq) {
2110 ret = wm8903_set_pdata_irq_trigger(i2c, wm8903->pdata);
2111 if (ret != 0)
2112 return ret;
2113 }
2074 } 2114 }
2075 2115
2076 ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val); 2116 ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val);