From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Alex Soo <yuklin.soo@starfivetech.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
Hal Feng <hal.feng@starfivetech.com>,
Ley Foon Tan <leyfoon.tan@starfivetech.com>,
Jianlong Huang <jianlong.huang@starfivetech.com>,
Emil Renner Berthing <kernel@esmil.dk>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Drew Fustini <drew@beagleboard.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Subject: Re: [RFC PATCH v3 6/7] gpiolib: enable GPIO interrupt to wake up a system from sleep
Date: Mon, 6 May 2024 23:25:01 +0300 [thread overview]
Message-ID: <Zjk8nU562g3YxsVm@surfacebook.localdomain> (raw)
In-Reply-To: <20240503111436.113089-7-yuklin.soo@starfivetech.com>
Fri, May 03, 2024 at 07:14:35PM +0800, Alex Soo kirjoitti:
> Add function gpiochip_wakeup_irq_setup() to configure and enable a
> GPIO pin with interrupt wakeup capability according to user-defined
> wakeup-gpios property in the device tree. Interrupt generated by
> toggling the logic level (rising/falling edge) on the specified
> GPIO pin can wake up a system from sleep mode.
...
> +static irqreturn_t gpio_wake_irq_handler(int irq, void *data)
> +{
> + struct irq_data *irq_data = data;
> +
> + if (!irq_data || irq != irq_data->irq)
Hmm... When irq_data can be NULL?
> + return IRQ_NONE;
> +
> + return IRQ_HANDLED;
> +}
...
> +static int gpiochip_wakeup_irq_setup(struct gpio_chip *gc)
> +{
> + struct device *dev = gc->parent;
> + struct gpio_irq_chip *girq = &gc->irq;
> + struct gpio_desc *wakeup_gpiod;
> + struct irq_desc *wakeup_irqd;
> + struct irq_domain *irq_domain;
> + struct irq_data *irq_data;
> + unsigned int offset;
> + int wakeup_irq;
> + int ret;
> +
> + if (!(device_property_read_bool(dev, "wakeup-source")))
Too many parentheses.
> + return 0;
> +
> + irq_domain = girq->domain;
> +
Unneeded blank line. Ditto for all similar cases.
> + if (!irq_domain) {
> + dev_err(dev, "Couldn't allocate IRQ domain\n");
> + return -ENXIO;
return dev_err_probe(...);
Ditto for all similar cases.
> + }
...
> + wakeup_gpiod = devm_gpiod_get_optional(dev, "wakeup", GPIOD_IN);
> +
> + if (IS_ERR(wakeup_gpiod)) {
> + dev_err(dev, "invalid wakeup gpio: %lu\n", PTR_ERR(wakeup_gpiod));
> + return PTR_ERR(wakeup_gpiod);
> + }
> + if (!wakeup_gpiod) {
> + dev_dbg(dev, "property wakeup-gpios is not defined\n");
> + return 0;
> + }
> +
> + offset = gpio_chip_hwgpio(wakeup_gpiod);
> + wakeup_irq = gpiod_to_irq(wakeup_gpiod);
> + if (wakeup_irq < 0) {
> + dev_err(dev, "failed to convert wakeup GPIO to IRQ\n");
> + return wakeup_irq;
> + }
> + irq_domain->ops->map(irq_domain, wakeup_irq, offset);
> + wakeup_irqd = irq_to_desc(wakeup_irq);
> + irq_data = irq_get_irq_data(wakeup_irq);
What these lines are for?
> + girq->handler = handle_edge_irq;
> +
> + if (!(wakeup_irqd->status_use_accessors & IRQ_NOREQUEST)) {
> + device_init_wakeup(dev, 1);
> + ret = devm_request_threaded_irq(dev, wakeup_irq, NULL,
> + gpio_wake_irq_handler,
> + IRQF_TRIGGER_FALLING |
> + IRQF_TRIGGER_RISING |
What's wrong with the flags from DT?
> + IRQF_ONESHOT |
> + IRQF_SHARED,
> + "pm-wakeup-gpio", irq_data);
> + if (ret) {
> + dev_err(dev, "unable to request wakeup IRQ: %d\n", ret);
> + return ret;
> + }
> + }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2024-05-06 20:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 11:14 [RFC PATCH v3 0/7] Add Pinctrl driver for Starfive JH8100 SoC Alex Soo
2024-05-03 11:14 ` [RFC PATCH v3 1/7] dt-bindings: pinctrl: starfive: Add JH8100 pinctrl Alex Soo
2024-05-03 13:34 ` Rob Herring (Arm)
2024-05-03 16:07 ` Conor Dooley
2024-05-09 2:24 ` Yuklin Soo
2024-05-03 11:14 ` [RFC PATCH v3 2/7] pinctrl: starfive: jh8100: add main driver and sys_east domain sub-driver Alex Soo
2024-05-06 20:15 ` Andy Shevchenko
2024-05-03 11:14 ` [RFC PATCH v3 3/7] pinctrl: starfive: jh8100: add sys_west " Alex Soo
2024-05-03 11:14 ` [RFC PATCH v3 4/7] pinctrl: starfive: jh8100: add sys_gmac " Alex Soo
2024-05-03 11:14 ` [RFC PATCH v3 5/7] pinctrl: starfive: jh8100: add AON " Alex Soo
2024-05-03 11:14 ` [RFC PATCH v3 6/7] gpiolib: enable GPIO interrupt to wake up a system from sleep Alex Soo
2024-05-06 20:25 ` Andy Shevchenko [this message]
2024-05-27 12:31 ` Linus Walleij
2024-05-03 11:14 ` [RFC PATCH v3 7/7] riscv: dts: starfive: jh8100: add pinctrl device tree nodes Alex Soo
2024-05-06 6:35 ` [RFC PATCH v3 0/7] Add Pinctrl driver for Starfive JH8100 SoC Linus Walleij
2024-05-06 7:31 ` Leyfoon Tan
2024-05-06 12:09 ` Conor Dooley
2024-05-06 20:25 ` Andy Shevchenko
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=Zjk8nU562g3YxsVm@surfacebook.localdomain \
--to=andy.shevchenko@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=bartosz.golaszewski@linaro.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=drew@beagleboard.org \
--cc=hal.feng@starfivetech.com \
--cc=jianlong.huang@starfivetech.com \
--cc=kernel@esmil.dk \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=leyfoon.tan@starfivetech.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=yuklin.soo@starfivetech.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