Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Beomho Seo and committed by
Sebastian Reichel
709c2c70 7be5ac2c

+18 -24
+10 -23
drivers/power/max17042_battery.c
··· 63 63 #define dP_ACC_100 0x1900 64 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 66 struct max17042_chip { 70 67 struct i2c_client *client; 71 68 struct regmap *regmap; ··· 128 131 val->intval *= 20000; /* Units of LSB = 20mV */ 129 132 break; 130 133 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 131 - if (chip->chip_type == MAX17042) 134 + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) 132 135 ret = regmap_read(map, MAX17042_V_empty, &data); 133 136 else 134 137 ret = regmap_read(map, MAX17047_V_empty, &data); ··· 375 378 regmap_write(map, MAX17042_FilterCFG, 376 379 config->filter_cfg); 377 380 regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); 378 - if (chip->chip_type == MAX17047) 381 + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 || 382 + chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050) 379 383 regmap_write(map, MAX17047_FullSOCThr, 380 384 config->full_soc_thresh); 381 385 } ··· 389 391 max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); 390 392 max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); 391 393 max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); 392 - if (chip->chip_type == MAX17042) { 394 + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) { 393 395 regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); 394 396 max17042_write_verify_reg(map, MAX17042_K_empty0, 395 397 config->kempty0); ··· 498 500 499 501 max17042_override_por(map, MAX17042_FullCAP, config->fullcap); 500 502 max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); 501 - if (chip->chip_type == MAX17042) 503 + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) 502 504 max17042_override_por(map, MAX17042_SOC_empty, 503 505 config->socempty); 504 506 max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); 505 507 max17042_override_por(map, MAX17042_dQacc, config->dqacc); 506 508 max17042_override_por(map, MAX17042_dPacc, config->dpacc); 507 509 508 - if (chip->chip_type == MAX17042) 510 + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) 509 511 max17042_override_por(map, MAX17042_V_empty, config->vempty); 510 512 else 511 513 max17042_override_por(map, MAX17047_V_empty, config->vempty); ··· 707 709 } 708 710 709 711 i2c_set_clientdata(client, chip); 712 + chip->chip_type = id->driver_data; 710 713 psy_cfg.drv_data = chip; 711 - 712 - regmap_read(chip->regmap, MAX17042_DevName, &val); 713 - if (val == MAX17042_IC_VERSION) { 714 - dev_dbg(&client->dev, "chip type max17042 detected\n"); 715 - chip->chip_type = MAX17042; 716 - } else if (val == MAX17047_IC_VERSION) { 717 - dev_dbg(&client->dev, "chip type max17047/50 detected\n"); 718 - chip->chip_type = MAX17047; 719 - } else { 720 - dev_err(&client->dev, "device version mismatch: %x\n", val); 721 - return -EIO; 722 - } 723 714 724 715 /* When current is not measured, 725 716 * CURRENT_NOW and CURRENT_AVG properties should be invisible. */ ··· 821 834 #endif 822 835 823 836 static const struct i2c_device_id max17042_id[] = { 824 - { "max17042", 0 }, 825 - { "max17047", 1 }, 826 - { "max17050", 2 }, 837 + { "max17042", MAXIM_DEVICE_TYPE_MAX17042 }, 838 + { "max17047", MAXIM_DEVICE_TYPE_MAX17047 }, 839 + { "max17050", MAXIM_DEVICE_TYPE_MAX17050 }, 827 840 { } 828 841 }; 829 842 MODULE_DEVICE_TABLE(i2c, max17042_id);
+8 -1
include/linux/power/max17042_battery.h
··· 126 126 MAX17047_QRTbl30 = 0x42, 127 127 }; 128 128 129 - enum max170xx_chip_type {MAX17042, MAX17047}; 129 + enum max170xx_chip_type { 130 + MAXIM_DEVICE_TYPE_UNKNOWN = 0, 131 + MAXIM_DEVICE_TYPE_MAX17042, 132 + MAXIM_DEVICE_TYPE_MAX17047, 133 + MAXIM_DEVICE_TYPE_MAX17050, 134 + 135 + MAXIM_DEVICE_TYPE_NUM 136 + }; 130 137 131 138 /* 132 139 * used for setting a register to a desired value