Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * consumer.h -- SoC Regulator consumer support. |
| 3 | * |
| 4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. |
| 5 | * |
Liam Girdwood | 1dd68f0 | 2009-02-02 21:43:31 +0000 | [diff] [blame] | 6 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * Regulator Consumer Interface. |
| 13 | * |
| 14 | * A Power Management Regulator framework for SoC based devices. |
| 15 | * Features:- |
| 16 | * o Voltage and current level control. |
| 17 | * o Operating mode control. |
| 18 | * o Regulator status. |
| 19 | * o sysfs entries for showing client devices and status |
| 20 | * |
| 21 | * EXPERIMENTAL FEATURES: |
| 22 | * Dynamic Regulator operating Mode Switching (DRMS) - allows regulators |
| 23 | * to use most efficient operating mode depending upon voltage and load and |
| 24 | * is transparent to client drivers. |
| 25 | * |
| 26 | * e.g. Devices x,y,z share regulator r. Device x and y draw 20mA each during |
| 27 | * IO and 1mA at idle. Device z draws 100mA when under load and 5mA when |
| 28 | * idling. Regulator r has > 90% efficiency in NORMAL mode at loads > 100mA |
| 29 | * but this drops rapidly to 60% when below 100mA. Regulator r has > 90% |
| 30 | * efficiency in IDLE mode at loads < 10mA. Thus regulator r will operate |
| 31 | * in normal mode for loads > 10mA and in IDLE mode for load <= 10mA. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #ifndef __LINUX_REGULATOR_CONSUMER_H_ |
| 36 | #define __LINUX_REGULATOR_CONSUMER_H_ |
| 37 | |
Guenter Roeck | 174e964 | 2014-10-09 12:43:27 -0700 | [diff] [blame] | 38 | #include <linux/err.h> |
| 39 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 40 | struct device; |
| 41 | struct notifier_block; |
Tuomas Tynkkynen | 04eca28 | 2014-07-21 18:38:48 +0300 | [diff] [blame] | 42 | struct regmap; |
Liam Girdwood | b56daf1 | 2009-11-11 14:16:10 +0000 | [diff] [blame] | 43 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 44 | /* |
| 45 | * Regulator operating modes. |
| 46 | * |
| 47 | * Regulators can run in a variety of different operating modes depending on |
| 48 | * output load. This allows further system power savings by selecting the |
| 49 | * best (and most efficient) regulator mode for a desired load. |
| 50 | * |
| 51 | * Most drivers will only care about NORMAL. The modes below are generic and |
| 52 | * will probably not match the naming convention of your regulator data sheet |
| 53 | * but should match the use cases in the datasheet. |
| 54 | * |
| 55 | * In order of power efficiency (least efficient at top). |
| 56 | * |
| 57 | * Mode Description |
| 58 | * FAST Regulator can handle fast changes in it's load. |
| 59 | * e.g. useful in CPU voltage & frequency scaling where |
| 60 | * load can quickly increase with CPU frequency increases. |
| 61 | * |
| 62 | * NORMAL Normal regulator power supply mode. Most drivers will |
| 63 | * use this mode. |
| 64 | * |
| 65 | * IDLE Regulator runs in a more efficient mode for light |
| 66 | * loads. Can be used for devices that have a low power |
| 67 | * requirement during periods of inactivity. This mode |
| 68 | * may be more noisy than NORMAL and may not be able |
| 69 | * to handle fast load switching. |
| 70 | * |
| 71 | * STANDBY Regulator runs in the most efficient mode for very |
| 72 | * light loads. Can be used by devices when they are |
| 73 | * in a sleep/standby state. This mode is likely to be |
| 74 | * the most noisy and may not be able to handle fast load |
| 75 | * switching. |
| 76 | * |
| 77 | * NOTE: Most regulators will only support a subset of these modes. Some |
| 78 | * will only just support NORMAL. |
| 79 | * |
| 80 | * These modes can be OR'ed together to make up a mask of valid register modes. |
| 81 | */ |
| 82 | |
| 83 | #define REGULATOR_MODE_FAST 0x1 |
| 84 | #define REGULATOR_MODE_NORMAL 0x2 |
| 85 | #define REGULATOR_MODE_IDLE 0x4 |
| 86 | #define REGULATOR_MODE_STANDBY 0x8 |
| 87 | |
| 88 | /* |
| 89 | * Regulator notifier events. |
| 90 | * |
| 91 | * UNDER_VOLTAGE Regulator output is under voltage. |
| 92 | * OVER_CURRENT Regulator output current is too high. |
| 93 | * REGULATION_OUT Regulator output is out of regulation. |
| 94 | * FAIL Regulator output has failed. |
| 95 | * OVER_TEMP Regulator over temp. |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 96 | * FORCE_DISABLE Regulator forcibly shut down by software. |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 97 | * VOLTAGE_CHANGE Regulator voltage changed. |
Heiko Stübner | 7179569 | 2014-08-28 12:36:04 -0700 | [diff] [blame] | 98 | * Data passed is old voltage cast to (void *). |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 99 | * DISABLE Regulator was disabled. |
Heiko Stübner | 7179569 | 2014-08-28 12:36:04 -0700 | [diff] [blame] | 100 | * PRE_VOLTAGE_CHANGE Regulator is about to have voltage changed. |
| 101 | * Data passed is "struct pre_voltage_change_data" |
| 102 | * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason. |
| 103 | * Data passed is old voltage cast to (void *). |
Richard Fitzgerald | a1c8a55 | 2014-11-24 14:10:52 +0000 | [diff] [blame] | 104 | * PRE_DISABLE Regulator is about to be disabled |
| 105 | * ABORT_DISABLE Regulator disable failed for some reason |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 106 | * |
| 107 | * NOTE: These events can be OR'ed together when passed into handler. |
| 108 | */ |
| 109 | |
| 110 | #define REGULATOR_EVENT_UNDER_VOLTAGE 0x01 |
| 111 | #define REGULATOR_EVENT_OVER_CURRENT 0x02 |
| 112 | #define REGULATOR_EVENT_REGULATION_OUT 0x04 |
| 113 | #define REGULATOR_EVENT_FAIL 0x08 |
| 114 | #define REGULATOR_EVENT_OVER_TEMP 0x10 |
| 115 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 116 | #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 |
Geert Uytterhoeven | 5c9e719 | 2015-02-23 17:10:03 +0100 | [diff] [blame] | 117 | #define REGULATOR_EVENT_DISABLE 0x80 |
Heiko Stübner | 7179569 | 2014-08-28 12:36:04 -0700 | [diff] [blame] | 118 | #define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100 |
| 119 | #define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200 |
Richard Fitzgerald | a1c8a55 | 2014-11-24 14:10:52 +0000 | [diff] [blame] | 120 | #define REGULATOR_EVENT_PRE_DISABLE 0x400 |
| 121 | #define REGULATOR_EVENT_ABORT_DISABLE 0x800 |
Heiko Stübner | 7179569 | 2014-08-28 12:36:04 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event |
| 125 | * |
| 126 | * @old_uV: Current voltage before change. |
| 127 | * @min_uV: Min voltage we'll change to. |
| 128 | * @max_uV: Max voltage we'll change to. |
| 129 | */ |
| 130 | struct pre_voltage_change_data { |
| 131 | unsigned long old_uV; |
| 132 | unsigned long min_uV; |
| 133 | unsigned long max_uV; |
| 134 | }; |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 135 | |
| 136 | struct regulator; |
| 137 | |
| 138 | /** |
| 139 | * struct regulator_bulk_data - Data used for bulk regulator operations. |
| 140 | * |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 141 | * @supply: The name of the supply. Initialised by the user before |
| 142 | * using the bulk regulator APIs. |
Bjorn Andersson | 3ff3f51 | 2015-11-09 22:20:37 -0800 | [diff] [blame] | 143 | * @optional: The supply should be considered optional. Initialised by the user |
| 144 | * before using the bulk regulator APIs. |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 145 | * @consumer: The regulator consumer for the supply. This will be managed |
| 146 | * by the bulk API. |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 147 | * |
| 148 | * The regulator APIs provide a series of regulator_bulk_() API calls as |
| 149 | * a convenience to consumers which require multiple supplies. This |
| 150 | * structure is used to manage data for these calls. |
| 151 | */ |
| 152 | struct regulator_bulk_data { |
| 153 | const char *supply; |
Bjorn Andersson | 3ff3f51 | 2015-11-09 22:20:37 -0800 | [diff] [blame] | 154 | bool optional; |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 155 | struct regulator *consumer; |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 156 | |
Randy Dunlap | bff747c | 2011-09-08 10:16:47 -0700 | [diff] [blame] | 157 | /* private: Internal use */ |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 158 | int ret; |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | #if defined(CONFIG_REGULATOR) |
| 162 | |
| 163 | /* regulator get and put */ |
| 164 | struct regulator *__must_check regulator_get(struct device *dev, |
| 165 | const char *id); |
Stephen Boyd | 070b907 | 2012-01-16 19:39:58 -0800 | [diff] [blame] | 166 | struct regulator *__must_check devm_regulator_get(struct device *dev, |
| 167 | const char *id); |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 168 | struct regulator *__must_check regulator_get_exclusive(struct device *dev, |
| 169 | const char *id); |
Matthias Kaehlcke | 9efdd27 | 2013-08-25 17:54:13 +0200 | [diff] [blame] | 170 | struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev, |
| 171 | const char *id); |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 172 | struct regulator *__must_check regulator_get_optional(struct device *dev, |
| 173 | const char *id); |
| 174 | struct regulator *__must_check devm_regulator_get_optional(struct device *dev, |
| 175 | const char *id); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 176 | void regulator_put(struct regulator *regulator); |
Axel Lin | 2950c4b | 2012-01-29 17:52:37 +0800 | [diff] [blame] | 177 | void devm_regulator_put(struct regulator *regulator); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 178 | |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 179 | int regulator_register_supply_alias(struct device *dev, const char *id, |
| 180 | struct device *alias_dev, |
| 181 | const char *alias_id); |
| 182 | void regulator_unregister_supply_alias(struct device *dev, const char *id); |
| 183 | |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 184 | int regulator_bulk_register_supply_alias(struct device *dev, |
| 185 | const char *const *id, |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 186 | struct device *alias_dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 187 | const char *const *alias_id, |
| 188 | int num_id); |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 189 | void regulator_bulk_unregister_supply_alias(struct device *dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 190 | const char * const *id, int num_id); |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 191 | |
| 192 | int devm_regulator_register_supply_alias(struct device *dev, const char *id, |
| 193 | struct device *alias_dev, |
| 194 | const char *alias_id); |
| 195 | void devm_regulator_unregister_supply_alias(struct device *dev, |
| 196 | const char *id); |
| 197 | |
| 198 | int devm_regulator_bulk_register_supply_alias(struct device *dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 199 | const char *const *id, |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 200 | struct device *alias_dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 201 | const char *const *alias_id, |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 202 | int num_id); |
| 203 | void devm_regulator_bulk_unregister_supply_alias(struct device *dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 204 | const char *const *id, |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 205 | int num_id); |
| 206 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 207 | /* regulator output control and status */ |
Mark Brown | c8801a8 | 2012-03-19 16:35:48 +0000 | [diff] [blame] | 208 | int __must_check regulator_enable(struct regulator *regulator); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 209 | int regulator_disable(struct regulator *regulator); |
| 210 | int regulator_force_disable(struct regulator *regulator); |
| 211 | int regulator_is_enabled(struct regulator *regulator); |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 212 | int regulator_disable_deferred(struct regulator *regulator, int ms); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 213 | |
Mark Brown | c8801a8 | 2012-03-19 16:35:48 +0000 | [diff] [blame] | 214 | int __must_check regulator_bulk_get(struct device *dev, int num_consumers, |
| 215 | struct regulator_bulk_data *consumers); |
| 216 | int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers, |
| 217 | struct regulator_bulk_data *consumers); |
| 218 | int __must_check regulator_bulk_enable(int num_consumers, |
| 219 | struct regulator_bulk_data *consumers); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 220 | int regulator_bulk_disable(int num_consumers, |
| 221 | struct regulator_bulk_data *consumers); |
Donggeun Kim | e1de2f4 | 2012-01-03 16:22:03 +0900 | [diff] [blame] | 222 | int regulator_bulk_force_disable(int num_consumers, |
| 223 | struct regulator_bulk_data *consumers); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 224 | void regulator_bulk_free(int num_consumers, |
| 225 | struct regulator_bulk_data *consumers); |
| 226 | |
Marek Szyprowski | d1e7de3 | 2012-12-04 15:01:01 +0100 | [diff] [blame] | 227 | int regulator_can_change_voltage(struct regulator *regulator); |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 228 | int regulator_count_voltages(struct regulator *regulator); |
| 229 | int regulator_list_voltage(struct regulator *regulator, unsigned selector); |
Mark Brown | a7a1ad90 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 230 | int regulator_is_supported_voltage(struct regulator *regulator, |
| 231 | int min_uV, int max_uV); |
Paul Walmsley | 2a668a8 | 2013-06-07 08:06:56 +0000 | [diff] [blame] | 232 | unsigned int regulator_get_linear_step(struct regulator *regulator); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 233 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); |
Linus Walleij | 88cd222b | 2011-03-17 13:24:52 +0100 | [diff] [blame] | 234 | int regulator_set_voltage_time(struct regulator *regulator, |
| 235 | int old_uV, int new_uV); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 236 | int regulator_get_voltage(struct regulator *regulator); |
Mark Brown | 606a256 | 2010-12-16 15:49:36 +0000 | [diff] [blame] | 237 | int regulator_sync_voltage(struct regulator *regulator); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 238 | int regulator_set_current_limit(struct regulator *regulator, |
| 239 | int min_uA, int max_uA); |
| 240 | int regulator_get_current_limit(struct regulator *regulator); |
| 241 | |
| 242 | int regulator_set_mode(struct regulator *regulator, unsigned int mode); |
| 243 | unsigned int regulator_get_mode(struct regulator *regulator); |
Bjorn Andersson | e39ce48 | 2015-02-11 19:35:27 -0800 | [diff] [blame] | 244 | int regulator_set_load(struct regulator *regulator, int load_uA); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 245 | |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 246 | int regulator_allow_bypass(struct regulator *regulator, bool allow); |
| 247 | |
Tuomas Tynkkynen | 04eca28 | 2014-07-21 18:38:48 +0300 | [diff] [blame] | 248 | struct regmap *regulator_get_regmap(struct regulator *regulator); |
| 249 | int regulator_get_hardware_vsel_register(struct regulator *regulator, |
| 250 | unsigned *vsel_reg, |
| 251 | unsigned *vsel_mask); |
| 252 | int regulator_list_hardware_vsel(struct regulator *regulator, |
| 253 | unsigned selector); |
| 254 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 255 | /* regulator notifier block */ |
| 256 | int regulator_register_notifier(struct regulator *regulator, |
| 257 | struct notifier_block *nb); |
Charles Keepax | 046db76 | 2015-03-05 15:39:20 +0000 | [diff] [blame] | 258 | int devm_regulator_register_notifier(struct regulator *regulator, |
| 259 | struct notifier_block *nb); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 260 | int regulator_unregister_notifier(struct regulator *regulator, |
| 261 | struct notifier_block *nb); |
Charles Keepax | 046db76 | 2015-03-05 15:39:20 +0000 | [diff] [blame] | 262 | void devm_regulator_unregister_notifier(struct regulator *regulator, |
| 263 | struct notifier_block *nb); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 264 | |
| 265 | /* driver data - core doesn't touch */ |
| 266 | void *regulator_get_drvdata(struct regulator *regulator); |
| 267 | void regulator_set_drvdata(struct regulator *regulator, void *data); |
| 268 | |
| 269 | #else |
| 270 | |
| 271 | /* |
| 272 | * Make sure client drivers will still build on systems with no software |
| 273 | * controllable voltage or current regulators. |
| 274 | */ |
| 275 | static inline struct regulator *__must_check regulator_get(struct device *dev, |
| 276 | const char *id) |
| 277 | { |
| 278 | /* Nothing except the stubbed out regulator API should be |
| 279 | * looking at the value except to check if it is an error |
Jean Delvare | be1a50d | 2010-04-03 17:37:45 +0200 | [diff] [blame] | 280 | * value. Drivers are free to handle NULL specifically by |
| 281 | * skipping all regulator API calls, but they don't have to. |
| 282 | * Drivers which don't, should make sure they properly handle |
| 283 | * corner cases of the API, such as regulator_get_voltage() |
| 284 | * returning 0. |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 285 | */ |
Jean Delvare | be1a50d | 2010-04-03 17:37:45 +0200 | [diff] [blame] | 286 | return NULL; |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 287 | } |
Stephen Boyd | 070b907 | 2012-01-16 19:39:58 -0800 | [diff] [blame] | 288 | |
| 289 | static inline struct regulator *__must_check |
| 290 | devm_regulator_get(struct device *dev, const char *id) |
| 291 | { |
| 292 | return NULL; |
| 293 | } |
| 294 | |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 295 | static inline struct regulator *__must_check |
Mark Brown | 4bdfb27 | 2013-07-29 21:00:53 +0100 | [diff] [blame] | 296 | regulator_get_exclusive(struct device *dev, const char *id) |
| 297 | { |
Mark Brown | 70b946f | 2014-10-24 21:56:58 +0100 | [diff] [blame] | 298 | return ERR_PTR(-ENODEV); |
Mark Brown | 4bdfb27 | 2013-07-29 21:00:53 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 301 | static inline struct regulator *__must_check |
| 302 | regulator_get_optional(struct device *dev, const char *id) |
| 303 | { |
Tim Kryger | df7926f | 2014-04-17 11:55:24 -0700 | [diff] [blame] | 304 | return ERR_PTR(-ENODEV); |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Mark Brown | 4bdfb27 | 2013-07-29 21:00:53 +0100 | [diff] [blame] | 307 | |
| 308 | static inline struct regulator *__must_check |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 309 | devm_regulator_get_optional(struct device *dev, const char *id) |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 310 | { |
Tim Kryger | df7926f | 2014-04-17 11:55:24 -0700 | [diff] [blame] | 311 | return ERR_PTR(-ENODEV); |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static inline void regulator_put(struct regulator *regulator) |
| 315 | { |
| 316 | } |
| 317 | |
Axel Lin | 2950c4b | 2012-01-29 17:52:37 +0800 | [diff] [blame] | 318 | static inline void devm_regulator_put(struct regulator *regulator) |
| 319 | { |
| 320 | } |
| 321 | |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 322 | static inline int regulator_register_supply_alias(struct device *dev, |
| 323 | const char *id, |
| 324 | struct device *alias_dev, |
| 325 | const char *alias_id) |
| 326 | { |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static inline void regulator_unregister_supply_alias(struct device *dev, |
| 331 | const char *id) |
| 332 | { |
| 333 | } |
| 334 | |
| 335 | static inline int regulator_bulk_register_supply_alias(struct device *dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 336 | const char *const *id, |
| 337 | struct device *alias_dev, |
| 338 | const char * const *alias_id, |
| 339 | int num_id) |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 340 | { |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | static inline void regulator_bulk_unregister_supply_alias(struct device *dev, |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 345 | const char * const *id, |
| 346 | int num_id) |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 347 | { |
| 348 | } |
| 349 | |
| 350 | static inline int devm_regulator_register_supply_alias(struct device *dev, |
| 351 | const char *id, |
| 352 | struct device *alias_dev, |
| 353 | const char *alias_id) |
| 354 | { |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static inline void devm_regulator_unregister_supply_alias(struct device *dev, |
| 359 | const char *id) |
| 360 | { |
| 361 | } |
| 362 | |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 363 | static inline int devm_regulator_bulk_register_supply_alias(struct device *dev, |
| 364 | const char *const *id, |
| 365 | struct device *alias_dev, |
| 366 | const char *const *alias_id, |
| 367 | int num_id) |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 368 | { |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static inline void devm_regulator_bulk_unregister_supply_alias( |
Lee Jones | 9f8c0fe | 2014-05-23 16:44:10 +0100 | [diff] [blame] | 373 | struct device *dev, const char *const *id, int num_id) |
Charles Keepax | a06ccd9 | 2013-10-15 20:14:20 +0100 | [diff] [blame] | 374 | { |
| 375 | } |
| 376 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 377 | static inline int regulator_enable(struct regulator *regulator) |
| 378 | { |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static inline int regulator_disable(struct regulator *regulator) |
| 383 | { |
| 384 | return 0; |
| 385 | } |
| 386 | |
MyungJoo Ham | 935a5210 | 2012-01-02 18:49:32 +0900 | [diff] [blame] | 387 | static inline int regulator_force_disable(struct regulator *regulator) |
| 388 | { |
| 389 | return 0; |
| 390 | } |
| 391 | |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 392 | static inline int regulator_disable_deferred(struct regulator *regulator, |
| 393 | int ms) |
| 394 | { |
| 395 | return 0; |
| 396 | } |
| 397 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 398 | static inline int regulator_is_enabled(struct regulator *regulator) |
| 399 | { |
| 400 | return 1; |
| 401 | } |
| 402 | |
| 403 | static inline int regulator_bulk_get(struct device *dev, |
| 404 | int num_consumers, |
| 405 | struct regulator_bulk_data *consumers) |
| 406 | { |
| 407 | return 0; |
| 408 | } |
| 409 | |
Axel Lin | e24abd6 | 2012-01-27 12:55:28 +0800 | [diff] [blame] | 410 | static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers, |
| 411 | struct regulator_bulk_data *consumers) |
| 412 | { |
| 413 | return 0; |
| 414 | } |
| 415 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 416 | static inline int regulator_bulk_enable(int num_consumers, |
| 417 | struct regulator_bulk_data *consumers) |
| 418 | { |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static inline int regulator_bulk_disable(int num_consumers, |
| 423 | struct regulator_bulk_data *consumers) |
| 424 | { |
| 425 | return 0; |
| 426 | } |
| 427 | |
Donggeun Kim | e1de2f4 | 2012-01-03 16:22:03 +0900 | [diff] [blame] | 428 | static inline int regulator_bulk_force_disable(int num_consumers, |
| 429 | struct regulator_bulk_data *consumers) |
| 430 | { |
| 431 | return 0; |
| 432 | } |
| 433 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 434 | static inline void regulator_bulk_free(int num_consumers, |
| 435 | struct regulator_bulk_data *consumers) |
| 436 | { |
| 437 | } |
| 438 | |
Arnd Bergmann | b14903e | 2014-06-04 16:46:00 +0200 | [diff] [blame] | 439 | static inline int regulator_can_change_voltage(struct regulator *regulator) |
| 440 | { |
| 441 | return 0; |
| 442 | } |
| 443 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 444 | static inline int regulator_set_voltage(struct regulator *regulator, |
| 445 | int min_uV, int max_uV) |
| 446 | { |
| 447 | return 0; |
| 448 | } |
| 449 | |
Viresh Kumar | d660e92 | 2014-05-27 17:37:29 +0530 | [diff] [blame] | 450 | static inline int regulator_set_voltage_time(struct regulator *regulator, |
| 451 | int old_uV, int new_uV) |
| 452 | { |
| 453 | return 0; |
| 454 | } |
| 455 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 456 | static inline int regulator_get_voltage(struct regulator *regulator) |
| 457 | { |
Mark Brown | 08aed2f | 2012-06-11 20:14:24 +0800 | [diff] [blame] | 458 | return -EINVAL; |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Philip Rakity | 4fe2379 | 2012-06-30 16:05:36 -0700 | [diff] [blame] | 461 | static inline int regulator_is_supported_voltage(struct regulator *regulator, |
| 462 | int min_uV, int max_uV) |
| 463 | { |
| 464 | return 0; |
| 465 | } |
| 466 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 467 | static inline int regulator_set_current_limit(struct regulator *regulator, |
| 468 | int min_uA, int max_uA) |
| 469 | { |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static inline int regulator_get_current_limit(struct regulator *regulator) |
| 474 | { |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static inline int regulator_set_mode(struct regulator *regulator, |
| 479 | unsigned int mode) |
| 480 | { |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static inline unsigned int regulator_get_mode(struct regulator *regulator) |
| 485 | { |
| 486 | return REGULATOR_MODE_NORMAL; |
| 487 | } |
| 488 | |
Bjorn Andersson | e39ce48 | 2015-02-11 19:35:27 -0800 | [diff] [blame] | 489 | static inline int regulator_set_load(struct regulator *regulator, int load_uA) |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 490 | { |
| 491 | return REGULATOR_MODE_NORMAL; |
| 492 | } |
| 493 | |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 494 | static inline int regulator_allow_bypass(struct regulator *regulator, |
| 495 | bool allow) |
| 496 | { |
| 497 | return 0; |
| 498 | } |
| 499 | |
Mark Brown | 3bc0312 | 2014-07-25 19:07:11 +0100 | [diff] [blame] | 500 | static inline struct regmap *regulator_get_regmap(struct regulator *regulator) |
Tuomas Tynkkynen | 04eca28 | 2014-07-21 18:38:48 +0300 | [diff] [blame] | 501 | { |
| 502 | return ERR_PTR(-EOPNOTSUPP); |
| 503 | } |
| 504 | |
Mark Brown | 3bc0312 | 2014-07-25 19:07:11 +0100 | [diff] [blame] | 505 | static inline int regulator_get_hardware_vsel_register(struct regulator *regulator, |
| 506 | unsigned *vsel_reg, |
| 507 | unsigned *vsel_mask) |
Tuomas Tynkkynen | 04eca28 | 2014-07-21 18:38:48 +0300 | [diff] [blame] | 508 | { |
| 509 | return -EOPNOTSUPP; |
| 510 | } |
| 511 | |
Mark Brown | 3bc0312 | 2014-07-25 19:07:11 +0100 | [diff] [blame] | 512 | static inline int regulator_list_hardware_vsel(struct regulator *regulator, |
| 513 | unsigned selector) |
Tuomas Tynkkynen | 04eca28 | 2014-07-21 18:38:48 +0300 | [diff] [blame] | 514 | { |
| 515 | return -EOPNOTSUPP; |
| 516 | } |
| 517 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 518 | static inline int regulator_register_notifier(struct regulator *regulator, |
| 519 | struct notifier_block *nb) |
| 520 | { |
| 521 | return 0; |
| 522 | } |
| 523 | |
Charles Keepax | 046db76 | 2015-03-05 15:39:20 +0000 | [diff] [blame] | 524 | static inline int devm_regulator_register_notifier(struct regulator *regulator, |
| 525 | struct notifier_block *nb) |
| 526 | { |
| 527 | return 0; |
| 528 | } |
| 529 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 530 | static inline int regulator_unregister_notifier(struct regulator *regulator, |
| 531 | struct notifier_block *nb) |
| 532 | { |
| 533 | return 0; |
| 534 | } |
| 535 | |
Charles Keepax | 046db76 | 2015-03-05 15:39:20 +0000 | [diff] [blame] | 536 | static inline int devm_regulator_unregister_notifier(struct regulator *regulator, |
| 537 | struct notifier_block *nb) |
| 538 | { |
| 539 | return 0; |
| 540 | } |
| 541 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 542 | static inline void *regulator_get_drvdata(struct regulator *regulator) |
| 543 | { |
| 544 | return NULL; |
| 545 | } |
| 546 | |
| 547 | static inline void regulator_set_drvdata(struct regulator *regulator, |
| 548 | void *data) |
| 549 | { |
| 550 | } |
| 551 | |
Philip Rakity | 1a8f85d | 2012-11-20 18:07:41 +0100 | [diff] [blame] | 552 | static inline int regulator_count_voltages(struct regulator *regulator) |
| 553 | { |
| 554 | return 0; |
| 555 | } |
Suzuki K. Poulose | 5127e31 | 2015-07-10 16:26:38 +0100 | [diff] [blame] | 556 | |
| 557 | static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector) |
| 558 | { |
| 559 | return -EINVAL; |
| 560 | } |
| 561 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 562 | #endif |
| 563 | |
Viresh Kumar | 30f93ca | 2015-08-17 08:16:51 +0530 | [diff] [blame] | 564 | static inline int regulator_set_voltage_triplet(struct regulator *regulator, |
| 565 | int min_uV, int target_uV, |
| 566 | int max_uV) |
| 567 | { |
| 568 | if (regulator_set_voltage(regulator, target_uV, max_uV) == 0) |
| 569 | return 0; |
| 570 | |
| 571 | return regulator_set_voltage(regulator, min_uV, max_uV); |
| 572 | } |
| 573 | |
Shawn Guo | 3f19657 | 2012-08-05 23:05:20 +0800 | [diff] [blame] | 574 | static inline int regulator_set_voltage_tol(struct regulator *regulator, |
| 575 | int new_uV, int tol_uV) |
| 576 | { |
Mark Brown | dc9ceed | 2013-07-04 17:27:14 +0100 | [diff] [blame] | 577 | if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0) |
| 578 | return 0; |
| 579 | else |
| 580 | return regulator_set_voltage(regulator, |
| 581 | new_uV - tol_uV, new_uV + tol_uV); |
Shawn Guo | 3f19657 | 2012-08-05 23:05:20 +0800 | [diff] [blame] | 582 | } |
| 583 | |
Mark Brown | fe1e43f | 2012-11-14 16:47:10 +0900 | [diff] [blame] | 584 | static inline int regulator_is_supported_voltage_tol(struct regulator *regulator, |
| 585 | int target_uV, int tol_uV) |
| 586 | { |
| 587 | return regulator_is_supported_voltage(regulator, |
| 588 | target_uV - tol_uV, |
| 589 | target_uV + tol_uV); |
| 590 | } |
| 591 | |
Liam Girdwood | e2ce4eaa | 2008-04-30 15:10:07 +0100 | [diff] [blame] | 592 | #endif |