Skip to content

Commit 9a8422d

Browse files
Ramakrishna PallalaAnton Vorontsov
authored andcommitted
max17042_battery: Add support for max17047/50 chip
max17047 is improved version of max17042 chip. It has few HW bug fixes with minor changes in register set. max17050 is same as max17047 chip except its silicon packging. So from driver's point of view there is no difference btw max1047 and max1050. This patch adds the support to dynamically detect the chip type and adds steps to initialize the max17047 chip. Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
1 parent b1f092f commit 9a8422d

3 files changed

Lines changed: 78 additions & 13 deletions

File tree

‎drivers/power/Kconfig‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,15 @@ config BATTERY_MAX17040
181181
to operate with a single lithium cell
182182

183183
config BATTERY_MAX17042
184-
tristate "Maxim MAX17042/8997/8966 Fuel Gauge"
184+
tristate "Maxim MAX17042/17047/17050/8997/8966 Fuel Gauge"
185185
depends on I2C
186186
help
187187
MAX17042 is fuel-gauge systems for lithium-ion (Li+) batteries
188188
in handheld and portable equipment. The MAX17042 is configured
189189
to operate with a single lithium cell. MAX8997 and MAX8966 are
190190
multi-function devices that include fuel gauages that are compatible
191-
with MAX17042.
191+
with MAX17042. This driver also supports max17047/50 chips which are
192+
improved version of max17042.
192193

193194
config BATTERY_Z2
194195
tristate "Z2 battery driver"

‎drivers/power/max17042_battery.c‎

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@
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+
6568
struct 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

394404
static 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

410431
static 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

515546
static 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
779822
static const struct of_device_id max17042_dt_match[] = {
780823
{ .compatible = "maxim,max17042" },
824+
{ .compatible = "maxim,max17047" },
825+
{ .compatible = "maxim,max17050" },
781826
{ },
782827
};
783828
MODULE_DEVICE_TABLE(of, max17042_dt_match);
784829
#endif
785830

786831
static const struct i2c_device_id max17042_id[] = {
787832
{ "max17042", 0 },
833+
{ "max17047", 1 },
834+
{ "max17050", 2 },
788835
{ }
789836
};
790837
MODULE_DEVICE_TABLE(i2c, max17042_id);

‎include/linux/power/max17042_battery.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ enum max17042_register {
116116
MAX17042_VFSOC = 0xFF,
117117
};
118118

119+
/* Registers specific to max17047/50 */
120+
enum max17047_register {
121+
MAX17047_QRTbl00 = 0x12,
122+
MAX17047_FullSOCThr = 0x13,
123+
MAX17047_QRTbl10 = 0x22,
124+
MAX17047_QRTbl20 = 0x32,
125+
MAX17047_V_empty = 0x3A,
126+
MAX17047_QRTbl30 = 0x42,
127+
};
128+
129+
enum max170xx_chip_type {MAX17042, MAX17047};
130+
119131
/*
120132
* used for setting a register to a desired value
121133
* addr : address for a register
@@ -144,6 +156,7 @@ struct max17042_config_data {
144156
u16 shdntimer; /* 0x03F */
145157

146158
/* App data */
159+
u16 full_soc_thresh; /* 0x13 */
147160
u16 design_cap; /* 0x18 */
148161
u16 ichgt_term; /* 0x1E */
149162

@@ -162,6 +175,10 @@ struct max17042_config_data {
162175
u16 lavg_empty; /* 0x36 */
163176
u16 dqacc; /* 0x45 */
164177
u16 dpacc; /* 0x46 */
178+
u16 qrtbl00; /* 0x12 */
179+
u16 qrtbl10; /* 0x22 */
180+
u16 qrtbl20; /* 0x32 */
181+
u16 qrtbl30; /* 0x42 */
165182

166183
/* Cell technology from power_supply.h */
167184
u16 cell_technology;

0 commit comments

Comments
 (0)