consumer.txt 8.2 KB

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