driver.h 7.6 KB

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