Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Banajit Goswami <bgoswami@quicinc.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org,
	linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Subject: Re: [PATCH 2/4] reset: add GPIO-based reset controller
Date: Thu, 28 Dec 2023 11:05:41 -0500	[thread overview]
Message-ID: <530e3473-eb3b-477c-8599-e7aa12779640@seco.com> (raw)
In-Reply-To: <20231222150133.732662-3-krzysztof.kozlowski@linaro.org>

On 12/22/23 10:01, Krzysztof Kozlowski wrote:
> Add simple driver to control GPIO-based resets using the reset
> controller API for the cases when the GPIOs are shared and reset should
> be coordinated.  The driver is expected to be used by reset core
> framework for ad-hoc reset controllers.

How do we handle power sequencing? Often GPIOs need some pre/post delay in
order to ensure proper power sequencing. For regular reset drivers, this is
internal to the driver.

Maybe something like

my-device {
	reset-gpios = <&gpio 555 GPIO_ACTIVE_LOW>;
        reset-gpios-post-deassert-us = <100>;
};

Of course, this is a bit ambiguous if you have multiple devices using the same
GPIO with different delays. Maybe we take the max? But the driver below seems
to only have access to one device. Which I suppose begs the question: how do
we know when it's safe to deassert the reset (e.g. we've gotten to the point
where all devices using this reset gpio have gotten far enough to detect that
they use it)?

--Sean

> Cc: Bartosz Golaszewski <brgl@bgdev.pl>
> Cc: Sean Anderson <sean.anderson@seco.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  MAINTAINERS                |   5 ++
>  drivers/reset/Kconfig      |   9 ++++
>  drivers/reset/Makefile     |   1 +
>  drivers/reset/reset-gpio.c | 105 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 120 insertions(+)
>  create mode 100644 drivers/reset/reset-gpio.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 7fe27cd60e1b..a0fbd4814bc7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8866,6 +8866,11 @@ F:	Documentation/i2c/muxes/i2c-mux-gpio.rst
>  F:	drivers/i2c/muxes/i2c-mux-gpio.c
>  F:	include/linux/platform_data/i2c-mux-gpio.h
>  
> +GENERIC GPIO RESET DRIVER
> +M:	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> +S:	Maintained
> +F:	drivers/reset/reset-gpio.c
> +
>  GENERIC HDLC (WAN) DRIVERS
>  M:	Krzysztof Halasa <khc@pm.waw.pl>
>  S:	Maintained
> diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
> index ccd59ddd7610..bb1b5a326eb7 100644
> --- a/drivers/reset/Kconfig
> +++ b/drivers/reset/Kconfig
> @@ -66,6 +66,15 @@ config RESET_BRCMSTB_RESCAL
>  	  This enables the RESCAL reset controller for SATA, PCIe0, or PCIe1 on
>  	  BCM7216.
>  
> +config RESET_GPIO
> +	tristate "GPIO reset controller"
> +	help
> +	  This enables a generic reset controller for resets attached via
> +	  GPIOs.  Typically for OF platforms this driver expects "reset-gpios"
> +	  property.
> +
> +	  If compiled as module, it will be called reset-gpio.
> +
>  config RESET_HSDK
>  	bool "Synopsys HSDK Reset Driver"
>  	depends on HAS_IOMEM
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 8270da8a4baa..fd8b49fa46fc 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -11,6 +11,7 @@ obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
>  obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o
>  obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o
>  obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o
> +obj-$(CONFIG_RESET_GPIO) += reset-gpio.o
>  obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
>  obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
>  obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o
> diff --git a/drivers/reset/reset-gpio.c b/drivers/reset/reset-gpio.c
> new file mode 100644
> index 000000000000..6952996dbc9f
> --- /dev/null
> +++ b/drivers/reset/reset-gpio.c
> @@ -0,0 +1,105 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/gpio/consumer.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reset-controller.h>
> +
> +struct reset_gpio_priv {
> +	struct reset_controller_dev rc;
> +	struct gpio_desc *reset;
> +};
> +
> +static inline struct reset_gpio_priv
> +*rc_to_reset_gpio(struct reset_controller_dev *rc)
> +{
> +	return container_of(rc, struct reset_gpio_priv, rc);
> +}
> +
> +static int reset_gpio_assert(struct reset_controller_dev *rc, unsigned long id)
> +{
> +	struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
> +
> +	gpiod_set_value_cansleep(priv->reset, 1);
> +
> +	return 0;
> +}
> +
> +static int reset_gpio_deassert(struct reset_controller_dev *rc,
> +			       unsigned long id)
> +{
> +	struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
> +
> +	gpiod_set_value_cansleep(priv->reset, 0);
> +
> +	return 0;
> +}
> +
> +static int reset_gpio_status(struct reset_controller_dev *rc, unsigned long id)
> +{
> +	struct reset_gpio_priv *priv = rc_to_reset_gpio(rc);
> +
> +	return gpiod_get_value_cansleep(priv->reset);
> +}
> +
> +static const struct reset_control_ops reset_gpio_ops = {
> +	.assert = reset_gpio_assert,
> +	.deassert = reset_gpio_deassert,
> +	.status = reset_gpio_status,
> +};
> +
> +static int reset_gpio_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device_node **platdata = dev_get_platdata(dev);
> +	struct reset_gpio_priv *priv;
> +
> +	if (!platdata && !*platdata)
> +		return -EINVAL;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, &priv->rc);
> +	device_set_node(dev, of_fwnode_handle(*platdata));
> +
> +	/*
> +	 * Need to get non-exclusive because it is used in reset core as cookie
> +	 * to find existing controllers.  However the actual use is exclusive.
> +	 */
> +	priv->reset = devm_gpiod_get(dev, "reset",
> +				     GPIOD_OUT_HIGH);
> +	if (IS_ERR(priv->reset))
> +		return dev_err_probe(dev, PTR_ERR(priv->reset),
> +				     "Could not get reset gpios\n");
> +
> +	priv->rc.ops = &reset_gpio_ops;
> +	priv->rc.owner = THIS_MODULE;
> +	priv->rc.dev = dev;
> +	priv->rc.cookie = priv->reset;
> +	priv->rc.nr_resets = 1;
> +
> +	return devm_reset_controller_register(dev, &priv->rc);
> +}
> +
> +static const struct platform_device_id reset_gpio_ids[] = {
> +	{ .name = "reset-gpio", },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(platform, reset_gpio_ids);
> +
> +static struct platform_driver reset_gpio_driver = {
> +	.probe		= reset_gpio_probe,
> +	.id_table	= reset_gpio_ids,
> +	.driver	= {
> +		.name = "reset-gpio",
> +	},
> +};
> +module_platform_driver(reset_gpio_driver);
> +
> +MODULE_AUTHOR("Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>");
> +MODULE_DESCRIPTION("Generic GPIO reset driver");
> +MODULE_LICENSE("GPL");


  parent reply	other threads:[~2023-12-28 16:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22 15:01 [PATCH 0/4] reset: gpio: ASoC: shared GPIO resets Krzysztof Kozlowski
2023-12-22 15:01 ` [PATCH 1/4] reset: instantiate reset GPIO controller for shared reset-gpios Krzysztof Kozlowski
2023-12-22 17:31   ` Bartosz Golaszewski
2023-12-27 12:35     ` Krzysztof Kozlowski
2023-12-27 19:13       ` Bartosz Golaszewski
2023-12-22 15:01 ` [PATCH 2/4] reset: add GPIO-based reset controller Krzysztof Kozlowski
2023-12-22 15:08   ` Krzysztof Kozlowski
2023-12-28 16:05   ` Sean Anderson [this message]
2024-01-04  8:57     ` Krzysztof Kozlowski
2024-01-04 16:04       ` Sean Anderson
2024-01-04 16:08         ` Krzysztof Kozlowski
2024-01-04 16:30           ` Sean Anderson
2024-01-04 19:08             ` Krzysztof Kozlowski
2024-01-05 14:31               ` Philipp Zabel
2024-01-09  9:41                 ` Krzysztof Kozlowski
2024-01-09 15:51                   ` Sean Anderson
2024-01-05 14:33               ` Mark Brown
2024-01-06 15:32                 ` Krzysztof Kozlowski
2024-01-04 16:11         ` Krzysztof Kozlowski
2023-12-22 15:01 ` [PATCH 3/4] ASoC: dt-bindings: qcom,wsa8840: Add reset-gpios for shared line Krzysztof Kozlowski
2023-12-22 15:16   ` Krzysztof Kozlowski
2023-12-22 16:18   ` Rob Herring
2023-12-22 15:01 ` [PATCH 4/4] ASoC: codecs: wsa884x: Allow sharing reset GPIO Krzysztof Kozlowski
2023-12-22 15:22   ` Krzysztof Kozlowski
2023-12-22 15:09 ` [PATCH 0/4] reset: gpio: ASoC: shared GPIO resets Krzysztof Kozlowski
2023-12-22 15:18 ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2024-02-29 17:26 [PATCH 2/4] reset: add GPIO-based reset controller Tim Harvey
2024-02-29 17:45 ` Krzysztof Kozlowski

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=530e3473-eb3b-477c-8599-e7aa12779640@seco.com \
    --to=sean.anderson@seco.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andersson@kernel.org \
    --cc=bgoswami@quicinc.com \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.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