Example #1
0
int axp_calculate_rdc(void)
{
    struct axp_adc_res axp_adc;
    char    buf[100];
    int32_t i_lo, i_hi;
    int32_t v_lo, v_hi;
    int32_t rdc_cal = 0;

    if (ocv > 4000) {                           // don't calculate rdc when ocv is too high
        return 0;
    }
    axp_write(0x33, 0xc1);                      // set charge current to 400mA 
    udelay(500000);
    axp_read_adc(&axp_adc);
    i_lo = ABS(axp_ibat_to_mA(axp_adc.ichar_res)-axp_ibat_to_mA(axp_adc.idischar_res)); 
    v_lo = (axp_adc.vbat_res * 1100) / 1000;
    axp_write(0x33, 0xc9);                      // set charge current to 1.2A
    udelay(500000);
    axp_read_adc(&axp_adc);
    i_hi = ABS(axp_ibat_to_mA(axp_adc.ichar_res)-axp_ibat_to_mA(axp_adc.idischar_res)); 
    v_hi = (axp_adc.vbat_res * 1100) / 1000;
    rdc_cal = (v_hi - v_lo) * 1000 / (i_hi - i_lo);
    sprintf(buf, "i_lo:%4d, i_hi:%4d, u_lo:%4d, u_hi:%4d, rdc:%4d\n", i_lo, i_hi, v_lo, v_hi, rdc_cal);
    terminal_print(0, 36, buf);
    if (rdc_cal < 0 || rdc_cal >= 300) {        // usually RDC will not greater than 300 mhom
        return 0;
    }
    return rdc_cal;
}
Example #2
0
void axp_charger_update(struct axp_charger *charger, const struct axp_config_info *axp_config)
{
	uint16_t tmp;
	uint8_t val[2];
#ifdef CONFIG_AW_AXP19
#else
	int bat_temp_mv;
#endif

	charger->adc = &adc;
	axp_read_adc(charger, &adc);
	tmp = charger->adc->vbat_res;

	spin_lock(&charger->charger_lock);
	charger->vbat = axp_vbat_to_mV(tmp);
	spin_unlock(&charger->charger_lock);

	//tmp = charger->adc->ichar_res + charger->adc->idischar_res;
	spin_lock(&charger->charger_lock);
	charger->ibat = ABS(axp_icharge_to_mA(charger->adc->ichar_res)-axp_ibat_to_mA(charger->adc->idischar_res));
	tmp = 00;///qin
	charger->vac = axp_vdc_to_mV(tmp);
	tmp = 00;
	charger->iac = axp_iac_to_mA(tmp);
	tmp = 00;
	charger->vusb = axp_vdc_to_mV(tmp);
	tmp = 00;
	charger->iusb = axp_iusb_to_mA(tmp);
	spin_unlock(&charger->charger_lock);

	axp_reads(charger->master,AXP_INTTEMP,2,val);
	//DBG_PSY_MSG("TEMPERATURE:val1=0x%x,val2=0x%x\n",val[1],val[0]);
	tmp = (val[0] << 4 ) + (val[1] & 0x0F);

#ifdef CONFIG_AW_AXP19
	spin_lock(&charger->charger_lock);
	charger->ic_temp = (int) ((tmp - 1447)/10);
	charger->disvbat =  charger->vbat;
	charger->disibat =  axp_ibat_to_mA(charger->adc->idischar_res);
	spin_unlock(&charger->charger_lock);
#else
	spin_lock(&charger->charger_lock);
	charger->ic_temp = (int) tmp *1063/10000  - 2667/10;
	charger->disvbat =  charger->vbat;
	charger->disibat =  axp_ibat_to_mA(charger->adc->idischar_res);
	spin_unlock(&charger->charger_lock);

	tmp = charger->adc->ocvbat_res;
	spin_lock(&charger->charger_lock);
	charger->ocv = axp_ocvbat_to_mV(tmp);
	spin_unlock(&charger->charger_lock);
	
	tmp = charger->adc->ts_res;
	bat_temp_mv = axp_vts_to_mV(tmp);
	spin_lock(&charger->charger_lock);
	charger->bat_temp = axp_vts_to_temp(bat_temp_mv, axp_config);
	spin_unlock(&charger->charger_lock);
#endif
}
static void axp_charger_update(struct axp_charger *charger)
{
	uint8_t tmp;
	struct axp_adc_res adc;
	charger->adc = &adc;
	axp_read_adc(charger, &adc);

	tmp = charger->adc->vbat_res;
	charger->vbat = axp18_vbat_to_vbat(tmp);
	tmp = charger->adc->ibat_res;
	charger->ibat = axp18_i_to_ibat(tmp);
	tmp = charger->adc->vac_res;
	charger->vac = axp18_vac_to_vbat(tmp);
	tmp = charger->adc->iac_res;
	charger->iac = axp18_i_to_ibat(tmp);
}
Example #4
0
static int axp_calculate_ocv(int charging, int rdc)
{
    struct axp_adc_res axp_adc;
    int ibat, vbat;
    int ocv;

    axp_read_adc(&axp_adc);
    ibat = ABS(axp_ibat_to_mA(axp_adc.ichar_res)-axp_ibat_to_mA(axp_adc.idischar_res)); 
    vbat = (axp_adc.vbat_res * 1100) / 1000;
    if (charging) {
        ocv = vbat - (ibat * rdc) / 1000;
    } else {
        ocv = vbat + (ibat * rdc) / 1000;
    }
    avg_voltage += vbat;
    avg_current += ibat;
    return ocv;
}
static void axp_charger_update(struct axp_charger *charger)
{
	uint16_t tmp;
	struct axp_adc_res adc;
	charger->adc = &adc;
	axp_read_adc(charger, &adc);
	tmp = charger->adc->vbat_res;
	charger->vbat = axp199_vbat_to_mV(tmp);
	//tmp = charger->adc->ichar_res + charger->adc->idischar_res;
	charger->ibat = ABS(axp199_ibat_to_mA(charger->adc->ichar_res)-axp199_ibat_to_mA(charger->adc->idischar_res));
	tmp = charger->adc->vac_res;
	charger->vac = axp199_vdc_to_mV(tmp);
	tmp = charger->adc->iac_res;
	charger->iac = axp199_iac_to_mA(tmp);
	tmp = charger->adc->vusb_res;
	charger->vusb = axp199_vdc_to_mV(tmp);
	tmp = charger->adc->iusb_res;
	charger->iusb = axp199_iusb_to_mA(tmp);
}
Example #6
0
int axp_update_calibrate(int charge)
{
    uint8_t val[2];
    struct axp_adc_res axp_adc;
    uint32_t tmp0, tmp1;

    coulomb = axp_get_coulomb(); 
    ocv = axp_get_ocv(); 
    axp_read_adc(&axp_adc);
    ibat = ABS(axp_ibat_to_mA(axp_adc.ichar_res)-axp_ibat_to_mA(axp_adc.idischar_res)); 
    tmp0 = axp_adc.vbat_res;
    vbat_i = (tmp0 * 1100) / 1000;

    axp_reads(0xBA, 2, val);
    tmp1 = ((val[0] & 0x1F) << 8) | val[1];
    rdc_r = (tmp1  * 10742) / 10000;
    if (charge) {
        return axp_calculate_rdc();
    }
    return 0;
}