Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014-2015 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | #include <errno.h> |
| 8 | #include <dm.h> |
| 9 | #include <dm/uclass-internal.h> |
| 10 | #include <power/regulator.h> |
| 11 | |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 12 | #define LIMIT_DEVNAME 20 |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 13 | #define LIMIT_OFNAME 32 |
| 14 | #define LIMIT_INFO 18 |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 15 | |
| 16 | static struct udevice *currdev; |
| 17 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 18 | static int failure(int ret) |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 19 | { |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 20 | printf("Error: %d (%s)\n", ret, errno_str(ret)); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 21 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 22 | return CMD_RET_FAILURE; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 26 | { |
| 27 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 28 | const char *name; |
| 29 | int ret = -ENXIO; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 30 | |
| 31 | switch (argc) { |
| 32 | case 2: |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 33 | name = argv[1]; |
| 34 | ret = regulator_get_by_platname(name, &currdev); |
| 35 | if (ret) { |
| 36 | printf("Can't get the regulator: %s!\n", name); |
| 37 | return failure(ret); |
| 38 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 39 | case 1: |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 40 | if (!currdev) { |
| 41 | printf("Regulator device is not set!\n\n"); |
| 42 | return CMD_RET_USAGE; |
| 43 | } |
| 44 | |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 45 | uc_pdata = dev_get_uclass_platdata(currdev); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 46 | if (!uc_pdata) { |
| 47 | printf("%s: no regulator platform data!\n", currdev->name); |
| 48 | return failure(ret); |
| 49 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 50 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 51 | printf("dev: %s @ %s\n", uc_pdata->name, currdev->name); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | return CMD_RET_SUCCESS; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 57 | static int curr_dev_and_platdata(struct udevice **devp, |
| 58 | struct dm_regulator_uclass_platdata **uc_pdata, |
| 59 | bool allow_type_fixed) |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 60 | { |
| 61 | *devp = NULL; |
| 62 | *uc_pdata = NULL; |
| 63 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 64 | if (!currdev) { |
| 65 | printf("First, set the regulator device!\n"); |
| 66 | return CMD_RET_FAILURE; |
| 67 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 68 | |
| 69 | *devp = currdev; |
| 70 | |
| 71 | *uc_pdata = dev_get_uclass_platdata(*devp); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 72 | if (!*uc_pdata) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 73 | pr_err("Regulator: %s - missing platform data!", currdev->name); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 74 | return CMD_RET_FAILURE; |
| 75 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 76 | |
| 77 | if (!allow_type_fixed && (*uc_pdata)->type == REGULATOR_TYPE_FIXED) { |
| 78 | printf("Operation not allowed for fixed regulator!\n"); |
| 79 | return CMD_RET_FAILURE; |
| 80 | } |
| 81 | |
| 82 | return CMD_RET_SUCCESS; |
| 83 | } |
| 84 | |
| 85 | static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 86 | { |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 87 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 88 | struct udevice *dev; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 89 | int ret; |
| 90 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 91 | printf("| %-*.*s| %-*.*s| %s\n", |
| 92 | LIMIT_DEVNAME, LIMIT_DEVNAME, "Device", |
| 93 | LIMIT_OFNAME, LIMIT_OFNAME, "regulator-name", |
| 94 | "Parent"); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 95 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 96 | for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev; |
| 97 | ret = uclass_find_next_device(&dev)) { |
| 98 | if (ret) |
| 99 | continue; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 100 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 101 | uc_pdata = dev_get_uclass_platdata(dev); |
| 102 | printf("| %-*.*s| %-*.*s| %s\n", |
| 103 | LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name, |
| 104 | LIMIT_OFNAME, LIMIT_OFNAME, uc_pdata->name, |
| 105 | dev->parent->name); |
| 106 | } |
| 107 | |
| 108 | return ret; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static int constraint(const char *name, int val, const char *val_name) |
| 112 | { |
| 113 | printf("%-*s", LIMIT_INFO, name); |
| 114 | if (val < 0) { |
| 115 | printf(" %s (err: %d)\n", errno_str(val), val); |
| 116 | return val; |
| 117 | } |
| 118 | |
| 119 | if (val_name) |
| 120 | printf(" %d (%s)\n", val, val_name); |
| 121 | else |
| 122 | printf(" %d\n", val); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static const char *get_mode_name(struct dm_regulator_mode *mode, |
| 128 | int mode_count, |
| 129 | int mode_id) |
| 130 | { |
| 131 | while (mode_count--) { |
| 132 | if (mode->id == mode_id) |
| 133 | return mode->name; |
| 134 | mode++; |
| 135 | } |
| 136 | |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | static int do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 141 | { |
| 142 | struct udevice *dev; |
| 143 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 144 | struct dm_regulator_mode *modes; |
| 145 | const char *parent_uc; |
| 146 | int mode_count; |
| 147 | int ret; |
| 148 | int i; |
| 149 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 150 | ret = curr_dev_and_platdata(&dev, &uc_pdata, true); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 151 | if (ret) |
| 152 | return ret; |
| 153 | |
| 154 | parent_uc = dev_get_uclass_name(dev->parent); |
| 155 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 156 | printf("%s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s\n", |
| 157 | "Regulator info:", |
| 158 | LIMIT_INFO, "* regulator-name:", uc_pdata->name, |
| 159 | LIMIT_INFO, "* device name:", dev->name, |
| 160 | LIMIT_INFO, "* parent name:", dev->parent->name, |
| 161 | LIMIT_INFO, "* parent uclass:", parent_uc, |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 162 | LIMIT_INFO, "* constraints:"); |
| 163 | |
| 164 | constraint(" - min uV:", uc_pdata->min_uV, NULL); |
| 165 | constraint(" - max uV:", uc_pdata->max_uV, NULL); |
| 166 | constraint(" - min uA:", uc_pdata->min_uA, NULL); |
| 167 | constraint(" - max uA:", uc_pdata->max_uA, NULL); |
| 168 | constraint(" - always on:", uc_pdata->always_on, |
| 169 | uc_pdata->always_on ? "true" : "false"); |
| 170 | constraint(" - boot on:", uc_pdata->boot_on, |
| 171 | uc_pdata->boot_on ? "true" : "false"); |
| 172 | |
| 173 | mode_count = regulator_mode(dev, &modes); |
| 174 | constraint("* op modes:", mode_count, NULL); |
| 175 | |
| 176 | for (i = 0; i < mode_count; i++, modes++) |
| 177 | constraint(" - mode id:", modes->id, modes->name); |
| 178 | |
| 179 | return CMD_RET_SUCCESS; |
| 180 | } |
| 181 | |
Simon Glass | 0875f24 | 2016-01-21 19:43:27 -0700 | [diff] [blame] | 182 | static void do_status_detail(struct udevice *dev, |
| 183 | struct dm_regulator_uclass_platdata *uc_pdata) |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 184 | { |
Simon Glass | 0875f24 | 2016-01-21 19:43:27 -0700 | [diff] [blame] | 185 | int current, value, mode; |
| 186 | const char *mode_name; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 187 | bool enabled; |
| 188 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 189 | printf("Regulator %s status:\n", uc_pdata->name); |
| 190 | |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 191 | enabled = regulator_get_enable(dev); |
| 192 | constraint(" * enable:", enabled, enabled ? "true" : "false"); |
| 193 | |
| 194 | value = regulator_get_value(dev); |
| 195 | constraint(" * value uV:", value, NULL); |
| 196 | |
| 197 | current = regulator_get_current(dev); |
| 198 | constraint(" * current uA:", current, NULL); |
| 199 | |
| 200 | mode = regulator_get_mode(dev); |
| 201 | mode_name = get_mode_name(uc_pdata->mode, uc_pdata->mode_count, mode); |
| 202 | constraint(" * mode id:", mode, mode_name); |
Simon Glass | 0875f24 | 2016-01-21 19:43:27 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void do_status_line(struct udevice *dev) |
| 206 | { |
| 207 | struct dm_regulator_uclass_platdata *pdata; |
| 208 | int current, value, mode; |
| 209 | const char *mode_name; |
| 210 | bool enabled; |
| 211 | |
| 212 | pdata = dev_get_uclass_platdata(dev); |
| 213 | enabled = regulator_get_enable(dev); |
| 214 | value = regulator_get_value(dev); |
| 215 | current = regulator_get_current(dev); |
| 216 | mode = regulator_get_mode(dev); |
| 217 | mode_name = get_mode_name(pdata->mode, pdata->mode_count, mode); |
| 218 | printf("%-20s %-10s ", pdata->name, enabled ? "enabled" : "disabled"); |
| 219 | if (value >= 0) |
| 220 | printf("%10d ", value); |
| 221 | else |
| 222 | printf("%10s ", "-"); |
| 223 | if (current >= 0) |
| 224 | printf("%10d ", current); |
| 225 | else |
| 226 | printf("%10s ", "-"); |
| 227 | if (mode >= 0) |
| 228 | printf("%-10s", mode_name); |
| 229 | else |
| 230 | printf("%-10s", "-"); |
| 231 | printf("\n"); |
| 232 | } |
| 233 | |
| 234 | static int do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 235 | { |
| 236 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 237 | struct udevice *dev; |
| 238 | int ret; |
| 239 | |
| 240 | if (currdev && (argc < 2 || strcmp(argv[1], "-a"))) { |
| 241 | ret = curr_dev_and_platdata(&dev, &uc_pdata, true); |
| 242 | if (ret) |
| 243 | return CMD_RET_FAILURE; |
| 244 | do_status_detail(dev, uc_pdata); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /* Show all of them in a list, probing them as needed */ |
| 249 | printf("%-20s %-10s %10s %10s %-10s\n", "Name", "Enabled", "uV", "mA", |
| 250 | "Mode"); |
| 251 | for (ret = uclass_first_device(UCLASS_REGULATOR, &dev); dev; |
| 252 | ret = uclass_next_device(&dev)) |
| 253 | do_status_line(dev); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 254 | |
| 255 | return CMD_RET_SUCCESS; |
| 256 | } |
| 257 | |
| 258 | static int do_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 259 | { |
| 260 | struct udevice *dev; |
| 261 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 262 | int value; |
| 263 | int force; |
| 264 | int ret; |
| 265 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 266 | ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 267 | if (ret) |
| 268 | return ret; |
| 269 | |
| 270 | if (argc == 1) { |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 271 | ret = regulator_get_value(dev); |
| 272 | if (ret < 0) { |
| 273 | printf("Regulator: %s - can't get the Voltage!\n", |
| 274 | uc_pdata->name); |
| 275 | return failure(ret); |
| 276 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 277 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 278 | printf("%d uV\n", ret); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 279 | return CMD_RET_SUCCESS; |
| 280 | } |
| 281 | |
| 282 | if (argc == 3) |
| 283 | force = !strcmp("-f", argv[2]); |
| 284 | else |
| 285 | force = 0; |
| 286 | |
| 287 | value = simple_strtoul(argv[1], NULL, 0); |
| 288 | if ((value < uc_pdata->min_uV || value > uc_pdata->max_uV) && !force) { |
Simon Glass | e5c88ea | 2015-07-02 18:16:07 -0600 | [diff] [blame] | 289 | printf("Value exceeds regulator constraint limits %d..%d uV\n", |
| 290 | uc_pdata->min_uV, uc_pdata->max_uV); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 291 | return CMD_RET_FAILURE; |
| 292 | } |
| 293 | |
Keerthy | 162c02e | 2016-10-26 13:42:30 +0530 | [diff] [blame] | 294 | if (!force) |
| 295 | ret = regulator_set_value(dev, value); |
| 296 | else |
| 297 | ret = regulator_set_value_force(dev, value); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 298 | if (ret) { |
| 299 | printf("Regulator: %s - can't set the Voltage!\n", |
| 300 | uc_pdata->name); |
| 301 | return failure(ret); |
| 302 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 303 | |
| 304 | return CMD_RET_SUCCESS; |
| 305 | } |
| 306 | |
| 307 | static int do_current(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 308 | { |
| 309 | struct udevice *dev; |
| 310 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 311 | int current; |
| 312 | int ret; |
| 313 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 314 | ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 315 | if (ret) |
| 316 | return ret; |
| 317 | |
| 318 | if (argc == 1) { |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 319 | ret = regulator_get_current(dev); |
| 320 | if (ret < 0) { |
| 321 | printf("Regulator: %s - can't get the Current!\n", |
| 322 | uc_pdata->name); |
| 323 | return failure(ret); |
| 324 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 325 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 326 | printf("%d uA\n", ret); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 327 | return CMD_RET_SUCCESS; |
| 328 | } |
| 329 | |
| 330 | current = simple_strtoul(argv[1], NULL, 0); |
| 331 | if (current < uc_pdata->min_uA || current > uc_pdata->max_uA) { |
| 332 | printf("Current exceeds regulator constraint limits\n"); |
| 333 | return CMD_RET_FAILURE; |
| 334 | } |
| 335 | |
| 336 | ret = regulator_set_current(dev, current); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 337 | if (ret) { |
| 338 | printf("Regulator: %s - can't set the Current!\n", |
| 339 | uc_pdata->name); |
| 340 | return failure(ret); |
| 341 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 342 | |
| 343 | return CMD_RET_SUCCESS; |
| 344 | } |
| 345 | |
| 346 | static int do_mode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 347 | { |
| 348 | struct udevice *dev; |
| 349 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 350 | int mode; |
| 351 | int ret; |
| 352 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 353 | ret = curr_dev_and_platdata(&dev, &uc_pdata, false); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 354 | if (ret) |
| 355 | return ret; |
| 356 | |
| 357 | if (argc == 1) { |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 358 | ret = regulator_get_mode(dev); |
| 359 | if (ret < 0) { |
| 360 | printf("Regulator: %s - can't get the operation mode!\n", |
| 361 | uc_pdata->name); |
| 362 | return failure(ret); |
| 363 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 364 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 365 | printf("mode id: %d\n", ret); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 366 | return CMD_RET_SUCCESS; |
| 367 | } |
| 368 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 369 | mode = simple_strtoul(argv[1], NULL, 0); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 370 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 371 | ret = regulator_set_mode(dev, mode); |
| 372 | if (ret) { |
| 373 | printf("Regulator: %s - can't set the operation mode!\n", |
| 374 | uc_pdata->name); |
| 375 | return failure(ret); |
| 376 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 377 | |
| 378 | return CMD_RET_SUCCESS; |
| 379 | } |
| 380 | |
| 381 | static int do_enable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 382 | { |
| 383 | struct udevice *dev; |
| 384 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 385 | int ret; |
| 386 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 387 | ret = curr_dev_and_platdata(&dev, &uc_pdata, true); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 388 | if (ret) |
| 389 | return ret; |
| 390 | |
| 391 | ret = regulator_set_enable(dev, true); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 392 | if (ret) { |
| 393 | printf("Regulator: %s - can't enable!\n", uc_pdata->name); |
| 394 | return failure(ret); |
| 395 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 396 | |
| 397 | return CMD_RET_SUCCESS; |
| 398 | } |
| 399 | |
| 400 | static int do_disable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 401 | { |
| 402 | struct udevice *dev; |
| 403 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 404 | int ret; |
| 405 | |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 406 | ret = curr_dev_and_platdata(&dev, &uc_pdata, true); |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 407 | if (ret) |
| 408 | return ret; |
| 409 | |
| 410 | ret = regulator_set_enable(dev, false); |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 411 | if (ret) { |
| 412 | printf("Regulator: %s - can't disable!\n", uc_pdata->name); |
| 413 | return failure(ret); |
| 414 | } |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 415 | |
| 416 | return CMD_RET_SUCCESS; |
| 417 | } |
| 418 | |
| 419 | static cmd_tbl_t subcmd[] = { |
| 420 | U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""), |
| 421 | U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""), |
| 422 | U_BOOT_CMD_MKENT(info, 2, 1, do_info, "", ""), |
| 423 | U_BOOT_CMD_MKENT(status, 2, 1, do_status, "", ""), |
| 424 | U_BOOT_CMD_MKENT(value, 3, 1, do_value, "", ""), |
| 425 | U_BOOT_CMD_MKENT(current, 3, 1, do_current, "", ""), |
| 426 | U_BOOT_CMD_MKENT(mode, 2, 1, do_mode, "", ""), |
| 427 | U_BOOT_CMD_MKENT(enable, 1, 1, do_enable, "", ""), |
| 428 | U_BOOT_CMD_MKENT(disable, 1, 1, do_disable, "", ""), |
| 429 | }; |
| 430 | |
| 431 | static int do_regulator(cmd_tbl_t *cmdtp, int flag, int argc, |
| 432 | char * const argv[]) |
| 433 | { |
| 434 | cmd_tbl_t *cmd; |
| 435 | |
| 436 | argc--; |
| 437 | argv++; |
| 438 | |
| 439 | cmd = find_cmd_tbl(argv[0], subcmd, ARRAY_SIZE(subcmd)); |
| 440 | if (cmd == NULL || argc > cmd->maxargs) |
| 441 | return CMD_RET_USAGE; |
| 442 | |
| 443 | return cmd->cmd(cmdtp, flag, argc, argv); |
| 444 | } |
| 445 | |
| 446 | U_BOOT_CMD(regulator, CONFIG_SYS_MAXARGS, 1, do_regulator, |
| 447 | "uclass operations", |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 448 | "list - list UCLASS regulator devices\n" |
| 449 | "regulator dev [regulator-name] - show/[set] operating regulator device\n" |
| 450 | "regulator info - print constraints info\n" |
Simon Glass | 0875f24 | 2016-01-21 19:43:27 -0700 | [diff] [blame] | 451 | "regulator status [-a] - print operating status [for all]\n" |
Przemyslaw Marczak | 6df3ba7 | 2015-05-13 13:38:29 +0200 | [diff] [blame] | 452 | "regulator value [val] [-f] - print/[set] voltage value [uV] (force)\n" |
| 453 | "regulator current [val] - print/[set] current value [uA]\n" |
| 454 | "regulator mode [id] - print/[set] operating mode id\n" |
| 455 | "regulator enable - enable the regulator output\n" |
| 456 | "regulator disable - disable the regulator output\n" |
Przemyslaw Marczak | 6a92312 | 2015-04-20 20:07:44 +0200 | [diff] [blame] | 457 | ); |