driver.h 11 KB

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