linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bin Gao <bin.gao@linux.intel.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Alexandre Courbot <gnurou@gmail.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>,
	Yegnesh S Iyer <yegnesh.s.iyer@intel.com>,
	Bin Gao <bin.gao@intel.com>
Subject: Re: [PATCH v4] gpio: add Intel WhiskeyCove GPIO driver
Date: Wed, 6 Jul 2016 22:29:45 -0700	[thread overview]
Message-ID: <20160707052945.GA115716@worksta> (raw)
In-Reply-To: <CACRpkdZJ0AUWmxLApzryCZbQcQmwWO1A-NLMP46WsLkJBZgprQ@mail.gmail.com>

On Wed, Jul 06, 2016 at 10:57:19AM +0200, Linus Walleij wrote:
> > +static irqreturn_t wcove_gpio_irq_handler(int irq, void *data)
> > +{
> > +       int pending;
> > +       unsigned int p0, p1, virq, gpio;
> > +       struct wcove_gpio *wg = data;
> > +
> > +       if (regmap_read(wg->regmap, IRQ_STATUS_OFFSET + 0, &p0) ||
> > +           regmap_read(wg->regmap, IRQ_STATUS_OFFSET + 1, &p1)) {
> 
> Why can't you use regmap_bulk_read() here?

Will fix this in v5.

> 
> > +               dev_err(wg->chip.parent, "%s(): regmap_read() failed.\n",
> > +                                                               __func__);
> > +               return IRQ_NONE;
> > +       }
> > +
> > +       pending = p0 | (p1 << 8);
> > +
> > +       for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) {
> > +               if (pending & BIT(gpio)) {
> > +                       virq = irq_find_mapping(wg->chip.irqdomain, gpio);
> > +                       handle_nested_irq(virq);
> > +               }
> > +       }
> > +
> > +       regmap_write(wg->regmap, IRQ_STATUS_OFFSET + 0, p0);
> > +       regmap_write(wg->regmap, IRQ_STATUS_OFFSET + 1, p1);
> 
> Use regmap_bulk_write()?

Will fix this in v5.

> 
> Also you're ignoring the return error code. Check it and dev_err() if
> it fails.

Yes, will fix.

> 
> This loop seems like it could miss interrupts happening while
> processing. Especially edge interrupts, and thatr will lead to serious
> bugs later.
> 
> Please consider the following construction:
> 
> 1. read status register
> 2. Any IRQs active?
>   2.1 No IRQs active: if this is the FIRST iteration, exit with IRQ_NONE
>   2.2 No IRQs active If this the second iteration or later, exit with
> IRQ_HANDLED
>   2.3 IRQs active, continue
> 2. Find first active IRQ
> 3. Handle first active IRQ
> 4. ACK the first active IRQ by writing the status register
> 5. Reiterate from 1
> 
> This way, if two IRQs happen at the same time, or if a new IRQ appears
> while you're inside the interrupt handler, it gets served.

I agree. Writing to status register should be done bit by bit, instead of
one write for all bits. Will fix this in v5.

> 
> > +static void wcove_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
> > +{
> > +       struct wcove_gpio *wg = gpiochip_get_data(chip);
> > +       int gpio, offset, group;
> > +       unsigned int ctlo, ctli, irq_mask, irq_status;
> > +
> > +       for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) {
> > +               group = gpio < GROUP0_NR_IRQS ? 0 : 1;
> > +               regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &ctlo);
> > +               regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &ctli);
> > +               regmap_read(wg->regmap, IRQ_MASK_OFFSET + group, &irq_mask);
> > +               regmap_read(wg->regmap, IRQ_STATUS_OFFSET + group, &irq_status);
> 
> Ignoring error codes. Fix this.

Will Fix in v5.

> 
> > +       gpiochip_irqchip_add(&wg->chip, &wcove_irqchip, 0,
> > +                            handle_simple_irq, IRQ_TYPE_NONE);
> 
> Reexamine the use of handle_simple_irq() here. We have two kinds of
> irq hardware: those with one register for ACKing and reading the status
> of an IRQ, and those with two registers for it: one where you ACK the
> IRQ (so it can immediately re-trigger) and one to read the status of
> whether it happened. Sometimes different handling is needed for
> levek and edge IRQs even (c.f. gpio-pl061.c).
> 
> Only the hardware with just one register for both things should use
> handle_simple_irq(). This seems to be the case here but I want you
> to verify.

I will check and fix if it's needed.

> 
> Yours,
> Linus Walleij

Thanks for your review.

  parent reply	other threads:[~2016-07-07  5:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 23:56 [PATCH v4] gpio: add Intel WhiskeyCove GPIO driver Bin Gao
2016-07-01 20:21 ` Andy Shevchenko
2016-07-06  8:57 ` Linus Walleij
2016-07-06 10:07   ` Mika Westerberg
2016-07-07  5:30     ` Bin Gao
2016-07-07  5:29   ` Bin Gao [this message]
2016-07-12  0:12   ` Bin Gao

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=20160707052945.GA115716@worksta \
    --to=bin.gao@linux.intel.com \
    --cc=ajay.thomas.david.rajamanickam@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bin.gao@intel.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=yegnesh.s.iyer@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).