[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACRpkdaY7xpoeeUqBBqUS2swe6Y5gKt67VYNvNRrsbFhyU=ATw@mail.gmail.com>
Date: Thu, 2 Jan 2014 13:32:49 +0100
From: Linus Walleij <linus.walleij@...aro.org>
To: Sergei Ianovich <ynvich@...il.com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>,
Arnd Bergmann <arnd@...db.de>,
Rob Herring <rob.herring@...xeda.com>,
Pawel Moll <pawel.moll@....com>,
Mark Rutland <mark.rutland@....com>,
Ian Campbell <ijc+devicetree@...lion.org.uk>,
Kumar Gala <galak@...eaurora.org>,
Rob Landley <rob@...dley.net>,
Russell King <linux@....linux.org.uk>,
Thomas Gleixner <tglx@...utronix.de>,
Grant Likely <grant.likely@...aro.org>,
"open list:OPEN FIRMWARE AND..." <devicetree@...r.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@...r.kernel.org>
Subject: Re: [PATCH v3 11/21] ARM: pxa: support ICP DAS LP-8x4x FPGA irq
On Tue, Dec 17, 2013 at 8:37 PM, Sergei Ianovich <ynvich@...il.com> wrote:
> ICP DAS LP-8x4x contains FPGA chip. The chip functions as a interrupt
> source providing 16 additional interrupts among other things. The
> interrupt lines are muxed to a GPIO pin. GPIO pins are in turn muxed
> to a CPU interrupt line.
>
> Until pxa is completely converted to device tree, it is impossible
> to use IRQCHIP_DECLARE() and the irqdomain needs to added manually.
>
> Signed-off-by: Sergei Ianovich <ynvich@...il.com>
> CC: Arnd Bergmann <arnd@...db.de>
> CC: Linus Walleij <linus.walleij@...aro.org>
(...)
> +++ b/drivers/irqchip/irq-lp8x4x.c
Usually combined GPIO+IRQ controllers are put into drivers/gpio but
this is a bit special as it seems to handle also non-GPIO-related IRQs
so let's get some input on this.
> +static unsigned char irq_sys_enabled;
> +static unsigned char irq_high_enabled;
> +static void *base;
> +static int irq_base;
> +static int num_irq = 16;
Please use the state container design pattern and get rid of these
global variables.
This documentation patch describes this pattern and has been
merged for v3.14, so please read this:
http://marc.info/?l=linux-kernel&m=138615980524966&w=2
> +static void lp8x4x_mask_irq(struct irq_data *d)
> +{
> + unsigned mask;
> + int irq = d->irq - irq_base;
Don't calculate hardware IRQ numbers from offsets. Use
irqdomain, which is done for exactly this purpose.
> + if (irq < 8) {
> + irq_high_enabled &= ~(1 << irq);
I usually use the BIT() macro for this, like:
#include <linux/bitops.h>
irq_high_enabled &= ~BIT(irq);
> +static struct irq_chip lp8x4x_irq_chip = {
> + .name = "FPGA",
> + .irq_ack = lp8x4x_mask_irq,
> + .irq_mask = lp8x4x_mask_irq,
> + .irq_mask_ack = lp8x4x_mask_irq,
> + .irq_unmask = lp8x4x_unmask_irq,
> +};
After you have added your state container you will have
a handle to your struct gpio_chip in the cookie passed to
as irqdata.
Then you need to mark the GPIO lines used for IRQs by
doing something similar to this patch in your startup()
and shutdown() callbacks:
http://marc.info/?l=linux-gpio&m=138547223832167&w=2
> +static void lp8x4x_irq_handler(unsigned int irq, struct irq_desc *desc)
> +{> +static void lp8x4x_unmask_irq(struct irq_data *d)
> +{
> + unsigned mask;
> + int irq = d->irq - irq_base;
Use the irqdomain.
> + int loop, n;
> + unsigned long mask;
> + struct irq_chip *chip = irq_desc_get_chip(desc);
> +
> + chained_irq_enter(chip, desc);
> +
> + do {
> + loop = 0;
> + mask = ioread8(base + CLRHILVINT) & 0xff;
> + mask |= (ioread8(base + SECOINT) & 0x1f) << 8;
> + mask |= (ioread8(base + PRIMINT) & 0xe0) << 8;
#define these magic constants so we know what they mean.
0x1f, 0xe0...
> + mask &= (irq_high_enabled | (irq_sys_enabled << 8));
> + for_each_set_bit(n, &mask, BITS_PER_LONG) {
> + loop = 1;
> +
> + generic_handle_irq(irq_base + n);
> + }
> + } while (loop);
If you're going to do it like this then have "loop" be a bool variable.
However I don't quite like this construction, an eternal for() loop
with a break; statement works too, but try to just use the mask and
get rid of the "loop" helper variable.
> + iowrite8(0, base + EOI);
This looks dangerous, what are you doing here?
> +static int lp8x4x_irq_probe(struct platform_device *pdev)
> +{
> + struct resource *rm, *ri;
Explain these names. Usually we call them "res" or something
simple like this.
> + irq_base = irq_alloc_descs(-1, 0, num_irq, 0);
> + if (irq_base < 0) {
> + dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n");
> + return irq_base;
> + }
Instead of doing this, create the descriptors by calling
irq_create_mapping() on all the hardware lines after adding
the irq domain.
> + domain = irq_domain_add_legacy(np, num_irq, irq_base, 0,
> + &lp8x4x_irq_domain_ops, NULL);
> + if (!domain) {
> + dev_err(&pdev->dev, "Failed to add IRQ domain\n");
> + return -ENOMEM;
> + }
Why are you using a legacy irqdomain? You're not dependent
on any specific base so use a linear domain.
> + iowrite8(0, base + CLRRISEINT);
> + iowrite8(0, base + ENRISEINT);
> + iowrite8(0, base + CLRFALLINT);
> + iowrite8(0, base + ENFALLINT);
> + iowrite8(0, base + CLRHILVINT);
> + iowrite8(0, base + ENHILVINT);
> + iowrite8(0, base + ENSYSINT);
> + iowrite8(0, base + SECOINT);
Add a comment explaining what you're doing here.
> +static int __init lp8x4x_irq_init(void)
> +{
> + return platform_driver_register(&lp8x4x_irq_driver);
> +}
> +postcore_initcall(lp8x4x_irq_init);
Do you *have* to do it this early? I guess if it's used for
the UARTs then yes, but make a case for it...
Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists