Exemplo n.º 1
0
static int d2041_regulator_disable(struct regulator_dev *rdev)
{
    struct d2041 *d2041 = rdev_get_drvdata(rdev);
    unsigned int regulator_id = rdev_get_id(rdev);
    unsigned int reg_num = 0;
    int ret = 0;
    u8 reg_val;

    if (regulator_id >= D2041_NUMBER_OF_REGULATORS)
        return -EINVAL;

	if(!is_mode_control_enabled()){
	
		reg_num = get_regulator_reg(regulator_id);
		
		d2041_reg_read(d2041, reg_num, &reg_val);
		reg_val &= ~(1<<6);
		d2041_reg_write(d2041, reg_num, reg_val);
	}else{

    reg_num = get_regulator_mctl_reg(regulator_id);
    /* 0x00 ==  D2041_REGULATOR_MCTL0_OFF | D2041_REGULATOR_MCTL1_OFF 
     *        | D2041_REGULATOR_MCTL2_OFF | D2041_REGULATOR_MCTL3_OFF 
     */

    ret = d2041_reg_write(d2041, reg_num, 0x00);

	}

    return ret;
}
static int d2199_regulator_set_suspend_disable(struct regulator_dev *rdev)
{
	struct d2199 *d2199 = rdev_get_drvdata(rdev);
	unsigned int regulator_id = rdev_get_id(rdev);
	unsigned int reg_num = 0;
	int ret = 0;
	u8 reg_val;

	pr_info("Regulator '%s' suspend disable\n", rdev->desc->name);

	if (unlikely(regulator_id >= D2199_NUMBER_OF_REGULATORS))
		return -EINVAL;

	reg_num = regulator_register_map[regulator_id].mctl_reg;
	ret = d2199_reg_read(d2199, reg_num, &reg_val);
	if (ret < 0) {
		pr_err("I2C Error! Reg = 0x%02X\n", reg_num);
		return ret;
	}

	reg_val &= ~(D2199_REGULATOR_MCTL0 | D2199_REGULATOR_MCTL2);
	d2199_reg_write(d2199, reg_num, reg_val);

	if (!is_mode_control_enabled()) {
		reg_num = regulator_register_map[regulator_id].en_reg;

		d2199_reg_read(d2199, reg_num, &reg_val);
		reg_val &= ~regulator_register_map[regulator_id].en_mask;
		d2199_reg_write(d2199, reg_num, reg_val);
	}

	return ret;
}
/*
 * d2199_regulator_disable
 */
static int d2199_regulator_disable(struct regulator_dev *rdev)
{
	struct d2199 *d2199 = rdev_get_drvdata(rdev);
	unsigned int regulator_id = rdev_get_id(rdev);
	unsigned int reg_num = 0;
	int ret = 0;
	u8 reg_val;

	if (regulator_id >= D2199_NUMBER_OF_REGULATORS)
		return -EINVAL;

	if (!is_mode_control_enabled()) {
		reg_num = regulator_register_map[regulator_id].en_reg;

		d2199_reg_read(d2199, reg_num, &reg_val);
		reg_val &= ~regulator_register_map[regulator_id].en_mask;
		d2199_reg_write(d2199, reg_num, reg_val);
	} else {
		reg_num = regulator_register_map[regulator_id].mctl_reg;
		ret = d2199_reg_read(d2199, reg_num, &reg_val);
		if (ret < 0) {
			pr_err("I2C read error\n");
			return ret;
		}

		/* Clear MCTL11 and MCTL01 */
		reg_val &= ~(D2199_REGULATOR_MCTL1 | D2199_REGULATOR_MCTL3);
		ret = d2199_reg_write(d2199, reg_num, reg_val);
		pr_info("Disable: regl_id[%d], reg_num[0x%x], reg_val[0x%x]\n",
				regulator_id, reg_num, reg_val);
	}

	return ret;
}
Exemplo n.º 4
0
static int d2041_regulator_enable(struct regulator_dev *rdev)
{
    struct d2041 *d2041 = rdev_get_drvdata(rdev);
    u8 reg_val;
    int ret = 0;
    unsigned int regulator_id = rdev_get_id(rdev);
    unsigned int reg_num;

    if (regulator_id >= D2041_NUMBER_OF_REGULATORS)
        return -EINVAL;

	if(!is_mode_control_enabled()){
		reg_num = get_regulator_reg(regulator_id);
		
		d2041_reg_read(d2041, reg_num, &reg_val);
		reg_val |= (1<<6);
		ret = d2041_reg_write(d2041, reg_num,reg_val);

	}else {
    reg_num = get_regulator_mctl_reg(regulator_id);
	    
    ret = d2041_reg_read(d2041, reg_num, &reg_val);
    if(ret < 0) {
        dlg_err("I2C read error\n");
        return ret;
    }

    reg_val &= ~(D2041_REGULATOR_MCTL1 | D2041_REGULATOR_MCTL3);   // Clear MCTL11 and MCTL01
    reg_val |= (D2041_REGULATOR_MCTL1_ON | D2041_REGULATOR_MCTL3_ON);

    switch(get_regulator_dsm_opmode(regulator_id)) {
        case D2041_REGULATOR_LPM_IN_DSM :
            reg_val &= ~(D2041_REGULATOR_MCTL0 | D2041_REGULATOR_MCTL2);
            reg_val |= (D2041_REGULATOR_MCTL0_SLEEP | D2041_REGULATOR_MCTL2_SLEEP);
            break;
        case D2041_REGULATOR_OFF_IN_DSM :
            reg_val &= ~(D2041_REGULATOR_MCTL0 | D2041_REGULATOR_MCTL2);
            break;
        case D2041_REGULATOR_ON_IN_DSM :
            reg_val &= ~(D2041_REGULATOR_MCTL0 | D2041_REGULATOR_MCTL2);
            reg_val |= (D2041_REGULATOR_MCTL0_ON | D2041_REGULATOR_MCTL2_ON);
            break;
    }

    ret |= d2041_reg_write(d2041, reg_num, reg_val);
	}

    return ret;
}
/*
 * d2199_regulator_is_enabled
 */
static int d2199_regulator_is_enabled(struct regulator_dev *rdev)
{
	struct d2199 *d2199 = rdev_get_drvdata(rdev);
	unsigned int reg_num, regulator_id = rdev_get_id(rdev);
	int ret = -EINVAL;
	u8 reg_val = 0;

	if (regulator_id >= D2199_NUMBER_OF_REGULATORS)
		return -EINVAL;

	if (!is_mode_control_enabled()) {

		reg_num = regulator_register_map[regulator_id].en_reg;

		ret = d2199_reg_read(d2199, reg_num, &reg_val);
		if (ret < 0) {
			dlg_err("I2C read error.\n");
			return ret;
		}

		if (reg_val & regulator_register_map[regulator_id].en_mask)
			return 1;
		else
			return 0;
	} else {
		reg_num = regulator_register_map[regulator_id].mctl_reg;
		ret = d2199_reg_read(d2199, reg_num, &reg_val);
		if (ret < 0) {
			dlg_err("I2C read error.\n");
			return ret;
		}

		/* 0x0 : Off    * 0x1 : On    * 0x2 : Sleep    * 0x3 : n/a */
		ret = ((reg_val &
			(D2199_REGULATOR_MCTL1|D2199_REGULATOR_MCTL3)) >= 1)
								? 1 : 0;
		return ret;
	}

}
Exemplo n.º 6
0
static int d2041_regulator_is_enabled(struct regulator_dev *rdev)
{
    struct d2041 *d2041 = rdev_get_drvdata(rdev);
    unsigned int reg_num, regulator_id = rdev_get_id(rdev);
    int ret = -EINVAL;
    u8 reg_val = 0;

	if(!is_mode_control_enabled()){

		reg_num = get_regulator_reg(regulator_id);
		
	    ret = d2041_reg_read(d2041, reg_num, &reg_val);
	    if(ret < 0) {
	        dlg_err("I2C read error. \n");
	        return ret;
	    }

		/* 0x0 : off, 0x1 : on */
		ret = reg_val & (1<<6);
	}else{
    if (regulator_id >= D2041_NUMBER_OF_REGULATORS)
        return -EINVAL;

    reg_num = get_regulator_mctl_reg(regulator_id);
    ret = d2041_reg_read(d2041, reg_num, &reg_val);
    if(ret < 0) {
        dlg_err("I2C read error. \n");
        return ret;
    }

    /* 0x0 : Off    * 0x1 : On    * 0x2 : Sleep    * 0x3 : n/a */
		ret = ((reg_val & (D2041_REGULATOR_MCTL1|D2041_REGULATOR_MCTL3)) >= 1) ? 1 : 0;
	}

    return ret;
}