driver.h 9.3 KB

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