From patchwork Tue Sep 3 07:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788212 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 64FA1CD342E for ; Tue, 3 Sep 2024 07:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LWcU6RysEIzIJ6pAz/3hn/zvAsi9B5aKaEc9SGRcJtw=; b=S+etXXLH+Ta0+xObHa3epVeDxq CNn7cUSeERrlgYMVsTayuJlsLIyhdKGjFuIqEEwZ4gID1iBjgN6fO4jjWOvCpqIRouX5d76Rhb6EH 2lyb9owtUSOtuX7w3rRL2l97M2VY2hTBvvBCjL9HLfYUtVlIdqMpyeT+BJoc5ZeDe8tr6LOZpgDRU Bs08qahCBtndMdTHPC+lQdQyZ//4/zm8QIru76EE+QjhK5iNtmhV/4v8naTrQvg1x7Bt/hirWqgtf rxLPpd4XsgurWz2Y4KcoGsafOUw1kScqtRoe2qsXPPy5omJbvhqH8hOjz7YEYALCCOCITeSCJDPQ9 /QCZ02Vw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slODH-0000000GjrV-2QJe; Tue, 03 Sep 2024 07:44:31 +0000 Received: from mail-m6039.netease.com ([210.79.60.39]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6R-0000000GiKM-0iKG; Tue, 03 Sep 2024 07:37:31 +0000 DKIM-Signature: a=rsa-sha256; b=QE83XfVJnV872hJcBU3fCDGXKPJcRmU2IbwwAUj1MFHXdryNNCujqgVyPsWLD/oY+Bdl12msXxMHPJJS9gKSgGSyQF5FfH22M9ijvEpHaubR0/f6IFqc6YKofEaaxMPfAYPKCexKbacA6Qq4HBXYe50ututOjywi/tNf7VCVFpc=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=LWcU6RysEIzIJ6pAz/3hn/zvAsi9B5aKaEc9SGRcJtw=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 1E0FE7E06CB; Tue, 3 Sep 2024 15:37:03 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 01/12] gpio: rockchip: avoid division by zero Date: Tue, 3 Sep 2024 15:36:38 +0800 Message-Id: <20240903073649.237362-2-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGRkfTVZCShhKH0lNH05JHUJWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0d04409cfkunm1e0fe7e06cb X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Pi46EBw*CTI6NEkUFhwVFSIf PwEaCRZVSlVKTElOSE9CS0lPTUpIVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSU9LSzcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003728_273437_42B967E4 X-CRM114-Status: UNSURE ( 8.31 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the clk_get_rate return '0', it will happen division by zero. Fixes: 3bcbd1a85b68 ("gpio/rockchip: support next version gpio controller") Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 0bd339813110..712258224eb3 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -207,6 +207,8 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) { div_debounce_support = true; freq = clk_get_rate(bank->db_clk); + if (!freq) + return -EINVAL; max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq; if (debounce > max_debounce) return -EINVAL; From patchwork Tue Sep 3 07:36:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788199 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C2DA8CD342C for ; Tue, 3 Sep 2024 07:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aKIFSG7psQm1vWjapk5w2XfwNBNv7IDfrqqRzIJzccQ=; b=VNSCRWtC8XXs+FL8dqYivYQ3OI ohRam5bGSFLnAJ8SgxoM1K8s6mX74s7CFiQrRKlsAM8bm8e39b7jWI0AjyJKhl0xKd90j6sZbBIBo jRMMZ5VPdfGg2Y8HCehABptpviV6f4T6UjqG4D2sFpZxpxDIx4dofreWDVHfyngeqEEjeoYy3KKna gdEQKpkYg4/AfPFoFSkFfTvwTNBGc8+KU4hQOXsYBDivCVQMYL4Gbz48DEOw79cF2ngt8cW02Klej ClaLigVAPPCCf/vsbaJY4jof0sBG4N4Ps+tEsUUtw3BkxXN+xli0dJkD3r0KxmWqtR4nMWKnx2noz pe+zj4CQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO82-0000000Gik4-0GWm; Tue, 03 Sep 2024 07:39:06 +0000 Received: from mail-m6039.netease.com ([210.79.60.39]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6P-0000000GiKH-41dx; Tue, 03 Sep 2024 07:37:28 +0000 DKIM-Signature: a=rsa-sha256; b=YUPQenCZLsF1LQYjiZQWJFdQfS1EbqjWN9BC3pkl+b59EEc0AKT9zaaK7QXHnMHeqUzze+eoOwnlkAqs3jDvg5zZnnJDON97rw+/PW3ylHjHJokBVdssjTAvtTZg577oVMxSeiwG3Y8OiNFv7MDV4UU8oKSGDO0E1ehlRtRUBxM=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=aKIFSG7psQm1vWjapk5w2XfwNBNv7IDfrqqRzIJzccQ=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id B04CA7E06F3; Tue, 3 Sep 2024 15:37:04 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 02/12] gpio: rockchip: release reference to device node Date: Tue, 3 Sep 2024 15:36:39 +0800 Message-Id: <20240903073649.237362-3-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGRhNQ1ZIQ0lITEweQxpKTE5WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0d68609cfkunmb04ca7e06f3 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NRg6Sxw5AjI3GklWPBMRFRlI UQsaCjVVSlVKTElOSE9CS0lOQkpLVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSUhNSzcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003726_640777_8D68F98A X-CRM114-Status: UNSURE ( 7.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Added a call to of_node_put(pctlnp) in rockchip_gpio_probe to properly release the reference to the device node, improving memory management and preventing potential leaks. Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio") Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 712258224eb3..5f60162baaeb 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -715,6 +715,7 @@ static int rockchip_gpio_probe(struct platform_device *pdev) return -ENODEV; pctldev = of_pinctrl_get(pctlnp); + of_node_put(pctlnp); if (!pctldev) return -EPROBE_DEFER; From patchwork Tue Sep 3 07:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788211 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 143A8CD342E for ; Tue, 3 Sep 2024 07:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gdGxnEFCwoF+dZLxfO/pczGvZ3xJZOxamH4IgiqR/d4=; b=gonifxthAApFvixlBYHPB8RED1 H9F+c2d/69NzteZPgbXpaRmtWv2lDksoGThMIY0LLZAMOsKlWWfudBRHezMIgUpxVW8i7KvOqrfmq rDJzc1N1a8+rBhMuG2curK2JK/tAzjYVfLGSvJPfM7gwrEYv621F7pPUBxXxGvIbwdlLZYGXuOxcr XnHE8d/+dxgSu/aLOnM223Ag4ByPA9gy37P9fUVybrv+9nmXKyX03QfAXQJAxyJWwdtRpzOeHtLQt DrffLi4w+VGLh8P76flQamSaCwbTydVGws70Hf75JJ+W4uI7KYeN6FB62WANXZfnj1Wq5LF83UoGM he8r6yaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOCO-0000000Gjhe-3wYq; Tue, 03 Sep 2024 07:43:36 +0000 Received: from mail-m24122.xmail.ntesmail.com ([45.195.24.122]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6Q-0000000GiMh-41IY; Tue, 03 Sep 2024 07:37:30 +0000 DKIM-Signature: a=rsa-sha256; b=eHCUsYDijVCUcxN5WpfM6rMoU/EtMl+FlpL0m4xDYX/kWcYs4aTZhpNYUnP864K/69dIWzDEpmNOtPg3TdSKD1ephNOcFUvyLoXvfLg7nfij5uiSrmanrAa9aTZs/2xewbQx5kp2QEA2QBbD1zIuH6qhP7Us7xa6TMzFDhCfzOo=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=gdGxnEFCwoF+dZLxfO/pczGvZ3xJZOxamH4IgiqR/d4=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 046827E06E6; Tue, 3 Sep 2024 15:37:05 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 03/12] gpio: rockchip: resolve overflow issues Date: Tue, 3 Sep 2024 15:36:40 +0800 Message-Id: <20240903073649.237362-4-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQkNNGlZJSxodSx0fGB5MSkhWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0dbcf09cfkunm046827e06e6 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MSI6CDo*EDI6PEkVSxxMFSke NTkwCktVSlVKTElOSE9CS0lMSElDVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSUNPSTcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003727_445862_5C474F80 X-CRM114-Status: UNSURE ( 9.59 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Prevent overflow issues when performing debounce-related calculations. Fixes: 3bcbd1a85b68 ("gpio/rockchip: support next version gpio controller") Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 5f60162baaeb..6dcb8bb0d1b4 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "../pinctrl/core.h" #include "../pinctrl/pinctrl-rockchip.h" @@ -209,11 +210,12 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, freq = clk_get_rate(bank->db_clk); if (!freq) return -EINVAL; - max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq; + div = (u64)(GENMASK(23, 0) + 1) * 2 * HZ_PER_MHZ; + max_debounce = DIV_ROUND_CLOSEST_ULL(div, freq); if (debounce > max_debounce) return -EINVAL; - div = debounce * freq; + div = (u64)debounce * freq; div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1; } else { div_debounce_support = false; From patchwork Tue Sep 3 07:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788210 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1B4E2CD342F for ; Tue, 3 Sep 2024 07:42:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tuUUQKIit1GImHErvUOMrTxOdciWFx+2Duf2CiFkka8=; b=CaQcHudHT3KJtWuCVf42uKJGdO noOgo6i73JZPlR272Xp/6NTPc1r+Vf+/f5fgJEVPQB0Y8pOApKLBhkSozdmQaptJht+U1KygyCZz5 PW6JG0q6YToLAmHF0hF7NnuzTxmS5OusY1ttDb3PGzvg6Y+1EjUW+danKBUI5qJ4x45aGd3n+2j8w ra69vsEgzQbFQGDX7/BcEu1h/ImawYTxBsTGfrxLqAN/nQxBnUEWiokMArpzXxepdNJtPJFY3Qiwx Zpz8SYPHMyPulvUFnJTqAmRkhO7Tr/v8NWOiU7pNShSdLxdVQO34NynEjKMLbNjzk3N2Sy22K9WlN vA+xtpnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOBY-0000000GjYM-0ACi; Tue, 03 Sep 2024 07:42:44 +0000 Received: from mail-m1287.netease.com ([103.209.128.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6R-0000000GiK7-2s5g; Tue, 03 Sep 2024 07:37:30 +0000 DKIM-Signature: a=rsa-sha256; b=a4ohL4HlhTGP0jZauLjo3lFgPfY9LKR56FWV/mpCdiukP1y4Z1B2Its+Wx5Onl0z2/qCz8veBBULfNMFBVXUfbGBHqjSlKjSz8dyz5rw1H8XQWV5G7b+x0Ht4u8UZ2WCvGDPpJNO7pTMK81jHObSG1dB/JjGp1GZxVVhyFNnPG4=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=tuUUQKIit1GImHErvUOMrTxOdciWFx+2Duf2CiFkka8=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 6C1FB7E0196; Tue, 3 Sep 2024 15:37:07 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 04/12] gpio: rockchip: resolve underflow issue Date: Tue, 3 Sep 2024 15:36:41 +0800 Message-Id: <20240903073649.237362-5-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGk9JTVYeHk9JTxlNQx9CHk1WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0e13409cfkunm6c1fb7e0196 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OSo6DAw4EzI9EklKFhwoFSEs TjwwCxpVSlVKTElOSE9CS0lDTE5MVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSUxCQjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003728_018658_83726F69 X-CRM114-Status: UNSURE ( 8.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org div_reg may be < 0 if debounce is zero, causing the unsigned int to overflow. Fixes: 3bcbd1a85b68 ("gpio/rockchip: support next version gpio controller") Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 6dcb8bb0d1b4..26191197cd37 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -205,8 +205,11 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, unsigned int cur_div_reg; u64 div; - if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) { + if ((bank->gpio_type == GPIO_TYPE_V2) && !IS_ERR(bank->db_clk)) div_debounce_support = true; + else + div_debounce_support = false; + if (debounce && div_debounce_support) { freq = clk_get_rate(bank->db_clk); if (!freq) return -EINVAL; @@ -217,8 +220,6 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, div = (u64)debounce * freq; div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1; - } else { - div_debounce_support = false; } raw_spin_lock_irqsave(&bank->slock, flags); From patchwork Tue Sep 3 07:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788201 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DF351CD342E for ; Tue, 3 Sep 2024 07:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=i3Ih0qHoA8BaoqENjDe44S2TQECjEhO9KvAw8e9oDoQ=; b=n/DIcYePEmQwwRaiAmT+4nk1+B AsKUAyrvieX22PElbGd1jNCpdoVBSq2WaQp3FXJezRB5jD61bIvtU4iI2ukPqIwJj8xy8DPDQzDCQ V1b/MpSlOjDuQABzN/abt8RYxhMIltq0zGP0HmtVwTEaS9fPo4O1egtvu8UUMKjGsSjd6FlNhq6xm Rqy1zXcCUJvuTB7pNb8KEfwShyzRbFxcrqXBNSbcfKoZGfW7EMzRMMbB9pUaYFMOINKlMLKWYqZXk U8UMsNS10lFXYivf5mDqjcN7XQ2eZ5Zhqo8ZpawFgTl2TLzKWcsgnDtKln0+2oczZToUa44eeSoQw niLGiyiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO9n-0000000Gj69-0p4O; Tue, 03 Sep 2024 07:40:55 +0000 Received: from mail-m1287.netease.com ([103.209.128.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6R-0000000GiKi-034f; Tue, 03 Sep 2024 07:37:29 +0000 DKIM-Signature: a=rsa-sha256; b=IUKg42GNT3xefHxZljlCyU0i5Ir/n0Tdxfi7ukaqzx/HGz+c4C/Idpy4zESZzqtC+jSEj0N09lQzk/dLj2E3YOLA/4szuvdCjKxw6CHBIh9oPIdzHOKMqYiGb1FeEyhCMHzmvRhc09QFRUi/Wb0f4QaqCxH8AXHk8KvtEAYkVmU=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=i3Ih0qHoA8BaoqENjDe44S2TQECjEhO9KvAw8e9oDoQ=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id D3C227E03F6; Tue, 3 Sep 2024 15:37:08 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 05/12] gpio: rockchip: fix debounce calculate Date: Tue, 3 Sep 2024 15:36:42 +0800 Message-Id: <20240903073649.237362-6-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQ04dTFYYTE1PQ0MZTklLGUJWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0e6d209cfkunmd3c227e03f6 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NS46Aww6IjIrS0kZLBJKFRhO H1FPFDVVSlVKTElOSE9CS0hLSktIVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSUJDSjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003727_418757_8FFFF11F X-CRM114-Status: GOOD ( 11.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The previous configuration ensured that signals with a duration greater than the debounce value would always be detected, while signals with a duration less than debounce / 2 would always not be detected. After the modification, it is changed to ensure that signals with a duration greater than 2 * debounce will always be detected, while signals with a duration less than debounce/2 will still not be detected. Fixes: 3bcbd1a85b68 ("gpio/rockchip: support next version gpio controller") Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 26191197cd37..75355f799751 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -213,13 +213,13 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, freq = clk_get_rate(bank->db_clk); if (!freq) return -EINVAL; - div = (u64)(GENMASK(23, 0) + 1) * 2 * HZ_PER_MHZ; + div = (u64)(GENMASK(23, 0) + 1) * HZ_PER_MHZ; max_debounce = DIV_ROUND_CLOSEST_ULL(div, freq); if (debounce > max_debounce) return -EINVAL; div = (u64)debounce * freq; - div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1; + div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC) - 1; } raw_spin_lock_irqsave(&bank->slock, flags); From patchwork Tue Sep 3 07:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788200 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1063BCD342A for ; Tue, 3 Sep 2024 07:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7nRvTAtpOVPJggbNeOvMCvQZFTSEWKhokB5ph5TViJI=; b=oMR4iCbd7zXUpKJ9+3hb88okar ES45B1wfsH4qk3yfKxbnK8gJAFW/lvfMYFitx8MTl7m1gXhBVcZYO7UXtH8ye3eNTb4jqJSF90vtx 4LT+l52Tk8eUZ753btujrYA5tzpXbiK9usRDRfAXii70vUNHyRzIQIGWmPacBj57ftX0ZWv4RllgE 5x2ZzicNTOuvE0gSKCLszkEaN4J8symM4ua/DeuXtQdlJHrrykJMLiaR7yDnpBKMy8U6+jB22i2FO 4jrdL6kYwtQ1iX+C7KioT6Fl+DHFYnbF2lb1N6G9eJKGyZL+nSfUC1lWv28CxxI7yaZKve3nESHvN KSXW/qlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO8u-0000000GiqS-07Cv; Tue, 03 Sep 2024 07:40:00 +0000 Received: from mail-m1287.netease.com ([103.209.128.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6Q-0000000GiKr-29f7; Tue, 03 Sep 2024 07:37:28 +0000 DKIM-Signature: a=rsa-sha256; b=H9poSmo4xSa6QADD84RJSRUCKv1ladIurqaxJKovOewpQjJDG6iFTbvjUgygFdLECHeilF/Ia8D5sWJVJLst18w6RrmG9ZBRwJ5YpGlVqoRmRkh5LQDrSOYiWussNGAq+oS5YVStHbw2kxu+vxjZ4rat8EXYuCHYaCyysrijRio=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=7nRvTAtpOVPJggbNeOvMCvQZFTSEWKhokB5ph5TViJI=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 342397E05B6; Tue, 3 Sep 2024 15:37:10 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 06/12] gpio: rockchip: Update debounce config function Date: Tue, 3 Sep 2024 15:36:43 +0800 Message-Id: <20240903073649.237362-7-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGR0fS1ZJSUMeHR8fT0JPHx9WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0ebff09cfkunm342397e05b6 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MAg6Ayo5KDI8MElDLBwtFR4r SRpPCjNVSlVKTElOSE9CS0hKTktKVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSEhKTjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003726_846536_5B60D226 X-CRM114-Status: GOOD ( 11.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the GPIO with version number 0x01000C2B, debounce configuration is already supported. Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 75355f799751..2e80f28bb0c4 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -254,6 +254,8 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, clk_prepare_enable(bank->db_clk); else clk_disable_unprepare(bank->db_clk); + } else { + return -ENOTSUPP; } return 0; @@ -282,22 +284,11 @@ static int rockchip_gpio_set_config(struct gpio_chip *gc, unsigned int offset, unsigned long config) { enum pin_config_param param = pinconf_to_config_param(config); + unsigned int debounce = pinconf_to_config_argument(config); switch (param) { case PIN_CONFIG_INPUT_DEBOUNCE: - rockchip_gpio_set_debounce(gc, offset, true); - /* - * Rockchip's gpio could only support up to one period - * of the debounce clock(pclk), which is far away from - * satisftying the requirement, as pclk is usually near - * 100MHz shared by all peripherals. So the fact is it - * has crippled debounce capability could only be useful - * to prevent any spurious glitches from waking up the system - * if the gpio is conguired as wakeup interrupt source. Let's - * still return -ENOTSUPP as before, to make sure the caller - * of gpiod_set_debounce won't change its behaviour. - */ - return -ENOTSUPP; + return rockchip_gpio_set_debounce(gc, offset, debounce); default: return -ENOTSUPP; } From patchwork Tue Sep 3 07:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788220 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9BE10CD342A for ; Tue, 3 Sep 2024 07:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q9p3HERBjpHzvy9d33e3BEdsxmACYt0ZV5dTXXk0BGE=; b=tdKZA+BadDS4ecsvC0oXCt60e1 Rez6WcfZPDHDTICDtAUe2i/j1gKea8wbi5symMZk0Ca7H8uLB12SWJOwHFY3/yCJxxMdRT2TcRPgL PIEwx8PdKN7BI8GIDMe/PGZ76jKFELyVAcVApOdZ+WILrmME0NOXuM7KjIPUzg5WJr8KENh2XsOle WZ/IszCKSernM5Mo2ccP080Xs6BUrpd2bQlw0th2yni/XCL6/ir09wQAYyh6Dl65wsUMe8+sxyN18 mbimAJcQHOh4tw90e2aIxlejF5hwYgnNj48yc+xYbwaFwq4lJhGzHUctNJPPnnzyj75U0o70y4Iom 9x5unMTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOFt-0000000GkQC-0CsQ; Tue, 03 Sep 2024 07:47:13 +0000 Received: from mail-m12826.netease.com ([103.209.128.26]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6T-0000000GiMd-1JsK; Tue, 03 Sep 2024 07:37:32 +0000 DKIM-Signature: a=rsa-sha256; b=Ii74ds9SnwnaDDrCQGKEgzMe1fgQ3dlfN8Sfln7XAvee6zhYZsqAaCcSYT2GRNzURVhuXUaTh7/Q3RdAjYENRls/oKCVD/ukdcH/BKW0Z4tQ9W22M2SUYHTo5z/0ZA2RiGZYx7C3oOwQxeXz7N8/jmisFGNIBBlw9NeGGtiLrm0=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=q9p3HERBjpHzvy9d33e3BEdsxmACYt0ZV5dTXXk0BGE=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 958CD7E05FF; Tue, 3 Sep 2024 15:37:11 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 07/12] gpio: rockchip: support 'clock-names' from dt nodes Date: Tue, 3 Sep 2024 15:36:44 +0800 Message-Id: <20240903073649.237362-8-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGh1LQlZOSEJDGUJPSE0ZQk1WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0f17809cfkunm958cd7e05ff X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NE06Pjo6OjI4HkkTLBE1FRNJ MQMKChhVSlVKTElOSE9CS0hJQ0lNVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBTkhPTjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003730_391586_1234A5F4 X-CRM114-Status: GOOD ( 13.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Added support for retrieving clocks using 'clock-names' from dt nodes Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 54 +++++++++++++++++++++--------- drivers/pinctrl/pinctrl-rockchip.h | 2 ++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 2e80f28bb0c4..83df1632112d 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -650,23 +650,12 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) if (!bank->irq) return -EINVAL; - bank->clk = of_clk_get(bank->of_node, 0); - if (IS_ERR(bank->clk)) - return PTR_ERR(bank->clk); - - clk_prepare_enable(bank->clk); id = readl(bank->reg_base + gpio_regs_v2.version_id); /* If not gpio v2, that is default to v1. */ if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) { bank->gpio_regs = &gpio_regs_v2; bank->gpio_type = GPIO_TYPE_V2; - bank->db_clk = of_clk_get(bank->of_node, 1); - if (IS_ERR(bank->db_clk)) { - dev_err(bank->dev, "cannot find debounce clk\n"); - clk_disable_unprepare(bank->clk); - return -EINVAL; - } } else { bank->gpio_regs = &gpio_regs_v1; bank->gpio_type = GPIO_TYPE_V1; @@ -726,9 +715,31 @@ static int rockchip_gpio_probe(struct platform_device *pdev) raw_spin_lock_init(&bank->slock); + bank->clk = devm_clk_get_enabled(dev, "bus"); + if (IS_ERR(bank->clk)) { + bank->clk = of_clk_get(dev->of_node, 0); + if (IS_ERR(bank->clk)) { + dev_err(dev, "fail to get apb clock\n"); + return PTR_ERR(bank->clk); + } + clk_prepare_enable(bank->clk); + bank->manual_clk_release = true; + } + + bank->db_clk = devm_clk_get_enabled(dev, "db"); + if (IS_ERR(bank->db_clk)) { + bank->db_clk = of_clk_get(dev->of_node, 1); + if (IS_ERR(bank->db_clk)) { + bank->db_clk = NULL; + } else { + clk_prepare_enable(bank->db_clk); + bank->manual_dbclk_release = true; + } + } + ret = rockchip_get_bank_data(bank); if (ret) - return ret; + goto err_disabled_clk; /* * Prevent clashes with a deferred output setting @@ -738,9 +749,8 @@ static int rockchip_gpio_probe(struct platform_device *pdev) ret = rockchip_gpiolib_register(bank); if (ret) { - clk_disable_unprepare(bank->clk); - mutex_unlock(&bank->deferred_lock); - return ret; + dev_err(bank->dev, "Failed to register gpio %d\n", ret); + goto err_unlock; } while (!list_empty(&bank->deferred_pins)) { @@ -773,13 +783,25 @@ static int rockchip_gpio_probe(struct platform_device *pdev) dev_info(dev, "probed %pOF\n", np); return 0; +err_unlock: + mutex_unlock(&bank->deferred_lock); +err_disabled_clk: + if (bank->manual_clk_release) + clk_disable_unprepare(bank->clk); + if (bank->manual_dbclk_release) + clk_disable_unprepare(bank->db_clk); + + return ret; } static void rockchip_gpio_remove(struct platform_device *pdev) { struct rockchip_pin_bank *bank = platform_get_drvdata(pdev); - clk_disable_unprepare(bank->clk); + if (bank->manual_clk_release) + clk_disable_unprepare(bank->clk); + if (bank->manual_dbclk_release) + clk_disable_unprepare(bank->db_clk); gpiochip_remove(&bank->gpio_chip); } diff --git a/drivers/pinctrl/pinctrl-rockchip.h b/drivers/pinctrl/pinctrl-rockchip.h index 0b2b56014b17..bb6df7296508 100644 --- a/drivers/pinctrl/pinctrl-rockchip.h +++ b/drivers/pinctrl/pinctrl-rockchip.h @@ -319,6 +319,8 @@ struct rockchip_pin_bank { struct regmap *regmap_pull; struct clk *clk; struct clk *db_clk; + bool manual_clk_release; + bool manual_dbclk_release; int irq; u32 saved_masks; u32 pin_base; From patchwork Tue Sep 3 07:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788219 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C66D6CD342E for ; Tue, 3 Sep 2024 07:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=W9W3b1cC6JwIHwdDAYaUZzjm26fmoNzaEXMwpd0X3Lc=; b=h7+9ZD+BS1hVnxWz+SpCYlVKVG VWqA/Y9YvkVb9jhXZYSSLUlUllRxup+o3VWso2Jfy7fEKYvloTPYBXAyot0BClesD+wXv0t0mhoIW +1mXIRWgr5qfIGL/2epTSlFWJS1I3R8G11N5K9IU1QuwparWqbmOskj5JBgo8S8+dbxElHwAlESbA 7PG5Ofj7FloOYFT55qQg2z/A3/2kaX4LolNu8S9/pEDf0o31JYp8T6Et9F3nmXWFn1yoB+SpSKfgU scdrSBrFZV2Oz3rj2JDSO0DjbI8cBlxSuwd77F/Kknjk92Y1nnjCUgWhqTYVQuzFW0gLMExLRdSMT hfkrqfAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOF0-0000000GkEM-2ZyO; Tue, 03 Sep 2024 07:46:18 +0000 Received: from mail-m49237.qiye.163.com ([45.254.49.237]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6R-0000000GiMa-3RHj; Tue, 03 Sep 2024 07:37:31 +0000 DKIM-Signature: a=rsa-sha256; b=fdJxs/RD6w9KtJuqvJJCxbAHwT4Kwppi4tvayV5svYfh8Olp2z3Uv7eiQLNGeMY4rb+PQkamZ7X6OshAtuxDGMqIUSd2HfeF2NlATlaMND/PvHyJeV035OfPu+he0rmgRIHnBoBpXKM6ye8KZum4eRxdiAuQieO+L3KtnQ1js/M=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=W9W3b1cC6JwIHwdDAYaUZzjm26fmoNzaEXMwpd0X3Lc=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id E54487E0574; Tue, 3 Sep 2024 15:37:12 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 08/12] gpio: rockchip: explan the format of the GPIO version ID Date: Tue, 3 Sep 2024 15:36:45 +0800 Message-Id: <20240903073649.237362-9-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGkoYT1ZDTU8eTxoZHR0dTENWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0f6a209cfkunme54487e0574 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NRA6Lww*MDI3EklKLBI#FQ8q FRQaFBVVSlVKTElOSE9CS0hPSk1LVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSU1ITjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003728_068084_C5D4F155 X-CRM114-Status: UNSURE ( 8.75 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Remove redundant comments and provide a detailed explanation of the GPIO version ID. Signed-off-by: Ye Zhang Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-rockchip.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 83df1632112d..04a24f1d77eb 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -27,9 +27,15 @@ #include "../pinctrl/core.h" #include "../pinctrl/pinctrl-rockchip.h" +/* + * Version ID Register + * Bits [31:24] - Major Version + * Bits [23:16] - Minor Version + * Bits [15:0] - SVN Number + */ #define GPIO_TYPE_V1 (0) /* GPIO Version ID reserved */ -#define GPIO_TYPE_V2 (0x01000C2B) /* GPIO Version ID 0x01000C2B */ -#define GPIO_TYPE_V2_1 (0x0101157C) /* GPIO Version ID 0x0101157C */ +#define GPIO_TYPE_V2 (0x01000C2B) +#define GPIO_TYPE_V2_1 (0x0101157C) static const struct rockchip_gpio_regs gpio_regs_v1 = { .port_dr = 0x00, From patchwork Tue Sep 3 07:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788209 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 55065CD342F for ; Tue, 3 Sep 2024 07:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YHgiyOsxvY6K4cw4rtUovbYtN4FFCAToL86cwycTCM4=; b=hNyFX1vMV5KfqD46E2ThcoYByA MzzNO+2ZUwro2pvCSvDpeXed1dMUd/CLBzkCSewdCJTUc7eOwWJz20MW8bnRFJ0XPDmsKYyRY80Rq lNuVHgr0gYWpguMYRii/qXVDaEAulvWOnDSdeAlmTTENxTcywatjr9//Gp3iIqIrxbnJBiVIaETQZ H5F2V5/nKG9t2eqfuDHVJPPqqQyDWRl+DB7SFBmPNLB3B9oS1rWbQ40DetnDz4sqqvHr5RXnrv/FY dTKKDs/Kc3dz6sIimit+IBBmx/HAoU/irBfYvRvPRQ+MISrlCHrb7ljP8Gu8uxW0kzWbY0V8le+zZ dZNohbVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOAf-0000000GjLM-34Pp; Tue, 03 Sep 2024 07:41:49 +0000 Received: from mail-m49251.qiye.163.com ([45.254.49.251]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6R-0000000GiN7-1jcK; Tue, 03 Sep 2024 07:37:30 +0000 DKIM-Signature: a=rsa-sha256; b=To3Vw5zwDTrHkUlidzc1QbyWCgNJMuMTi0h7dyi+1imDW5AcuFSUMZlSXmM/F0LHjf3w1Mop8cvPi4z5O4N5fj5/eaSg2VGdSSJLJ595pu7IhDgYr2U1G1RE2l0Z6i3R7dRlGZ9tCbgIxNWNKXnuF8nMyUXSFjJkoGuO1I9b6hY=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=YHgiyOsxvY6K4cw4rtUovbYtN4FFCAToL86cwycTCM4=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 41FA27E0380; Tue, 3 Sep 2024 15:37:14 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 09/12] gpio: rockchip: change the GPIO version judgment logic Date: Tue, 3 Sep 2024 15:36:46 +0800 Message-Id: <20240903073649.237362-10-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQxpJH1ZCTx0ZGR4dSk5JT09WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d0fbdb09cfkunm41fa27e0380 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OCI6DDo*AzI6OEk3PBxPFQgT MjAKFDdVSlVKTElOSE9CS0hOTkpIVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSUxOSzcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003727_665774_60AE02B6 X-CRM114-Status: GOOD ( 10.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Have a list of valid V1 IDs and default to -ENODEV. Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 04a24f1d77eb..579701ad3c6f 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -658,13 +658,20 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) id = readl(bank->reg_base + gpio_regs_v2.version_id); - /* If not gpio v2, that is default to v1. */ - if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) { - bank->gpio_regs = &gpio_regs_v2; - bank->gpio_type = GPIO_TYPE_V2; - } else { + /* The GPIO version ID is incrementing. */ + switch (id) { + case GPIO_TYPE_V1: bank->gpio_regs = &gpio_regs_v1; bank->gpio_type = GPIO_TYPE_V1; + break; + case GPIO_TYPE_V2: + case GPIO_TYPE_V2_1: + bank->gpio_regs = &gpio_regs_v2; + bank->gpio_type = GPIO_TYPE_V2; + break; + default: + dev_err(bank->dev, "cannot get the version ID\n"); + return -ENODEV; } return 0; From patchwork Tue Sep 3 07:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788221 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3D2FFCD342F for ; Tue, 3 Sep 2024 07:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Wn6GkJwhWRWTq791Zs8sxLcCjb5vjEFNBYms3MzvyHw=; b=D6+UTNuByhRjNcI6HimPlIdhgl Zjq8fC+/TQUmz+pWjZO8PmoNzJyd9mzw5Va+o+n1rsNguOwqTfjqj5S1D+UB75z2Jfytjdbz8FozW s/zWdXeV8uGIaCcExHOYxsdndBCW+JfusfZ1hCK825WaZ1GF0CVP1oSCk7Q1rRxzJcdntLeinJQL/ gkSslpWjJ44ZLgJ/+z2u8gb+TO0q64hbUZ886V3UNxcfBQNk6huyJC/XtW1UHxKaTYUIrPKrWhhDE wjLWFl0y9iCD6PaHqQkXGmTWkbUG1+jDHnyRdiA1XnW6ZPRs5LZhiob2TZCjkUdEdynHRq3u4mPa2 21dpMzxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOGk-0000000GkcE-3ARs; Tue, 03 Sep 2024 07:48:06 +0000 Received: from mail-m127173.xmail.ntesmail.com ([115.236.127.173]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6T-0000000GiNt-0Luj; Tue, 03 Sep 2024 07:37:32 +0000 DKIM-Signature: a=rsa-sha256; b=dA5o9xVhK1QRgaUA/cNrN7wOBI14iJktjBG5H947XGoJBMFA+TYndQMPpN0IhrCBILl2U5N3dXBR8EPsWyHFD8goyRi19yHtIbyluMsLINep4ipcna+6mzW0CLi4DzMEai0XGGGMrpSq4XKbpDhg6qhJLMSlij7pnPE2vCIG76I=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=Wn6GkJwhWRWTq791Zs8sxLcCjb5vjEFNBYms3MzvyHw=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 9860B7E0638; Tue, 3 Sep 2024 15:37:15 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 10/12] gpio: rockchip: support new version gpio Date: Tue, 3 Sep 2024 15:36:47 +0800 Message-Id: <20240903073649.237362-11-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQk1OTFZKGE1PGR8aSUMfQk9WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d1018109cfkunm9860b7e0638 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PDo6Mjo*KTIyDklOFhxIFRIp HQMKCxNVSlVKTElOSE9CS0hNQklMVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBTkxJTTcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003729_581489_EF203CD7 X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The next version gpio controller on SoCs like rk3576 which support four OS operation and four interrupts Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 579701ad3c6f..6deebf1dd9dd 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -36,6 +36,7 @@ #define GPIO_TYPE_V1 (0) /* GPIO Version ID reserved */ #define GPIO_TYPE_V2 (0x01000C2B) #define GPIO_TYPE_V2_1 (0x0101157C) +#define GPIO_TYPE_V2_2 (0x010219C8) static const struct rockchip_gpio_regs gpio_regs_v1 = { .port_dr = 0x00, @@ -85,7 +86,7 @@ static inline void rockchip_gpio_writel(struct rockchip_pin_bank *bank, { void __iomem *reg = bank->reg_base + offset; - if (bank->gpio_type == GPIO_TYPE_V2) + if (bank->gpio_type >= GPIO_TYPE_V2) gpio_writel_v2(value, reg); else writel(value, reg); @@ -97,7 +98,7 @@ static inline u32 rockchip_gpio_readl(struct rockchip_pin_bank *bank, void __iomem *reg = bank->reg_base + offset; u32 value; - if (bank->gpio_type == GPIO_TYPE_V2) + if (bank->gpio_type >= GPIO_TYPE_V2) value = gpio_readl_v2(reg); else value = readl(reg); @@ -112,7 +113,7 @@ static inline void rockchip_gpio_writel_bit(struct rockchip_pin_bank *bank, void __iomem *reg = bank->reg_base + offset; u32 data; - if (bank->gpio_type == GPIO_TYPE_V2) { + if (bank->gpio_type >= GPIO_TYPE_V2) { if (value) data = BIT(bit % 16) | BIT(bit % 16 + 16); else @@ -133,7 +134,7 @@ static inline u32 rockchip_gpio_readl_bit(struct rockchip_pin_bank *bank, void __iomem *reg = bank->reg_base + offset; u32 data; - if (bank->gpio_type == GPIO_TYPE_V2) { + if (bank->gpio_type >= GPIO_TYPE_V2) { data = readl(bit >= 16 ? reg + 0x4 : reg); data >>= bit % 16; } else { @@ -220,12 +221,18 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, if (!freq) return -EINVAL; div = (u64)(GENMASK(23, 0) + 1) * HZ_PER_MHZ; - max_debounce = DIV_ROUND_CLOSEST_ULL(div, freq); + if (bank->gpio_type == GPIO_TYPE_V2) + max_debounce = DIV_ROUND_CLOSEST_ULL(div, freq); + else + max_debounce = DIV_ROUND_CLOSEST_ULL(div, 2 * freq); if (debounce > max_debounce) return -EINVAL; div = (u64)debounce * freq; - div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC) - 1; + if (bank->gpio_type == GPIO_TYPE_V2) + div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC) - 1; + else + div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC / 2) - 1; } raw_spin_lock_irqsave(&bank->slock, flags); @@ -411,7 +418,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) polarity = rockchip_gpio_readl(bank, bank->gpio_regs->int_polarity); if (type == IRQ_TYPE_EDGE_BOTH) { - if (bank->gpio_type == GPIO_TYPE_V2) { + if (bank->gpio_type >= GPIO_TYPE_V2) { rockchip_gpio_writel_bit(bank, d->hwirq, 1, bank->gpio_regs->int_bothedge); goto out; @@ -430,7 +437,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) polarity |= mask; } } else { - if (bank->gpio_type == GPIO_TYPE_V2) { + if (bank->gpio_type >= GPIO_TYPE_V2) { rockchip_gpio_writel_bit(bank, d->hwirq, 0, bank->gpio_regs->int_bothedge); } else { @@ -536,7 +543,7 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) } gc = irq_get_domain_generic_chip(bank->domain, 0); - if (bank->gpio_type == GPIO_TYPE_V2) { + if (bank->gpio_type >= GPIO_TYPE_V2) { gc->reg_writel = gpio_writel_v2; gc->reg_readl = gpio_readl_v2; } @@ -669,6 +676,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) bank->gpio_regs = &gpio_regs_v2; bank->gpio_type = GPIO_TYPE_V2; break; + case GPIO_TYPE_V2_2: + bank->gpio_regs = &gpio_regs_v2; + bank->gpio_type = GPIO_TYPE_V2_2; + break; default: dev_err(bank->dev, "cannot get the version ID\n"); return -ENODEV; From patchwork Tue Sep 3 07:36:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788222 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2C15DCD342F for ; Tue, 3 Sep 2024 07:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zDVZ8TZm7nkWoJsuX0habbG1+gqX4d/hwXj0dJJAT7Y=; b=PveDk8v9I7AcQJFTC1LrtNFdYJ wFcIIH+j0rv9hs8+hbme0aut0w3yUcXWJyUkR9Skzym3KqTls214lT9wFnS7s/nhz7eD60zk/G451 ZaGJBv06Ay6d1CpNZnhn5Kd3ed2eBNiD7FNDrkK5fdiB0Q8AyWSuzxsRd2t2zU6SVMdcZLd7euLZQ AnuGS+AHUiN7/tVRWjXc1TMlRb4ulZlDDAwaisq6XXsLO1MPgISB7StW9STkvn0yWFSXeOj0bJYlY nDjj5oWN00NW4Xudr2ZA8equCXuM8BbK8jzSMoL2sCy2U6b6ANbYg4ZEyG/1PDsLAaEYxuUfW38uA qrj9DXkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOHe-0000000GkuT-41mr; Tue, 03 Sep 2024 07:49:02 +0000 Received: from mail-m118218.qiye.163.com ([115.236.118.218]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6V-0000000GiPY-29qe; Tue, 03 Sep 2024 07:37:33 +0000 DKIM-Signature: a=rsa-sha256; b=GKCejw2dVuzw9CkrXNsUGDcFloWio3UugIYBHK2SHk9yoT0YOOo51O9Tfb/8XnvQ6EwlQ6DxOXMdIETLy/42UT8IhQtwEEs8dWnFFwDROm47EOLPZUYULxJ5i5U7Dr4wAJL0KWrSYfh9CEvJTLKOK6wPU01HiJgbI0joZjOOCa4=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=zDVZ8TZm7nkWoJsuX0habbG1+gqX4d/hwXj0dJJAT7Y=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 08F447E0659; Tue, 3 Sep 2024 15:37:16 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 11/12] gpio: rockchip: Set input direction when request irq Date: Tue, 3 Sep 2024 15:36:48 +0800 Message-Id: <20240903073649.237362-12-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQk1LHVZNTx5JTklMSENJTEtWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d106a209cfkunm08f447e0659 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NEk6NDo5ITIwNEkhLBEaFQ0X DEwwCy1VSlVKTElOSE9CS0hDSEpCVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSU1PSTcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003731_938538_8EA406A7 X-CRM114-Status: UNSURE ( 9.10 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources. Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 6deebf1dd9dd..73e57efb46fc 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -476,10 +476,14 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) static int rockchip_irq_reqres(struct irq_data *d) { + irq_hw_number_t hwirq; struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct rockchip_pin_bank *bank = gc->private; - return gpiochip_reqres_irq(&bank->gpio_chip, d->hwirq); + hwirq = irqd_to_hwirq(d); + rockchip_gpio_direction_input(&bank->gpio_chip, hwirq); + + return gpiochip_reqres_irq(&bank->gpio_chip, hwirq); } static void rockchip_irq_relres(struct irq_data *d) From patchwork Tue Sep 3 07:36:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Zhang X-Patchwork-Id: 13788223 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 77376CD342F for ; Tue, 3 Sep 2024 07:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mgSI3a/7dMdZbLCNsqhcURBOepC3DqKjtYsqMJY17gk=; b=pQ13bphp2ykkux/cAjnUqceSRU QaLqTq2yocfncxSw8h2C6uATb5jw93jFDtS3GTEth/lvTwdlQRsMtByj3o2nsHfKHlWUGx4zcBZFK +8ov/nKVwvjCZCD92PTi0ISpKZu5FVW2tuzfj5AHBPGmCs4xbbrXNc2Y8dQskSC7RFLgidXOtDsxV pNPiYQZSolk+rHMrDa7xctMoxHMxUg/m/8nR6cgRki0tCjH15q0JVQ+ex2XKLYCzlS0uQgYTguxL8 vZzQOBQYljziZfkiWtqQI6J8f45UUWhrjGRGxbxpa+VvrnWC+uZU/usEuR6ZRrdu1vn2ZKzrsUVec +i4T2hUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOIX-0000000Gl7l-27mA; Tue, 03 Sep 2024 07:49:57 +0000 Received: from mail-m12787.qiye.163.com ([115.236.127.87]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO6a-0000000GiSx-28VT; Tue, 03 Sep 2024 07:37:37 +0000 DKIM-Signature: a=rsa-sha256; b=Svn1LfzBXD6+X08id4l9jK0W/Cla+KEeOVEdn7IGloLESmycgijpufkzijYmggBJ5spOLgBeGqUeFSEdc0N8UlAFTvIqp68PCaGCfjsXywmzn++Iqemx3up6RQA/vZiX/g/OcB5IoGskpHPuAtgVuDEJZXxxFi84o9UnXIZdCwY=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=mgSI3a/7dMdZbLCNsqhcURBOepC3DqKjtYsqMJY17gk=; h=date:mime-version:subject:message-id:from; Received: from rockchip.. (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTPA id 68C3B7E0292; Tue, 3 Sep 2024 15:37:18 +0800 (CST) From: Ye Zhang To: Ye Zhang , linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, tao.huang@rock-chips.com, finley.xiao@rock-chips.com, tim.chen@rock-chips.com, elaine.zhang@rock-chips.com Subject: [PATCH v3 12/12] gpio: rockchip: replace mutex_lock() with guard() Date: Tue, 3 Sep 2024 15:36:49 +0800 Message-Id: <20240903073649.237362-13-ye.zhang@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903073649.237362-1-ye.zhang@rock-chips.com> References: <20240903073649.237362-1-ye.zhang@rock-chips.com> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGUwaTFYZTkIZGUlCGh5JTR5WFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhCSE NVSktLVUpCS0tZBg++ X-HM-Tid: 0a91b6d10c2209cfkunm68c3b7e0292 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Pk06Qzo6GjI1FklRLBEfFQgt Qw1PCTpVSlVKTElOSE9CS0hCTUNIVTMWGhIXVQIeVQETGhUcOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSEtNQjcG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_003736_767039_B8AF96E5 X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Replacing mutex_lock with guard() simplifies the code and helps avoid deadlocks. Signed-off-by: Ye Zhang --- drivers/gpio/gpio-rockchip.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 73e57efb46fc..d5c57617fc86 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -765,20 +765,19 @@ static int rockchip_gpio_probe(struct platform_device *pdev) } } - ret = rockchip_get_bank_data(bank); - if (ret) - goto err_disabled_clk; - /* * Prevent clashes with a deferred output setting * being added right at this moment. */ - mutex_lock(&bank->deferred_lock); + guard(mutex)(&bank->deferred_lock); + ret = rockchip_get_bank_data(bank); + if (ret) + goto err_disabled_clk; ret = rockchip_gpiolib_register(bank); if (ret) { dev_err(bank->dev, "Failed to register gpio %d\n", ret); - goto err_unlock; + goto err_disabled_clk; } while (!list_empty(&bank->deferred_pins)) { @@ -805,14 +804,11 @@ static int rockchip_gpio_probe(struct platform_device *pdev) kfree(cfg); } - mutex_unlock(&bank->deferred_lock); platform_set_drvdata(pdev, bank); dev_info(dev, "probed %pOF\n", np); return 0; -err_unlock: - mutex_unlock(&bank->deferred_lock); err_disabled_clk: if (bank->manual_clk_release) clk_disable_unprepare(bank->clk);