[PATCH v2 4/7] test: dm: regulator: provide test of auto setup
Svyatoslav Ryhel
clamor95 at gmail.com
Thu Jul 20 14:37:41 CEST 2023
Replace deprecated API test with test of uclass wide autosetup.
LDO2 voltage according to dts should be 3.3v not 3.0v
Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
---
include/power/sandbox_pmic.h | 2 +-
test/dm/regulator.c | 131 +++++++----------------------------
2 files changed, 27 insertions(+), 106 deletions(-)
diff --git a/include/power/sandbox_pmic.h b/include/power/sandbox_pmic.h
index 1dbd15b523..50fc5881f8 100644
--- a/include/power/sandbox_pmic.h
+++ b/include/power/sandbox_pmic.h
@@ -137,7 +137,7 @@ enum {
#define SANDBOX_LDO1_AUTOSET_EXPECTED_UA 100000
#define SANDBOX_LDO1_AUTOSET_EXPECTED_ENABLE true
-#define SANDBOX_LDO2_AUTOSET_EXPECTED_UV 3000000
+#define SANDBOX_LDO2_AUTOSET_EXPECTED_UV 3300000
#define SANDBOX_LDO2_AUTOSET_EXPECTED_UA -ENOSYS
#define SANDBOX_LDO2_AUTOSET_EXPECTED_ENABLE false
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 9b503e4c59..eb96ddcdac 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -182,12 +182,11 @@ static
int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts)
{
const char *platname;
- struct udevice *dev, *dev_autoset;
+ struct udevice *dev;
bool val_set = false;
/* Get BUCK1 - always on regulator */
platname = regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
ut_assertok(regulator_get_by_platname(platname, &dev));
/* Try disabling always-on regulator */
@@ -196,7 +195,6 @@ int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts)
/* Set the Enable of LDO1 - default is disabled */
platname = regulator_names[LDO1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
ut_assertok(regulator_get_by_platname(platname, &dev));
/* Get the Enable state of LDO1 and compare it with the requested one */
@@ -293,131 +291,54 @@ static int dm_test_power_regulator_set_get_suspend_enable(struct unit_test_state
}
DM_TEST(dm_test_power_regulator_set_get_suspend_enable, UT_TESTF_SCAN_FDT);
-/* Test regulator autoset method */
-static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
+/* Test regulator setup inside uclass driver */
+static int dm_test_power_regulator_set(struct unit_test_state *uts)
{
const char *platname;
- struct udevice *dev, *dev_autoset;
+ struct udevice *dev;
/*
- * Test the BUCK1 with fdt properties
- * - min-microvolt = max-microvolt = 1200000
- * - min-microamp = max-microamp = 200000
- * - always-on = set
- * - boot-on = not set
- * Expected output state: uV=1200000; uA=200000; output enabled
+ * LDO1 with fdt properties:
+ * - min-microvolt = max-microvolt = 1800000
+ * - min-microamp = max-microamp = 100000
+ * - always-on = not set
+ * - boot-on = set
+ * Expected output state: uV=1800000; uA=100000; output enabled
*/
- platname = regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
/* Check, that the returned device is proper */
+ platname = regulator_names[LDO1][PLATNAME];
ut_assertok(regulator_get_by_platname(platname, &dev));
- ut_asserteq_ptr(dev, dev_autoset);
/* Check the setup after autoset */
ut_asserteq(regulator_get_value(dev),
- SANDBOX_BUCK1_AUTOSET_EXPECTED_UV);
+ SANDBOX_LDO1_AUTOSET_EXPECTED_UV);
ut_asserteq(regulator_get_current(dev),
- SANDBOX_BUCK1_AUTOSET_EXPECTED_UA);
+ SANDBOX_LDO1_AUTOSET_EXPECTED_UA);
ut_asserteq(regulator_get_enable(dev),
- SANDBOX_BUCK1_AUTOSET_EXPECTED_ENABLE);
-
- return 0;
-}
-DM_TEST(dm_test_power_regulator_autoset, UT_TESTF_SCAN_FDT);
-
-/*
- * Struct setting: to keep the expected output settings.
- * @voltage: Voltage value [uV]
- * @current: Current value [uA]
- * @enable: output enable state: true/false
- */
-struct setting {
- int voltage;
- int current;
- bool enable;
-};
-
-/*
- * platname_list: an array of regulator platform names.
- * For testing regulator_list_autoset() for outputs:
- * - LDO1
- * - LDO2
- */
-static const char *platname_list[] = {
- SANDBOX_LDO1_PLATNAME,
- SANDBOX_LDO2_PLATNAME,
- NULL,
-};
-
-/*
- * expected_setting_list: an array of regulator output setting, expected after
- * call of the regulator_list_autoset() for the "platname_list" array.
- * For testing results of regulator_list_autoset() for outputs:
- * - LDO1
- * - LDO2
- * The settings are defined in: include/power/sandbox_pmic.h
- */
-static const struct setting expected_setting_list[] = {
- [0] = { /* LDO1 */
- .voltage = SANDBOX_LDO1_AUTOSET_EXPECTED_UV,
- .current = SANDBOX_LDO1_AUTOSET_EXPECTED_UA,
- .enable = SANDBOX_LDO1_AUTOSET_EXPECTED_ENABLE,
- },
- [1] = { /* LDO2 */
- .voltage = SANDBOX_LDO2_AUTOSET_EXPECTED_UV,
- .current = SANDBOX_LDO2_AUTOSET_EXPECTED_UA,
- .enable = SANDBOX_LDO2_AUTOSET_EXPECTED_ENABLE,
- },
-};
-
-static int list_count = ARRAY_SIZE(expected_setting_list);
-
-/* Test regulator list autoset method */
-static int dm_test_power_regulator_autoset_list(struct unit_test_state *uts)
-{
- struct udevice *dev_list[2], *dev;
- int i;
+ SANDBOX_LDO1_AUTOSET_EXPECTED_ENABLE);
/*
- * Test the settings of the regulator list:
- * LDO1 with fdt properties:
- * - min-microvolt = max-microvolt = 1800000
- * - min-microamp = max-microamp = 100000
- * - always-on = not set
- * - boot-on = set
- * Expected output state: uV=1800000; uA=100000; output enabled
- *
* LDO2 with fdt properties:
* - min-microvolt = max-microvolt = 3300000
* - always-on = not set
* - boot-on = not set
- * Expected output state: uV=300000(default); output disabled(default)
+ * Expected output state: uV=330000; output disabled
* The expected settings are defined in: include/power/sandbox_pmic.h.
*/
- ut_assertok(regulator_list_autoset(platname_list, dev_list, false));
- for (i = 0; i < list_count; i++) {
- /* Check, that the returned device is non-NULL */
- ut_assert(dev_list[i]);
-
- /* Check, that the returned device is proper */
- ut_assertok(regulator_get_by_platname(platname_list[i], &dev));
- ut_asserteq_ptr(dev_list[i], dev);
-
- /* Check, that regulator output Voltage value is as expected */
- ut_asserteq(regulator_get_value(dev_list[i]),
- expected_setting_list[i].voltage);
-
- /* Check, that regulator output Current value is as expected */
- ut_asserteq(regulator_get_current(dev_list[i]),
- expected_setting_list[i].current);
+ /* Check, that the returned device is proper */
+ platname = regulator_names[LDO2][PLATNAME];
+ ut_assertok(regulator_get_by_platname(platname, &dev));
- /* Check, that regulator output Enable state is as expected */
- ut_asserteq(regulator_get_enable(dev_list[i]),
- expected_setting_list[i].enable);
- }
+ /* Check the setup after autoset */
+ ut_asserteq(regulator_get_value(dev),
+ SANDBOX_LDO2_AUTOSET_EXPECTED_UV);
+ ut_asserteq(regulator_get_current(dev),
+ SANDBOX_LDO2_AUTOSET_EXPECTED_UA);
+ ut_asserteq(regulator_get_enable(dev),
+ SANDBOX_LDO2_AUTOSET_EXPECTED_ENABLE);
return 0;
}
-DM_TEST(dm_test_power_regulator_autoset_list, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set, UT_TESTF_SCAN_FDT);
--
2.39.2
More information about the U-Boot
mailing list