From: Mehmet Fide <[email protected]>

Give sandbox a fixed regulator with an enable GPIO and a gpio regulator
with a voltage GPIO and check the two phases explicitly: after
of_to_plat() the pin is unclaimed in the GPIO name table and its
simulated direction is still the input default; only probe() requests
it and turns it into an output; enabling the regulator, or switching
its voltage, then moves the pin.

The pins come from the pinmux-gpios bank, whose two cells also carry
the flags the way a real regulator node does; the base-gpios bank has
no offset left that the other tests or its hogs do not use. The gpio
regulator driver was not built for sandbox before.

Signed-off-by: Mehmet Fide <[email protected]>
---

Notes:
    Changes in v2:
    - move the regulator to c8 in the pinmux-gpios bank, a10 is a hog pin
      (Simon Glass)
    - name the node fixed-gpio-reg instead of the compatible (Simon Glass)
    - add a gpio regulator on c9 and a test for it, enable
      CONFIG_DM_REGULATOR_GPIO in the sandbox defconfigs (Simon Glass)
    - check the simulated pad direction, not only the name table (Simon Glass)

 arch/sandbox/dts/test.dts          | 18 ++++++++++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 configs/sandbox_vpl_defconfig      |  1 +
 test/dm/regulator.c                | 58 ++++++++++++++++++++++++++++++
 8 files changed, 82 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a5d8d3977a0..b05f4c24c3a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -883,6 +883,24 @@
                compatible = "sandbox,fpga";
        };
 
+       fixed_gpio_reg: fixed-gpio-reg {
+               compatible = "regulator-fixed";
+               regulator-name = "fixed-gpio-enabled";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               enable-active-high;
+               gpio = <&gpio_c 8 GPIO_ACTIVE_HIGH>;
+       };
+
+       gpio_reg: gpio-reg {
+               compatible = "regulator-gpio";
+               regulator-name = "gpio-switched";
+               regulator-min-microvolt = <1800000>;
+               regulator-max-microvolt = <3300000>;
+               gpios = <&gpio_c 9 GPIO_ACTIVE_HIGH>;
+               states = <1800000 0>, <3300000 1>;
+       };
+
        pinctrl-gpio {
                compatible = "sandbox,pinctrl-gpio";
 
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 070ef0b6369..59e08d03f77 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -220,6 +220,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index c6edd9d2423..5ebbe5ca8f6 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -308,6 +308,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
diff --git a/configs/sandbox_flattree_defconfig 
b/configs/sandbox_flattree_defconfig
index 9546fbf730f..57f915d4ba9 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -175,6 +175,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig
index 0708b65ea80..7a755012795 100644
--- a/configs/sandbox_noinst_defconfig
+++ b/configs/sandbox_noinst_defconfig
@@ -219,6 +219,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index 11f16f5d622..60b497f4888 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -186,6 +186,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
diff --git a/configs/sandbox_vpl_defconfig b/configs/sandbox_vpl_defconfig
index c7df8571663..c85bfbfb3b1 100644
--- a/configs/sandbox_vpl_defconfig
+++ b/configs/sandbox_vpl_defconfig
@@ -193,6 +193,7 @@ CONFIG_DM_REGULATOR=y
 CONFIG_REGULATOR_ACT8846=y
 CONFIG_DM_REGULATOR_MAX77686=y
 CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 51007d4079d..123cee6f499 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,63 @@ 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);
 
+/* Reading the platform data must leave the pin untouched, probe claims it */
+static int check_gpio_claimed_in_probe(struct unit_test_state *uts,
+                                      struct udevice *dev, struct gpio_desc 
*chk)
+{
+       ut_assertok(device_of_to_plat(dev));
+       ut_asserteq(GPIOF_UNUSED, gpio_get_function(chk->dev, chk->offset,
+                                                   NULL));
+       ut_asserteq(0, sandbox_gpio_get_direction(chk->dev, chk->offset));
+
+       ut_assertok(device_probe(dev));
+       ut_asserteq(GPIOF_OUTPUT, gpio_get_function(chk->dev, chk->offset,
+                                                   NULL));
+       ut_assert(sandbox_gpio_get_direction(chk->dev, chk->offset) > 0);
+
+       return 0;
+}
+
+/* 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,
+                                              "fixed-gpio-reg", &dev));
+       ut_assertok(dm_gpio_lookup_name("c8", &chk));
+       ut_assertok(check_gpio_claimed_in_probe(uts, dev, &chk));
+
+       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);
+
+/* The gpio regulator must claim its voltage GPIO in probe, not before */
+static int dm_test_power_regulator_gpio_value_gpio(struct unit_test_state *uts)
+{
+       struct gpio_desc chk;
+       struct udevice *dev;
+
+       ut_assertok(uclass_find_device_by_name(UCLASS_REGULATOR, "gpio-reg",
+                                              &dev));
+       ut_assertok(dm_gpio_lookup_name("c9", &chk));
+       ut_assertok(check_gpio_claimed_in_probe(uts, dev, &chk));
+
+       ut_assertok(regulator_set_value(dev, 3300000));
+       ut_asserteq(1, sandbox_gpio_get_value(chk.dev, chk.offset));
+       ut_assertok(regulator_set_value(dev, 1800000));
+       ut_asserteq(0, sandbox_gpio_get_value(chk.dev, chk.offset));
+
+       return 0;
+}
+DM_TEST(dm_test_power_regulator_gpio_value_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.55.0

Reply via email to