regulator.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2021, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef REGULATOR_H
  7. #define REGULATOR_H
  8. #include <platform_def.h>
  9. #ifndef PLAT_NB_RDEVS
  10. #error "Missing PLAT_NB_RDEVS"
  11. #endif
  12. /*
  13. * Consumer interface
  14. */
  15. /* regulator-always-on : regulator should never be disabled */
  16. #define REGUL_ALWAYS_ON BIT(0)
  17. /*
  18. * regulator-boot-on:
  19. * It's expected that this regulator was left on by the bootloader.
  20. * The core shouldn't prevent it from being turned off later.
  21. * The regulator is needed to exit from suspend so it is turned on during suspend entry.
  22. */
  23. #define REGUL_BOOT_ON BIT(1)
  24. /* regulator-over-current-protection: Enable over current protection. */
  25. #define REGUL_OCP BIT(2)
  26. /* regulator-active-discharge: enable active discharge. */
  27. #define REGUL_ACTIVE_DISCHARGE BIT(3)
  28. /* regulator-pull-down: Enable pull down resistor when the regulator is disabled. */
  29. #define REGUL_PULL_DOWN BIT(4)
  30. /*
  31. * st,mask-reset: set mask reset for the regulator, meaning that the regulator
  32. * setting is maintained during pmic reset.
  33. */
  34. #define REGUL_MASK_RESET BIT(5)
  35. /* st,regulator-sink-source: set the regulator in sink source mode */
  36. #define REGUL_SINK_SOURCE BIT(6)
  37. /* st,regulator-bypass: set the regulator in bypass mode */
  38. #define REGUL_ENABLE_BYPASS BIT(7)
  39. struct rdev *regulator_get_by_name(const char *node_name);
  40. struct rdev *regulator_get_by_supply_name(const void *fdt, int node, const char *name);
  41. int regulator_enable(struct rdev *rdev);
  42. int regulator_disable(struct rdev *rdev);
  43. int regulator_is_enabled(const struct rdev *rdev);
  44. int regulator_set_voltage(struct rdev *rdev, uint16_t volt);
  45. int regulator_set_min_voltage(struct rdev *rdev);
  46. int regulator_get_voltage(const struct rdev *rdev);
  47. int regulator_list_voltages(const struct rdev *rdev, const uint16_t **levels, size_t *count);
  48. void regulator_get_range(const struct rdev *rdev, uint16_t *min_mv, uint16_t *max_mv);
  49. int regulator_set_flag(struct rdev *rdev, uint16_t flag);
  50. /*
  51. * Driver Interface
  52. */
  53. /* set_state() arguments */
  54. #define STATE_DISABLE false
  55. #define STATE_ENABLE true
  56. struct regul_description {
  57. const char *node_name;
  58. const struct regul_ops *ops;
  59. const void *driver_data;
  60. const char *supply_name;
  61. const uint32_t enable_ramp_delay;
  62. };
  63. struct regul_ops {
  64. int (*set_state)(const struct regul_description *desc, bool state);
  65. int (*get_state)(const struct regul_description *desc);
  66. int (*set_voltage)(const struct regul_description *desc, uint16_t mv);
  67. int (*get_voltage)(const struct regul_description *desc);
  68. int (*list_voltages)(const struct regul_description *desc,
  69. const uint16_t **levels, size_t *count);
  70. int (*set_flag)(const struct regul_description *desc, uint16_t flag);
  71. void (*lock)(const struct regul_description *desc);
  72. void (*unlock)(const struct regul_description *desc);
  73. };
  74. int regulator_register(const struct regul_description *desc, int node);
  75. /*
  76. * Internal regulator structure
  77. * The structure is internal to the core, and the content should not be used
  78. * by a consumer nor a driver.
  79. */
  80. struct rdev {
  81. const struct regul_description *desc;
  82. int32_t phandle;
  83. uint16_t min_mv;
  84. uint16_t max_mv;
  85. uint16_t flags;
  86. uint32_t enable_ramp_delay;
  87. };
  88. #endif /* REGULATOR_H */