driver.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * driver.h -- SoC Regulator driver support.
  3. *
  4. * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  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. * @enable: Configure the regulator as enabled.
  34. * @disable: Configure the regulator as disabled.
  35. * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
  36. * May also return negative errno.
  37. *
  38. * @set_voltage: Set the voltage for the regulator within the range specified.
  39. * The driver should select the voltage closest to min_uV.
  40. * @get_voltage: Return the currently configured voltage for the regulator.
  41. * @list_voltage: Return one of the supported voltages, in microvolts; zero
  42. * if the selector indicates a voltage that is unusable on this system;
  43. * or negative errno. Selectors range from zero to one less than
  44. * regulator_desc.n_voltages. Voltages may be reported in any order.
  45. *
  46. * @set_current_limit: Configure a limit for a current-limited regulator.
  47. * @get_current_limit: Get the configured limit for a current-limited regulator.
  48. *
  49. * @set_mode: Set the configured operating mode for the regulator.
  50. * @get_mode: Get the configured operating mode for the regulator.
  51. * @get_status: Return actual (not as-configured) status of regulator, as a
  52. * REGULATOR_STATUS value (or negative errno)
  53. * @get_optimum_mode: Get the most efficient operating mode for the regulator
  54. * when running with the specified parameters.
  55. *
  56. * @enable_time: Time taken for the regulator voltage output voltage to
  57. * stabalise after being enabled, in microseconds.
  58. *
  59. * @set_suspend_voltage: Set the voltage for the regulator when the system
  60. * is suspended.
  61. * @set_suspend_enable: Mark the regulator as enabled when the system is
  62. * suspended.
  63. * @set_suspend_disable: Mark the regulator as disabled when the system is
  64. * suspended.
  65. * @set_suspend_mode: Set the operating mode for the regulator when the
  66. * system is suspended.
  67. *
  68. * This struct describes regulator operations which can be implemented by
  69. * regulator chip drivers.
  70. */
  71. struct regulator_ops {
  72. /* enumerate supported voltages */
  73. int (*list_voltage) (struct regulator_dev *, unsigned selector);
  74. /* get/set regulator voltage */
  75. int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
  76. unsigned *selector);
  77. int (*get_voltage) (struct regulator_dev *);
  78. /* get/set regulator current */
  79. int (*set_current_limit) (struct regulator_dev *,
  80. int min_uA, int max_uA);
  81. int (*get_current_limit) (struct regulator_dev *);
  82. /* enable/disable regulator */
  83. int (*enable) (struct regulator_dev *);
  84. int (*disable) (struct regulator_dev *);
  85. int (*is_enabled) (struct regulator_dev *);
  86. /* get/set regulator operating mode (defined in regulator.h) */
  87. int (*set_mode) (struct regulator_dev *, unsigned int mode);
  88. unsigned int (*get_mode) (struct regulator_dev *);
  89. /* Time taken to enable the regulator */
  90. int (*enable_time) (struct regulator_dev *);
  91. /* report regulator status ... most other accessors report
  92. * control inputs, this reports results of combining inputs
  93. * from Linux (and other sources) with the actual load.
  94. * returns REGULATOR_STATUS_* or negative errno.
  95. */
  96. int (*get_status)(struct regulator_dev *);
  97. /* get most efficient regulator operating mode for load */
  98. unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
  99. int output_uV, int load_uA);
  100. /* the operations below are for configuration of regulator state when
  101. * its parent PMIC enters a global STANDBY/HIBERNATE state */
  102. /* set regulator suspend voltage */
  103. int (*set_suspend_voltage) (struct regulator_dev *, int uV);
  104. /* enable/disable regulator in suspend state */
  105. int (*set_suspend_enable) (struct regulator_dev *);
  106. int (*set_suspend_disable) (struct regulator_dev *);
  107. /* set regulator suspend operating mode (defined in regulator.h) */
  108. int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
  109. };
  110. /*
  111. * Regulators can either control voltage or current.
  112. */
  113. enum regulator_type {
  114. REGULATOR_VOLTAGE,
  115. REGULATOR_CURRENT,
  116. };
  117. /**
  118. * struct regulator_desc - Regulator descriptor
  119. *
  120. * Each regulator registered with the core is described with a structure of
  121. * this type.
  122. *
  123. * @name: Identifying name for the regulator.
  124. * @id: Numerical identifier for the regulator.
  125. * @n_voltages: Number of selectors available for ops.list_voltage().
  126. * @ops: Regulator operations table.
  127. * @irq: Interrupt number for the regulator.
  128. * @type: Indicates if the regulator is a voltage or current regulator.
  129. * @owner: Module providing the regulator, used for refcounting.
  130. */
  131. struct regulator_desc {
  132. const char *name;
  133. int id;
  134. unsigned n_voltages;
  135. struct regulator_ops *ops;
  136. int irq;
  137. enum regulator_type type;
  138. struct module *owner;
  139. };
  140. /*
  141. * struct regulator_dev
  142. *
  143. * Voltage / Current regulator class device. One for each
  144. * regulator.
  145. *
  146. * This should *not* be used directly by anything except the regulator
  147. * core and notification injection (which should take the mutex and do
  148. * no other direct access).
  149. */
  150. struct regulator_dev {
  151. struct regulator_desc *desc;
  152. int use_count;
  153. int open_count;
  154. int exclusive;
  155. /* lists we belong to */
  156. struct list_head list; /* list of all regulators */
  157. struct list_head slist; /* list of supplied regulators */
  158. /* lists we own */
  159. struct list_head consumer_list; /* consumers we supply */
  160. struct list_head supply_list; /* regulators we supply */
  161. struct blocking_notifier_head notifier;
  162. struct mutex mutex; /* consumer lock */
  163. struct module *owner;
  164. struct device dev;
  165. struct regulation_constraints *constraints;
  166. struct regulator_dev *supply; /* for tree */
  167. void *reg_data; /* regulator_dev data */
  168. };
  169. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  170. struct device *dev, struct regulator_init_data *init_data,
  171. void *driver_data);
  172. void regulator_unregister(struct regulator_dev *rdev);
  173. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  174. unsigned long event, void *data);
  175. void *rdev_get_drvdata(struct regulator_dev *rdev);
  176. struct device *rdev_get_dev(struct regulator_dev *rdev);
  177. int rdev_get_id(struct regulator_dev *rdev);
  178. int regulator_mode_to_status(unsigned int);
  179. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
  180. #endif