linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Linux Input <linux-input@vger.kernel.org>,
	"linux-leds@vger.kernel.org" <linux-leds@vger.kernel.org>,
	"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
	"linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	Andrea Adami <andrea.adami@gmail.com>,
	Russell King <linux@arm.linux.org.uk>,
	Daniel Mack <daniel@zonque.org>,
	Haojian Zhuang <haojian.zhuang@gmail.com>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	Alexandre Courbot <gnurou@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Jingoo
Subject: Re: [PATCH 14/15] gpio: locomo: implement per-pin irq handling
Date: Fri, 31 Oct 2014 09:00:49 +0100	[thread overview]
Message-ID: <CACRpkdamVriR9kJSeY=LVAx7ADukT8+GpqmNH9YMnL3OKUk8iw@mail.gmail.com> (raw)
In-Reply-To: <1414454528-24240-15-git-send-email-dbaryshkov@gmail.com>

On Tue, Oct 28, 2014 at 1:02 AM, Dmitry Eremin-Solenikov
<dbaryshkov@gmail.com> wrote:

> LoCoMo has a possibility to generate per-GPIO edge irqs. Support for
> that was there in old locomo driver, got 'cleaned up' during old driver
> IRQ cascading cleanup and is now reimplemented. It is expected that
> SL-5500 (collie) will use locomo gpio irqs for mmc detection irq.
>
> Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>

Please don't use open-coded IRQ handling like this, we are moving
away from that.

In Kconfig,

select GPIOLIB_IRQCHIP

and look at the other drivers selecting this for inspiration. There
is even some documentation in Documentation/gpio/driver.txt

You will find that it cuts down a lot of overhead from your driver
and does everything in the right way in a central place.

>  struct locomo_gpio {
>         void __iomem *regs;
> +       int irq;
>
>         spinlock_t lock;
>         struct gpio_chip gpio;
> +       int irq_base;

gpiolib irqchip helpers uses irqdomain to do all this debasing
and rebasing for you. Go with that.

> +static int locomo_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
> +{
> +       struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
> +
> +       return lg->irq_base + offset;
> +}

And it implements .to_irq() in the gpiolib core.

> +static void
> +locomo_gpio_handler(unsigned int irq, struct irq_desc *desc)

It's locomo_gpio_irq_handler() right?

> +{
> +       u16 req;
> +       struct locomo_gpio *lg = irq_get_handler_data(irq);
> +       int i = lg->irq_base;
> +
> +       req = readw(lg->regs + LOCOMO_GIR) &
> +             readw(lg->regs + LOCOMO_GPD);
> +
> +       while (req) {
> +               if (req & 1)
> +                       generic_handle_irq(i);
> +               req >>= 1;
> +               i++;
> +       }

Same thing as the MFD device, look closer at how you construct
the IRQ handling loop, so the register gets re-read each iteration.

> +static void locomo_gpio_ack_irq(struct irq_data *d)
> +{
> +       struct locomo_gpio *lg = irq_data_get_irq_chip_data(d);
> +       unsigned long flags;
> +       u16 r;
> +
> +       spin_lock_irqsave(&lg->lock, flags);
> +
> +       r = readw(lg->regs + LOCOMO_GWE);
> +       r |= (0x0001 << (d->irq - lg->irq_base));
> +       writew(r, lg->regs + LOCOMO_GWE);
> +
> +       r = readw(lg->regs + LOCOMO_GIS);
> +       r &= ~(0x0001 << (d->irq - lg->irq_base));
> +       writew(r, lg->regs + LOCOMO_GIS);
> +
> +       r = readw(lg->regs + LOCOMO_GWE);
> +       r &= ~(0x0001 << (d->irq - lg->irq_base));
> +       writew(r, lg->regs + LOCOMO_GWE);
> +
> +       spin_unlock_irqrestore(&lg->lock, flags);
> +}

I really wonder if this locking is needed around these
regioster accesses. It seems more like a habit than
like something that is actually needed. Think it over.

*irqsave* versions of spinlocks are definately wrong
in the irqchip callbacks, if you give it a minute I think
you quickly realize why.

> +static int locomo_gpio_type(struct irq_data *d, unsigned int type)
> +{
> +       unsigned int mask;
> +       struct locomo_gpio *lg = irq_data_get_irq_chip_data(d);
> +       unsigned long flags;
> +
> +       mask = 1 << (d->irq - lg->irq_base);

This should just use d->hwirq with irqdomain implemented
correctly.

(...)

> +static void locomo_gpio_setup_irq(struct locomo_gpio *lg)
> +{
> +       int irq;
> +
> +       lg->irq_base = irq_alloc_descs(-1, 0, LOCOMO_GPIO_NR_IRQS, -1);
> +
> +       /* Install handlers for IRQ_LOCOMO_* */
> +       for (irq = lg->irq_base;
> +                       irq < lg->irq_base + LOCOMO_GPIO_NR_IRQS;
> +                       irq++) {
> +               irq_set_chip_and_handler(irq, &locomo_gpio_chip,
> +                               handle_edge_irq);
> +               irq_set_chip_data(irq, lg);
> +               set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
> +       }
> +
> +       /*
> +        * Install handler for IRQ_LOCOMO_HW.
> +        */
> +       irq_set_handler_data(lg->irq, lg);
> +       irq_set_chained_handler(lg->irq, locomo_gpio_handler);
> +}

All this gets redundant with gpiochip_irqchip_add()
and gpiochip_set_chained_irqchip().

Yours,
Linus Walleij

  reply	other threads:[~2014-10-31  8:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-28  0:01 [PATCH 00/15] new locomo driver Dmitry Eremin-Solenikov
2014-10-28  0:01 ` [PATCH 01/15] mfd: add new driver for Sharp LoCoMo Dmitry Eremin-Solenikov
     [not found]   ` <1414454528-24240-2-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-31  7:42     ` Linus Walleij
2014-10-31  9:54       ` Dmitry Eremin-Solenikov
     [not found]         ` <CALT56yNX8v4mZn=o1ZoVLHPmg6wq0dgFNowpqNuFtU=eCc+d8w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-03 13:41           ` Linus Walleij
2014-11-05 20:02             ` Dmitry Eremin-Solenikov
2014-11-05 20:24               ` Mark Brown
2014-11-14 12:47                 ` Dmitry Eremin-Solenikov
2014-11-14 15:10                   ` Mark Brown
2014-11-14 15:30                     ` Dmitry Eremin-Solenikov
2014-11-05 20:32               ` Lars-Peter Clausen
2014-11-05 20:42                 ` Lars-Peter Clausen
2014-10-28  0:01 ` [PATCH 02/15] GPIO: port LoCoMo gpio support from old driver Dmitry Eremin-Solenikov
2014-10-31  7:48   ` Linus Walleij
     [not found]     ` <CACRpkdY7tRadod2vQfEytmw-ubaMAvr_=XTczD5bUMkqie0xkg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-31  9:39       ` Dmitry Eremin-Solenikov
     [not found]         ` <CALT56yOgMUA7o2dzfHph=S2zkDV4zERzMh4ishpPwpAx7Cqj6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-03 13:43           ` Linus Walleij
     [not found]             ` <CACRpkdb7v3LmOhbhQ9TPk1_bnLnpwizawW6RQvhQRLSjRewAaQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-05 21:33               ` Dmitry Eremin-Solenikov
2014-11-06  6:03                 ` Mark Brown
2014-11-11 13:16                   ` Dmitry Eremin-Solenikov
     [not found]                     ` <CALT56yPr42FV66USngocw=eWPt81d5R2MJxmzBnv02HOMmXAkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-11 13:23                       ` Mark Brown
2014-11-14 10:11                       ` Linus Walleij
2014-11-14 12:48                         ` Dmitry Eremin-Solenikov
2014-10-28  0:01 ` [PATCH 03/15] leds: port locomo leds driver to new locomo core Dmitry Eremin-Solenikov
     [not found] ` <1414454528-24240-1-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-28  0:01   ` [PATCH 04/15] input: convert LoCoMo keyboard driver to use " Dmitry Eremin-Solenikov
2014-10-28  0:09     ` Dmitry Torokhov
2014-10-28  0:02   ` [PATCH 08/15] ARM: sa1100: make collie use new locomo drivers Dmitry Eremin-Solenikov
2014-10-28  0:02   ` [PATCH 12/15] ARM: pxa: poodle: don't preallocate IRQ space for locomo Dmitry Eremin-Solenikov
2014-10-28 19:13     ` Robert Jarzmik
2014-10-28  0:02   ` [PATCH 13/15] ARM: drop old LoCoMo driver Dmitry Eremin-Solenikov
2014-10-28  0:02   ` [PATCH 14/15] gpio: locomo: implement per-pin irq handling Dmitry Eremin-Solenikov
2014-10-31  8:00     ` Linus Walleij [this message]
2014-10-31  9:35       ` Dmitry Eremin-Solenikov
2014-10-28  0:02   ` [PATCH 15/15] spi: add locomo SPI driver Dmitry Eremin-Solenikov
     [not found]     ` <1414454528-24240-16-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-28 11:03       ` Mark Brown
2014-10-28  0:01 ` [PATCH 05/15] video: backlight: add new locomo backlight driver Dmitry Eremin-Solenikov
2014-10-28  0:24   ` Jingoo Han
2014-10-28  0:01 ` [PATCH 06/15] video: lcd: add LoCoMo LCD driver Dmitry Eremin-Solenikov
2014-10-28  0:30   ` Jingoo Han
2014-10-28 16:47     ` Dmitry Eremin-Solenikov
2014-10-28  0:02 ` [PATCH 07/15] video: backlight: drop old locomo bl/lcd driver Dmitry Eremin-Solenikov
2014-10-28  0:02 ` [PATCH 09/15] ARM: sa1100: don't preallocate IRQ space for locomo Dmitry Eremin-Solenikov
2014-10-31  7:50   ` Linus Walleij
2014-10-31  9:33     ` Dmitry Eremin-Solenikov
2014-10-28  0:02 ` [PATCH 10/15] ARM: pxa: poodle: use new LoCoMo driver Dmitry Eremin-Solenikov
2014-10-28  0:02 ` [PATCH 11/15] sound: soc: poodle: make use of new locomo GPIO interface Dmitry Eremin-Solenikov
     [not found]   ` <1414454528-24240-12-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-28 14:58     ` Mark Brown
     [not found]       ` <20141028145850.GU18557-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-10-28 16:45         ` Dmitry Eremin-Solenikov
2014-10-29  3:03       ` Alexandre Courbot
     [not found]         ` <CAAVeFuKgARoMFzf+663iP6cULs93d4WSQS8ESjUb9VcxguWurA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-31  9:52           ` Linus Walleij
2014-10-31  9:58             ` Dmitry Eremin-Solenikov
2014-11-01  5:42               ` Alexandre Courbot
2014-10-28  0:13 ` [PATCH 00/15] new locomo driver Russell King - ARM Linux
     [not found]   ` <20141028001338.GZ27405-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2014-10-28  0:28     ` Dmitry Eremin-Solenikov
2014-10-28  0:29   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACRpkdamVriR9kJSeY=LVAx7ADukT8+GpqmNH9YMnL3OKUk8iw@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andrea.adami@gmail.com \
    --cc=broonie@kernel.org \
    --cc=cooloney@gmail.com \
    --cc=daniel@zonque.org \
    --cc=dbaryshkov@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gnurou@gmail.com \
    --cc=haojian.zhuang@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=robert.jarzmik@free.fr \
    --cc=rpurdie@rpsys.net \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).