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: 761525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B4BFC3DA6E for ; Fri, 5 Jan 2024 16:00:31 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B740DE79; Fri, 5 Jan 2024 17:00:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B740DE79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1704470428; bh=vxDO7NWsyYOxdk8MH6oAWFQBB4uYXhaj5d9IsPnW244=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=VsqNFn+A3uMqeB3RLdR4OTk6d837QtD7xlN38LracVKmCNWnCpnNU/15A8SK0VqmV fgLpXEuQiQVJ2YNYrx0rBWvocfA2k2WawOueyo9pJ7Y90N5XpEiM/m2MKkP4/od858 b/BKLBHGCUwzOJCh5ObnHfZyaJ2FCVOUD2MiwMOw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4F8FFF805C7; Fri, 5 Jan 2024 16:59:46 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id CF19AF805BD; Fri, 5 Jan 2024 16:59:45 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F1961F805AC; Fri, 5 Jan 2024 16:59:40 +0100 (CET) Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 060D0F80086 for ; Fri, 5 Jan 2024 16:59:25 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 060D0F80086 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=T+m7E62h Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a26f73732c5so184709066b.3 for ; Fri, 05 Jan 2024 07:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470365; x=1705075165; darn=alsa-project.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=T+m7E62ha0NS/bhWVhhb2NiIF3eExylGpEZo99WsByu1EQefESksDhhmRTDUHGBUBb yb3sP3XuFtloszB12zc0wdB9jXAyp53xbuqcr8NZ39+JCWUP8YvvYRl8hY3zvQxJXDoB OnYpW/j/uKSYzeVjlHh09kn0uVI940zXa78R6ES2jtJck66oYiOlpdKO9Y5dNRBcX3LQ EO/cWXjulq6UegDeBEVKtIi8+9KEJsJ2gQ1Voriqhq+FZalcS+GlJeUt37NaB412kQgu X80Fax1HifHLl0pJzJ/eXgFwhxL3p3GJif7AxhwUfgTbXr+jDvEMLZICL2GrObApYcnb fFJQ== 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=IuGdLOtl22cZ5/IgpzJA76SAGfPlvVlj5p7RD/gGsEbSG/ipaxhZq2lmLGZnAip+4Y uEmmJiAIMUMnHcEKANyq7u2B6cx7gJJi7KVa+mrYH160/RTzJtvJnzbsbxgHPHBVAePG tCrCdoybOH+UB2MWu5uGalVIp6x5y/LYeG6b5Gy3Vn4yBrm329WAxD4IkJtBSKT9DgS6 rBLMfnw58f41HMt84YBOTJrMnZYV1oODhqAgT9vdRjC19XHjHXmHjY4/KD88aQXfTB2W iT75Db0glIgI1H2LsYRnMr83kdlrQEXlEKK6FvzZ2RpXPdJivDJ2OFFJBfy44fjbTxhP wBIg== X-Gm-Message-State: AOJu0YyH2L5cdHNw2L+3PeeJtLvVxdixAXK4IutddUjL0FmWra3O2l78 F5QLy7o5jegWaX3ZEr8h4IFHqzruUACoZQ== 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> MIME-Version: 1.0 Message-ID-Hash: CZXTYDCU32RW4I7ZPXM5SOW5ITXKMVTR X-Message-ID-Hash: CZXTYDCU32RW4I7ZPXM5SOW5ITXKMVTR X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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: 760235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 535A0C3DA6E for ; Fri, 5 Jan 2024 16:00:47 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A3300E7B; Fri, 5 Jan 2024 17:00:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A3300E7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1704470445; bh=bc+iXpdz9DbsJ3J2wS5bEwodgL6YbnpTsc8B/pGoOSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=VILgyBcFEFr5TJ8rhlXNd5xw2WLOtk0D0cd3eBEcZtgKkJke8ncaCwV3fqyyZ0TOM 9vhkex0xrBZWjQvmATtNAJzxLV7j1CJQXJ7/kwuJYm9HLLJk0Au8HAUFV/A+6TorJV 76rOVq5OntjDilcoXwARMUUDGG3PdyO0G3t+owkQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B5766F805E3; Fri, 5 Jan 2024 16:59:49 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 392E4F805E8; Fri, 5 Jan 2024 16:59:49 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6DF1AF8058C; Fri, 5 Jan 2024 16:59:43 +0100 (CET) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id EF7E3F80496 for ; Fri, 5 Jan 2024 16:59:27 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz EF7E3F80496 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=WczM9FPy Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a26fa294e56so181104166b.0 for ; Fri, 05 Jan 2024 07:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470367; x=1705075167; darn=alsa-project.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=WczM9FPyrV8RfP9ekF8U0T2Ki+9ZueGAb2eyNUZ02HXuFRF9CH3AJywly5ZFnvbIN5 NBrigWRb+NRmoSFVehFqQ8Lch1M2XjXvzjcZTKmiZQDbVEp0yBOxgLzrTZFjxq2NbAhU treY1iy1409EWfoKR8vf5G8+A39LV2liy4Chb930TfGx3pYnasxzfvzRLpH+Ezw6OTMT weyHn8MYU9NlmwO1h8RJTMhcvFcUjV0hjeBSTty1NAWJJNr9QULMrHHPJalnrDUWDHk2 UTjfjj0hLUqZSwwJlf7z8t/+uSyzrgn8yywFHMluvM7EPsrQwiluHoPBhPPt46OjKeO0 XQug== 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=IPv4IzW+bSIZJfVNKAlwraKzPldvaJi//7psPxrWd2m92VHEr/UfQ9jFQUiXFyAYER Unei/2Mdfj3VGZniP58tHFZ0Vsm0hIiiZsBdu1iffZMDBlm+uRVDQNaHk3pA/PspL9k2 FaGoXVImoOWRG2rnvbLa3bMxfJ1eGRzH9GLqhPeSVM+AFYhykKasjyIdZm1Op6MSpGxy TnBREDBp+ePukwtXC1PSAtYIhhiNAqvldZErQgjMIdD4QQlxNMXZThRZ9Xuy7fVOI9r5 KJ4LkwOTxb71bdGcmuUXBKMLBS7cKuNWHFLmwMbYq5cMxD6aNwrSl+8v0N6okA1StQX4 2sVQ== X-Gm-Message-State: AOJu0YzRfGU3ZARRVHmmSLnDBlLyUijmMdGhqGrd6u3Uov7b3pb06iJL Cv2xB7CD/Zz7m9hgjjTLdEdoTXpf4WHxXw== 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> MIME-Version: 1.0 Message-ID-Hash: SM5PZCD7QHQXJNH2EPTL53H3TUCJHYZB X-Message-ID-Hash: SM5PZCD7QHQXJNH2EPTL53H3TUCJHYZB X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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: 760234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89EFBC3DA6E for ; Fri, 5 Jan 2024 16:01:13 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B745FEC6; Fri, 5 Jan 2024 17:01:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B745FEC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1704470471; bh=i7un3vONZnr77R7B2m9eLAG2l16u/2NVCWr/W91lMOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=g4lpvx5Wc+QVUFumFngrWbSXZwwRP8iSgldn9MSJ/26V4iYw6KfqMNl7oqDu3wrAr uIq09JCt4PJVOItHrSETfPKv1No5FfKK13eeDiRzSWbAYgsOh4kg/6KQbQzEKE+OHV uy2GS0QzrcvXjipfDOtOQt9rpSqvraZGxmBknhHA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B7682F8061F; Fri, 5 Jan 2024 16:59:54 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 2B0FEF8063D; Fri, 5 Jan 2024 16:59:54 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 68DE4F805BF; Fri, 5 Jan 2024 16:59:45 +0100 (CET) Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 291A4F804B0 for ; Fri, 5 Jan 2024 16:59:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 291A4F804B0 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=s4n1xXB6 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40d41555f9dso16717495e9.2 for ; Fri, 05 Jan 2024 07:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470369; x=1705075169; darn=alsa-project.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=s4n1xXB6M1KzMuQ3qt690wbTWvjzmrNkVGSgFvw1/ortei4UOmmxaZol2Q8RCW3Kbx fh7Y42NT/matyeLvlrPkHDLOeJG6u3qo2fKaPrJv+5ICHCjkkuDvO2R9U+VXW4/fc2PQ PBdDdmqSN70iFKQLoFfohqJrtBhj1TsvEJmTeWk+BdJyUUuk6pwB0MXSOA9FhzROcge7 1CKxAs91Kz3Rmbm6/q4j2oxJOpBpqz4SGfgkpmZOXDNahY4IDHdiQjl1sg5rSs7R/Kze l2Favr3lXFjiN1/sBqcSw+tDTwEVdeCtVRVdmuXojRObNfUjYJ2mcaDCC444xwf02h51 C4ig== 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=T/ELgQ4W5JNXf5SzNQwS6XxKu6TW2V69dbEo1Z8ecdywBho5wogQJ7ctLZOmYpHsny Phyw03FNxh3q1svgU/O1qjVkdSTfveZcR4Ik6oo/eDIJIHAWjxvWzd/OHc0bC3fqwbP2 beJ4zuvw7nzdSNSOO8i8/mOijtpyiUc3vHkvxT+G2wHuTox/tIEBhbQKFTRjpVRIaCF3 AMqi8shAKBDtpCg9gOafveYmAqu9bMBfN/YX+xuHD4qPz+b74mF8PEMnL4rMc/1q3LXj XK2Lx5TcLh5nPx54hB45kK8+qrRSdoPrHaA3etcEAuj+XvBLCRt9yhYmYviZDyY1y/ZL JoZQ== X-Gm-Message-State: AOJu0Yyjt+hzxlTorMpk5B9V8MrOmZQyfvRq8QwTtUwgq04p/niBGsGS +wRoOQbKpQCHM+qd9O+tH6SrHzsaJwi4uQ== 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> MIME-Version: 1.0 Message-ID-Hash: PERDO5VLZVXPJED32THRJDT7EKKYEH6T X-Message-ID-Hash: PERDO5VLZVXPJED32THRJDT7EKKYEH6T X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: <> List-Archive: <> List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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: 761524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BC31C3DA6E for ; Fri, 5 Jan 2024 16:01:02 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3ADACE79; Fri, 5 Jan 2024 17:00:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3ADACE79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1704470461; bh=zd6Bmh48g7rsM+87XsXBkxNU+Zs2Yu+NMiweLujpj9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=tXNnKzArsPqz9KnXtGW7gskrj1itWeTJbJ7ZCrPbY8Z+itQ4g3OXV9hmE14E5cGgd 8tl8eVphwRy1SLuj60d9Ep7gKuyBh7fHHqZWcrLV2Y4mhBmuxuwWH5CiK6Fj6uFm36 0+iU4nVVU0E2royyk9BF7w4kQmmEATkteXqHd0DU= Received: by alsa1.perex.cz (Postfix, from userid 50401) id AD2B4F80619; Fri, 5 Jan 2024 16:59:52 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id EE1A5F805F4; Fri, 5 Jan 2024 16:59:51 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 720EEF8055B; Fri, 5 Jan 2024 16:59:43 +0100 (CET) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 0C9EFF804B2 for ; Fri, 5 Jan 2024 16:59:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0C9EFF804B2 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=G0LJtZHE Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b5155e154so19033835e9.3 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=alsa-project.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=G0LJtZHEsZnIS23O7tw6rYTHl0Zql+FM8jycdK29LLL0uSiIzsPz3SwqqLsKT6Y/Ym 2/6Qn4SKBWLEENuk4SDnXtIJNI2LSJcK1zyTXl2DdY3NYQ91pDNkQg/yN8K4k3ARiX2D mxy+zNxaXQ3pDy6nR8IF/3yAc1pPseRUODjbew/XXaiTgpY5K6/sYOPaDQBWd+WNK/N1 hfOWdQ7VPvD90Od94LfXkLsXcG1mjUCO0PMs+1GSRU8B1jceL9iu5NffTul6KySjb40O N5VXdaEu6lkAD42hsKwO51oXQuZrrW6c2svHxr1BUAdYP6GmghklLwrtP2WvmlzY1ceY eb/w== 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=qkbOVHxonH/jpMG6J8ZCYUqurypCaChKUwXda025obQZYBoyboDtUk6B6ON8Mpxafa +cTeeVp16h1ToF8d02VG6ZQz8232FO+8j8N4f3806Algey3rfQ3TZ+jC7eoFIuXg9Hjd t/+Cjhl/LgWWZNGq90RQyuhRw0/+b/qGL+Rf0VklIuLbcVuAidR0SrlReUzPyBjB9G3k yFgN4zTDf0jfnYgE6BI1KqyTsq+I6MgSREX49YhE8FcNpdLuIcv1Y3HBKS7YZX3Il1VD aWK9HhViodd9/9mjGUUF8kDf3FP59krYkBAehcGp/YX2MuZZIBNHc2V6MLAWINFUFc/C Lwwg== X-Gm-Message-State: AOJu0Yx+LovN71LDWBydZzy/D/U0zD+2Io4KKOCzE5naDj6uodwbUFmc e3HEVf9YMHunLuxeexB8BYrC4mWLM3wGgw== 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> MIME-Version: 1.0 Message-ID-Hash: V4DVBOBBRQI7QAD7EPH6MQRZWBCQAFFS X-Message-ID-Hash: V4DVBOBBRQI7QAD7EPH6MQRZWBCQAFFS X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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;