[PATCH 4/4] test: dm: check the fixed regulator claims its GPIO at probe time

Mehmet Fide <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
From: Mehmet Fide <[email protected]>

Give sandbox a fixed regulator with an enable GPIO and check the two
phases explicitly: after of_to_plat() the GPIO is still unclaimed, and
only probe() requests it and sets the direction; enabling and disabling
the regulator then moves the pin.

Signed-off-by: Mehmet Fide <[email protected]>
---
 arch/sandbox/dts/test.dts |  9 +++++++++
 test/dm/regulator.c       | 29 +++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index d24feec5422..19773305b4c 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -880,6 +880,15 @@
 		compatible = "sandbox,fpga";
 	};
 
+	fixed_gpio_reg: regulator-fixed {
+		compatible = "regulator-fixed";
+		regulator-name = "fixed-gpio-enabled";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+		enable-active-high;
+		gpio = <&gpio_a 10>;
+	};
+
 	pinctrl-gpio {
 		compatible = "sandbox,pinctrl-gpio";
 
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 51007d4079d..b78627023af 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -12,6 +12,7 @@
 #include <log.h>
 #include <malloc.h>
 #include <dm/device-internal.h>
+#include <asm/gpio.h>
 #include <dm/root.h>
 #include <dm/util.h>
 #include <dm/test.h>
@@ -195,6 +196,34 @@ static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_power_regulator_set_get_current, UTF_SCAN_FDT);
 
+/* The fixed regulator must claim its enable GPIO in probe, not before */
+static int dm_test_power_regulator_fixed_enable_gpio(struct unit_test_state *uts)
+{
+	struct gpio_desc chk;
+	struct udevice *dev;
+
+	ut_assertok(uclass_find_device_by_name(UCLASS_REGULATOR,
+					       "regulator-fixed", &dev));
+	ut_assertok(device_of_to_plat(dev));
+	ut_assertok(dm_gpio_lookup_name("a10", &chk));
+
+	/* reading the platform data must not have claimed the GPIO */
+	ut_asserteq(GPIOF_UNUSED, gpio_get_function(chk.dev, chk.offset,
+						    NULL));
+
+	ut_assertok(device_probe(dev));
+	ut_asserteq(GPIOF_OUTPUT, gpio_get_function(chk.dev, chk.offset,
+						    NULL));
+
+	ut_assertok(regulator_set_enable(dev, true));
+	ut_asserteq(1, sandbox_gpio_get_value(chk.dev, chk.offset));
+	ut_assertok(regulator_set_enable(dev, false));
+	ut_asserteq(0, sandbox_gpio_get_value(chk.dev, chk.offset));
+
+	return 0;
+}
+DM_TEST(dm_test_power_regulator_fixed_enable_gpio, UTF_SCAN_FDT);
+
 /* Test regulator set and get Enable method */
 static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts)
 {
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.