driver.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * driver.h -- SoC Regulator driver support.
  3. *
  4. * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Regulator Driver Interface.
  13. */
  14. #ifndef __LINUX_REGULATOR_DRIVER_H_
  15. #define __LINUX_REGULATOR_DRIVER_H_
  16. #include <linux/device.h>
  17. #include <linux/regulator/consumer.h>
  18. struct regulator_dev;
  19. struct regulator_init_data;
  20. enum regulator_status {
  21. REGULATOR_STATUS_OFF,
  22. REGULATOR_STATUS_ON,
  23. REGULATOR_STATUS_ERROR,
  24. /* fast/normal/idle/standby are flavors of "on" */
  25. REGULATOR_STATUS_FAST,
  26. REGULATOR_STATUS_NORMAL,
  27. REGULATOR_STATUS_IDLE,
  28. REGULATOR_STATUS_STANDBY,
  29. };
  30. /**
  31. * struct regulator_ops - regulator operations.
  32. *
  33. * This struct describes regulator operations which can be implemented by
  34. * regulator chip drivers.
  35. *
  36. * @enable: Enable the regulator.
  37. * @disable: Disable the regulator.
  38. * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise.
  39. *
  40. * @set_voltage: Set the voltage for the regulator within the range specified.
  41. * The driver should select the voltage closest to min_uV.
  42. * @get_voltage: Return the currently configured voltage for the regulator.
  43. *
  44. * @set_current_limit: Configure a limit for a current-limited regulator.
  45. * @get_current_limit: Get the limit for a current-limited regulator.
  46. *
  47. * @set_mode: Set the operating mode for the regulator.
  48. * @get_mode: Get the current operating mode for the regulator.
  49. * @get_optimum_mode: Get the most efficient operating mode for the regulator
  50. * when running with the specified parameters.
  51. *
  52. * @set_suspend_voltage: Set the voltage for the regulator when the system
  53. * is suspended.
  54. * @set_suspend_enable: Mark the regulator as enabled when the system is
  55. * suspended.
  56. * @set_suspend_disable: Mark the regulator as disabled when the system is
  57. * suspended.
  58. * @set_suspend_mode: Set the operating mode for the regulator when the
  59. * system is suspended.
  60. */
  61. struct regulator_ops {
  62. /* get/set regulator voltage */
  63. int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV);
  64. int (*get_voltage) (struct regulator_dev *);
  65. /* get/set regulator current */
  66. int (*set_current_limit) (struct regulator_dev *,
  67. int min_uA, int max_uA);
  68. int (*get_current_limit) (struct regulator_dev *);
  69. /* enable/disable regulator */
  70. int (*enable) (struct regulator_dev *);
  71. int (*disable) (struct regulator_dev *);
  72. int (*is_enabled) (struct regulator_dev *);
  73. /* get/set regulator operating mode (defined in regulator.h) */
  74. int (*set_mode) (struct regulator_dev *, unsigned int mode);
  75. unsigned int (*get_mode) (struct regulator_dev *);
  76. /* report regulator status ... most other accessors report
  77. * control inputs, this reports results of combining inputs
  78. * from Linux (and other sources) with the actual load.
  79. */
  80. int (*get_status)(struct regulator_dev *);
  81. /* get most efficient regulator operating mode for load */
  82. unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
  83. int output_uV, int load_uA);
  84. /* the operations below are for configuration of regulator state when
  85. * its parent PMIC enters a global STANDBY/HIBERNATE state */
  86. /* set regulator suspend voltage */
  87. int (*set_suspend_voltage) (struct regulator_dev *, int uV);
  88. /* enable/disable regulator in suspend state */
  89. int (*set_suspend_enable) (struct regulator_dev *);
  90. int (*set_suspend_disable) (struct regulator_dev *);
  91. /* set regulator suspend operating mode (defined in regulator.h) */
  92. int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
  93. };
  94. /*
  95. * Regulators can either control voltage or current.
  96. */
  97. enum regulator_type {
  98. REGULATOR_VOLTAGE,
  99. REGULATOR_CURRENT,
  100. };
  101. /**
  102. * struct regulator_desc - Regulator descriptor
  103. *
  104. * Each regulator registered with the core is described with a structure of
  105. * this type.
  106. *
  107. * @name: Identifying name for the regulator.
  108. * @id: Numerical identifier for the regulator.
  109. * @ops: Regulator operations table.
  110. * @irq: Interrupt number for the regulator.
  111. * @type: Indicates if the regulator is a voltage or current regulator.
  112. * @owner: Module providing the regulator, used for refcounting.
  113. */
  114. struct regulator_desc {
  115. const char *name;
  116. int id;
  117. struct regulator_ops *ops;
  118. int irq;
  119. enum regulator_type type;
  120. struct module *owner;
  121. };
  122. /*
  123. * struct regulator_dev
  124. *
  125. * Voltage / Current regulator class device. One for each
  126. * regulator.
  127. *
  128. * This should *not* be used directly by anything except the regulator
  129. * core and notification injection (which should take the mutex and do
  130. * no other direct access).
  131. */
  132. struct regulator_dev {
  133. struct regulator_desc *desc;
  134. int use_count;
  135. /* lists we belong to */
  136. struct list_head list; /* list of all regulators */
  137. struct list_head slist; /* list of supplied regulators */
  138. /* lists we own */
  139. struct list_head consumer_list; /* consumers we supply */
  140. struct list_head supply_list; /* regulators we supply */
  141. struct blocking_notifier_head notifier;
  142. struct mutex mutex; /* consumer lock */
  143. struct module *owner;
  144. struct device dev;
  145. struct regulation_constraints *constraints;
  146. struct regulator_dev *supply; /* for tree */
  147. void *reg_data; /* regulator_dev data */
  148. };
  149. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  150. struct device *dev, struct regulator_init_data *init_data,
  151. void *driver_data);
  152. void regulator_unregister(struct regulator_dev *rdev);
  153. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  154. unsigned long event, void *data);
  155. void *rdev_get_drvdata(struct regulator_dev *rdev);
  156. struct device *rdev_get_dev(struct regulator_dev *rdev);
  157. int rdev_get_id(struct regulator_dev *rdev);
  158. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
  159. #endif