From patchwork Fri Apr 22 07:38:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 1620639 X-Patchwork-Delegate: patrick.delaunay73@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=rcs49MNh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kl5r6673Xz9s0w for ; Fri, 22 Apr 2022 17:38:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 77E8583D58; Fri, 22 Apr 2022 09:38:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="rcs49MNh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ABF8383D5B; Fri, 22 Apr 2022 09:38:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8295383D3D for ; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=011196f9c1=patrice.chotard@foss.st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23M2iiqj028979; Fri, 22 Apr 2022 09:38:37 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=selector1; bh=T/AuYMRvdKW3/GuSR+Eg21E3OslIHUyZWdRE09orsn0=; b=rcs49MNh47hYpBXEwN9e95qNVWLk3qS4hYOdN9eZi2y3EBsIzrKSWqBBF7zAT6xSsjkN crJWdXWQCNbALqYndqSukd5iKWZ8fsaANki9BKcTHWLm3cTxtZs5syhsuIlyzwF+wNWx Mhth1cB8EdFjOM5wjrsf1Oq19AGkHnZBspzHEFc0YZcqKeC419xiNB0sQHcw4OeBcc1Z VoBvdjPNJHGJMeNwbJSonO9sbp04Hs2Y0/2MwjYoFTDUyWqsmvDSgrK9anxPrtOP+69/ LPb9opjBDYOcjk+R2lKlnx9ApEsXNE2sxyc6uvJvtPMRlXwh+zVgb7XYuCQ1MLtVy/mA 3Q== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3fk4fvd7gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 09:38:37 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A1BC1100034; Fri, 22 Apr 2022 09:38:36 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 9C68A216833; Fri, 22 Apr 2022 09:38:36 +0200 (CEST) Received: from localhost (10.75.127.47) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 22 Apr 2022 09:38:36 +0200 From: Patrice Chotard To: CC: Patrice CHOTARD , Patrick DELAUNAY , U-Boot STM32 Subject: [PATCH 1/3] pinctrl: pinctrl_stm32: Update pinmux_mode definition Date: Fri, 22 Apr 2022 09:38:29 +0200 Message-ID: <20220422073831.15538-1-patrice.chotard@foss.st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-22_02,2022-04-21_01,2022-02-23_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean pinmux_mode[] is linked to gpio_function[] defined in gpio-uclass.c So reuse the same gpio_func_t enum value Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay --- drivers/pinctrl/pinctrl_stm32.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 5729799b12..5d8e156d62 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -42,13 +42,12 @@ struct stm32_gpio_bank { #ifndef CONFIG_SPL_BUILD static char pin_name[PINNAME_SIZE]; -#define PINMUX_MODE_COUNT 5 -static const char * const pinmux_mode[PINMUX_MODE_COUNT] = { - "gpio input", - "gpio output", - "analog", - "unknown", - "alt function", +static const char * const pinmux_mode[GPIOF_COUNT] = { + [GPIOF_INPUT] = "gpio input", + [GPIOF_OUTPUT] = "gpio output", + [GPIOF_UNUSED] = "analog", + [GPIOF_UNKNOWN] = "unknown", + [GPIOF_FUNC] = "alt function", }; static const char * const pinmux_bias[] = { From patchwork Fri Apr 22 07:38:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 1620640 X-Patchwork-Delegate: patrick.delaunay73@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=wwdqStyq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kl5rH5f6mz9s0w for ; Fri, 22 Apr 2022 17:38:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D388783D66; Fri, 22 Apr 2022 09:38:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="wwdqStyq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F0E0D83D40; Fri, 22 Apr 2022 09:38:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F371583D4B for ; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=011196f9c1=patrice.chotard@foss.st.com Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23M0p0P7017328; Fri, 22 Apr 2022 09:38:37 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=ahUyJMYWusAV1D+RgZ3kbvv1qBiFP7wigtlJwEPZxcE=; b=wwdqStyq19tgHqnoqtyv0MkqpjcQECR9jdvX4i1vrvLgL9E7nohngJaGuj+PBxLpdyZk /Jp4uc957CzEB2FTMdlSs+nW8GJBTVC9E8I1NNspSh29WDTqVT9eysi0ebqlEI2fwX+0 siN3rfTcACH9IowxzmjqQtwjxSAs9gtdRPxsH7n4eLKZnIwR2UYyVYr8R8zTG1kOEwTG UR0vKUBk1cXCHCjPwL5xAFjoKjXiNPBRQQQLuJHfDqycNThMM1SPZsoRNzeHqcUNXC0b oMXxYnunmjpIR1SZ5nx+A5u4wEAu2jePdKP4KHtvz5XWXjh+iAXPJCxGdt2XY5NW0ppA 3g== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ffpqe7g97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 09:38:37 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 28523100038; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2307C216833; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Received: from localhost (10.75.127.47) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 22 Apr 2022 09:38:36 +0200 From: Patrice Chotard To: CC: Patrice CHOTARD , Patrick DELAUNAY , U-Boot STM32 Subject: [PATCH 2/3] pinctrl: pinctrl_stm32: Use GPIOF_UNKNOWN to indicate not mapped pins Date: Fri, 22 Apr 2022 09:38:30 +0200 Message-ID: <20220422073831.15538-2-patrice.chotard@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220422073831.15538-1-patrice.chotard@foss.st.com> References: <20220422073831.15538-1-patrice.chotard@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-22_02,2022-04-21_01,2022-02-23_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean GPIOF_UNKNOWN becomes a valid pin muxing information to indicate that a pin is not mapped. Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay --- drivers/pinctrl/pinctrl_stm32.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 5d8e156d62..373f51f046 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -220,8 +220,6 @@ static int stm32_pinctrl_get_pin_muxing(struct udevice *dev, switch (mode) { case GPIOF_UNKNOWN: - /* should never happen */ - return -EINVAL; case GPIOF_UNUSED: snprintf(buf, size, "%s", pinmux_mode[mode]); break; From patchwork Fri Apr 22 07:38:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 1620641 X-Patchwork-Delegate: patrick.delaunay73@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=w9hoKkTn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kl5rZ1ZBzz9s0w for ; Fri, 22 Apr 2022 17:39:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8FC7483D4B; Fri, 22 Apr 2022 09:38:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="w9hoKkTn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DCACD83D3D; Fri, 22 Apr 2022 09:38:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6AD4883D39 for ; Fri, 22 Apr 2022 09:38:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=011196f9c1=patrice.chotard@foss.st.com Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23M1eZAV015687; Fri, 22 Apr 2022 09:38:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=RBDp0Kc5xSPWa5TtfI1tnusXPd+II5QPdNyz6ohD9wQ=; b=w9hoKkTnqvp1iQVOf06xekcxZwV5iJlMzYdvXQLqCTqnurneXwU8nRNtYsIofovZCmA5 hmL74czI8674QhAVwKSWtUZJBOCTVZlr4ocBRotH+/efIAuJZrTLfvv5PKcw1RVl2jeA 6+rCeAO53huh2RZutiKmxQFCetzaFffN7m95WISGrSZuBxK2we4p/kV9J7f1uWARiEsk +wYq03+VB4sXDPQM/A60WSQa1YyMj//0hGvw6pcwOkve0r2Nw8n5nQbfunbfwMfNcv6v NoyedFp4x2Hb3IP74nuxDt5MZ96wr0IwenvZODpBIFXZuM30mp/QSp82FMIXrHQfWR7w 8w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ffpqe7g98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 09:38:38 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C8594100034; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id BF529216833; Fri, 22 Apr 2022 09:38:37 +0200 (CEST) Received: from localhost (10.75.127.44) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 22 Apr 2022 09:38:37 +0200 From: Patrice Chotard To: CC: Patrice CHOTARD , Patrick DELAUNAY , U-Boot STM32 , Simon Glass Subject: [PATCH 3/3] gpio: stm32_gpio: Rework GPIO hole management Date: Fri, 22 Apr 2022 09:38:31 +0200 Message-ID: <20220422073831.15538-3-patrice.chotard@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220422073831.15538-1-patrice.chotard@foss.st.com> References: <20220422073831.15538-1-patrice.chotard@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-22_02,2022-04-21_01,2022-02-23_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On some STM32 SoC's package, GPIO bank may have hole in their GPIO bank Example: If GPIO bank have 16 GPIO pins [0-15]. In particular SoC's package case, some GPIO bank can have less GPIO pins: - [0-10] => 11 pins; - [2-7] => 6 pins. Commit dbf928dd2634 ("gpio: stm32f7: Add gpio bank holes management") proposed a first implementation by not counting GPIO "inside" hole. GPIO are not displaying correctly using gpio or pinmux command when GPIO holes are located at the beginning of GPIO bank. To simplify, consider that all GPIO have 16 GPIO and use the gpio_ranges struct to indicate if a GPIO is mapped or not. GPIO uclass offers several GPIO functions ("input", "output", "unused", "unknown" and "func"), use "unknown" GPIO function to indicate that a GPIO is not mapped. stm32_offset_to_index() is no more needed and removed. This must be reflected using the "gpio" command to indicate to user that a particular GPIO is not mapped (marked as "unknown") as shown below: Example for a 16 pins GPIO bank with the [2-7] mapping (only 6 pins mapped): GPIOI0 : unknown GPIOI1 : unknown GPIOI2 : analog GPIOI3 : analog GPIOI4 : alt function 0 push-pull pull-down GPIOI5 : alt function 0 push-pull pull-down GPIOI6 : alt function 0 push-pull pull-down GPIOI7 : analog GPIOI8 : unknown GPIOI9 : unknown GPIOI10 : unknown GPIOI11 : unknown GPIOI12 : unknown GPIOI13 : unknown GPIOI14 : unknown GPIOI15 : unknown Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay --- drivers/gpio/stm32_gpio.c | 103 +++++++++++--------------------- drivers/gpio/stm32_gpio_priv.h | 2 - drivers/pinctrl/pinctrl_stm32.c | 5 +- 3 files changed, 37 insertions(+), 73 deletions(-) diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c index 8667ed3835..7a2ca91c76 100644 --- a/drivers/gpio/stm32_gpio.c +++ b/drivers/gpio/stm32_gpio.c @@ -83,38 +83,22 @@ static enum stm32_gpio_pupd stm32_gpio_get_pupd(struct stm32_gpio_regs *regs, return (readl(®s->pupdr) >> PUPD_BITS(idx)) & PUPD_MASK; } -/* - * convert gpio offset to gpio index taking into account gpio holes - * into gpio bank - */ -int stm32_offset_to_index(struct udevice *dev, unsigned int offset) +static bool stm32_gpio_is_mapped(struct udevice *dev, int offset) { struct stm32_gpio_priv *priv = dev_get_priv(dev); - unsigned int idx = 0; - int i; - - for (i = 0; i < STM32_GPIOS_PER_BANK; i++) { - if (priv->gpio_range & BIT(i)) { - if (idx == offset) - return idx; - idx++; - } - } - /* shouldn't happen */ - return -EINVAL; + + return !!(priv->gpio_range & BIT(offset)); } static int stm32_gpio_direction_input(struct udevice *dev, unsigned offset) { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; - stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_IN); + stm32_gpio_set_moder(regs, offset, STM32_GPIO_MODE_IN); return 0; } @@ -124,15 +108,13 @@ static int stm32_gpio_direction_output(struct udevice *dev, unsigned offset, { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; - stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_OUT); + stm32_gpio_set_moder(regs, offset, STM32_GPIO_MODE_OUT); - writel(BSRR_BIT(idx, value), ®s->bsrr); + writel(BSRR_BIT(offset, value), ®s->bsrr); return 0; } @@ -141,26 +123,22 @@ static int stm32_gpio_get_value(struct udevice *dev, unsigned offset) { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; - return readl(®s->idr) & BIT(idx) ? 1 : 0; + return readl(®s->idr) & BIT(offset) ? 1 : 0; } static int stm32_gpio_set_value(struct udevice *dev, unsigned offset, int value) { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; - writel(BSRR_BIT(idx, value), ®s->bsrr); + writel(BSRR_BIT(offset, value), ®s->bsrr); return 0; } @@ -171,14 +149,12 @@ static int stm32_gpio_get_function(struct udevice *dev, unsigned int offset) struct stm32_gpio_regs *regs = priv->regs; int bits_index; int mask; - int idx; u32 mode; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return GPIOF_UNKNOWN; - bits_index = MODE_BITS(idx); + bits_index = MODE_BITS(offset); mask = MODE_BITS_MASK << bits_index; mode = (readl(®s->moder) & mask) >> bits_index; @@ -197,30 +173,28 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset, { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; if (flags & GPIOD_IS_OUT) { bool value = flags & GPIOD_IS_OUT_ACTIVE; if (flags & GPIOD_OPEN_DRAIN) - stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_OD); + stm32_gpio_set_otype(regs, offset, STM32_GPIO_OTYPE_OD); else - stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_PP); + stm32_gpio_set_otype(regs, offset, STM32_GPIO_OTYPE_PP); - stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_OUT); - writel(BSRR_BIT(idx, value), ®s->bsrr); + stm32_gpio_set_moder(regs, offset, STM32_GPIO_MODE_OUT); + writel(BSRR_BIT(offset, value), ®s->bsrr); } else if (flags & GPIOD_IS_IN) { - stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_IN); + stm32_gpio_set_moder(regs, offset, STM32_GPIO_MODE_IN); } if (flags & GPIOD_PULL_UP) - stm32_gpio_set_pupd(regs, idx, STM32_GPIO_PUPD_UP); + stm32_gpio_set_pupd(regs, offset, STM32_GPIO_PUPD_UP); else if (flags & GPIOD_PULL_DOWN) - stm32_gpio_set_pupd(regs, idx, STM32_GPIO_PUPD_DOWN); + stm32_gpio_set_pupd(regs, offset, STM32_GPIO_PUPD_DOWN); return 0; } @@ -230,19 +204,17 @@ static int stm32_gpio_get_flags(struct udevice *dev, unsigned int offset, { struct stm32_gpio_priv *priv = dev_get_priv(dev); struct stm32_gpio_regs *regs = priv->regs; - int idx; ulong dir_flags = 0; - idx = stm32_offset_to_index(dev, offset); - if (idx < 0) - return idx; + if (!stm32_gpio_is_mapped(dev, offset)) + return -ENXIO; - switch (stm32_gpio_get_moder(regs, idx)) { + switch (stm32_gpio_get_moder(regs, offset)) { case STM32_GPIO_MODE_OUT: dir_flags |= GPIOD_IS_OUT; - if (stm32_gpio_get_otype(regs, idx) == STM32_GPIO_OTYPE_OD) + if (stm32_gpio_get_otype(regs, offset) == STM32_GPIO_OTYPE_OD) dir_flags |= GPIOD_OPEN_DRAIN; - if (readl(®s->idr) & BIT(idx)) + if (readl(®s->idr) & BIT(offset)) dir_flags |= GPIOD_IS_OUT_ACTIVE; break; case STM32_GPIO_MODE_IN: @@ -251,7 +223,7 @@ static int stm32_gpio_get_flags(struct udevice *dev, unsigned int offset, default: break; } - switch (stm32_gpio_get_pupd(regs, idx)) { + switch (stm32_gpio_get_pupd(regs, offset)) { case STM32_GPIO_PUPD_UP: dir_flags |= GPIOD_PULL_UP; break; @@ -304,17 +276,14 @@ static int gpio_stm32_probe(struct udevice *dev) if (!ret && args.args_count < 3) return -EINVAL; - if (ret == -ENOENT) { - uc_priv->gpio_count = STM32_GPIOS_PER_BANK; + uc_priv->gpio_count = STM32_GPIOS_PER_BANK; + if (ret == -ENOENT) priv->gpio_range = GENMASK(STM32_GPIOS_PER_BANK - 1, 0); - } while (ret != -ENOENT) { priv->gpio_range |= GENMASK(args.args[2] + args.args[0] - 1, args.args[0]); - uc_priv->gpio_count += args.args[2]; - ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3, ++i, &args); if (!ret && args.args_count < 3) diff --git a/drivers/gpio/stm32_gpio_priv.h b/drivers/gpio/stm32_gpio_priv.h index d3d8f2ed5d..662a000fe7 100644 --- a/drivers/gpio/stm32_gpio_priv.h +++ b/drivers/gpio/stm32_gpio_priv.h @@ -81,6 +81,4 @@ struct stm32_gpio_priv { unsigned int gpio_range; }; -int stm32_offset_to_index(struct udevice *dev, unsigned int offset); - #endif /* _STM32_GPIO_PRIV_H_ */ diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 373f51f046..56a20e8bd2 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -157,10 +157,7 @@ static struct udevice *stm32_pinctrl_get_gpio_dev(struct udevice *dev, * we found the bank, convert pin selector to * gpio bank index */ - *idx = stm32_offset_to_index(gpio_bank->gpio_dev, - selector - pin_count); - if (IS_ERR_VALUE(*idx)) - return NULL; + *idx = selector - pin_count; return gpio_bank->gpio_dev; }