Example #1
0
static void max17040_get_vcell(void)
{
	u8 msb;
	u8 lsb;
	int avalue=0;
	int voltage=0;
	dbg_func_in();
	msb = max17040_read_reg(MAX17040_VCELL_MSB);
	lsb = max17040_read_reg(MAX17040_VCELL_LSB);

	//check i2c error
	if(msb<0 ||lsb <0)
	{
	max17040_data.i2c_state_vol =1;
	}
	else
	{
	max17040_data.i2c_state_vol =0;
	max17040_data.prev_voltage=max17040_data.vcell;
	}
	
	voltage=(msb<<4)|((lsb&0xf0)>>4);
	avalue=(voltage*125)/100;
//	sleep_dbg(" MSB [%d] : LSB [%d] : LOW VOLTAGE [%d] : VOLTAGE_NOW [%d]\n",msb,lsb,voltage,avalue);
	/* ps2 team shs : voltage changes but the event is not sent.
	//temp code
	if(avalue!=max17040_data.vcell)
	max17040_data.event=Events;
	*/
	mutex_lock(&max17040_data.data_mutex); 	
	max17040_data.vcell = avalue;
	mutex_unlock(&max17040_data.data_mutex);	
	dbg_func_out();	
}
static void max17040_get_version(void)
{
	u8 msb;
	u8 lsb;

	msb = max17040_read_reg(MAX17040_VER_MSB);
	lsb = max17040_read_reg(MAX17040_VER_LSB);
	dbgme("MAX17040 Fuel-Gauge Ver %d%d\n", msb, lsb);
}
Example #3
0
static void max17040_get_version(void)
{
	u8 msb;
	u8 lsb;

	msb = max17040_read_reg(MAX17040_VER_MSB);
	lsb = max17040_read_reg(MAX17040_VER_LSB);
	pr_info("[MAX17040] Fuel-Gauge Ver %d%d\n", msb, lsb);
}
Example #4
0
static void max17040_quick_get_soc(void)
{
	u8 msb=0;
	u8 lsb=0;
	int avalue=0;
	//unsigned long quick_soc;
	int i=0;
	bool completed = false;
	dbg_func_in();

	while (!completed) {

	msb = max17040_read_reg(MAX17040_SOC_MSB);
	lsb = max17040_read_reg(MAX17040_SOC_LSB);
	if(msb < 0 || lsb < 0)
	{
		for(i=0;i<MAX_READ;i++)
		{
			msb = max17040_read_reg(MAX17040_SOC_MSB);
			lsb = max17040_read_reg(MAX17040_SOC_LSB);
			if(msb < 0 || lsb <0)
			{
				continue;
			}
			else
			break;
		}
	}
	/*//description
	read i2c data [msb=20,lsb=10]
	avalue=20*1000+(10*1000)/256
	*/
	avalue=SKY_MULT_1000(msb)+(SKY_MULT_1000(lsb)/SKY_SOC_LSB);	
	//Ajdusted soc%=(SOC%-EMPTY)/(FULL-EMPTY)*100
	//logic code	
	sleep_dbg("MAX17040_QUICK Adjusted SOC MSB [%d] : LSB [%d] : Adjusted SOC [%d] :Try Count [%d]\n",msb,lsb,avalue,i);
	
	if(i>=MAX_READ-1 || msb < 0 || lsb <0 ) { //Battery Bug Fixing Coded by Illustrious by Proto
		printk("Re-running to check Battery SoC!!!\n");
		i = 0;
		continue;			
	} else {
		mutex_lock(&max17040_data.data_mutex); 	
		max17040_data.quick_data.soc_msb=msb;	
		max17040_data.quick_data.soc_lsb=lsb;
		max17040_data.quick_data.quick_soc=avalue;
		mutex_unlock(&max17040_data.data_mutex);
		completed = true;
		break;
	}

	}	

	dbg_func_out();	
}
Example #5
0
static void max17040_quick_get_vcell(void)
{
	u8 msb=0;
	u8 lsb=0;
	unsigned long quick_avalue;
	//unsigned long temp;	
	unsigned long voltage=0;
	int i=0;
	bool completed = false;

	while (!completed) {

	msb = max17040_read_reg(MAX17040_VCELL_MSB);
	lsb = max17040_read_reg(MAX17040_VCELL_LSB);
	if(msb < 0 || lsb < 0)
	{
		for(i=0;i<MAX_READ;i++)
		{
		msb = max17040_read_reg(MAX17040_VCELL_MSB);
		lsb = max17040_read_reg(MAX17040_VCELL_LSB);
		if(msb < 0 || lsb <0)
		{
		continue;
		}
		else
		break;
		}
	}
	voltage=(msb<<4)|((lsb&0xf0)>>4);
	quick_avalue=(voltage*1250)/100;
	sleep_dbg("MAX17040_QUICK  LOW MSB [%d] : LSB [%d] : LOW VOLTAGE [%d]\n",msb,lsb,voltage);
	sleep_dbg("MAX17040_QUICK  Adjusted [%d] : I2C Error Count [%d]\n",quick_avalue,i);	
	
	if(i==MAX_READ) {
		printk("Re-running to check V-Cell!!!\n");
		i = 0;
		continue;
	} else {
		mutex_lock(&max17040_data.data_mutex); 	
		max17040_data.quick_data.vcell_msb = msb;	
		max17040_data.quick_data.vcell_lsb = lsb;	
		max17040_data.quick_data.quick_vcell = quick_avalue;
		mutex_unlock(&max17040_data.data_mutex);
		completed = true;
		break;
	}

	}

}
Example #6
0
static void max17040_get_version(struct i2c_client *client)
{
	u16 version;

	version = max17040_read_reg(client, MAX17040_VER);

	dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", version);
}
Example #7
0
static void max17040_quick_get_value(void)
{
	u8 rcomp=0, rcomp_low;
	sleep_dbg("\n=======================================================================\n");	
	sleep_dbg("[INFORMATION] QUICK START STATE [%d]\n",max17040_data.quick_data.quick_state);	      
	sleep_dbg("[INFORMATION] QUICK START SOC_MSB [%d]\n",max17040_data.quick_data.soc_msb);	
	sleep_dbg("[INFORMATION] QUICK START SOC_LSB [%d]\n",max17040_data.quick_data.soc_lsb);		
	sleep_dbg("[INFORMATION] QUICK START SOC [%d]\n",max17040_data.quick_data.quick_soc);	
	sleep_dbg("[INFORMATION] QUICK START REFERENSE SOC [%d]\n",sky_fuelgauge_ref_soc);				
	sleep_dbg("[INFORMATION] QUICK START VCELL_MSB [%d]\n",max17040_data.quick_data.vcell_msb);		
	sleep_dbg("[INFORMATION] QUICK START VCELL_LSB [%d]\n",max17040_data.quick_data.vcell_lsb);	
	sleep_dbg("[INFORMATION] QUICK START VOLTAGE [%d]\n",max17040_data.quick_data.quick_vcell);	
	rcomp=max17040_read_reg(MAX17040_RCOMP_MSB);
	rcomp_low=max17040_read_reg(MAX17040_RCOMP_LSB);	
	sleep_dbg("[INFORMATION] RCOMP 0x[%x][%x]\n",rcomp,rcomp_low);			
	sleep_dbg("\n=======================================================================\n");		
}
Example #8
0
static void max17040_get_vcell(void)
{
	u8 msb;
	u8 lsb;
	int avalue=0;
	int voltage=0;
	dbg_func_in();
	msb = max17040_read_reg(MAX17040_VCELL_MSB);
	lsb = max17040_read_reg(MAX17040_VCELL_LSB);

	//check i2c error
	if(msb<0 ||lsb <0)
	{
	max17040_data.i2c_state_vol =1;
	}
	else
	{
	max17040_data.i2c_state_vol =0;
	max17040_data.prev_voltage=max17040_data.vcell;
	}
	
	voltage=(msb<<4)|((lsb&0xf0)>>4);
	avalue=(voltage*125)/100;
	
//	sleep_dbg(" MSB [%d] : LSB [%d] : LOW VOLTAGE [%d] : VOLTAGE_NOW [%d]\n",msb,lsb,voltage,avalue);

	/* voltage changes but the event is not sent.
	//temp code
	if(avalue!=max17040_data.vcell)
	max17040_data.event=Events;
	*/
	
	mutex_lock(&max17040_data.data_mutex); 	
	max17040_data.vcell = avalue;
	mutex_unlock(&max17040_data.data_mutex);	
	
//Factory cable debug
#ifdef CONFIG_SKY_SMB136S_CHARGER
//printk("Max17040_data.vcell = %d\n", max17040_data.vcell);
	if(pm8058_chg_nobattery_factory_cable())
		max17040_data.vcell = 4100;
#endif

	dbg_func_out();	
}
Example #9
0
static void max17040_get_soc(struct i2c_client *client)
{
	struct max17040_chip *chip = i2c_get_clientdata(client);
	u16 soc;

	soc = max17040_read_reg(client, MAX17040_SOC);

	chip->soc = (soc >> 8);
}
Example #10
0
static void max17040_get_vcell(struct i2c_client *client)
{
	struct max17040_chip *chip = i2c_get_clientdata(client);
	u16 vcell;

	vcell = max17040_read_reg(client, MAX17040_VCELL);

	chip->vcell = vcell;
}
Example #11
0
static void max17040_quick_get_soc(void)
{
    u8 msb=0;
    u8 lsb=0;
    int avalue=0;
    //unsigned long quick_soc;
    int i=0;
    dbg_func_in();
    msb = max17040_read_reg(MAX17040_SOC_MSB);
    lsb = max17040_read_reg(MAX17040_SOC_LSB);
    if(msb < 0 || lsb < 0)
    {
        for(i=0; i<MAX_READ; i++)
        {
            msb = max17040_read_reg(MAX17040_SOC_MSB);
            lsb = max17040_read_reg(MAX17040_SOC_LSB);
            if(msb < 0 || lsb <0)
            {
                continue;
            }
            else
                break;
        }
    }
    /*//description
    read i2c data [msb=20,lsb=10]
    avalue=20*1000+(10*1000)/256
    */
    avalue=SKY_MULT_1000(msb)+(SKY_MULT_1000(lsb)/SKY_SOC_LSB);
    //Ajdusted soc%=(SOC%-EMPTY)/(FULL-EMPTY)*100
    //logic code
    sleep_dbg("MAX17040_QUICK Adjusted SOC MSB [%d] : LSB [%d] : Adjusted SOC [%d] :Try Count [%d]\n",msb,lsb,avalue,i);
    mutex_lock(&max17040_data.data_mutex);
    max17040_data.quick_data.soc_msb=msb;
    max17040_data.quick_data.soc_lsb=lsb;
    if(i==MAX_READ)
        max17040_data.quick_data.quick_soc=0;
    else
        max17040_data.quick_data.quick_soc=avalue;
    mutex_unlock(&max17040_data.data_mutex);
    dbg_func_out();
}
static int max17040_get_soc(void)
{
	u8 msb;
	u8 lsb;
	int soc;

	msb = max17040_read_reg(MAX17040_SOC_MSB);
	lsb = max17040_read_reg(MAX17040_SOC_LSB);

	//check i2c error
	if(msb<0 ||lsb <0)
	{
		soc = max17040_data.soc;
	}
	else
	{
		soc = SKY_MULT_1000(msb)+(SKY_MULT_1000(lsb)/SKY_SOC_LSB);	
		max17040_data.soc = soc;
	}

	return soc;
}
Example #13
0
static void max17040_quick_get_vcell(void)
{
    u8 msb=0;
    u8 lsb=0;
    unsigned long quick_avalue;
    //unsigned long temp;
    unsigned long voltage=0;
    int i=0;
    msb = max17040_read_reg(MAX17040_VCELL_MSB);
    lsb = max17040_read_reg(MAX17040_VCELL_LSB);
    if(msb < 0 || lsb < 0)
    {
        for(i=0; i<MAX_READ; i++)
        {
            msb = max17040_read_reg(MAX17040_VCELL_MSB);
            lsb = max17040_read_reg(MAX17040_VCELL_LSB);
            if(msb < 0 || lsb <0)
            {
                continue;
            }
            else
                break;
        }
    }
    voltage=(msb<<4)|((lsb&0xf0)>>4);
    quick_avalue=(voltage*1250)/100;
    sleep_dbg("MAX17040_QUICK  LOW MSB [%d] : LSB [%d] : LOW VOLTAGE [%d]\n",msb,lsb,(unsigned int)voltage);
    sleep_dbg("MAX17040_QUICK  Adjusted [%d] : I2C Error Count [%d]\n",(unsigned int)quick_avalue,i);
    mutex_lock(&max17040_data.data_mutex);
    max17040_data.quick_data.vcell_msb = msb;
    max17040_data.quick_data.vcell_lsb = lsb;
    if(i==MAX_READ)
        max17040_data.quick_data.quick_vcell = 33975;
    else
        max17040_data.quick_data.quick_vcell = quick_avalue;
    mutex_unlock(&max17040_data.data_mutex);

}
static int max17040_get_vcell(void)
{
	u8 msb;
	u8 lsb;
	int voltage=0;
	int vcell=0;

	msb = max17040_read_reg(MAX17040_VCELL_MSB);
	lsb = max17040_read_reg(MAX17040_VCELL_LSB);

	//check i2c error
	if(msb<0 ||lsb <0)
	{
		vcell = max17040_data.vcell;
	}
	else
	{
		voltage=(msb<<4)|((lsb&0xf0)>>4);
		vcell=(voltage*125)/100;
		max17040_data.vcell = vcell;
	}
	return vcell;
}
Example #15
0
	return average;
}

static void max17040_get_vcell(struct i2c_client *client)
{
	struct max17040_chip *chip = i2c_get_clientdata(client);
	u8 data[2];
	int temp;

	if (is_max17048) {
		temp = max17040_read_word(client, MAX17040_VCELL_MSB);
		data[0] = temp & 0xff;
		data[1] = temp >> 8;
	} else {
		data[0] = max17040_read_reg(client, MAX17040_VCELL_MSB);
		data[1] = max17040_read_reg(client, MAX17040_VCELL_LSB);
	}
	chip->prevcell = chip->vcell;
	chip->vcell = ((data[0] << 4) + (data[1] >> 4)) * 1250;
	if (chip->prevcell == 0)
		chip->prevcell = chip->vcell;

	chip->avgvcell = max17040_get_average_vcell(client);
}

static void max17040_get_soc(struct i2c_client *client)
{
	struct max17040_chip *chip = i2c_get_clientdata(client);
	u8 data[2];
	int temp;
Example #16
0
static void max17040_get_soc(void)
{
	u8 msb;
	u8 lsb;
	int avalue=0;
	int soc=0;
#ifdef MAX17040_SLEEP_DEBUG
	int sky_state=0;
#endif
	dbg_func_in();
	msb = max17040_read_reg(MAX17040_SOC_MSB);
	lsb = max17040_read_reg(MAX17040_SOC_LSB);

	//check i2c error
	if(msb<0 ||lsb <0)
	{
	max17040_data.i2c_state =1;
	}
	else
	{
	max17040_data.i2c_state =0;
	max17040_data.prev_soc=max17040_data.soc;
	}

#ifdef MAX17040_DEBUG_QUICK		
	//quick start code
	soc=SKY_MULT_1000(msb)+(SKY_MULT_1000(lsb)/SKY_SOC_LSB);	
	soc=soc/1000;
#else
	/*//description
	read i2c data [msb=20,lsb=10]
	avalue=20*1000+(10*1000)/256
	*/
	avalue=SKY_MULT_1000(msb)+(SKY_MULT_1000(lsb)/SKY_SOC_LSB);	
	//Ajdusted soc%=(SOC%-EMPTY)/(FULL-EMPTY)*100
	if(avalue>1200)
		soc=(((avalue-SKY_MULT_100(SKY_SOC_EMPTY))*100)/(SKY_MULT_100(SKY_SOC_FULL)-SKY_MULT_100(SKY_SOC_EMPTY)));
	else 
		soc=0;
	if(avalue >1000 && avalue <1200)
		soc=1;	
#endif	
	//logic code
	if(soc>100) //soc>100
		soc=100;
	if(soc==100)
	charge_state=1;
	else
	charge_state=0;		
#ifdef CONFIG_SKY_CHARGING
	if(pm8058_chg_nobattery_factory_cable())
		soc = 10;
#endif
	if(max17040_data.event) // ps2 team shs : soc is changed 
	{
	sleep_dbg("CONFIG CAPACITY [%d] : BATTERY STATS  : [%d]\n",soc,sky_state);
	sleep_dbg("SOC MSB [%d] : LSB [%d] : Lower SOC [%d] : Adjusted SOC [%d] : charge_state [%d] \n",msb,lsb,avalue,soc,charge_state);
	}
	if(soc!=max17040_data.soc)
	max17040_data.event=Events;
	if(soc==0)//ps1 team shs : 0% persent is occured events
	max17040_data.event=Events;
	max17040_check_power(soc);
	mutex_lock(&max17040_data.data_mutex); 	
	max17040_data.soc = soc;	
	mutex_unlock(&max17040_data.data_mutex);
	dbg_func_out();		
}