Beispiel #1
0
static ssize_t workmode_store(struct device *dev,
				struct device_attribute *attr, const char *buf, size_t count)
{	
	struct regulator_dev *rdev = dev_get_drvdata(dev);
	struct axp_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *axp_dev = to_axp_dev(rdev);
	char mode;
	uint8_t val;
	if(  buf[0] > '0' && buf[0] < '9' )// 1/AUTO: auto mode; 2/PWM: pwm mode;
		mode = buf[0];
	else
		mode = buf[1];
	
	switch(mode){
	 case 'U':
	 case 'u':
	 case '1':
		val = 0;break;
	 case 'W':
	 case 'w':
	 case '2':
	 	val = 1;break;
	 default:
	    val =0;	
	}
	
	if(info->desc.id == AXP20_ID_DCDC2){
		if(val)
			axp_set_bits(axp_dev, AXP20_BUCKMODE,0x04);
		else
			axp_clr_bits(axp_dev, AXP20_BUCKMODE,0x04);
	}
	else if(info->desc.id == AXP20_ID_DCDC3){
		if(val)
			axp_set_bits(axp_dev, AXP20_BUCKMODE,0x02);
		else
			axp_clr_bits(axp_dev, AXP20_BUCKMODE,0x02);
	}
	
	return count;
}
static int axp_get_voltage(struct regulator_dev *rdev)
{
    struct axp_regulator_info *info = rdev_get_drvdata(rdev);
    struct device *axp_dev = to_axp_dev(rdev);
    uint8_t val, mask;
    int ret;

    ret = axp_read(axp_dev, info->vol_reg, &val);
    if (ret)
        return ret;

    mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
    val = (val & mask) >> info->vol_shift;
    //AXP18 LDO5
    if (AXP18_ID_LDO5 == info->desc.id) {
        return axp18_ldo5_data[val];
    }

    return info->min_uV + info->step_uV * val;

}
static ssize_t frequency_store(struct device *dev,
                               struct device_attribute *attr, const char *buf, size_t count)
{
    struct regulator_dev *rdev = dev_get_drvdata(dev);
    struct device *axp_dev = to_axp_dev(rdev);
    uint8_t val,tmp;
    int var;
    var = simple_strtoul(buf, NULL, 10);
    if(var < 750)
        var = 750;
    if(var > 1875)
        var = 1875;

    val = (var -750)/75;
    val &= 0x0F;

    axp_read(axp_dev, AXP18_BUCKFREQ, &tmp);
    tmp &= 0xF0;
    val |= tmp;
    axp_write(axp_dev, AXP18_BUCKFREQ, val);
    return count;
}
Beispiel #4
0
static int axp_set_aldo12_voltage(struct regulator_dev *rdev,
				  int min_uV, int max_uV)
{
	struct axp_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *axp_dev = to_axp_dev(rdev);
	uint8_t val, mask;
	int i;

	if (check_range(info, min_uV, max_uV)) {
		pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
		return -EINVAL;
	}

	for(i = 0,val = 0; i < sizeof(axp15_aldo12_data);i++){
		if(min_uV <= axp15_aldo12_data[i] * 1000){
			val = i;
			break;
		}
	}
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
	return axp_update(axp_dev, info->vol_reg, val, mask);
}
static ssize_t workmode_store(struct device *dev,
                              struct device_attribute *attr, const char *buf, size_t count)
{
    struct regulator_dev *rdev = dev_get_drvdata(dev);
    struct axp_regulator_info *info = rdev_get_drvdata(rdev);
    struct device *axp_dev = to_axp_dev(rdev);
    char mode;
    uint8_t val;
    if(  buf[0] > '0' && buf[0] < '9' )// 1/AUTO: auto mode; 2/PWM: pwm mode;
        mode = buf[0];
    else
        mode = buf[1];

    switch(mode) {
    case 'U':
    case 'u':
    case '1':
        val = 0;
        break;
    case 'W':
    case 'w':
    case '2':
        val = 1;
        break;
    case 'F':
    case 'f':
    case '4':
        val = 2;
        break;
    default:
        val = 3;
        break;
    }

    if(info->desc.id == AXP18_ID_BUCK1) {
        if(val == 0)
            axp_clr_bits(axp_dev, AXP18_BUCKMODE,0x80);
        else if(val == 1)
            axp_update(axp_dev, AXP18_BUCKMODE,0x80,0x84);
        else if(val == 2)
            axp_update(axp_dev,AXP18_BUCKMODE,0x84,0x84);
        else
            return -EINVAL;
    }
    else if(info->desc.id == AXP18_ID_BUCK2) {
        if(val == 0)
            axp_clr_bits(axp_dev, AXP19_BUCKMODE,0x40);
        else if(val == 1)
            axp_update(axp_dev, AXP18_BUCKMODE,0x40,0x42);
        else if(val == 2)
            axp_update(axp_dev,AXP18_BUCKMODE,0x42,0x42);
        else
            return -EINVAL;
    }
    else if(info->desc.id == AXP18_ID_BUCK3) {
        if(val == 0)
            axp_clr_bits(axp_dev, AXP18_BUCKMODE,0x20);
        else if(val == 1)
            axp_update(axp_dev, AXP19_BUCKMODE,0x20,0x21);
        else if(val == 2)
            axp_update(axp_dev, AXP19_BUCKMODE,0x21,0x21);
        else
            return -EINVAL;
    }
    else
        return -ENXIO;
    return count;
}