Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp576321rdb; Mon, 15 Jan 2024 06:50:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNKO7IAbgR5aCyLBnogh9IO1D/9X08mhNG9uh1tqbn29qQABwGKtvTk+Y9ObkaKTPGvmwM X-Received: by 2002:a05:6a21:164e:b0:19b:2037:a80c with SMTP id no14-20020a056a21164e00b0019b2037a80cmr369612pzb.98.1705330255810; Mon, 15 Jan 2024 06:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330255; cv=none; d=google.com; s=arc-20160816; b=g4zG2WdbcNJFvbW3c3wyXb0mXuf4lybJ0YZhUkuAa9VBsJxZlCvHGfzYnqkYhZOjm3 lgF29LSAwZF+eAM1KFH0nTzW6CKD0gZ/9uPlfXR2U4eHYN5yxawIXoOT6yzBoRW8Bj46 cHiaa57lfAjx8JFJgeJMu7z+rkQIy4VBgE/16Rj4eN+PYVxtHO63aChSdLWguh8hwRxb m24MimB59AkDTgYD8E7E/6FL0qeBCjSISja5LkSHqypQ9q8CZLnBqfdbH8m0rIyw2hPA JcV19LMtofwWw+ijfV7lppk3+ieN6wBM6e+Xz5jnESNx+hiPFbB9fxCwryxC3p2pfhvH sSRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=SuVawFO9EzN+TBa58xh+36pumfMhcFBvr33I0w01EEI=; fh=GCOForHZEEAuOhKtgdQmAXVzAmv0DCsAhoojApZ25Kg=; b=U3/ubiQMQ3588n8xl1iCPSC9JbHh/SXSuXtMnvjnq3fHKUVu5gdpcNf8CH8Hc5QQDL FPDuCj0Xdt8LLIexa3RlGvQhcxheAykjuALXvZjsVQu3oeNbpTExGt4iopYrYM8ZtntD Fnd2V6n5WEEbpABOyzWCCXlcL6HqcZU97RTTw9zoJS2S2kNW3g9PiPUidLhUbJb3lD6h BtioxyW03DIw1RRbb8Txk2GWQrPAqcMb7QrQVd3QiRDrCNmA2Opp1mGT2bc3av3UiZe+ xbytzrYJpbjqt1TjGySwIK7RaRXAlqRULlbPT2hdAApTmac3/42oFh68wmCHC8O/yJ16 VW6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=xbDeizeT; spf=pass (google.com: domain of linux-kernel+bounces-26121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26121-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s16-20020a056a00195000b006d9bdf9dce5si9181106pfk.230.2024.01.15.06.50.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:50:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=xbDeizeT; spf=pass (google.com: domain of linux-kernel+bounces-26121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26121-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 21FAA2835EB for ; Mon, 15 Jan 2024 14:45:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB20A1759D; Mon, 15 Jan 2024 14:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="xbDeizeT" Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E545717BA5 for ; Mon, 15 Jan 2024 14:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-4670a58b118so1675683137.2 for ; Mon, 15 Jan 2024 06:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1705329907; x=1705934707; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SuVawFO9EzN+TBa58xh+36pumfMhcFBvr33I0w01EEI=; b=xbDeizeTFR77qfQn/4lgShIRjYHatOyt6iUD7GFqJq1Kb429l94pL+i6xSU7O3wLRr 8vEoXgcy7rpzFD6GlFdgB7cBSt41PXrbW2wgZTL5ZnkbO7df6MMMVWbcDTwjk9CpeqMe ELtInBdOY2+ctmHd2/e9cWRwqZwIDGhdh2LFlmyiPfXpGvUfOYpRGqSZzK3nDQnzP4G0 /1ACvPUBEnSkxzt5jnf0vnGceoGVlgsolRoPoBGlN45iFpUoDr3oGYE7vB/7RZD+OzYF qOxnfFgtyIU8ZT4EW98+gqsUiVt+T+WxOBxUHUQ5D6rfy4UWPgOfMQbBUal0i1nboRGU tgsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705329907; x=1705934707; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SuVawFO9EzN+TBa58xh+36pumfMhcFBvr33I0w01EEI=; b=O+GaJ5DRlnt7LVvgstO6BH123NGI7mtJ37fxQtId16FGiocfXmSdHH0LNilNNCQZLq C7W4uN+vD+ojFMW1+sdB3tWpi6gqfWVCOdT6o2ap4Ti8muZVhsqAO/ZrJxL3Jb5vywej OFjvO7q+/ZbnLjzZkYwWvFhWCL8u9Dpm0Dseje2AqZsM0GTC2k1pewMIsJ1uoyWkXVNY l0zjAC9JVUJt5gZPoreB2z0Nknw0JUt4ZvQWlcYboEgCsgf7TVfYlYdwmmsBsZd3i4HR szueBJgZKFwsspVQWry8ERiS+ogzZkRVWRu9yCt3XOPfCga6WmYmxF+JS9RkDRSQDZRp 7teA== X-Gm-Message-State: AOJu0YzjImEm+qOfmNYza9TJkFM5HFY5SzxXpewDD2ENkY7CeKUGoZM5 YkNVKABKXxmo/Fh7TEr5dWsOvXXxKcdidwCbs1ZHueFR4Rv23w== X-Received: by 2002:a67:ed0e:0:b0:467:ac23:3ca2 with SMTP id l14-20020a67ed0e000000b00467ac233ca2mr3160044vsp.8.1705329906237; Mon, 15 Jan 2024 06:45:06 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> <20240112163608.528453-2-krzysztof.kozlowski@linaro.org> In-Reply-To: <20240112163608.528453-2-krzysztof.kozlowski@linaro.org> From: Bartosz Golaszewski Date: Mon, 15 Jan 2024 15:44:55 +0100 Message-ID: Subject: Re: [PATCH v3 1/5] reset: gpio: Add GPIO-based reset controller To: Krzysztof Kozlowski Cc: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , Jaroslav Kysela , Takashi Iwai , 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, linux-i2c@vger.kernel.org, Chris Packham , Sean Anderson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 12, 2024 at 5:36=E2=80=AFPM Krzysztof Kozlowski wrote: > > Add a 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. > > Cc: Bartosz Golaszewski > Cc: Chris Packham > Cc: Sean Anderson > Signed-off-by: Krzysztof Kozlowski > --- > MAINTAINERS | 5 ++ > drivers/reset/Kconfig | 9 +++ > drivers/reset/Makefile | 1 + > drivers/reset/reset-gpio.c | 121 +++++++++++++++++++++++++++++++++++++ > 4 files changed, 136 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 > +S: Maintained > +F: drivers/reset/reset-gpio.c > + > GENERIC HDLC (WAN) DRIVERS > M: Krzysztof Halasa > 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 PC= Ie1 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-g= pios" > + 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) +=3D reset-bcm6345.o > obj-$(CONFIG_RESET_BERLIN) +=3D reset-berlin.o > obj-$(CONFIG_RESET_BRCMSTB) +=3D reset-brcmstb.o > obj-$(CONFIG_RESET_BRCMSTB_RESCAL) +=3D reset-brcmstb-rescal.o > +obj-$(CONFIG_RESET_GPIO) +=3D reset-gpio.o > obj-$(CONFIG_RESET_HSDK) +=3D reset-hsdk.o > obj-$(CONFIG_RESET_IMX7) +=3D reset-imx7.o > obj-$(CONFIG_RESET_INTEL_GW) +=3D reset-intel-gw.o > diff --git a/drivers/reset/reset-gpio.c b/drivers/reset/reset-gpio.c > new file mode 100644 > index 000000000000..0fe482740f1b > --- /dev/null > +++ b/drivers/reset/reset-gpio.c > @@ -0,0 +1,121 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +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 l= ong id) > +{ > + struct reset_gpio_priv *priv =3D 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 =3D 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 l= ong id) > +{ > + struct reset_gpio_priv *priv =3D rc_to_reset_gpio(rc); > + > + return gpiod_get_value_cansleep(priv->reset); > +} > + > +static const struct reset_control_ops reset_gpio_ops =3D { > + .assert =3D reset_gpio_assert, > + .deassert =3D reset_gpio_deassert, > + .status =3D reset_gpio_status, > +}; > + > +static int reset_gpio_of_xlate(struct reset_controller_dev *rcdev, > + const struct of_phandle_args *reset_spec) > +{ > + return reset_spec->args[0]; > +} > + > +static void reset_gpio_of_node_put(void *data) > +{ > + of_node_put(data); > +} > + > +static int reset_gpio_probe(struct platform_device *pdev) > +{ > + struct device *dev =3D &pdev->dev; > + struct of_phandle_args *platdata =3D dev_get_platdata(dev); > + struct reset_gpio_priv *priv; > + int ret; > + > + if (!platdata) > + return -EINVAL; > + > + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, &priv->rc); > + > + /* Relies on GPIO_LOOKUP */ That doesn't mean anything. The GPIO abstraction is there to hide *how* the GPIO is assigned to the device. This relies on regular GPIO infrastructure common to all drivers. If at some point this gets an OF compatible or is instantiated from ACPI or otherwise, the same code will still work and not rely on "GPIO_LOOKUP"). > + priv->reset =3D 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 =3D &reset_gpio_ops; > + priv->rc.owner =3D THIS_MODULE; > + priv->rc.dev =3D dev; > + priv->rc.of_args =3D platdata; > + priv->rc.of_node =3D of_node_get(platdata->np); > + ret =3D devm_add_action_or_reset(dev, reset_gpio_of_node_put, > + priv->rc.of_node); > + if (ret) > + return ret; > + > + /* Cells to match GPIO specifier, but it's not really used */ > + priv->rc.of_reset_n_cells =3D 2; > + priv->rc.of_xlate =3D reset_gpio_of_xlate; > + priv->rc.nr_resets =3D 1; > + > + return devm_reset_controller_register(dev, &priv->rc); > +} > + > +static const struct platform_device_id reset_gpio_ids[] =3D { > + { .name =3D "reset-gpio", }, > + {} > +}; > +MODULE_DEVICE_TABLE(platform, reset_gpio_ids); > + > +static struct platform_driver reset_gpio_driver =3D { > + .probe =3D reset_gpio_probe, > + .id_table =3D reset_gpio_ids, > + .driver =3D { > + .name =3D "reset-gpio", > + }, > +}; > +module_platform_driver(reset_gpio_driver); > + > +MODULE_AUTHOR("Krzysztof Kozlowski "); > +MODULE_DESCRIPTION("Generic GPIO reset driver"); > +MODULE_LICENSE("GPL"); > -- > 2.34.1 > With the above dropped: Reviewed-by: Bartosz Golaszewski