driver.h 6.4 KB

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