driver.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/regulator/consumer.h>
  18. struct regulator_dev;
  19. struct regulator_init_data;
  20. enum regulator_status {
  21. REGULATOR_STATUS_OFF,
  22. REGULATOR_STATUS_ON,
  23. REGULATOR_STATUS_ERROR,
  24. /* fast/normal/idle/standby are flavors of "on" */
  25. REGULATOR_STATUS_FAST,
  26. REGULATOR_STATUS_NORMAL,
  27. REGULATOR_STATUS_IDLE,
  28. REGULATOR_STATUS_STANDBY,
  29. };
  30. /**
  31. * struct regulator_ops - regulator operations.
  32. *
  33. * @enable: Configure the regulator as enabled.
  34. * @disable: Configure the regulator as disabled.
  35. * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise.
  36. *
  37. * @set_voltage: Set the voltage for the regulator within the range specified.
  38. * The driver should select the voltage closest to min_uV.
  39. * @get_voltage: Return the currently configured voltage for the regulator.
  40. * @list_voltage: Return one of the supported voltages, in microvolts; zero
  41. * if the selector indicates a voltage that is unusable on this system;
  42. * or negative errno. Selectors range from zero to one less than
  43. * regulator_desc.n_voltages. Voltages may be reported in any order.
  44. *
  45. * @set_current_limit: Configure a limit for a current-limited regulator.
  46. * @get_current_limit: Get the configured limit for a current-limited regulator.
  47. *
  48. * @set_mode: Set the configured operating mode for the regulator.
  49. * @get_mode: Get the configured operating mode for the regulator.
  50. * @get_status: Return actual (not as-configured) status of regulator, as a
  51. * REGULATOR_STATUS value (or negative errno)
  52. * @get_optimum_mode: Get the most efficient operating mode for the regulator
  53. * when running with the specified parameters.
  54. *
  55. * @set_suspend_voltage: Set the voltage for the regulator when the system
  56. * is suspended.
  57. * @set_suspend_enable: Mark the regulator as enabled when the system is
  58. * suspended.
  59. * @set_suspend_disable: Mark the regulator as disabled when the system is
  60. * suspended.
  61. * @set_suspend_mode: Set the operating mode for the regulator when the
  62. * system is suspended.
  63. *
  64. * This struct describes regulator operations which can be implemented by
  65. * regulator chip drivers.
  66. */
  67. struct regulator_ops {
  68. /* enumerate supported voltages */
  69. int (*list_voltage) (struct regulator_dev *, unsigned selector);
  70. /* get/set regulator voltage */
  71. int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV);
  72. int (*get_voltage) (struct regulator_dev *);
  73. /* get/set regulator current */
  74. int (*set_current_limit) (struct regulator_dev *,
  75. int min_uA, int max_uA);
  76. int (*get_current_limit) (struct regulator_dev *);
  77. /* enable/disable regulator */
  78. int (*enable) (struct regulator_dev *);
  79. int (*disable) (struct regulator_dev *);
  80. int (*is_enabled) (struct regulator_dev *);
  81. /* get/set regulator operating mode (defined in regulator.h) */
  82. int (*set_mode) (struct regulator_dev *, unsigned int mode);
  83. unsigned int (*get_mode) (struct regulator_dev *);
  84. /* report regulator status ... most other accessors report
  85. * control inputs, this reports results of combining inputs
  86. * from Linux (and other sources) with the actual load.
  87. * returns REGULATOR_STATUS_* or negative errno.
  88. */
  89. int (*get_status)(struct regulator_dev *);
  90. /* get most efficient regulator operating mode for load */
  91. unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
  92. int output_uV, int load_uA);
  93. /* the operations below are for configuration of regulator state when
  94. * its parent PMIC enters a global STANDBY/HIBERNATE state */
  95. /* set regulator suspend voltage */
  96. int (*set_suspend_voltage) (struct regulator_dev *, int uV);
  97. /* enable/disable regulator in suspend state */
  98. int (*set_suspend_enable) (struct regulator_dev *);
  99. int (*set_suspend_disable) (struct regulator_dev *);
  100. /* set regulator suspend operating mode (defined in regulator.h) */
  101. int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
  102. };
  103. /*
  104. * Regulators can either control voltage or current.
  105. */
  106. enum regulator_type {
  107. REGULATOR_VOLTAGE,
  108. REGULATOR_CURRENT,
  109. };
  110. /**
  111. * struct regulator_desc - Regulator descriptor
  112. *
  113. * Each regulator registered with the core is described with a structure of
  114. * this type.
  115. *
  116. * @name: Identifying name for the regulator.
  117. * @id: Numerical identifier for the regulator.
  118. * @n_voltages: Number of selectors available for ops.list_voltage().
  119. * @ops: Regulator operations table.
  120. * @irq: Interrupt number for the regulator.
  121. * @type: Indicates if the regulator is a voltage or current regulator.
  122. * @owner: Module providing the regulator, used for refcounting.
  123. */
  124. struct regulator_desc {
  125. const char *name;
  126. int id;
  127. unsigned n_voltages;
  128. struct regulator_ops *ops;
  129. int irq;
  130. enum regulator_type type;
  131. struct module *owner;
  132. };
  133. /*
  134. * struct regulator_dev
  135. *
  136. * Voltage / Current regulator class device. One for each
  137. * regulator.
  138. *
  139. * This should *not* be used directly by anything except the regulator
  140. * core and notification injection (which should take the mutex and do
  141. * no other direct access).
  142. */
  143. struct regulator_dev {
  144. struct regulator_desc *desc;
  145. int use_count;
  146. /* lists we belong to */
  147. struct list_head list; /* list of all regulators */
  148. struct list_head slist; /* list of supplied regulators */
  149. /* lists we own */
  150. struct list_head consumer_list; /* consumers we supply */
  151. struct list_head supply_list; /* regulators we supply */
  152. struct blocking_notifier_head notifier;
  153. struct mutex mutex; /* consumer lock */
  154. struct module *owner;
  155. struct device dev;
  156. struct regulation_constraints *constraints;
  157. struct regulator_dev *supply; /* for tree */
  158. void *reg_data; /* regulator_dev data */
  159. };
  160. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  161. struct device *dev, struct regulator_init_data *init_data,
  162. void *driver_data);
  163. void regulator_unregister(struct regulator_dev *rdev);
  164. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  165. unsigned long event, void *data);
  166. void *rdev_get_drvdata(struct regulator_dev *rdev);
  167. struct device *rdev_get_dev(struct regulator_dev *rdev);
  168. int rdev_get_id(struct regulator_dev *rdev);
  169. int regulator_mode_to_status(unsigned int);
  170. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
  171. #endif