Devicetree
 help / color / mirror / Atom feed
From: Rodolfo Giometti <giometti@enneenne.com>
To: Eliav Farber <farbere@amazon.com>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Fabio Estevam <festevam@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	devicetree@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] pps: clients: gpio: release pins to an inactive state on remove and shutdown
Date: Thu, 17 Sep 2026 09:14:03 +0200	[thread overview]
Message-ID: <1b25ba28-c53e-4425-8165-8205eab60e22@enneenne.com> (raw)
In-Reply-To: <20260916182641.9768-3-farbere@amazon.com>

On 16/09/2026 20:26, Eliav Farber wrote:
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index 73ec2c7335e5..e619c7bb2f78 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -17,6 +17,7 @@
>  #include <linux/slab.h>
>  #include <linux/pps_kernel.h>
>  #include <linux/gpio/consumer.h>
> +#include <linux/pinctrl/consumer.h>
>  #include <linux/list.h>
>  #include <linux/property.h>
>  #include <linux/timer.h>
> @@ -30,6 +31,8 @@ struct pps_gpio_device_data {
>  	struct gpio_desc *gpio_pin;	/* GPIO port descriptors */
>  	struct gpio_desc *echo_pin;
>  	struct timer_list echo_timer;	/* timer to reset echo active state */
> +	struct pinctrl *pinctrl;	/* pin control handle */
> +	struct pinctrl_state *pins_inactive;	/* pins released when unbound */
>  	bool assert_falling_edge;
>  	unsigned int echo_active_ms;	/* PPS echo active duration */
>  	unsigned long echo_timeout;	/* timer timeout value in jiffies */
> @@ -96,6 +99,51 @@ static void pps_gpio_echo_timer_callback(struct timer_list *t)
>  	gpiod_set_value(info->echo_pin, 0);
>  }
>  
> +/*
> + * Look up the optional "inactive" pinctrl state: the mux to restore when
> + * pps-gpio is unbound or the system is shut down. It is only meaningful
> + * paired with a "default" state, which the driver core applies before probe
> + * to mux the pins for PPS use. A board that describes neither is unaffected;
> + * one that describes "inactive" without "default" is rejected, since
> + * releasing pins that were never put into a defined PPS state is incoherent.
> + */
> +static int pps_gpio_get_pins(struct device *dev)
> +{
> +	struct pps_gpio_device_data *data = dev_get_drvdata(dev);
> +	struct pinctrl_state *pins_default;
> +
> +	data->pinctrl = devm_pinctrl_get(dev);
> +	if (IS_ERR(data->pinctrl))
> +		return dev_err_probe(dev, PTR_ERR(data->pinctrl),
> +				     "failed to get pinctrl\n");
> +
> +	/* The "inactive" state is optional; without it there is nothing to do. */
> +	data->pins_inactive = pinctrl_lookup_state(data->pinctrl, "inactive");
> +	if (IS_ERR(data->pins_inactive)) {
> +		data->pins_inactive = NULL;
> +		return 0;
> +	}
> +
> +	/* "inactive" requires a "default" state to release back from. */
> +	pins_default = pinctrl_lookup_state(data->pinctrl, "default");
> +	if (IS_ERR(pins_default))
> +		return dev_err_probe(dev, PTR_ERR(pins_default),
> +				     "\"inactive\" pinctrl state requires a \"default\" state\n");
> +
> +	return 0;
> +}

pinctrl_dt_to_map() returns -ENODEV when the node has no pinctrl-0 and
create_pinctrl() forwards it. So this fails the probe on every pps-gpio
board that describes no pinctrl at all, which is most of them; your
setup has one, so the test does not show it. Shouldn't -ENODEV simply
mean "no pinctrl here, nothing to do"?

> +
> +/*
> + * Release the pins to their "inactive" state, if the board describes one, so
> + * they are handed back to whatever function uses them while pps-gpio is not
> + * driving PPS. Boards without an "inactive" state are unaffected.
> + */
> +static void pps_gpio_release_pins(struct pps_gpio_device_data *data)
> +{
> +	if (data->pins_inactive)
> +		pinctrl_select_state(data->pinctrl, data->pins_inactive);
> +}

The return value is the only sign that the mux was not restored, which
is what the whole series is for. Why drop it?

> +
>  static int pps_gpio_setup(struct device *dev)
>  {
>  	struct pps_gpio_device_data *data = dev_get_drvdata(dev);
> @@ -161,6 +209,11 @@ static int pps_gpio_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	/* pinctrl setup (optional states) */
> +	ret = pps_gpio_get_pins(dev);
> +	if (ret)
> +		return ret;
> +
>  	/* IRQ setup */
>  	ret = gpiod_to_irq(data->gpio_pin);
>  	if (ret < 0) {
> @@ -216,9 +269,30 @@ static void pps_gpio_remove(struct platform_device *pdev)
>  	timer_delete_sync(&data->echo_timer);
>  	/* reset echo pin in any case */
>  	gpiod_set_value(data->echo_pin, 0);
> +	/* release the pins last, once nothing can drive them anymore */
> +	pps_gpio_release_pins(data);
>  	dev_info(&pdev->dev, "removed IRQ %d as PPS source\n", data->irq);
>  }
>  
> +static void pps_gpio_shutdown(struct platform_device *pdev)
> +{
> +	struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
> +
> +	/*
> +	 * Quiesce the hardware before touching the mux: stop the IRQ and the
> +	 * echo timer first so nothing can drive the pins, then hand them back
> +	 * to their "inactive" function. The kernel keeps running after
> +	 * device_shutdown() (for example to load and start a kexec image), so
> +	 * the pins must not be released while an IRQ or timer callback can
> +	 * still reach them. The PPS source is left registered; unregistering
> +	 * it is a remove-time concern and is unnecessary on shutdown.
> +	 */
> +	free_irq(data->irq, data);
> +	timer_delete_sync(&data->echo_timer);
> +	gpiod_set_value(data->echo_pin, 0);
> +	pps_gpio_release_pins(data);
> +}
> +
>  static const struct of_device_id pps_gpio_dt_ids[] = {
>  	{ .compatible = "pps-gpio", },
>  	{ /* sentinel */ }
> @@ -228,6 +302,7 @@ MODULE_DEVICE_TABLE(of, pps_gpio_dt_ids);
>  static struct platform_driver pps_gpio_driver = {
>  	.probe		= pps_gpio_probe,
>  	.remove		= pps_gpio_remove,
> +	.shutdown	= pps_gpio_shutdown,
>  	.driver		= {
>  		.name	= PPS_GPIO_NAME,
>  		.of_match_table	= pps_gpio_dt_ids,

Ciao,

Rodolfo

  parent reply	other threads:[~2026-09-17  7:17 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 13:47 [PATCH 0/2] pps-gpio: restore pin mux on unbind and shutdown Eliav Farber
2026-09-16 13:47 ` [PATCH 1/2] dt-bindings: pps: pps-gpio: document optional idle pinctrl state Eliav Farber
2026-09-16 13:47 ` [PATCH 2/2] pps: clients: gpio: release pins to idle state on remove and shutdown Eliav Farber
2026-09-16 13:57   ` sashiko-bot
2026-09-16 16:48 ` [PATCH 0/2] pps-gpio: restore pin mux on unbind " Rodolfo Giometti
2026-09-16 18:25   ` Farber, Eliav
2026-09-16 18:26 ` [PATCH v2 " Eliav Farber
2026-09-16 18:26   ` [PATCH v2 1/2] dt-bindings: pps: pps-gpio: document optional pinctrl states Eliav Farber
2026-09-17  7:13     ` Rodolfo Giometti
2026-09-17  7:48       ` Farber, Eliav
2026-09-16 18:26   ` [PATCH v2 2/2] pps: clients: gpio: release pins to an inactive state on remove and shutdown Eliav Farber
2026-09-16 18:43     ` sashiko-bot
2026-09-17  7:14     ` Rodolfo Giometti [this message]
2026-09-17  7:52       ` Farber, Eliav
2026-09-17  7:56   ` [PATCH v3 0/3] pps-gpio: restore pin mux on unbind " Eliav Farber
2026-09-17  7:56     ` [PATCH v3 1/3] pps: clients: gpio: propagate probe error codes Eliav Farber
2026-09-17  8:04       ` sashiko-bot
2026-09-17  9:58       ` Bartosz Golaszewski
2026-09-18  7:50       ` Rodolfo Giometti
2026-09-17  7:56     ` [PATCH v3 2/3] dt-bindings: pps: pps-gpio: document optional pinctrl states Eliav Farber
2026-09-17 15:35       ` Rob Herring (Arm)
2026-09-17 16:13       ` Rob Herring
2026-09-18  7:50       ` Rodolfo Giometti
2026-09-18 15:43         ` Rob Herring
2026-09-17  7:56     ` [PATCH v3 3/3] pps: clients: gpio: release pins to an inactive state on remove and shutdown Eliav Farber
2026-09-17  8:10       ` sashiko-bot
2026-09-19 17:11     ` [PATCH v4 0/3] pps-gpio: restore pin mux on unbind " Eliav Farber
2026-09-22  7:40       ` Rodolfo Giometti
2026-09-22 10:08         ` Farber, Eliav
2026-09-22 10:30       ` [PATCH v5 0/4] " Eliav Farber
2026-09-22 10:30         ` [PATCH v5 1/4] pps: clients: gpio: propagate probe error codes Eliav Farber
2026-09-22 10:30         ` [PATCH v5 2/4] pps: clients: gpio: only tear down the echo timer when it exists Eliav Farber
2026-09-22 10:30         ` [PATCH v5 3/4] dt-bindings: pps: pps-gpio: document optional pinctrl states Eliav Farber
2026-09-22 12:46           ` Rodolfo Giometti
2026-09-23 12:36             ` Rob Herring
2026-09-23 13:13               ` Farber, Eliav
2026-09-23 18:04                 ` Rob Herring
2026-09-22 10:30         ` [PATCH v5 4/4] pps: clients: gpio: release pins to an inactive state on remove and shutdown Eliav Farber
2026-09-22 10:39           ` sashiko-bot
2026-09-22 12:46           ` Rodolfo Giometti
2026-09-22 14:55             ` Farber, Eliav
2026-09-23  7:50               ` Rodolfo Giometti
2026-09-23 18:22         ` [PATCH v6 0/4] pps-gpio: restore pin mux on unbind " Eliav Farber
2026-09-23 18:22           ` [PATCH v6 1/4] pps: clients: gpio: propagate probe error codes Eliav Farber
2026-09-24 12:58             ` Rodolfo Giometti
2026-09-24 14:46             ` Bartosz Golaszewski
2026-09-23 18:22           ` [PATCH v6 2/4] pps: clients: gpio: only tear down the echo timer when it exists Eliav Farber
2026-09-24 12:59             ` Rodolfo Giometti
2026-09-24 14:47             ` Bartosz Golaszewski
2026-09-23 18:22           ` [PATCH v6 3/4] dt-bindings: pps: pps-gpio: document optional pinctrl states Eliav Farber
2026-09-23 18:41             ` Rob Herring
2026-09-24 12:59             ` Rodolfo Giometti
2026-09-23 18:22           ` [PATCH v6 4/4] pps: clients: gpio: release pins to an inactive state on remove and shutdown Eliav Farber
2026-09-24 12:59             ` Rodolfo Giometti
2026-10-01  7:53             ` Linus Walleij
2026-09-24 12:58           ` [PATCH v6 0/4] pps-gpio: restore pin mux on unbind " Rodolfo Giometti
2026-09-19 17:11     ` [PATCH v4 1/3] pps: clients: gpio: propagate probe error codes Eliav Farber
2026-09-22  7:40       ` Rodolfo Giometti
2026-09-22  8:08         ` Farber, Eliav
2026-09-22  8:22           ` Rodolfo Giometti
2026-09-22 10:06             ` Farber, Eliav
2026-09-19 17:11     ` [PATCH v4 2/3] dt-bindings: pps: pps-gpio: document optional pinctrl states Eliav Farber
2026-09-22  7:40       ` Rodolfo Giometti
2026-09-22 10:11         ` Farber, Eliav
2026-09-19 17:11     ` [PATCH v4 3/3] pps: clients: gpio: release pins to an inactive state on remove and shutdown Eliav Farber
2026-09-22  7:40       ` Rodolfo Giometti
2026-09-22 10:13         ` Farber, Eliav

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=1b25ba28-c53e-4425-8165-8205eab60e22@enneenne.com \
    --to=giometti@enneenne.com \
    --cc=akpm@linux-foundation.org \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=farbere@amazon.com \
    --cc=festevam@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox