coupler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * coupler.h -- SoC Regulator support, coupler API.
  4. *
  5. * Regulator Coupler Interface.
  6. */
  7. #ifndef __LINUX_REGULATOR_COUPLER_H_
  8. #define __LINUX_REGULATOR_COUPLER_H_
  9. #include <linux/kernel.h>
  10. #include <linux/suspend.h>
  11. struct regulator_coupler;
  12. struct regulator_dev;
  13. /**
  14. * struct regulator_coupler - customized regulator's coupler
  15. *
  16. * Regulator's coupler allows to customize coupling algorithm.
  17. *
  18. * @list: couplers list entry
  19. * @attach_regulator: Callback invoked on creation of a coupled regulator,
  20. * couples are unresolved at this point. The callee should
  21. * check that it could handle the regulator and return 0 on
  22. * success, -errno on failure and 1 if given regulator is
  23. * not suitable for this coupler (case of having multiple
  24. * regulators in a system). Callback shall be implemented.
  25. * @detach_regulator: Callback invoked on destruction of a coupled regulator.
  26. * This callback is optional and could be NULL.
  27. * @balance_voltage: Callback invoked when voltage of a coupled regulator is
  28. * changing. Called with all of the coupled rdev's being held
  29. * under "consumer lock". The callee should perform voltage
  30. * balancing, changing voltage of the coupled regulators as
  31. * needed. It's up to the coupler to verify the voltage
  32. * before changing it in hardware, i.e. coupler should
  33. * check consumer's min/max and etc. This callback is
  34. * optional and could be NULL, in which case a generic
  35. * voltage balancer will be used.
  36. */
  37. struct regulator_coupler {
  38. struct list_head list;
  39. int (*attach_regulator)(struct regulator_coupler *coupler,
  40. struct regulator_dev *rdev);
  41. int (*detach_regulator)(struct regulator_coupler *coupler,
  42. struct regulator_dev *rdev);
  43. int (*balance_voltage)(struct regulator_coupler *coupler,
  44. struct regulator_dev *rdev,
  45. suspend_state_t state);
  46. };
  47. #ifdef CONFIG_REGULATOR
  48. int regulator_coupler_register(struct regulator_coupler *coupler);
  49. const char *rdev_get_name(struct regulator_dev *rdev);
  50. int regulator_check_consumers(struct regulator_dev *rdev,
  51. int *min_uV, int *max_uV,
  52. suspend_state_t state);
  53. int regulator_check_voltage(struct regulator_dev *rdev,
  54. int *min_uV, int *max_uV);
  55. int regulator_get_voltage_rdev(struct regulator_dev *rdev);
  56. int regulator_set_voltage_rdev(struct regulator_dev *rdev,
  57. int min_uV, int max_uV,
  58. suspend_state_t state);
  59. int regulator_do_balance_voltage(struct regulator_dev *rdev,
  60. suspend_state_t state, bool skip_coupled);
  61. #else
  62. static inline int regulator_coupler_register(struct regulator_coupler *coupler)
  63. {
  64. return 0;
  65. }
  66. static inline const char *rdev_get_name(struct regulator_dev *rdev)
  67. {
  68. return NULL;
  69. }
  70. static inline int regulator_check_consumers(struct regulator_dev *rdev,
  71. int *min_uV, int *max_uV,
  72. suspend_state_t state)
  73. {
  74. return -EINVAL;
  75. }
  76. static inline int regulator_check_voltage(struct regulator_dev *rdev,
  77. int *min_uV, int *max_uV)
  78. {
  79. return -EINVAL;
  80. }
  81. static inline int regulator_get_voltage_rdev(struct regulator_dev *rdev)
  82. {
  83. return -EINVAL;
  84. }
  85. static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
  86. int min_uV, int max_uV,
  87. suspend_state_t state)
  88. {
  89. return -EINVAL;
  90. }
  91. static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
  92. suspend_state_t state,
  93. bool skip_coupled)
  94. {
  95. return -EINVAL;
  96. }
  97. #endif
  98. #endif