From patchwork Fri Aug 3 15:01:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 953276 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=st.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41hr1d6c4lz9s0R for ; Sat, 4 Aug 2018 01:04:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8F7EAC21F2F; Fri, 3 Aug 2018 15:03:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 287F0C21F8A; Fri, 3 Aug 2018 15:01:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 68854C21FD1; Fri, 3 Aug 2018 15:01:32 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lists.denx.de (Postfix) with ESMTPS id 7F779C21F93 for ; Fri, 3 Aug 2018 15:01:27 +0000 (UTC) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w73ExWAH002370; Fri, 3 Aug 2018 17:01:26 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kmgnvtpst-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 03 Aug 2018 17:01:26 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6969731; Fri, 3 Aug 2018 15:01:25 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 510255350; Fri, 3 Aug 2018 15:01:25 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 3 Aug 2018 17:01:24 +0200 From: Patrice Chotard To: Simon Glass Date: Fri, 3 Aug 2018 17:01:10 +0200 Message-ID: <1533308471-14098-6-git-send-email-patrice.chotard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1533308471-14098-1-git-send-email-patrice.chotard@st.com> References: <1533308471-14098-1-git-send-email-patrice.chotard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-08-03_06:, , signatures=0 Cc: U-Boot STM32 , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 5/5] test: dm: Add gpio get_alternate_function ops test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" In order to test get_alternate_function ops, add sandbox_gpio_set_function() and sandbox_gpio_set_alternate_function() to be able to configure a pin not as a GPIO and to select the alternate function index. Signed-off-by: Patrice Chotard Reviewed-by: Simon Glass --- Changes in v2: - Rename get_function_number to get_alternate_function in test/dm/gpio.c, drivers/gpio/sandbox.c and in arch/sandbox/include/asm/gpio.h arch/sandbox/include/asm/gpio.h | 24 ++++++++++++++++++++++++ drivers/gpio/sandbox.c | 27 +++++++++++++++++++++++++++ test/dm/gpio.c | 13 +++++++++++++ 3 files changed, 64 insertions(+) diff --git a/arch/sandbox/include/asm/gpio.h b/arch/sandbox/include/asm/gpio.h index de8ac37f4262..e7fb6d73ddd3 100644 --- a/arch/sandbox/include/asm/gpio.h +++ b/arch/sandbox/include/asm/gpio.h @@ -82,4 +82,28 @@ int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, int output); +/** + * Set the simulated usage of a pin, as a GPIO or not (used only in sandbox + * test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param value 0 to set as GPIO, 1 to set as not a GPIO + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_function(struct udevice *dev, unsigned int offset, + int value); + +/** + * Set the simulated alternate function of a pin when pin is not used as a GPIO + * (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param value pin alternate function number + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_alternate_function(struct udevice *dev, + unsigned int offset, + int value); #endif diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 50afa697d01c..c9720c824549 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -15,6 +15,8 @@ #define SDBX_GPIO_OUTPUT BIT(0) /* Currently set as an output */ #define SDBX_GPIO_HIGH BIT(1) /* Currently set high */ #define SDBX_GPIO_ODR BIT(2) /* Currently set to open drain mode */ +#define SDBX_GPIO_FUNC BIT(3) /* Currently set as not used as GPIO */ +#define SDBX_GPIO_FUNC_NB BIT(4) /* Currently set as function number 1 */ struct gpio_state { const char *label; /* label given by requester */ @@ -90,6 +92,19 @@ int sandbox_gpio_set_direction(struct udevice *dev, unsigned offset, int output) return set_gpio_flag(dev, offset, SDBX_GPIO_OUTPUT, output); } +int sandbox_gpio_set_function(struct udevice *dev, unsigned int offset, + int value) +{ + return set_gpio_flag(dev, offset, SDBX_GPIO_FUNC, value); +} + +int sandbox_gpio_set_alternate_function(struct udevice *dev, + unsigned int offset, + int value) +{ + return set_gpio_flag(dev, offset, SDBX_GPIO_FUNC_NB, value); +} + /* * These functions implement the public interface within U-Boot */ @@ -158,11 +173,22 @@ static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int valu static int sb_gpio_get_function(struct udevice *dev, unsigned offset) { + if (get_gpio_flag(dev, offset, SDBX_GPIO_FUNC)) + return GPIOF_FUNC; + if (get_gpio_flag(dev, offset, SDBX_GPIO_OUTPUT)) return GPIOF_OUTPUT; return GPIOF_INPUT; } +static int sb_gpio_get_alternate_function(struct udevice *dev, + unsigned int offset) +{ + debug("%s: offset:%u\n", __func__, offset); + + return get_gpio_flag(dev, offset, SDBX_GPIO_FUNC_NB); +} + static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { @@ -189,6 +215,7 @@ static const struct dm_gpio_ops gpio_sandbox_ops = { .get_open_drain = sb_gpio_get_open_drain, .set_open_drain = sb_gpio_set_open_drain, .get_function = sb_gpio_get_function, + .get_alternate_function = sb_gpio_get_alternate_function, .xlate = sb_gpio_xlate, }; diff --git a/test/dm/gpio.c b/test/dm/gpio.c index bb4b20cea938..4b792ae2164c 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -92,6 +92,19 @@ static int dm_test_gpio(struct unit_test_state *uts) ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: input: 0 [ ]", buf); + /* + * Make it not used as GPIO, select function + * (by default function number 0 is active) + */ + sandbox_gpio_set_function(dev, offset, 1); + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); + ut_asserteq_str("b4: func: 0", buf); + + /* select function number 1 */ + sandbox_gpio_set_alternate_function(dev, offset, 1); + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); + ut_asserteq_str("b4: func: 1", buf); + /* Check the 'a' bank also */ ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "base-gpios");