先看regular使用的小demo,如

i2c8{
    [email protected] {
           vddcama-supply = <&xxxxx>;
    };
}
int ret;
struct regulator *power;
static int ts_probe(struct i2c_client *client,const struct i2c_device_id *id)
{
    power=regulator_get(&client->dev,"vddcama");
    ret=regulator_set_voltage(power, 1800000, 1800000);//mV
    ret=regulator_enable(power);
    ret=regulator_disable(power);
}

如果是共享电源,其他使用者没有关闭电源,调用regulator_disable不能关闭 电源。

int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
{
	int ret = 0;

	regulator_lock_supply(regulator->rdev);

	ret = regulator_set_voltage_unlocked(regulator, min_uV, max_uV);

	regulator_unlock_supply(regulator->rdev);

	return ret;
}
EXPORT_SYMBOL_GPL(regulator_set_voltage);

int regulator_disable(struct regulator *regulator)
{
	struct regulator_dev *rdev = regulator->rdev;
	int ret = 0;

	if (regulator->always_on)
		return 0;

	mutex_lock(&rdev->mutex);
	ret = _regulator_disable(rdev);
	mutex_unlock(&rdev->mutex);

	if (ret == 0 && rdev->supply)
		regulator_disable(rdev->supply);

	return ret;
}

/**
 * regulator_enable - enable regulator output
 * @regulator: regulator source
 *
 * Request that the regulator be enabled with the regulator output at
 * the predefined voltage or current value.  Calls to regulator_enable()
 * must be balanced with calls to regulator_disable().
 *
 * NOTE: the output value can be set by other drivers, boot loader or may be
 * hardwired in the regulator.
 */
int regulator_enable(struct regulator *regulator)
{
	struct regulator_dev *rdev = regulator->rdev;
	int ret = 0;

	if (regulator->always_on)
		return 0;

	if (rdev->supply) {
		ret = regulator_enable(rdev->supply);
		if (ret != 0)
			return ret;
	}

	mutex_lock(&rdev->mutex);
	ret = _regulator_enable(rdev);
	mutex_unlock(&rdev->mutex);

	if (ret != 0 && rdev->supply)
		regulator_disable(rdev->supply);

	return ret;
}
EXPORT_SYMBOL_GPL(regulator_enable);

/sys/class/regulator下有所有的regular,如

Linux下的regular调试

每个节点有如下的属性

cpu0-cpu                   使用者名字
device
max_microvolts       最大电压
microvolts
min_microvolts       最小电压
name                            电源名字
num_users               当前的使用者数量(use_count)
of_node                     dts配置信息        
power
state                           当前状态(打开或关闭)
subsystem
suspend_disk_state
suspend_mem_state
suspend_standby_state   
type                        电源类型(电压或电流)
uevent

查看/d/regulator/regulator_summary有所有电源的信息,如

Linux下的regular调试

use  同num_users(use_count)

open当前打开次数(open_count)(_regulator_get+1    _regulator_put-1)

相关文章:

猜你喜欢
相关资源
相似解决方案