From patchwork Fri Jan 12 16:36:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 187787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp294432dyc; Fri, 12 Jan 2024 08:37:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmn7tQPiYGGGOaK254thE6W2Yo4+SwHnLh0S2oqf+jEEdLzNYTqLGIjy8+AO/2b5UUxp2c X-Received: by 2002:a05:622a:1756:b0:429:8522:4ce2 with SMTP id l22-20020a05622a175600b0042985224ce2mr1800330qtk.98.1705077442001; Fri, 12 Jan 2024 08:37:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705077441; cv=none; d=google.com; s=arc-20160816; b=cIQAQKz70a6TQDEb2TUBpCtsP2uk2bfeqQolXMFBId3N+nS+Vpozy5ZHDdX8P8xknR n8AYBvbMN2X0Jhx7ZwAbnWhFvRc+/ibkU3fXhqKFzrKDzZ8UrbRp9vhC/XM4u1gY5qh9 Nm3tRNmGcrFa/TSjSgie9FaJS5r5Kqg8wrRvUNwoPANqUAfdllu5+2eJWLjXK/DAw6zO OI0Dy8I0vAsIo7Ml+ohKJ07JEbGSqyAY0frWKwSNopHBE/eu1ON3EUrsZ3w4ZrDQx9GR EMQ4rx9XKsY7QWCjanmOLLzLcWk/NtWOVbf8Et77QooyLY0San6B5bVaiXgAcgC7Bgtr 5YOg== 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=68a0GULzTNp5I10XTHNXdWuvNz9Mn+A/t6I9BSr+hho=; fh=O48av0w63oqyBwyJ444pZAVrdLa46/f2S34FJDLoWVA=; b=A1+qTp06UsAjeOWFrVSFQAb+YCJjNJctsxtiJP5IxQwtI9Lg6gC2rm1lhy+DqfbtLq DGINddUxyiBQO/ZtWCDQidu8juKLiQUU6ZBiQZAKW8jbLJ7mx7rWwAksL7hNJGVu8pZ7 pywnIcmhKtdToPr7P44mW6UtTdWXH/Nbw1mW4epjC+mbCC9rDpRkbfrnkBmv/wDzCFX2 w0H6Q6pAcW0D17tAcrI5kShTytuuxCbEydEpvk03BiwZ73edQrMKMKOdsBRmZYiu2eFK JgTVocX1NKsSxqYWWWT0BX54Mw+T2pdROu6Z2xX/ZrnGJg86kEl63zPq8RZ9+jpjC2CX Yuxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oEc42AHT; spf=pass (google.com: domain of linux-kernel+bounces-24863-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24863-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e16-20020ac85990000000b00429934444f1si3211739qte.241.2024.01.12.08.37.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:37:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24863-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oEc42AHT; spf=pass (google.com: domain of linux-kernel+bounces-24863-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24863-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B05B11C20EDF for ; Fri, 12 Jan 2024 16:37:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79F3477F14; Fri, 12 Jan 2024 16:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oEc42AHT" Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 42CE47691E for ; Fri, 12 Jan 2024 16:36:24 +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-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40d6b4e2945so76956645e9.0 for ; Fri, 12 Jan 2024 08:36:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077382; x=1705682182; 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=68a0GULzTNp5I10XTHNXdWuvNz9Mn+A/t6I9BSr+hho=; b=oEc42AHT8EjnqGyNsHIEdPwI5UY+qJyG4TujOSQYO9iLtjkLVT/o19AQhSWsbsHG9b bAyBYE9Xc7bY68ntAgubzH5FPHFkvZOwSI0IpvLJQgf1MMOoA6tn6cFxm7hcXf6HPEql TNBcPNH7ZP6X16XPN/0ntzwuBOvlmlSE5HumdRu5PZnP3SFxYZ4z7xx7dB/WxwKhKtnm V9sP9apzqwUYxjwtzfXZdMWqfNVLe7kh5gzUJyjyt05bOsuP7EZpdt3YLuenI7GjJ9Ll 4jCWlbULj93ZMdo2Y9TXlqLU91lZ7CsJOROX/kWLKbN1iegLvkkW4k5ocp7lxuunwuno 7lkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077382; x=1705682182; 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=68a0GULzTNp5I10XTHNXdWuvNz9Mn+A/t6I9BSr+hho=; b=RHVtqoLVJHorjbANt2mZtRZBPhWhYykCn81QHid55meVz/KXwpoGW+RfhqlKl1dsI6 bumkSCCFFoGs8jugh+KosJKcvmbluztOLQpWDWxbeQxeJiUPylIQ/RYcn9fHwXvgBXE2 7ox2ZkwODcecslL1C/jm/K4SERaRYCv+KZdecNf/xg6m36WOvxIU5UUesnXFv+yuQDU0 R6fzlCV7ypScjRBztZLsQFk/Cuo5U8mGdeNpf/4Yf4R74dWAp11k7ZQq+cf26vsyRHEz kJweNcaUPIpFbPwRiamT+6Vj2JSg30JcaskfH77V1GWbXXTLJkqB6u0Dq53pANjE6Rco fVFQ== X-Gm-Message-State: AOJu0YyoB3LSd7p5x0w+QYLISehxC6sXwIgrV4DuVO81Ndq5oBVhTFKG nCm7WQDrJfMrGrDcGYaDM6+BbmgNPdjqSw== X-Received: by 2002:a05:600c:31a9:b0:40d:725a:994b with SMTP id s41-20020a05600c31a900b0040d725a994bmr659058wmp.174.1705077382570; Fri, 12 Jan 2024 08:36:22 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id bd16-20020a05600c1f1000b0040e5a93ae53sm6573195wmb.22.2024.01.12.08.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:36:22 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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-i2c@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Chris Packham , Sean Anderson Subject: [PATCH v3 1/5] reset: gpio: Add GPIO-based reset controller Date: Fri, 12 Jan 2024 17:36:04 +0100 Message-Id: <20240112163608.528453-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> References: <20240112163608.528453-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: 1787903283691750994 X-GMAIL-MSGID: 1787903283691750994 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 Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bartosz Golaszewski --- 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..0fe482740f1b --- /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 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); + + /* Relies on GPIO_LOOKUP */ + 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; + priv->rc.of_node = of_node_get(platdata->np); + 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"); From patchwork Fri Jan 12 16:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 187789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp294723dyc; Fri, 12 Jan 2024 08:37:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHndL6iUrKhEOOVnsIuVgVMbwXE20KK5+GAi6WbciStRucZ3N+b2n0Wm87yxixTTvQjS3iE X-Received: by 2002:a17:90b:3650:b0:28d:e16c:7055 with SMTP id nh16-20020a17090b365000b0028de16c7055mr1295129pjb.73.1705077472271; Fri, 12 Jan 2024 08:37:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705077472; cv=none; d=google.com; s=arc-20160816; b=RfdQp/FCNahKsIq5obzwusT93/PlhF8HilRCk0Mil2NuSYKw8zgUBDQ+OzNRg5KHjf Gnc1N0FvOIcToOccPEb+wOadw1VJM9rblexbWAr5Kgs1P6EezC7TvEBW36uutoXveuEd 7h7GBzzwgZncHZVNALzr3VAPYtrZh+FuQFr2NeaO07Xv23t3hI5TMUtE7qHeJ6MhRm1D Ty8+L1ePfbQ6m9ky1LuGQ53k8Cjl6UmQANa5ao/oRAnbxZ1cSL2izNKuCEcN+/UnLLWG oLHMJzcPIoM6Qi3Bu4IlE04zEwPxetRSa0grb1TnyN2DmnBmLr/UMw+jdGWmglxiXaVN LEZw== 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=gyDDK8wz61UD70/QcPoYFZCJBphOvhD/N3TrrEWzs04=; fh=O48av0w63oqyBwyJ444pZAVrdLa46/f2S34FJDLoWVA=; b=IU85PNwiAJp1disgg6/sQ1kPrzPdWEmEpkPOMqVTeqWFzYJbK23Nfa7/59n+yqfiue 3BkxijixLnNS6G3CkLt4rq795JtmxsjhAIPkwwmkKHeAJw9LwOa/6DeqGPjpzi14NFk1 6rMo00RetFmRPpMjDtff2b/mfJXdSQG4h/HPURHx137MfB2OA/YfM7TZvuy5A+y2nrG2 Z83mkLL6z1x0PPao5+2oOygZ5dc94rJtnA+Yv1NDKr2oNi03L9gnTpR+1hmM++LyKZlA 3b+NrdB6aMXhsT4PoEqIiNl7a+P4InEotA/XuZPt9IQtqhAZVOPe6Vy9F8dEzOilR7pM RsUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WFMKF70M; spf=pass (google.com: domain of linux-kernel+bounces-24864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24864-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jy13-20020a17090342cd00b001d55aa9ffecsi3640305plb.253.2024.01.12.08.37.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:37:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WFMKF70M; spf=pass (google.com: domain of linux-kernel+bounces-24864-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24864-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0C033282D50 for ; Fri, 12 Jan 2024 16:37:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C21147E78A; Fri, 12 Jan 2024 16:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WFMKF70M" Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 4497777641 for ; Fri, 12 Jan 2024 16:36: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-wr1-f50.google.com with SMTP id ffacd0b85a97d-3367a304091so5596968f8f.3 for ; Fri, 12 Jan 2024 08:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077384; x=1705682184; 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=gyDDK8wz61UD70/QcPoYFZCJBphOvhD/N3TrrEWzs04=; b=WFMKF70MQdvbpCQNxtFCRG4HC2JPJ+F8sKSGod/UI3nSLF7tQW4qLRgcGPw7x/OVeX 0+/dwlkJCWSqGKbC55TcQ6iwJM+FTAb4o4Eh9X8cxkwHKZtxuf7HfgqdB5YPf9zfBKQN pIjguKLVEo5ypA8hu1TXFkU2ZhkQG5YPf48z4/gWoyYz7YT10TGAalMwKwPuiAsND4gr jT5+cwydZzGqe/MeqZc8mjcmWAK0U5Dpk9ll/GEaQSgYGgsFnEZYhzekOdBPghHJVT4V yYhsLQWplnKHJ+Eooz/b0emwV/lVJ5LrXVry1BdgPICbjL8K39Nq6WF+0r0CR06OeapX ZVFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077384; x=1705682184; 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=gyDDK8wz61UD70/QcPoYFZCJBphOvhD/N3TrrEWzs04=; b=F786W0+Z6AmHIc36aZ2eCLlXvRvnqmuGJa4yfI5WD16dnYC2fzE6TAJZXwCXBguGUv UFCP3vv8MQpkFNb1PGQRTdKnVqp4+7BAOKtuvG8BywOAPUwR5zs7jIqDOUTxt2O8I8Fj LhOivwBYUok7pPhg+2Y6nN2mpce0Kusp1Z4frrOloZvwxlfDRB6BP8zdruSaC+f1Km2Q MkpVxPpqMK47Bjb7bVh5l0sxPQoW3ResXw87JTRb6SJxlfn0vM4XUs67SjIGexugcdki PQzOOOGsysatzdJv0CoCdCZBtBr586Y2dpNhny40TZvboZMeZ7bcN5xewLt+POKmXARp TZfg== X-Gm-Message-State: AOJu0YxGzZZiLGqdiTItQ7JXhv3FWL0xWvUIM15W0WAHUetVicMNan/U Xk7K4JT/zLvKtncIeAva6vUADc1wZY8HXQ== X-Received: by 2002:a7b:c5cb:0:b0:40e:4921:5038 with SMTP id n11-20020a7bc5cb000000b0040e49215038mr648930wmk.91.1705077384525; Fri, 12 Jan 2024 08:36:24 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id bd16-20020a05600c1f1000b0040e5a93ae53sm6573195wmb.22.2024.01.12.08.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:36:24 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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-i2c@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Chris Packham , Sean Anderson Subject: [PATCH v3 2/5] reset: Instantiate reset GPIO controller for shared reset-gpios Date: Fri, 12 Jan 2024 17:36:05 +0100 Message-Id: <20240112163608.528453-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> References: <20240112163608.528453-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: 1787903315867154603 X-GMAIL-MSGID: 1787903315867154603 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, while "resets" Devicetree property is missing but there is a "reset-gpios" one, 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]. To avoid creating multiple "reset-gpio" platform devices, store the Devicetree "reset-gpios" GPIO specifiers used for new devices on a linked list. Later such Devicetree GPIO specifier (phandle to GPIO controller, GPIO number and GPIO flags) is used to check if reset controller for given GPIO was already registered. If two devices have conflicting "reset-gpios" property, e.g. with different ACTIVE_xxx flags, this would allow to spawn two separate "reset-gpio" devices, where the second would fail probing on busy GPIO request. Link: https://lore.kernel.org/all/YXi5CUCEi7YmNxXM@robh.at.kernel.org/ [1] Cc: Bartosz Golaszewski Cc: Chris Packham Cc: Sean Anderson Signed-off-by: Krzysztof Kozlowski --- drivers/reset/core.c | 227 +++++++++++++++++++++++++++++-- include/linux/reset-controller.h | 4 + 2 files changed, 217 insertions(+), 14 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 4d5a78d3c085..86e33a703ad2 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -10,9 +10,13 @@ #include #include #include +#include +#include +#include #include #include #include +#include #include #include #include @@ -23,6 +27,11 @@ static LIST_HEAD(reset_controller_list); static DEFINE_MUTEX(reset_lookup_mutex); static LIST_HEAD(reset_lookup_list); +/* Protects reset_gpio_lookup_list */ +static DEFINE_MUTEX(reset_gpio_lookup_mutex); +static LIST_HEAD(reset_gpio_lookup_list); +static DEFINE_IDA(reset_gpio_ida); + /** * struct reset_control - a reset control * @rcdev: a pointer to the reset controller device @@ -63,6 +72,16 @@ struct reset_control_array { struct reset_control *rstc[] __counted_by(num_rstcs); }; +/** + * struct reset_gpio_lookup - lookup key for ad-hoc created reset-gpio devices + * @of_args: phandle to the reset controller with all the args like GPIO number + * @list: list entry for the reset_gpio_lookup_list + */ +struct reset_gpio_lookup { + 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 +832,183 @@ 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]) + return false; + + return true; +} + +static int __reset_add_reset_gpio_lookup(int id, struct device_node *np, + unsigned int gpio, + unsigned int of_flags) +{ + struct gpiod_lookup_table *lookup __free(kfree) = NULL; + struct gpio_device *gdev __free(gpio_device_put) = NULL; + char *label __free(kfree) = NULL; + unsigned int lookup_flags; + + /* + * Later we map GPIO flags between OF and Linux, however not all + * constants from include/dt-bindings/gpio/gpio.h and + * include/linux/gpio/machine.h match each other. + */ + if (of_flags > GPIO_ACTIVE_LOW) { + pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n", + of_flags, gpio); + return -EINVAL; + } + + gdev = gpio_device_find_by_fwnode(of_fwnode_handle(np)); + if (!gdev) + return -EPROBE_DEFER; + + label = kstrdup(gpio_device_get_label(gdev), GFP_KERNEL); + if (!label) + return -EINVAL; + + /* Size: one lookup entry plus sentinel */ + lookup = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL); + if (!lookup) + return -ENOMEM; + + lookup->dev_id = kasprintf(GFP_KERNEL, "reset-gpio.%d", id); + if (!lookup->dev_id) + return -ENOMEM; + + lookup_flags = GPIO_PERSISTENT; + lookup_flags |= of_flags & GPIO_ACTIVE_LOW; + lookup->table[0] = GPIO_LOOKUP(no_free_ptr(label), gpio, "reset", + lookup_flags); + + gpiod_add_lookup_table(no_free_ptr(lookup)); + + return 0; +} + +/* + * @reset_args: phandle to the GPIO provider with all the args like GPIO number + */ +static int __reset_add_reset_gpio_device(const struct of_phandle_args *args) +{ + struct reset_gpio_lookup *rgpio_dev; + struct platform_device *pdev; + int id, ret; + + /* + * Registering reset-gpio device might cause immediate + * bind, resulting in its probe() registering new reset controller thus + * taking reset_list_mutex lock via reset_controller_register(). + */ + lockdep_assert_not_held(&reset_list_mutex); + + mutex_lock(&reset_gpio_lookup_mutex); + + list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { + if (args->np == rgpio_dev->of_args.np) { + if (__reset_gpios_args_match(args, &rgpio_dev->of_args)) + goto out; /* Already on the list, done */ + } + } + + id = ida_alloc(&reset_gpio_ida, GFP_KERNEL); + if (id < 0) { + ret = id; + goto err_unlock; + } + + /* + * Not freed in normal path, persisent subsystem data (which is assumed + * also in the reset-gpio driver). + */ + rgpio_dev = kzalloc(sizeof(*rgpio_dev), GFP_KERNEL); + if (!rgpio_dev) { + ret = -ENOMEM; + goto err_ida_free; + } + + ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0], + args->args[1]); + if (ret < 0) + goto err_kfree; + + rgpio_dev->of_args = *args; + /* + * We keep the device_node reference, but of_args.np is put at the end + * of __of_reset_control_get(), so get it one more time. + * Hold reference as long as rgpio_dev memory is valid. + */ + of_node_get(rgpio_dev->of_args.np); + pdev = platform_device_register_data(NULL, "reset-gpio", id, + &rgpio_dev->of_args, + sizeof(rgpio_dev->of_args)); + ret = PTR_ERR_OR_ZERO(pdev); + if (ret) + goto err_put; + + list_add(&rgpio_dev->list, &reset_gpio_lookup_list); + +out: + mutex_unlock(&reset_gpio_lookup_mutex); + + return 0; + +err_put: + of_node_put(rgpio_dev->of_args.np); +err_kfree: + kfree(rgpio_dev); +err_ida_free: + ida_free(&reset_gpio_ida, id); +err_unlock: + mutex_unlock(&reset_gpio_lookup_mutex); + + return ret; +} + +static struct reset_controller_dev *__reset_find_rcdev(const struct of_phandle_args *args, + bool gpio_fallback) +{ + 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)) { + 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,39 +1028,49 @@ __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; + + ret = __reset_add_reset_gpio_device(&args); + if (ret) { + rstc = ERR_PTR(ret); + goto out_put; } } + mutex_lock(&reset_list_mutex); + rcdev = __reset_find_rcdev(&args, gpio_fallback); if (!rcdev) { rstc = ERR_PTR(-EPROBE_DEFER); - goto out; + goto out_unlock; } if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { rstc = ERR_PTR(-EINVAL); - goto out; + goto out_unlock; } rstc_id = rcdev->of_xlate(rcdev, &args); if (rstc_id < 0) { rstc = ERR_PTR(rstc_id); - goto out; + goto out_unlock; } /* reset_list_mutex also protects the rcdev's reset_control list */ rstc = __reset_control_get_internal(rcdev, rstc_id, shared, acquired); -out: +out_unlock: mutex_unlock(&reset_list_mutex); +out_put: of_node_put(args.np); return rstc; 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 12 16:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 187788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp294678dyc; Fri, 12 Jan 2024 08:37:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4ydKOkZp0oOsLywakKehf6is2Aq+1TU2c39qMu4syYTqGj49G3zE/7vLnrwVmd/MbHxja X-Received: by 2002:a05:6402:1647:b0:556:f13c:d6ec with SMTP id s7-20020a056402164700b00556f13cd6ecmr965964edx.76.1705077467846; Fri, 12 Jan 2024 08:37:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705077467; cv=none; d=google.com; s=arc-20160816; b=HSKvSYRtfpLdt3rF/+2RIUeCcdlQbr8o/GpVijmEuO37j+D7GeQD665Dh257lK60w0 RQDYK4cCVVR1VPIp6jnHQ7aBfKVDtuC+pdPAMSbuL0ZELutU6Sqdl94giQeWnOpXEXHq uy6aJx/WcueijiPWBeciRuRp/lxngSmxjr4QYDagtJRENpn1VkbCScZny/XxH7y+Jh1J 15T6PP/ouHELG8hYeCMQDFGrn2EV+p7Ous5+k2b+Wz1RxqM2o66uvl+GUxOtPelSseU7 rB5wBSu8xN4cPQgqhQ4JJMI3tmpJDpTgTLqF4V+1jCDRpxkpVHurqP/JhGf9BHEhZVRI vKEQ== 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=jT3J/E5ihwUzRJFy9hQ6iVDhNFb12f1LhdaU7OTuQXY=; fh=+9Max/V/7cjj8RZEj+C1lXQLChlj/u+Ka2QetC5y70Q=; b=IIXUT2MSZh5bLKCLW8djMPt4dAGN0HNES44TRSKV69ydQflRSV4ooUIfO8ZQOe+KuW cNPB95Lx1b486jiku1/NsD+HOz4VGBwu5h5QkKmZLtOAMdEPX5bdqFRWiteokiDz6yJ3 bXUIhtRKTXmQJm/+i09kq6TW1Rpi8C34zY5gMpl1+ICcuFx3rYA4ilGeTkiNBdqXGsZ3 o6P3ne7IRr2vQEW+jBvsx857SEAmvLGyhZAvZaTODGCmeLsOcKKpWoWXBtoIwQQLPq+E ps0r4h+cxYeILF6sFCvksmxfWqnlkvwiv8hpq4BWW3tzomwvddSCVXapel6Rx/ce40EK xhvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s05yJW4L; spf=pass (google.com: domain of linux-kernel+bounces-24865-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24865-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 m12-20020a056402050c00b00557c159731dsi1510996edv.547.2024.01.12.08.37.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:37:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24865-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=s05yJW4L; spf=pass (google.com: domain of linux-kernel+bounces-24865-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24865-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 734F11F22B75 for ; Fri, 12 Jan 2024 16:37:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4631074E3F; Fri, 12 Jan 2024 16:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s05yJW4L" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 D944D77656 for ; Fri, 12 Jan 2024 16:36:27 +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-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40e68ca8b45so5028465e9.0 for ; Fri, 12 Jan 2024 08:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077386; x=1705682186; 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=s05yJW4LVxTTdr1T+ybkziivMzscUXlfoSb/PSt/1uy+0UC2WWnuXaWSZZWMQ8YaKy Pgc45rcT5YcwB6w/uTouIyP9BD/ZqsEi1+77/rjT7hiS/9Um3k513ygGI4oKOZ0ro5jN Mn+8vuaUK9RSLsdXG8dPyHLD3pIkp2p4GlIZTd4yjTW7Kzydvt6Q2CdVKYSViHupnNV3 hhe3ri2xRiEXIY7JEQ6/Dck74lP7nZ93HwYhgnyDPkMVXw0lNGb9mQMWnnTuqT6pAKDc gqgoRDEuIu+rcvr9nKQCEKhpWhRXDOUgh8wYpcHOl4W4mYXsb38ElX5GZWO06tMFsJ+u uyUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077386; x=1705682186; 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=j3mm1YD+j4GART7nHFIrBl62PvB3x4iRJDhT6XvNIgaLQQNI0tz03KAcLLepoVqK1w jpxZ9U4P6ScfzMkG+qpepxX4tAL08+eXpbBxUbKvr7NZvTfvs6N3KbmIQ/4A8jFczTiQ 2eHRAQMrX6FDwQBsfPg3KXsQWYDrPn+MJJgf6y8B6YOjWIJhNStl2cDzBK7w7h+bNRvz tJqKquOJvnQSzVLbEu93q/1kOsiCgsUxic4qefPSXTdggGAvz8z3x3zwr6sMpTCLNBhZ PBOVEvukYWTSDVwRVYAOZmPugk6VBgIUexn+04LhKsynk/0LDEQ5WteJcnPy2EFEeFCt lWEA== X-Gm-Message-State: AOJu0YxK3GftYC/Tkd0IwtgwXlyzmUglqmoRHx5KsDxbsnrtdiPknaHH xfl+NLkXXaB6I1DKmrqY3E6iTiqk8MQZ3w== X-Received: by 2002:a05:600c:4505:b0:40e:5534:f6fb with SMTP id t5-20020a05600c450500b0040e5534f6fbmr1019053wmo.165.1705077386295; Fri, 12 Jan 2024 08:36:26 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id bd16-20020a05600c1f1000b0040e5a93ae53sm6573195wmb.22.2024.01.12.08.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:36:25 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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-i2c@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Sean Anderson Subject: [PATCH v3 3/5] ASoC: dt-bindings: qcom,wsa8840: Add reset-gpios for shared line Date: Fri, 12 Jan 2024 17:36:06 +0100 Message-Id: <20240112163608.528453-4-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> References: <20240112163608.528453-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: 1787903311015048642 X-GMAIL-MSGID: 1787903311015048642 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 Acked-by: Rob Herring --- 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 12 16:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 187790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp295036dyc; Fri, 12 Jan 2024 08:38:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjUyIgfU1sC8v3MZtjqbectWf/9QrEjycqOlB3IzqTPWnOk0X22mqqi5KVWi+GT0Ta5cIh X-Received: by 2002:a17:90a:8a11:b0:28e:1212:3dcf with SMTP id w17-20020a17090a8a1100b0028e12123dcfmr711086pjn.68.1705077500961; Fri, 12 Jan 2024 08:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705077500; cv=none; d=google.com; s=arc-20160816; b=qQ5XyGhDZuTYbiRZSTmimg8aU49hC7fN5ap4lHAcTVeUayxLzuQmZAR+Tka4U0sxP7 BWRxOyjheBU0umfDSWF3b5sJ3veq7g4OC4hOfdgk3yJ4hT/gud/NJyOnqNkNnUIz4CQm JEaPaNx0HvDk6JMhcPoKR1wDHdWjxWouPbhWD0ZcILQGlDMzq5FhlInm1ZKt9zob5OEd 6aV+ksfnZjc3UZYD0har3Czo7Q0+wpETyW6iOdRxQXfnuqLet6FeetjJPratzTZUnIlr ruCk0rlR9IuUnfgqr9ztmzvOGUI6Gsdd+jAf1cxVEvKNr6oTJvuJP1nZexyZCuNc3HmK 6YQw== 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=qJ0gjfKMOfp9CH0Fl1AfdBLtnAI1t5WhWrFWLERW/vA=; fh=+9Max/V/7cjj8RZEj+C1lXQLChlj/u+Ka2QetC5y70Q=; b=qVbC3YSu4w4lFWJBz1lDZJwDYBjKoYBmNC/Ftoa4PxIF4P1AbL8ZbDKZqOTkWlm9PJ QXurP4ti0dDbTPsooTg4gHPJZ8y/EqagaLs4YdtI/T736kgr2HP8kP7Y8A1B1F47Rytm FGGXeg+odF/EoRNrsXeiGNcXYwDtZpjBXegRE7JKKZPPL+uigPamNnNvySbE9ygOtYsk 3hQ+Gh5fGe44uBwdtd8O0xuFNt42cBXMdH6lN5Lcu9hpHFO36z6wpXohW3CIuv/EVGmp XFQyoRy5JMIRrZB2OUjS96l3AN6CcYtLeCpw4beHRJGEmeS4adi/BWtWM4JR1oV2N8iM WIVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=crFy3OhX; spf=pass (google.com: domain of linux-kernel+bounces-24866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24866-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id la6-20020a170902fa0600b001d5a61ff46fsi1360773plb.505.2024.01.12.08.38.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:38:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=crFy3OhX; spf=pass (google.com: domain of linux-kernel+bounces-24866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24866-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 09A85B22C7E for ; Fri, 12 Jan 2024 16:38:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94D637FBAB; Fri, 12 Jan 2024 16:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="crFy3OhX" Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 BE14077F24 for ; Fri, 12 Jan 2024 16:36:29 +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-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40e62e6e3b0so14029505e9.2 for ; Fri, 12 Jan 2024 08:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077388; x=1705682188; 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=crFy3OhX9eZtbss3gYEfpxA4SPcDBc2AGE5zY0Z4ap2j4Amtc9vH+ZJ2wwyrQ+y0fc sD2hwMPhVoZpQf0207k7tJJeugRSKYcJs6IcLTaCgF44CF38rZVSjyA8RG2HR68HPpNG uR3z9RIIw9ylGg+QB5RLNh17hnTT4UP7HGINuezoII0pAwISkhf7HDFr4oTxrFHGAsYz 0E/ZONyYbgctJKUS8dmCeRi+Xl1OrutehtQf+rWfR1gQEB3CaYZGfH+1sqIxzsJgMgeb sdqKv6nLX28pmyNqhyXS7oFGwOj5cXLvDFpV0Nvz0o0tekNwqhVVDW01r7XkDYtY0nRV nHRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077388; x=1705682188; 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=Uwcz4KIncTl6FxXLlpqn6kq6DVHYyhE5w953fvmtXhR8kwB9Jhk/ofy9+3f3AQuBjN cWUkLTMYr6lgfZ4YaouzKAkCBaTtX3+FyeA6OEvlUaeMhutZ4Lz3td4lBaZ3iTaxtmf4 GybKFEFZ51c8U3w+w5PeSGCXumq8MFcz6xDmzyDzoh1AlzfOX+oHigPPxT+YpCIxkjYG FMi2u2jL4aNXCR0xuOjgoPUEmOHVLNhm9Ni4g+0tbCu7yBTl5OAzzLUI6fjUz9CGTeYp +QECPbDSzo8GV8BXrkpDtbu6FalTQj8eOtLJ2LQQ3srlpp5JtEwGv0zjOK7CB945+SNB xJuQ== X-Gm-Message-State: AOJu0YwkX+CGMH0y9/imUWq0oHcE2uzIYIfQJoPjlHtrv967TyR4eseg cKnP0tV+ucWDPUW8zzYEn2I1YnDCONzwSA== X-Received: by 2002:a05:600c:181b:b0:40e:437c:7db2 with SMTP id n27-20020a05600c181b00b0040e437c7db2mr665698wmp.211.1705077387970; Fri, 12 Jan 2024 08:36:27 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id bd16-20020a05600c1f1000b0040e5a93ae53sm6573195wmb.22.2024.01.12.08.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:36:27 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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-i2c@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Sean Anderson Subject: [PATCH v3 4/5] ASoC: codecs: wsa884x: Allow sharing reset GPIO Date: Fri, 12 Jan 2024 17:36:07 +0100 Message-Id: <20240112163608.528453-5-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> References: <20240112163608.528453-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: 1787903345791749427 X-GMAIL-MSGID: 1787903345791749427 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; From patchwork Fri Jan 12 16:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 187791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp295146dyc; Fri, 12 Jan 2024 08:38:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEu6FjhYqTdS7ZQaygsL4LZqMj0jnuJx65iAUpwolNdj3ars3iNE5haDZwN3rU1RTmtYZFj X-Received: by 2002:a05:6871:6289:b0:206:32c:e984 with SMTP id re9-20020a056871628900b00206032ce984mr1750326oab.9.1705077511151; Fri, 12 Jan 2024 08:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705077511; cv=none; d=google.com; s=arc-20160816; b=jg27lfrH8J/K/PJLWGuuOUuQI7bb1IeWZDjqw103FpQn63DdHPWq98sK/IxsWvgTEI UDcGX4yhRCXn4OnmyF3KjjtnuyQGEL2CBMXlcxq+uqFqc9iGffYztL7pa6JsvlxulCcv RH68xUR4XHAkWmyl0TOQ+CMmT52y09v/YP2YzNCjUu8U8iGTfw8fxyLF6gmxjUlZ2SEr qnUmdIBDXfBGGk1NcRLa+0aiCdxA8ed0CSXGob7WFZg8Cwxk3QjSCK/bU7HspEPfuTak dXi2RR8aX4sXIDOKCrGchN3t8y793csmEjvZDht8JwTrzmPzm7K2Q9zoTPnZKhj5Iz+2 MdJw== 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=+tAwGTFBvrjSR+D7qo0JkBwlnmAMUSdISzHDQJb3VJ8=; fh=1uhmN9+TkwIK7+W3IRxzy43JZJH7koq07cxoiS8OF+E=; b=EU5a4rgL6eDEK5kHCJW6Xk8GkMwNw1hJnqIfCE0H/Q+mHxSZvN0ktfSTC7V9eDgyLP XSxVnTUJutKEbkMyeoCe1JVKLPyefU2zrB7h5BxSM50iqDdUAADiytAIyneM9jBz5kVc Ftx6X/G2BIluaa3eRsFl8tddVm6ht8sND570DNDTmaUC1B6Tl20eQUlJ2ADS7Kq0as77 aUZXy6hN3P9Z9oO8Hludf+mYlfstuHZKwjV2mx4uG+rwLHo+QICQ3ougyKQ/Da3k66G4 Ps5r2jVTW2EzJcUH5nUF/YuXm9Kl0jee2thq2eBoV87WW3q3Cxi6Wfl+iEwG4Yv7qbKr qLBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SJAM6Zhq; spf=pass (google.com: domain of linux-kernel+bounces-24867-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24867-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 75-20020a63014e000000b005c600ffa335si3568377pgb.217.2024.01.12.08.38.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:38:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24867-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SJAM6Zhq; spf=pass (google.com: domain of linux-kernel+bounces-24867-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24867-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D69ECB229B6 for ; Fri, 12 Jan 2024 16:38:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 047637FBB9; Fri, 12 Jan 2024 16:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SJAM6Zhq" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 6FFEA7E76A for ; Fri, 12 Jan 2024 16:36:31 +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-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40e490c2115so32730485e9.0 for ; Fri, 12 Jan 2024 08:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077390; x=1705682190; 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=+tAwGTFBvrjSR+D7qo0JkBwlnmAMUSdISzHDQJb3VJ8=; b=SJAM6ZhqX5sQrxdeKesiLB2E7w0LvCgHKx799uY5OLzvjo4NxuzDGrBLhPq9BPHVdI Z++P/Rah05n4B9lWwAR2+RA1/j9dKLQ1Yu74L6X+sx6eighuBIgINITPXCwGUqZycIAv b7NUMuNA+hnOTUNoJz+xNwvfechsPnBh3M4vdYxOAF5q8mzeT0VYXxOsy+fjApbmvzy1 4TW3mGl7GGzcrqpfQM1hWEKqP8OjOYKPUmhKevd/XPabFaYHDDOnc/GCo9rvvvddM176 CKWfvGzBtaAk9txmeG+//CrjiT96qxRt1mZv78RjSMdfNlToQXQLHtt5cBc89f4W/s6a ZFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077390; x=1705682190; 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=+tAwGTFBvrjSR+D7qo0JkBwlnmAMUSdISzHDQJb3VJ8=; b=PbKU5S73D7ZsIxy0hWiUWv1ESVd9wFNgFzMyUnjrIsuwpIzgVLIDdzDhK9DdVPfngi CO/vmYWjsHv55sN8rG26sXKwc2Ddf7EpyzkpGhNwKmQB1IevX53TYDMNSHIFXSt/k3oV n54646MAdNT5DL07x9a6zZCHE5VnlvDn4Y2zpyljjZHkIVi2PljSS/kl/FjpazM9EKSh xkSm6RZtBFRH+rw1RC0Ex8O22EiQhM2wh2087RoLj0m8l39wsLpbFnNvQBHTG6rb9WMV sCaqCLKpe05F9aD6g1Ir5bHMOIzjZp6VpJKdXjqI8kt/K2V8CJdDO1ZzD5dM0T4haa9/ eC9g== X-Gm-Message-State: AOJu0YxfcsdTY38QmNYZRVQQ4ZGGe7iUbxNPu2OsTksD9ytICKX2Pqz3 GgDXPmnmbIuQeFxXjTdhgWG/pJ842CW07w== X-Received: by 2002:a05:600c:1c25:b0:40e:4613:daae with SMTP id j37-20020a05600c1c2500b0040e4613daaemr1033231wms.30.1705077389852; Fri, 12 Jan 2024 08:36:29 -0800 (PST) Received: from krzk-bin.. ([178.197.223.112]) by smtp.gmail.com with ESMTPSA id bd16-20020a05600c1f1000b0040e5a93ae53sm6573195wmb.22.2024.01.12.08.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:36:29 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Philipp Zabel , 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-i2c@vger.kernel.org Cc: Chris Packham , Krzysztof Kozlowski , Bartosz Golaszewski , Sean Anderson Subject: [PATCH v3 5/5] i2c: muxes: pca954x: Allow sharing reset GPIO Date: Fri, 12 Jan 2024 17:36:08 +0100 Message-Id: <20240112163608.528453-6-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112163608.528453-1-krzysztof.kozlowski@linaro.org> References: <20240112163608.528453-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: 1787903356043679990 X-GMAIL-MSGID: 1787903356043679990 From: Chris Packham Some hardware designs with multiple PCA954x devices use a reset GPIO connected to all the muxes. Support this configuration by making use of the reset controller framework which can deal with the shared reset GPIOs. Fall back to the old GPIO descriptor method if the reset controller framework is not enabled. Signed-off-by: Chris Packham Acked-by: Peter Rosin Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20240108041913.7078-1-chris.packham@alliedtelesis.co.nz Signed-off-by: Krzysztof Kozlowski --- If previous patches are fine, then this commit is independent and could be taken via I2C. Cc: Chris Packham Cc: Bartosz Golaszewski Cc: Sean Anderson --- drivers/i2c/muxes/i2c-mux-pca954x.c | 46 ++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 2219062104fb..1702e8d49b91 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -102,6 +103,9 @@ struct pca954x { unsigned int irq_mask; raw_spinlock_t lock; struct regulator *supply; + + struct gpio_desc *reset_gpio; + struct reset_control *reset_cont; }; /* Provide specs for the MAX735x, PCA954x and PCA984x types we know about */ @@ -477,6 +481,35 @@ static int pca954x_init(struct i2c_client *client, struct pca954x *data) return ret; } +static int pca954x_get_reset(struct device *dev, struct pca954x *data) +{ + data->reset_cont = devm_reset_control_get_optional_shared(dev, NULL); + if (IS_ERR(data->reset_cont)) + return dev_err_probe(dev, PTR_ERR(data->reset_cont), + "Failed to get reset\n"); + else if (data->reset_cont) + return 0; + + /* + * fallback to legacy reset-gpios + */ + data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(data->reset_gpio)) { + return dev_err_probe(dev, PTR_ERR(data->reset_gpio), + "Failed to get reset gpio"); + } + + return 0; +} + +static void pca954x_reset_deassert(struct pca954x *data) +{ + if (data->reset_cont) + reset_control_deassert(data->reset_cont); + else + gpiod_set_value_cansleep(data->reset_gpio, 0); +} + /* * I2C init/probing/exit functions */ @@ -485,7 +518,6 @@ static int pca954x_probe(struct i2c_client *client) const struct i2c_device_id *id = i2c_client_get_device_id(client); struct i2c_adapter *adap = client->adapter; struct device *dev = &client->dev; - struct gpio_desc *gpio; struct i2c_mux_core *muxc; struct pca954x *data; int num; @@ -513,15 +545,13 @@ static int pca954x_probe(struct i2c_client *client) return dev_err_probe(dev, ret, "Failed to enable vdd supply\n"); - /* Reset the mux if a reset GPIO is specified. */ - gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(gpio)) { - ret = PTR_ERR(gpio); + ret = pca954x_get_reset(dev, data); + if (ret) goto fail_cleanup; - } - if (gpio) { + + if (data->reset_cont || data->reset_gpio) { udelay(1); - gpiod_set_value_cansleep(gpio, 0); + pca954x_reset_deassert(data); /* Give the chip some time to recover. */ udelay(1); }