From patchwork Fri Jan 5 15:59:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 185436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6308358dyb; Fri, 5 Jan 2024 08:00:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHijnfuvKXarnHAqWtWI31NIXEI/dimJ54rejAtHRLfbfoSn2tBc62171RvJfW/DcgHP4zE X-Received: by 2002:a50:ab12:0:b0:54c:a432:4e8 with SMTP id s18-20020a50ab12000000b0054ca43204e8mr1384172edc.35.1704470424654; Fri, 05 Jan 2024 08:00:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704470424; cv=none; d=google.com; s=arc-20160816; b=UgV9SZ7FfSaeDFziCR+T6ZrI9qInL/gIl1hOQiODTvLs2gdEX6IZdODcKIiBm+N5ec nr3ZgJ8mzvahdsVqKmkWRObRPVYkDI4ZReT4gdk2hMNYnW4iHYIzbfAf+JBZX1riA3p9 DYiff1hBkPqXHBvwSXNSLVR2sZbY/nmMmk3+LRqlaKVgzjrWtdzIR5x9SnZD7+P7n9t6 ce66F5WMdmkf2BaiIeHhQ+hHN2GpTC3ZTHj4vpI6+B14fvbjuiWL4MxfQQFQYrPyUTeU 09QB0XwREAya2MZYt5nQLUcOpVQPfpi7lDIznkuI3ZYWgABjUxN5n0ljQVR3mNaDJ2/r qPqg== ARC-Message-Signature: i=1; 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=TDuMrijv2n4yWr4gr0fXQfwtgxk4DAsUrjH6HhYvL7U=; fh=iJvz1+kl97MC+qFV9naLRWeJcJKNAc5zkQmU9UfpBXI=; b=xb4m6faJCF1t52GUDAnL5Poh3oPkMtVyRaTuGcFugQYKxYtD1/doNpuDrQuQ3qKS0s 2/Gr4mGIcMDQWf1TGUwBHCO8PgUuKYxoEaEiN1sp64/9CQWwqlARkN7q/YPjWWu3wCcQ rkB3SSNqqbAlBk/G+AJ4tGOGDjknr3Na2Jhn3LFS29/IBzgTteUGknGhOHA3XcwfF8yh U17VFPRSwfusf9LlO5/ts/io3pZjEjZ2E/5zdQ0XRFsXvl2ebiaanoBHdktpHQLaXwVV xXw7CH4tTso+xW7cMKhapv6qXcsppvkKsYcXD6f/l0dam9R/jR+9ZeK9grEb73ocZc+J Bo+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TrEFfzKj; spf=pass (google.com: domain of linux-kernel+bounces-18024-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18024-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dc16-20020a056402311000b005551842b3e7si736173edb.19.2024.01.05.08.00.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:00:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18024-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TrEFfzKj; spf=pass (google.com: domain of linux-kernel+bounces-18024-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18024-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1DD6C1F23B00 for ; Fri, 5 Jan 2024 16:00:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 795B5321B7; Fri, 5 Jan 2024 15:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TrEFfzKj" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 CBB3F2E822 for ; Fri, 5 Jan 2024 15:59:26 +0000 (UTC) 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-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5542a7f1f3cso2102784a12.2 for ; Fri, 05 Jan 2024 07:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470365; x=1705075165; 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=TDuMrijv2n4yWr4gr0fXQfwtgxk4DAsUrjH6HhYvL7U=; b=TrEFfzKj7DPV5LXPJX+9KUyUi1nniNQ0ubPf/T3T1z9K6arfehVZcEaeylLAy5t/va HdPKHMy+EFgWbCUDEBMp76L0E9pN9ZaLjjb1zazKS8QnfRnCmkjyEj81PZKNwh1qIF+/ y06vJD6bD82c0WYVCtTjlngMXgswMkoUd53iqiLAcEBhdqUFBbZAXaq81IpSQWUwK84a GYyo583xEYxMEdhbj3aSCLu/peSuDn1MUFbyJzsROc5P4+GOKflsfTHQDBqJfTLAqpTj eBlklJB5+VGgalvRaBP7+Pup7B63vaIFrNyor3iS0D75xC+FJ5WmmB1Cd3dLYTWMJs5D mF4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470365; x=1705075165; 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=TDuMrijv2n4yWr4gr0fXQfwtgxk4DAsUrjH6HhYvL7U=; b=V4417/gjtXz6FSs5Os2sLsaedeYc219/B+YAWN1Ea9YvKiwUcY7oBSDszWr9qYP6KH pclJykgzXfWnonMlY/B1lP3mQ0cotDqD7rgmG+kHVAlbbs6Pbx9cbmCcXSSIC1BbfbP/ 22KSC08dmZh6lBf7JJFyu8RTl+2LLjlPszxu9ZYImDfIklk/1iBDMPkDyz815xsH9Wrq BFh7qEw7vqXmg4lBJ+mIBWkYdHQ/XncFL7ah2qkDOXi1iuR/oIOKZetZD2QZf6aHF9/d RAZAdZCdHm03ak0bRfN68rTOvhoEl5IrWwuoZabkXrbsxEEszyl/zvHIP0NtX8NjpPOM ci/g== X-Gm-Message-State: AOJu0Yw++xRShDSN+NG31zHjsQBsRqK3BulvBHMjPpoMRcPW9noFByhP 2EEvUWHLQTOlm2qx9ICLlOaUsoDHjSNouw== X-Received: by 2002:a17:906:4a09:b0:a28:ad3e:7071 with SMTP id w9-20020a1709064a0900b00a28ad3e7071mr1327840eju.118.1704470365032; Fri, 05 Jan 2024 07:59:25 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id su8-20020a17090703c800b00a29910a9366sm326024ejb.8.2024.01.05.07.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 07:59:24 -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 , 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 Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Sean Anderson Subject: [PATCH v2 1/4] reset: gpio: Add GPIO-based reset controller Date: Fri, 5 Jan 2024 16:59:15 +0100 Message-Id: <20240105155918.279657-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105155918.279657-1-krzysztof.kozlowski@linaro.org> References: <20240105155918.279657-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787266780319716894 X-GMAIL-MSGID: 1787266780319716894 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: 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 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..cf0a867cbc5f --- /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 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 void reset_gpio_of_args_put(void *data) +{ + of_node_put(data); +} + +static int reset_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node **platdata = dev_get_platdata(dev); + struct of_phandle_args gpio_args; + struct reset_gpio_priv *priv; + int ret; + + 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)); + + 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"); + + ret = of_parse_phandle_with_args(*platdata, "reset-gpios", + "#gpio-cells", 0, &gpio_args); + if (ret) + return ret; + + priv->rc.ops = &reset_gpio_ops; + priv->rc.owner = THIS_MODULE; + priv->rc.dev = dev; + priv->rc.nr_resets = 1; + priv->rc.of_node = gpio_args.np; + ret = devm_add_action_or_reset(dev, reset_gpio_of_args_put, + priv->rc.of_node); + if (ret) + return ret; + + priv->rc.of_args = devm_kmemdup(dev, &gpio_args, sizeof(gpio_args), + GFP_KERNEL); + if (!priv->rc.of_args) + return -ENOMEM; + + 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");