All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Ardelean <aardelean@deviqon.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio <linux-iio@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 3/5] iio: accel: mma9551: Add support to get irqs directly from fwnode
Date: Mon, 24 May 2021 11:16:47 +0300	[thread overview]
Message-ID: <CAASAkoY+gz0B9ig4napKdXmtTr74DXs_ONXnBmh9sghk1a6gxg@mail.gmail.com> (raw)
In-Reply-To: <20210523162315.1965869-4-jic23@kernel.org>

On Sun, 23 May 2021 at 19:24, Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> The driver previous supported using GPIO requests to retrieve
> multiple interrupt lines.  As existing firmware may be using
> this method, we need to continue to support it.  However, that doesn't
> stop us also supporting just getting irqs directly.
>
> The handling of irqflags has to take into account the fact that using
> a GPIO method to identify the interrupt does not convey direction of
> the trigger that fwnode_irq_get() will. So we need to set the
> IRQF_TRIGGER_RISING in that path but not otherwise, where it will
> cause an issue if we reprobe the driver after removal.
>

I'm not too experienced here [with this GPIO/IRQ API] to be able to
review this confidently.

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/accel/mma9551.c | 35 +++++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c
> index 1b4a8b27f14a..a0bb4ccdbec7 100644
> --- a/drivers/iio/accel/mma9551.c
> +++ b/drivers/iio/accel/mma9551.c
> @@ -406,30 +406,37 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev)
>         int i, ret;
>         struct mma9551_data *data = iio_priv(indio_dev);
>         struct device *dev = &data->client->dev;
> +       unsigned long irqflags = IRQF_ONESHOT;
>
>         for (i = 0; i < MMA9551_GPIO_COUNT; i++) {
> -               gpio = devm_gpiod_get_index(dev, NULL, i, GPIOD_IN);
> -               if (IS_ERR(gpio)) {
> -                       dev_err(dev, "acpi gpio get index failed\n");
> -                       return PTR_ERR(gpio);
> -               }
> -
> -               ret = gpiod_to_irq(gpio);
> -               if (ret < 0)
> +               /* GPIO provided for backwards compatibility reasons */
> +               ret = fwnode_irq_get(dev_fwnode(dev), i);
> +               if (ret == -EPROBE_DEFER)
>                         return ret;
>
> +               /* fwnode_irq_get() returns 0 for not present on OF, and -EINVAL for ACPI */
> +               if (ret == 0 || ret == -EINVAL) {
> +                       gpio = devm_gpiod_get_index(dev, NULL, i, GPIOD_IN);
> +                       if (IS_ERR(gpio)) {
> +                               dev_err(dev, "gpio get index failed\n");
> +                               return PTR_ERR(gpio);
> +                       }
> +
> +                       ret = gpiod_to_irq(gpio);
> +                       if (ret < 0)
> +                               return ret;
> +                       /* GPIO interrupt does npt have a specified direction */
> +                       irqflags |= IRQF_TRIGGER_RISING;
> +               }
>                 data->irqs[i] = ret;
>                 ret = devm_request_threaded_irq(dev, data->irqs[i],
> -                               NULL, mma9551_event_handler,
> -                               IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> -                               MMA9551_IRQ_NAME, indio_dev);
> +                                               NULL, mma9551_event_handler,
> +                                               irqflags,
> +                                               MMA9551_IRQ_NAME, indio_dev);
>                 if (ret < 0) {
>                         dev_err(dev, "request irq %d failed\n", data->irqs[i]);
>                         return ret;
>                 }
> -
> -               dev_dbg(dev, "gpio resource, no:%d irq:%d\n",
> -                       desc_to_gpio(gpio), data->irqs[i]);
>         }
>
>         return 0;
> --
> 2.31.1
>

  parent reply	other threads:[~2021-05-24  8:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 16:23 [PATCH 0/5] iio: accel: mma9551/mma9553 Cleanup and update Jonathan Cameron
2021-05-23 16:23 ` [PATCH 1/5] iio: accel: mma9551/mma9553: Drop explicit ACPI match support Jonathan Cameron
2021-05-23 19:17   ` Andy Shevchenko
2021-05-24  7:28   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 2/5] iio: accel: mma9551/mma9553: Simplify pm logic Jonathan Cameron
2021-05-24  7:33   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 3/5] iio: accel: mma9551: Add support to get irqs directly from fwnode Jonathan Cameron
2021-05-24  6:13   ` Andy Shevchenko
2021-05-24  9:27     ` Jonathan Cameron
2021-06-03 18:40       ` Jonathan Cameron
2021-05-24  8:16   ` Alexandru Ardelean [this message]
2021-05-23 16:23 ` [PATCH 4/5] iio: accel: mma9551: Use devm managed functions to tidy up probe() Jonathan Cameron
2021-05-24  8:13   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 5/5] iio: accel: mma9553: " Jonathan Cameron
2021-05-24  8:15   ` Alexandru Ardelean

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=CAASAkoY+gz0B9ig4napKdXmtTr74DXs_ONXnBmh9sghk1a6gxg@mail.gmail.com \
    --to=aardelean@deviqon.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /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.