Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Tests for the driver model regulator API |
| 4 | * |
| 5 | * Copyright (c) 2015 Samsung Electronics |
| 6 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <dm.h> |
| 11 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/root.h> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 16 | #include <dm/util.h> |
| 17 | #include <dm/test.h> |
| 18 | #include <dm/uclass-internal.h> |
| 19 | #include <power/pmic.h> |
| 20 | #include <power/regulator.h> |
| 21 | #include <power/sandbox_pmic.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 22 | #include <test/test.h> |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 23 | #include <test/ut.h> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 24 | |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 25 | enum { |
| 26 | BUCK1, |
| 27 | BUCK2, |
Felix Brack | e23c388 | 2017-11-27 09:14:16 +0100 | [diff] [blame] | 28 | BUCK3, |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 29 | LDO1, |
| 30 | LDO2, |
| 31 | OUTPUT_COUNT, |
| 32 | }; |
| 33 | |
| 34 | enum { |
| 35 | DEVNAME = 0, |
| 36 | PLATNAME, |
| 37 | OUTPUT_NAME_COUNT, |
| 38 | }; |
| 39 | |
| 40 | static const char *regulator_names[OUTPUT_COUNT][OUTPUT_NAME_COUNT] = { |
| 41 | /* devname, platname */ |
| 42 | { SANDBOX_BUCK1_DEVNAME, SANDBOX_BUCK1_PLATNAME }, |
| 43 | { SANDBOX_BUCK2_DEVNAME, SANDBOX_BUCK2_PLATNAME }, |
Felix Brack | e23c388 | 2017-11-27 09:14:16 +0100 | [diff] [blame] | 44 | { SANDBOX_BUCK3_DEVNAME, SANDBOX_BUCK3_PLATNAME }, |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 45 | { SANDBOX_LDO1_DEVNAME, SANDBOX_LDO1_PLATNAME}, |
| 46 | { SANDBOX_LDO2_DEVNAME, SANDBOX_LDO2_PLATNAME}, |
| 47 | }; |
| 48 | |
| 49 | /* Test regulator get method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 50 | static int dm_test_power_regulator_get(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 51 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 52 | struct dm_regulator_uclass_plat *uc_pdata; |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 53 | struct udevice *dev_by_devname; |
| 54 | struct udevice *dev_by_platname; |
| 55 | const char *devname; |
| 56 | const char *platname; |
| 57 | int i; |
| 58 | |
| 59 | for (i = 0; i < OUTPUT_COUNT; i++) { |
| 60 | /* |
| 61 | * Do the test for each regulator's devname and platname, |
| 62 | * which are related to a single device. |
| 63 | */ |
| 64 | devname = regulator_names[i][DEVNAME]; |
| 65 | platname = regulator_names[i][PLATNAME]; |
| 66 | |
| 67 | /* |
| 68 | * Check, that regulator_get_by_devname() function, returns |
| 69 | * a device with the name equal to the requested one. |
| 70 | */ |
| 71 | ut_assertok(regulator_get_by_devname(devname, &dev_by_devname)); |
| 72 | ut_asserteq_str(devname, dev_by_devname->name); |
| 73 | |
| 74 | /* |
| 75 | * Check, that regulator_get_by_platname() function, returns |
| 76 | * a device with the name equal to the requested one. |
| 77 | */ |
| 78 | ut_assertok(regulator_get_by_platname(platname, &dev_by_platname)); |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 79 | uc_pdata = dev_get_uclass_plat(dev_by_platname); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 80 | ut_assert(uc_pdata); |
| 81 | ut_asserteq_str(platname, uc_pdata->name); |
| 82 | |
| 83 | /* |
| 84 | * Check, that the pointers returned by both get functions, |
| 85 | * points to the same regulator device. |
| 86 | */ |
| 87 | ut_asserteq_ptr(dev_by_devname, dev_by_platname); |
| 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 92 | DM_TEST(dm_test_power_regulator_get, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 93 | |
| 94 | /* Test regulator set and get Voltage method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 95 | static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 96 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 97 | struct dm_regulator_uclass_plat *uc_pdata; |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 98 | struct udevice *dev; |
| 99 | const char *platname; |
| 100 | int val_set, val_get; |
| 101 | |
| 102 | /* Set and get Voltage of BUCK1 - set to 'min' constraint */ |
| 103 | platname = regulator_names[BUCK1][PLATNAME]; |
| 104 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 105 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 106 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 107 | ut_assert(uc_pdata); |
| 108 | |
| 109 | val_set = uc_pdata->min_uV; |
| 110 | ut_assertok(regulator_set_value(dev, val_set)); |
| 111 | |
| 112 | val_get = regulator_get_value(dev); |
| 113 | ut_assert(val_get >= 0); |
| 114 | |
| 115 | ut_asserteq(val_set, val_get); |
| 116 | |
| 117 | return 0; |
| 118 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 119 | DM_TEST(dm_test_power_regulator_set_get_voltage, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 120 | |
| 121 | /* Test regulator set and get Current method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 122 | static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 123 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 124 | struct dm_regulator_uclass_plat *uc_pdata; |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 125 | struct udevice *dev; |
| 126 | const char *platname; |
| 127 | int val_set, val_get; |
| 128 | |
| 129 | /* Set and get the Current of LDO1 - set to 'min' constraint */ |
| 130 | platname = regulator_names[LDO1][PLATNAME]; |
| 131 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 132 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 133 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 134 | ut_assert(uc_pdata); |
| 135 | |
| 136 | val_set = uc_pdata->min_uA; |
| 137 | ut_assertok(regulator_set_current(dev, val_set)); |
| 138 | |
| 139 | val_get = regulator_get_current(dev); |
| 140 | ut_assert(val_get >= 0); |
| 141 | |
| 142 | ut_asserteq(val_set, val_get); |
| 143 | |
| 144 | /* Check LDO2 current limit constraints - should be -ENODATA */ |
| 145 | platname = regulator_names[LDO2][PLATNAME]; |
| 146 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 147 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 148 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 149 | ut_assert(uc_pdata); |
| 150 | ut_asserteq(-ENODATA, uc_pdata->min_uA); |
| 151 | ut_asserteq(-ENODATA, uc_pdata->max_uA); |
| 152 | |
| 153 | /* Try set the Current of LDO2 - should return -ENOSYS */ |
| 154 | ut_asserteq(-ENOSYS, regulator_set_current(dev, 0)); |
| 155 | |
| 156 | return 0; |
| 157 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 158 | DM_TEST(dm_test_power_regulator_set_get_current, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 159 | |
| 160 | /* Test regulator set and get Enable method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 161 | static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 162 | { |
| 163 | const char *platname; |
| 164 | struct udevice *dev; |
| 165 | bool val_set = true; |
| 166 | |
| 167 | /* Set the Enable of LDO1 - default is disabled */ |
| 168 | platname = regulator_names[LDO1][PLATNAME]; |
| 169 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 170 | ut_assertok(regulator_set_enable(dev, val_set)); |
| 171 | |
| 172 | /* Get the Enable state of LDO1 and compare it with the requested one */ |
| 173 | ut_asserteq(regulator_get_enable(dev), val_set); |
| 174 | |
| 175 | return 0; |
| 176 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 177 | DM_TEST(dm_test_power_regulator_set_get_enable, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 178 | |
Lokesh Vutla | 7106b78 | 2019-01-11 15:15:51 +0530 | [diff] [blame] | 179 | /* Test regulator set and get enable if allowed method */ |
| 180 | static |
| 181 | int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts) |
| 182 | { |
| 183 | const char *platname; |
| 184 | struct udevice *dev, *dev_autoset; |
| 185 | bool val_set = false; |
| 186 | |
| 187 | /* Get BUCK1 - always on regulator */ |
| 188 | platname = regulator_names[BUCK1][PLATNAME]; |
| 189 | ut_assertok(regulator_autoset_by_name(platname, &dev_autoset)); |
| 190 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 191 | |
| 192 | /* Try disabling always-on regulator */ |
| 193 | ut_assertok(regulator_set_enable_if_allowed(dev, val_set)); |
| 194 | ut_asserteq(regulator_get_enable(dev), !val_set); |
| 195 | |
| 196 | return 0; |
| 197 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 198 | DM_TEST(dm_test_power_regulator_set_enable_if_allowed, UT_TESTF_SCAN_FDT); |
Lokesh Vutla | 7106b78 | 2019-01-11 15:15:51 +0530 | [diff] [blame] | 199 | |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 200 | /* Test regulator set and get mode method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 201 | static int dm_test_power_regulator_set_get_mode(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 202 | { |
| 203 | const char *platname; |
| 204 | struct udevice *dev; |
| 205 | int val_set = LDO_OM_SLEEP; |
| 206 | |
| 207 | /* Set the mode id to LDO_OM_SLEEP of LDO1 - default is LDO_OM_OFF */ |
| 208 | platname = regulator_names[LDO1][PLATNAME]; |
| 209 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 210 | ut_assertok(regulator_set_mode(dev, val_set)); |
| 211 | |
| 212 | /* Get the mode id of LDO1 and compare it with the requested one */ |
| 213 | ut_asserteq(regulator_get_mode(dev), val_set); |
| 214 | |
| 215 | return 0; |
| 216 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 217 | DM_TEST(dm_test_power_regulator_set_get_mode, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 218 | |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 219 | /* Test regulator set and get suspend Voltage method */ |
| 220 | static int dm_test_power_regulator_set_get_suspend_voltage(struct unit_test_state *uts) |
| 221 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 222 | struct dm_regulator_uclass_plat *uc_pdata; |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 223 | const struct dm_regulator_ops *ops; |
| 224 | struct udevice *dev; |
| 225 | const char *platname; |
| 226 | int val_set, val_get; |
| 227 | |
| 228 | /* Set and get Voltage of BUCK1 - set to 'min' constraint */ |
| 229 | platname = regulator_names[BUCK1][PLATNAME]; |
| 230 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 231 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 232 | uc_pdata = dev_get_uclass_plat(dev); |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 233 | ut_assert(uc_pdata); |
| 234 | |
| 235 | ops = dev_get_driver_ops(dev); |
| 236 | |
| 237 | if (ops->set_suspend_value && ops->get_suspend_value) { |
| 238 | val_set = uc_pdata->suspend_uV; |
| 239 | ut_assertok(regulator_set_suspend_value(dev, val_set)); |
| 240 | val_get = regulator_get_suspend_value(dev); |
| 241 | ut_assert(val_get >= 0); |
| 242 | |
| 243 | ut_asserteq(val_set, val_get); |
| 244 | } |
| 245 | return 0; |
| 246 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 247 | DM_TEST(dm_test_power_regulator_set_get_suspend_voltage, UT_TESTF_SCAN_FDT); |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 248 | |
| 249 | /* Test regulator set and get suspend Enable method */ |
| 250 | static int dm_test_power_regulator_set_get_suspend_enable(struct unit_test_state *uts) |
| 251 | { |
| 252 | const struct dm_regulator_ops *ops; |
| 253 | const char *platname; |
| 254 | struct udevice *dev; |
| 255 | bool val_set = true; |
| 256 | |
| 257 | /* Set the Enable of LDO1 - default is disabled */ |
| 258 | platname = regulator_names[LDO1][PLATNAME]; |
| 259 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 260 | |
| 261 | ops = dev_get_driver_ops(dev); |
| 262 | |
| 263 | if (ops->set_suspend_enable && ops->get_suspend_enable) { |
| 264 | ut_assertok(regulator_set_suspend_enable(dev, val_set)); |
| 265 | |
| 266 | /* |
| 267 | * Get the Enable state of LDO1 and |
| 268 | * compare it with the requested one |
| 269 | */ |
| 270 | ut_asserteq(regulator_get_suspend_enable(dev), val_set); |
| 271 | } |
| 272 | return 0; |
| 273 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 274 | DM_TEST(dm_test_power_regulator_set_get_suspend_enable, UT_TESTF_SCAN_FDT); |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 275 | |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 276 | /* Test regulator autoset method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 277 | static int dm_test_power_regulator_autoset(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 278 | { |
| 279 | const char *platname; |
| 280 | struct udevice *dev, *dev_autoset; |
| 281 | |
| 282 | /* |
| 283 | * Test the BUCK1 with fdt properties |
| 284 | * - min-microvolt = max-microvolt = 1200000 |
| 285 | * - min-microamp = max-microamp = 200000 |
| 286 | * - always-on = set |
| 287 | * - boot-on = not set |
| 288 | * Expected output state: uV=1200000; uA=200000; output enabled |
| 289 | */ |
| 290 | platname = regulator_names[BUCK1][PLATNAME]; |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 291 | ut_assertok(regulator_autoset_by_name(platname, &dev_autoset)); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 292 | |
| 293 | /* Check, that the returned device is proper */ |
| 294 | ut_assertok(regulator_get_by_platname(platname, &dev)); |
| 295 | ut_asserteq_ptr(dev, dev_autoset); |
| 296 | |
| 297 | /* Check the setup after autoset */ |
| 298 | ut_asserteq(regulator_get_value(dev), |
| 299 | SANDBOX_BUCK1_AUTOSET_EXPECTED_UV); |
| 300 | ut_asserteq(regulator_get_current(dev), |
| 301 | SANDBOX_BUCK1_AUTOSET_EXPECTED_UA); |
| 302 | ut_asserteq(regulator_get_enable(dev), |
| 303 | SANDBOX_BUCK1_AUTOSET_EXPECTED_ENABLE); |
| 304 | |
| 305 | return 0; |
| 306 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 307 | DM_TEST(dm_test_power_regulator_autoset, UT_TESTF_SCAN_FDT); |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Struct setting: to keep the expected output settings. |
| 311 | * @voltage: Voltage value [uV] |
| 312 | * @current: Current value [uA] |
| 313 | * @enable: output enable state: true/false |
| 314 | */ |
| 315 | struct setting { |
| 316 | int voltage; |
| 317 | int current; |
| 318 | bool enable; |
| 319 | }; |
| 320 | |
| 321 | /* |
| 322 | * platname_list: an array of regulator platform names. |
| 323 | * For testing regulator_list_autoset() for outputs: |
| 324 | * - LDO1 |
| 325 | * - LDO2 |
| 326 | */ |
| 327 | static const char *platname_list[] = { |
| 328 | SANDBOX_LDO1_PLATNAME, |
| 329 | SANDBOX_LDO2_PLATNAME, |
| 330 | NULL, |
| 331 | }; |
| 332 | |
| 333 | /* |
| 334 | * expected_setting_list: an array of regulator output setting, expected after |
| 335 | * call of the regulator_list_autoset() for the "platname_list" array. |
| 336 | * For testing results of regulator_list_autoset() for outputs: |
| 337 | * - LDO1 |
| 338 | * - LDO2 |
| 339 | * The settings are defined in: include/power/sandbox_pmic.h |
| 340 | */ |
| 341 | static const struct setting expected_setting_list[] = { |
| 342 | [0] = { /* LDO1 */ |
| 343 | .voltage = SANDBOX_LDO1_AUTOSET_EXPECTED_UV, |
| 344 | .current = SANDBOX_LDO1_AUTOSET_EXPECTED_UA, |
| 345 | .enable = SANDBOX_LDO1_AUTOSET_EXPECTED_ENABLE, |
| 346 | }, |
| 347 | [1] = { /* LDO2 */ |
| 348 | .voltage = SANDBOX_LDO2_AUTOSET_EXPECTED_UV, |
| 349 | .current = SANDBOX_LDO2_AUTOSET_EXPECTED_UA, |
| 350 | .enable = SANDBOX_LDO2_AUTOSET_EXPECTED_ENABLE, |
| 351 | }, |
| 352 | }; |
| 353 | |
| 354 | static int list_count = ARRAY_SIZE(expected_setting_list); |
| 355 | |
| 356 | /* Test regulator list autoset method */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 357 | static int dm_test_power_regulator_autoset_list(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 358 | { |
| 359 | struct udevice *dev_list[2], *dev; |
| 360 | int i; |
| 361 | |
| 362 | /* |
| 363 | * Test the settings of the regulator list: |
| 364 | * LDO1 with fdt properties: |
| 365 | * - min-microvolt = max-microvolt = 1800000 |
| 366 | * - min-microamp = max-microamp = 100000 |
| 367 | * - always-on = not set |
| 368 | * - boot-on = set |
| 369 | * Expected output state: uV=1800000; uA=100000; output enabled |
| 370 | * |
| 371 | * LDO2 with fdt properties: |
| 372 | * - min-microvolt = max-microvolt = 3300000 |
| 373 | * - always-on = not set |
| 374 | * - boot-on = not set |
| 375 | * Expected output state: uV=300000(default); output disabled(default) |
| 376 | * The expected settings are defined in: include/power/sandbox_pmic.h. |
| 377 | */ |
| 378 | ut_assertok(regulator_list_autoset(platname_list, dev_list, false)); |
| 379 | |
| 380 | for (i = 0; i < list_count; i++) { |
| 381 | /* Check, that the returned device is non-NULL */ |
| 382 | ut_assert(dev_list[i]); |
| 383 | |
| 384 | /* Check, that the returned device is proper */ |
| 385 | ut_assertok(regulator_get_by_platname(platname_list[i], &dev)); |
| 386 | ut_asserteq_ptr(dev_list[i], dev); |
| 387 | |
| 388 | /* Check, that regulator output Voltage value is as expected */ |
| 389 | ut_asserteq(regulator_get_value(dev_list[i]), |
| 390 | expected_setting_list[i].voltage); |
| 391 | |
| 392 | /* Check, that regulator output Current value is as expected */ |
| 393 | ut_asserteq(regulator_get_current(dev_list[i]), |
| 394 | expected_setting_list[i].current); |
| 395 | |
| 396 | /* Check, that regulator output Enable state is as expected */ |
| 397 | ut_asserteq(regulator_get_enable(dev_list[i]), |
| 398 | expected_setting_list[i].enable); |
| 399 | } |
| 400 | |
| 401 | return 0; |
| 402 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 403 | DM_TEST(dm_test_power_regulator_autoset_list, UT_TESTF_SCAN_FDT); |