driver.h 9.5 KB

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