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