Re: [PATCH V2 3/4] irq: imx-irqsteer: change to use reg_num instead of irq_group

From: Lucas Stach
Date: Wed Jan 30 2019 - 08:22:07 EST


Am Mittwoch, den 30.01.2019, 13:06 +0000 schrieb Aisheng Dong:
> One group can manage 64 interrupts by using two registers (e.g. STATUS/SET).
> However, the integrated irqsteer may support only 32 interrupts which
> needs only one register in a group. But the current driver assume there's
> a mininum of two registers in a group which result in a wrong register map
> for 32 interrupts per channel irqsteer. Let's use the reg_num caculated by
> interrupts per channel instead of irq_group to cover this case.
>
> > Cc: Marc Zyngier <marc.zyngier@xxxxxxx>
> > Cc: Rob Herring <robh+dt@xxxxxxxxxx>
> > Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> > Cc: Shawn Guo <shawnguo@xxxxxxxxxx>
> Signed-off-by: Dong Aisheng <aisheng.dong@xxxxxxx>

Minor nit below, otherwise:

Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>

> ---
> v1->v2:
> Â* The using of property name updated accordingly
> ---
> Âdrivers/irqchip/irq-imx-irqsteer.c | 35 +++++++++++++++++++----------------
> Â1 file changed, 19 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/irqchip/irq-imx-irqsteer.c b/drivers/irqchip/irq-imx-irqsteer.c
> index 5b3f1d7..67ed862 100644
> --- a/drivers/irqchip/irq-imx-irqsteer.c
> +++ b/drivers/irqchip/irq-imx-irqsteer.c
> @@ -13,7 +13,7 @@
> Â#include <linux/of_platform.h>
> Â#include <linux/spinlock.h>
> Â
> > -#define CTRL_STRIDE_OFF(_t, _r) (_t * 8 * _r)
> > +#define CTRL_STRIDE_OFF(_t, _r) (_t * 4 * _r)
> > Â#define CHANCTRL 0x0
> > Â#define CHANMASK(n, t) (CTRL_STRIDE_OFF(t, 0) + 0x4 * (n) + 0x4)
> > Â#define CHANSET(n, t) (CTRL_STRIDE_OFF(t, 1) + 0x4 * (n) + 0x4)
> @@ -26,7 +26,7 @@ struct irqsteer_data {
> > > Â struct clk *ipg_clk;
> > > Â int irq;
> > > Â raw_spinlock_t lock;
> > > - int irq_groups;
> > > + int reg_num;
> > > Â int channel;
> > > Â struct irq_domain *domain;
> > > Â u32 *saved_reg;
> @@ -35,7 +35,7 @@ struct irqsteer_data {
> Âstatic int imx_irqsteer_get_reg_index(struct irqsteer_data *data,
> > Â ÂÂÂÂÂÂunsigned long irqnum)
> Â{
> > - return (data->irq_groups * 2 - irqnum / 32 - 1);
> > + return (data->reg_num - irqnum / 32 - 1);
> Â}
> Â
> Âstatic void imx_irqsteer_irq_unmask(struct irq_data *d)
> @@ -46,9 +46,9 @@ static void imx_irqsteer_irq_unmask(struct irq_data *d)
> > Â u32 val;
> Â
> > Â raw_spin_lock_irqsave(&data->lock, flags);
> > - val = readl_relaxed(data->regs + CHANMASK(idx, data->irq_groups));
> > + val = readl_relaxed(data->regs + CHANMASK(idx, data->reg_num));
> > Â val |= BIT(d->hwirq % 32);
> > - writel_relaxed(val, data->regs + CHANMASK(idx, data->irq_groups));
> > + writel_relaxed(val, data->regs + CHANMASK(idx, data->reg_num));
> > Â raw_spin_unlock_irqrestore(&data->lock, flags);
> Â}
> Â
> @@ -60,9 +60,9 @@ static void imx_irqsteer_irq_mask(struct irq_data *d)
> > Â u32 val;
> Â
> > Â raw_spin_lock_irqsave(&data->lock, flags);
> > - val = readl_relaxed(data->regs + CHANMASK(idx, data->irq_groups));
> > + val = readl_relaxed(data->regs + CHANMASK(idx, data->reg_num));
> > Â val &= ~BIT(d->hwirq % 32);
> > - writel_relaxed(val, data->regs + CHANMASK(idx, data->irq_groups));
> > + writel_relaxed(val, data->regs + CHANMASK(idx, data->reg_num));
> > Â raw_spin_unlock_irqrestore(&data->lock, flags);
> Â}
> Â
> @@ -94,13 +94,13 @@ static void imx_irqsteer_irq_handler(struct irq_desc *desc)
> Â
> > Â chained_irq_enter(irq_desc_get_chip(desc), desc);
> Â
> > - for (i = 0; i < data->irq_groups * 64; i += 32) {
> > + for (i = 0; i < data->reg_num * 32; i += 32) {
> > Â int idx = imx_irqsteer_get_reg_index(data, i);
> > Â unsigned long irqmap;
> > Â int pos, virq;
> Â
> > Â irqmap = readl_relaxed(data->regs +
> > - ÂÂÂÂÂÂÂCHANSTATUS(idx, data->irq_groups));
> > + ÂÂÂÂÂÂÂCHANSTATUS(idx, data->reg_num));
> Â
> > Â for_each_set_bit(pos, &irqmap, 32) {
> > Â virq = irq_find_mapping(data->domain, pos + i);
> @@ -146,12 +146,15 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> Â
> > Â raw_spin_lock_init(&data->lock);
> Â
> > - of_property_read_u32(np, "fsl,irq-groups", &data->irq_groups);
> > + of_property_read_u32(np, "fsl,num-irqs", &data->reg_num);
> > Â of_property_read_u32(np, "fsl,channel", &data->channel);
> Â
> > + /* one register bit map represents 32 input interrupts */
> > + data->reg_num /= 32;
> +
> > Â if (IS_ENABLED(CONFIG_PM_SLEEP)) {
> > Â data->saved_reg = devm_kzalloc(&pdev->dev,
> > - sizeof(u32) * data->irq_groups * 2,
> > + sizeof(u32) * data->reg_num,
> Â GFP_KERNEL);

Does this last parameter now fit on the line above?

> Â if (!data->saved_reg)
> > Â return -ENOMEM;
> @@ -166,7 +169,7 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> > Â /* steer all IRQs into configured channel */
> > Â writel_relaxed(BIT(data->channel), data->regs + CHANCTRL);
> Â
> > - data->domain = irq_domain_add_linear(np, data->irq_groups * 64,
> > + data->domain = irq_domain_add_linear(np, data->reg_num * 32,
> > Â ÂÂÂÂÂ&imx_irqsteer_domain_ops, data);
> > Â if (!data->domain) {
> > Â dev_err(&pdev->dev, "failed to create IRQ domain\n");
> @@ -199,9 +202,9 @@ static void imx_irqsteer_save_regs(struct irqsteer_data *data)
> Â{
> > Â int i;
> Â
> > - for (i = 0; i < data->irq_groups * 2; i++)
> > + for (i = 0; i < data->reg_num; i++)
> > Â data->saved_reg[i] = readl_relaxed(data->regs +
> > - CHANMASK(i, data->irq_groups));
> > + CHANMASK(i, data->reg_num));
> Â}
> Â
> Âstatic void imx_irqsteer_restore_regs(struct irqsteer_data *data)
> @@ -209,9 +212,9 @@ static void imx_irqsteer_restore_regs(struct irqsteer_data *data)
> > Â int i;
> Â
> > Â writel_relaxed(BIT(data->channel), data->regs + CHANCTRL);
> > - for (i = 0; i < data->irq_groups * 2; i++)
> > + for (i = 0; i < data->reg_num; i++)
> > Â writel_relaxed(data->saved_reg[i],
> > - ÂÂÂÂÂÂÂdata->regs + CHANMASK(i, data->irq_groups));
> > + ÂÂÂÂÂÂÂdata->regs + CHANMASK(i, data->reg_num));
> Â}
> Â
> Âstatic int imx_irqsteer_suspend(struct device *dev)