Back to home page

OSCL-LXR

 
 

    


0001 ===================================
0002 Regulator Consumer Driver Interface
0003 ===================================
0004 
0005 This text describes the regulator interface for consumer device drivers.
0006 Please see overview.txt for a description of the terms used in this text.
0007 
0008 
0009 1. Consumer Regulator Access (static & dynamic drivers)
0010 =======================================================
0011 
0012 A consumer driver can get access to its supply regulator by calling ::
0013 
0014         regulator = regulator_get(dev, "Vcc");
0015 
0016 The consumer passes in its struct device pointer and power supply ID. The core
0017 then finds the correct regulator by consulting a machine specific lookup table.
0018 If the lookup is successful then this call will return a pointer to the struct
0019 regulator that supplies this consumer.
0020 
0021 To release the regulator the consumer driver should call ::
0022 
0023         regulator_put(regulator);
0024 
0025 Consumers can be supplied by more than one regulator e.g. codec consumer with
0026 analog and digital supplies ::
0027 
0028         digital = regulator_get(dev, "Vcc");  /* digital core */
0029         analog = regulator_get(dev, "Avdd");  /* analog */
0030 
0031 The regulator access functions regulator_get() and regulator_put() will
0032 usually be called in your device drivers probe() and remove() respectively.
0033 
0034 
0035 2. Regulator Output Enable & Disable (static & dynamic drivers)
0036 ===============================================================
0037 
0038 
0039 A consumer can enable its power supply by calling::
0040 
0041         int regulator_enable(regulator);
0042 
0043 NOTE:
0044   The supply may already be enabled before regulator_enabled() is called.
0045   This may happen if the consumer shares the regulator or the regulator has been
0046   previously enabled by bootloader or kernel board initialization code.
0047 
0048 A consumer can determine if a regulator is enabled by calling::
0049 
0050         int regulator_is_enabled(regulator);
0051 
0052 This will return > zero when the regulator is enabled.
0053 
0054 
0055 A consumer can disable its supply when no longer needed by calling::
0056 
0057         int regulator_disable(regulator);
0058 
0059 NOTE:
0060   This may not disable the supply if it's shared with other consumers. The
0061   regulator will only be disabled when the enabled reference count is zero.
0062 
0063 Finally, a regulator can be forcefully disabled in the case of an emergency::
0064 
0065         int regulator_force_disable(regulator);
0066 
0067 NOTE:
0068   this will immediately and forcefully shutdown the regulator output. All
0069   consumers will be powered off.
0070 
0071 
0072 3. Regulator Voltage Control & Status (dynamic drivers)
0073 =======================================================
0074 
0075 Some consumer drivers need to be able to dynamically change their supply
0076 voltage to match system operating points. e.g. CPUfreq drivers can scale
0077 voltage along with frequency to save power, SD drivers may need to select the
0078 correct card voltage, etc.
0079 
0080 Consumers can control their supply voltage by calling::
0081 
0082         int regulator_set_voltage(regulator, min_uV, max_uV);
0083 
0084 Where min_uV and max_uV are the minimum and maximum acceptable voltages in
0085 microvolts.
0086 
0087 NOTE: this can be called when the regulator is enabled or disabled. If called
0088 when enabled, then the voltage changes instantly, otherwise the voltage
0089 configuration changes and the voltage is physically set when the regulator is
0090 next enabled.
0091 
0092 The regulators configured voltage output can be found by calling::
0093 
0094         int regulator_get_voltage(regulator);
0095 
0096 NOTE:
0097   get_voltage() will return the configured output voltage whether the
0098   regulator is enabled or disabled and should NOT be used to determine regulator
0099   output state. However this can be used in conjunction with is_enabled() to
0100   determine the regulator physical output voltage.
0101 
0102 
0103 4. Regulator Current Limit Control & Status (dynamic drivers)
0104 =============================================================
0105 
0106 Some consumer drivers need to be able to dynamically change their supply
0107 current limit to match system operating points. e.g. LCD backlight driver can
0108 change the current limit to vary the backlight brightness, USB drivers may want
0109 to set the limit to 500mA when supplying power.
0110 
0111 Consumers can control their supply current limit by calling::
0112 
0113         int regulator_set_current_limit(regulator, min_uA, max_uA);
0114 
0115 Where min_uA and max_uA are the minimum and maximum acceptable current limit in
0116 microamps.
0117 
0118 NOTE:
0119   this can be called when the regulator is enabled or disabled. If called
0120   when enabled, then the current limit changes instantly, otherwise the current
0121   limit configuration changes and the current limit is physically set when the
0122   regulator is next enabled.
0123 
0124 A regulators current limit can be found by calling::
0125 
0126         int regulator_get_current_limit(regulator);
0127 
0128 NOTE:
0129   get_current_limit() will return the current limit whether the regulator
0130   is enabled or disabled and should not be used to determine regulator current
0131   load.
0132 
0133 
0134 5. Regulator Operating Mode Control & Status (dynamic drivers)
0135 ==============================================================
0136 
0137 Some consumers can further save system power by changing the operating mode of
0138 their supply regulator to be more efficient when the consumers operating state
0139 changes. e.g. consumer driver is idle and subsequently draws less current
0140 
0141 Regulator operating mode can be changed indirectly or directly.
0142 
0143 Indirect operating mode control.
0144 --------------------------------
0145 Consumer drivers can request a change in their supply regulator operating mode
0146 by calling::
0147 
0148         int regulator_set_load(struct regulator *regulator, int load_uA);
0149 
0150 This will cause the core to recalculate the total load on the regulator (based
0151 on all its consumers) and change operating mode (if necessary and permitted)
0152 to best match the current operating load.
0153 
0154 The load_uA value can be determined from the consumer's datasheet. e.g. most
0155 datasheets have tables showing the maximum current consumed in certain
0156 situations.
0157 
0158 Most consumers will use indirect operating mode control since they have no
0159 knowledge of the regulator or whether the regulator is shared with other
0160 consumers.
0161 
0162 Direct operating mode control.
0163 ------------------------------
0164 
0165 Bespoke or tightly coupled drivers may want to directly control regulator
0166 operating mode depending on their operating point. This can be achieved by
0167 calling::
0168 
0169         int regulator_set_mode(struct regulator *regulator, unsigned int mode);
0170         unsigned int regulator_get_mode(struct regulator *regulator);
0171 
0172 Direct mode will only be used by consumers that *know* about the regulator and
0173 are not sharing the regulator with other consumers.
0174 
0175 
0176 6. Regulator Events
0177 ===================
0178 
0179 Regulators can notify consumers of external events. Events could be received by
0180 consumers under regulator stress or failure conditions.
0181 
0182 Consumers can register interest in regulator events by calling::
0183 
0184         int regulator_register_notifier(struct regulator *regulator,
0185                                         struct notifier_block *nb);
0186 
0187 Consumers can unregister interest by calling::
0188 
0189         int regulator_unregister_notifier(struct regulator *regulator,
0190                                           struct notifier_block *nb);
0191 
0192 Regulators use the kernel notifier framework to send event to their interested
0193 consumers.
0194 
0195 7. Regulator Direct Register Access
0196 ===================================
0197 
0198 Some kinds of power management hardware or firmware are designed such that
0199 they need to do low-level hardware access to regulators, with no involvement
0200 from the kernel. Examples of such devices are:
0201 
0202 - clocksource with a voltage-controlled oscillator and control logic to change
0203   the supply voltage over I2C to achieve a desired output clock rate
0204 - thermal management firmware that can issue an arbitrary I2C transaction to
0205   perform system poweroff during overtemperature conditions
0206 
0207 To set up such a device/firmware, various parameters like I2C address of the
0208 regulator, addresses of various regulator registers etc. need to be configured
0209 to it. The regulator framework provides the following helpers for querying
0210 these details.
0211 
0212 Bus-specific details, like I2C addresses or transfer rates are handled by the
0213 regmap framework. To get the regulator's regmap (if supported), use::
0214 
0215         struct regmap *regulator_get_regmap(struct regulator *regulator);
0216 
0217 To obtain the hardware register offset and bitmask for the regulator's voltage
0218 selector register, use::
0219 
0220         int regulator_get_hardware_vsel_register(struct regulator *regulator,
0221                                                  unsigned *vsel_reg,
0222                                                  unsigned *vsel_mask);
0223 
0224 To convert a regulator framework voltage selector code (used by
0225 regulator_list_voltage) to a hardware-specific voltage selector that can be
0226 directly written to the voltage selector register, use::
0227 
0228         int regulator_list_hardware_vsel(struct regulator *regulator,
0229                                          unsigned selector);