static irqreturn_t watchdog_expire_isr(int irq, void *dev_id)
{
	struct tps80031_charger *charger = dev_id;
	int ret;

	dev_info(charger->dev, "%s()\n", __func__);
	if (charger->state != charging_state_charging_in_progress)
		return IRQ_HANDLED;

	/* Enable watchdog timer again*/
	ret = tps80031_write(charger->dev->parent, SLAVE_ID2, CONTROLLER_WDG,
			charger->watch_time_sec);
	if (ret < 0)
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CONTROLLER_WDG);

	/* Rewrite to enable the charging */
	if (!ret) {
		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 IRQ_HANDLED;
}
Exemplo n.º 2
0
static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev,
		unsigned sel)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	int ret;

	/* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
	if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) &&
			(ri->device_flags & TRACK_MODE_ENABLE)) {
		unsigned nvsel = (sel) & 0x1F;
		if (((tps80031_get_chip_info(parent) == TPS80031) ||
			((tps80031_get_chip_info(parent) == TPS80032) &&
			(tps80031_get_pmu_version(parent) == 0x0))) &&
			((nvsel == 0x0) || (nvsel >= 0x19 && nvsel <= 0x1F))) {
				dev_err(ri->dev,
					"Invalid sel %d in track mode LDO2\n",
					nvsel);
				return -EINVAL;
		}
	}

	ret = tps80031_write(parent, ri->rinfo->volt_id,
			ri->rinfo->volt_reg, sel);
	if (ret < 0)
		dev_err(ri->dev, "Error in writing reg 0x%02x, e = %d\n",
			ri->rinfo->volt_reg, ret);
	return ret;
}
Exemplo n.º 3
0
static int tps80031_vbus_disable(struct regulator_dev *rdev)
{
	struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
	struct device *parent = to_tps80031_dev(rdev);
	int ret = 0;

	if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) {
		ret = tps80031_write(parent, TPS80031_SLAVE_ID2,
			USB_VBUS_CTRL_SET, VBUS_DISCHRG);
		if (ret < 0) {
			dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n",
				USB_VBUS_CTRL_SET, ret);
			return ret;
		}
	}

	ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2,
			TPS80031_CHARGERUSB_CTRL1,  OPA_MODE_EN);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n",
				TPS80031_CHARGERUSB_CTRL1, ret);
		return ret;
	}

	ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2,
				TPS80031_CHARGERUSB_CTRL3, BOOST_HW_PWR_EN);
	if (ret < 0) {
		dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n",
				TPS80031_CHARGERUSB_CTRL3, ret);
		return ret;
	}

	mdelay(DIV_ROUND_UP(ri->rinfo->desc.enable_time, 1000));
	if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) {
		ret = tps80031_write(parent, TPS80031_SLAVE_ID2,
			USB_VBUS_CTRL_CLR, VBUS_DISCHRG);
		if (ret < 0) {
			dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n",
					USB_VBUS_CTRL_CLR, ret);
			return ret;
		}
	}
	return ret;
}
Exemplo n.º 4
0
static int tps80031_reg_write(struct tps80031_gpadc_data *gpadc, int sid,
				int reg, uint8_t val)
{
	int ret;

	ret = tps80031_write(gpadc->dev->parent, sid, reg, val);
	if (ret < 0)
		dev_err(gpadc->dev, "Failed write register 0x%02x\n", reg);
	return ret;
}
Exemplo n.º 5
0
static int tps80031_reg_write(struct tps80031_device_info *di, int sid, int reg,
					uint8_t val)
{
	int ret;

	ret = tps80031_write(di->dev->parent, sid, reg, val);
	if (ret < 0)
		dev_err(di->dev, "Failed write register 0x%02x\n",
					reg);
	return ret;
}
Exemplo n.º 6
0
static irqreturn_t watchdog_expire_isr(int irq, void *dev_id)
{
	struct tps80031_charger *charger = dev_id;
	int ret;

	dev_info(charger->dev, "%s()\n", __func__);
	if (charger->state != charging_state_charging_in_progress) {
		/*
		 * After the charge completed, the chip can enable the
		 * charging again if battery voltage is 120mV below the
		 * charging voltage (defined by VOREG register).
		 */
		if (tps80031_check_charging_completed(charger)) {
			return IRQ_HANDLED;
		} else {
			/* "recharging" after charging completed happened */
			charger->state = charging_state_charging_in_progress;
			if (charger->charger_cb)
				charger->charger_cb(charger->state,
						charger->charger_cb_data);
		}
	}

	/* Enable watchdog timer again*/
	ret = tps80031_write(charger->dev->parent, TPS80031_SLAVE_ID2, CONTROLLER_WDG,
			charger->watch_time_sec);
	if (ret < 0)
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CONTROLLER_WDG);

	/* Rewrite to enable the charging */
	if (!ret) {
		ret = tps80031_write(charger->dev->parent, TPS80031_SLAVE_ID2,
			CONTROLLER_CTRL1, 0x30);
		if (ret < 0)
			dev_err(charger->dev, "%s(): Failed in writing "
				"register 0x%02x\n",
				__func__, CONTROLLER_CTRL1);
	}
	return IRQ_HANDLED;
}
Exemplo n.º 7
0
void wdg_work_fun(void)
{
    struct tps80031_charger *charger = charger_data;
    int ret;
    static int count=0;
    ret = tps80031_write(charger->dev->parent, SLAVE_ID2, CONTROLLER_WDG,
                         0xFF);
    if (ret < 0)
        dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
                __func__, CONTROLLER_WDG);

    schedule_delayed_work(&wdg_work,2000);
    printk("[%s]CXG  enter wdg_work_fun !\n",__func__);
    return;
}
static int set_charge_current_limit(struct regulator_dev *rdev,
		int min_uA, int max_uA)
{
	struct tps80031_charger *charger = rdev_get_drvdata(rdev);
	int max_vbus_current = 1500;
	int max_charge_current = 1500;
	int ret;

	dev_info(charger->dev, "%s(): Min curr %dmA and max current %dmA\n",
		__func__, min_uA/1000, max_uA/1000);

	if (!max_uA) {
		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);

		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);
		charger->state = charging_state_charging_stopped;
		if (charger->charger_cb)
			charger->charger_cb(charger->state,
					charger->charger_cb_data);
		return ret;
	}

	max_vbus_current = min(max_uA/1000, max_vbus_current);
	max_vbus_current = max_vbus_current/50;
	if (max_vbus_current)
		max_vbus_current--;
	ret = tps80031_update(charger->dev->parent, SLAVE_ID2,
			CHARGERUSB_CINLIMIT,
			charging_current_val_code[max_vbus_current], 0x3F);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_CINLIMIT);
		return ret;
	}

	max_charge_current = min(max_uA/1000, max_charge_current);
	if (max_charge_current <= 300)
		max_charge_current = 0;
	else if ((max_charge_current > 300) && (max_charge_current <= 500))
		max_charge_current = (max_charge_current - 300)/50;
	else
		max_charge_current = (max_charge_current - 500) / 100 + 4;
	ret = tps80031_update(charger->dev->parent, SLAVE_ID2,
			CHARGERUSB_VICHRG, (uint8_t)max_charge_current, 0xF);
	if (ret < 0) {
		dev_err(charger->dev, "%s(): Failed in writing register 0x%02x\n",
				__func__, CHARGERUSB_VICHRG);
		return ret;
	}

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

	/* Enable the charging */
	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;
	}
	charger->state = charging_state_charging_in_progress;
	if (charger->charger_cb)
		charger->charger_cb(charger->state,
				charger->charger_cb_data);
	return 0;
}
static int configure_charging_parameter(struct tps80031_charger *charger)
{
	int ret;
	int max_charge_current;
	int max_charge_volt;
	int term_current;

	/* 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 */
	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;
	}

	/* 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;
	}

	/* 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;
	}

	/* 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;
	}

	return 0;
}
Exemplo n.º 10
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;
    }
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}