diff options
| author | Beomho Seo <beomho.seo@samsung.com> | 2015-04-03 04:26:08 -0400 |
|---|---|---|
| committer | Sebastian Reichel <sre@kernel.org> | 2015-04-06 11:46:27 -0400 |
| commit | 709c2c70c8ea73f488971f1de3c39fbdac995951 (patch) | |
| tree | d9e71388036e98b7e6752a813e354bc499227f31 /drivers/power | |
| parent | 7be5ac2c32bd26c47a05367c0135cb6e67b3d452 (diff) | |
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>
Diffstat (limited to 'drivers/power')
| -rw-r--r-- | drivers/power/max17042_battery.c | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index e5645ea6f9d8..bf5a82c9370e 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c | |||
| @@ -63,9 +63,6 @@ | |||
| 63 | #define dP_ACC_100 0x1900 | 63 | #define dP_ACC_100 0x1900 |
| 64 | #define dP_ACC_200 0x3200 | 64 | #define dP_ACC_200 0x3200 |
| 65 | 65 | ||
| 66 | #define MAX17042_IC_VERSION 0x0092 | ||
| 67 | #define MAX17047_IC_VERSION 0x00AC /* same for max17050 */ | ||
| 68 | |||
| 69 | struct max17042_chip { | 66 | struct max17042_chip { |
| 70 | struct i2c_client *client; | 67 | struct i2c_client *client; |
| 71 | struct regmap *regmap; | 68 | struct regmap *regmap; |
| @@ -131,7 +128,7 @@ static int max17042_get_property(struct power_supply *psy, | |||
| 131 | val->intval *= 20000; /* Units of LSB = 20mV */ | 128 | val->intval *= 20000; /* Units of LSB = 20mV */ |
| 132 | break; | 129 | break; |
| 133 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | 130 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
| 134 | if (chip->chip_type == MAX17042) | 131 | if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) |
| 135 | ret = regmap_read(map, MAX17042_V_empty, &data); | 132 | ret = regmap_read(map, MAX17042_V_empty, &data); |
| 136 | else | 133 | else |
| 137 | ret = regmap_read(map, MAX17047_V_empty, &data); | 134 | ret = regmap_read(map, MAX17047_V_empty, &data); |
| @@ -378,7 +375,8 @@ static void max17042_write_config_regs(struct max17042_chip *chip) | |||
| 378 | regmap_write(map, MAX17042_FilterCFG, | 375 | regmap_write(map, MAX17042_FilterCFG, |
| 379 | config->filter_cfg); | 376 | config->filter_cfg); |
| 380 | regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); | 377 | regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); |
| 381 | if (chip->chip_type == MAX17047) | 378 | if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 || |
| 379 | chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050) | ||
| 382 | regmap_write(map, MAX17047_FullSOCThr, | 380 | regmap_write(map, MAX17047_FullSOCThr, |
| 383 | config->full_soc_thresh); | 381 | config->full_soc_thresh); |
| 384 | } | 382 | } |
| @@ -391,7 +389,7 @@ static void max17042_write_custom_regs(struct max17042_chip *chip) | |||
| 391 | max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); | 389 | max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); |
| 392 | max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); | 390 | max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); |
| 393 | max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); | 391 | max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); |
| 394 | if (chip->chip_type == MAX17042) { | 392 | if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) { |
| 395 | regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); | 393 | regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); |
| 396 | max17042_write_verify_reg(map, MAX17042_K_empty0, | 394 | max17042_write_verify_reg(map, MAX17042_K_empty0, |
| 397 | config->kempty0); | 395 | config->kempty0); |
| @@ -500,14 +498,14 @@ static inline void max17042_override_por_values(struct max17042_chip *chip) | |||
| 500 | 498 | ||
| 501 | max17042_override_por(map, MAX17042_FullCAP, config->fullcap); | 499 | max17042_override_por(map, MAX17042_FullCAP, config->fullcap); |
| 502 | max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); | 500 | max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); |
| 503 | if (chip->chip_type == MAX17042) | 501 | if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) |
| 504 | max17042_override_por(map, MAX17042_SOC_empty, | 502 | max17042_override_por(map, MAX17042_SOC_empty, |
| 505 | config->socempty); | 503 | config->socempty); |
| 506 | max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); | 504 | max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); |
| 507 | max17042_override_por(map, MAX17042_dQacc, config->dqacc); | 505 | max17042_override_por(map, MAX17042_dQacc, config->dqacc); |
| 508 | max17042_override_por(map, MAX17042_dPacc, config->dpacc); | 506 | max17042_override_por(map, MAX17042_dPacc, config->dpacc); |
| 509 | 507 | ||
| 510 | if (chip->chip_type == MAX17042) | 508 | if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) |
| 511 | max17042_override_por(map, MAX17042_V_empty, config->vempty); | 509 | max17042_override_por(map, MAX17042_V_empty, config->vempty); |
| 512 | else | 510 | else |
| 513 | max17042_override_por(map, MAX17047_V_empty, config->vempty); | 511 | max17042_override_por(map, MAX17047_V_empty, config->vempty); |
| @@ -709,20 +707,9 @@ static int max17042_probe(struct i2c_client *client, | |||
| 709 | } | 707 | } |
| 710 | 708 | ||
| 711 | i2c_set_clientdata(client, chip); | 709 | i2c_set_clientdata(client, chip); |
| 710 | chip->chip_type = id->driver_data; | ||
| 712 | psy_cfg.drv_data = chip; | 711 | psy_cfg.drv_data = chip; |
| 713 | 712 | ||
| 714 | regmap_read(chip->regmap, MAX17042_DevName, &val); | ||
| 715 | if (val == MAX17042_IC_VERSION) { | ||
| 716 | dev_dbg(&client->dev, "chip type max17042 detected\n"); | ||
| 717 | chip->chip_type = MAX17042; | ||
| 718 | } else if (val == MAX17047_IC_VERSION) { | ||
| 719 | dev_dbg(&client->dev, "chip type max17047/50 detected\n"); | ||
| 720 | chip->chip_type = MAX17047; | ||
| 721 | } else { | ||
| 722 | dev_err(&client->dev, "device version mismatch: %x\n", val); | ||
| 723 | return -EIO; | ||
| 724 | } | ||
| 725 | |||
| 726 | /* When current is not measured, | 713 | /* When current is not measured, |
| 727 | * CURRENT_NOW and CURRENT_AVG properties should be invisible. */ | 714 | * CURRENT_NOW and CURRENT_AVG properties should be invisible. */ |
| 728 | if (!chip->pdata->enable_current_sense) | 715 | if (!chip->pdata->enable_current_sense) |
| @@ -834,9 +821,9 @@ MODULE_DEVICE_TABLE(of, max17042_dt_match); | |||
| 834 | #endif | 821 | #endif |
| 835 | 822 | ||
| 836 | static const struct i2c_device_id max17042_id[] = { | 823 | static const struct i2c_device_id max17042_id[] = { |
| 837 | { "max17042", 0 }, | 824 | { "max17042", MAXIM_DEVICE_TYPE_MAX17042 }, |
| 838 | { "max17047", 1 }, | 825 | { "max17047", MAXIM_DEVICE_TYPE_MAX17047 }, |
| 839 | { "max17050", 2 }, | 826 | { "max17050", MAXIM_DEVICE_TYPE_MAX17050 }, |
| 840 | { } | 827 | { } |
| 841 | }; | 828 | }; |
| 842 | MODULE_DEVICE_TABLE(i2c, max17042_id); | 829 | MODULE_DEVICE_TABLE(i2c, max17042_id); |
