driver.h 7.8 KB

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