Skip to content

Commit c0ec489

Browse files
aborzeszBartosz Golaszewski
authored andcommitted
gpio: graniterapids: Check if GPIO line can be used for IRQs
GPIO line can only be used as interrupt if its INTSEL register is programmed by the BIOS. Cc: [email protected] Signed-off-by: Alan Borzeszkowski <[email protected]> Signed-off-by: Mika Westerberg <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 0588504 commit c0ec489

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/gpio/gpio-graniterapids.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#define GNR_CFG_DW_HOSTSW_MODE BIT(27)
4141
#define GNR_CFG_DW_RX_MASK GENMASK(23, 22)
42+
#define GNR_CFG_DW_INTSEL_MASK GENMASK(21, 14)
4243
#define GNR_CFG_DW_RX_DISABLE FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
4344
#define GNR_CFG_DW_RX_EDGE FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
4445
#define GNR_CFG_DW_RX_LEVEL FIELD_PREP(GNR_CFG_DW_RX_MASK, 0)
@@ -227,10 +228,18 @@ static void gnr_gpio_irq_unmask(struct irq_data *d)
227228
static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
228229
{
229230
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
230-
irq_hw_number_t pin = irqd_to_hwirq(d);
231-
u32 mask = GNR_CFG_DW_RX_MASK;
231+
struct gnr_gpio *priv = gpiochip_get_data(gc);
232+
irq_hw_number_t hwirq = irqd_to_hwirq(d);
233+
u32 reg;
232234
u32 set;
233235

236+
/* Allow interrupts only if Interrupt Select field is non-zero */
237+
reg = readl(gnr_gpio_get_padcfg_addr(priv, hwirq));
238+
if (!(reg & GNR_CFG_DW_INTSEL_MASK)) {
239+
dev_dbg(gc->parent, "GPIO %lu cannot be used as IRQ", hwirq);
240+
return -EPERM;
241+
}
242+
234243
/* Falling edge and level low triggers not supported by the GPIO controller */
235244
switch (type) {
236245
case IRQ_TYPE_NONE:
@@ -248,7 +257,7 @@ static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
248257
return -EINVAL;
249258
}
250259

251-
return gnr_gpio_configure_line(gc, pin, mask, set);
260+
return gnr_gpio_configure_line(gc, hwirq, GNR_CFG_DW_RX_MASK, set);
252261
}
253262

254263
static const struct irq_chip gnr_gpio_irq_chip = {

0 commit comments

Comments
 (0)