driver.h 10 KB

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