driver.h 13 KB

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