internal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <[email protected]>
  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 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_find_regulator_by_node(struct device_node *np);
  61. struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
  62. const struct regulator_desc *desc,
  63. struct regulator_config *config,
  64. struct device_node **node);
  65. struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
  66. int index);
  67. int of_get_n_coupled(struct regulator_dev *rdev);
  68. bool of_check_coupling_data(struct regulator_dev *rdev);
  69. #else
  70. static inline struct regulator_dev *
  71. of_find_regulator_by_node(struct device_node *np)
  72. {
  73. return NULL;
  74. }
  75. static inline struct regulator_init_data *
  76. regulator_of_get_init_data(struct device *dev,
  77. const struct regulator_desc *desc,
  78. struct regulator_config *config,
  79. struct device_node **node)
  80. {
  81. return NULL;
  82. }
  83. static inline struct regulator_dev *
  84. of_parse_coupled_regulator(struct regulator_dev *rdev,
  85. int index)
  86. {
  87. return NULL;
  88. }
  89. static inline int of_get_n_coupled(struct regulator_dev *rdev)
  90. {
  91. return 0;
  92. }
  93. static inline bool of_check_coupling_data(struct regulator_dev *rdev)
  94. {
  95. return false;
  96. }
  97. #endif
  98. enum regulator_get_type {
  99. NORMAL_GET,
  100. EXCLUSIVE_GET,
  101. OPTIONAL_GET,
  102. MAX_GET_TYPE
  103. };
  104. struct regulator *_regulator_get(struct device *dev, const char *id,
  105. enum regulator_get_type get_type);
  106. #endif