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 | */ |
| 6 | |
| 7 | #ifndef _INCLUDE_REGULATOR_H_ |
| 8 | #define _INCLUDE_REGULATOR_H_ |
| 9 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 12 | /** |
| 13 | * U-Boot Voltage/Current Regulator |
| 14 | * ================================ |
| 15 | * |
| 16 | * The regulator API is based on a driver model, with the device tree support. |
| 17 | * And this header describes the functions and data types for the uclass id: |
| 18 | * 'UCLASS_REGULATOR' and the regulator driver API. |
| 19 | * |
| 20 | * The regulator uclass - is based on uclass platform data which is allocated, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 21 | * automatically for each regulator device on bind and 'dev->uclass_plat' |
| 22 | * points to it. The data type is: 'struct dm_regulator_uclass_plat'. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 23 | * The uclass file: 'drivers/power/regulator/regulator-uclass.c' |
| 24 | * |
| 25 | * The regulator device - is based on driver's model 'struct udevice'. |
| 26 | * The API can use regulator name in two meanings: |
| 27 | * - devname - the regulator device's name: 'dev->name' |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 28 | * - platname - the device's plat's name. So in the code it looks like: |
| 29 | * 'uc_pdata = dev->uclass_plat'; 'name = uc_pdata->name'. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 30 | * |
| 31 | * The regulator device driver - provide an implementation of uclass operations |
| 32 | * pointed by 'dev->driver->ops' as a struct of type 'struct dm_regulator_ops'. |
| 33 | * |
| 34 | * To proper bind the regulator device, the device tree node should provide |
| 35 | * regulator constraints, like in the example below: |
| 36 | * |
| 37 | * ldo1 { |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 38 | * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 39 | * regulator-min-microvolt = <1000000>; (optional) |
| 40 | * regulator-max-microvolt = <1000000>; (optional) |
| 41 | * regulator-min-microamp = <1000>; (optional) |
| 42 | * regulator-max-microamp = <1000>; (optional) |
| 43 | * regulator-always-on; (optional) |
| 44 | * regulator-boot-on; (optional) |
| 45 | * }; |
| 46 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 47 | * Note: For the proper operation, at least name constraint is needed, since |
| 48 | * it can be used when calling regulator_get_by_platname(). And the mandatory |
| 49 | * rule for this name is, that it must be globally unique for the single dts. |
Peng Fan | b4cb9ce | 2015-08-07 16:43:43 +0800 | [diff] [blame] | 50 | * If regulator-name property is not provided, node name will be chosen. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 51 | * |
| 52 | * Regulator bind: |
Simon Glass | 6996c66 | 2020-11-28 17:50:03 -0700 | [diff] [blame] | 53 | * For each regulator device, the device_bind() should be called with passed |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 54 | * device tree offset. This is required for this uclass's '.post_bind' method, |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 55 | * which does the scan on the device node, for the 'regulator-name' constraint. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 56 | * If the parent is not a PMIC device, and the child is not bind by function: |
| 57 | * 'pmic_bind_childs()', then it's recommended to bind the device by call to |
Simon Glass | 09128c5 | 2016-07-05 17:10:09 -0600 | [diff] [blame] | 58 | * dm_scan_fdt_dev() - this is usually done automatically for bus devices, |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 59 | * as a post bind method. |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 60 | * |
| 61 | * Regulator get: |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 62 | * Having the device's name constraint, we can call regulator_by_platname(), |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 63 | * to find the required regulator. Before return, the regulator is probed, |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 64 | * and the rest of its constraints are put into the device's uclass platform |
| 65 | * data, by the uclass regulator '.pre_probe' method. |
| 66 | * |
| 67 | * For more info about PMIC bind, please refer to file: 'include/power/pmic.h' |
| 68 | * |
| 69 | * Note: |
| 70 | * Please do not use the device_bind_by_name() function, since it pass '-1' as |
| 71 | * device node offset - and the bind will fail on uclass .post_bind method, |
| 72 | * because of missing 'regulator-name' constraint. |
| 73 | * |
| 74 | * |
| 75 | * Fixed Voltage/Current Regulator |
| 76 | * =============================== |
| 77 | * |
| 78 | * When fixed voltage regulator is needed, then enable the config: |
| 79 | * - CONFIG_DM_REGULATOR_FIXED |
| 80 | * |
| 81 | * The driver file: 'drivers/power/regulator/fixed.c', provides basic support |
| 82 | * for control the GPIO, and return the device tree constraint values. |
| 83 | * |
| 84 | * To bind the fixed voltage regulator device, we usually use a 'simple-bus' |
| 85 | * node as a parent. And 'regulator-fixed' for the driver compatible. This is |
| 86 | * the same as in the kernel. The example node of fixed regulator: |
| 87 | * |
| 88 | * simple-bus { |
| 89 | * compatible = "simple-bus"; |
| 90 | * #address-cells = <1>; |
| 91 | * #size-cells = <0>; |
| 92 | * |
| 93 | * blue_led { |
| 94 | * compatible = "regulator-fixed"; |
| 95 | * regulator-name = "VDD_LED_3.3V"; |
| 96 | * regulator-min-microvolt = <3300000>; |
| 97 | * regulator-max-microvolt = <3300000>; |
| 98 | * gpio = <&gpc1 0 GPIO_ACTIVE_LOW>; |
| 99 | * }; |
| 100 | * }; |
| 101 | * |
| 102 | * The fixed regulator devices also provide regulator uclass platform data. And |
| 103 | * devices bound from such node, can use the regulator drivers API. |
| 104 | */ |
| 105 | |
| 106 | /* enum regulator_type - used for regulator_*() variant calls */ |
| 107 | enum regulator_type { |
| 108 | REGULATOR_TYPE_LDO = 0, |
| 109 | REGULATOR_TYPE_BUCK, |
| 110 | REGULATOR_TYPE_DVS, |
| 111 | REGULATOR_TYPE_FIXED, |
Keerthy | 17b3fe7 | 2016-09-15 17:04:06 +0530 | [diff] [blame] | 112 | REGULATOR_TYPE_GPIO, |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 113 | REGULATOR_TYPE_OTHER, |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * struct dm_regulator_mode - this structure holds an information about |
| 118 | * each regulator operation mode. Probably in most cases - an array. |
| 119 | * This will be probably a driver-static data, since it is device-specific. |
| 120 | * |
| 121 | * @id - a driver-specific mode id |
| 122 | * @register_value - a driver-specific value for its mode id |
| 123 | * @name - the name of mode - used for regulator command |
| 124 | * Note: |
| 125 | * The field 'id', should be always a positive number, since the negative values |
| 126 | * are reserved for the errno numbers when returns the mode id. |
| 127 | */ |
| 128 | struct dm_regulator_mode { |
| 129 | int id; /* Set only as >= 0 (negative value is reserved for errno) */ |
| 130 | int register_value; |
| 131 | const char *name; |
| 132 | }; |
| 133 | |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 134 | enum regulator_flag { |
| 135 | REGULATOR_FLAG_AUTOSET_UV = 1 << 0, |
| 136 | REGULATOR_FLAG_AUTOSET_UA = 1 << 1, |
| 137 | }; |
| 138 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 139 | /** |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 140 | * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 141 | * allocated on each regulator bind. This structure holds an information |
| 142 | * about each regulator's constraints and supported operation modes. |
| 143 | * There is no "step" voltage value - so driver should take care of this. |
| 144 | * |
| 145 | * @type - one of 'enum regulator_type' |
| 146 | * @mode - pointer to the regulator mode (array if more than one) |
| 147 | * @mode_count - number of '.mode' entries |
| 148 | * @min_uV* - minimum voltage (micro Volts) |
| 149 | * @max_uV* - maximum voltage (micro Volts) |
| 150 | * @min_uA* - minimum amperage (micro Amps) |
| 151 | * @max_uA* - maximum amperage (micro Amps) |
| 152 | * @always_on* - bool type, true or false |
| 153 | * @boot_on* - bool type, true or false |
Konstantin Porotchkin | 621dab5 | 2017-05-29 15:59:38 +0300 | [diff] [blame] | 154 | * @force_off* - bool type, true or false |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 155 | * TODO(sjg@chromium.org): Consider putting the above two into @flags |
Krzysztof Kozlowski | e2fa397 | 2019-03-06 19:37:54 +0100 | [diff] [blame] | 156 | * @ramp_delay - Time to settle down after voltage change (unit: uV/us) |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 157 | * @flags: - flags value (see REGULATOR_FLAG_...) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 158 | * @name** - fdt regulator name - should be taken from the device tree |
Keerthy | 4d96cd0 | 2016-09-30 09:20:42 +0530 | [diff] [blame] | 159 | * ctrl_reg: - Control register offset used to enable/disable regulator |
| 160 | * volt_reg: - register offset for writing voltage vsel values |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 161 | * |
| 162 | * Note: |
| 163 | * * - set automatically on device probe by the uclass's '.pre_probe' method. |
| 164 | * ** - set automatically on device bind by the uclass's '.post_bind' method. |
| 165 | * The constraints: type, mode, mode_count, can be set by device driver, e.g. |
| 166 | * by the driver '.probe' method. |
| 167 | */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 168 | struct dm_regulator_uclass_plat { |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 169 | enum regulator_type type; |
| 170 | struct dm_regulator_mode *mode; |
| 171 | int mode_count; |
| 172 | int min_uV; |
| 173 | int max_uV; |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 174 | int init_uV; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 175 | int min_uA; |
| 176 | int max_uA; |
Krzysztof Kozlowski | e2fa397 | 2019-03-06 19:37:54 +0100 | [diff] [blame] | 177 | unsigned int ramp_delay; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 178 | bool always_on; |
| 179 | bool boot_on; |
Konstantin Porotchkin | 621dab5 | 2017-05-29 15:59:38 +0300 | [diff] [blame] | 180 | bool force_off; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 181 | const char *name; |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 182 | int flags; |
Keerthy | 4d96cd0 | 2016-09-30 09:20:42 +0530 | [diff] [blame] | 183 | u8 ctrl_reg; |
| 184 | u8 volt_reg; |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 185 | bool suspend_on; |
| 186 | u32 suspend_uV; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | /* Regulator device operations */ |
| 190 | struct dm_regulator_ops { |
| 191 | /** |
| 192 | * The regulator output value function calls operates on a micro Volts. |
| 193 | * |
| 194 | * get/set_value - get/set output value of the given output number |
| 195 | * @dev - regulator device |
| 196 | * Sets: |
| 197 | * @uV - set the output value [micro Volts] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 198 | * @return output value [uV] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 199 | */ |
| 200 | int (*get_value)(struct udevice *dev); |
| 201 | int (*set_value)(struct udevice *dev, int uV); |
| 202 | |
| 203 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 204 | * The regulator suspend output value function calls operates |
| 205 | * on a micro Volts. |
| 206 | * |
| 207 | * get/set_suspen_value - get/set suspend mode output value |
| 208 | * @dev - regulator device |
| 209 | * Sets: |
| 210 | * @uV - set the suspend output value [micro Volts] |
| 211 | * @return output value [uV] on success or negative errno if fail. |
| 212 | */ |
| 213 | int (*set_suspend_value)(struct udevice *dev, int uV); |
| 214 | int (*get_suspend_value)(struct udevice *dev); |
| 215 | |
| 216 | /** |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 217 | * The regulator output current function calls operates on a micro Amps. |
| 218 | * |
| 219 | * get/set_current - get/set output current of the given output number |
| 220 | * @dev - regulator device |
| 221 | * Sets: |
| 222 | * @uA - set the output current [micro Amps] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 223 | * @return output value [uA] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 224 | */ |
| 225 | int (*get_current)(struct udevice *dev); |
| 226 | int (*set_current)(struct udevice *dev, int uA); |
| 227 | |
| 228 | /** |
| 229 | * The most basic feature of the regulator output is its enable state. |
| 230 | * |
| 231 | * get/set_enable - get/set enable state of the given output number |
| 232 | * @dev - regulator device |
| 233 | * Sets: |
| 234 | * @enable - set true - enable or false - disable |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 235 | * @return true/false for get or -errno if fail; 0 / -errno for set. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 236 | */ |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 237 | int (*get_enable)(struct udevice *dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 238 | int (*set_enable)(struct udevice *dev, bool enable); |
| 239 | |
| 240 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 241 | * The most basic feature of the regulator output is its enable state |
| 242 | * in suspend mode. |
| 243 | * |
| 244 | * get/set_suspend_enable - get/set enable state of the suspend output |
| 245 | * @dev - regulator device |
| 246 | * Sets: |
| 247 | * @enable - set true - enable or false - disable |
| 248 | * @return true/false for get or -errno if fail; 0 / -errno for set. |
| 249 | */ |
| 250 | int (*set_suspend_enable)(struct udevice *dev, bool enable); |
| 251 | int (*get_suspend_enable)(struct udevice *dev); |
| 252 | |
| 253 | /** |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 254 | * The 'get/set_mode()' function calls should operate on a driver- |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 255 | * specific mode id definitions, which should be found in: |
| 256 | * field 'id' of struct dm_regulator_mode. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 257 | * |
| 258 | * get/set_mode - get/set operation mode of the given output number |
| 259 | * @dev - regulator device |
| 260 | * Sets |
| 261 | * @mode_id - set output mode id (struct dm_regulator_mode->id) |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 262 | * @return id/0 for get/set on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 263 | * Note: |
| 264 | * The field 'id' of struct type 'dm_regulator_mode', should be always |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 265 | * a positive number, since the negative is reserved for the error. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 266 | */ |
| 267 | int (*get_mode)(struct udevice *dev); |
| 268 | int (*set_mode)(struct udevice *dev, int mode_id); |
| 269 | }; |
| 270 | |
Peng Fan | a1a2a22 | 2020-10-15 18:06:48 +0800 | [diff] [blame] | 271 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 272 | /** |
| 273 | * regulator_mode: returns a pointer to the array of regulator mode info |
| 274 | * |
| 275 | * @dev - pointer to the regulator device |
| 276 | * @modep - pointer to the returned mode info array |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 277 | * @return - count of modep entries on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 278 | */ |
| 279 | int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep); |
| 280 | |
| 281 | /** |
| 282 | * regulator_get_value: get microvoltage voltage value of a given regulator |
| 283 | * |
| 284 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 285 | * @return - positive output value [uV] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 286 | */ |
| 287 | int regulator_get_value(struct udevice *dev); |
| 288 | |
| 289 | /** |
| 290 | * regulator_set_value: set the microvoltage value of a given regulator. |
| 291 | * |
| 292 | * @dev - pointer to the regulator device |
| 293 | * @uV - the output value to set [micro Volts] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 294 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 295 | */ |
| 296 | int regulator_set_value(struct udevice *dev, int uV); |
| 297 | |
| 298 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 299 | * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator. |
| 300 | * |
| 301 | * @dev - pointer to the regulator device |
| 302 | * @uV - the output suspend value to set [micro Volts] |
| 303 | * @return - 0 on success or -errno val if fails |
| 304 | */ |
| 305 | int regulator_set_suspend_value(struct udevice *dev, int uV); |
| 306 | |
| 307 | /** |
| 308 | * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator. |
| 309 | * |
| 310 | * @dev - pointer to the regulator device |
| 311 | * @return - positive output value [uV] on success or negative errno if fail. |
| 312 | */ |
| 313 | int regulator_get_suspend_value(struct udevice *dev); |
| 314 | |
| 315 | /** |
Keerthy | 162c02e | 2016-10-26 13:42:30 +0530 | [diff] [blame] | 316 | * regulator_set_value_force: set the microvoltage value of a given regulator |
| 317 | * without any min-,max condition check |
| 318 | * |
| 319 | * @dev - pointer to the regulator device |
| 320 | * @uV - the output value to set [micro Volts] |
| 321 | * @return - 0 on success or -errno val if fails |
| 322 | */ |
| 323 | int regulator_set_value_force(struct udevice *dev, int uV); |
| 324 | |
| 325 | /** |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 326 | * regulator_get_current: get microampere value of a given regulator |
| 327 | * |
| 328 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 329 | * @return - positive output current [uA] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 330 | */ |
| 331 | int regulator_get_current(struct udevice *dev); |
| 332 | |
| 333 | /** |
| 334 | * regulator_set_current: set the microampere value of a given regulator. |
| 335 | * |
| 336 | * @dev - pointer to the regulator device |
| 337 | * @uA - set the output current [micro Amps] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 338 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 339 | */ |
| 340 | int regulator_set_current(struct udevice *dev, int uA); |
| 341 | |
| 342 | /** |
| 343 | * regulator_get_enable: get regulator device enable state. |
| 344 | * |
| 345 | * @dev - pointer to the regulator device |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 346 | * @return - true/false of enable state or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 347 | */ |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 348 | int regulator_get_enable(struct udevice *dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 349 | |
| 350 | /** |
| 351 | * regulator_set_enable: set regulator enable state |
| 352 | * |
| 353 | * @dev - pointer to the regulator device |
| 354 | * @enable - set true or false |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 355 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 356 | */ |
| 357 | int regulator_set_enable(struct udevice *dev, bool enable); |
| 358 | |
| 359 | /** |
Lokesh Vutla | 7106b78 | 2019-01-11 15:15:51 +0530 | [diff] [blame] | 360 | * regulator_set_enable_if_allowed: set regulator enable state if allowed by |
| 361 | * regulator |
| 362 | * |
| 363 | * @dev - pointer to the regulator device |
| 364 | * @enable - set true or false |
| 365 | * @return - 0 on success or if enabling is not supported |
| 366 | * -errno val if fails. |
| 367 | */ |
| 368 | int regulator_set_enable_if_allowed(struct udevice *dev, bool enable); |
| 369 | |
| 370 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 371 | * regulator_set_suspend_enable: set regulator suspend enable state |
| 372 | * |
| 373 | * @dev - pointer to the regulator device |
| 374 | * @enable - set true or false |
| 375 | * @return - 0 on success or -errno val if fails |
| 376 | */ |
| 377 | int regulator_set_suspend_enable(struct udevice *dev, bool enable); |
| 378 | |
| 379 | /** |
| 380 | * regulator_get_suspend_enable: get regulator suspend enable state |
| 381 | * |
| 382 | * @dev - pointer to the regulator device |
| 383 | * @return - true/false of enable state or -errno val if fails |
| 384 | */ |
| 385 | int regulator_get_suspend_enable(struct udevice *dev); |
| 386 | |
| 387 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 388 | * regulator_get_mode: get active operation mode id of a given regulator |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 389 | * |
| 390 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 391 | * @return - positive mode 'id' number on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 392 | * Note: |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 393 | * The device can provide an array of operating modes, which is type of struct |
| 394 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside |
| 395 | * that array. By calling this function, the driver should return an active mode |
| 396 | * id of the given regulator device. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 397 | */ |
| 398 | int regulator_get_mode(struct udevice *dev); |
| 399 | |
| 400 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 401 | * regulator_set_mode: set the given regulator's, active mode id |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 402 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 403 | * @dev - pointer to the regulator device |
| 404 | * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode) |
| 405 | * @return - 0 on success or -errno value if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 406 | * Note: |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 407 | * The device can provide an array of operating modes, which is type of struct |
| 408 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside |
| 409 | * that array. By calling this function, the driver should set the active mode |
| 410 | * of a given regulator to given by "mode_id" argument. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 411 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 412 | int regulator_set_mode(struct udevice *dev, int mode_id); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 413 | |
| 414 | /** |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 415 | * regulators_enable_boot_on() - enable regulators needed for boot |
| 416 | * |
| 417 | * This enables all regulators which are marked to be on at boot time. This |
| 418 | * only works for regulators which don't have a range for voltage/current, |
| 419 | * since in that case it is not possible to know which value to use. |
| 420 | * |
| 421 | * This effectively calls regulator_autoset() for every regulator. |
| 422 | */ |
| 423 | int regulators_enable_boot_on(bool verbose); |
| 424 | |
| 425 | /** |
Konstantin Porotchkin | 621dab5 | 2017-05-29 15:59:38 +0300 | [diff] [blame] | 426 | * regulators_enable_boot_off() - disable regulators needed for boot |
| 427 | * |
| 428 | * This disables all regulators which are marked to be off at boot time. |
| 429 | * |
| 430 | * This effectively calls regulator_unset() for every regulator. |
| 431 | */ |
| 432 | int regulators_enable_boot_off(bool verbose); |
| 433 | |
| 434 | /** |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 435 | * regulator_autoset: setup the voltage/current on a regulator |
| 436 | * |
| 437 | * The setup depends on constraints found in device's uclass's platform data |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 438 | * (struct dm_regulator_uclass_plat): |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 439 | * |
| 440 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, |
| 441 | * or if both are unset, then the function returns |
| 442 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal |
| 443 | * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal |
| 444 | * |
| 445 | * The function returns on the first-encountered error. |
| 446 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 447 | * @platname - expected string for dm_regulator_uclass_plat .name field |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 448 | * @devp - returned pointer to the regulator device - if non-NULL passed |
| 449 | * @return: 0 on success or negative value of errno. |
| 450 | */ |
| 451 | int regulator_autoset(struct udevice *dev); |
| 452 | |
| 453 | /** |
Konstantin Porotchkin | 621dab5 | 2017-05-29 15:59:38 +0300 | [diff] [blame] | 454 | * regulator_unset: turn off a regulator |
| 455 | * |
| 456 | * The setup depends on constraints found in device's uclass's platform data |
| 457 | * (struct dm_regulator_uclass_platdata): |
| 458 | * |
| 459 | * - Disable - will set - if 'force_off' is set to true, |
| 460 | * |
| 461 | * The function returns on the first-encountered error. |
| 462 | */ |
| 463 | int regulator_unset(struct udevice *dev); |
| 464 | |
| 465 | /** |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 466 | * regulator_autoset_by_name: setup the regulator given by its uclass's |
| 467 | * platform data name field. The setup depends on constraints found in device's |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 468 | * uclass's platform data (struct dm_regulator_uclass_plat): |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 469 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, |
| 470 | * or if both are unset, then the function returns |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 471 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal |
| 472 | * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 473 | * |
| 474 | * The function returns on first encountered error. |
| 475 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 476 | * @platname - expected string for dm_regulator_uclass_plat .name field |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 477 | * @devp - returned pointer to the regulator device - if non-NULL passed |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 478 | * @return: 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 479 | * |
| 480 | * The returned 'regulator' device can be used with: |
| 481 | * - regulator_get/set_* |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 482 | */ |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 483 | int regulator_autoset_by_name(const char *platname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 484 | |
| 485 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 486 | * regulator_list_autoset: setup the regulators given by list of their uclass's |
| 487 | * platform data name field. The setup depends on constraints found in device's |
| 488 | * uclass's platform data. The function loops with calls to: |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 489 | * regulator_autoset_by_name() for each name from the list. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 490 | * |
| 491 | * @list_platname - an array of expected strings for .name field of each |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 492 | * regulator's uclass plat |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 493 | * @list_devp - an array of returned pointers to the successfully setup |
| 494 | * regulator devices if non-NULL passed |
| 495 | * @verbose - (true/false) print each regulator setup info, or be quiet |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 496 | * @return 0 on successfully setup of all list entries, otherwise first error. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 497 | * |
| 498 | * The returned 'regulator' devices can be used with: |
| 499 | * - regulator_get/set_* |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 500 | * |
| 501 | * Note: The list must ends with NULL entry, like in the "platname" list below: |
| 502 | * char *my_regulators[] = { |
| 503 | * "VCC_3.3V", |
| 504 | * "VCC_1.8V", |
| 505 | * NULL, |
| 506 | * }; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 507 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 508 | int regulator_list_autoset(const char *list_platname[], |
| 509 | struct udevice *list_devp[], |
| 510 | bool verbose); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 511 | |
| 512 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 513 | * regulator_get_by_devname: returns the pointer to the pmic regulator device. |
| 514 | * Search by name, found in regulator device's name. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 515 | * |
| 516 | * @devname - expected string for 'dev->name' of regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 517 | * @devp - returned pointer to the regulator device |
| 518 | * @return 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 519 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 520 | * The returned 'regulator' device is probed and can be used with: |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 521 | * - regulator_get/set_* |
| 522 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 523 | int regulator_get_by_devname(const char *devname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 524 | |
| 525 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 526 | * regulator_get_by_platname: returns the pointer to the pmic regulator device. |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 527 | * Search by name, found in regulator uclass plat. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 528 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 529 | * @platname - expected string for uc_pdata->name of regulator uclass plat |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 530 | * @devp - returns pointer to the regulator device or NULL on error |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 531 | * @return 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 532 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 533 | * The returned 'regulator' device is probed and can be used with: |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 534 | * - regulator_get/set_* |
| 535 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 536 | int regulator_get_by_platname(const char *platname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 537 | |
Przemyslaw Marczak | c900103 | 2015-10-27 13:07:59 +0100 | [diff] [blame] | 538 | /** |
| 539 | * device_get_supply_regulator: returns the pointer to the supply regulator. |
| 540 | * Search by phandle, found in device's node. |
| 541 | * |
| 542 | * Note: Please pay attention to proper order of device bind sequence. |
| 543 | * The regulator device searched by the phandle, must be binded before |
| 544 | * this function call. |
| 545 | * |
| 546 | * @dev - device with supply phandle |
| 547 | * @supply_name - phandle name of regulator |
| 548 | * @devp - returned pointer to the supply device |
| 549 | * @return 0 on success or negative value of errno. |
| 550 | */ |
| 551 | int device_get_supply_regulator(struct udevice *dev, const char *supply_name, |
| 552 | struct udevice **devp); |
Peng Fan | a1a2a22 | 2020-10-15 18:06:48 +0800 | [diff] [blame] | 553 | #else |
| 554 | static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep) |
| 555 | { |
| 556 | return -ENOSYS; |
| 557 | } |
| 558 | |
| 559 | static inline int regulator_get_value(struct udevice *dev) |
| 560 | { |
| 561 | return -ENOSYS; |
| 562 | } |
| 563 | |
| 564 | static inline int regulator_set_value(struct udevice *dev, int uV) |
| 565 | { |
| 566 | return -ENOSYS; |
| 567 | } |
| 568 | |
| 569 | static inline int regulator_set_suspend_value(struct udevice *dev, int uV) |
| 570 | { |
| 571 | return -ENOSYS; |
| 572 | } |
| 573 | |
| 574 | static inline int regulator_get_suspend_value(struct udevice *dev) |
| 575 | { |
| 576 | return -ENOSYS; |
| 577 | } |
| 578 | |
| 579 | static inline int regulator_set_value_force(struct udevice *dev, int uV) |
| 580 | { |
| 581 | return -ENOSYS; |
| 582 | } |
| 583 | |
| 584 | static inline int regulator_get_current(struct udevice *dev) |
| 585 | { |
| 586 | return -ENOSYS; |
| 587 | } |
| 588 | |
| 589 | static inline int regulator_set_current(struct udevice *dev, int uA) |
| 590 | { |
| 591 | return -ENOSYS; |
| 592 | } |
| 593 | |
| 594 | static inline int regulator_get_enable(struct udevice *dev) |
| 595 | { |
| 596 | return -ENOSYS; |
| 597 | } |
| 598 | |
| 599 | static inline int regulator_set_enable(struct udevice *dev, bool enable) |
| 600 | { |
| 601 | return -ENOSYS; |
| 602 | } |
| 603 | |
| 604 | static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable) |
| 605 | { |
| 606 | return -ENOSYS; |
| 607 | } |
| 608 | |
| 609 | static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable) |
| 610 | { |
| 611 | return -ENOSYS; |
| 612 | } |
| 613 | |
| 614 | static inline int regulator_get_suspend_enable(struct udevice *dev) |
| 615 | { |
| 616 | return -ENOSYS; |
| 617 | } |
| 618 | |
| 619 | static inline int regulator_get_mode(struct udevice *dev) |
| 620 | { |
| 621 | return -ENOSYS; |
| 622 | } |
| 623 | |
| 624 | static inline int regulator_set_mode(struct udevice *dev, int mode_id) |
| 625 | { |
| 626 | return -ENOSYS; |
| 627 | } |
| 628 | |
| 629 | static inline int regulators_enable_boot_on(bool verbose) |
| 630 | { |
| 631 | return -ENOSYS; |
| 632 | } |
| 633 | |
| 634 | static inline int regulator_autoset(struct udevice *dev) |
| 635 | { |
| 636 | return -ENOSYS; |
| 637 | } |
| 638 | |
| 639 | static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp) |
| 640 | { |
| 641 | return -ENOSYS; |
| 642 | } |
| 643 | |
| 644 | static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[], |
| 645 | bool verbose) |
| 646 | { |
| 647 | return -ENOSYS; |
| 648 | } |
| 649 | |
| 650 | static inline int regulator_get_by_devname(const char *devname, struct udevice **devp) |
| 651 | { |
| 652 | return -ENOSYS; |
| 653 | } |
| 654 | |
| 655 | static inline int regulator_get_by_platname(const char *platname, struct udevice **devp) |
| 656 | { |
| 657 | return -ENOSYS; |
| 658 | } |
| 659 | |
| 660 | static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name, |
| 661 | struct udevice **devp) |
| 662 | { |
| 663 | return -ENOSYS; |
| 664 | } |
| 665 | #endif |
Przemyslaw Marczak | c900103 | 2015-10-27 13:07:59 +0100 | [diff] [blame] | 666 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 667 | #endif /* _INCLUDE_REGULATOR_H_ */ |