driver.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. int (*get_voltage) (struct regulator_dev *);
  77. /* get/set regulator current */
  78. int (*set_current_limit) (struct regulator_dev *,
  79. int min_uA, int max_uA);
  80. int (*get_current_limit) (struct regulator_dev *);
  81. /* enable/disable regulator */
  82. int (*enable) (struct regulator_dev *);
  83. int (*disable) (struct regulator_dev *);
  84. int (*is_enabled) (struct regulator_dev *);
  85. /* get/set regulator operating mode (defined in regulator.h) */
  86. int (*set_mode) (struct regulator_dev *, unsigned int mode);
  87. unsigned int (*get_mode) (struct regulator_dev *);
  88. /* Time taken to enable the regulator */
  89. int (*enable_time) (struct regulator_dev *);
  90. /* report regulator status ... most other accessors report
  91. * control inputs, this reports results of combining inputs
  92. * from Linux (and other sources) with the actual load.
  93. * returns REGULATOR_STATUS_* or negative errno.
  94. */
  95. int (*get_status)(struct regulator_dev *);
  96. /* get most efficient regulator operating mode for load */
  97. unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
  98. int output_uV, int load_uA);
  99. /* the operations below are for configuration of regulator state when
  100. * its parent PMIC enters a global STANDBY/HIBERNATE state */
  101. /* set regulator suspend voltage */
  102. int (*set_suspend_voltage) (struct regulator_dev *, int uV);
  103. /* enable/disable regulator in suspend state */
  104. int (*set_suspend_enable) (struct regulator_dev *);
  105. int (*set_suspend_disable) (struct regulator_dev *);
  106. /* set regulator suspend operating mode (defined in regulator.h) */
  107. int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
  108. };
  109. /*
  110. * Regulators can either control voltage or current.
  111. */
  112. enum regulator_type {
  113. REGULATOR_VOLTAGE,
  114. REGULATOR_CURRENT,
  115. };
  116. /**
  117. * struct regulator_desc - Regulator descriptor
  118. *
  119. * Each regulator registered with the core is described with a structure of
  120. * this type.
  121. *
  122. * @name: Identifying name for the regulator.
  123. * @id: Numerical identifier for the regulator.
  124. * @n_voltages: Number of selectors available for ops.list_voltage().
  125. * @ops: Regulator operations table.
  126. * @irq: Interrupt number for the regulator.
  127. * @type: Indicates if the regulator is a voltage or current regulator.
  128. * @owner: Module providing the regulator, used for refcounting.
  129. */
  130. struct regulator_desc {
  131. const char *name;
  132. int id;
  133. unsigned n_voltages;
  134. struct regulator_ops *ops;
  135. int irq;
  136. enum regulator_type type;
  137. struct module *owner;
  138. };
  139. /*
  140. * struct regulator_dev
  141. *
  142. * Voltage / Current regulator class device. One for each
  143. * regulator.
  144. *
  145. * This should *not* be used directly by anything except the regulator
  146. * core and notification injection (which should take the mutex and do
  147. * no other direct access).
  148. */
  149. struct regulator_dev {
  150. struct regulator_desc *desc;
  151. int use_count;
  152. int open_count;
  153. int exclusive;
  154. /* lists we belong to */
  155. struct list_head list; /* list of all regulators */
  156. struct list_head slist; /* list of supplied regulators */
  157. /* lists we own */
  158. struct list_head consumer_list; /* consumers we supply */
  159. struct list_head supply_list; /* regulators we supply */
  160. struct blocking_notifier_head notifier;
  161. struct mutex mutex; /* consumer lock */
  162. struct module *owner;
  163. struct device dev;
  164. struct regulation_constraints *constraints;
  165. struct regulator_dev *supply; /* for tree */
  166. void *reg_data; /* regulator_dev data */
  167. };
  168. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  169. struct device *dev, struct regulator_init_data *init_data,
  170. void *driver_data);
  171. void regulator_unregister(struct regulator_dev *rdev);
  172. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  173. unsigned long event, void *data);
  174. void *rdev_get_drvdata(struct regulator_dev *rdev);
  175. struct device *rdev_get_dev(struct regulator_dev *rdev);
  176. int rdev_get_id(struct regulator_dev *rdev);
  177. int regulator_mode_to_status(unsigned int);
  178. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
  179. #endif