Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014-2015 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 5 | */ |
Simon Glass | eeb99de | 2017-05-18 20:09:34 -0600 | [diff] [blame] | 6 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 7 | #include <common.h> |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/uclass-internal.h> |
| 11 | #include <power/pmic.h> |
| 12 | #include <power/regulator.h> |
| 13 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 14 | int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep) |
| 15 | { |
| 16 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 17 | |
| 18 | *modep = NULL; |
| 19 | |
| 20 | uc_pdata = dev_get_uclass_platdata(dev); |
| 21 | if (!uc_pdata) |
| 22 | return -ENXIO; |
| 23 | |
| 24 | *modep = uc_pdata->mode; |
| 25 | return uc_pdata->mode_count; |
| 26 | } |
| 27 | |
| 28 | int regulator_get_value(struct udevice *dev) |
| 29 | { |
| 30 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 31 | |
| 32 | if (!ops || !ops->get_value) |
| 33 | return -ENOSYS; |
| 34 | |
| 35 | return ops->get_value(dev); |
| 36 | } |
| 37 | |
| 38 | int regulator_set_value(struct udevice *dev, int uV) |
| 39 | { |
| 40 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
Keerthy | c6e6669 | 2016-10-26 13:42:31 +0530 | [diff] [blame] | 41 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 42 | |
| 43 | uc_pdata = dev_get_uclass_platdata(dev); |
| 44 | if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV) |
| 45 | return -EINVAL; |
| 46 | if (uc_pdata->max_uV != -ENODATA && uV > uc_pdata->max_uV) |
| 47 | return -EINVAL; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 48 | |
| 49 | if (!ops || !ops->set_value) |
| 50 | return -ENOSYS; |
| 51 | |
| 52 | return ops->set_value(dev, uV); |
| 53 | } |
| 54 | |
Keerthy | 162c02e | 2016-10-26 13:42:30 +0530 | [diff] [blame] | 55 | /* |
| 56 | * To be called with at most caution as there is no check |
| 57 | * before setting the actual voltage value. |
| 58 | */ |
| 59 | int regulator_set_value_force(struct udevice *dev, int uV) |
| 60 | { |
| 61 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 62 | |
| 63 | if (!ops || !ops->set_value) |
| 64 | return -ENOSYS; |
| 65 | |
| 66 | return ops->set_value(dev, uV); |
| 67 | } |
| 68 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 69 | int regulator_get_current(struct udevice *dev) |
| 70 | { |
| 71 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 72 | |
| 73 | if (!ops || !ops->get_current) |
| 74 | return -ENOSYS; |
| 75 | |
| 76 | return ops->get_current(dev); |
| 77 | } |
| 78 | |
| 79 | int regulator_set_current(struct udevice *dev, int uA) |
| 80 | { |
| 81 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
Keerthy | ce152be | 2016-10-26 13:42:32 +0530 | [diff] [blame] | 82 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 83 | |
| 84 | uc_pdata = dev_get_uclass_platdata(dev); |
| 85 | if (uc_pdata->min_uA != -ENODATA && uA < uc_pdata->min_uA) |
| 86 | return -EINVAL; |
| 87 | if (uc_pdata->max_uA != -ENODATA && uA > uc_pdata->max_uA) |
| 88 | return -EINVAL; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 89 | |
| 90 | if (!ops || !ops->set_current) |
| 91 | return -ENOSYS; |
| 92 | |
| 93 | return ops->set_current(dev, uA); |
| 94 | } |
| 95 | |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 96 | int regulator_get_enable(struct udevice *dev) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 97 | { |
| 98 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 99 | |
| 100 | if (!ops || !ops->get_enable) |
| 101 | return -ENOSYS; |
| 102 | |
| 103 | return ops->get_enable(dev); |
| 104 | } |
| 105 | |
| 106 | int regulator_set_enable(struct udevice *dev, bool enable) |
| 107 | { |
| 108 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
Patrick Delaunay | d7585f2 | 2018-11-15 13:45:31 +0100 | [diff] [blame] | 109 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 110 | |
| 111 | if (!ops || !ops->set_enable) |
| 112 | return -ENOSYS; |
| 113 | |
Patrick Delaunay | d7585f2 | 2018-11-15 13:45:31 +0100 | [diff] [blame] | 114 | uc_pdata = dev_get_uclass_platdata(dev); |
| 115 | if (!enable && uc_pdata->always_on) |
Lokesh Vutla | f870da2 | 2019-01-11 15:15:50 +0530 | [diff] [blame] | 116 | return -EACCES; |
Patrick Delaunay | d7585f2 | 2018-11-15 13:45:31 +0100 | [diff] [blame] | 117 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 118 | return ops->set_enable(dev, enable); |
| 119 | } |
| 120 | |
Lokesh Vutla | 7106b78 | 2019-01-11 15:15:51 +0530 | [diff] [blame^] | 121 | int regulator_set_enable_if_allowed(struct udevice *dev, bool enable) |
| 122 | { |
| 123 | int ret; |
| 124 | |
| 125 | ret = regulator_set_enable(dev, enable); |
| 126 | if (ret == -ENOSYS || ret == -EACCES) |
| 127 | return 0; |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 132 | int regulator_get_mode(struct udevice *dev) |
| 133 | { |
| 134 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 135 | |
| 136 | if (!ops || !ops->get_mode) |
| 137 | return -ENOSYS; |
| 138 | |
| 139 | return ops->get_mode(dev); |
| 140 | } |
| 141 | |
| 142 | int regulator_set_mode(struct udevice *dev, int mode) |
| 143 | { |
| 144 | const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); |
| 145 | |
| 146 | if (!ops || !ops->set_mode) |
| 147 | return -ENOSYS; |
| 148 | |
| 149 | return ops->set_mode(dev, mode); |
| 150 | } |
| 151 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 152 | int regulator_get_by_platname(const char *plat_name, struct udevice **devp) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 153 | { |
| 154 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 155 | struct udevice *dev; |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 156 | int ret; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 157 | |
| 158 | *devp = NULL; |
| 159 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 160 | for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev; |
| 161 | ret = uclass_find_next_device(&dev)) { |
Simon Glass | fc3ebf1 | 2017-05-31 17:57:15 -0600 | [diff] [blame] | 162 | if (ret) { |
| 163 | debug("regulator %s, ret=%d\n", dev->name, ret); |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 164 | continue; |
Simon Glass | fc3ebf1 | 2017-05-31 17:57:15 -0600 | [diff] [blame] | 165 | } |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 166 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 167 | uc_pdata = dev_get_uclass_platdata(dev); |
| 168 | if (!uc_pdata || strcmp(plat_name, uc_pdata->name)) |
| 169 | continue; |
| 170 | |
| 171 | return uclass_get_device_tail(dev, 0, devp); |
| 172 | } |
| 173 | |
Simon Glass | fc3ebf1 | 2017-05-31 17:57:15 -0600 | [diff] [blame] | 174 | debug("%s: can't find: %s, ret=%d\n", __func__, plat_name, ret); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 175 | |
| 176 | return -ENODEV; |
| 177 | } |
| 178 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 179 | int regulator_get_by_devname(const char *devname, struct udevice **devp) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 180 | { |
| 181 | return uclass_get_device_by_name(UCLASS_REGULATOR, devname, devp); |
| 182 | } |
| 183 | |
Przemyslaw Marczak | c900103 | 2015-10-27 13:07:59 +0100 | [diff] [blame] | 184 | int device_get_supply_regulator(struct udevice *dev, const char *supply_name, |
| 185 | struct udevice **devp) |
| 186 | { |
| 187 | return uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 188 | supply_name, devp); |
| 189 | } |
| 190 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 191 | int regulator_autoset(struct udevice *dev) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 192 | { |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 193 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 194 | int ret = 0; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 195 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 196 | uc_pdata = dev_get_uclass_platdata(dev); |
| 197 | if (!uc_pdata->always_on && !uc_pdata->boot_on) |
| 198 | return -EMEDIUMTYPE; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 199 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 200 | if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV) |
| 201 | ret = regulator_set_value(dev, uc_pdata->min_uV); |
| 202 | if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA)) |
| 203 | ret = regulator_set_current(dev, uc_pdata->min_uA); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 204 | |
| 205 | if (!ret) |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 206 | ret = regulator_set_enable(dev, true); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 211 | static void regulator_show(struct udevice *dev, int ret) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 212 | { |
| 213 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 214 | |
| 215 | uc_pdata = dev_get_uclass_platdata(dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 216 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 217 | printf("%s@%s: ", dev->name, uc_pdata->name); |
| 218 | if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV) |
| 219 | printf("set %d uV", uc_pdata->min_uV); |
| 220 | if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA) |
| 221 | printf("; set %d uA", uc_pdata->min_uA); |
| 222 | printf("; enabling"); |
| 223 | if (ret) |
Simon Glass | 46ad8cb | 2016-01-21 19:43:58 -0700 | [diff] [blame] | 224 | printf(" (ret: %d)", ret); |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 225 | printf("\n"); |
| 226 | } |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 227 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 228 | int regulator_autoset_by_name(const char *platname, struct udevice **devp) |
| 229 | { |
| 230 | struct udevice *dev; |
| 231 | int ret; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 232 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 233 | ret = regulator_get_by_platname(platname, &dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 234 | if (devp) |
| 235 | *devp = dev; |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 236 | if (ret) { |
Simon Glass | fc3ebf1 | 2017-05-31 17:57:15 -0600 | [diff] [blame] | 237 | debug("Can get the regulator: %s (err=%d)\n", platname, ret); |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 238 | return ret; |
| 239 | } |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 240 | |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 241 | return regulator_autoset(dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 244 | int regulator_list_autoset(const char *list_platname[], |
| 245 | struct udevice *list_devp[], |
| 246 | bool verbose) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 247 | { |
| 248 | struct udevice *dev; |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 249 | int error = 0, i = 0, ret; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 250 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 251 | while (list_platname[i]) { |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 252 | ret = regulator_autoset_by_name(list_platname[i], &dev); |
| 253 | if (ret != -EMEDIUMTYPE && verbose) |
| 254 | regulator_show(dev, ret); |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 255 | if (ret & !error) |
| 256 | error = ret; |
| 257 | |
| 258 | if (list_devp) |
| 259 | list_devp[i] = dev; |
| 260 | |
| 261 | i++; |
| 262 | } |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 263 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 264 | return error; |
| 265 | } |
| 266 | |
| 267 | static bool regulator_name_is_unique(struct udevice *check_dev, |
| 268 | const char *check_name) |
| 269 | { |
| 270 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 271 | struct udevice *dev; |
| 272 | int check_len = strlen(check_name); |
| 273 | int ret; |
| 274 | int len; |
| 275 | |
| 276 | for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev; |
| 277 | ret = uclass_find_next_device(&dev)) { |
| 278 | if (ret || dev == check_dev) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 279 | continue; |
| 280 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 281 | uc_pdata = dev_get_uclass_platdata(dev); |
| 282 | len = strlen(uc_pdata->name); |
| 283 | if (len != check_len) |
| 284 | continue; |
| 285 | |
| 286 | if (!strcmp(uc_pdata->name, check_name)) |
| 287 | return false; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 290 | return true; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static int regulator_post_bind(struct udevice *dev) |
| 294 | { |
| 295 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 296 | const char *property = "regulator-name"; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 297 | |
| 298 | uc_pdata = dev_get_uclass_platdata(dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 299 | |
| 300 | /* Regulator's mandatory constraint */ |
Simon Glass | eeb99de | 2017-05-18 20:09:34 -0600 | [diff] [blame] | 301 | uc_pdata->name = dev_read_string(dev, property); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 302 | if (!uc_pdata->name) { |
Simon Glass | eeb99de | 2017-05-18 20:09:34 -0600 | [diff] [blame] | 303 | debug("%s: dev '%s' has no property '%s'\n", |
| 304 | __func__, dev->name, property); |
| 305 | uc_pdata->name = dev_read_name(dev); |
Peng Fan | cd672d4 | 2015-08-07 16:43:42 +0800 | [diff] [blame] | 306 | if (!uc_pdata->name) |
| 307 | return -EINVAL; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 310 | if (regulator_name_is_unique(dev, uc_pdata->name)) |
| 311 | return 0; |
| 312 | |
Simon Glass | eeb99de | 2017-05-18 20:09:34 -0600 | [diff] [blame] | 313 | debug("'%s' of dev: '%s', has nonunique value: '%s\n", |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 314 | property, dev->name, uc_pdata->name); |
| 315 | |
| 316 | return -EINVAL; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int regulator_pre_probe(struct udevice *dev) |
| 320 | { |
| 321 | struct dm_regulator_uclass_platdata *uc_pdata; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 322 | |
| 323 | uc_pdata = dev_get_uclass_platdata(dev); |
| 324 | if (!uc_pdata) |
| 325 | return -ENXIO; |
| 326 | |
| 327 | /* Regulator's optional constraints */ |
Simon Glass | eeb99de | 2017-05-18 20:09:34 -0600 | [diff] [blame] | 328 | uc_pdata->min_uV = dev_read_u32_default(dev, "regulator-min-microvolt", |
| 329 | -ENODATA); |
| 330 | uc_pdata->max_uV = dev_read_u32_default(dev, "regulator-max-microvolt", |
| 331 | -ENODATA); |
| 332 | uc_pdata->min_uA = dev_read_u32_default(dev, "regulator-min-microamp", |
| 333 | -ENODATA); |
| 334 | uc_pdata->max_uA = dev_read_u32_default(dev, "regulator-max-microamp", |
| 335 | -ENODATA); |
| 336 | uc_pdata->always_on = dev_read_bool(dev, "regulator-always-on"); |
| 337 | uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on"); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 338 | |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 339 | /* Those values are optional (-ENODATA if unset) */ |
| 340 | if ((uc_pdata->min_uV != -ENODATA) && |
| 341 | (uc_pdata->max_uV != -ENODATA) && |
| 342 | (uc_pdata->min_uV == uc_pdata->max_uV)) |
| 343 | uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_UV; |
| 344 | |
| 345 | /* Those values are optional (-ENODATA if unset) */ |
| 346 | if ((uc_pdata->min_uA != -ENODATA) && |
| 347 | (uc_pdata->max_uA != -ENODATA) && |
| 348 | (uc_pdata->min_uA == uc_pdata->max_uA)) |
| 349 | uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_UA; |
| 350 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 354 | int regulators_enable_boot_on(bool verbose) |
| 355 | { |
| 356 | struct udevice *dev; |
| 357 | struct uclass *uc; |
| 358 | int ret; |
| 359 | |
| 360 | ret = uclass_get(UCLASS_REGULATOR, &uc); |
| 361 | if (ret) |
| 362 | return ret; |
| 363 | for (uclass_first_device(UCLASS_REGULATOR, &dev); |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 364 | dev; |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 365 | uclass_next_device(&dev)) { |
| 366 | ret = regulator_autoset(dev); |
Simon Glass | f55c951 | 2015-07-02 18:16:06 -0600 | [diff] [blame] | 367 | if (ret == -EMEDIUMTYPE) { |
| 368 | ret = 0; |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 369 | continue; |
Simon Glass | f55c951 | 2015-07-02 18:16:06 -0600 | [diff] [blame] | 370 | } |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 371 | if (verbose) |
| 372 | regulator_show(dev, ret); |
Simon Glass | d6eddad | 2016-01-21 19:43:59 -0700 | [diff] [blame] | 373 | if (ret == -ENOSYS) |
| 374 | ret = 0; |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | return ret; |
| 378 | } |
| 379 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 380 | UCLASS_DRIVER(regulator) = { |
| 381 | .id = UCLASS_REGULATOR, |
| 382 | .name = "regulator", |
| 383 | .post_bind = regulator_post_bind, |
| 384 | .pre_probe = regulator_pre_probe, |
| 385 | .per_device_platdata_auto_alloc_size = |
| 386 | sizeof(struct dm_regulator_uclass_platdata), |
| 387 | }; |