Re: [PATCH V3 4/4] irq: imx: irqsteer: add multi output interrupts support
From: Lucas Stach
Date: Thu Jan 31 2019 - 04:08:37 EST
Am Donnerstag, den 31.01.2019, 08:03 +0000 schrieb Aisheng Dong:
> One irqsteer channel can support up to 8 output interrupts.
>
> > Cc: Marc Zyngier <marc.zyngier@xxxxxxx>
> > Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> > Cc: Shawn Guo <shawnguo@xxxxxxxxxx>
> Signed-off-by: Dong Aisheng <aisheng.dong@xxxxxxx>
Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> ---
> ChangeLog:
> v2->v3:
> Â* add error check for imx_irqsteer_get_hwirq_base
> Â* use DIV_ROUND_UP
> Â* merge 'hwirq +=32' into for loop
> Â* common error path in probe to avoid replicating clk_disable_unprepare
> v1->v2:
> Â* calculate irq_count by fsl,num-irqs instead of parsing interrupts
> ÂÂÂproperty from devicetree to match the input interrupts and outputs
> Â* improve output interrupt handler by searching only two registers
> ÂÂÂwithint the same group
> ---
> Âdrivers/irqchip/irq-imx-irqsteer.c | 88 +++++++++++++++++++++++++++++---------
> Â1 file changed, 68 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/irqchip/irq-imx-irqsteer.c b/drivers/irqchip/irq-imx-irqsteer.c
> index 67ed862..d1098f4 100644
> --- a/drivers/irqchip/irq-imx-irqsteer.c
> +++ b/drivers/irqchip/irq-imx-irqsteer.c
> @@ -10,6 +10,7 @@
> Â#include <linux/irqchip/chained_irq.h>
> Â#include <linux/irqdomain.h>
> Â#include <linux/kernel.h>
> +#include <linux/of_irq.h>
> Â#include <linux/of_platform.h>
> Â#include <linux/spinlock.h>
> Â
> @@ -21,10 +22,13 @@
> > Â#define CHAN_MINTDIS(t) (CTRL_STRIDE_OFF(t, 3) + 0x4)
> > Â#define CHAN_MASTRSTAT(t) (CTRL_STRIDE_OFF(t, 3) + 0x8)
> Â
> > +#define CHAN_MAX_OUTPUT_INT 0x8
> +
> Âstruct irqsteer_data {
> > > Â void __iomem *regs;
> > > Â struct clk *ipg_clk;
> > > - int irq;
> > > + int irq[CHAN_MAX_OUTPUT_INT];
> > > + int irq_count;
> > > Â raw_spinlock_t lock;
> > > Â int reg_num;
> > > Â int channel;
> @@ -87,23 +91,47 @@ static const struct irq_domain_ops imx_irqsteer_domain_ops = {
> > > Â .xlate = irq_domain_xlate_onecell,
> Â};
> Â
> +static int imx_irqsteer_get_hwirq_base(struct irqsteer_data *data, u32 irq)
> +{
> > + int i;
> +
> > + for (i = 0; i < data->irq_count; i++) {
> > + if (data->irq[i] == irq)
> > + return i * 64;
> > + }
> +
> > + return -EINVAL;
> +}
> +
> Âstatic void imx_irqsteer_irq_handler(struct irq_desc *desc)
> Â{
> > Â struct irqsteer_data *data = irq_desc_get_handler_data(desc);
> > - int i;
> > + int hwirq;
> > + int irq, i;
> Â
> > Â chained_irq_enter(irq_desc_get_chip(desc), desc);
> Â
> > - for (i = 0; i < data->reg_num * 32; i += 32) {
> > - int idx = imx_irqsteer_get_reg_index(data, i);
> > + irq = irq_desc_get_irq(desc);
> > + hwirq = imx_irqsteer_get_hwirq_base(data, irq);
> > + if (hwirq < 0) {
> > + pr_warn("%s: unable to get hwirq base for irq %d\n",
> > + __func__, irq);
> > + return;
> > + }
> +
> > + for (i = 0; i < 2; i++, hwirq += 32) {
> > + int idx = imx_irqsteer_get_reg_index(data, hwirq);
> > Â unsigned long irqmap;
> > Â int pos, virq;
> Â
> > + if (hwirq >= data->reg_num * 32)
> > + break;
> +
> > Â irqmap = readl_relaxed(data->regs +
> > Â ÂÂÂÂÂÂÂCHANSTATUS(idx, data->reg_num));
> Â
> > Â for_each_set_bit(pos, &irqmap, 32) {
> > - virq = irq_find_mapping(data->domain, pos + i);
> > + virq = irq_find_mapping(data->domain, pos + hwirq);
> > Â if (virq)
> > Â generic_handle_irq(virq);
> > Â }
> @@ -117,7 +145,8 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> > Â struct device_node *np = pdev->dev.of_node;
> > Â struct irqsteer_data *data;
> > Â struct resource *res;
> > - int ret;
> > + u32 irqs_num;
> > + int i, ret;
> Â
> > Â data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > Â if (!data)
> @@ -130,12 +159,6 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> > Â return PTR_ERR(data->regs);
> > Â }
> Â
> > - data->irq = platform_get_irq(pdev, 0);
> > - if (data->irq <= 0) {
> > - dev_err(&pdev->dev, "failed to get irq\n");
> > - return -ENODEV;
> > - }
> -
> > Â data->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
> > Â if (IS_ERR(data->ipg_clk)) {
> > Â ret = PTR_ERR(data->ipg_clk);
> @@ -146,11 +169,15 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> Â
> > Â raw_spin_lock_init(&data->lock);
> Â
> > - of_property_read_u32(np, "fsl,num-irqs", &data->reg_num);
> > + of_property_read_u32(np, "fsl,num-irqs", &irqs_num);
> > Â of_property_read_u32(np, "fsl,channel", &data->channel);
> Â
> > - /* one register bit map represents 32 input interrupts */
> > - data->reg_num /= 32;
> > + /*
> > + Â* There is one output irq for each group of 64 inputs.
> > + Â* One register bit map can represent 32 input interrupts.
> > + Â*/
> > + data->irq_count = DIV_ROUND_UP(irqs_num, 64);
> > + data->reg_num = irqs_num / 32;
> Â
> > Â if (IS_ENABLED(CONFIG_PM_SLEEP)) {
> > Â data->saved_reg = devm_kzalloc(&pdev->dev,
> @@ -173,23 +200,44 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
> > Â ÂÂÂÂÂ&imx_irqsteer_domain_ops, data);
> > Â if (!data->domain) {
> > Â dev_err(&pdev->dev, "failed to create IRQ domain\n");
> > - clk_disable_unprepare(data->ipg_clk);
> > - return -ENOMEM;
> > + ret = -ENOMEM;
> > + goto out;
> > Â }
> Â
> > - irq_set_chained_handler_and_data(data->irq, imx_irqsteer_irq_handler,
> > - Âdata);
> > + if (!data->irq_count || data->irq_count > CHAN_MAX_OUTPUT_INT) {
> > + ret = -EINVAL;
> > + goto out;
> > + }
> +
> > + for (i = 0; i < data->irq_count; i++) {
> > + data->irq[i] = irq_of_parse_and_map(np, i);
> > + if (!data->irq[i]) {
> > + ret = -EINVAL;
> > + goto out;
> > + }
> +
> > + irq_set_chained_handler_and_data(data->irq[i],
> > + Âimx_irqsteer_irq_handler,
> > + Âdata);
> > + }
> Â
> > Â platform_set_drvdata(pdev, data);
> Â
> > Â return 0;
> +out:
> > + clk_disable_unprepare(data->ipg_clk);
> > + return ret;
> Â}
> Â
> Âstatic int imx_irqsteer_remove(struct platform_device *pdev)
> Â{
> > Â struct irqsteer_data *irqsteer_data = platform_get_drvdata(pdev);
> > + int i;
> +
> > + for (i = 0; i < irqsteer_data->irq_count; i++)
> > + irq_set_chained_handler_and_data(irqsteer_data->irq[i],
> > + ÂNULL, NULL);
> Â
> > - irq_set_chained_handler_and_data(irqsteer_data->irq, NULL, NULL);
> > Â irq_domain_remove(irqsteer_data->domain);
> Â
> > Â clk_disable_unprepare(irqsteer_data->ipg_clk);