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