internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * internal.h -- Voltage/Current Regulator framework internal code
  4. *
  5. * Copyright 2007, 2008 Wolfson Microelectronics PLC.
  6. * Copyright 2008 SlimLogic Ltd.
  7. *
  8. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  9. */
  10. #ifndef __REGULATOR_INTERNAL_H
  11. #define __REGULATOR_INTERNAL_H
  12. #include <linux/suspend.h>
  13. #define REGULATOR_STATES_NUM (PM_SUSPEND_MAX + 1)
  14. #define rdev_crit(rdev, fmt, ...) \
  15. pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
  16. #define rdev_err(rdev, fmt, ...) \
  17. pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
  18. #define rdev_warn(rdev, fmt, ...) \
  19. pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
  20. #define rdev_info(rdev, fmt, ...) \
  21. pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
  22. #define rdev_dbg(rdev, fmt, ...) \
  23. pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
  24. struct regulator_voltage {
  25. int min_uV;
  26. int max_uV;
  27. };
  28. /*
  29. * struct regulator
  30. *
  31. * One for each consumer device.
  32. * @voltage - a voltage array for each state of runtime, i.e.:
  33. * PM_SUSPEND_ON
  34. * PM_SUSPEND_TO_IDLE
  35. * PM_SUSPEND_STANDBY
  36. * PM_SUSPEND_MEM
  37. * PM_SUSPEND_MAX
  38. */
  39. struct regulator {
  40. struct device *dev;
  41. struct list_head list;
  42. unsigned int always_on:1;
  43. unsigned int bypass:1;
  44. unsigned int device_link:1;
  45. int uA_load;
  46. unsigned int enable_count;
  47. unsigned int deferred_disables;
  48. struct regulator_voltage voltage[REGULATOR_STATES_NUM];
  49. const char *supply_name;
  50. struct device_attribute dev_attr;
  51. struct regulator_dev *rdev;
  52. struct dentry *debugfs;
  53. };
  54. extern const struct class regulator_class;
  55. static inline struct regulator_dev *dev_to_rdev(struct device *dev)
  56. {
  57. return container_of(dev, struct regulator_dev, dev);
  58. }
  59. #ifdef CONFIG_OF
  60. struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
  61. const char *supply);
  62. struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
  63. const struct regulator_desc *desc,
  64. struct regulator_config *config,
  65. struct device_node **node);
  66. struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
  67. int index);
  68. int of_get_n_coupled(struct regulator_dev *rdev);
  69. bool of_check_coupling_data(struct regulator_dev *rdev);
  70. #else
  71. static inline struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
  72. const char *supply)
  73. {
  74. return ERR_PTR(-ENODEV);
  75. }
  76. static inline struct regulator_init_data *
  77. regulator_of_get_init_data(struct device *dev,
  78. const struct regulator_desc *desc,
  79. struct regulator_config *config,
  80. struct device_node **node)
  81. {
  82. return NULL;
  83. }
  84. static inline struct regulator_dev *
  85. of_parse_coupled_regulator(struct regulator_dev *rdev,
  86. int index)
  87. {
  88. return NULL;
  89. }
  90. static inline int of_get_n_coupled(struct regulator_dev *rdev)
  91. {
  92. return 0;
  93. }
  94. static inline bool of_check_coupling_data(struct regulator_dev *rdev)
  95. {
  96. return false;
  97. }
  98. #endif
  99. enum regulator_get_type {
  100. NORMAL_GET,
  101. EXCLUSIVE_GET,
  102. OPTIONAL_GET,
  103. MAX_GET_TYPE
  104. };
  105. int _regulator_get_common_check(struct device *dev, const char *id,
  106. enum regulator_get_type get_type);
  107. struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev,
  108. const char *id, enum regulator_get_type get_type);
  109. struct regulator *_regulator_get(struct device *dev, const char *id,
  110. enum regulator_get_type get_type);
  111. int _regulator_bulk_get(struct device *dev, int num_consumers,
  112. struct regulator_bulk_data *consumers, enum regulator_get_type get_type);
  113. #endif