power: max17042_battery: Use reg type instead of chip type

Currently, max17042 battery driver choose register map by MAX17042_DevName
register. But it is return IC specific firmware version. So other maxim chip
hard to use this drvier. This patch choose chip type from driver_data.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
This commit is contained in:
Beomho Seo 2015-04-03 17:26:08 +09:00 committed by Sebastian Reichel
parent 7be5ac2c32
commit 709c2c70c8
2 changed files with 18 additions and 24 deletions

View File

@ -63,9 +63,6 @@
#define dP_ACC_100 0x1900 #define dP_ACC_100 0x1900
#define dP_ACC_200 0x3200 #define dP_ACC_200 0x3200
#define MAX17042_IC_VERSION 0x0092
#define MAX17047_IC_VERSION 0x00AC /* same for max17050 */
struct max17042_chip { struct max17042_chip {
struct i2c_client *client; struct i2c_client *client;
struct regmap *regmap; struct regmap *regmap;
@ -131,7 +128,7 @@ static int max17042_get_property(struct power_supply *psy,
val->intval *= 20000; /* Units of LSB = 20mV */ val->intval *= 20000; /* Units of LSB = 20mV */
break; break;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
if (chip->chip_type == MAX17042) if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
ret = regmap_read(map, MAX17042_V_empty, &data); ret = regmap_read(map, MAX17042_V_empty, &data);
else else
ret = regmap_read(map, MAX17047_V_empty, &data); ret = regmap_read(map, MAX17047_V_empty, &data);
@ -378,7 +375,8 @@ static void max17042_write_config_regs(struct max17042_chip *chip)
regmap_write(map, MAX17042_FilterCFG, regmap_write(map, MAX17042_FilterCFG,
config->filter_cfg); config->filter_cfg);
regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg);
if (chip->chip_type == MAX17047) if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 ||
chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)
regmap_write(map, MAX17047_FullSOCThr, regmap_write(map, MAX17047_FullSOCThr,
config->full_soc_thresh); config->full_soc_thresh);
} }
@ -391,7 +389,7 @@ static void max17042_write_custom_regs(struct max17042_chip *chip)
max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0);
max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0);
max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term);
if (chip->chip_type == MAX17042) { if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) {
regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco);
max17042_write_verify_reg(map, MAX17042_K_empty0, max17042_write_verify_reg(map, MAX17042_K_empty0,
config->kempty0); config->kempty0);
@ -500,14 +498,14 @@ static inline void max17042_override_por_values(struct max17042_chip *chip)
max17042_override_por(map, MAX17042_FullCAP, config->fullcap); max17042_override_por(map, MAX17042_FullCAP, config->fullcap);
max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom);
if (chip->chip_type == MAX17042) if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
max17042_override_por(map, MAX17042_SOC_empty, max17042_override_por(map, MAX17042_SOC_empty,
config->socempty); config->socempty);
max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
max17042_override_por(map, MAX17042_dQacc, config->dqacc); max17042_override_por(map, MAX17042_dQacc, config->dqacc);
max17042_override_por(map, MAX17042_dPacc, config->dpacc); max17042_override_por(map, MAX17042_dPacc, config->dpacc);
if (chip->chip_type == MAX17042) if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
max17042_override_por(map, MAX17042_V_empty, config->vempty); max17042_override_por(map, MAX17042_V_empty, config->vempty);
else else
max17042_override_por(map, MAX17047_V_empty, config->vempty); max17042_override_por(map, MAX17047_V_empty, config->vempty);
@ -709,20 +707,9 @@ static int max17042_probe(struct i2c_client *client,
} }
i2c_set_clientdata(client, chip); i2c_set_clientdata(client, chip);
chip->chip_type = id->driver_data;
psy_cfg.drv_data = chip; psy_cfg.drv_data = chip;
regmap_read(chip->regmap, MAX17042_DevName, &val);
if (val == MAX17042_IC_VERSION) {
dev_dbg(&client->dev, "chip type max17042 detected\n");
chip->chip_type = MAX17042;
} else if (val == MAX17047_IC_VERSION) {
dev_dbg(&client->dev, "chip type max17047/50 detected\n");
chip->chip_type = MAX17047;
} else {
dev_err(&client->dev, "device version mismatch: %x\n", val);
return -EIO;
}
/* When current is not measured, /* When current is not measured,
* CURRENT_NOW and CURRENT_AVG properties should be invisible. */ * CURRENT_NOW and CURRENT_AVG properties should be invisible. */
if (!chip->pdata->enable_current_sense) if (!chip->pdata->enable_current_sense)
@ -834,9 +821,9 @@ MODULE_DEVICE_TABLE(of, max17042_dt_match);
#endif #endif
static const struct i2c_device_id max17042_id[] = { static const struct i2c_device_id max17042_id[] = {
{ "max17042", 0 }, { "max17042", MAXIM_DEVICE_TYPE_MAX17042 },
{ "max17047", 1 }, { "max17047", MAXIM_DEVICE_TYPE_MAX17047 },
{ "max17050", 2 }, { "max17050", MAXIM_DEVICE_TYPE_MAX17050 },
{ } { }
}; };
MODULE_DEVICE_TABLE(i2c, max17042_id); MODULE_DEVICE_TABLE(i2c, max17042_id);

View File

@ -126,7 +126,14 @@ enum max17047_register {
MAX17047_QRTbl30 = 0x42, MAX17047_QRTbl30 = 0x42,
}; };
enum max170xx_chip_type {MAX17042, MAX17047}; enum max170xx_chip_type {
MAXIM_DEVICE_TYPE_UNKNOWN = 0,
MAXIM_DEVICE_TYPE_MAX17042,
MAXIM_DEVICE_TYPE_MAX17047,
MAXIM_DEVICE_TYPE_MAX17050,
MAXIM_DEVICE_TYPE_NUM
};
/* /*
* used for setting a register to a desired value * used for setting a register to a desired value