driver.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. * @ops: Regulator operations table.
  146. * @irq: Interrupt number for the regulator.
  147. * @type: Indicates if the regulator is a voltage or current regulator.
  148. * @owner: Module providing the regulator, used for refcounting.
  149. *
  150. * @n_voltages: Number of selectors available for ops.list_voltage().
  151. *
  152. * @min_uV: Voltage given by the lowest selector (if linear mapping)
  153. * @uV_step: Voltage increase with each selector (if linear mapping)
  154. * @ramp_delay: Time to settle down after voltage change (unit: mV/us)
  155. * @volt_table: Voltage mapping table (if table based mapping)
  156. *
  157. * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
  158. * @vsel_mask: Mask for register bitfield used for selector
  159. * @enable_reg: Register for control when using regmap enable/disable ops
  160. * @enable_mask: Mask for control when using regmap enable/disable ops
  161. */
  162. struct regulator_desc {
  163. const char *name;
  164. const char *supply_name;
  165. int id;
  166. unsigned n_voltages;
  167. struct regulator_ops *ops;
  168. int irq;
  169. enum regulator_type type;
  170. struct module *owner;
  171. unsigned int min_uV;
  172. unsigned int uV_step;
  173. unsigned int ramp_delay;
  174. const unsigned int *volt_table;
  175. unsigned int vsel_reg;
  176. unsigned int vsel_mask;
  177. unsigned int enable_reg;
  178. unsigned int enable_mask;
  179. };
  180. /**
  181. * struct regulator_config - Dynamic regulator descriptor
  182. *
  183. * Each regulator registered with the core is described with a
  184. * structure of this type and a struct regulator_desc. This structure
  185. * contains the runtime variable parts of the regulator description.
  186. *
  187. * @dev: struct device for the regulator
  188. * @init_data: platform provided init data, passed through by driver
  189. * @driver_data: private regulator data
  190. * @of_node: OpenFirmware node to parse for device tree bindings (may be
  191. * NULL).
  192. * @regmap: regmap to use for core regmap helpers
  193. */
  194. struct regulator_config {
  195. struct device *dev;
  196. const struct regulator_init_data *init_data;
  197. void *driver_data;
  198. struct device_node *of_node;
  199. struct regmap *regmap;
  200. };
  201. /*
  202. * struct regulator_dev
  203. *
  204. * Voltage / Current regulator class device. One for each
  205. * regulator.
  206. *
  207. * This should *not* be used directly by anything except the regulator
  208. * core and notification injection (which should take the mutex and do
  209. * no other direct access).
  210. */
  211. struct regulator_dev {
  212. const struct regulator_desc *desc;
  213. int exclusive;
  214. u32 use_count;
  215. u32 open_count;
  216. /* lists we belong to */
  217. struct list_head list; /* list of all regulators */
  218. /* lists we own */
  219. struct list_head consumer_list; /* consumers we supply */
  220. struct blocking_notifier_head notifier;
  221. struct mutex mutex; /* consumer lock */
  222. struct module *owner;
  223. struct device dev;
  224. struct regulation_constraints *constraints;
  225. struct regulator *supply; /* for tree */
  226. struct regmap *regmap;
  227. struct delayed_work disable_work;
  228. int deferred_disables;
  229. void *reg_data; /* regulator_dev data */
  230. struct dentry *debugfs;
  231. };
  232. struct regulator_dev *
  233. regulator_register(const struct regulator_desc *regulator_desc,
  234. const struct regulator_config *config);
  235. void regulator_unregister(struct regulator_dev *rdev);
  236. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  237. unsigned long event, void *data);
  238. void *rdev_get_drvdata(struct regulator_dev *rdev);
  239. struct device *rdev_get_dev(struct regulator_dev *rdev);
  240. int rdev_get_id(struct regulator_dev *rdev);
  241. int regulator_mode_to_status(unsigned int);
  242. int regulator_list_voltage_linear(struct regulator_dev *rdev,
  243. unsigned int selector);
  244. int regulator_list_voltage_table(struct regulator_dev *rdev,
  245. unsigned int selector);
  246. int regulator_map_voltage_linear(struct regulator_dev *rdev,
  247. int min_uV, int max_uV);
  248. int regulator_map_voltage_iterate(struct regulator_dev *rdev,
  249. int min_uV, int max_uV);
  250. int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
  251. int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
  252. int regulator_is_enabled_regmap(struct regulator_dev *rdev);
  253. int regulator_enable_regmap(struct regulator_dev *rdev);
  254. int regulator_disable_regmap(struct regulator_dev *rdev);
  255. int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  256. unsigned int old_selector,
  257. unsigned int new_selector);
  258. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
  259. #endif