From patchwork Fri May 3 06:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13652453 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 7B832C4345F for ; Fri, 3 May 2024 06:28: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: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:In-Reply-To:References: List-Owner; bh=6qIYBVFFaC3oY81PBhLZD15SanXo92c/lxIrgI0VS2M=; b=OQWdHd55XqeMNA WVrNSv8g8bdfM+9fo81JHgkM6Lk5XETJYT4rVgVduqI+swXxdXUmeOTAtTVdI+3hprJaL+Caunzzx Ba3nfZO5QJAqsAEvbRTJ/D+NGBCxwD4nCkAR/6LOJ3hEeb0hKO1haMTrR+bhUUXC2wmBARpTXMmO3 zwxww5vGeXwI2xwz61XSckkh2XtxnJy+7menMgKwduFTolAPjdrkaW1pelzYLsApIwGNE4v/PGm90 8tNLYHoeqM9qrsZ0icq8sZdbbBFwHAFhlddE5gkQSNu00Ucjfx6RuuMZZF+gViMj3dwCKXcOHDyy6 gM7o0vU0fnwbEw0ZbaNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2mP5-0000000FJdz-3e1P; Fri, 03 May 2024 06:28:19 +0000 Received: from mout.gmx.net ([212.227.15.18]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2mP1-0000000FJco-2tPl for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2024 06:28:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1714717689; x=1715322489; i=wahrenst@gmx.net; bh=Q1p9KR+G9aa+TDUZhbp6bfC0A0vuMuQ1F8vjV2eqkoc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=KKHbWn3hp1xONDA1XvU7sihywV/duqD8qgW9txu+GmL8vlA0g7i31NJ8qrOK/+RM 5nthmlILyZVNc6NpQ6FGEgH1vG3/F/vrYnLMRQKJIuyhImmp0HzTwzVQEKNPcKNfa jyMBU9/g/6eUvMYZXIuGXdcSQh/pG+QYV3g4fG9F2rDk/6vCDovOYMfWfSAKHIhal knrkugOKWit/HWdYiBmgqkkB3o1tObh3Gb40uaZECT4abOV2DjBO+3k67gaS08LCu tRq2ZprfFfYWGTR2wPHFYVj4f1Du8AeeHJIus2nIX6qCNWl64mRESIx2rPr5sJkP7 PA2SV+vPB2YHCWiFEw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFsUv-1rrZB944YJ-00HMbM; Fri, 03 May 2024 08:28:09 +0200 From: Stefan Wahren To: Linus Walleij , Florian Fainelli Cc: bcm-kernel-feedback-list@broadcom.com, Ray Jui , Scott Branden , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski , Phil Elwell , Kent Gibson , Stefan Wahren Subject: [PATCH V2] pinctrl: bcm2835: Make pin freeing behavior configurable Date: Fri, 3 May 2024 08:27:45 +0200 Message-Id: <20240503062745.11298-1-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:4U3OBSwNwE4ir9nLtcGNRIwLehYn5ZgXVQDgGfW5WPXLvk+lmwP 7RHzHHmsubv9jYnStJXl4oZ8Kau5Mw0oZ56dvkGTKhI1aw43qVUm5zIQWk/OV5KQDpEU6pc 8MPzSS95z5xQSNJLKk/Bhv668ezZELacIOvf6heSWtA8Ol3h195AtdNUWRgGe3DoxFecjMl hnP9tVEyjmTpPD0QrpluA== UI-OutboundReport: notjunk:1;M01:P0:i7A+T2fS+eY=;9pgMDjQbnCzS1rdAajih5R5rwdd ahvm4KqcrcjJdFh+ZMhEiwqnQLC/M5aitUmexs4WoFPk6534saG666lk3kSWssds95GgN+nlj 13euBSeENeryN6bJY15uvNzLsAg0++2DLVd7cuzfnuKQDaKl5qHPcJOjhk19BqgPOgzr1e6Fe D2T36LPdQXsX/wK613q4oDKjoVdU+45g/Gf96An8VxSo44Ew1XMNpPnzgfiAdhxni06K+Hxnz Oj3d3LHp4uUOMAzvqpvQQtwiVWjYDCsXPUw20zY2rAh3hdHRE0rnfTMbC67AjoKKzlHgPoj2I 0d8WOhQvuUnK4ocgyNOvxaBvstBSzNErFI8Rf3xAEvooyDj3+0vzDVkXNuRMbs29QvI5chVTc c03pQ1E0B8YP1NGsWdvx0Hb/aeyRRbmU9zwESYSTSWJJJ1LXc2zbf5SkqSBRP43iop5py3OXA 8PXa+UgqskHGMwkhCO0ATjR6TK5QY9JL5eox6HJWFzlPIQBPm+HRcFRBKcoHYGQyy2l+KFARF 7/nnEn8lhVKuZf1UmLvFSw4HYCGDjtDwrt+E78HBhAVZCp87dDsExDbw2Ct1Wa86wkH/BuZaB nR3vlukwtQMBOzsLGzXx2ChZXVPQHyVwcE2Me3OpFZIW2l/WYk6jMZOuMbh8r5gwuQGa8man4 sIdQOCgG9uBD9UnD27fUzth2KwPDd945q5+msL5Cl6bRH4/z4LCFjM/K9qMbl3aJkWSVq2uRo eBpV3yrBcrZKQqkQjg8YY8j+MCwqCbw9PcpH4eFULL9K5apP0Ysv2sqMaB50eoBY1K/3U666+ wnfGNqr37es59uhGy2deohv6ezTBKp46lVZxQniMRawuc= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240502_232816_039108_B9A24CCB X-CRM114-Status: GOOD ( 14.47 ) 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 Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN. So in case it was configured as GPIO_OUT before the configured output level also get lost. As long as GPIO sysfs was used this wasn't actually a problem because the pins and their possible output level were kept by sysfs. Since more and more Raspberry Pi users start using libgpiod they are confused about this behavior. So make the pin freeing behavior of GPIO_OUT configurable via module parameter. In case pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is kept. This patch based on the downstream work of Phil Elwell. Link: https://github.com/raspberrypi/linux/pull/6117 Signed-off-by: Stefan Wahren --- Changes in V2: - improve parameter name as suggested by Kent Gibson drivers/pinctrl/bcm/pinctrl-bcm2835.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) -- 2.34.1 diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c index f5a9372d43bd..b4293a827a89 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c @@ -244,6 +244,10 @@ static const char * const irq_type_names[] = { [IRQ_TYPE_LEVEL_LOW] = "level-low", }; +static bool persist_gpio_outputs; +module_param(persist_gpio_outputs, bool, 0644); +MODULE_PARM_DESC(persist_gpio_outputs, "Enable GPIO_OUT persistence when pin is freed"); + static inline u32 bcm2835_gpio_rd(struct bcm2835_pinctrl *pc, unsigned reg) { return readl(pc->base + reg); @@ -926,6 +930,13 @@ static int bcm2835_pmx_free(struct pinctrl_dev *pctldev, unsigned offset) { struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); + enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset); + + if (fsel == BCM2835_FSEL_GPIO_IN) + return 0; + + if (persist_gpio_outputs && fsel == BCM2835_FSEL_GPIO_OUT) + return 0; /* disable by setting to GPIO_IN */ bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); @@ -970,10 +981,7 @@ static void bcm2835_pmx_gpio_disable_free(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset) { - struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev); - - /* disable by setting to GPIO_IN */ - bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN); + bcm2835_pmx_free(pctldev, offset); } static int bcm2835_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, @@ -1419,6 +1427,9 @@ static int bcm2835_pinctrl_probe(struct platform_device *pdev) goto out_remove; } + dev_info(dev, "GPIO_OUT persistence: %s\n", + persist_gpio_outputs ? "yes" : "no"); + return 0; out_remove: