Skip to content

Commit 3092f80

Browse files
broonieSamuel Ortiz
authored andcommitted
mfd: arizona: Allow GPIO to be specified for IRQ line
If a GPIO is specified for the chip IRQ line then request it. This improves support for systems that do not put pins into input mode when used as interrupts. Also use this GPIO when the primary IRQ is in edge triggered mode to detect if we have handled pending interrupts in order to improve robustness. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent f8a0941 commit 3092f80

2 files changed

Lines changed: 56 additions & 13 deletions

File tree

‎drivers/mfd/arizona-irq.c‎

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static irqreturn_t arizona_ctrlif_err(int irq, void *data)
9494
static irqreturn_t arizona_irq_thread(int irq, void *data)
9595
{
9696
struct arizona *arizona = data;
97+
bool poll;
9798
unsigned int val;
9899
int ret;
99100

@@ -103,20 +104,39 @@ static irqreturn_t arizona_irq_thread(int irq, void *data)
103104
return IRQ_NONE;
104105
}
105106

106-
/* Always handle the AoD domain */
107-
handle_nested_irq(irq_find_mapping(arizona->virq, 0));
107+
do {
108+
poll = false;
109+
110+
/* Always handle the AoD domain */
111+
handle_nested_irq(irq_find_mapping(arizona->virq, 0));
112+
113+
/*
114+
* Check if one of the main interrupts is asserted and only
115+
* check that domain if it is.
116+
*/
117+
ret = regmap_read(arizona->regmap, ARIZONA_IRQ_PIN_STATUS,
118+
&val);
119+
if (ret == 0 && val & ARIZONA_IRQ1_STS) {
120+
handle_nested_irq(irq_find_mapping(arizona->virq, 1));
121+
} else if (ret != 0) {
122+
dev_err(arizona->dev,
123+
"Failed to read main IRQ status: %d\n", ret);
124+
}
108125

109-
/*
110-
* Check if one of the main interrupts is asserted and only
111-
* check that domain if it is.
112-
*/
113-
ret = regmap_read(arizona->regmap, ARIZONA_IRQ_PIN_STATUS, &val);
114-
if (ret == 0 && val & ARIZONA_IRQ1_STS) {
115-
handle_nested_irq(irq_find_mapping(arizona->virq, 1));
116-
} else if (ret != 0) {
117-
dev_err(arizona->dev, "Failed to read main IRQ status: %d\n",
118-
ret);
119-
}
126+
/*
127+
* Poll the IRQ pin status to see if we're really done
128+
* if the interrupt controller can't do it for us.
129+
*/
130+
if (!arizona->pdata.irq_gpio) {
131+
break;
132+
} else if (arizona->pdata.irq_flags & IRQF_TRIGGER_RISING &&
133+
gpio_get_value_cansleep(arizona->pdata.irq_gpio)) {
134+
poll = true;
135+
} else if (arizona->pdata.irq_flags & IRQF_TRIGGER_FALLING &&
136+
!gpio_get_value_cansleep(arizona->pdata.irq_gpio)) {
137+
poll = true;
138+
}
139+
} while (poll);
120140

121141
pm_runtime_mark_last_busy(arizona->dev);
122142
pm_runtime_put_autosuspend(arizona->dev);
@@ -262,6 +282,26 @@ int arizona_irq_init(struct arizona *arizona)
262282
}
263283
}
264284

285+
/* Used to emulate edge trigger and to work around broken pinmux */
286+
if (arizona->pdata.irq_gpio) {
287+
if (gpio_to_irq(arizona->pdata.irq_gpio) != arizona->irq) {
288+
dev_warn(arizona->dev, "IRQ %d is not GPIO %d (%d)\n",
289+
arizona->irq, arizona->pdata.irq_gpio,
290+
gpio_to_irq(arizona->pdata.irq_gpio));
291+
arizona->irq = gpio_to_irq(arizona->pdata.irq_gpio);
292+
}
293+
294+
ret = devm_gpio_request_one(arizona->dev,
295+
arizona->pdata.irq_gpio,
296+
GPIOF_IN, "arizona IRQ");
297+
if (ret != 0) {
298+
dev_err(arizona->dev,
299+
"Failed to request IRQ GPIO %d:: %d\n",
300+
arizona->pdata.irq_gpio, ret);
301+
arizona->pdata.irq_gpio = 0;
302+
}
303+
}
304+
265305
ret = request_threaded_irq(arizona->irq, NULL, arizona_irq_thread,
266306
flags, "arizona", arizona);
267307

‎include/linux/mfd/arizona/pdata.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ struct arizona_pdata {
163163

164164
/** Haptic actuator type */
165165
unsigned int hap_act;
166+
167+
/** GPIO for primary IRQ (used for edge triggered emulation) */
168+
int irq_gpio;
166169
};
167170

168171
#endif

0 commit comments

Comments
 (0)