consumer.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ===================================
  2. Regulator Consumer Driver Interface
  3. ===================================
  4. This text describes the regulator interface for consumer device drivers.
  5. Please see overview.txt for a description of the terms used in this text.
  6. 1. Consumer Regulator Access (static & dynamic drivers)
  7. =======================================================
  8. A consumer driver can get access to its supply regulator by calling ::
  9. regulator = regulator_get(dev, "Vcc");
  10. The consumer passes in its struct device pointer and power supply ID. The core
  11. then finds the correct regulator by consulting a machine specific lookup table.
  12. If the lookup is successful then this call will return a pointer to the struct
  13. regulator that supplies this consumer.
  14. To release the regulator the consumer driver should call ::
  15. regulator_put(regulator);
  16. Consumers can be supplied by more than one regulator e.g. codec consumer with
  17. analog and digital supplies ::
  18. digital = regulator_get(dev, "Vcc"); /* digital core */
  19. analog = regulator_get(dev, "Avdd"); /* analog */
  20. The regulator access functions regulator_get() and regulator_put() will
  21. usually be called in your device drivers probe() and remove() respectively.
  22. 2. Regulator Output Enable & Disable (static & dynamic drivers)
  23. ===============================================================
  24. A consumer can enable its power supply by calling::
  25. int regulator_enable(regulator);
  26. NOTE:
  27. The supply may already be enabled before regulator_enabled() is called.
  28. This may happen if the consumer shares the regulator or the regulator has been
  29. previously enabled by bootloader or kernel board initialization code.
  30. A consumer can determine if a regulator is enabled by calling::
  31. int regulator_is_enabled(regulator);
  32. This will return > zero when the regulator is enabled.
  33. A consumer can disable its supply when no longer needed by calling::
  34. int regulator_disable(regulator);
  35. NOTE:
  36. This may not disable the supply if it's shared with other consumers. The
  37. regulator will only be disabled when the enabled reference count is zero.
  38. Finally, a regulator can be forcefully disabled in the case of an emergency::
  39. int regulator_force_disable(regulator);
  40. NOTE:
  41. this will immediately and forcefully shutdown the regulator output. All
  42. consumers will be powered off.
  43. 3. Regulator Voltage Control & Status (dynamic drivers)
  44. =======================================================
  45. Some consumer drivers need to be able to dynamically change their supply
  46. voltage to match system operating points. e.g. CPUfreq drivers can scale
  47. voltage along with frequency to save power, SD drivers may need to select the
  48. correct card voltage, etc.
  49. Consumers can control their supply voltage by calling::
  50. int regulator_set_voltage(regulator, min_uV, max_uV);
  51. Where min_uV and max_uV are the minimum and maximum acceptable voltages in
  52. microvolts.
  53. NOTE: this can be called when the regulator is enabled or disabled. If called
  54. when enabled, then the voltage changes instantly, otherwise the voltage
  55. configuration changes and the voltage is physically set when the regulator is
  56. next enabled.
  57. The regulators configured voltage output can be found by calling::
  58. int regulator_get_voltage(regulator);
  59. NOTE:
  60. get_voltage() will return the configured output voltage whether the
  61. regulator is enabled or disabled and should NOT be used to determine regulator
  62. output state. However this can be used in conjunction with is_enabled() to
  63. determine the regulator physical output voltage.
  64. 4. Regulator Current Limit Control & Status (dynamic drivers)
  65. =============================================================
  66. Some consumer drivers need to be able to dynamically change their supply
  67. current limit to match system operating points. e.g. LCD backlight driver can
  68. change the current limit to vary the backlight brightness, USB drivers may want
  69. to set the limit to 500mA when supplying power.
  70. Consumers can control their supply current limit by calling::
  71. int regulator_set_current_limit(regulator, min_uA, max_uA);
  72. Where min_uA and max_uA are the minimum and maximum acceptable current limit in
  73. microamps.
  74. NOTE:
  75. this can be called when the regulator is enabled or disabled. If called
  76. when enabled, then the current limit changes instantly, otherwise the current
  77. limit configuration changes and the current limit is physically set when the
  78. regulator is next enabled.
  79. A regulators current limit can be found by calling::
  80. int regulator_get_current_limit(regulator);
  81. NOTE:
  82. get_current_limit() will return the current limit whether the regulator
  83. is enabled or disabled and should not be used to determine regulator current
  84. load.
  85. 5. Regulator Operating Mode Control & Status (dynamic drivers)
  86. ==============================================================
  87. Some consumers can further save system power by changing the operating mode of
  88. their supply regulator to be more efficient when the consumers operating state
  89. changes. e.g. consumer driver is idle and subsequently draws less current
  90. Regulator operating mode can be changed indirectly or directly.
  91. Indirect operating mode control.
  92. --------------------------------
  93. Consumer drivers can request a change in their supply regulator operating mode
  94. by calling::
  95. int regulator_set_load(struct regulator *regulator, int load_uA);
  96. This will cause the core to recalculate the total load on the regulator (based
  97. on all its consumers) and change operating mode (if necessary and permitted)
  98. to best match the current operating load.
  99. The load_uA value can be determined from the consumer's datasheet. e.g. most
  100. datasheets have tables showing the maximum current consumed in certain
  101. situations.
  102. Most consumers will use indirect operating mode control since they have no
  103. knowledge of the regulator or whether the regulator is shared with other
  104. consumers.
  105. Direct operating mode control.
  106. ------------------------------
  107. Bespoke or tightly coupled drivers may want to directly control regulator
  108. operating mode depending on their operating point. This can be achieved by
  109. calling::
  110. int regulator_set_mode(struct regulator *regulator, unsigned int mode);
  111. unsigned int regulator_get_mode(struct regulator *regulator);
  112. Direct mode will only be used by consumers that *know* about the regulator and
  113. are not sharing the regulator with other consumers.
  114. 6. Regulator Events
  115. ===================
  116. Regulators can notify consumers of external events. Events could be received by
  117. consumers under regulator stress or failure conditions.
  118. Consumers can register interest in regulator events by calling::
  119. int regulator_register_notifier(struct regulator *regulator,
  120. struct notifier_block *nb);
  121. Consumers can unregister interest by calling::
  122. int regulator_unregister_notifier(struct regulator *regulator,
  123. struct notifier_block *nb);
  124. Regulators use the kernel notifier framework to send event to their interested
  125. consumers.
  126. 7. Regulator Direct Register Access
  127. ===================================
  128. Some kinds of power management hardware or firmware are designed such that
  129. they need to do low-level hardware access to regulators, with no involvement
  130. from the kernel. Examples of such devices are:
  131. - clocksource with a voltage-controlled oscillator and control logic to change
  132. the supply voltage over I2C to achieve a desired output clock rate
  133. - thermal management firmware that can issue an arbitrary I2C transaction to
  134. perform system poweroff during overtemperature conditions
  135. To set up such a device/firmware, various parameters like I2C address of the
  136. regulator, addresses of various regulator registers etc. need to be configured
  137. to it. The regulator framework provides the following helpers for querying
  138. these details.
  139. Bus-specific details, like I2C addresses or transfer rates are handled by the
  140. regmap framework. To get the regulator's regmap (if supported), use::
  141. struct regmap *regulator_get_regmap(struct regulator *regulator);
  142. To obtain the hardware register offset and bitmask for the regulator's voltage
  143. selector register, use::
  144. int regulator_get_hardware_vsel_register(struct regulator *regulator,
  145. unsigned *vsel_reg,
  146. unsigned *vsel_mask);
  147. To convert a regulator framework voltage selector code (used by
  148. regulator_list_voltage) to a hardware-specific voltage selector that can be
  149. directly written to the voltage selector register, use::
  150. int regulator_list_hardware_vsel(struct regulator *regulator,
  151. unsigned selector);