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 |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 154 | * TODO(sjg@chromium.org): Consider putting the above two into @flags |
Krzysztof Kozlowski | e2fa397 | 2019-03-06 19:37:54 +0100 | [diff] [blame] | 155 | * @ramp_delay - Time to settle down after voltage change (unit: uV/us) |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 156 | * @flags: - flags value (see REGULATOR_FLAG_...) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 157 | * @name** - fdt regulator name - should be taken from the device tree |
Keerthy | 4d96cd0 | 2016-09-30 09:20:42 +0530 | [diff] [blame] | 158 | * ctrl_reg: - Control register offset used to enable/disable regulator |
| 159 | * volt_reg: - register offset for writing voltage vsel values |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 160 | * |
| 161 | * Note: |
| 162 | * * - set automatically on device probe by the uclass's '.pre_probe' method. |
| 163 | * ** - set automatically on device bind by the uclass's '.post_bind' method. |
| 164 | * The constraints: type, mode, mode_count, can be set by device driver, e.g. |
| 165 | * by the driver '.probe' method. |
| 166 | */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 167 | struct dm_regulator_uclass_plat { |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 168 | enum regulator_type type; |
| 169 | struct dm_regulator_mode *mode; |
| 170 | int mode_count; |
| 171 | int min_uV; |
| 172 | int max_uV; |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 173 | int init_uV; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 174 | int min_uA; |
| 175 | int max_uA; |
Krzysztof Kozlowski | e2fa397 | 2019-03-06 19:37:54 +0100 | [diff] [blame] | 176 | unsigned int ramp_delay; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 177 | bool always_on; |
| 178 | bool boot_on; |
| 179 | const char *name; |
Simon Glass | 991f9bc | 2015-06-23 15:38:57 -0600 | [diff] [blame] | 180 | int flags; |
Keerthy | 4d96cd0 | 2016-09-30 09:20:42 +0530 | [diff] [blame] | 181 | u8 ctrl_reg; |
| 182 | u8 volt_reg; |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 183 | bool suspend_on; |
| 184 | u32 suspend_uV; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | /* Regulator device operations */ |
| 188 | struct dm_regulator_ops { |
| 189 | /** |
| 190 | * The regulator output value function calls operates on a micro Volts. |
| 191 | * |
| 192 | * get/set_value - get/set output value of the given output number |
| 193 | * @dev - regulator device |
| 194 | * Sets: |
| 195 | * @uV - set the output value [micro Volts] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 196 | * @return output value [uV] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 197 | */ |
| 198 | int (*get_value)(struct udevice *dev); |
| 199 | int (*set_value)(struct udevice *dev, int uV); |
| 200 | |
| 201 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 202 | * The regulator suspend output value function calls operates |
| 203 | * on a micro Volts. |
| 204 | * |
| 205 | * get/set_suspen_value - get/set suspend mode output value |
| 206 | * @dev - regulator device |
| 207 | * Sets: |
| 208 | * @uV - set the suspend output value [micro Volts] |
| 209 | * @return output value [uV] on success or negative errno if fail. |
| 210 | */ |
| 211 | int (*set_suspend_value)(struct udevice *dev, int uV); |
| 212 | int (*get_suspend_value)(struct udevice *dev); |
| 213 | |
| 214 | /** |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 215 | * The regulator output current function calls operates on a micro Amps. |
| 216 | * |
| 217 | * get/set_current - get/set output current of the given output number |
| 218 | * @dev - regulator device |
| 219 | * Sets: |
| 220 | * @uA - set the output current [micro Amps] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 221 | * @return output value [uA] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 222 | */ |
| 223 | int (*get_current)(struct udevice *dev); |
| 224 | int (*set_current)(struct udevice *dev, int uA); |
| 225 | |
| 226 | /** |
| 227 | * The most basic feature of the regulator output is its enable state. |
| 228 | * |
| 229 | * get/set_enable - get/set enable state of the given output number |
| 230 | * @dev - regulator device |
| 231 | * Sets: |
| 232 | * @enable - set true - enable or false - disable |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 233 | * @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] | 234 | */ |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 235 | int (*get_enable)(struct udevice *dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 236 | int (*set_enable)(struct udevice *dev, bool enable); |
| 237 | |
| 238 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 239 | * The most basic feature of the regulator output is its enable state |
| 240 | * in suspend mode. |
| 241 | * |
| 242 | * get/set_suspend_enable - get/set enable state of the suspend output |
| 243 | * @dev - regulator device |
| 244 | * Sets: |
| 245 | * @enable - set true - enable or false - disable |
| 246 | * @return true/false for get or -errno if fail; 0 / -errno for set. |
| 247 | */ |
| 248 | int (*set_suspend_enable)(struct udevice *dev, bool enable); |
| 249 | int (*get_suspend_enable)(struct udevice *dev); |
| 250 | |
| 251 | /** |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 252 | * The 'get/set_mode()' function calls should operate on a driver- |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 253 | * specific mode id definitions, which should be found in: |
| 254 | * field 'id' of struct dm_regulator_mode. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 255 | * |
| 256 | * get/set_mode - get/set operation mode of the given output number |
| 257 | * @dev - regulator device |
| 258 | * Sets |
| 259 | * @mode_id - set output mode id (struct dm_regulator_mode->id) |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 260 | * @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] | 261 | * Note: |
| 262 | * The field 'id' of struct type 'dm_regulator_mode', should be always |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 263 | * a positive number, since the negative is reserved for the error. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 264 | */ |
| 265 | int (*get_mode)(struct udevice *dev); |
| 266 | int (*set_mode)(struct udevice *dev, int mode_id); |
| 267 | }; |
| 268 | |
Peng Fan | a1a2a22 | 2020-10-15 18:06:48 +0800 | [diff] [blame] | 269 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 270 | /** |
| 271 | * regulator_mode: returns a pointer to the array of regulator mode info |
| 272 | * |
| 273 | * @dev - pointer to the regulator device |
| 274 | * @modep - pointer to the returned mode info array |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 275 | * @return - count of modep entries on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 276 | */ |
| 277 | int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep); |
| 278 | |
| 279 | /** |
| 280 | * regulator_get_value: get microvoltage voltage value of a given regulator |
| 281 | * |
| 282 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 283 | * @return - positive output value [uV] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 284 | */ |
| 285 | int regulator_get_value(struct udevice *dev); |
| 286 | |
| 287 | /** |
| 288 | * regulator_set_value: set the microvoltage value of a given regulator. |
| 289 | * |
| 290 | * @dev - pointer to the regulator device |
| 291 | * @uV - the output value to set [micro Volts] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 292 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 293 | */ |
| 294 | int regulator_set_value(struct udevice *dev, int uV); |
| 295 | |
| 296 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 297 | * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator. |
| 298 | * |
| 299 | * @dev - pointer to the regulator device |
| 300 | * @uV - the output suspend value to set [micro Volts] |
| 301 | * @return - 0 on success or -errno val if fails |
| 302 | */ |
| 303 | int regulator_set_suspend_value(struct udevice *dev, int uV); |
| 304 | |
| 305 | /** |
| 306 | * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator. |
| 307 | * |
| 308 | * @dev - pointer to the regulator device |
| 309 | * @return - positive output value [uV] on success or negative errno if fail. |
| 310 | */ |
| 311 | int regulator_get_suspend_value(struct udevice *dev); |
| 312 | |
| 313 | /** |
Keerthy | 162c02e | 2016-10-26 13:42:30 +0530 | [diff] [blame] | 314 | * regulator_set_value_force: set the microvoltage value of a given regulator |
| 315 | * without any min-,max condition check |
| 316 | * |
| 317 | * @dev - pointer to the regulator device |
| 318 | * @uV - the output value to set [micro Volts] |
| 319 | * @return - 0 on success or -errno val if fails |
| 320 | */ |
| 321 | int regulator_set_value_force(struct udevice *dev, int uV); |
| 322 | |
| 323 | /** |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 324 | * regulator_get_current: get microampere value of a given regulator |
| 325 | * |
| 326 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 327 | * @return - positive output current [uA] on success or negative errno if fail. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 328 | */ |
| 329 | int regulator_get_current(struct udevice *dev); |
| 330 | |
| 331 | /** |
| 332 | * regulator_set_current: set the microampere value of a given regulator. |
| 333 | * |
| 334 | * @dev - pointer to the regulator device |
| 335 | * @uA - set the output current [micro Amps] |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 336 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 337 | */ |
| 338 | int regulator_set_current(struct udevice *dev, int uA); |
| 339 | |
| 340 | /** |
| 341 | * regulator_get_enable: get regulator device enable state. |
| 342 | * |
| 343 | * @dev - pointer to the regulator device |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 344 | * @return - true/false of enable state or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 345 | */ |
Keerthy | 23be7fb | 2017-06-13 09:53:45 +0530 | [diff] [blame] | 346 | int regulator_get_enable(struct udevice *dev); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * regulator_set_enable: set regulator enable state |
| 350 | * |
| 351 | * @dev - pointer to the regulator device |
| 352 | * @enable - set true or false |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 353 | * @return - 0 on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 354 | */ |
| 355 | int regulator_set_enable(struct udevice *dev, bool enable); |
| 356 | |
| 357 | /** |
Lokesh Vutla | 7106b78 | 2019-01-11 15:15:51 +0530 | [diff] [blame] | 358 | * regulator_set_enable_if_allowed: set regulator enable state if allowed by |
| 359 | * regulator |
| 360 | * |
| 361 | * @dev - pointer to the regulator device |
| 362 | * @enable - set true or false |
| 363 | * @return - 0 on success or if enabling is not supported |
| 364 | * -errno val if fails. |
| 365 | */ |
| 366 | int regulator_set_enable_if_allowed(struct udevice *dev, bool enable); |
| 367 | |
| 368 | /** |
Joseph Chen | bb51132 | 2019-09-26 15:43:52 +0800 | [diff] [blame] | 369 | * regulator_set_suspend_enable: set regulator suspend enable state |
| 370 | * |
| 371 | * @dev - pointer to the regulator device |
| 372 | * @enable - set true or false |
| 373 | * @return - 0 on success or -errno val if fails |
| 374 | */ |
| 375 | int regulator_set_suspend_enable(struct udevice *dev, bool enable); |
| 376 | |
| 377 | /** |
| 378 | * regulator_get_suspend_enable: get regulator suspend enable state |
| 379 | * |
| 380 | * @dev - pointer to the regulator device |
| 381 | * @return - true/false of enable state or -errno val if fails |
| 382 | */ |
| 383 | int regulator_get_suspend_enable(struct udevice *dev); |
| 384 | |
| 385 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 386 | * regulator_get_mode: get active operation mode id of a given regulator |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 387 | * |
| 388 | * @dev - pointer to the regulator device |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 389 | * @return - positive mode 'id' number on success or -errno val if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 390 | * Note: |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 391 | * The device can provide an array of operating modes, which is type of struct |
| 392 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside |
| 393 | * that array. By calling this function, the driver should return an active mode |
| 394 | * id of the given regulator device. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 395 | */ |
| 396 | int regulator_get_mode(struct udevice *dev); |
| 397 | |
| 398 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 399 | * regulator_set_mode: set the given regulator's, active mode id |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 400 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 401 | * @dev - pointer to the regulator device |
| 402 | * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode) |
| 403 | * @return - 0 on success or -errno value if fails |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 404 | * Note: |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 405 | * The device can provide an array of operating modes, which is type of struct |
| 406 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside |
| 407 | * that array. By calling this function, the driver should set the active mode |
| 408 | * of a given regulator to given by "mode_id" argument. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 409 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 410 | int regulator_set_mode(struct udevice *dev, int mode_id); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 411 | |
| 412 | /** |
Simon Glass | efeeb2c | 2015-06-23 15:38:59 -0600 | [diff] [blame] | 413 | * regulators_enable_boot_on() - enable regulators needed for boot |
| 414 | * |
| 415 | * This enables all regulators which are marked to be on at boot time. This |
| 416 | * only works for regulators which don't have a range for voltage/current, |
| 417 | * since in that case it is not possible to know which value to use. |
| 418 | * |
| 419 | * This effectively calls regulator_autoset() for every regulator. |
| 420 | */ |
| 421 | int regulators_enable_boot_on(bool verbose); |
| 422 | |
| 423 | /** |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 424 | * regulator_autoset: setup the voltage/current on a regulator |
| 425 | * |
| 426 | * 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] | 427 | * (struct dm_regulator_uclass_plat): |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 428 | * |
| 429 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, |
| 430 | * or if both are unset, then the function returns |
| 431 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal |
| 432 | * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal |
| 433 | * |
| 434 | * The function returns on the first-encountered error. |
| 435 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 436 | * @platname - expected string for dm_regulator_uclass_plat .name field |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 437 | * @devp - returned pointer to the regulator device - if non-NULL passed |
| 438 | * @return: 0 on success or negative value of errno. |
| 439 | */ |
| 440 | int regulator_autoset(struct udevice *dev); |
| 441 | |
| 442 | /** |
| 443 | * regulator_autoset_by_name: setup the regulator given by its uclass's |
| 444 | * 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] | 445 | * uclass's platform data (struct dm_regulator_uclass_plat): |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 446 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, |
| 447 | * or if both are unset, then the function returns |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 448 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal |
| 449 | * - 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] | 450 | * |
| 451 | * The function returns on first encountered error. |
| 452 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 453 | * @platname - expected string for dm_regulator_uclass_plat .name field |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 454 | * @devp - returned pointer to the regulator device - if non-NULL passed |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 455 | * @return: 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 456 | * |
| 457 | * The returned 'regulator' device can be used with: |
| 458 | * - regulator_get/set_* |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 459 | */ |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 460 | int regulator_autoset_by_name(const char *platname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 461 | |
| 462 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 463 | * regulator_list_autoset: setup the regulators given by list of their uclass's |
| 464 | * platform data name field. The setup depends on constraints found in device's |
| 465 | * uclass's platform data. The function loops with calls to: |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 466 | * regulator_autoset_by_name() for each name from the list. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 467 | * |
| 468 | * @list_platname - an array of expected strings for .name field of each |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 469 | * regulator's uclass plat |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 470 | * @list_devp - an array of returned pointers to the successfully setup |
| 471 | * regulator devices if non-NULL passed |
| 472 | * @verbose - (true/false) print each regulator setup info, or be quiet |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 473 | * @return 0 on successfully setup of all list entries, otherwise first error. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 474 | * |
| 475 | * The returned 'regulator' devices can be used with: |
| 476 | * - regulator_get/set_* |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 477 | * |
| 478 | * Note: The list must ends with NULL entry, like in the "platname" list below: |
| 479 | * char *my_regulators[] = { |
| 480 | * "VCC_3.3V", |
| 481 | * "VCC_1.8V", |
| 482 | * NULL, |
| 483 | * }; |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 484 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 485 | int regulator_list_autoset(const char *list_platname[], |
| 486 | struct udevice *list_devp[], |
| 487 | bool verbose); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 488 | |
| 489 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 490 | * regulator_get_by_devname: returns the pointer to the pmic regulator device. |
| 491 | * Search by name, found in regulator device's name. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 492 | * |
| 493 | * @devname - expected string for 'dev->name' of regulator device |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 494 | * @devp - returned pointer to the regulator device |
| 495 | * @return 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 496 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 497 | * The returned 'regulator' device is probed and can be used with: |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 498 | * - regulator_get/set_* |
| 499 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 500 | int regulator_get_by_devname(const char *devname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 501 | |
| 502 | /** |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 503 | * regulator_get_by_platname: returns the pointer to the pmic regulator device. |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 504 | * Search by name, found in regulator uclass plat. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 505 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 506 | * @platname - expected string for uc_pdata->name of regulator uclass plat |
Simon Glass | 46cb824 | 2015-06-23 15:38:58 -0600 | [diff] [blame] | 507 | * @devp - returns pointer to the regulator device or NULL on error |
Przemyslaw Marczak | afee81e | 2015-04-20 20:07:47 +0200 | [diff] [blame] | 508 | * @return 0 on success or negative value of errno. |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 509 | * |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 510 | * The returned 'regulator' device is probed and can be used with: |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 511 | * - regulator_get/set_* |
| 512 | */ |
Przemyslaw Marczak | 75692a3 | 2015-05-13 13:38:27 +0200 | [diff] [blame] | 513 | int regulator_get_by_platname(const char *platname, struct udevice **devp); |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 514 | |
Przemyslaw Marczak | c900103 | 2015-10-27 13:07:59 +0100 | [diff] [blame] | 515 | /** |
| 516 | * device_get_supply_regulator: returns the pointer to the supply regulator. |
| 517 | * Search by phandle, found in device's node. |
| 518 | * |
| 519 | * Note: Please pay attention to proper order of device bind sequence. |
| 520 | * The regulator device searched by the phandle, must be binded before |
| 521 | * this function call. |
| 522 | * |
| 523 | * @dev - device with supply phandle |
| 524 | * @supply_name - phandle name of regulator |
| 525 | * @devp - returned pointer to the supply device |
| 526 | * @return 0 on success or negative value of errno. |
| 527 | */ |
| 528 | int device_get_supply_regulator(struct udevice *dev, const char *supply_name, |
| 529 | struct udevice **devp); |
Peng Fan | a1a2a22 | 2020-10-15 18:06:48 +0800 | [diff] [blame] | 530 | #else |
| 531 | static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep) |
| 532 | { |
| 533 | return -ENOSYS; |
| 534 | } |
| 535 | |
| 536 | static inline int regulator_get_value(struct udevice *dev) |
| 537 | { |
| 538 | return -ENOSYS; |
| 539 | } |
| 540 | |
| 541 | static inline int regulator_set_value(struct udevice *dev, int uV) |
| 542 | { |
| 543 | return -ENOSYS; |
| 544 | } |
| 545 | |
| 546 | static inline int regulator_set_suspend_value(struct udevice *dev, int uV) |
| 547 | { |
| 548 | return -ENOSYS; |
| 549 | } |
| 550 | |
| 551 | static inline int regulator_get_suspend_value(struct udevice *dev) |
| 552 | { |
| 553 | return -ENOSYS; |
| 554 | } |
| 555 | |
| 556 | static inline int regulator_set_value_force(struct udevice *dev, int uV) |
| 557 | { |
| 558 | return -ENOSYS; |
| 559 | } |
| 560 | |
| 561 | static inline int regulator_get_current(struct udevice *dev) |
| 562 | { |
| 563 | return -ENOSYS; |
| 564 | } |
| 565 | |
| 566 | static inline int regulator_set_current(struct udevice *dev, int uA) |
| 567 | { |
| 568 | return -ENOSYS; |
| 569 | } |
| 570 | |
| 571 | static inline int regulator_get_enable(struct udevice *dev) |
| 572 | { |
| 573 | return -ENOSYS; |
| 574 | } |
| 575 | |
| 576 | static inline int regulator_set_enable(struct udevice *dev, bool enable) |
| 577 | { |
| 578 | return -ENOSYS; |
| 579 | } |
| 580 | |
| 581 | static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable) |
| 582 | { |
| 583 | return -ENOSYS; |
| 584 | } |
| 585 | |
| 586 | static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable) |
| 587 | { |
| 588 | return -ENOSYS; |
| 589 | } |
| 590 | |
| 591 | static inline int regulator_get_suspend_enable(struct udevice *dev) |
| 592 | { |
| 593 | return -ENOSYS; |
| 594 | } |
| 595 | |
| 596 | static inline int regulator_get_mode(struct udevice *dev) |
| 597 | { |
| 598 | return -ENOSYS; |
| 599 | } |
| 600 | |
| 601 | static inline int regulator_set_mode(struct udevice *dev, int mode_id) |
| 602 | { |
| 603 | return -ENOSYS; |
| 604 | } |
| 605 | |
| 606 | static inline int regulators_enable_boot_on(bool verbose) |
| 607 | { |
| 608 | return -ENOSYS; |
| 609 | } |
| 610 | |
| 611 | static inline int regulator_autoset(struct udevice *dev) |
| 612 | { |
| 613 | return -ENOSYS; |
| 614 | } |
| 615 | |
| 616 | static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp) |
| 617 | { |
| 618 | return -ENOSYS; |
| 619 | } |
| 620 | |
| 621 | static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[], |
| 622 | bool verbose) |
| 623 | { |
| 624 | return -ENOSYS; |
| 625 | } |
| 626 | |
| 627 | static inline int regulator_get_by_devname(const char *devname, struct udevice **devp) |
| 628 | { |
| 629 | return -ENOSYS; |
| 630 | } |
| 631 | |
| 632 | static inline int regulator_get_by_platname(const char *platname, struct udevice **devp) |
| 633 | { |
| 634 | return -ENOSYS; |
| 635 | } |
| 636 | |
| 637 | static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name, |
| 638 | struct udevice **devp) |
| 639 | { |
| 640 | return -ENOSYS; |
| 641 | } |
| 642 | #endif |
Przemyslaw Marczak | c900103 | 2015-10-27 13:07:59 +0100 | [diff] [blame] | 643 | |
Przemyslaw Marczak | 08edd00 | 2015-04-20 20:07:42 +0200 | [diff] [blame] | 644 | #endif /* _INCLUDE_REGULATOR_H_ */ |