2323 * http://focus.ti.com/docs/prod/folders/print/bq27000.html
2424 * http://focus.ti.com/docs/prod/folders/print/bq27500.html
2525 * http://www.ti.com/product/bq27425-g1
26+ * http://www.ti.com/product/BQ27742-G1
2627 */
2728
2829#include <linux/device.h>
7172#define BQ27500_FLAG_FC BIT(9)
7273#define BQ27500_FLAG_OTC BIT(15)
7374
75+ #define BQ27742_POWER_AVG 0x76
76+
7477/* bq27425 register addresses are same as bq27x00 addresses minus 4 */
7578#define BQ27425_REG_OFFSET 0x04
7679#define BQ27425_REG_SOC 0x18 /* Register address plus offset */
@@ -83,7 +86,7 @@ struct bq27x00_access_methods {
8386 int (* read )(struct bq27x00_device_info * di , u8 reg , bool single );
8487};
8588
86- enum bq27x00_chip { BQ27000 , BQ27500 , BQ27425 };
89+ enum bq27x00_chip { BQ27000 , BQ27500 , BQ27425 , BQ27742 };
8790
8891struct bq27x00_reg_cache {
8992 int temperature ;
@@ -152,6 +155,24 @@ static enum power_supply_property bq27425_battery_props[] = {
152155 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN ,
153156};
154157
158+ static enum power_supply_property bq27742_battery_props [] = {
159+ POWER_SUPPLY_PROP_STATUS ,
160+ POWER_SUPPLY_PROP_PRESENT ,
161+ POWER_SUPPLY_PROP_VOLTAGE_NOW ,
162+ POWER_SUPPLY_PROP_CURRENT_NOW ,
163+ POWER_SUPPLY_PROP_CAPACITY ,
164+ POWER_SUPPLY_PROP_CAPACITY_LEVEL ,
165+ POWER_SUPPLY_PROP_TEMP ,
166+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW ,
167+ POWER_SUPPLY_PROP_TECHNOLOGY ,
168+ POWER_SUPPLY_PROP_CHARGE_FULL ,
169+ POWER_SUPPLY_PROP_CHARGE_NOW ,
170+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN ,
171+ POWER_SUPPLY_PROP_CYCLE_COUNT ,
172+ POWER_SUPPLY_PROP_POWER_AVG ,
173+ POWER_SUPPLY_PROP_HEALTH ,
174+ };
175+
155176static unsigned int poll_interval = 360 ;
156177module_param (poll_interval , uint , 0644 );
157178MODULE_PARM_DESC (poll_interval , "battery poll interval in seconds - " \
@@ -176,7 +197,7 @@ static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
176197 */
177198static bool bq27xxx_is_chip_version_higher (struct bq27x00_device_info * di )
178199{
179- if (di -> chip == BQ27425 || di -> chip == BQ27500 )
200+ if (di -> chip == BQ27425 || di -> chip == BQ27500 || di -> chip == BQ27742 )
180201 return true;
181202 return false;
182203}
@@ -189,7 +210,7 @@ static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
189210{
190211 int rsoc ;
191212
192- if (di -> chip == BQ27500 )
213+ if (di -> chip == BQ27500 || di -> chip == BQ27742 )
193214 rsoc = bq27x00_read (di , BQ27500_REG_SOC , false);
194215 else if (di -> chip == BQ27425 )
195216 rsoc = bq27x00_read (di , BQ27425_REG_SOC , false);
@@ -414,6 +435,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
414435 struct bq27x00_reg_cache cache = {0 , };
415436 bool is_bq27500 = di -> chip == BQ27500 ;
416437 bool is_bq27425 = di -> chip == BQ27425 ;
438+ bool is_bq27742 = di -> chip == BQ27742 ;
417439
418440 cache .flags = bq27x00_read (di , BQ27x00_REG_FLAGS , !is_bq27500 );
419441 if ((cache .flags & 0xff ) == 0xff )
@@ -432,7 +454,11 @@ static void bq27x00_update(struct bq27x00_device_info *di)
432454 cache .health = - ENODATA ;
433455 } else {
434456 cache .capacity = bq27x00_battery_read_rsoc (di );
435- if (!is_bq27425 ) {
457+ if (is_bq27742 )
458+ cache .time_to_empty =
459+ bq27x00_battery_read_time (di ,
460+ BQ27x00_REG_TTE );
461+ else if (!is_bq27425 ) {
436462 cache .energy = bq27x00_battery_read_energy (di );
437463 cache .time_to_empty =
438464 bq27x00_battery_read_time (di ,
@@ -444,14 +470,22 @@ static void bq27x00_update(struct bq27x00_device_info *di)
444470 bq27x00_battery_read_time (di ,
445471 BQ27x00_REG_TTF );
446472 }
447- cache .charge_full = bq27x00_battery_read_lmd (di );
473+ if (!is_bq27742 )
474+ cache .charge_full =
475+ bq27x00_battery_read_lmd (di );
448476 cache .health = bq27x00_battery_read_health (di );
449477 }
450478 cache .temperature = bq27x00_battery_read_temperature (di );
451479 if (!is_bq27425 )
452480 cache .cycle_count = bq27x00_battery_read_cyct (di );
453- cache .power_avg =
454- bq27x00_battery_read_pwr_avg (di , BQ27x00_POWER_AVG );
481+ if (is_bq27742 )
482+ cache .power_avg =
483+ bq27x00_battery_read_pwr_avg (di ,
484+ BQ27742_POWER_AVG );
485+ else
486+ cache .power_avg =
487+ bq27x00_battery_read_pwr_avg (di ,
488+ BQ27x00_POWER_AVG );
455489
456490 /* We only have to read charge design full once */
457491 if (di -> charge_design_full <= 0 )
@@ -702,6 +736,9 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
702736 if (di -> chip == BQ27425 ) {
703737 di -> bat .properties = bq27425_battery_props ;
704738 di -> bat .num_properties = ARRAY_SIZE (bq27425_battery_props );
739+ } else if (di -> chip == BQ27742 ) {
740+ di -> bat .properties = bq27742_battery_props ;
741+ di -> bat .num_properties = ARRAY_SIZE (bq27742_battery_props );
705742 } else {
706743 di -> bat .properties = bq27x00_battery_props ;
707744 di -> bat .num_properties = ARRAY_SIZE (bq27x00_battery_props );
@@ -858,6 +895,7 @@ static const struct i2c_device_id bq27x00_id[] = {
858895 { "bq27200" , BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
859896 { "bq27500" , BQ27500 },
860897 { "bq27425" , BQ27425 },
898+ { "bq27742" , BQ27742 },
861899 {},
862900};
863901MODULE_DEVICE_TABLE (i2c , bq27x00_id );
0 commit comments