Hi Mehmet,

On 2026-08-28T10:52:07, Mehmet Fide <[email protected]> wrote:
> test: dm: check the fixed regulator claims its GPIO at probe time
>
> 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
> @@ -883,6 +883,15 @@
> +     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>;
> +     };

Pin a10 is already used by hog_input_active_low further down in this
file. It happens to work because the test framework binds but does not
auto-probe DM_FLAG_PROBE_AFTER_BIND devices, so the hog never claims
the pin - but that is a subtle dependency a reader cannot see. Please
pick a pin not otherwise referenced in test.dts (a15-a18 look free),
or extend the bank and use a fresh offset.

> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> @@ -883,6 +883,15 @@
> +     fixed_gpio_reg: regulator-fixed {
> +             compatible = "regulator-fixed";

The node name regulator-fixed matches the compatible and is what
uclass_find_device_by_name() then keys on. If anyone adds a second
fixed regulator to test.dts the lookup becomes ambiguous. Please give
the node a distinctive name (e.g. fixed-gpio-reg matching the label)
so the test is not accidentally tied to being the only regulator-fixed
instance.

> diff --git a/test/dm/regulator.c b/test/dm/regulator.c
> @@ -195,6 +196,34 @@ static int 
> dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
> +/* 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)

Patch 2 moves the same claim-in-probe pattern into gpio-regulator and
fixed-clock, but only fixed-regulator is covered here. Please add
analogous cases (or parametrise this one) so a future regression in
either of the other two drivers is caught.

> diff --git a/test/dm/regulator.c b/test/dm/regulator.c
> @@ -195,6 +196,34 @@ static int 
> dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
> +     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));

gpio_get_function() returns GPIOF_UNUSED whenever the pin is not
claimed via the DM name table, regardless of the sandbox pad state. So
this assertion only proves 'no dm_gpio_request() ran', not that the
direction was untouched. Would it be worth checking that on sandbox
the pad-level value/direction is what pinctrl (or the reset default)
set?

Regards,
Simon

Reply via email to