From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: linux-gpio@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH v3] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
Date: Wed, 27 May 2020 16:28:47 +0300 [thread overview]
Message-ID: <20200527132847.GS1634618@smile.fi.intel.com> (raw)
In-Reply-To: <20200527112749.GS247495@lahna.fi.intel.com>
On Wed, May 27, 2020 at 02:27:49PM +0300, Mika Westerberg wrote:
> On Tue, May 26, 2020 at 08:12:22PM +0300, Andy Shevchenko wrote:
> > ACPI table on Intel Galileo Gen 2 has wrong pin number for IRQ resource
> > of one of the I²C GPIO expanders. Since we know what that number is and
> > luckily have GPIO bases fixed for SoC's controllers, we may use a simple
> > DMI quirk to match the platform and retrieve GpioInt() pin on it for
> > the expander in question.
...
> > +static int pca953x_acpi_get_pin(struct acpi_resource *ares, void *data)
> > +{
> > + struct acpi_resource_gpio *agpio;
> > + int *pin = data;
> > +
> > + if (!acpi_gpio_get_irq_resource(ares, &agpio))
> > + return 1;
> > +
> > + *pin = agpio->pin_table[0];
>
> Writing it like below looks better IMHO:
>
> if (acpi_gpio_get_irq_resource(ares, &agpio))
> *pin = agpio->pin_table[0];
> return 1;
Actually this reveals a suboptimal behaviour in comparison to
acpi_walk_resources(), i.e. there is no way to stop traversing when
(1st) resource is found.
But okay, I will rewrite.
> > +}
...
> > + ret = acpi_dev_get_resources(adev, &r, pca953x_acpi_get_pin, &pin);
> > + acpi_dev_free_resource_list(&r);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return pin;
>
> Or
> return ret < 0 ? ret : pin;
I think former is better to read since it has been grouped appropriately.
...
> > +static int pca953x_acpi_get_irq(struct device *dev)
> > +{
> > + int pin, ret;
> > +
> > + pin = pca953x_acpi_find_pin(dev);
> > + if (pin < 0)
> > + return pin;
>
> Since you don't actually check the error value you may also return
> simply 0 here (invalid IRQ) and other places.
I don't think it is a good idea, because...
> > + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> > +
> > + if (!gpio_is_valid(pin))
> > + return -EINVAL;
> > +
> > + ret = gpio_request(pin, "pca953x interrupt");
> > + if (ret)
> > + return ret;
> > +
> > + return gpio_to_irq(pin);
... this will become to something like
ret = gpio_to_irq();
if (ret < 0)
return 0;
return ret;
> > +}
...
I agree on the rest.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2020-05-27 13:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-26 17:12 [PATCH v3] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2 Andy Shevchenko
2020-05-27 5:46 ` Linus Walleij
2020-05-27 9:08 ` Andy Shevchenko
2020-05-27 9:13 ` Andy Shevchenko
2020-05-27 11:27 ` Mika Westerberg
2020-05-27 13:28 ` Andy Shevchenko [this message]
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=20200527132847.GS1634618@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=mika.westerberg@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.