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

power: supply: smb347-charger: Support SMB345 and SMB358

SMB345 tested on Nexus 7 2013.

Based on:
- https://patchwork.kernel.org/patch/4922431/
- https://patchwork.ozlabs.org/patch/666877/

Signed-off-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

David Heidelberg and committed by
Sebastian Reichel
de76fd29 364bec75

+62 -53
+3 -3
drivers/power/supply/Kconfig
··· 632 632 Say Y to enable support for the TI BQ25890 battery charger. 633 633 634 634 config CHARGER_SMB347 635 - tristate "Summit Microelectronics SMB347 Battery Charger" 635 + tristate "Summit Microelectronics SMB3XX Battery Charger" 636 636 depends on I2C 637 637 select REGMAP_I2C 638 638 help 639 - Say Y to include support for Summit Microelectronics SMB347 640 - Battery Charger. 639 + Say Y to include support for Summit Microelectronics SMB345, 640 + SMB347 or SMB358 Battery Charger. 641 641 642 642 config CHARGER_TPS65090 643 643 tristate "TPS65090 battery charger driver"
+59 -50
drivers/power/supply/smb347-charger.c
··· 128 128 * @mains: power_supply instance for AC/DC power 129 129 * @usb: power_supply instance for USB power 130 130 * @battery: power_supply instance for battery 131 + * @id: SMB charger ID 131 132 * @mains_online: is AC/DC input connected 132 133 * @usb_online: is USB input connected 133 134 * @charging_enabled: is charging enabled ··· 141 140 struct power_supply *mains; 142 141 struct power_supply *usb; 143 142 struct power_supply *battery; 143 + unsigned int id; 144 144 bool mains_online; 145 145 bool usb_online; 146 146 bool charging_enabled; 147 147 const struct smb347_charger_platform_data *pdata; 148 148 }; 149 149 150 - /* Fast charge current in uA */ 151 - static const unsigned int fcc_tbl[] = { 152 - 700000, 153 - 900000, 154 - 1200000, 155 - 1500000, 156 - 1800000, 157 - 2000000, 158 - 2200000, 159 - 2500000, 150 + enum smb_charger_chipid { 151 + SMB345, 152 + SMB347, 153 + SMB358, 154 + NUM_CHIP_TYPES, 160 155 }; 161 156 157 + /* Fast charge current in uA */ 158 + static const unsigned int fcc_tbl[NUM_CHIP_TYPES][8] = { 159 + [SMB345] = { 200000, 450000, 600000, 900000, 160 + 1300000, 1500000, 1800000, 2000000 }, 161 + [SMB347] = { 700000, 900000, 1200000, 1500000, 162 + 1800000, 2000000, 2200000, 2500000 }, 163 + [SMB358] = { 200000, 450000, 600000, 900000, 164 + 1300000, 1500000, 1800000, 2000000 }, 165 + }; 162 166 /* Pre-charge current in uA */ 163 - static const unsigned int pcc_tbl[] = { 164 - 100000, 165 - 150000, 166 - 200000, 167 - 250000, 167 + static const unsigned int pcc_tbl[NUM_CHIP_TYPES][4] = { 168 + [SMB345] = { 150000, 250000, 350000, 450000 }, 169 + [SMB347] = { 100000, 150000, 200000, 250000 }, 170 + [SMB358] = { 150000, 250000, 350000, 450000 }, 168 171 }; 169 172 170 173 /* Termination current in uA */ 171 - static const unsigned int tc_tbl[] = { 172 - 37500, 173 - 50000, 174 - 100000, 175 - 150000, 176 - 200000, 177 - 250000, 178 - 500000, 179 - 600000, 174 + static const unsigned int tc_tbl[NUM_CHIP_TYPES][8] = { 175 + [SMB345] = { 30000, 40000, 60000, 80000, 176 + 100000, 125000, 150000, 200000 }, 177 + [SMB347] = { 37500, 50000, 100000, 150000, 178 + 200000, 250000, 500000, 600000 }, 179 + [SMB358] = { 30000, 40000, 60000, 80000, 180 + 100000, 125000, 150000, 200000 }, 180 181 }; 181 182 182 183 /* Input current limit in uA */ 183 - static const unsigned int icl_tbl[] = { 184 - 300000, 185 - 500000, 186 - 700000, 187 - 900000, 188 - 1200000, 189 - 1500000, 190 - 1800000, 191 - 2000000, 192 - 2200000, 193 - 2500000, 184 + static const unsigned int icl_tbl[NUM_CHIP_TYPES][10] = { 185 + [SMB345] = { 300000, 500000, 700000, 1000000, 1500000, 186 + 1800000, 2000000, 2000000, 2000000, 2000000 }, 187 + [SMB347] = { 300000, 500000, 700000, 900000, 1200000, 188 + 1500000, 1800000, 2000000, 2200000, 2500000 }, 189 + [SMB358] = { 300000, 500000, 700000, 1000000, 1500000, 190 + 1800000, 2000000, 2000000, 2000000, 2000000 }, 194 191 }; 195 192 196 193 /* Charge current compensation in uA */ 197 - static const unsigned int ccc_tbl[] = { 198 - 250000, 199 - 700000, 200 - 900000, 201 - 1200000, 194 + static const unsigned int ccc_tbl[NUM_CHIP_TYPES][4] = { 195 + [SMB345] = { 200000, 450000, 600000, 900000 }, 196 + [SMB347] = { 250000, 700000, 900000, 1200000 }, 197 + [SMB358] = { 200000, 450000, 600000, 900000 }, 202 198 }; 203 199 204 200 /* Convert register value to current using lookup table */ ··· 350 352 351 353 static int smb347_set_charge_current(struct smb347_charger *smb) 352 354 { 355 + unsigned int id = smb->id; 353 356 int ret; 354 357 355 358 if (smb->pdata->max_charge_current) { 356 - ret = current_to_hw(fcc_tbl, ARRAY_SIZE(fcc_tbl), 359 + ret = current_to_hw(fcc_tbl[id], ARRAY_SIZE(fcc_tbl[id]), 357 360 smb->pdata->max_charge_current); 358 361 if (ret < 0) 359 362 return ret; ··· 367 368 } 368 369 369 370 if (smb->pdata->pre_charge_current) { 370 - ret = current_to_hw(pcc_tbl, ARRAY_SIZE(pcc_tbl), 371 + ret = current_to_hw(pcc_tbl[id], ARRAY_SIZE(pcc_tbl[id]), 371 372 smb->pdata->pre_charge_current); 372 373 if (ret < 0) 373 374 return ret; ··· 380 381 } 381 382 382 383 if (smb->pdata->termination_current) { 383 - ret = current_to_hw(tc_tbl, ARRAY_SIZE(tc_tbl), 384 + ret = current_to_hw(tc_tbl[id], ARRAY_SIZE(tc_tbl[id]), 384 385 smb->pdata->termination_current); 385 386 if (ret < 0) 386 387 return ret; ··· 396 397 397 398 static int smb347_set_current_limits(struct smb347_charger *smb) 398 399 { 400 + unsigned int id = smb->id; 399 401 int ret; 400 402 401 403 if (smb->pdata->mains_current_limit) { 402 - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), 404 + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), 403 405 smb->pdata->mains_current_limit); 404 406 if (ret < 0) 405 407 return ret; ··· 413 413 } 414 414 415 415 if (smb->pdata->usb_hc_current_limit) { 416 - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), 416 + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), 417 417 smb->pdata->usb_hc_current_limit); 418 418 if (ret < 0) 419 419 return ret; ··· 463 463 464 464 static int smb347_set_temp_limits(struct smb347_charger *smb) 465 465 { 466 + unsigned int id = smb->id; 466 467 bool enable_therm_monitor = false; 467 468 int ret = 0; 468 469 int val; ··· 588 587 } 589 588 590 589 if (smb->pdata->charge_current_compensation) { 591 - val = current_to_hw(ccc_tbl, ARRAY_SIZE(ccc_tbl), 590 + val = current_to_hw(ccc_tbl[id], ARRAY_SIZE(ccc_tbl[id]), 592 591 smb->pdata->charge_current_compensation); 593 592 if (val < 0) 594 593 return val; ··· 884 883 */ 885 884 static int get_const_charge_current(struct smb347_charger *smb) 886 885 { 886 + unsigned int id = smb->id; 887 887 int ret, intval; 888 888 unsigned int v; 889 889 ··· 900 898 * and we can detect which table to use from bit 5. 901 899 */ 902 900 if (v & 0x20) { 903 - intval = hw_to_current(fcc_tbl, ARRAY_SIZE(fcc_tbl), v & 7); 901 + intval = hw_to_current(fcc_tbl[id], 902 + ARRAY_SIZE(fcc_tbl[id]), v & 7); 904 903 } else { 905 904 v >>= 3; 906 - intval = hw_to_current(pcc_tbl, ARRAY_SIZE(pcc_tbl), v & 7); 905 + intval = hw_to_current(pcc_tbl[id], 906 + ARRAY_SIZE(pcc_tbl[id]), v & 7); 907 907 } 908 908 909 909 return intval; ··· 1353 1349 1354 1350 mutex_init(&smb->lock); 1355 1351 smb->dev = &client->dev; 1352 + smb->id = id->driver_data; 1356 1353 1357 1354 smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap); 1358 1355 if (IS_ERR(smb->regmap)) ··· 1418 1413 } 1419 1414 1420 1415 static const struct i2c_device_id smb347_id[] = { 1421 - { "smb347", 0 }, 1422 - { } 1416 + { "smb345", SMB345 }, 1417 + { "smb347", SMB347 }, 1418 + { "smb358", SMB358 }, 1419 + { }, 1423 1420 }; 1424 1421 MODULE_DEVICE_TABLE(i2c, smb347_id); 1425 1422 1426 1423 static const struct of_device_id smb3xx_of_match[] = { 1424 + { .compatible = "summit,smb345" }, 1427 1425 { .compatible = "summit,smb347" }, 1426 + { .compatible = "summit,smb358" }, 1428 1427 { }, 1429 1428 }; 1430 1429 MODULE_DEVICE_TABLE(of, smb3xx_of_match);