static void bq27541_set(void) { struct bq27541_device_info *di; int i = 0; u8 buf[2]; di = bq27541_di; printk("enter 0x41\n"); buf[0] = 0x41; buf[1] = 0x00; bq27541_write(di->client,0x00,buf,2); msleep(1500); printk("enter 0x21\n"); buf[0] = 0x21; buf[1] = 0x00; bq27541_write(di->client,0x00,buf,2); buf[0] = 0; buf[1] = 0; bq27541_read(di->client,0x00,buf,2); while((buf[0] & 0x04)&&(i<5)) { printk("enter more 0x21 times i = %d\n",i); mdelay(1000); buf[0] = 0x21; buf[1] = 0x00; bq27541_write(di->client,0x00,buf,2); buf[0] = 0; buf[1] = 0; bq27541_read(di->client,0x00,buf,2); i++; } if(i>5) printk("write 0x21 error\n"); else printk("bq27541 write 0x21 success\n"); }
/* * Return the battery Relative State-of-Charge * Or < 0 if something fails. */ static int bq27541_battery_rsoc(struct bq27541_device_info *di) { int ret; int rsoc = 0; int flags = 0; int status = 0; #if 0 int nvcap = 0,facap = 0,remcap=0,fccap=0,full=0,cnt=0; int art = 0, artte = 0, ai = 0, tte = 0, ttf = 0, si = 0; int stte = 0, mli = 0, mltte = 0, ae = 0, ap = 0, ttecp = 0, cc = 0; #endif u8 buf[2]; #if defined (CONFIG_NO_BATTERY_IC) return 100; #endif if(virtual_battery_enable == 1) return 50/*100*/; ret = bq27541_read(di->client,BQ27500_REG_SOC,buf,2); if (ret<0) { dev_err(di->dev, "error reading relative State-of-Charge\n"); return ret; } rsoc = get_unaligned_le16(buf); DBG("Enter:%s %d--read rsoc = %d\n",__FUNCTION__,__LINE__,rsoc); /* covert the capacity range */ rsoc = min(rsoc, 100); if ((g_pdata != NULL) && g_pdata->capacity_max && g_pdata->capacity_min) { rsoc = max(rsoc, g_pdata->capacity_min); rsoc = ((rsoc - g_pdata->capacity_min) * 100 + (g_pdata->capacity_max - g_pdata->capacity_min) / 2) / (g_pdata->capacity_max - g_pdata->capacity_min); } bq27541_cap = rsoc; /*check full flags,if not full, show 99%*/ ret = bq27541_read(di->client,BQ27x00_REG_FLAGS, buf, 2); if (ret < 0) { dev_err(di->dev, "error reading flags\n"); return ret; } flags = get_unaligned_le16(buf); DBG("Enter:%s %d--flags = 0x%x\n",__FUNCTION__,__LINE__,flags); if ((bq27541_cap > 99) && (flags & BQ27500_FLAG_FC)) status = POWER_SUPPLY_STATUS_FULL; if(status != POWER_SUPPLY_STATUS_FULL) rsoc = min(rsoc, 99); DBG("Enter:%s %d--cal rsoc = %d\n",__FUNCTION__,__LINE__,rsoc); #if defined (CONFIG_NO_BATTERY_IC) rsoc = 100; #endif #if 0 //other register information, for debug use ret = bq27541_read(di->client,0x0c,buf,2); //NominalAvailableCapacity nvcap = get_unaligned_le16(buf); DBG("\nEnter:%s %d--nvcap = %d\n",__FUNCTION__,__LINE__,nvcap); ret = bq27541_read(di->client,0x0e,buf,2); //FullAvailableCapacity facap = get_unaligned_le16(buf); DBG("Enter:%s %d--facap = %d\n",__FUNCTION__,__LINE__,facap); ret = bq27541_read(di->client,0x10,buf,2); //RemainingCapacity remcap = get_unaligned_le16(buf); DBG("Enter:%s %d--remcap = %d\n",__FUNCTION__,__LINE__,remcap); ret = bq27541_read(di->client,0x12,buf,2); //FullChargeCapacity fccap = get_unaligned_le16(buf); DBG("Enter:%s %d--fccap = %d\n",__FUNCTION__,__LINE__,fccap); ret = bq27541_read(di->client,0x3c,buf,2); //DesignCapacity full = get_unaligned_le16(buf); DBG("Enter:%s %d--DesignCapacity = %d\n",__FUNCTION__,__LINE__,full); buf[0] = 0x00; //CONTROL_STATUS buf[1] = 0x00; bq27541_write(di->client,0x00,buf,2); ret = bq27541_read(di->client,0x00,buf,2); cnt = get_unaligned_le16(buf); DBG("Enter:%s %d--Control status = %x\n",__FUNCTION__,__LINE__,cnt); ret = bq27541_read(di->client,0x02,buf,2); //AtRate art = get_unaligned_le16(buf); DBG("Enter:%s %d--AtRate = %d\n",__FUNCTION__,__LINE__,art); ret = bq27541_read(di->client,0x04,buf,2); //AtRateTimeToEmpty artte = get_unaligned_le16(buf); DBG("Enter:%s %d--AtRateTimeToEmpty = %d\n",__FUNCTION__,__LINE__,artte); ret = bq27541_read(di->client,0x14,buf,2); //AverageCurrent ai = get_unaligned_le16(buf); DBG("Enter:%s %d--AverageCurrent = %d\n",__FUNCTION__,__LINE__,ai); ret = bq27541_read(di->client,0x16,buf,2); //TimeToEmpty tte = get_unaligned_le16(buf); DBG("Enter:%s %d--TimeToEmpty = %d\n",__FUNCTION__,__LINE__,tte); ret = bq27541_read(di->client,0x18,buf,2); //TimeToFull ttf = get_unaligned_le16(buf); DBG("Enter:%s %d--TimeToFull = %d\n",__FUNCTION__,__LINE__,ttf); ret = bq27541_read(di->client,0x1a,buf,2); //StandbyCurrent si = get_unaligned_le16(buf); DBG("Enter:%s %d--StandbyCurrent = %d\n",__FUNCTION__,__LINE__,si); ret = bq27541_read(di->client,0x1c,buf,2); //StandbyTimeToEmpty stte = get_unaligned_le16(buf); DBG("Enter:%s %d--StandbyTimeToEmpty = %d\n",__FUNCTION__,__LINE__,stte); ret = bq27541_read(di->client,0x1e,buf,2); //MaxLoadCurrent mli = get_unaligned_le16(buf); DBG("Enter:%s %d--MaxLoadCurrent = %d\n",__FUNCTION__,__LINE__,mli); ret = bq27541_read(di->client,0x20,buf,2); //MaxLoadTimeToEmpty mltte = get_unaligned_le16(buf); DBG("Enter:%s %d--MaxLoadTimeToEmpty = %d\n",__FUNCTION__,__LINE__,mltte); ret = bq27541_read(di->client,0x22,buf,2); //AvailableEnergy ae = get_unaligned_le16(buf); DBG("Enter:%s %d--AvailableEnergy = %d\n",__FUNCTION__,__LINE__,ae); ret = bq27541_read(di->client,0x24,buf,2); //AveragePower ap = get_unaligned_le16(buf); DBG("Enter:%s %d--AveragePower = %d\n",__FUNCTION__,__LINE__,ap); ret = bq27541_read(di->client,0x26,buf,2); //TTEatConstantPower ttecp = get_unaligned_le16(buf); DBG("Enter:%s %d--TTEatConstantPower = %d\n",__FUNCTION__,__LINE__,ttecp); ret = bq27541_read(di->client,0x2a,buf,2); //CycleCount cc = get_unaligned_le16(buf); DBG("Enter:%s %d--CycleCount = %d\n",__FUNCTION__,__LINE__,cc); #endif return rsoc; }
/* * Return the battery Relative State-of-Charge * Or < 0 if something fails. */ static int bq27541_battery_rsoc(struct bq27541_device_info *di) { int ret; int rsoc = 0; #if 0 int nvcap = 0,facap = 0,remcap=0,fccap=0,full=0,cnt=0; int art = 0, artte = 0, ai = 0, tte = 0, ttf = 0, si = 0; int stte = 0, mli = 0, mltte = 0, ae = 0, ap = 0, ttecp = 0, cc = 0; #endif u8 buf[2]; #if defined (CONFIG_NO_BATTERY_IC) return 100; #endif if(virtual_battery_enable == 1) return 50/*100*/; ret = bq27541_read(di->client,BQ27500_REG_SOC,buf,2); if (ret<0) { dev_err(di->dev, "error reading relative State-of-Charge\n"); return ret; } rsoc = get_unaligned_le16(buf); DBG("Enter:%s %d--rsoc = %d\n",__FUNCTION__,__LINE__,rsoc); #if defined (CONFIG_NO_BATTERY_IC) rsoc = 100; #endif #if 0 //other register information, for debug use ret = bq27541_read(di->client,0x0c,buf,2); //NominalAvailableCapacity nvcap = get_unaligned_le16(buf); DBG("\nEnter:%s %d--nvcap = %d\n",__FUNCTION__,__LINE__,nvcap); ret = bq27541_read(di->client,0x0e,buf,2); //FullAvailableCapacity facap = get_unaligned_le16(buf); DBG("Enter:%s %d--facap = %d\n",__FUNCTION__,__LINE__,facap); ret = bq27541_read(di->client,0x10,buf,2); //RemainingCapacity remcap = get_unaligned_le16(buf); DBG("Enter:%s %d--remcap = %d\n",__FUNCTION__,__LINE__,remcap); ret = bq27541_read(di->client,0x12,buf,2); //FullChargeCapacity fccap = get_unaligned_le16(buf); DBG("Enter:%s %d--fccap = %d\n",__FUNCTION__,__LINE__,fccap); ret = bq27541_read(di->client,0x3c,buf,2); //DesignCapacity full = get_unaligned_le16(buf); DBG("Enter:%s %d--DesignCapacity = %d\n",__FUNCTION__,__LINE__,full); buf[0] = 0x00; //CONTROL_STATUS buf[1] = 0x00; bq27541_write(di->client,0x00,buf,2); ret = bq27541_read(di->client,0x00,buf,2); cnt = get_unaligned_le16(buf); DBG("Enter:%s %d--Control status = %x\n",__FUNCTION__,__LINE__,cnt); ret = bq27541_read(di->client,0x02,buf,2); //AtRate art = get_unaligned_le16(buf); DBG("Enter:%s %d--AtRate = %d\n",__FUNCTION__,__LINE__,art); ret = bq27541_read(di->client,0x04,buf,2); //AtRateTimeToEmpty artte = get_unaligned_le16(buf); DBG("Enter:%s %d--AtRateTimeToEmpty = %d\n",__FUNCTION__,__LINE__,artte); ret = bq27541_read(di->client,0x14,buf,2); //AverageCurrent ai = get_unaligned_le16(buf); DBG("Enter:%s %d--AverageCurrent = %d\n",__FUNCTION__,__LINE__,ai); ret = bq27541_read(di->client,0x16,buf,2); //TimeToEmpty tte = get_unaligned_le16(buf); DBG("Enter:%s %d--TimeToEmpty = %d\n",__FUNCTION__,__LINE__,tte); ret = bq27541_read(di->client,0x18,buf,2); //TimeToFull ttf = get_unaligned_le16(buf); DBG("Enter:%s %d--TimeToFull = %d\n",__FUNCTION__,__LINE__,ttf); ret = bq27541_read(di->client,0x1a,buf,2); //StandbyCurrent si = get_unaligned_le16(buf); DBG("Enter:%s %d--StandbyCurrent = %d\n",__FUNCTION__,__LINE__,si); ret = bq27541_read(di->client,0x1c,buf,2); //StandbyTimeToEmpty stte = get_unaligned_le16(buf); DBG("Enter:%s %d--StandbyTimeToEmpty = %d\n",__FUNCTION__,__LINE__,stte); ret = bq27541_read(di->client,0x1e,buf,2); //MaxLoadCurrent mli = get_unaligned_le16(buf); DBG("Enter:%s %d--MaxLoadCurrent = %d\n",__FUNCTION__,__LINE__,mli); ret = bq27541_read(di->client,0x20,buf,2); //MaxLoadTimeToEmpty mltte = get_unaligned_le16(buf); DBG("Enter:%s %d--MaxLoadTimeToEmpty = %d\n",__FUNCTION__,__LINE__,mltte); ret = bq27541_read(di->client,0x22,buf,2); //AvailableEnergy ae = get_unaligned_le16(buf); DBG("Enter:%s %d--AvailableEnergy = %d\n",__FUNCTION__,__LINE__,ae); ret = bq27541_read(di->client,0x24,buf,2); //AveragePower ap = get_unaligned_le16(buf); DBG("Enter:%s %d--AveragePower = %d\n",__FUNCTION__,__LINE__,ap); ret = bq27541_read(di->client,0x26,buf,2); //TTEatConstantPower ttecp = get_unaligned_le16(buf); DBG("Enter:%s %d--TTEatConstantPower = %d\n",__FUNCTION__,__LINE__,ttecp); ret = bq27541_read(di->client,0x2a,buf,2); //CycleCount cc = get_unaligned_le16(buf); DBG("Enter:%s %d--CycleCount = %d\n",__FUNCTION__,__LINE__,cc); #endif return rsoc; }