[Linux Driver] - Regulator usage and specific usage examples of power management chip

One, regulator usage

1.1. The power management regulator is divided into static and dynamic: static does not need to change the voltage and current, only the switching power supply, used in the BootLoader, frameware, kernel board stage, etc.; dynamic is to change the voltage and current according to needs.

1.2. Obtain the regulator and dev of the device as the device pointer corresponding to the driver. You can use NULL, and Vcc is the ID of the power supply. The kernel will look up the table to find the regulator corresponding to the power supply ID. Such as: struct regulator *ldo; ldo = regualtor_get(NULL, "act_ldo5");

regulator = regulator_get(dev, "Vcc"); //Get device regulator

1.3、 regulator_put(regulator); //释放regulator

1.4. int regulator_enable(regulator); //Enable power output. It may have been enabled before the call. So use the following function to judge.

1.5. int regulator_is_enabled(regulator); //Determine whether it is enabled, >0 means it has been enabled.

1.6, int regulator_disable(regulator); //Turn off the power output. However, it may not be shut down immediately, and there may be a scenario of power sharing.

1.7, int regulator_force_disable(regulator); //Forcibly turn off the power.

1.8, int regulator_set_volatage(regulator, min_uV, max_uV); //The minimum and maximum output of the regulator voltage. If you call regulator_enable next, then this value will take effect immediately. If you call regulator_disable and others, it will not take effect until the next time regulator_enable is called.

1.9. int regulator_get_voltage(regulator); //Get the configured output voltage through this interface.

Examples are as follows:

regulator_set_voltage(ldo_28, 2800000, 2800000); //设置电压
regulator_enable(ldo_28); //使能
int value = regulator_get_voltage(ldo_28); //获取电压值

regulator_put(ldo_28); //释放

2. Specific use cases

2.1 The device tree configuration is as follows

ldo8: ldo8 {
        regulator-compatible = "LDO8";
        regulator-name = "ldo8_1v5";
        regulator-min-microvolt = <1500000>;
        regulator-max-microvolt = <1600000>;
        //regulator-boot-on;   //boot 时打开
        //regulator-always-on; //一直打开
        sleep-slot = <15>;
        poweron-slot = <0x20>;
};

2.2 The driver source code is as follows

//打开
struct regulator *reg;
reg = devm_regulator_get(&i2c->dev, "ldo8_1v5");
regulator_set_volatage(reg, 1500000, 1500000);
regulator_enable(reg);

//关闭
struct regulator *reg;
reg = devm_regualtor_get(&i2c->dev, "ldo8_1v5");
regulator_disable(reg);

Note: For the detailed introduction of regulator, please refer to - Wowo Technology - Linux Regulator Framework related chapters

Guess you like

Origin blog.csdn.net/u014674293/article/details/113866110