6262#define dP_ACC_100 0x1900
6363#define dP_ACC_200 0x3200
6464
65+ #define MAX17042_IC_VERSION 0x0092
66+ #define MAX17047_IC_VERSION 0x00AC /* same for max17050 */
67+
6568struct max17042_chip {
6669 struct i2c_client * client ;
6770 struct power_supply battery ;
71+ enum max170xx_chip_type chip_type ;
6872 struct max17042_platform_data * pdata ;
6973 struct work_struct work ;
7074 int init_complete ;
@@ -152,7 +156,10 @@ static int max17042_get_property(struct power_supply *psy,
152156 val -> intval *= 20000 ; /* Units of LSB = 20mV */
153157 break ;
154158 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN :
155- ret = max17042_read_reg (chip -> client , MAX17042_V_empty );
159+ if (chip -> chip_type == MAX17042 )
160+ ret = max17042_read_reg (chip -> client , MAX17042_V_empty );
161+ else
162+ ret = max17042_read_reg (chip -> client , MAX17047_V_empty );
156163 if (ret < 0 )
157164 return ret ;
158165
@@ -389,6 +396,9 @@ static void max17042_write_config_regs(struct max17042_chip *chip)
389396 max17042_write_reg (chip -> client , MAX17042_FilterCFG ,
390397 config -> filter_cfg );
391398 max17042_write_reg (chip -> client , MAX17042_RelaxCFG , config -> relax_cfg );
399+ if (chip -> chip_type == MAX17047 )
400+ max17042_write_reg (chip -> client , MAX17047_FullSOCThr ,
401+ config -> full_soc_thresh );
392402}
393403
394404static void max17042_write_custom_regs (struct max17042_chip * chip )
@@ -399,12 +409,23 @@ static void max17042_write_custom_regs(struct max17042_chip *chip)
399409 config -> rcomp0 );
400410 max17042_write_verify_reg (chip -> client , MAX17042_TempCo ,
401411 config -> tcompc0 );
402- max17042_write_reg (chip -> client , MAX17042_EmptyTempCo ,
403- config -> empty_tempco );
404- max17042_write_verify_reg (chip -> client , MAX17042_K_empty0 ,
405- config -> kempty0 );
406412 max17042_write_verify_reg (chip -> client , MAX17042_ICHGTerm ,
407413 config -> ichgt_term );
414+ if (chip -> chip_type == MAX17042 ) {
415+ max17042_write_reg (chip -> client , MAX17042_EmptyTempCo ,
416+ config -> empty_tempco );
417+ max17042_write_verify_reg (chip -> client , MAX17042_K_empty0 ,
418+ config -> kempty0 );
419+ } else {
420+ max17042_write_verify_reg (chip -> client , MAX17047_QRTbl00 ,
421+ config -> qrtbl00 );
422+ max17042_write_verify_reg (chip -> client , MAX17047_QRTbl10 ,
423+ config -> qrtbl10 );
424+ max17042_write_verify_reg (chip -> client , MAX17047_QRTbl20 ,
425+ config -> qrtbl20 );
426+ max17042_write_verify_reg (chip -> client , MAX17047_QRTbl30 ,
427+ config -> qrtbl30 );
428+ }
408429}
409430
410431static void max17042_update_capacity_regs (struct max17042_chip * chip )
@@ -460,6 +481,8 @@ static void max17042_load_new_capacity_params(struct max17042_chip *chip)
460481 config -> design_cap );
461482 max17042_write_verify_reg (chip -> client , MAX17042_FullCAPNom ,
462483 config -> fullcapnom );
484+ /* Update SOC register with new SOC */
485+ max17042_write_reg (chip -> client , MAX17042_RepSOC , vfSoc );
463486}
464487
465488/*
@@ -496,20 +519,28 @@ static inline void max17042_override_por_values(struct max17042_chip *chip)
496519
497520 max17042_override_por (client , MAX17042_FullCAP , config -> fullcap );
498521 max17042_override_por (client , MAX17042_FullCAPNom , config -> fullcapnom );
499- max17042_override_por (client , MAX17042_SOC_empty , config -> socempty );
522+ if (chip -> chip_type == MAX17042 )
523+ max17042_override_por (client , MAX17042_SOC_empty ,
524+ config -> socempty );
500525 max17042_override_por (client , MAX17042_LAvg_empty , config -> lavg_empty );
501526 max17042_override_por (client , MAX17042_dQacc , config -> dqacc );
502527 max17042_override_por (client , MAX17042_dPacc , config -> dpacc );
503528
504- max17042_override_por (client , MAX17042_V_empty , config -> vempty );
529+ if (chip -> chip_type == MAX17042 )
530+ max17042_override_por (client , MAX17042_V_empty , config -> vempty );
531+ else
532+ max17042_override_por (client , MAX17047_V_empty , config -> vempty );
505533 max17042_override_por (client , MAX17042_TempNom , config -> temp_nom );
506534 max17042_override_por (client , MAX17042_TempLim , config -> temp_lim );
507535 max17042_override_por (client , MAX17042_FCTC , config -> fctc );
508536 max17042_override_por (client , MAX17042_RCOMP0 , config -> rcomp0 );
509537 max17042_override_por (client , MAX17042_TempCo , config -> tcompc0 );
510- max17042_override_por (client , MAX17042_EmptyTempCo ,
511- config -> empty_tempco );
512- max17042_override_por (client , MAX17042_K_empty0 , config -> kempty0 );
538+ if (chip -> chip_type ) {
539+ max17042_override_por (client , MAX17042_EmptyTempCo ,
540+ config -> empty_tempco );
541+ max17042_override_por (client , MAX17042_K_empty0 ,
542+ config -> kempty0 );
543+ }
513544}
514545
515546static int max17042_init_chip (struct max17042_chip * chip )
@@ -666,7 +697,19 @@ static int __devinit max17042_probe(struct i2c_client *client,
666697
667698 i2c_set_clientdata (client , chip );
668699
669- chip -> battery .name = "max17042_battery" ;
700+ ret = max17042_read_reg (chip -> client , MAX17042_DevName );
701+ if (ret == MAX17042_IC_VERSION ) {
702+ dev_dbg (& client -> dev , "chip type max17042 detected\n" );
703+ chip -> chip_type = MAX17042 ;
704+ } else if (ret == MAX17047_IC_VERSION ) {
705+ dev_dbg (& client -> dev , "chip type max17047/50 detected\n" );
706+ chip -> chip_type = MAX17047 ;
707+ } else {
708+ dev_err (& client -> dev , "device version mismatch: %x\n" , ret );
709+ return - EIO ;
710+ }
711+
712+ chip -> battery .name = "max170xx_battery" ;
670713 chip -> battery .type = POWER_SUPPLY_TYPE_BATTERY ;
671714 chip -> battery .get_property = max17042_get_property ;
672715 chip -> battery .properties = max17042_battery_props ;
@@ -778,13 +821,17 @@ static const struct dev_pm_ops max17042_pm_ops = {
778821#ifdef CONFIG_OF
779822static const struct of_device_id max17042_dt_match [] = {
780823 { .compatible = "maxim,max17042" },
824+ { .compatible = "maxim,max17047" },
825+ { .compatible = "maxim,max17050" },
781826 { },
782827};
783828MODULE_DEVICE_TABLE (of , max17042_dt_match );
784829#endif
785830
786831static const struct i2c_device_id max17042_id [] = {
787832 { "max17042" , 0 },
833+ { "max17047" , 1 },
834+ { "max17050" , 2 },
788835 { }
789836};
790837MODULE_DEVICE_TABLE (i2c , max17042_id );
0 commit comments