0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef __LINUX_REGULATOR_CONSUMER_H_
0032 #define __LINUX_REGULATOR_CONSUMER_H_
0033
0034 #include <linux/err.h>
0035 #include <linux/suspend.h>
0036
0037 struct device;
0038 struct notifier_block;
0039 struct regmap;
0040 struct regulator_dev;
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 #define REGULATOR_MODE_INVALID 0x0
0082 #define REGULATOR_MODE_FAST 0x1
0083 #define REGULATOR_MODE_NORMAL 0x2
0084 #define REGULATOR_MODE_IDLE 0x4
0085 #define REGULATOR_MODE_STANDBY 0x8
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 #define REGULATOR_EVENT_UNDER_VOLTAGE 0x01
0110 #define REGULATOR_EVENT_OVER_CURRENT 0x02
0111 #define REGULATOR_EVENT_REGULATION_OUT 0x04
0112 #define REGULATOR_EVENT_FAIL 0x08
0113 #define REGULATOR_EVENT_OVER_TEMP 0x10
0114 #define REGULATOR_EVENT_FORCE_DISABLE 0x20
0115 #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
0116 #define REGULATOR_EVENT_DISABLE 0x80
0117 #define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
0118 #define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
0119 #define REGULATOR_EVENT_PRE_DISABLE 0x400
0120 #define REGULATOR_EVENT_ABORT_DISABLE 0x800
0121 #define REGULATOR_EVENT_ENABLE 0x1000
0122
0123
0124
0125
0126
0127 #define REGULATOR_EVENT_UNDER_VOLTAGE_WARN 0x2000
0128 #define REGULATOR_EVENT_OVER_CURRENT_WARN 0x4000
0129 #define REGULATOR_EVENT_OVER_VOLTAGE_WARN 0x8000
0130 #define REGULATOR_EVENT_OVER_TEMP_WARN 0x10000
0131 #define REGULATOR_EVENT_WARN_MASK 0x1E000
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 #define REGULATOR_ERROR_UNDER_VOLTAGE BIT(1)
0146 #define REGULATOR_ERROR_OVER_CURRENT BIT(2)
0147 #define REGULATOR_ERROR_REGULATION_OUT BIT(3)
0148 #define REGULATOR_ERROR_FAIL BIT(4)
0149 #define REGULATOR_ERROR_OVER_TEMP BIT(5)
0150
0151 #define REGULATOR_ERROR_UNDER_VOLTAGE_WARN BIT(6)
0152 #define REGULATOR_ERROR_OVER_CURRENT_WARN BIT(7)
0153 #define REGULATOR_ERROR_OVER_VOLTAGE_WARN BIT(8)
0154 #define REGULATOR_ERROR_OVER_TEMP_WARN BIT(9)
0155
0156
0157
0158
0159
0160
0161
0162
0163 struct pre_voltage_change_data {
0164 unsigned long old_uV;
0165 unsigned long min_uV;
0166 unsigned long max_uV;
0167 };
0168
0169 struct regulator;
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 struct regulator_bulk_data {
0187 const char *supply;
0188 int init_load_uA;
0189 struct regulator *consumer;
0190
0191
0192 int ret;
0193 };
0194
0195 #if defined(CONFIG_REGULATOR)
0196
0197
0198 struct regulator *__must_check regulator_get(struct device *dev,
0199 const char *id);
0200 struct regulator *__must_check devm_regulator_get(struct device *dev,
0201 const char *id);
0202 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
0203 const char *id);
0204 struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
0205 const char *id);
0206 struct regulator *__must_check regulator_get_optional(struct device *dev,
0207 const char *id);
0208 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
0209 const char *id);
0210 void regulator_put(struct regulator *regulator);
0211 void devm_regulator_put(struct regulator *regulator);
0212
0213 int regulator_register_supply_alias(struct device *dev, const char *id,
0214 struct device *alias_dev,
0215 const char *alias_id);
0216 void regulator_unregister_supply_alias(struct device *dev, const char *id);
0217
0218 int regulator_bulk_register_supply_alias(struct device *dev,
0219 const char *const *id,
0220 struct device *alias_dev,
0221 const char *const *alias_id,
0222 int num_id);
0223 void regulator_bulk_unregister_supply_alias(struct device *dev,
0224 const char * const *id, int num_id);
0225
0226 int devm_regulator_register_supply_alias(struct device *dev, const char *id,
0227 struct device *alias_dev,
0228 const char *alias_id);
0229
0230 int devm_regulator_bulk_register_supply_alias(struct device *dev,
0231 const char *const *id,
0232 struct device *alias_dev,
0233 const char *const *alias_id,
0234 int num_id);
0235
0236
0237 int __must_check regulator_enable(struct regulator *regulator);
0238 int regulator_disable(struct regulator *regulator);
0239 int regulator_force_disable(struct regulator *regulator);
0240 int regulator_is_enabled(struct regulator *regulator);
0241 int regulator_disable_deferred(struct regulator *regulator, int ms);
0242
0243 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
0244 struct regulator_bulk_data *consumers);
0245 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
0246 struct regulator_bulk_data *consumers);
0247 int __must_check devm_regulator_bulk_get_const(
0248 struct device *dev, int num_consumers,
0249 const struct regulator_bulk_data *in_consumers,
0250 struct regulator_bulk_data **out_consumers);
0251 int __must_check regulator_bulk_enable(int num_consumers,
0252 struct regulator_bulk_data *consumers);
0253 int regulator_bulk_disable(int num_consumers,
0254 struct regulator_bulk_data *consumers);
0255 int regulator_bulk_force_disable(int num_consumers,
0256 struct regulator_bulk_data *consumers);
0257 void regulator_bulk_free(int num_consumers,
0258 struct regulator_bulk_data *consumers);
0259
0260 int regulator_count_voltages(struct regulator *regulator);
0261 int regulator_list_voltage(struct regulator *regulator, unsigned selector);
0262 int regulator_is_supported_voltage(struct regulator *regulator,
0263 int min_uV, int max_uV);
0264 unsigned int regulator_get_linear_step(struct regulator *regulator);
0265 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
0266 int regulator_set_voltage_time(struct regulator *regulator,
0267 int old_uV, int new_uV);
0268 int regulator_get_voltage(struct regulator *regulator);
0269 int regulator_sync_voltage(struct regulator *regulator);
0270 int regulator_set_current_limit(struct regulator *regulator,
0271 int min_uA, int max_uA);
0272 int regulator_get_current_limit(struct regulator *regulator);
0273
0274 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
0275 unsigned int regulator_get_mode(struct regulator *regulator);
0276 int regulator_get_error_flags(struct regulator *regulator,
0277 unsigned int *flags);
0278 int regulator_set_load(struct regulator *regulator, int load_uA);
0279
0280 int regulator_allow_bypass(struct regulator *regulator, bool allow);
0281
0282 struct regmap *regulator_get_regmap(struct regulator *regulator);
0283 int regulator_get_hardware_vsel_register(struct regulator *regulator,
0284 unsigned *vsel_reg,
0285 unsigned *vsel_mask);
0286 int regulator_list_hardware_vsel(struct regulator *regulator,
0287 unsigned selector);
0288
0289
0290 int regulator_register_notifier(struct regulator *regulator,
0291 struct notifier_block *nb);
0292 int devm_regulator_register_notifier(struct regulator *regulator,
0293 struct notifier_block *nb);
0294 int regulator_unregister_notifier(struct regulator *regulator,
0295 struct notifier_block *nb);
0296 void devm_regulator_unregister_notifier(struct regulator *regulator,
0297 struct notifier_block *nb);
0298
0299
0300 int regulator_suspend_enable(struct regulator_dev *rdev,
0301 suspend_state_t state);
0302 int regulator_suspend_disable(struct regulator_dev *rdev,
0303 suspend_state_t state);
0304 int regulator_set_suspend_voltage(struct regulator *regulator, int min_uV,
0305 int max_uV, suspend_state_t state);
0306
0307
0308 void *regulator_get_drvdata(struct regulator *regulator);
0309 void regulator_set_drvdata(struct regulator *regulator, void *data);
0310
0311
0312
0313 void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
0314 const char *const *supply_names,
0315 unsigned int num_supplies);
0316
0317 bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2);
0318
0319 #else
0320
0321
0322
0323
0324
0325 static inline struct regulator *__must_check regulator_get(struct device *dev,
0326 const char *id)
0327 {
0328
0329
0330
0331
0332
0333
0334
0335
0336 return NULL;
0337 }
0338
0339 static inline struct regulator *__must_check
0340 devm_regulator_get(struct device *dev, const char *id)
0341 {
0342 return NULL;
0343 }
0344
0345 static inline struct regulator *__must_check
0346 regulator_get_exclusive(struct device *dev, const char *id)
0347 {
0348 return ERR_PTR(-ENODEV);
0349 }
0350
0351 static inline struct regulator *__must_check
0352 devm_regulator_get_exclusive(struct device *dev, const char *id)
0353 {
0354 return ERR_PTR(-ENODEV);
0355 }
0356
0357 static inline struct regulator *__must_check
0358 regulator_get_optional(struct device *dev, const char *id)
0359 {
0360 return ERR_PTR(-ENODEV);
0361 }
0362
0363
0364 static inline struct regulator *__must_check
0365 devm_regulator_get_optional(struct device *dev, const char *id)
0366 {
0367 return ERR_PTR(-ENODEV);
0368 }
0369
0370 static inline void regulator_put(struct regulator *regulator)
0371 {
0372 }
0373
0374 static inline void devm_regulator_put(struct regulator *regulator)
0375 {
0376 }
0377
0378 static inline int regulator_register_supply_alias(struct device *dev,
0379 const char *id,
0380 struct device *alias_dev,
0381 const char *alias_id)
0382 {
0383 return 0;
0384 }
0385
0386 static inline void regulator_unregister_supply_alias(struct device *dev,
0387 const char *id)
0388 {
0389 }
0390
0391 static inline int regulator_bulk_register_supply_alias(struct device *dev,
0392 const char *const *id,
0393 struct device *alias_dev,
0394 const char * const *alias_id,
0395 int num_id)
0396 {
0397 return 0;
0398 }
0399
0400 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
0401 const char * const *id,
0402 int num_id)
0403 {
0404 }
0405
0406 static inline int devm_regulator_register_supply_alias(struct device *dev,
0407 const char *id,
0408 struct device *alias_dev,
0409 const char *alias_id)
0410 {
0411 return 0;
0412 }
0413
0414 static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
0415 const char *const *id,
0416 struct device *alias_dev,
0417 const char *const *alias_id,
0418 int num_id)
0419 {
0420 return 0;
0421 }
0422
0423 static inline int regulator_enable(struct regulator *regulator)
0424 {
0425 return 0;
0426 }
0427
0428 static inline int regulator_disable(struct regulator *regulator)
0429 {
0430 return 0;
0431 }
0432
0433 static inline int regulator_force_disable(struct regulator *regulator)
0434 {
0435 return 0;
0436 }
0437
0438 static inline int regulator_disable_deferred(struct regulator *regulator,
0439 int ms)
0440 {
0441 return 0;
0442 }
0443
0444 static inline int regulator_is_enabled(struct regulator *regulator)
0445 {
0446 return 1;
0447 }
0448
0449 static inline int regulator_bulk_get(struct device *dev,
0450 int num_consumers,
0451 struct regulator_bulk_data *consumers)
0452 {
0453 return 0;
0454 }
0455
0456 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
0457 struct regulator_bulk_data *consumers)
0458 {
0459 return 0;
0460 }
0461
0462 static inline int regulator_bulk_enable(int num_consumers,
0463 struct regulator_bulk_data *consumers)
0464 {
0465 return 0;
0466 }
0467
0468 static inline int regulator_bulk_disable(int num_consumers,
0469 struct regulator_bulk_data *consumers)
0470 {
0471 return 0;
0472 }
0473
0474 static inline int regulator_bulk_force_disable(int num_consumers,
0475 struct regulator_bulk_data *consumers)
0476 {
0477 return 0;
0478 }
0479
0480 static inline void regulator_bulk_free(int num_consumers,
0481 struct regulator_bulk_data *consumers)
0482 {
0483 }
0484
0485 static inline int regulator_set_voltage(struct regulator *regulator,
0486 int min_uV, int max_uV)
0487 {
0488 return 0;
0489 }
0490
0491 static inline int regulator_set_voltage_time(struct regulator *regulator,
0492 int old_uV, int new_uV)
0493 {
0494 return 0;
0495 }
0496
0497 static inline int regulator_get_voltage(struct regulator *regulator)
0498 {
0499 return -EINVAL;
0500 }
0501
0502 static inline int regulator_sync_voltage(struct regulator *regulator)
0503 {
0504 return -EINVAL;
0505 }
0506
0507 static inline int regulator_is_supported_voltage(struct regulator *regulator,
0508 int min_uV, int max_uV)
0509 {
0510 return 0;
0511 }
0512
0513 static inline unsigned int regulator_get_linear_step(struct regulator *regulator)
0514 {
0515 return 0;
0516 }
0517
0518 static inline int regulator_set_current_limit(struct regulator *regulator,
0519 int min_uA, int max_uA)
0520 {
0521 return 0;
0522 }
0523
0524 static inline int regulator_get_current_limit(struct regulator *regulator)
0525 {
0526 return 0;
0527 }
0528
0529 static inline int regulator_set_mode(struct regulator *regulator,
0530 unsigned int mode)
0531 {
0532 return 0;
0533 }
0534
0535 static inline unsigned int regulator_get_mode(struct regulator *regulator)
0536 {
0537 return REGULATOR_MODE_NORMAL;
0538 }
0539
0540 static inline int regulator_get_error_flags(struct regulator *regulator,
0541 unsigned int *flags)
0542 {
0543 return -EINVAL;
0544 }
0545
0546 static inline int regulator_set_load(struct regulator *regulator, int load_uA)
0547 {
0548 return 0;
0549 }
0550
0551 static inline int regulator_allow_bypass(struct regulator *regulator,
0552 bool allow)
0553 {
0554 return 0;
0555 }
0556
0557 static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
0558 {
0559 return ERR_PTR(-EOPNOTSUPP);
0560 }
0561
0562 static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
0563 unsigned *vsel_reg,
0564 unsigned *vsel_mask)
0565 {
0566 return -EOPNOTSUPP;
0567 }
0568
0569 static inline int regulator_list_hardware_vsel(struct regulator *regulator,
0570 unsigned selector)
0571 {
0572 return -EOPNOTSUPP;
0573 }
0574
0575 static inline int regulator_register_notifier(struct regulator *regulator,
0576 struct notifier_block *nb)
0577 {
0578 return 0;
0579 }
0580
0581 static inline int devm_regulator_register_notifier(struct regulator *regulator,
0582 struct notifier_block *nb)
0583 {
0584 return 0;
0585 }
0586
0587 static inline int regulator_unregister_notifier(struct regulator *regulator,
0588 struct notifier_block *nb)
0589 {
0590 return 0;
0591 }
0592
0593 static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
0594 struct notifier_block *nb)
0595 {
0596 return 0;
0597 }
0598
0599 static inline int regulator_suspend_enable(struct regulator_dev *rdev,
0600 suspend_state_t state)
0601 {
0602 return -EINVAL;
0603 }
0604
0605 static inline int regulator_suspend_disable(struct regulator_dev *rdev,
0606 suspend_state_t state)
0607 {
0608 return -EINVAL;
0609 }
0610
0611 static inline int regulator_set_suspend_voltage(struct regulator *regulator,
0612 int min_uV, int max_uV,
0613 suspend_state_t state)
0614 {
0615 return -EINVAL;
0616 }
0617
0618 static inline void *regulator_get_drvdata(struct regulator *regulator)
0619 {
0620 return NULL;
0621 }
0622
0623 static inline void regulator_set_drvdata(struct regulator *regulator,
0624 void *data)
0625 {
0626 }
0627
0628 static inline int regulator_count_voltages(struct regulator *regulator)
0629 {
0630 return 0;
0631 }
0632
0633 static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector)
0634 {
0635 return -EINVAL;
0636 }
0637
0638 static inline void
0639 regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
0640 const char *const *supply_names,
0641 unsigned int num_supplies)
0642 {
0643 }
0644
0645 static inline bool
0646 regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
0647 {
0648 return false;
0649 }
0650 #endif
0651
0652 static inline int regulator_set_voltage_triplet(struct regulator *regulator,
0653 int min_uV, int target_uV,
0654 int max_uV)
0655 {
0656 if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
0657 return 0;
0658
0659 return regulator_set_voltage(regulator, min_uV, max_uV);
0660 }
0661
0662 static inline int regulator_set_voltage_tol(struct regulator *regulator,
0663 int new_uV, int tol_uV)
0664 {
0665 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
0666 return 0;
0667 else
0668 return regulator_set_voltage(regulator,
0669 new_uV - tol_uV, new_uV + tol_uV);
0670 }
0671
0672 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
0673 int target_uV, int tol_uV)
0674 {
0675 return regulator_is_supported_voltage(regulator,
0676 target_uV - tol_uV,
0677 target_uV + tol_uV);
0678 }
0679
0680 #endif