driver.h 12 KB

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