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: 760299 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 CD80F2E824 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TrEFfzKj" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a27cd5850d6so184593166b.1 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=ZokYTM+SncPh/JgaQjINGQcOkpLKGBrGnf2KsX2Yye6Fiy9O1tB09bOUy3FnOsTPBd lxK2IxnopsWy9qd43vYh3Vsv40jYOWOU0v/5dVK671Ey52phzBiylM4ch/7kzjVcHdg9 u0uLFhnyhNTzkfQJ8F/Du4nT/Osfi08nWxpyMiVxasrRWNHumnm0E8H/Cg53TcS6Bdmb gSWFQ2KDWAUTTVuaHPhvLHW6vlSxdyZ2zu64u6jI2Hp1ARoFW9uQZxGmvxILCxuKENyG 1LIByUPDgCiCI2iu7MXI5tgyeHRPjpuCYWs5nksozOiL40f9CAL2+VumMykZRIwK8DZR pLEw== X-Gm-Message-State: AOJu0YzY90gLjovk92HmDIa67Zb8S9OncQNGJeFC5am7c5bNjsaobJWS WcrnY0FVBmwP1Tf0aJjwyhBZxHS0Kk0AFw== X-Google-Smtp-Source: AGHT+IGHO2j43GzLRzecHQARtf8C7nxj4MOciN8ZW/ZXj6BM8h9fz4oBqoa3deDOqDTdz6Ido16D6g== 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: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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"); From patchwork Fri Jan 5 15:59:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 760490 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 AF4B62E84A for ; Fri, 5 Jan 2024 15:59:28 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="W7sHsspT" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a28ab7ae504so180578466b.3 for ; Fri, 05 Jan 2024 07:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470367; x=1705075167; 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=2tTyPxtOHyPhs2m2q+fBlzqfN887mU2OuCBzVF3uVpc=; b=W7sHsspT/V4ihEea9GxR/wqQ3RnazzeC5k6cllOX3977/PLex7eZ/NmG45QcqcGQq1 YYtCG4dYNz8BP3pZ1ldRFgZbOoH/v1CpTNEXpFDJlSGv+ieMC8pLuA83Adm6g5yf5yo2 eGbyP0xqgmSHN/jnOzT9IHVolhszkJfFKt84HAtGYX/woyQ0MWhiJKQtoyNqmV5BNS5s vMLk4Igu9li+eT8U9K7VYdyveWtGIwBPOxhJQ6dhoWUkcbEVKrhF5gDdqYriupRvxlIJ FBuG9vOoDm+RJQE2FCRfMe5wF9R0gzDy9Hm9vksdg+cUaB08cITuA5zTrD+Y6s+2Ypbw tf3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470367; x=1705075167; 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=2tTyPxtOHyPhs2m2q+fBlzqfN887mU2OuCBzVF3uVpc=; b=wKwZkCmEpFCJTQH2D/R5suXxvGbAUiFEL0Y9/XfNirhyfK3NmV+/t1Y8g//gdX2umJ UBpULvtPlR3Y4aMVmD+a/OhDx0dCVemm4FwufH7Z5eUyVbQM/A9Yx2Xmzs73XD8nAJG/ /jQeyw5wMHcKC+/o495MNhMMkhqmj3GgakkIESixWKAqnmKVZaZIP/t8Gplk908pgRzf EbwcFbnvYD6KUKA+srjdOL2sjF5SausvKx4d/+ADKHKkF+Yc0/MX9XXuzwr238AxM/hw tFBdeFCYQQDRH8jWPzef0+30FOJE3EOh8saSy5QTlBDJ8nA43wM72/mVYTAdHvN1oXwY uA1w== X-Gm-Message-State: AOJu0YwrQjA+atWntrYwPIk2MyeQxg9OXaIznFrRuJE/7fAJ3Ym+POZl E4EbM1rYZl3hRcNuyGJE99j1cW/06Rg8pA== X-Google-Smtp-Source: AGHT+IEJllJOQYWFJfcK4fFNCU2+uk/9rAtZgBP1Rn9juMOU1AONaO8vekFgnIMLnJEdjkon7/9SEQ== X-Received: by 2002:a17:907:98a:b0:a27:d9ef:8ab with SMTP id bf10-20020a170907098a00b00a27d9ef08abmr1310502ejc.2.1704470366902; Fri, 05 Jan 2024 07:59:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 07:59: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 , 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 2/4] reset: Instantiate reset GPIO controller for shared reset-gpios Date: Fri, 5 Jan 2024 16:59:16 +0100 Message-Id: <20240105155918.279657-3-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: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Devices sharing a reset GPIO could use the reset framework for coordinated handling of that shared GPIO line. We have several cases of such needs, at least for Devicetree-based platforms. If Devicetree-based device requests a reset line, which is missing but there is a reset-gpios property, instantiate a new "reset-gpio" platform device which will handle such reset line. This allows seamless handling of such shared reset-gpios without need of changing Devicetree binding [1]. All newly registered "reset-gpio" platform devices will be stored on their own list to avoid any duplicated devices. The key to find each of such platform device is the entire Devicetree GPIO specifier: phandle to GPIO controller, GPIO number and GPIO flags. If two devices have conflicting "reset-gpios" property, e.g. with different ACTIVE_xxx flags, this would spawn two separate "reset-gpio" devices, where the second would fail probing on busy GPIO reques Link: https://lore.kernel.org/all/YXi5CUCEi7YmNxXM@robh.at.kernel.org/ [1] Cc: Bartosz Golaszewski Cc: Sean Anderson Signed-off-by: Krzysztof Kozlowski --- drivers/reset/core.c | 176 ++++++++++++++++++++++++++++--- include/linux/reset-controller.h | 4 + 2 files changed, 167 insertions(+), 13 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 4d5a78d3c085..ec9b3ff419cf 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,10 @@ static LIST_HEAD(reset_controller_list); static DEFINE_MUTEX(reset_lookup_mutex); static LIST_HEAD(reset_lookup_list); +/* Protects reset_gpio_device_list */ +static DEFINE_MUTEX(reset_gpio_device_mutex); +static LIST_HEAD(reset_gpio_device_list); + /** * struct reset_control - a reset control * @rcdev: a pointer to the reset controller device @@ -63,6 +68,16 @@ struct reset_control_array { struct reset_control *rstc[] __counted_by(num_rstcs); }; +/** + * struct reset_gpio_device - ad-hoc created reset-gpio device + * @of_args: phandle to the reset controller with all the args like GPIO number + * @list: list entry for the reset_lookup_list + */ +struct reset_gpio_device { + struct of_phandle_args of_args; + struct list_head list; +}; + static const char *rcdev_name(struct reset_controller_dev *rcdev) { if (rcdev->dev) @@ -813,13 +828,119 @@ static void __reset_control_put_internal(struct reset_control *rstc) kref_put(&rstc->refcnt, __reset_control_release); } +static bool __reset_gpios_args_match(const struct of_phandle_args *a1, + const struct of_phandle_args *a2) +{ + unsigned int i; + + if (!a2) + return false; + + if (a1->args_count != a2->args_count) + return false; + + for (i = 0; i < a1->args_count; i++) + if (a1->args[i] != a2->args[i]) + break; + + /* All args matched? */ + if (i == a1->args_count) + return true; + + return false; +} + +/* + * @node: node of the device requesting reset + * @reset_args: phandle to the reset controller with all the args like GPIO number + */ +static int __reset_add_reset_gpio_device(struct device_node *node, + struct of_phandle_args *args) +{ + struct reset_gpio_device *rgpio_dev; + struct platform_device *pdev; + int ret; + + lockdep_assert_not_held(&reset_list_mutex); + + mutex_lock(&reset_gpio_device_mutex); + + list_for_each_entry(rgpio_dev, &reset_gpio_device_list, list) { + if (args->np == rgpio_dev->of_args.np) { + if (__reset_gpios_args_match(args, + &rgpio_dev->of_args)) { + ret = 0; + goto out_unlock; + } + } + } + + /* Not freed in normal path, persisent subsyst data */ + rgpio_dev = kzalloc(sizeof(*rgpio_dev), GFP_KERNEL); + if (!rgpio_dev) { + ret = -ENOMEM; + goto out_unlock; + } + + rgpio_dev->of_args = *args; + pdev = platform_device_register_data(NULL, "reset-gpio", + PLATFORM_DEVID_AUTO, &node, + sizeof(node)); + ret = PTR_ERR_OR_ZERO(pdev); + if (!ret) + list_add(&rgpio_dev->list, &reset_gpio_device_list); + else + kfree(rgpio_dev); + +out_unlock: + mutex_unlock(&reset_gpio_device_mutex); + + return ret; +} + +static struct reset_controller_dev *__reset_find_rcdev(struct of_phandle_args *args, + bool gpio_fallback, + const void *cookie) +{ + struct reset_controller_dev *r, *rcdev; + + lockdep_assert_held(&reset_list_mutex); + + rcdev = NULL; + list_for_each_entry(r, &reset_controller_list, list) { + if (args->np == r->of_node) { + if (gpio_fallback) { + if (__reset_gpios_args_match(args, r->of_args)) { + /* + * Fake args (take first reset) and + * args_count (to matcg reset-gpio + * of_reset_n_cells) because reset-gpio + * has only one reset and does not care + * about reset of GPIO specifier. + */ + args->args[0] = 0; + args->args_count = 1; + rcdev = r; + break; + } + } else { + rcdev = r; + break; + } + } + } + + return rcdev; +} + struct reset_control * __of_reset_control_get(struct device_node *node, const char *id, int index, bool shared, bool optional, bool acquired) { + struct of_phandle_args args = {0}; + bool gpio_fallback = false; struct reset_control *rstc; - struct reset_controller_dev *r, *rcdev; - struct of_phandle_args args; + struct reset_controller_dev *rcdev; int rstc_id; int ret; @@ -839,21 +960,50 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, index, &args); if (ret == -EINVAL) return ERR_PTR(ret); - if (ret) - return optional ? NULL : ERR_PTR(ret); + if (ret) { + /* + * There can be only one reset-gpio for regular devices, so + * don't bother with GPIO index. + */ + ret = of_parse_phandle_with_args(node, "reset-gpios", "#gpio-cells", + 0, &args); + if (ret) + return optional ? NULL : ERR_PTR(ret); - mutex_lock(&reset_list_mutex); - rcdev = NULL; - list_for_each_entry(r, &reset_controller_list, list) { - if (args.np == r->of_node) { - rcdev = r; - break; - } + gpio_fallback = true; } + mutex_lock(&reset_list_mutex); + rcdev = __reset_find_rcdev(&args, gpio_fallback, NULL); + if (!rcdev) { - rstc = ERR_PTR(-EPROBE_DEFER); - goto out; + if (gpio_fallback) { + /* + * Registering reset-gpio device might cause immediate + * bind, thus taking reset_list_mutex lock via + * reset_controller_register(). + */ + mutex_unlock(&reset_list_mutex); + ret = __reset_add_reset_gpio_device(node, &args); + mutex_lock(&reset_list_mutex); + if (ret) { + rstc = ERR_PTR(ret); + goto out; + } + /* + * Success: reset-gpio could probe immediately, so + * re-check the lookup. + */ + rcdev = __reset_find_rcdev(&args, gpio_fallback, NULL); + if (!rcdev) { + rstc = ERR_PTR(-EPROBE_DEFER); + goto out; + } + /* Success, rcdev is valid thus do not bail out */ + } else { + rstc = ERR_PTR(-EPROBE_DEFER); + goto out; + } } if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h index 0fa4f60e1186..e064473215de 100644 --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -61,6 +61,9 @@ struct reset_control_lookup { * @dev: corresponding driver model device struct * @of_node: corresponding device tree node as phandle target * @of_reset_n_cells: number of cells in reset line specifiers + * TODO: of_args have of_node, so we have here duplication + * @of_args: for reset-gpios controllers: corresponding phandle args with GPIO + * number complementing of_node * @of_xlate: translation function to translate from specifier as found in the * device tree to id as given to the reset control ops, defaults * to :c:func:`of_reset_simple_xlate`. @@ -74,6 +77,7 @@ struct reset_controller_dev { struct device *dev; struct device_node *of_node; int of_reset_n_cells; + const struct of_phandle_args *of_args; int (*of_xlate)(struct reset_controller_dev *rcdev, const struct of_phandle_args *reset_spec); unsigned int nr_resets; From patchwork Fri Jan 5 15:59:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 760298 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 48ED231A81 for ; Fri, 5 Jan 2024 15:59:30 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gKFQskzt" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-40e353c8d75so14742665e9.3 for ; Fri, 05 Jan 2024 07:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470369; x=1705075169; 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=jT3J/E5ihwUzRJFy9hQ6iVDhNFb12f1LhdaU7OTuQXY=; b=gKFQskzt/u4Fyqu59e+TLxIiOYzC3Amq0Ld6MEYdXrMlsk3W09Lt2EBS35W4iFxm4q 5vyi6zjKEFvv7DYQbL3uRMGnH5yknMrm0SYEaNN/ioaNHXmPt5emxGPp5SejTa5FaAOk IibSwcb6CsdxYdBJOCTVpWCCRxkj4G0Ul6nMKSsAUPme2pU7hxn44b5xgYV0ADEkQUar iozUeAT31AIV0EwdTKlButyJVelMs2QIYWrLEh/OPR6J2bRr7pLoixkd0Ix2XdL+Bb8v TwNH7dTvzcH2tEiMl09KaLM9WbsvbnW5QqZvE/Db41AL7AsCG1AKBnQhhKQY8CxdJXJJ UfzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470369; x=1705075169; 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=jT3J/E5ihwUzRJFy9hQ6iVDhNFb12f1LhdaU7OTuQXY=; b=vKfvSa/S1zKQOv6Qg5M1PRG+s03tyvEsv7XgN2aVD109C2zjqEDwBYmQQ4hfEU+fTU 0mDW/8GivX92yJByI8pxdyYcCl2LtQgtzTUvMyUYhrorork6dZ6QeXdKAq+n/VjiXxHp l7zrYJ1ZEZydHV26KMRAGT7f4PWR+9+CMQTAQd9GkO0EfSbGr9OReIfqVpmlwh5iqEP9 YL8rFy0oxTyWMqCKjJtBlEXC4SidA1SeMy87tMXUErhqSNRmN19hTXX1ukSHXwsGijzN 5jRAQt4Gag0YA3DcS9L9TEaXkRnlOCsQYfZZZR+GZjaJu2+l3EKdTL1pCew4dMTAt0hu gQKw== X-Gm-Message-State: AOJu0YwqSzRUaS5EZIE30a8P0GM+F4N1mnrECKhaKOMb2ajDHyjzuhnC owDgGwyD5F8TEBGlujwsxCcx1f0RaEOR2w== X-Google-Smtp-Source: AGHT+IH5ut0EXwmAZDo/9DvX++hIFWHA1Cpb3/Vc1PS5kLNAcDr62IMg/U92zdOSnDTc/Xtlv/jLDQ== X-Received: by 2002:a05:600c:1f83:b0:40d:355e:ab90 with SMTP id je3-20020a05600c1f8300b0040d355eab90mr1335180wmb.67.1704470369044; Fri, 05 Jan 2024 07:59:29 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 07:59:28 -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 3/4] ASoC: dt-bindings: qcom,wsa8840: Add reset-gpios for shared line Date: Fri, 5 Jan 2024 16:59:17 +0100 Message-Id: <20240105155918.279657-4-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: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On newer Qualcomm platforms, like X1E80100-CRD, the WSA884x speakers share SD_N GPIOs between two speakers, thus a coordinated assertion is needed. Linux supports handling shared GPIO lines through "reset-gpios" property, thus allow specifying either powerdown or reset GPIOs (these are the same). Cc: Bartosz Golaszewski Cc: Sean Anderson Signed-off-by: Krzysztof Kozlowski --- If previous patches are fine, then this commit is independent and could be taken via ASoC. --- .../devicetree/bindings/sound/qcom,wsa8840.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml b/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml index d717017b0fdb..22798d22d981 100644 --- a/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml @@ -28,6 +28,10 @@ properties: description: Powerdown/Shutdown line to use (pin SD_N) maxItems: 1 + reset-gpios: + description: Powerdown/Shutdown line to use (pin SD_N) + maxItems: 1 + '#sound-dai-cells': const: 0 @@ -37,11 +41,16 @@ properties: required: - compatible - reg - - powerdown-gpios - '#sound-dai-cells' - vdd-1p8-supply - vdd-io-supply +oneOf: + - required: + - powerdown-gpios + - required: + - reset-gpios + unevaluatedProperties: false examples: From patchwork Fri Jan 5 15:59:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 760489 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 5293D321AD for ; Fri, 5 Jan 2024 15:59:32 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XS/Sb/Bz" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40d8e7a50c1so19112475e9.2 for ; Fri, 05 Jan 2024 07:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470370; x=1705075170; 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=qJ0gjfKMOfp9CH0Fl1AfdBLtnAI1t5WhWrFWLERW/vA=; b=XS/Sb/BzcPN/YiYnQh1ADnuMiAW0yh9gnCJUcvgxtAc3Dc7QAeaap5dcZwG3r+BmsQ zhPbWOPJ2Wlbdm1L8V0ceFSmiUYT6+XxbifY3nttZEzNllKI1kM5bcOshbqo8Bcb12K5 EgRg5PZzg3ntwFiylX0TVdKDDElIDF0IrA/oVt3eIfaoNRrAycPAIqdj49oGxzxTdLUB fZGEJFoNT0goismEutz8xFQhBbI7YBjVzmo7jOTn3CknPWXY4SInnkAH0NZuD5YXx3t4 a2+BOKsK/N9TCeJgpzEb1ZVaxD/q13oFaEOmgV6C/W4CZA/k3xAjMBo0ZrladGbTJeil gZoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470370; x=1705075170; 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=qJ0gjfKMOfp9CH0Fl1AfdBLtnAI1t5WhWrFWLERW/vA=; b=q54hEL6CbwlJabwF6kvcAHyh3Xxtyi4xYMhTTVfY3I4yv2orRn325mDxzyrVWa/WPP 3NUy1DYKMwCdUfzNDGd3acXoz/C8vkx2QWPr1mp3XbIZEB3ZroxVSo5aL8Cw4MCui1JX qgPzUP2y+T4dOdh0c1EJBDQ240IfDDvwQtbPTLO/8OTT2RErlkdNaZVuJ9oc6Vf1Fi+1 3ya1bwPRP7Uq44rHbwcoyEN98Ok2Hj2rS1ci22ejm3x+30LvvUF4MvlHCVxsJmLSNorf M/1vSVrMm0R7WtcAtF4TXi8gew3vOVUVK/BK2m4Auh3qMxTcmLsIagRC9lrLoavoP/zE 7axA== X-Gm-Message-State: AOJu0YwC62zpSa+jpJIJlJyCNk8OCx+OaTMhDYLnhnS4vJGa/SeuZcWN JtvQrYzJ2xlXav/F1YP/u2scTzm3w5phtg== X-Google-Smtp-Source: AGHT+IGj8XXcjRZqX0CMRZnlgyrYxQ9F41PD/Rl4Wzog+acUIvZibg08DZgrOQHo9/UmfHMwsM5gyA== X-Received: by 2002:a05:600c:a0b:b0:40d:8dcc:ffd6 with SMTP id z11-20020a05600c0a0b00b0040d8dccffd6mr1236643wmp.136.1704470370692; Fri, 05 Jan 2024 07:59:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 07:59:30 -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 4/4] ASoC: codecs: wsa884x: Allow sharing reset GPIO Date: Fri, 5 Jan 2024 16:59:18 +0100 Message-Id: <20240105155918.279657-5-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: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some boards with multiple WSA8840/WSA8845 speakers, the reset (shutdown) GPIO is shared between two speakers. Use the reset controller framework and its "reset-gpio" driver to handle this case. This allows bring-up and proper handling of all WSA884x speakers on X1E80100-CRD board. Cc: Bartosz Golaszewski Cc: Sean Anderson Signed-off-by: Krzysztof Kozlowski --- If previous patches are fine, then this commit is independent and could be taken via ASoC. --- sound/soc/codecs/wsa884x.c | 53 +++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c index f2653df84e4a..a9767ef0e39d 100644 --- a/sound/soc/codecs/wsa884x.c +++ b/sound/soc/codecs/wsa884x.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -699,6 +700,7 @@ struct wsa884x_priv { struct sdw_stream_runtime *sruntime; struct sdw_port_config port_config[WSA884X_MAX_SWR_PORTS]; struct gpio_desc *sd_n; + struct reset_control *sd_reset; bool port_prepared[WSA884X_MAX_SWR_PORTS]; bool port_enable[WSA884X_MAX_SWR_PORTS]; unsigned int variant; @@ -1799,9 +1801,22 @@ static struct snd_soc_dai_driver wsa884x_dais[] = { }, }; -static void wsa884x_gpio_powerdown(void *data) +static void wsa884x_reset_powerdown(void *data) { - gpiod_direction_output(data, 1); + struct wsa884x_priv *wsa884x = data; + + if (wsa884x->sd_reset) + reset_control_assert(wsa884x->sd_reset); + else + gpiod_direction_output(wsa884x->sd_n, 1); +} + +static void wsa884x_reset_deassert(struct wsa884x_priv *wsa884x) +{ + if (wsa884x->sd_reset) + reset_control_deassert(wsa884x->sd_reset); + else + gpiod_direction_output(wsa884x->sd_n, 0); } static void wsa884x_regulator_disable(void *data) @@ -1809,6 +1824,27 @@ static void wsa884x_regulator_disable(void *data) regulator_bulk_disable(WSA884X_SUPPLIES_NUM, data); } +static int wsa884x_get_reset(struct device *dev, struct wsa884x_priv *wsa884x) +{ + wsa884x->sd_reset = devm_reset_control_get_optional_shared(dev, NULL); + if (IS_ERR(wsa884x->sd_reset)) + return dev_err_probe(dev, PTR_ERR(wsa884x->sd_reset), + "Failed to get reset\n"); + else if (wsa884x->sd_reset) + return 0; + /* + * else: NULL, so use the backwards compatible way for powerdown-gpios, + * which does not handle sharing GPIO properly. + */ + wsa884x->sd_n = devm_gpiod_get_optional(dev, "powerdown", + GPIOD_OUT_HIGH); + if (IS_ERR(wsa884x->sd_n)) + return dev_err_probe(dev, PTR_ERR(wsa884x->sd_n), + "Shutdown Control GPIO not found\n"); + + return 0; +} + static int wsa884x_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) { @@ -1838,11 +1874,9 @@ static int wsa884x_probe(struct sdw_slave *pdev, if (ret) return ret; - wsa884x->sd_n = devm_gpiod_get_optional(dev, "powerdown", - GPIOD_OUT_HIGH); - if (IS_ERR(wsa884x->sd_n)) - return dev_err_probe(dev, PTR_ERR(wsa884x->sd_n), - "Shutdown Control GPIO not found\n"); + ret = wsa884x_get_reset(dev, wsa884x); + if (ret) + return ret; dev_set_drvdata(dev, wsa884x); wsa884x->slave = pdev; @@ -1858,9 +1892,8 @@ static int wsa884x_probe(struct sdw_slave *pdev, pdev->prop.sink_dpn_prop = wsa884x_sink_dpn_prop; pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY; - /* Bring out of reset */ - gpiod_direction_output(wsa884x->sd_n, 0); - ret = devm_add_action_or_reset(dev, wsa884x_gpio_powerdown, wsa884x->sd_n); + wsa884x_reset_deassert(wsa884x); + ret = devm_add_action_or_reset(dev, wsa884x_reset_powerdown, wsa884x); if (ret) return ret;