128128 * @mains: power_supply instance for AC/DC power
129129 * @usb: power_supply instance for USB power
130130 * @battery: power_supply instance for battery
131+ * @id: SMB charger ID
131132 * @mains_online: is AC/DC input connected
132133 * @usb_online: is USB input connected
133134 * @charging_enabled: is charging enabled
@@ -140,64 +141,61 @@ struct smb347_charger {
140141 struct power_supply * mains ;
141142 struct power_supply * usb ;
142143 struct power_supply * battery ;
144+ unsigned int id ;
143145 bool mains_online ;
144146 bool usb_online ;
145147 bool charging_enabled ;
146148 const struct smb347_charger_platform_data * pdata ;
147149};
148150
149- /* Fast charge current in uA */
150- static const unsigned int fcc_tbl [] = {
151- 700000 ,
152- 900000 ,
153- 1200000 ,
154- 1500000 ,
155- 1800000 ,
156- 2000000 ,
157- 2200000 ,
158- 2500000 ,
151+ enum smb_charger_chipid {
152+ SMB345 ,
153+ SMB347 ,
154+ SMB358 ,
155+ NUM_CHIP_TYPES ,
159156};
160157
158+ /* Fast charge current in uA */
159+ static const unsigned int fcc_tbl [NUM_CHIP_TYPES ][8 ] = {
160+ [SMB345 ] = { 200000 , 450000 , 600000 , 900000 ,
161+ 1300000 , 1500000 , 1800000 , 2000000 },
162+ [SMB347 ] = { 700000 , 900000 , 1200000 , 1500000 ,
163+ 1800000 , 2000000 , 2200000 , 2500000 },
164+ [SMB358 ] = { 200000 , 450000 , 600000 , 900000 ,
165+ 1300000 , 1500000 , 1800000 , 2000000 },
166+ };
161167/* Pre-charge current in uA */
162- static const unsigned int pcc_tbl [] = {
163- 100000 ,
164- 150000 ,
165- 200000 ,
166- 250000 ,
168+ static const unsigned int pcc_tbl [NUM_CHIP_TYPES ][4 ] = {
169+ [SMB345 ] = { 150000 , 250000 , 350000 , 450000 },
170+ [SMB347 ] = { 100000 , 150000 , 200000 , 250000 },
171+ [SMB358 ] = { 150000 , 250000 , 350000 , 450000 },
167172};
168173
169174/* Termination current in uA */
170- static const unsigned int tc_tbl [] = {
171- 37500 ,
172- 50000 ,
173- 100000 ,
174- 150000 ,
175- 200000 ,
176- 250000 ,
177- 500000 ,
178- 600000 ,
175+ static const unsigned int tc_tbl [NUM_CHIP_TYPES ][8 ] = {
176+ [SMB345 ] = { 30000 , 40000 , 60000 , 80000 ,
177+ 100000 , 125000 , 150000 , 200000 },
178+ [SMB347 ] = { 37500 , 50000 , 100000 , 150000 ,
179+ 200000 , 250000 , 500000 , 600000 },
180+ [SMB358 ] = { 30000 , 40000 , 60000 , 80000 ,
181+ 100000 , 125000 , 150000 , 200000 },
179182};
180183
181184/* Input current limit in uA */
182- static const unsigned int icl_tbl [] = {
183- 300000 ,
184- 500000 ,
185- 700000 ,
186- 900000 ,
187- 1200000 ,
188- 1500000 ,
189- 1800000 ,
190- 2000000 ,
191- 2200000 ,
192- 2500000 ,
185+ static const unsigned int icl_tbl [NUM_CHIP_TYPES ][10 ] = {
186+ [SMB345 ] = { 300000 , 500000 , 700000 , 1000000 , 1500000 ,
187+ 1800000 , 2000000 , 2000000 , 2000000 , 2000000 },
188+ [SMB347 ] = { 300000 , 500000 , 700000 , 900000 , 1200000 ,
189+ 1500000 , 1800000 , 2000000 , 2200000 , 2500000 },
190+ [SMB358 ] = { 300000 , 500000 , 700000 , 1000000 , 1500000 ,
191+ 1800000 , 2000000 , 2000000 , 2000000 , 2000000 },
193192};
194193
195194/* Charge current compensation in uA */
196- static const unsigned int ccc_tbl [] = {
197- 250000 ,
198- 700000 ,
199- 900000 ,
200- 1200000 ,
195+ static const unsigned int ccc_tbl [NUM_CHIP_TYPES ][4 ] = {
196+ [SMB345 ] = { 200000 , 450000 , 600000 , 900000 },
197+ [SMB347 ] = { 250000 , 700000 , 900000 , 1200000 },
198+ [SMB358 ] = { 200000 , 450000 , 600000 , 900000 },
201199};
202200
203201/* Convert register value to current using lookup table */
@@ -352,10 +350,11 @@ static int smb347_start_stop_charging(struct smb347_charger *smb)
352350
353351static int smb347_set_charge_current (struct smb347_charger * smb )
354352{
353+ unsigned int id = smb -> id ;
355354 int ret ;
356355
357356 if (smb -> pdata -> max_charge_current ) {
358- ret = current_to_hw (fcc_tbl , ARRAY_SIZE (fcc_tbl ),
357+ ret = current_to_hw (fcc_tbl [ id ] , ARRAY_SIZE (fcc_tbl [ id ] ),
359358 smb -> pdata -> max_charge_current );
360359 if (ret < 0 )
361360 return ret ;
@@ -368,7 +367,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb)
368367 }
369368
370369 if (smb -> pdata -> pre_charge_current ) {
371- ret = current_to_hw (pcc_tbl , ARRAY_SIZE (pcc_tbl ),
370+ ret = current_to_hw (pcc_tbl [ id ] , ARRAY_SIZE (pcc_tbl [ id ] ),
372371 smb -> pdata -> pre_charge_current );
373372 if (ret < 0 )
374373 return ret ;
@@ -381,7 +380,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb)
381380 }
382381
383382 if (smb -> pdata -> termination_current ) {
384- ret = current_to_hw (tc_tbl , ARRAY_SIZE (tc_tbl ),
383+ ret = current_to_hw (tc_tbl [ id ] , ARRAY_SIZE (tc_tbl [ id ] ),
385384 smb -> pdata -> termination_current );
386385 if (ret < 0 )
387386 return ret ;
@@ -397,10 +396,11 @@ static int smb347_set_charge_current(struct smb347_charger *smb)
397396
398397static int smb347_set_current_limits (struct smb347_charger * smb )
399398{
399+ unsigned int id = smb -> id ;
400400 int ret ;
401401
402402 if (smb -> pdata -> mains_current_limit ) {
403- ret = current_to_hw (icl_tbl , ARRAY_SIZE (icl_tbl ),
403+ ret = current_to_hw (icl_tbl [ id ] , ARRAY_SIZE (icl_tbl [ id ] ),
404404 smb -> pdata -> mains_current_limit );
405405 if (ret < 0 )
406406 return ret ;
@@ -413,7 +413,7 @@ static int smb347_set_current_limits(struct smb347_charger *smb)
413413 }
414414
415415 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 ] ),
417417 smb -> pdata -> usb_hc_current_limit );
418418 if (ret < 0 )
419419 return ret ;
@@ -463,6 +463,7 @@ static int smb347_set_voltage_limits(struct smb347_charger *smb)
463463
464464static int smb347_set_temp_limits (struct smb347_charger * smb )
465465{
466+ unsigned int id = smb -> id ;
466467 bool enable_therm_monitor = false;
467468 int ret = 0 ;
468469 int val ;
@@ -587,7 +588,7 @@ static int smb347_set_temp_limits(struct smb347_charger *smb)
587588 }
588589
589590 if (smb -> pdata -> charge_current_compensation ) {
590- val = current_to_hw (ccc_tbl , ARRAY_SIZE (ccc_tbl ),
591+ val = current_to_hw (ccc_tbl [ id ] , ARRAY_SIZE (ccc_tbl [ id ] ),
591592 smb -> pdata -> charge_current_compensation );
592593 if (val < 0 )
593594 return val ;
@@ -883,6 +884,7 @@ static int smb347_irq_init(struct smb347_charger *smb,
883884 */
884885static int get_const_charge_current (struct smb347_charger * smb )
885886{
887+ unsigned int id = smb -> id ;
886888 int ret , intval ;
887889 unsigned int v ;
888890
@@ -898,10 +900,12 @@ static int get_const_charge_current(struct smb347_charger *smb)
898900 * and we can detect which table to use from bit 5.
899901 */
900902 if (v & 0x20 ) {
901- intval = hw_to_current (fcc_tbl , ARRAY_SIZE (fcc_tbl ), v & 7 );
903+ intval = hw_to_current (fcc_tbl [id ],
904+ ARRAY_SIZE (fcc_tbl [id ]), v & 7 );
902905 } else {
903906 v >>= 3 ;
904- intval = hw_to_current (pcc_tbl , ARRAY_SIZE (pcc_tbl ), v & 7 );
907+ intval = hw_to_current (pcc_tbl [id ],
908+ ARRAY_SIZE (pcc_tbl [id ]), v & 7 );
905909 }
906910
907911 return intval ;
@@ -1349,6 +1353,7 @@ static int smb347_probe(struct i2c_client *client,
13491353
13501354 mutex_init (& smb -> lock );
13511355 smb -> dev = & client -> dev ;
1356+ smb -> id = id -> driver_data ;
13521357
13531358 smb -> regmap = devm_regmap_init_i2c (client , & smb347_regmap );
13541359 if (IS_ERR (smb -> regmap ))
@@ -1413,13 +1418,17 @@ static int smb347_remove(struct i2c_client *client)
14131418}
14141419
14151420static const struct i2c_device_id smb347_id [] = {
1416- { "smb347" , 0 },
1417- { }
1421+ { "smb345" , SMB345 },
1422+ { "smb347" , SMB347 },
1423+ { "smb358" , SMB358 },
1424+ { },
14181425};
14191426MODULE_DEVICE_TABLE (i2c , smb347_id );
14201427
14211428static const struct of_device_id smb3xx_of_match [] = {
1429+ { .compatible = "summit,smb345" },
14221430 { .compatible = "summit,smb347" },
1431+ { .compatible = "summit,smb358" },
14231432 { },
14241433};
14251434MODULE_DEVICE_TABLE (of , smb3xx_of_match );
0 commit comments