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: 13788204 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 2B3EACD342E for ; Tue, 3 Sep 2024 07:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ca4wZwmUBe0j0Z64YHCjLFeIpw38mLF67omqNizxQ1U=; b=a26pk784f/24HL VdOAoaT9C9CBovqYHVTwxb8hBQyLwIlw8DV5etLxGwnpeWM/QJj2uyLHW6DB9lW0QchFNMnhFv233 zmOPZJcEA+h96Tpb70qOWLm08fUVko6N5QrRwC3djDIDTpBwOo+J+aDqw0omJoXgyE8ObnDUjtDn8 /MgRYTc5cXevq1xzYzD4uhDrtiKnZ3Ve+SF9E0N9IebVfG6AYdzyA5fy3YbgT89i2o3kEHC7Yds7S azySXnWBKWK/SPAO7/do5NV2D9TGnm/g0OZhX9RMWnaWF62jJi3UBcJkCBcngEB112RR3s5Kr7sXs gl/H1c2a5BubN1oaawzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOCQ-0000000GjiF-1VTR; Tue, 03 Sep 2024 07:43:38 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788190 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 8E7C4CD342E for ; Tue, 3 Sep 2024 07:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mwQ+avCzeamshHkuM1bVmfNwxV5XakDYKm1raK7nOZo=; b=RnShEg7EkZ4c6o dwl8YvjokjYdkIX79mnVkpTKFBUaHHGyHQM9XoTP5A8QmbD8qMx3ts9ccYDt5ada2LNA670EKCFwG /ymQndhTJpzDh9EZjSSz6cibcVdOSBnUtSr1gaPqkbv0faKC5n3l1B+XPaOlRRg4dW2vx6EZ8yuGJ FOHN5HiJslJy0Xl1tap5fD3FxOqZbUdgRgNw8gVqb//tHBBJshhDK0otRd/KXICriimbiRutee1WV b+/3YB35V9IcHr1igGXAdylvL0jdKKozhCzz4qYsc2Xe83lTvi/WjR8LEbTqzfFAxLSrZRxDxQyiG DRESIrp++Wji8WAVSg6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO7A-0000000GiYZ-2CN7; Tue, 03 Sep 2024 07:38:12 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788202 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 E498ACD342F for ; Tue, 3 Sep 2024 07:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K6xsaxFoT9f0n2pFTgTA3uoHv20cQ6RPPDKLttkde6s=; b=TRT/9bwT+r7RTg 8m9SdSPvkw85UdRdf9su+nqmuqUmH66QazlCzcbEU7cObGmpEEmfKlJZEBs0PJIJvP5O7DnW/Emy9 w/tQ/zRES8P3sFEuPaF0ezhO0wh9yOB4/ea/k31S0nCTiZesyabwDLA4ybJatf4R/DL+XnFHQEc3y QNPerK8ViWqfrgcegp0cGWGCXPNtV0E+yS/45up432dBzMFnkzJqxq1oSPR3AiCG/B3Zti2xKUDnn 6NrBC/or/tXmHdxvILTqLpn7bs1/pySt0dEp2DHoorAwYULYK+EAmLwRxidLioGx3sa0JwkktZsHr FNhmE2G/qu/vMrShCRqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOAh-0000000GjM2-0ccx; Tue, 03 Sep 2024 07:41:51 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788203 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 7A093CD342E for ; Tue, 3 Sep 2024 07:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Q7Wz1G1edScfjhAcmiOrVffoOLSPU21yPwyE3X/z3M0=; b=F7HXXqfyV6tkVd fMslNDCpb1Lm2tDqor63vxhj8Mg/ve7R2qsODxHgLQFFdJWjAHu/HwgAwYjH8inQmUapF0BIGdlyf bK3sX64UUyyADnFsEb9YpRuV6bk3llMKSdxZalaoU+b9H4AKSJF8IMJQLwi+4axs8HsZibzeW8Es4 vRRClfZ00PD5h+UzGLQYmh5mq2eGnNaXTpi9bmLNfvgIzeaJ/QJxLRs50eDuVDDgOQcS5/Ky0Sx92 L7/FlT0XCdcjLV/HepKUblCBEePfmdJ+43lZ1xrO0Mmfx7Z/LGkPNfzKwFpN2PZL7gj70xtFo1txS 66jAR3xYZEWKImKzOB3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOAg-0000000GjLj-3GjF; Tue, 03 Sep 2024 07:41:50 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788192 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 79D61CD342A for ; Tue, 3 Sep 2024 07:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7eHDKpXkAwf0EmM2MO2vn8f5Q+ZSxFUPVK83g650cEY=; b=Dv/cPcNj1yz+2X TVEH1PWVkgqQ+mal+/bQsPUdATwbiaeeq8UnG2YJIP+kxf5GmDnrm+FjhKO0EsmqbZDCk/LhfnWrq rniWyMPLPRoYRcTwTMhv7NINQCjmi0VWQScZHoU9whddlnq1Og1APjen1aNY4D6wgk1zxaFRjTBMv 8726fSeEAjfvOxGRM1nzHNcY4BjdO4sRTXRsixEambVhoDl50FLfjQeHCiRTkCoMi2mnMtcDuIOmx 7w4XwJl7tw2BYLNNNogPw9+78+lqCLZYG94P22LZO7Hwm5hMRTtOk8YORhsJgyJSDBAUn3o5f/vAA NuS8kASb1N2OlxBtZqUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO8u-0000000Giqu-2Ylj; 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 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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788191 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 B7A5FCD342F for ; Tue, 3 Sep 2024 07:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=z0H+TWkL0UhYD78FEPEAQLfSKyuMYZ6Dofh6hydwS1c=; b=W14azWuvNhO9qr PBxK25iNHCpnCSad7nf32RWvckBJxoy/h99boyJ/3dAnhH3IFTgEqwNBrUrJlzaQR6sDv3ftcE8T4 vcuTkKlw2TCia5VKTPH3Fi/YfRd1kltG91YI5Ew/G3G71K11pSI3v7xZjIoA5mPbotNJMAX+7sRM4 jA9uvxNXNc5YMF+76txTLkzgOLsEQ3D98HuvVd/ePUQiQCNjz3BNyPBV51JOGDqgKcL7ElEFYkhoo 6wbeaXFokNcg7GyfE8ouLPnPQ7Hf7vcIBDy69uUq4d2lpqhrXb3JVzYf947RA7zj0+T22dr8zSSTn mOVv46NMafS0UuriBcSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO7A-0000000GiYv-3oXa; Tue, 03 Sep 2024 07:38:12 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788207 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 E7255CD342E for ; Tue, 3 Sep 2024 07:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GffWFgp+W8lL15cYEFwvYTYW+/eti4l0odf1GbqmS3E=; b=07oFBsxaKG/yql jCn8l55/cDhAUBms9gmWvCFDBQzzjbmbJhr9GBx7Rojuo4M4Lubr3o7vcHJBUdkavvYdJXBhtDIRB tTW5TSM0EE1SGs50VjQLJUQVovPPT6tZhhQPZXHthALLrAI5AC3P34H+mmptrId1Me5j8uC/t39d/ cWcYJ4yD7yPEuR0SrQbluvaYuuYxsn0nP+GBRnjMj9+51tP8flF5zg2L3IW2zuJDNsIF6rEX+Rj3J DMSEWgO5JZzTzzSRO8y/5QSof40+mhrARDJyeZBRK2iKq1VaWyowEPFevN8yDN8KnXS9e8mCKZZcI ryy3n3BnagSUREfZ3wmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOEA-0000000Gk3S-32uB; Tue, 03 Sep 2024 07:45:26 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788206 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 4B7A5CD342F for ; Tue, 3 Sep 2024 07:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fq9wcTuyxld+gxqK/LiJfjbHwNbqwhPxmBBMxABCE7c=; b=iDR4Qsvy5hrhV5 ZdRZyvRzypX+0uP+ziJwF0+dv3iqguxUjnLThO48TDvo7p13qZvU7kDyYOvOw/DltOMHI+Qg75T4u C7ohN9LjA7M3yAVSWFuJGToRWijkqHjNYUlWZ3BAXk5I7oFk9D1lMn2NN5Oi7uQq5yV3c6YveEy5M h+dWXjjZCM+8TlckCvy26WxeBnc6WyDjP+o8WZgEJkL1eqkVRfhWOOzdDXAMTlkqcre99GHBBsksC RNP9e6xtE3tDi/DBio3+Jx/dYbk2RCT52F3lQwehBARG6IwVZrMmZsTzz59ImsxTj+HGMa834Jh/M JKpTULwRplZCoQ4DcBmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOEA-0000000Gk37-1KKS; Tue, 03 Sep 2024 07:45:26 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788193 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 16E8ECD342F for ; Tue, 3 Sep 2024 07:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kDqUJ+EE/miWy40EUvWUVnYJfA6cShNZEF3rhiFN8Aw=; b=oAtWIQvi41HDgM r8qKX/5IfU6+cZOovn4xQkEagf/42qiZDnVuN3si4DfZ/331X1nV7Xf6ICXRtXnrkHiHt6PHlJbyP DoqQyYGTO58nlWh9m/SehYBvxfIFuTP76A2mgdzBV9foHXyKB6kvvbW6+4zmTKEPZrACEwJcHw4NE fzZbaVBhIm2VEQlRVyR0fB6ZAQhgdo90ghuPX/jmh7oTnpDLKpmI0bhijuj1eCFE6lxRGwFYYavCa 8nC+yncVlsYI79lzQCyAnfwG0hxNr7yTeLzJGPqMwibhOOyhLLg6Vw8sEeDdc3gQV0ArL9ivc6e3v Cb4ob2ADkQB2r4ERpJrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slO9n-0000000Gj6X-3mLH; Tue, 03 Sep 2024 07:40:55 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788215 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 41941CD342F for ; Tue, 3 Sep 2024 07:47: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uuMXsj88wb4mJl6epyYSpCQSFgD5iEky3qoZTLAtid0=; b=sIS5R9JwM2Satq d++fzUdEy1Yr4S87ff3N2OtZTsJb2heRBY1lDgKhWM4lNVxgwh299u+u4Fi7BFfHsE/evzptgJNjR IY9BYW4yCfdVlEm1s2uFNy1YPINstOAV4vRztDOOFzpcVnxhFj3K1i1Jmn6X3UOSd2aCZVelgXcnN Q8aMjuqsrkNPFDN0St2cLWTKAwYN/ArYTW4NYJHAB0+/UDslgpfafn2CCyrzBMfuuKS0OgTpF6ldL Pf9A3f2rUpBsfoMPz4HXqfty1/Tta8FqL/afeu34/dmI/2iKkzGytcH91prrsCvxTO3B1z9yj3znH b+1ZK4jOMnrtVoWReJCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOFt-0000000GkQY-2bi8; Tue, 03 Sep 2024 07:47:13 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788216 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 D1D82CD342E for ; Tue, 3 Sep 2024 07:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=26pCxffy6pc+8wjIb+fvpGOwjRWLeGz2r8Gy4aIrbyk=; b=rd7j1ywiAHP5Cz R8CAcW3zcqNcNd36r+xwz4r2eraUFlfxO0xBHJ760OTxPScua3g6jl1wVTWeuV9/YnIXOnofhkH1P nVse7FOEq5Qol0rhjjgF8bS/n6wnceTT8gkxxF0wBVppdMDHKhqP3JZy6xOkPRo5cotEbvrq8U38G YVjgox/jtHba/du6+p9a/DqCkCZU19qxb20TfDuLh2dH1xf2h6ldGl+H1ZkSO7Tzw2iDaL8awIq7T GYxRb5/CV2Ep+NE6CPEOAKEfHsC5oxF6/aOrKvIRUFxpqcqEYuAGAAIwmt+PDbCqeTMpfZsACJY4X NxJ2fIJ3PP3ByxUhcuFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOGl-0000000GkcJ-1S58; Tue, 03 Sep 2024 07:48:07 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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: 13788217 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 530E0CD342F for ; Tue, 3 Sep 2024 07:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CYHd1GrMZj8AzQC/sUrWP4c0TFP7GXKyPvaUnR7Fb9M=; b=eZpiWsCEmIS/Ol nprDtCd+03VL5GCAZCfMX2wqDVM3LysaaaHUosOz0IzTPOf3vMsvNJfTaJ2wSPcpPtf032S2fFIQe 039kv7tcjS/l8V/wrTd9l309umtcqm61bZYC/7DLmOKGFDcQLG28uH5RzDquG1vj31lmv/AMpTmBd 7xRe/jXPLd6Op4Uad+Ne/m8EQDxMPIHv6Dt2oMUP++MBmypAy7ollOJQWt7Hs4X/6QQd5UNEN7nHT QLacaxlnCZYQwvG/4c3cLiR27eGrShQqAGV5HWgCsSaOsQ7ygGlleVJ0J0kbxhHPXWSP9Vsr5LLkP rVa635+tXQwjMHBhIJsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slOHf-0000000Gkum-2dGJ; Tue, 03 Sep 2024 07:49:03 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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);