Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp331485rdb; Mon, 29 Jan 2024 03:54:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOyTHX1yB7Ro3j4anvNReyDxhJwGjdUDUyUbIaWYWlqPKMbIUJilJWYayb9qC9J1eXsb1S X-Received: by 2002:a05:6a20:491b:b0:19c:9e7d:3f4e with SMTP id ft27-20020a056a20491b00b0019c9e7d3f4emr3907816pzb.1.1706529255436; Mon, 29 Jan 2024 03:54:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706529255; cv=pass; d=google.com; s=arc-20160816; b=RwsK5b2+q3uz2mebyKeREFLgW4fuFivrYay+akgUmU/oKZHm/USExt/Z3WUidBROTj gHgw1xVBWRraAhaRx2TRAneCumkHjlXLu9G0lIjRMvh7HJl2xrg8kkFiUPHLe7z1Gz1E JMsm4FTMona/cDA/FduHX75wVheW4vUXJtGsbsOqNgsmbMolAiAdpcXegwxoThI1FN8Y +X9rmbijtfPafmUfh1v8rjLaP8UmpdBOJ6xrM2rC/Jt9NOpWHe27Y7PcMvaXHsRmVGvW fZ9hx0xnCNWF9uTb1s8UIMAMF36NJRhi5+jVN0x+JJGAMBMTE8j+AP+Ese8340woW6AV dPuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xRfi7bENx/I9rSbdoOaYxClTFMvpbeifXHCV8MulR38=; fh=Bo7Hfhe8vKTO1PFfP+diH6nw8xfU2ThR5fq+auBM6tw=; b=NJmnqB/w+ap7gT6HqlpiXJ0XiGL2ENJsqOCcikWTjhvz8xDYnLwxx/4iDnRuY/kOVn NjKVyM1kN4EgQae1HG0RdBlrekGHY7qqMHG+GWhSPWuIpjNIgPCmbKMmgZ+4H1Bx0JuY NxOcObN383ZHh1PnfOAp8rn7xxEDC8Kc1PaBlCKQDX0c1mRguPJukqLDlSmZOwtdnQRP hUNhbdLorxjOMuErDPLJB6TNUWksaWxo1GgdAmgqLIR5Tc+pIAuaeNjk01bUhIOwbBfs s10dCXqdqqRudrevaeu/jR5mZ00h6dLsOY87w3n8iI39rNlxWJFyP0nEFK+11Vo74CVT S0Fg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SIZXnAv6; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-42641-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42641-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s191-20020a632cc8000000b005cda6105077si5448981pgs.299.2024.01.29.03.54.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:54:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42641-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=@linaro.org header.s=google header.b=SIZXnAv6; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-42641-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42641-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 30AFD286B2C for ; Mon, 29 Jan 2024 11:53:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 180A8605C6; Mon, 29 Jan 2024 11:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SIZXnAv6" Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 E0B1A604DB for ; Mon, 29 Jan 2024 11:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706529151; cv=none; b=SsI8rw5PuiBOc7syuVQye/Af6npgG488Oa2gGQ1z6uZ9RSouOjS4UegrCVVJPj2u1J99+M8tFhM09cL369UhudP108+ncHcS+O4XMnyGGkq49BB2dJO+pZg7Vq8jQh/3oZQjzVnuW2lmiuvXyCeOxLjT1Snd+FO4SK5x55O0UlM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706529151; c=relaxed/simple; bh=S2rlUFR7COiCXocSNwYdxys7hBLM3PNkPdINVgzUk+A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MxQKm5mbm26ObqCmyjHMQLDyDiDlSrhxsrguRIMwCiynj3tUZDOfb0nrJOeBr+RI1AxpmfIXIjHJ6uXy96phfxLOfPwVO9P0cIpW2XhvNBrhzYAjRvcVj595v7krBEG85ZJK3o+ks3D0zVTCFRoE+2laIxP4U0FDrumYyXTvkU4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=SIZXnAv6; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2cf4a22e10dso28758221fa.3 for ; Mon, 29 Jan 2024 03:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706529147; x=1707133947; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xRfi7bENx/I9rSbdoOaYxClTFMvpbeifXHCV8MulR38=; b=SIZXnAv6OxaK2ilNUBqeIfoDnW9RlK3G2azGdYkQaraxM9+K5sn32IfIpULHDLcMZv ajlZvwPE/rLvSamQF8eZSsHQ6CF/r56oPNZWMXuyi6/DMnOWvb8TKX87wm6HtYVuia8J rrYPrNuF2hF8cDxkNBwIBZFN8NJ1xrmxNi7G6Gc6RPPEFA8l+d5BURMTesTMzh+lx8j7 rpVQOV6MTNnk3Y0RQ+XxvtgFYqA+np6FUA8vYFWNU7Hym0ytFAU9VIV7L5nsXLBASont L0pSx4XG0FFXs+V1wFFsq9XP4bPVoKH8JAzYZ28eqh3GnHFH11i7e7WEW52xGNfxXBCY ZPxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706529147; x=1707133947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xRfi7bENx/I9rSbdoOaYxClTFMvpbeifXHCV8MulR38=; b=WHYRZUOsrNvHIGKytYTsi1rA3liyzvL6wkTJfU4FQMlBGIo49EICc2ARcpWQPNa2mc raRxk0EYilPkpfxwlhyj7dIv4pLUDWplVyOVrhI3xBBVo8z/QoL7KrQm1ek8iQFKgMgS WfPOU9IDkhx8hKfPqw5JX9S+EIb4O0ucfs3YbaW+NxbIiGiz/dRnUkqACTbxAboy4K8m pn0DZyTy3ejq7OQUoOq2HtnU5fQWS+9ITivAOYBSj4H8eVE+W2pfRJNiHYwrYeI39tH6 DYsS0hM1SPAx55rttU3SsLlsFOmMsFMmDxUn9hMwNk/lZlrMAJWtk8cC9m6f+t95SGX0 ssqQ== X-Gm-Message-State: AOJu0YzokXzEpQGc1n35xuXEy3vyPEdJvlgFq/NzkwHwYrqyHePfS3X+ ttubiYR0j0kIpCXGS1o32DhotZ1PZXKrADoHLkniXM8UPE406jQ2hoUWpxs2VeU= X-Received: by 2002:a2e:be11:0:b0:2d0:4c41:695 with SMTP id z17-20020a2ebe11000000b002d04c410695mr1588148ljq.37.1706529147037; Mon, 29 Jan 2024 03:52:27 -0800 (PST) Received: from krzk-bin.. ([178.197.222.62]) by smtp.gmail.com with ESMTPSA id ec19-20020a0564020d5300b0055f29ececeasm19907edb.57.2024.01.29.03.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:52:26 -0800 (PST) From: Krzysztof Kozlowski To: Srinivas Kandagatla , Banajit Goswami , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , "Rafael J. Wysocki" , Viresh Kumar , Frank Rowand , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Chris Packham , Sean Anderson , Bartosz Golaszewski Subject: [PATCH v6 3/6] reset: gpio: Add GPIO-based reset controller Date: Mon, 29 Jan 2024 12:52:13 +0100 Message-Id: <20240129115216.96479-4-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240129115216.96479-1-krzysztof.kozlowski@linaro.org> References: <20240129115216.96479-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Bartosz Golaszewski Reviewed-by: Philipp Zabel Signed-off-by: Krzysztof Kozlowski --- MAINTAINERS | 5 ++ drivers/reset/Kconfig | 9 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-gpio.c | 119 +++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 drivers/reset/reset-gpio.c diff --git a/MAINTAINERS b/MAINTAINERS index ddc5e1049921..91d45c6bade7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8905,6 +8905,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 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..2290b25b6703 --- /dev/null +++ b/drivers/reset/reset-gpio.c @@ -0,0 +1,119 @@ +// 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 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_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 = &pdev->dev; + struct of_phandle_args *platdata = dev_get_platdata(dev); + struct reset_gpio_priv *priv; + int ret; + + if (!platdata) + return -EINVAL; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, &priv->rc); + + 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.of_args = platdata; + ret = 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 = 2; + priv->rc.of_xlate = reset_gpio_of_xlate; + 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 "); +MODULE_DESCRIPTION("Generic GPIO reset driver"); +MODULE_LICENSE("GPL"); -- 2.34.1