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, ®_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 d2041_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { struct d2041 *d2041 = rdev_get_drvdata(rdev); int mV_val; int min_mV = uV_to_mV(min_uV); int max_mV = uV_to_mV(max_uV); unsigned int reg_num, regulator_id = rdev_get_id(rdev); u8 val; int ret = 0; /* before we do anything check the lock bit */ ret = d2041_reg_read(d2041, D2041_SUPPLY_REG, &val); if(val & D2041_SUPPLY_VLOCK) d2041_clear_bits(d2041, D2041_SUPPLY_REG, D2041_SUPPLY_VLOCK); mV_val = d2041_regulator_mvolts_to_val(min_mV, regulator_id, rdev); /* Sanity check for maximum value */ if (d2041_regulator_val_to_mvolts(mV_val, regulator_id, rdev) > max_mV) return -EINVAL; reg_num = get_regulator_reg(regulator_id); ret = d2041_reg_read(d2041, reg_num, &val); val &= ~D2041_MAX_VSEL; d2041_reg_write(d2041, reg_num, (val | mV_val)); /* For BUCKs enable the ramp */ if (regulator_id <= D2041_BUCK_4) d2041_set_bits(d2041, D2041_SUPPLY_REG, (D2041_SUPPLY_VBUCK1GO << regulator_id)); return ret; }
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, ®_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, ®_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; }
static int d2041_regulator_get_voltage(struct regulator_dev *rdev) { struct d2041 *d2041 = rdev_get_drvdata(rdev); unsigned int reg_num, regulator_id = rdev_get_id(rdev); int ret; u8 val; dlg_info("[[%s]], regulator_id[%d]\n", __func__, regulator_id); reg_num = get_regulator_reg(regulator_id); ret = d2041_reg_read(d2041, reg_num, &val); val &= D2041_MAX_VSEL; ret = mV_to_uV(d2041_regulator_val_to_mvolts(val, regulator_id, rdev)); return ret; }
static int d2083_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,unsigned *selector) { struct d2083 *d2083 = rdev_get_drvdata(rdev); int mV_val; int min_mV = uV_to_mV(min_uV); int max_mV = uV_to_mV(max_uV); unsigned int reg_num, regulator_id = rdev_get_id(rdev); u8 val; int ret = 0; *selector = -1; // Neet to implement parameter *selector : reference v_table / num_voltages /* before we do anything check the lock bit */ ret = d2083_reg_read(d2083, D2083_SUPPLY_REG, &val); if(val & D2083_SUPPLY_VLOCK) d2083_clear_bits(d2083, D2083_SUPPLY_REG, D2083_SUPPLY_VLOCK); mV_val = d2083_regulator_mvolts_to_val(min_mV, regulator_id, rdev); /* Sanity check for maximum value */ if (d2083_regulator_val_to_mvolts(mV_val, regulator_id, rdev) > max_mV) return -EINVAL; reg_num = get_regulator_reg(regulator_id); ret = d2083_reg_read(d2083, reg_num, &val); val &= ~D2083_MAX_VSEL; d2083_reg_write(d2083, reg_num, (val | mV_val)); /* For BUCKs enable the ramp */ if (regulator_id <= D2083_BUCK_4) d2083_set_bits(d2083, D2083_SUPPLY_REG, (D2083_SUPPLY_VBUCK1GO << regulator_id)); *selector = regulator_id; return ret; }
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, ®_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, ®_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; }