Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp499508rdb; Tue, 23 Jan 2024 06:14:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrdY1NZnmGgazwQMSTUvR77y8QbvZ2bXzYswa0C3lIpnjAFX8dGJ6NcfZpZRpvaoqGZpB8 X-Received: by 2002:a17:907:a091:b0:a30:6579:2648 with SMTP id hu17-20020a170907a09100b00a3065792648mr1107187ejc.17.1706019292075; Tue, 23 Jan 2024 06:14:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706019292; cv=pass; d=google.com; s=arc-20160816; b=WUnJH1t9aTSbsN3bBemt3iyVSokvQAiz5p46qphO0Po3/hxDMSL3ULDcsiY0MPuKlu iWXv4ooiHSxm3YKHtiAuHYrboXQKkMHovlJuewBDvc3dg06nWcJ8zcQNRSpFMUkMvua6 qQrseaY80JmHOwI2JmP5gFFcTS1H/DVXDYlc+6Mfp1vO5Bx2PWMY0d/7mqUsM+WEQ0Mi muhNaqolMwslRyLGgV4E7uWQH0U6Fajcd5N793ilCIR4kCSCptW2CoylJEUelxFfEbBB conKklLE1FSmniSFloRjaI5/EDqZONfNsNU2zptoTE5hJ54vNl6kv4QF2MDCJiHJZbI9 6oZQ== 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=hZ+XlfeIIIA0X9gDeF4vw53ttOCM6tywn9BtgTzvNSE=; fh=WOy8xA2VMstr6/9vw/Nn3yeV+ng+PbogVW5GUJsqpCU=; b=gOYUax6AZBzev9clbWX/1isvzhzEGx+xujWaAjK3v3cH6SC/fjmkcO2W1y5sSd2aqK FaiCd7uKcLH9Y+xp4cuBRi/tQhgfnT/0q18NOZ8lXmGLMTwjkSug2K2YA0L3m+6n37v6 DWkiS832ZRinLPgl/YrkNRUND4nXnwa3QRtlcQ9EcgtPK0UxvpGrKOG9HOwbBbUE+l88 TM1hKOiZDgcUQKgOhf5/cYIPB0picM2uFysZZdGXTAhEZnDjgHjoKrnX6lLmsfsh3EqF UdUrx36l7Wra/cK3e+OpksdYZ1OoFhM1qI9BBZN/jyQFa7lhuk89M+ELBAQZauj6gnUQ 9X+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RtEX4rSe; 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-35432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35432-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l27-20020a1709060e1b00b00a30f58b466esi56016eji.799.2024.01.23.06.14.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 06:14:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RtEX4rSe; 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-35432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35432-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 am.mirrors.kernel.org (Postfix) with ESMTPS id AA3F01F2A4FC for ; Tue, 23 Jan 2024 14:14:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C82FC5FF17; Tue, 23 Jan 2024 14:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RtEX4rSe" Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 A9D565FEE0 for ; Tue, 23 Jan 2024 14:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706019224; cv=none; b=BEFvLsZEUTmr6um4VJklggdPrvOMwVHx8ZdtR8VgIwBYDjEW1EWiEPXzeV8LInThnADPPd8H/1YT/SckQOjLl6LdhUSDMjrbNQWweuHUOcHWdZk7/jQUpZdpzqjr2Te71BBHGEP2kqnLpqv2tXcXJMJGTqYVkE06ZIJd88uXg3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706019224; c=relaxed/simple; bh=NVwcdnW8A7XQhpx5K/4jQMW8pILNh3MbaRAEeStWSEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sP9C6F8W84Lr5dQ58x7FlFINo3vmtcFcQ7/BdBFR46dyyKFyiPARTfXqfOM/1b3uBALP8nSh8UID/PGaxGpbpf9l8OAf7nJfsMS1PRZYj4/puMlPLZvg/9HANs+F7YFkjp/y/sZ0xWYNBfy/y9U3+nQC1bwyGJxcEpYpzqqYlQA= 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=RtEX4rSe; arc=none smtp.client-ip=209.85.221.54 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-wr1-f54.google.com with SMTP id ffacd0b85a97d-3392b12dd21so2521931f8f.0 for ; Tue, 23 Jan 2024 06:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706019221; x=1706624021; 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=hZ+XlfeIIIA0X9gDeF4vw53ttOCM6tywn9BtgTzvNSE=; b=RtEX4rSeEQQaavMt/BAtq9aMvdsAb08AWoBZwxEnKJ3UBUn8i3MeljyUfL9TXr6jVs fn3XmRfp+PTyARZZlAYtOJTc5sfleY6+QYH+3MvdhArzf/hXJTQ0mdm2NhuglZpXM/2p 2AhJyl+W8Ny3YKTh79siJsRcSNvLKMqp3VpG3e6t0bRtCG5LIPWAHOEFsA9cjTN7BJNx GIZy6lVc8fP8MnmvSkvXaPPTuiIUStLGnGRg48gzLPzuiL0Aj3ZVWq4M06WLZWW2nnwC i9A2tNIGhjP3/tuOt2XdxfrWTnxo4b9EfcYgM7HAla3N867p3UVWedWYRGcMCkhCEMDE B8eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706019221; x=1706624021; 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=hZ+XlfeIIIA0X9gDeF4vw53ttOCM6tywn9BtgTzvNSE=; b=sxmeX3vcysfzIeEOlQectpQYvWTtgXjvkeoYd9S6seaCv9nDsqmhUAX/enP6OD5GE2 /qn0aXWI9kpP91ouAq/rdxSRnFvPAZZ7rdH8Q9p5pr3AoVbv9QOO+fHkMp8WHNIXs+7f XwbXpUdSYLIgG+0NfJIRD48xMl3cn4aB5ZRAmyrpYD4ibMdrFKB/ouuoZ8XUq1Wy7yYV mfSnSsVfvkq6jbT5Fl/V2NvItAQ60bDfZN4FzuHNZy9HOXUIVYP1X6lVeoXRevZUN7O/ qxHnpC/XCwXRxyDzxTyWTq4CtFpWZ2dV3hDWI0SsNEYQQeee70CdI4WOJbk4sHIkwqCI THTQ== X-Gm-Message-State: AOJu0Yz1RIDJTuxzGANMnIIodvrEU4CcaslREkoxygKKkUXiY2YI4McM FrkUHOm90cJamC7tj6JOP06QzOfHOdrhJY4QkwVIfHjPAVhFJqujxl7NJu4RK3o= X-Received: by 2002:a5d:5886:0:b0:337:9b43:bb4e with SMTP id n6-20020a5d5886000000b003379b43bb4emr4085614wrf.74.1706019220784; Tue, 23 Jan 2024 06:13:40 -0800 (PST) Received: from krzk-bin.. ([178.197.215.66]) by smtp.gmail.com with ESMTPSA id r8-20020adfe688000000b00337d97338b0sm12132298wrm.76.2024.01.23.06.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 06:13:40 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , "Rafael J. Wysocki" , Viresh Kumar , Frank Rowand , 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-pm@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Chris Packham , Sean Anderson , Bartosz Golaszewski Subject: [PATCH v4 3/6] reset: gpio: Add GPIO-based reset controller Date: Tue, 23 Jan 2024 15:13:08 +0100 Message-Id: <20240123141311.220505-4-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123141311.220505-1-krzysztof.kozlowski@linaro.org> References: <20240123141311.220505-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 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