Commit 3e9aeba1 authored by Hans de Goede's avatar Hans de Goede Committed by Kamal Mostafa

pinctrl: sunxi: Fix A33 external interrupts not working

commit 5e7515ba upstream.

pinctrl-sun8i-a33.c (and the dts) declare only 2 interrupt banks,
where as the closely related a23 has 3 banks. This matches with the
datasheet for the A33 where only interrupt banks B and G are specified
where as the A23 has banks A, B and G.

However the A33 being the A23 derative it is means that the interrupt
configure/status io-addresses for the 2 banks it has are not changed
from the A23, iow they have the same address as if bank A was still
present. Where as the sunxi pinctrl currently tries to use the A23 bank
A addresses for bank B, since the pinctrl code does not know about the
removed bank A.

Add a irq_bank_base parameter and use this where appropriate to take
the missing bank A into account.

This fixes external interrupts not working on the A33 (tested with
an i2c touchscreen controller which uses an external interrupt).
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Acked-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 0c3a5264
...@@ -485,6 +485,7 @@ static const struct sunxi_pinctrl_desc sun8i_a33_pinctrl_data = { ...@@ -485,6 +485,7 @@ static const struct sunxi_pinctrl_desc sun8i_a33_pinctrl_data = {
.pins = sun8i_a33_pins, .pins = sun8i_a33_pins,
.npins = ARRAY_SIZE(sun8i_a33_pins), .npins = ARRAY_SIZE(sun8i_a33_pins),
.irq_banks = 2, .irq_banks = 2,
.irq_bank_base = 1,
}; };
static int sun8i_a33_pinctrl_probe(struct platform_device *pdev) static int sun8i_a33_pinctrl_probe(struct platform_device *pdev)
......
...@@ -589,7 +589,7 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -589,7 +589,7 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type)
{ {
struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d);
struct irq_desc *desc = container_of(d, struct irq_desc, irq_data); struct irq_desc *desc = container_of(d, struct irq_desc, irq_data);
u32 reg = sunxi_irq_cfg_reg(d->hwirq); u32 reg = sunxi_irq_cfg_reg(d->hwirq, pctl->desc->irq_bank_base);
u8 index = sunxi_irq_cfg_offset(d->hwirq); u8 index = sunxi_irq_cfg_offset(d->hwirq);
unsigned long flags; unsigned long flags;
u32 regval; u32 regval;
...@@ -637,7 +637,8 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -637,7 +637,8 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type)
static void sunxi_pinctrl_irq_ack(struct irq_data *d) static void sunxi_pinctrl_irq_ack(struct irq_data *d)
{ {
struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d);
u32 status_reg = sunxi_irq_status_reg(d->hwirq); u32 status_reg = sunxi_irq_status_reg(d->hwirq,
pctl->desc->irq_bank_base);
u8 status_idx = sunxi_irq_status_offset(d->hwirq); u8 status_idx = sunxi_irq_status_offset(d->hwirq);
/* Clear the IRQ */ /* Clear the IRQ */
...@@ -647,7 +648,7 @@ static void sunxi_pinctrl_irq_ack(struct irq_data *d) ...@@ -647,7 +648,7 @@ static void sunxi_pinctrl_irq_ack(struct irq_data *d)
static void sunxi_pinctrl_irq_mask(struct irq_data *d) static void sunxi_pinctrl_irq_mask(struct irq_data *d)
{ {
struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d);
u32 reg = sunxi_irq_ctrl_reg(d->hwirq); u32 reg = sunxi_irq_ctrl_reg(d->hwirq, pctl->desc->irq_bank_base);
u8 idx = sunxi_irq_ctrl_offset(d->hwirq); u8 idx = sunxi_irq_ctrl_offset(d->hwirq);
unsigned long flags; unsigned long flags;
u32 val; u32 val;
...@@ -664,7 +665,7 @@ static void sunxi_pinctrl_irq_mask(struct irq_data *d) ...@@ -664,7 +665,7 @@ static void sunxi_pinctrl_irq_mask(struct irq_data *d)
static void sunxi_pinctrl_irq_unmask(struct irq_data *d) static void sunxi_pinctrl_irq_unmask(struct irq_data *d)
{ {
struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d);
u32 reg = sunxi_irq_ctrl_reg(d->hwirq); u32 reg = sunxi_irq_ctrl_reg(d->hwirq, pctl->desc->irq_bank_base);
u8 idx = sunxi_irq_ctrl_offset(d->hwirq); u8 idx = sunxi_irq_ctrl_offset(d->hwirq);
unsigned long flags; unsigned long flags;
u32 val; u32 val;
...@@ -722,7 +723,7 @@ static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc) ...@@ -722,7 +723,7 @@ static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc)
if (bank == pctl->desc->irq_banks) if (bank == pctl->desc->irq_banks)
return; return;
reg = sunxi_irq_status_reg_from_bank(bank); reg = sunxi_irq_status_reg_from_bank(bank, pctl->desc->irq_bank_base);
val = readl(pctl->membase + reg); val = readl(pctl->membase + reg);
if (val) { if (val) {
...@@ -1001,9 +1002,11 @@ int sunxi_pinctrl_init(struct platform_device *pdev, ...@@ -1001,9 +1002,11 @@ int sunxi_pinctrl_init(struct platform_device *pdev,
for (i = 0; i < pctl->desc->irq_banks; i++) { for (i = 0; i < pctl->desc->irq_banks; i++) {
/* Mask and clear all IRQs before registering a handler */ /* Mask and clear all IRQs before registering a handler */
writel(0, pctl->membase + sunxi_irq_ctrl_reg_from_bank(i)); writel(0, pctl->membase + sunxi_irq_ctrl_reg_from_bank(i,
pctl->desc->irq_bank_base));
writel(0xffffffff, writel(0xffffffff,
pctl->membase + sunxi_irq_status_reg_from_bank(i)); pctl->membase + sunxi_irq_status_reg_from_bank(i,
pctl->desc->irq_bank_base));
irq_set_chained_handler_and_data(pctl->irq[i], irq_set_chained_handler_and_data(pctl->irq[i],
sunxi_pinctrl_irq_handler, sunxi_pinctrl_irq_handler,
......
...@@ -97,6 +97,7 @@ struct sunxi_pinctrl_desc { ...@@ -97,6 +97,7 @@ struct sunxi_pinctrl_desc {
int npins; int npins;
unsigned pin_base; unsigned pin_base;
unsigned irq_banks; unsigned irq_banks;
unsigned irq_bank_base;
bool irq_read_needs_mux; bool irq_read_needs_mux;
}; };
...@@ -233,12 +234,12 @@ static inline u32 sunxi_pull_offset(u16 pin) ...@@ -233,12 +234,12 @@ static inline u32 sunxi_pull_offset(u16 pin)
return pin_num * PULL_PINS_BITS; return pin_num * PULL_PINS_BITS;
} }
static inline u32 sunxi_irq_cfg_reg(u16 irq) static inline u32 sunxi_irq_cfg_reg(u16 irq, unsigned bank_base)
{ {
u8 bank = irq / IRQ_PER_BANK; u8 bank = irq / IRQ_PER_BANK;
u8 reg = (irq % IRQ_PER_BANK) / IRQ_CFG_IRQ_PER_REG * 0x04; u8 reg = (irq % IRQ_PER_BANK) / IRQ_CFG_IRQ_PER_REG * 0x04;
return IRQ_CFG_REG + bank * IRQ_MEM_SIZE + reg; return IRQ_CFG_REG + (bank_base + bank) * IRQ_MEM_SIZE + reg;
} }
static inline u32 sunxi_irq_cfg_offset(u16 irq) static inline u32 sunxi_irq_cfg_offset(u16 irq)
...@@ -247,16 +248,16 @@ static inline u32 sunxi_irq_cfg_offset(u16 irq) ...@@ -247,16 +248,16 @@ static inline u32 sunxi_irq_cfg_offset(u16 irq)
return irq_num * IRQ_CFG_IRQ_BITS; return irq_num * IRQ_CFG_IRQ_BITS;
} }
static inline u32 sunxi_irq_ctrl_reg_from_bank(u8 bank) static inline u32 sunxi_irq_ctrl_reg_from_bank(u8 bank, unsigned bank_base)
{ {
return IRQ_CTRL_REG + bank * IRQ_MEM_SIZE; return IRQ_CTRL_REG + (bank_base + bank) * IRQ_MEM_SIZE;
} }
static inline u32 sunxi_irq_ctrl_reg(u16 irq) static inline u32 sunxi_irq_ctrl_reg(u16 irq, unsigned bank_base)
{ {
u8 bank = irq / IRQ_PER_BANK; u8 bank = irq / IRQ_PER_BANK;
return sunxi_irq_ctrl_reg_from_bank(bank); return sunxi_irq_ctrl_reg_from_bank(bank, bank_base);
} }
static inline u32 sunxi_irq_ctrl_offset(u16 irq) static inline u32 sunxi_irq_ctrl_offset(u16 irq)
...@@ -265,16 +266,16 @@ static inline u32 sunxi_irq_ctrl_offset(u16 irq) ...@@ -265,16 +266,16 @@ static inline u32 sunxi_irq_ctrl_offset(u16 irq)
return irq_num * IRQ_CTRL_IRQ_BITS; return irq_num * IRQ_CTRL_IRQ_BITS;
} }
static inline u32 sunxi_irq_status_reg_from_bank(u8 bank) static inline u32 sunxi_irq_status_reg_from_bank(u8 bank, unsigned bank_base)
{ {
return IRQ_STATUS_REG + bank * IRQ_MEM_SIZE; return IRQ_STATUS_REG + (bank_base + bank) * IRQ_MEM_SIZE;
} }
static inline u32 sunxi_irq_status_reg(u16 irq) static inline u32 sunxi_irq_status_reg(u16 irq, unsigned bank_base)
{ {
u8 bank = irq / IRQ_PER_BANK; u8 bank = irq / IRQ_PER_BANK;
return sunxi_irq_status_reg_from_bank(bank); return sunxi_irq_status_reg_from_bank(bank, bank_base);
} }
static inline u32 sunxi_irq_status_offset(u16 irq) static inline u32 sunxi_irq_status_offset(u16 irq)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment