Ejemplo n.º 1
0
static int tps80031_dcdc_get_voltage_sel(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	uint8_t vsel = 0;
	int ret;

	if (ri->rinfo->force_reg) {
		ret = tps80031_read(parent, ri->rinfo->volt_id,
						ri->rinfo->force_reg, &vsel);
		if (ret < 0) {
			dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
					ri->rinfo->force_reg, ret);
			return ret;
		}

		if (!(vsel & SMPS_CMD_MASK))
			return vsel & SMPS_VSEL_MASK;
	}
	ret = tps80031_read(parent, ri->rinfo->volt_id,
				ri->rinfo->volt_reg, &vsel);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
			ri->rinfo->volt_reg, ret);
		return ret;
	}
	return vsel & SMPS_VSEL_MASK;
}
Ejemplo n.º 2
0
static int tps80031_vbus_is_enabled(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	int ret = -EIO;
	uint8_t ctrl1 = 0;
	uint8_t ctrl3 = 0;

	ret = tps80031_read(parent, TPS80031_SLAVE_ID2,
			TPS80031_CHARGERUSB_CTRL1, &ctrl1);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
			TPS80031_CHARGERUSB_CTRL1, ret);
		return ret;
	}
	ret = tps80031_read(parent, TPS80031_SLAVE_ID2,
				TPS80031_CHARGERUSB_CTRL3, &ctrl3);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
			TPS80031_CHARGERUSB_CTRL3, ret);
		return ret;
	}
	if ((ctrl1 & OPA_MODE_EN) && (ctrl3 & BOOST_HW_PWR_EN))
		return 1;
	return ret;
}
static irqreturn_t linch_status_isr(int irq, void *dev_id)
{
	struct tps80031_charger *charger = dev_id;
	uint8_t linch_status;
	int ret;
	dev_info(charger->dev, "%s() got called\n", __func__);

	ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
			LINEAR_CHRG_STS, &linch_status);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
				__func__, LINEAR_CHRG_STS);
	} else {
		dev_info(charger->dev, "%s():The status of LINEAR_CHRG_STS is 0x%02x\n",
				 __func__, linch_status);
		if (linch_status & 0x20) {
			charger->state = charging_state_charging_completed;
			if (charger->charger_cb)
				charger->charger_cb(charger->state,
					charger->charger_cb_data);
		}
	}

	return IRQ_HANDLED;
}
Ejemplo n.º 4
0
static int clear_alarm_int_status(struct device *dev, struct tps80031_rtc *rtc)
{
	int ret;
	u8 buf;

	/**
	 * As per datasheet, A dummy read of this  RTC_STATUS_REG register
	 * is necessary before each I2C read in order to update the status
	 * register value.
	 */
	ret = tps80031_read(dev->parent, TPS80031_SLAVE_ID1,
				TPS80031_RTC_STATUS_REG, &buf);
	if (ret < 0) {
		dev_err(dev, "reading RTC_STATUS failed. err = %d\n", ret);
		return ret;
	}

	/* clear Alarm status bits.*/
	ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
			TPS80031_RTC_STATUS_REG, ALARM_INT_STATUS);
	if (ret < 0) {
		dev_err(dev, "clear Alarm INT failed, err = %d\n", ret);
		return ret;
	}
	return 0;
}
Ejemplo n.º 5
0
static int tps80031_dcdc_set_voltage_sel(struct regulator_dev *rdev,
		unsigned vsel)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	int ret;
	u8 reg_val;

	if (ri->rinfo->force_reg) {
		ret = tps80031_read(parent, ri->rinfo->volt_id,
						ri->rinfo->force_reg, &reg_val);
		if (ret < 0) {
			dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n",
				ri->rinfo->force_reg, ret);
			return ret;
		}
		if (!(reg_val & SMPS_CMD_MASK)) {
			ret = tps80031_update(parent, ri->rinfo->volt_id,
				ri->rinfo->force_reg, vsel, SMPS_VSEL_MASK);
			if (ret < 0)
				dev_err(ri->dev,
					"reg 0x%02x update failed, e = %d\n",
					ri->rinfo->force_reg, ret);
			return ret;
		}
	}
	ret = tps80031_update(parent, ri->rinfo->volt_id,
			ri->rinfo->volt_reg, vsel, SMPS_VSEL_MASK);
	if (ret < 0)
		dev_err(ri->dev, "reg 0x%02x update failed, e = %d\n",
			ri->rinfo->volt_reg, ret);
	return ret;
}
Ejemplo n.º 6
0
static int tps80031_reg_read(struct tps80031_gpadc_data *gpadc, int sid,
				int reg, uint8_t *val)
{
	int ret;

	ret = tps80031_read(gpadc->dev->parent, sid, reg, val);
	if (ret < 0)
		dev_err(gpadc->dev, "Failed read register 0x%02x\n", reg);
	return ret;
}
Ejemplo n.º 7
0
static int tps80032_adc_wait_conversion_ready_locked(
				unsigned int timeout_ms)
{
	unsigned long timeout;
	int ret;
	u8 reg_value[3];

	CHECK_LOG();

	timeout = jiffies + msecs_to_jiffies(timeout_ms);
	do {
		ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
					TPS80032_CTRL_P1, &reg_value[0]);
		if (ret < 0) {
			pr_err("%s:read CTRL_P1 fail\n", __func__);
			return ret;
		}

		if (!(reg_value[0] & CP_BUSY_BIT)
			&& (reg_value[0] & CP_ECOCP1_BIT))
			return 0;
	} while(!time_after(jiffies, timeout));

	ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
			TPS80032_GPSELECT_ISB, &reg_value[1]);
	if (ret < 0) {
		pr_err("%s:read TPS80032_GPSELECT_ISB fail\n", __func__);
		return ret;
	}

	ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
			TPS80032_GPCH0_MSB, &reg_value[2]);
	if (ret < 0) {
		pr_err("%s:read register GPCH0_MSB fail\n", __func__);
		return ret;
	}

	pr_info("adc conversion timeout: CTRL_P1:0x%X, GPSELECT:0x%X GPCH0_MSB:0x%X\n"
			, reg_value[0], reg_value[1], reg_value[2]);

	return -EAGAIN;
}
Ejemplo n.º 8
0
static int tps80031_reg_read(struct tps80031_device_info *di, int sid, int reg,
					uint8_t *val)
{
	int ret;

	ret = tps80031_read(di->dev->parent, sid, reg, val);
	if (ret < 0)
		dev_err(di->dev, "Failed read register 0x%02x\n",
					reg);
	return ret;
}
Ejemplo n.º 9
0
static int tps80031_ldo_get_voltage_sel(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	uint8_t vsel;
	int ret;

	ret = tps80031_read(parent, ri->rinfo->volt_id,
				ri->rinfo->volt_reg, &vsel);
	if (ret < 0) {
		dev_err(ri->dev, "Error in writing the Voltage register\n");
		return ret;
	}
	return vsel & rdev->desc->vsel_mask;
}
Ejemplo n.º 10
0
int tps80032_read_boots_hw_pwr(void)
{
	uint8_t ctrl0;
	int ret;

	ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
			CHARGERUSB_CTRL3_ADD, &ctrl0);
	if (ret < 0) {
		pr_err("%s:read register CHARGERUSB_CTRL1_ADD fail\n",__func__);
		return ret;
	}
	if (ctrl0 & BOOST_HW_PWR_EN)
		return 1;
	return 0;
}
Ejemplo n.º 11
0
int tps80032_read_opa_mode(void)
{
	uint8_t ctrl0;
	int ret;

	ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
			CHARGERUSB_CTRL1_ADD, &ctrl0);
	if (ret < 0) {
		pr_err("%s:read register CHARGERUSB_CTRL1_ADD fail\n",__func__);
		return ret;
	}
	if (ctrl0 & OPA_MODE_EN)
		return 1;
	return 0;
}
Ejemplo n.º 12
0
int tps80032_read_vbus_detection(void)
{
	uint8_t ctrl0;
	int ret;

	ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
			CONTROLLER_STAT1, &ctrl0);
	if (ret < 0) {
		pr_err("%s:read register CONTROLLER_STAT1 fail\n",__func__);
		return ret;
	}

	if ((ctrl0 & VBUS_DET))
		return 1;
	return 0;
}
Ejemplo n.º 13
0
static int tps80031_reg_is_enabled(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	u8 reg_val;
	int ret;

	if (ri->ext_ctrl_flag & TPS80031_EXT_PWR_REQ)
		return true;

	ret = tps80031_read(parent, TPS80031_SLAVE_ID1, ri->rinfo->state_reg,
				&reg_val);
	if (ret < 0) {
		dev_err(&rdev->dev, "Reg 0x%02x read failed, err = %d\n",
			ri->rinfo->state_reg, ret);
		return ret;
	}
	return ((reg_val & TPS80031_STATE_MASK) == TPS80031_STATE_ON);
}
Ejemplo n.º 14
0
/*ZTE:add by caixiaoguang 20120531 for charge++*/
int tps80031_get_vbus_status(void)
{
    struct tps80031_charger *charger = charger_data;
    int ret;
    int is_present = -1;
    uint8_t controller_stat1_reg;
    ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
                        CONTROLLER_STAT1, &controller_stat1_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
                __func__, CONTROLLER_STAT1);
    }
    controller_stat1_reg &= 0x04;
    if(controller_stat1_reg == 0)
    {
        is_present = 0;
    }
    else
    {
        is_present = 1;
    }
    return is_present;
}
Ejemplo n.º 15
0
static bool tps80031_check_charging_completed(struct tps80031_charger *charger)
{
	int ret;
	uint8_t linch_status;

	ret = tps80031_read(charger->dev->parent, TPS80031_SLAVE_ID2,
			LINEAR_CHRG_STS, &linch_status);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
				__func__, LINEAR_CHRG_STS);
		return false;
	}

	if (linch_status & 0x20) {
		charger->state = charging_state_charging_completed;
		ret = true;
	} else {
		charger->state = charging_state_charging_in_progress;
		ret = false;
	}

	return ret;
}
Ejemplo n.º 16
0
bool tps80031_get_ovp_status(void)
{
    /*ZTE:add by liyun 20121109 for charge status by MHL charger++*/
    struct tps80031_charger *charger = charger_data;
    int ret;
    uint8_t vbus_ovp_status;
    ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
                        CHARGERUSB_STATUS_INT, &vbus_ovp_status);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
                __func__, CHARGERUSB_STATUS_INT);
    }
    vbus_ovp_status &= 0x01;
    if ( 1 == vbus_ovp_status )
    {
        vbus_ovp_flag = 1;
    }
    else
    {
        vbus_ovp_flag = 0;
    }
    /*ZTE:add by liyun 20121109 for charge status by MHL charger--*/
    return vbus_ovp_flag;
}
Ejemplo n.º 17
0
static int check_smps_mode_mult(struct device *parent,
	struct tps80031_regulator *ri)
{
	int mult_offset;
	int ret;
	u8 smps_offset;
	u8 smps_mult;

	ret = tps80031_read(parent, TPS80031_SLAVE_ID1,
			TPS80031_SMPS_OFFSET, &smps_offset);
	if (ret < 0) {
		dev_err(parent, "Error in reading smps offset register\n");
		return ret;
	}

	ret = tps80031_read(parent, TPS80031_SLAVE_ID1,
			TPS80031_SMPS_MULT, &smps_mult);
	if (ret < 0) {
		dev_err(parent, "Error in reading smps mult register\n");
		return ret;
	}

	switch (ri->rinfo->desc.id) {
	case TPS80031_REGULATOR_VIO:
		mult_offset = SMPS_MULTOFFSET_VIO;
		break;
	case TPS80031_REGULATOR_SMPS1:
		mult_offset = SMPS_MULTOFFSET_SMPS1;
		break;
	case TPS80031_REGULATOR_SMPS2:
		mult_offset = SMPS_MULTOFFSET_SMPS2;
		break;
	case TPS80031_REGULATOR_SMPS3:
		mult_offset = SMPS_MULTOFFSET_SMPS3;
		break;
	case TPS80031_REGULATOR_SMPS4:
		mult_offset = SMPS_MULTOFFSET_SMPS4;
		break;
	case TPS80031_REGULATOR_LDO2:
		ri->device_flags = smps_mult & BIT(5) ? TRACK_MODE_ENABLE : 0;
		/* TRACK mode the ldo2 varies from 600mV to 1300mV */
		if (ri->device_flags & TRACK_MODE_ENABLE) {
			ri->rinfo->desc.min_uV = 600000;
			ri->rinfo->desc.uV_step = 12500;
			ri->rinfo->desc.n_voltages = 57;
			ri->rinfo->desc.vsel_mask = LDO_TRACK_VSEL_MASK;
		}
		return 0;
	default:
		return 0;
	}

	ri->device_flags = (smps_offset & mult_offset) ? DCDC_OFFSET_EN : 0;
	ri->device_flags |= (smps_mult & mult_offset) ? DCDC_EXTENDED_EN : 0;
	switch (ri->device_flags) {
	case 0:
		ri->rinfo->desc.min_uV = 607700;
		ri->rinfo->desc.uV_step = 12660;
		break;
	case DCDC_OFFSET_EN:
		ri->rinfo->desc.min_uV = 700000;
		ri->rinfo->desc.uV_step = 12500;
		break;
	case DCDC_EXTENDED_EN:
		ri->rinfo->desc.min_uV = 1852000;
		ri->rinfo->desc.uV_step = 38600;
		break;
	case DCDC_OFFSET_EN | DCDC_EXTENDED_EN:
		ri->rinfo->desc.min_uV = 2161000;
		ri->rinfo->desc.uV_step = 38600;
		break;
	}
	return 0;
}
Ejemplo n.º 18
0
/*ZTE:add by caixiaoguang 20120531 for charge--*/
static int configure_charging_parameter(struct tps80031_charger *charger)
{
    int ret;
    int max_charge_current;
    int max_charge_volt;
    int term_current;
    uint8_t chargerusb_vichrg_reg;
    uint8_t chargerusb_int__mask_reg;
    int vbus_preset = -1;
    int chargertype = -1;
    /* Disable watchdog timer */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CONTROLLER_WDG, 0x0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_WDG);
        return ret;
    }

    /* Disable the charging if any */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CONTROLLER_CTRL1, 0x0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_CTRL1);
        return ret;
    }

    if (charger->board_init) {
        ret = charger->board_init(charger->board_data);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in board init\n",
                    __func__);
            return ret;
        }
    }

    /* Unlock value */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT2, 0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }

    /* Set max current limit */
#if 0
    max_charge_current = min(1500, charger->max_charge_current_mA);
    if (max_charge_current < 100)
        max_charge_current = 0;
    else
        max_charge_current = (max_charge_current - 100)/100;
    max_charge_current &= 0xF;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT2, (uint8_t)max_charge_current);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register "
                "0x%02x\n", __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }
#endif

    /* Set max voltage limit */
    max_charge_volt = min(4760, charger->max_charge_volt_mV);
    max_charge_volt = max(3500, max_charge_volt);
    max_charge_volt -= 3500;
    max_charge_volt = max_charge_volt/20;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT1, (uint8_t)max_charge_volt);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT1);
        return ret;
    }
#if 0
    /* Lock value */
    ret = tps80031_set_bits(charger->dev->parent, SLAVE_ID2,
                            CHARGERUSB_CTRLLIMIT2, (1 << 4));
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }
#endif
    /* set Pre Charge current to 400mA */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2, 0xDE, 0x3);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, 0xDD);
        return ret;
    }

    /* set charging termination current*/
    if (charger->charging_term_current_mA > 400)
        term_current =  7;
    else
        term_current = (charger->charging_term_current_mA - 50)/50;
    term_current = term_current << 5;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRL2, term_current);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRL2);
        return ret;
    }
    /*ZTE:add by caixiaoguang 20120531 for charge++*/
#if 0
    vbus_preset = tps80031_get_vbus_status();
    chargertype = fsl_charger_detect();
    if(1 == vbus_preset)
    {
        ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                             CONTROLLER_CTRL1, 0x30);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CONTROLLER_CTRL1);
            return ret;
        }
        //AC set CINLIMIT 1000mA,USB set 500mA
        if(1==chargertype)
        {
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CINLIMIT, 0x29);
        }
        else
        {
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CINLIMIT, 0x09);
        }
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CHARGERUSB_CINLIMIT);
            return ret;
        }

    }
#endif
    //mask CHARGERUSB_STAT interrupt in CHARGERUSB_INT
    ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
                        0xE5, &chargerusb_int__mask_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
                __func__, 0xE5);
    }
    chargerusb_int__mask_reg |= 0x1E;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         0xE5, chargerusb_int__mask_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, 0xE5);
        return ret;
    }
    return 0;
}
Ejemplo n.º 19
0
int32_t tps80032_adc_select_and_read(int32_t *result, u8 channel)
{
	u8 read_reg_value;
	int temp;
	int ret, i;

	CHECK_LOG();

	if (!bAdcReady) {
		*result = TPS80032_GPADC_FAIL_VALUE;
		return -ENODEV;
	}
	if (channel >= CHANNEL_NUM) {
		pr_err("%s:no such channel %u for gpadc\n", __func__, channel);
		ret = -ENODEV;
		goto no_channel_adc_fail;
	}

	mutex_lock(&adc_conversion_lock);

		if (channel == 10) {
			ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
					TPS80032_USB_VBUS_CTRL_SET, &read_reg_value);
			if (ret < 0) {
				pr_warn("%s:read register USB_VBUS_CTRL_SET fail\n"
						, __func__);
				goto vbus_mea_enable_fail;
			}

			read_reg_value |= VBUS_MEAS;

			ret = tps80031_write(adc_data->parent_dev, SLAVE_ID2,
					TPS80032_USB_VBUS_CTRL_SET, read_reg_value);
			if (ret < 0) {
				pr_warn("%s:write register USB_VBUS_CTRL_SET fail\n"
						, __func__);
				goto vbus_mea_enable_fail;
			}
		}

		ret = tps80031_write(adc_data->parent_dev, SLAVE_ID2,
				TPS80032_GPSELECT_ISB, channel);
		if (ret < 0) {
			pr_err("%s:write register GPSELECT_ISB fail\n"
					, __func__);
			goto write_i2c_adc_fail;
		}

		ret = tps80031_write(adc_data->parent_dev, SLAVE_ID2,
				TPS80032_CTRL_P1, CP_SP1_BIT);
		if (ret < 0) {
			pr_err("%s:write register CTRL_P1 fail\n"
					, __func__);
			goto write_i2c_adc_fail;
		}

		i = 0;
		do {
			ret = tps80032_adc_wait_conversion_ready_locked(5);
		} while (ret != 0 && ++i < 5);

		if (ret < 0) {
			pr_err("%s:conversion fail or timeout\n"
					, __func__);
			goto conversion_fail;
		}

		ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
				TPS80032_GPCH0_MSB, &read_reg_value);
		if (ret < 0) {
			pr_err("%s:read register GPCH0_MSB fail\n"
					, __func__);
			goto read_adc_fail;
		}

		if (read_reg_value & COLLISION_GP_BIT) {
			pr_err("%s:read register GPCH0_MSB encounter"
					" collision!!\n", __func__);
			ret = -EBUSY;
			goto read_adc_fail;
		}

		temp = (read_reg_value & 0x0F) << 8;
		ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
				TPS80032_GPCH0_LSB, &read_reg_value);
		if (ret < 0) {
			pr_err("%s:read register GPCH0_LSB fail\n"
						, __func__);
			goto read_adc_fail;
		}
		temp += read_reg_value;

#if ENABLE_CALIB
		if (!!(adc_data->calib_bit_map & (0x1 << channel)))
			temp = (temp * CHANNEL_VAL_SHIFT - calib_params[channel].offset)
					/ calib_params[channel].gain;
#endif

		if (channel == 10) {
			ret = tps80031_read(adc_data->parent_dev, SLAVE_ID2,
					TPS80032_USB_VBUS_CTRL_CLR, &read_reg_value);
			if (ret < 0) {
				pr_warn("%s:read register USB_VBUS_CTRL_SET fail\n"
						, __func__);
				goto vbus_mea_disable_fail;
			}

			read_reg_value |= VBUS_MEAS;

			ret = tps80031_write(adc_data->parent_dev, SLAVE_ID2,
					TPS80032_USB_VBUS_CTRL_CLR, read_reg_value);
			if (ret < 0) {
				pr_warn("%s:write register USB_VBUS_CTRL_SET fail\n"
						, __func__);
			}
		}

vbus_mea_disable_fail:
	mutex_unlock(&adc_conversion_lock);

	if (temp > 4095)
		temp = 4095;
	else if (temp < 0)
		temp = 0;

	*result = temp;

	return ret;
no_channel_adc_fail:
	*result = TPS80032_GPADC_FAIL_VALUE;
	return ret;
conversion_fail:
read_adc_fail:
write_i2c_adc_fail:
	*result = TPS80032_GPADC_FAIL_VALUE;
	mutex_unlock(&adc_conversion_lock);
	pr_err("%s:adc write or read fail at channel %u\n"
					, __func__, channel);
	return ret;
vbus_mea_enable_fail:
	*result = TPS80032_GPADC_FAIL_VALUE;
	mutex_unlock(&adc_conversion_lock);
	pr_warn("%s:adc write or read fail at channel 10\n"
					, __func__);
	return ret;
}
Ejemplo n.º 20
0
void tps80031_config_charge_parameter(void)
{
    struct tps80031_charger *charger = charger_data;
    int ret;
    int vbus_preset = -1;
    int chargertype = -1;
    uint8_t chargerusb_voreg=0;
    uint8_t chargerusb_ctrllimit=0;
    uint8_t vsel_comp_reg = 0;
    uint8_t reg1,reg2,reg3;
    int board_temp = 0;
    uint8_t chargeusb_vichrg= 0;
    vbus_preset = tps80031_get_vbus_status();
    chargertype = fsl_charger_detect();
    board_temp = zte_get_board_temp();
    if(board_temp > 50 )
    {
        chargeusb_vichrg = 0x0;//100mA
    }
    else if(board_temp > 45 )
    {
        chargeusb_vichrg = 0x2;//300mA
    }
    else if(board_temp > 43 )
    {
        chargeusb_vichrg = 0x4;//500mA
    }
    else
    {
        chargeusb_vichrg = 0x9;//1000mA
    }

    printk("[%s]CXG get vbus_preset=%d,chargertype=%d,chargeusb_vichrg=%d,usb_high_current=%d\n",__func__,vbus_preset,chargertype,chargeusb_vichrg,usb_high_current);
    /* Unlock value */
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CHARGERUSB_CTRLLIMIT2, 0);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CHARGERUSB_CTRLLIMIT2);
        return ret;
    }
    if(1 == vbus_preset)
    {
        if(1==chargertype)
        {
            //set vbus in current limit 1000mA
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CINLIMIT, 0x2e);
            if (ret < 0) {
                dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                        __func__, CHARGERUSB_CINLIMIT);
                return ret;
            }

            //set charge current 1000mA
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_VICHRG, chargeusb_vichrg);
            if (ret < 0) {
                dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                        __func__, CHARGERUSB_VICHRG);
                return ret;
            }
            //set max charge current 1000mA
            ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                 CHARGERUSB_CTRLLIMIT2, 0x09);
            if (ret < 0) {
                dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                        __func__, CHARGERUSB_VICHRG);
                return ret;
            }
        }
        else
        {
            if(1 == usb_high_current)
            {
                //set vbus in current limit 1000mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CINLIMIT, 0x2e);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CINLIMIT);
                    return ret;
                }

                //set charge current 1000mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_VICHRG, 0x9);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_VICHRG);
                    return ret;
                }
                //set max charge current 1000mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CTRLLIMIT2, 0x09);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_VICHRG);
                    return ret;
                }
            }
            else
            {
                //printk("[%s]CXG get usb_high_current=0,so set charge current 500mA\n",__func__);
                //set vbus in current limit 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CINLIMIT, 0x09);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CINLIMIT);
                    return ret;
                }

                //set charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_VICHRG, 0x04);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_VICHRG);
                    return ret;
                }
                //set max charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CTRLLIMIT2, 0x04);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CTRLLIMIT2);
                    return ret;
                }
            }

#if 0
            if(1 == usb_high_current)
            {
                //printk("[%s]CXG get usb_high_current=1,so set charge current 1500mA\n",__func__);
                //set vbus in current limit 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CINLIMIT, 0x2E);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CINLIMIT);
                    return ret;
                }

                //set charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_VICHRG, 0x0E);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_VICHRG);
                    return ret;
                }
                //set max charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CTRLLIMIT2, 0x0F);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CTRLLIMIT2);
                    return ret;
                }
            }
            else
            {
                //printk("[%s]CXG get usb_high_current=0,so set charge current 500mA\n",__func__);
                //set vbus in current limit 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CINLIMIT, 0x09);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CINLIMIT);
                    return ret;
                }

                //set charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_VICHRG, 0x04);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_VICHRG);
                    return ret;
                }
                //set max charge current 500mA
                ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                                     CHARGERUSB_CTRLLIMIT2, 0x04);
                if (ret < 0) {
                    dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                            __func__, CHARGERUSB_CTRLLIMIT2);
                    return ret;
                }
            }
#endif

        }

        //charge enable
        ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                             CONTROLLER_CTRL1, 0x30);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CONTROLLER_CTRL1);
            return ret;
        }
        //set max charge voltage
        ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                             CHARGERUSB_CTRLLIMIT1, MAX_CHARGE_VOLTAGE);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CHARGERUSB_CTRLLIMIT1);
            return ret;
        }
        //set charge voltage
        ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                             CHARGERUSB_VOREG, CHARGE_VOLTAGE);
        if (ret < 0) {
            dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                    __func__, CHARGERUSB_VOREG);
            return ret;
        }
    }
    else
    {
        printk("[%s]CXG  detect vbus pull out!\n",__func__);
    }
    //Set DLIN 50mA
    ret = tps80031_read(charger->dev->parent, SLAVE_ID2,
                        CONTROLLER_VSEL_COMP, &vsel_comp_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in reading register 0x%02x\n",
                __func__, CONTROLLER_VSEL_COMP);
    }
    vsel_comp_reg &= 0x9f;
    vsel_comp_reg |= 0x20;//100v
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2,
                         CONTROLLER_VSEL_COMP, vsel_comp_reg);
    if (ret < 0) {
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_VSEL_COMP);
        return ret;
    }
}