From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED60DC4338F for ; Sat, 7 Aug 2021 13:26:37 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44B9E610E7 for ; Sat, 7 Aug 2021 13:26:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 44B9E610E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A907783248; Sat, 7 Aug 2021 15:25:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lLITOcMF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4C5A982E4C; Sat, 7 Aug 2021 15:24:57 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 25F8C8311A for ; Sat, 7 Aug 2021 15:24:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x331.google.com with SMTP id v10-20020a9d604a0000b02904fa9613b53dso1334809otj.6 for ; Sat, 07 Aug 2021 06:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2uGjLZ0of7m5h9A1G2iWltfAs2y1+OVkGtnKz6nPqzM=; b=lLITOcMFSr7e4NiTVr3juQ95cBKj3ckH7+csUzGkQ2Go+zGkURUDtL/upwdwLcYc9J ZJ0Ka145iacwzojZ/HPJ+fCcTJVLE6bFKk2QPu/6iFhlPU+CXuZ5zN2GZT4jJzsO5DFH SDrY88IH1/YK0KNiqLy54Dhlz1ycbdT/JixNs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2uGjLZ0of7m5h9A1G2iWltfAs2y1+OVkGtnKz6nPqzM=; b=SF1Lr6hRBxgzNMzcMpOgtEKqSHSj/XiHjy1tQ23FClbOg1I6yNpEJtl0P+907Dpz52 62wnOjTo2K3YJUqKaolqkQ057j5vn2Ex9odpZ+MKEUgdnP8J3IMqgWdjs7YMIQuqLufP Vk8NL/u8ObPEcSVOi8CNgHsLMDjjmhqDI7RBDZ2ggwAbZ3TE2t8pXrMhxyjVsEGIuKAH 1hIW6Hr29F8iuITT8IhJPwY3Y6MmBbs/4fdyFRuXqhgbPTTUKDKLGWVp92R++qDCtCeC 3nOn+0L9JqVjDT9F2Mg8fMHKTd94j2yFW91M8TfYeZJvXgzsTVR9yT9w3vroeCgd/5MA 6T8A== X-Gm-Message-State: AOAM533Ca4h3/4g4sAqjEiVarzFus/nfcZcLvMYasa5oKCSCoxMWEJK2 lwmxfvgrrR6yGojYKOnFI0q5MqxPl1wYQ1c8 X-Google-Smtp-Source: ABdhPJy/6F/rcz4jABpXPbHOl1bznFeV/MV+IYxBQaXqPPpjBJ1CSQMG32xx2XfBUFh3rAOAx8/GMw== X-Received: by 2002:a05:6830:89:: with SMTP id a9mr11092896oto.83.1628342669566; Sat, 07 Aug 2021 06:24:29 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id x16sm1866417ooj.1.2021.08.07.06.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 06:24:29 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH 12/12] dm: gpio: Add of-platdata support Date: Sat, 7 Aug 2021 07:24:12 -0600 Message-Id: <20210807132413.3513724-13-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog In-Reply-To: <20210807132413.3513724-1-sjg@chromium.org> References: <20210807132413.3513724-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Add support for accessing GPIOs using of-plata. This uses the same mechanism as for clocks, but allows use of the xlate() method so that the driver can interpret the parameters. Update the condition for GPIO_HOG so that it is not built into SPL, since it needs SPL_OF_REAL which is not enabled in sandbox_spl. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dtsi | 8 +++++++- configs/sandbox_noinst_defconfig | 2 ++ configs/sandbox_spl_defconfig | 2 ++ drivers/gpio/Makefile | 4 ++-- drivers/gpio/gpio-uclass.c | 26 ++++++++++++++++++++++++-- drivers/gpio/sandbox.c | 14 ++++++++++---- drivers/gpio/sandbox_test.c | 21 +++++++++++++++++++++ include/asm-generic/gpio.h | 5 +++++ test/dm/of_platdata.c | 20 ++++++++++++++++++++ 9 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 drivers/gpio/sandbox_test.c diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 819e81464af..2d42cda6ebb 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -65,7 +65,7 @@ }; gpio_b: gpios@1 { - u-boot,dm-pre-proper; + u-boot,dm-spl; gpio-controller; compatible = "sandbox,gpio"; #gpio-cells = <2>; @@ -73,6 +73,12 @@ sandbox,gpio-count = <10>; }; + gpio-test { + u-boot,dm-spl; + compatible = "sandbox,gpio-test"; + test-gpios = <&gpio_b 3 0>; + }; + hexagon { compatible = "demo-simple"; colour = "white"; diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig index 88443f5ab27..4a6f0ee8b87 100644 --- a/configs/sandbox_noinst_defconfig +++ b/configs/sandbox_noinst_defconfig @@ -1,4 +1,5 @@ CONFIG_SYS_TEXT_BASE=0x200000 +CONFIG_SPL_GPIO=y CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_NR_DRAM_BANKS=1 @@ -120,6 +121,7 @@ CONFIG_SANDBOX_GPIO=y CONFIG_I2C_CROS_EC_TUNNEL=y CONFIG_I2C_CROS_EC_LDO=y CONFIG_DM_I2C_GPIO=y +# CONFIG_SPL_DM_I2C_GPIO is not set CONFIG_SYS_I2C_SANDBOX=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index 77dd83cf6fd..0e8098e2f40 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -1,4 +1,5 @@ CONFIG_SYS_TEXT_BASE=0x200000 +CONFIG_SPL_GPIO=y CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_NR_DRAM_BANKS=1 @@ -122,6 +123,7 @@ CONFIG_SANDBOX_GPIO=y CONFIG_I2C_CROS_EC_TUNNEL=y CONFIG_I2C_CROS_EC_LDO=y CONFIG_DM_I2C_GPIO=y +# CONFIG_SPL_DM_I2C_GPIO is not set CONFIG_SYS_I2C_SANDBOX=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 16b09fb1b5b..662ed5050b5 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -32,7 +32,7 @@ obj-$(CONFIG_ROCKCHIP_GPIO) += rk_gpio.o obj-$(CONFIG_RCAR_GPIO) += gpio-rcar.o obj-$(CONFIG_RZA1_GPIO) += gpio-rza1.o obj-$(CONFIG_S5P) += s5p_gpio.o -obj-$(CONFIG_SANDBOX_GPIO) += sandbox.o +obj-$(CONFIG_SANDBOX_GPIO) += sandbox.o sandbox_test.o obj-$(CONFIG_TEGRA_GPIO) += tegra_gpio.o obj-$(CONFIG_TEGRA186_GPIO) += tegra186_gpio.o obj-$(CONFIG_DA8XX_GPIO) += da8xx_gpio.o @@ -61,7 +61,7 @@ obj-$(CONFIG_OCTEON_GPIO) += octeon_gpio.o obj-$(CONFIG_MVEBU_GPIO) += mvebu_gpio.o obj-$(CONFIG_MSM_GPIO) += msm_gpio.o obj-$(CONFIG_$(SPL_)PCF8575_GPIO) += pcf8575_gpio.o -obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o +obj-$(CONFIG_$(SPL_TPL_)PM8916_GPIO) += pm8916_gpio.o obj-$(CONFIG_MT7620_GPIO) += mt7620_gpio.o obj-$(CONFIG_MT7621_GPIO) += mt7621_gpio.o obj-$(CONFIG_MSCC_SGPIO) += mscc_sgpio.o diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index e0d3ae6f8cf..bb2f23241ed 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -231,7 +232,7 @@ static int gpio_find_and_xlate(struct gpio_desc *desc, return gpio_xlate_offs_flags(desc->dev, desc, args); } -#if defined(CONFIG_GPIO_HOG) +#if CONFIG_IS_ENABLED(GPIO_HOG) struct gpio_hog_priv { struct gpio_desc gpiod; @@ -1226,6 +1227,27 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name) } #endif /* OF_PLATDATA */ +#if CONFIG_IS_ENABLED(OF_PLATDATA) +int gpio_request_by_phandle(struct udevice *dev, + const struct phandle_2_arg *cells, + struct gpio_desc *desc, int flags) +{ + struct ofnode_phandle_args args; + struct udevice *gpio_dev; + const int index = 0; + int ret; + + ret = device_get_by_ofplat_idx(cells->idx, &gpio_dev); + if (ret) + return ret; + args.args[0] = cells->arg[0]; + args.args[1] = cells->arg[1]; + + return gpio_request_tail(ret, NULL, &args, NULL, index, desc, flags, + index > 0, gpio_dev); +} +#endif + int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc) { /* For now, we don't do any checking of dev */ @@ -1430,7 +1452,7 @@ static int gpio_post_bind(struct udevice *dev) } #endif - if (IS_ENABLED(CONFIG_GPIO_HOG)) { + if (CONFIG_IS_ENABLED(OF_REAL) && IS_ENABLED(CONFIG_GPIO_HOG)) { dev_for_each_subnode(node, dev) { if (ofnode_read_bool(node, "gpio-hog")) { const char *name = ofnode_get_name(node); diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index d008fdd2224..106b2a7b27c 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -323,11 +323,13 @@ static const struct dm_gpio_ops gpio_sandbox_ops = { static int sandbox_gpio_of_to_plat(struct udevice *dev) { - struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + if (CONFIG_IS_ENABLED(OF_REAL)) { + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - uc_priv->gpio_count = dev_read_u32_default(dev, "sandbox,gpio-count", - 0); - uc_priv->bank_name = dev_read_string(dev, "gpio-bank-name"); + uc_priv->gpio_count = + dev_read_u32_default(dev, "sandbox,gpio-count", 0); + uc_priv->bank_name = dev_read_string(dev, "gpio-bank-name"); + } return 0; } @@ -371,6 +373,8 @@ U_BOOT_DRIVER(sandbox_gpio) = { DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias) +#if CONFIG_IS_ENABLED(PINCTRL) + /* pincontrol: used only to check GPIO pin configuration (pinmux command) */ struct sb_pinctrl_priv { @@ -579,3 +583,5 @@ U_BOOT_DRIVER(sandbox_pinctrl_gpio) = { .priv_auto = sizeof(struct sb_pinctrl_priv), ACPI_OPS_PTR(&pinctrl_sandbox_acpi_ops) }; + +#endif /* PINCTRL */ diff --git a/drivers/gpio/sandbox_test.c b/drivers/gpio/sandbox_test.c new file mode 100644 index 00000000000..c76e1997419 --- /dev/null +++ b/drivers/gpio/sandbox_test.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sandbox driver for testing GPIOs with of-platdata + * + * Copyright 2021 Google LLC + */ + +#include +#include +#include + +static const struct udevice_id sandbox_gpio_test_ids[] = { + { .compatible = "sandbox,gpio-test" }, + { } +}; + +U_BOOT_DRIVER(sandbox_gpio_test) = { + .name = "sandbox_gpio_test", + .id = UCLASS_MISC, + .of_match = sandbox_gpio_test_ids, +}; diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index e33cde7abdd..6de13d925eb 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -608,6 +608,11 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name, */ int dm_gpio_request(struct gpio_desc *desc, const char *label); +struct phandle_2_arg; +int gpio_request_by_phandle(struct udevice *dev, + const struct phandle_2_arg *cells, + struct gpio_desc *desc, int flags); + /** * gpio_get_list_count() - Returns the number of GPIOs in a list * diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c index 082989021d9..ec41087a558 100644 --- a/test/dm/of_platdata.c +++ b/test/dm/of_platdata.c @@ -8,6 +8,7 @@ #include #include #include +#include #include /* Test that we can find a device using of-platdata */ @@ -259,3 +260,22 @@ static int dm_test_of_plat_irq(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_of_plat_irq, UT_TESTF_SCAN_PDATA); + +/* Test GPIOs with of-platdata */ +static int dm_test_of_plat_gpio(struct unit_test_state *uts) +{ + struct dtd_sandbox_gpio_test *plat; + struct udevice *dev; + struct gpio_desc desc; + + ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_gpio_test", + &dev)); + plat = dev_get_plat(dev); + + ut_assertok(gpio_request_by_phandle(dev, &plat->test_gpios[0], &desc, + GPIOD_IS_OUT)); + ut_asserteq_str("sandbox_gpio", desc.dev->name); + + return 0; +} +DM_TEST(dm_test_of_plat_gpio, UT_TESTF_SCAN_PDATA); -- 2.32.0.605.g8dce9f2422-goog