Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / power / supply / smb347-charger.c
blobd3bf35ed12cee44bbe7068c8d5ce2c3c02f8cb9a
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Summit Microelectronics SMB347 Battery Charger Driver
5 * Copyright (C) 2011, Intel Corporation
7 * Authors: Bruce E. Robertson <bruce.e.robertson@intel.com>
8 * Mika Westerberg <mika.westerberg@linux.intel.com>
9 */
11 #include <linux/delay.h>
12 #include <linux/err.h>
13 #include <linux/gpio.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/i2c.h>
19 #include <linux/power_supply.h>
20 #include <linux/property.h>
21 #include <linux/regmap.h>
23 #include <dt-bindings/power/summit,smb347-charger.h>
25 /* Use the default compensation method */
26 #define SMB3XX_SOFT_TEMP_COMPENSATE_DEFAULT -1
28 /* Use default factory programmed value for hard/soft temperature limit */
29 #define SMB3XX_TEMP_USE_DEFAULT -273
32 * Configuration registers. These are mirrored to volatile RAM and can be
33 * written once %CMD_A_ALLOW_WRITE is set in %CMD_A register. They will be
34 * reloaded from non-volatile registers after POR.
36 #define CFG_CHARGE_CURRENT 0x00
37 #define CFG_CHARGE_CURRENT_FCC_MASK 0xe0
38 #define CFG_CHARGE_CURRENT_FCC_SHIFT 5
39 #define CFG_CHARGE_CURRENT_PCC_MASK 0x18
40 #define CFG_CHARGE_CURRENT_PCC_SHIFT 3
41 #define CFG_CHARGE_CURRENT_TC_MASK 0x07
42 #define CFG_CURRENT_LIMIT 0x01
43 #define CFG_CURRENT_LIMIT_DC_MASK 0xf0
44 #define CFG_CURRENT_LIMIT_DC_SHIFT 4
45 #define CFG_CURRENT_LIMIT_USB_MASK 0x0f
46 #define CFG_FLOAT_VOLTAGE 0x03
47 #define CFG_FLOAT_VOLTAGE_FLOAT_MASK 0x3f
48 #define CFG_FLOAT_VOLTAGE_THRESHOLD_MASK 0xc0
49 #define CFG_FLOAT_VOLTAGE_THRESHOLD_SHIFT 6
50 #define CFG_STAT 0x05
51 #define CFG_STAT_DISABLED BIT(5)
52 #define CFG_STAT_ACTIVE_HIGH BIT(7)
53 #define CFG_PIN 0x06
54 #define CFG_PIN_EN_CTRL_MASK 0x60
55 #define CFG_PIN_EN_CTRL_ACTIVE_HIGH 0x40
56 #define CFG_PIN_EN_CTRL_ACTIVE_LOW 0x60
57 #define CFG_PIN_EN_APSD_IRQ BIT(1)
58 #define CFG_PIN_EN_CHARGER_ERROR BIT(2)
59 #define CFG_THERM 0x07
60 #define CFG_THERM_SOFT_HOT_COMPENSATION_MASK 0x03
61 #define CFG_THERM_SOFT_HOT_COMPENSATION_SHIFT 0
62 #define CFG_THERM_SOFT_COLD_COMPENSATION_MASK 0x0c
63 #define CFG_THERM_SOFT_COLD_COMPENSATION_SHIFT 2
64 #define CFG_THERM_MONITOR_DISABLED BIT(4)
65 #define CFG_SYSOK 0x08
66 #define CFG_SYSOK_SUSPEND_HARD_LIMIT_DISABLED BIT(2)
67 #define CFG_OTHER 0x09
68 #define CFG_OTHER_RID_MASK 0xc0
69 #define CFG_OTHER_RID_ENABLED_AUTO_OTG 0xc0
70 #define CFG_OTG 0x0a
71 #define CFG_OTG_TEMP_THRESHOLD_MASK 0x30
72 #define CFG_OTG_TEMP_THRESHOLD_SHIFT 4
73 #define CFG_OTG_CC_COMPENSATION_MASK 0xc0
74 #define CFG_OTG_CC_COMPENSATION_SHIFT 6
75 #define CFG_TEMP_LIMIT 0x0b
76 #define CFG_TEMP_LIMIT_SOFT_HOT_MASK 0x03
77 #define CFG_TEMP_LIMIT_SOFT_HOT_SHIFT 0
78 #define CFG_TEMP_LIMIT_SOFT_COLD_MASK 0x0c
79 #define CFG_TEMP_LIMIT_SOFT_COLD_SHIFT 2
80 #define CFG_TEMP_LIMIT_HARD_HOT_MASK 0x30
81 #define CFG_TEMP_LIMIT_HARD_HOT_SHIFT 4
82 #define CFG_TEMP_LIMIT_HARD_COLD_MASK 0xc0
83 #define CFG_TEMP_LIMIT_HARD_COLD_SHIFT 6
84 #define CFG_FAULT_IRQ 0x0c
85 #define CFG_FAULT_IRQ_DCIN_UV BIT(2)
86 #define CFG_STATUS_IRQ 0x0d
87 #define CFG_STATUS_IRQ_TERMINATION_OR_TAPER BIT(4)
88 #define CFG_STATUS_IRQ_CHARGE_TIMEOUT BIT(7)
89 #define CFG_ADDRESS 0x0e
91 /* Command registers */
92 #define CMD_A 0x30
93 #define CMD_A_CHG_ENABLED BIT(1)
94 #define CMD_A_SUSPEND_ENABLED BIT(2)
95 #define CMD_A_ALLOW_WRITE BIT(7)
96 #define CMD_B 0x31
97 #define CMD_C 0x33
99 /* Interrupt Status registers */
100 #define IRQSTAT_A 0x35
101 #define IRQSTAT_C 0x37
102 #define IRQSTAT_C_TERMINATION_STAT BIT(0)
103 #define IRQSTAT_C_TERMINATION_IRQ BIT(1)
104 #define IRQSTAT_C_TAPER_IRQ BIT(3)
105 #define IRQSTAT_D 0x38
106 #define IRQSTAT_D_CHARGE_TIMEOUT_STAT BIT(2)
107 #define IRQSTAT_D_CHARGE_TIMEOUT_IRQ BIT(3)
108 #define IRQSTAT_E 0x39
109 #define IRQSTAT_E_USBIN_UV_STAT BIT(0)
110 #define IRQSTAT_E_USBIN_UV_IRQ BIT(1)
111 #define IRQSTAT_E_DCIN_UV_STAT BIT(4)
112 #define IRQSTAT_E_DCIN_UV_IRQ BIT(5)
113 #define IRQSTAT_F 0x3a
115 /* Status registers */
116 #define STAT_A 0x3b
117 #define STAT_A_FLOAT_VOLTAGE_MASK 0x3f
118 #define STAT_B 0x3c
119 #define STAT_C 0x3d
120 #define STAT_C_CHG_ENABLED BIT(0)
121 #define STAT_C_HOLDOFF_STAT BIT(3)
122 #define STAT_C_CHG_MASK 0x06
123 #define STAT_C_CHG_SHIFT 1
124 #define STAT_C_CHG_TERM BIT(5)
125 #define STAT_C_CHARGER_ERROR BIT(6)
126 #define STAT_E 0x3f
128 #define SMB347_MAX_REGISTER 0x3f
131 * struct smb347_charger - smb347 charger instance
132 * @dev: pointer to device
133 * @regmap: pointer to driver regmap
134 * @mains: power_supply instance for AC/DC power
135 * @usb: power_supply instance for USB power
136 * @id: SMB charger ID
137 * @mains_online: is AC/DC input connected
138 * @usb_online: is USB input connected
139 * @charging_enabled: is charging enabled
140 * @max_charge_current: maximum current (in uA) the battery can be charged
141 * @max_charge_voltage: maximum voltage (in uV) the battery can be charged
142 * @pre_charge_current: current (in uA) to use in pre-charging phase
143 * @termination_current: current (in uA) used to determine when the
144 * charging cycle terminates
145 * @pre_to_fast_voltage: voltage (in uV) treshold used for transitioning to
146 * pre-charge to fast charge mode
147 * @mains_current_limit: maximum input current drawn from AC/DC input (in uA)
148 * @usb_hc_current_limit: maximum input high current (in uA) drawn from USB
149 * input
150 * @chip_temp_threshold: die temperature where device starts limiting charge
151 * current [%100 - %130] (in degree C)
152 * @soft_cold_temp_limit: soft cold temperature limit [%0 - %15] (in degree C),
153 * granularity is 5 deg C.
154 * @soft_hot_temp_limit: soft hot temperature limit [%40 - %55] (in degree C),
155 * granularity is 5 deg C.
156 * @hard_cold_temp_limit: hard cold temperature limit [%-5 - %10] (in degree C),
157 * granularity is 5 deg C.
158 * @hard_hot_temp_limit: hard hot temperature limit [%50 - %65] (in degree C),
159 * granularity is 5 deg C.
160 * @suspend_on_hard_temp_limit: suspend charging when hard limit is hit
161 * @soft_temp_limit_compensation: compensation method when soft temperature
162 * limit is hit
163 * @charge_current_compensation: current (in uA) for charging compensation
164 * current when temperature hits soft limits
165 * @use_mains: AC/DC input can be used
166 * @use_usb: USB input can be used
167 * @use_usb_otg: USB OTG output can be used (not implemented yet)
168 * @enable_control: how charging enable/disable is controlled
169 * (driver/pin controls)
171 * @use_main, @use_usb, and @use_usb_otg are means to enable/disable
172 * hardware support for these. This is useful when we want to have for
173 * example OTG charging controlled via OTG transceiver driver and not by
174 * the SMB347 hardware.
176 * Hard and soft temperature limit values are given as described in the
177 * device data sheet and assuming NTC beta value is %3750. Even if this is
178 * not the case, these values should be used. They can be mapped to the
179 * corresponding NTC beta values with the help of table %2 in the data
180 * sheet. So for example if NTC beta is %3375 and we want to program hard
181 * hot limit to be %53 deg C, @hard_hot_temp_limit should be set to %50.
183 * If zero value is given in any of the current and voltage values, the
184 * factory programmed default will be used. For soft/hard temperature
185 * values, pass in %SMB3XX_TEMP_USE_DEFAULT instead.
187 struct smb347_charger {
188 struct device *dev;
189 struct regmap *regmap;
190 struct power_supply *mains;
191 struct power_supply *usb;
192 unsigned int id;
193 bool mains_online;
194 bool usb_online;
195 bool charging_enabled;
197 unsigned int max_charge_current;
198 unsigned int max_charge_voltage;
199 unsigned int pre_charge_current;
200 unsigned int termination_current;
201 unsigned int pre_to_fast_voltage;
202 unsigned int mains_current_limit;
203 unsigned int usb_hc_current_limit;
204 unsigned int chip_temp_threshold;
205 int soft_cold_temp_limit;
206 int soft_hot_temp_limit;
207 int hard_cold_temp_limit;
208 int hard_hot_temp_limit;
209 bool suspend_on_hard_temp_limit;
210 unsigned int soft_temp_limit_compensation;
211 unsigned int charge_current_compensation;
212 bool use_mains;
213 bool use_usb;
214 bool use_usb_otg;
215 unsigned int enable_control;
218 enum smb_charger_chipid {
219 SMB345,
220 SMB347,
221 SMB358,
222 NUM_CHIP_TYPES,
225 /* Fast charge current in uA */
226 static const unsigned int fcc_tbl[NUM_CHIP_TYPES][8] = {
227 [SMB345] = { 200000, 450000, 600000, 900000,
228 1300000, 1500000, 1800000, 2000000 },
229 [SMB347] = { 700000, 900000, 1200000, 1500000,
230 1800000, 2000000, 2200000, 2500000 },
231 [SMB358] = { 200000, 450000, 600000, 900000,
232 1300000, 1500000, 1800000, 2000000 },
234 /* Pre-charge current in uA */
235 static const unsigned int pcc_tbl[NUM_CHIP_TYPES][4] = {
236 [SMB345] = { 150000, 250000, 350000, 450000 },
237 [SMB347] = { 100000, 150000, 200000, 250000 },
238 [SMB358] = { 150000, 250000, 350000, 450000 },
241 /* Termination current in uA */
242 static const unsigned int tc_tbl[NUM_CHIP_TYPES][8] = {
243 [SMB345] = { 30000, 40000, 60000, 80000,
244 100000, 125000, 150000, 200000 },
245 [SMB347] = { 37500, 50000, 100000, 150000,
246 200000, 250000, 500000, 600000 },
247 [SMB358] = { 30000, 40000, 60000, 80000,
248 100000, 125000, 150000, 200000 },
251 /* Input current limit in uA */
252 static const unsigned int icl_tbl[NUM_CHIP_TYPES][10] = {
253 [SMB345] = { 300000, 500000, 700000, 1000000, 1500000,
254 1800000, 2000000, 2000000, 2000000, 2000000 },
255 [SMB347] = { 300000, 500000, 700000, 900000, 1200000,
256 1500000, 1800000, 2000000, 2200000, 2500000 },
257 [SMB358] = { 300000, 500000, 700000, 1000000, 1500000,
258 1800000, 2000000, 2000000, 2000000, 2000000 },
261 /* Charge current compensation in uA */
262 static const unsigned int ccc_tbl[NUM_CHIP_TYPES][4] = {
263 [SMB345] = { 200000, 450000, 600000, 900000 },
264 [SMB347] = { 250000, 700000, 900000, 1200000 },
265 [SMB358] = { 200000, 450000, 600000, 900000 },
268 /* Convert register value to current using lookup table */
269 static int hw_to_current(const unsigned int *tbl, size_t size, unsigned int val)
271 if (val >= size)
272 return -EINVAL;
273 return tbl[val];
276 /* Convert current to register value using lookup table */
277 static int current_to_hw(const unsigned int *tbl, size_t size, unsigned int val)
279 size_t i;
281 for (i = 0; i < size; i++)
282 if (val < tbl[i])
283 break;
284 return i > 0 ? i - 1 : -EINVAL;
288 * smb347_update_ps_status - refreshes the power source status
289 * @smb: pointer to smb347 charger instance
291 * Function checks whether any power source is connected to the charger and
292 * updates internal state accordingly. If there is a change to previous state
293 * function returns %1, otherwise %0 and negative errno in case of errror.
295 static int smb347_update_ps_status(struct smb347_charger *smb)
297 bool usb = false;
298 bool dc = false;
299 unsigned int val;
300 int ret;
302 ret = regmap_read(smb->regmap, IRQSTAT_E, &val);
303 if (ret < 0)
304 return ret;
307 * Dc and usb are set depending on whether they are enabled in
308 * platform data _and_ whether corresponding undervoltage is set.
310 if (smb->use_mains)
311 dc = !(val & IRQSTAT_E_DCIN_UV_STAT);
312 if (smb->use_usb)
313 usb = !(val & IRQSTAT_E_USBIN_UV_STAT);
315 ret = smb->mains_online != dc || smb->usb_online != usb;
316 smb->mains_online = dc;
317 smb->usb_online = usb;
319 return ret;
323 * smb347_is_ps_online - returns whether input power source is connected
324 * @smb: pointer to smb347 charger instance
326 * Returns %true if input power source is connected. Note that this is
327 * dependent on what platform has configured for usable power sources. For
328 * example if USB is disabled, this will return %false even if the USB cable
329 * is connected.
331 static bool smb347_is_ps_online(struct smb347_charger *smb)
333 return smb->usb_online || smb->mains_online;
337 * smb347_charging_status - returns status of charging
338 * @smb: pointer to smb347 charger instance
340 * Function returns charging status. %0 means no charging is in progress,
341 * %1 means pre-charging, %2 fast-charging and %3 taper-charging.
343 static int smb347_charging_status(struct smb347_charger *smb)
345 unsigned int val;
346 int ret;
348 if (!smb347_is_ps_online(smb))
349 return 0;
351 ret = regmap_read(smb->regmap, STAT_C, &val);
352 if (ret < 0)
353 return 0;
355 return (val & STAT_C_CHG_MASK) >> STAT_C_CHG_SHIFT;
358 static int smb347_charging_set(struct smb347_charger *smb, bool enable)
360 int ret = 0;
362 if (smb->enable_control != SMB3XX_CHG_ENABLE_SW) {
363 dev_dbg(smb->dev, "charging enable/disable in SW disabled\n");
364 return 0;
367 if (smb->charging_enabled != enable) {
368 ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED,
369 enable ? CMD_A_CHG_ENABLED : 0);
370 if (!ret)
371 smb->charging_enabled = enable;
374 return ret;
377 static inline int smb347_charging_enable(struct smb347_charger *smb)
379 return smb347_charging_set(smb, true);
382 static inline int smb347_charging_disable(struct smb347_charger *smb)
384 return smb347_charging_set(smb, false);
387 static int smb347_start_stop_charging(struct smb347_charger *smb)
389 int ret;
392 * Depending on whether valid power source is connected or not, we
393 * disable or enable the charging. We do it manually because it
394 * depends on how the platform has configured the valid inputs.
396 if (smb347_is_ps_online(smb)) {
397 ret = smb347_charging_enable(smb);
398 if (ret < 0)
399 dev_err(smb->dev, "failed to enable charging\n");
400 } else {
401 ret = smb347_charging_disable(smb);
402 if (ret < 0)
403 dev_err(smb->dev, "failed to disable charging\n");
406 return ret;
409 static int smb347_set_charge_current(struct smb347_charger *smb)
411 unsigned int id = smb->id;
412 int ret;
414 if (smb->max_charge_current) {
415 ret = current_to_hw(fcc_tbl[id], ARRAY_SIZE(fcc_tbl[id]),
416 smb->max_charge_current);
417 if (ret < 0)
418 return ret;
420 ret = regmap_update_bits(smb->regmap, CFG_CHARGE_CURRENT,
421 CFG_CHARGE_CURRENT_FCC_MASK,
422 ret << CFG_CHARGE_CURRENT_FCC_SHIFT);
423 if (ret < 0)
424 return ret;
427 if (smb->pre_charge_current) {
428 ret = current_to_hw(pcc_tbl[id], ARRAY_SIZE(pcc_tbl[id]),
429 smb->pre_charge_current);
430 if (ret < 0)
431 return ret;
433 ret = regmap_update_bits(smb->regmap, CFG_CHARGE_CURRENT,
434 CFG_CHARGE_CURRENT_PCC_MASK,
435 ret << CFG_CHARGE_CURRENT_PCC_SHIFT);
436 if (ret < 0)
437 return ret;
440 if (smb->termination_current) {
441 ret = current_to_hw(tc_tbl[id], ARRAY_SIZE(tc_tbl[id]),
442 smb->termination_current);
443 if (ret < 0)
444 return ret;
446 ret = regmap_update_bits(smb->regmap, CFG_CHARGE_CURRENT,
447 CFG_CHARGE_CURRENT_TC_MASK, ret);
448 if (ret < 0)
449 return ret;
452 return 0;
455 static int smb347_set_current_limits(struct smb347_charger *smb)
457 unsigned int id = smb->id;
458 int ret;
460 if (smb->mains_current_limit) {
461 ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]),
462 smb->mains_current_limit);
463 if (ret < 0)
464 return ret;
466 ret = regmap_update_bits(smb->regmap, CFG_CURRENT_LIMIT,
467 CFG_CURRENT_LIMIT_DC_MASK,
468 ret << CFG_CURRENT_LIMIT_DC_SHIFT);
469 if (ret < 0)
470 return ret;
473 if (smb->usb_hc_current_limit) {
474 ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]),
475 smb->usb_hc_current_limit);
476 if (ret < 0)
477 return ret;
479 ret = regmap_update_bits(smb->regmap, CFG_CURRENT_LIMIT,
480 CFG_CURRENT_LIMIT_USB_MASK, ret);
481 if (ret < 0)
482 return ret;
485 return 0;
488 static int smb347_set_voltage_limits(struct smb347_charger *smb)
490 int ret;
492 if (smb->pre_to_fast_voltage) {
493 ret = smb->pre_to_fast_voltage;
495 /* uV */
496 ret = clamp_val(ret, 2400000, 3000000) - 2400000;
497 ret /= 200000;
499 ret = regmap_update_bits(smb->regmap, CFG_FLOAT_VOLTAGE,
500 CFG_FLOAT_VOLTAGE_THRESHOLD_MASK,
501 ret << CFG_FLOAT_VOLTAGE_THRESHOLD_SHIFT);
502 if (ret < 0)
503 return ret;
506 if (smb->max_charge_voltage) {
507 ret = smb->max_charge_voltage;
509 /* uV */
510 ret = clamp_val(ret, 3500000, 4500000) - 3500000;
511 ret /= 20000;
513 ret = regmap_update_bits(smb->regmap, CFG_FLOAT_VOLTAGE,
514 CFG_FLOAT_VOLTAGE_FLOAT_MASK, ret);
515 if (ret < 0)
516 return ret;
519 return 0;
522 static int smb347_set_temp_limits(struct smb347_charger *smb)
524 unsigned int id = smb->id;
525 bool enable_therm_monitor = false;
526 int ret = 0;
527 int val;
529 if (smb->chip_temp_threshold) {
530 val = smb->chip_temp_threshold;
532 /* degree C */
533 val = clamp_val(val, 100, 130) - 100;
534 val /= 10;
536 ret = regmap_update_bits(smb->regmap, CFG_OTG,
537 CFG_OTG_TEMP_THRESHOLD_MASK,
538 val << CFG_OTG_TEMP_THRESHOLD_SHIFT);
539 if (ret < 0)
540 return ret;
543 if (smb->soft_cold_temp_limit != SMB3XX_TEMP_USE_DEFAULT) {
544 val = smb->soft_cold_temp_limit;
546 val = clamp_val(val, 0, 15);
547 val /= 5;
548 /* this goes from higher to lower so invert the value */
549 val = ~val & 0x3;
551 ret = regmap_update_bits(smb->regmap, CFG_TEMP_LIMIT,
552 CFG_TEMP_LIMIT_SOFT_COLD_MASK,
553 val << CFG_TEMP_LIMIT_SOFT_COLD_SHIFT);
554 if (ret < 0)
555 return ret;
557 enable_therm_monitor = true;
560 if (smb->soft_hot_temp_limit != SMB3XX_TEMP_USE_DEFAULT) {
561 val = smb->soft_hot_temp_limit;
563 val = clamp_val(val, 40, 55) - 40;
564 val /= 5;
566 ret = regmap_update_bits(smb->regmap, CFG_TEMP_LIMIT,
567 CFG_TEMP_LIMIT_SOFT_HOT_MASK,
568 val << CFG_TEMP_LIMIT_SOFT_HOT_SHIFT);
569 if (ret < 0)
570 return ret;
572 enable_therm_monitor = true;
575 if (smb->hard_cold_temp_limit != SMB3XX_TEMP_USE_DEFAULT) {
576 val = smb->hard_cold_temp_limit;
578 val = clamp_val(val, -5, 10) + 5;
579 val /= 5;
580 /* this goes from higher to lower so invert the value */
581 val = ~val & 0x3;
583 ret = regmap_update_bits(smb->regmap, CFG_TEMP_LIMIT,
584 CFG_TEMP_LIMIT_HARD_COLD_MASK,
585 val << CFG_TEMP_LIMIT_HARD_COLD_SHIFT);
586 if (ret < 0)
587 return ret;
589 enable_therm_monitor = true;
592 if (smb->hard_hot_temp_limit != SMB3XX_TEMP_USE_DEFAULT) {
593 val = smb->hard_hot_temp_limit;
595 val = clamp_val(val, 50, 65) - 50;
596 val /= 5;
598 ret = regmap_update_bits(smb->regmap, CFG_TEMP_LIMIT,
599 CFG_TEMP_LIMIT_HARD_HOT_MASK,
600 val << CFG_TEMP_LIMIT_HARD_HOT_SHIFT);
601 if (ret < 0)
602 return ret;
604 enable_therm_monitor = true;
608 * If any of the temperature limits are set, we also enable the
609 * thermistor monitoring.
611 * When soft limits are hit, the device will start to compensate
612 * current and/or voltage depending on the configuration.
614 * When hard limit is hit, the device will suspend charging
615 * depending on the configuration.
617 if (enable_therm_monitor) {
618 ret = regmap_update_bits(smb->regmap, CFG_THERM,
619 CFG_THERM_MONITOR_DISABLED, 0);
620 if (ret < 0)
621 return ret;
624 if (smb->suspend_on_hard_temp_limit) {
625 ret = regmap_update_bits(smb->regmap, CFG_SYSOK,
626 CFG_SYSOK_SUSPEND_HARD_LIMIT_DISABLED, 0);
627 if (ret < 0)
628 return ret;
631 if (smb->soft_temp_limit_compensation !=
632 SMB3XX_SOFT_TEMP_COMPENSATE_DEFAULT) {
633 val = smb->soft_temp_limit_compensation & 0x3;
635 ret = regmap_update_bits(smb->regmap, CFG_THERM,
636 CFG_THERM_SOFT_HOT_COMPENSATION_MASK,
637 val << CFG_THERM_SOFT_HOT_COMPENSATION_SHIFT);
638 if (ret < 0)
639 return ret;
641 ret = regmap_update_bits(smb->regmap, CFG_THERM,
642 CFG_THERM_SOFT_COLD_COMPENSATION_MASK,
643 val << CFG_THERM_SOFT_COLD_COMPENSATION_SHIFT);
644 if (ret < 0)
645 return ret;
648 if (smb->charge_current_compensation) {
649 val = current_to_hw(ccc_tbl[id], ARRAY_SIZE(ccc_tbl[id]),
650 smb->charge_current_compensation);
651 if (val < 0)
652 return val;
654 ret = regmap_update_bits(smb->regmap, CFG_OTG,
655 CFG_OTG_CC_COMPENSATION_MASK,
656 (val & 0x3) << CFG_OTG_CC_COMPENSATION_SHIFT);
657 if (ret < 0)
658 return ret;
661 return ret;
665 * smb347_set_writable - enables/disables writing to non-volatile registers
666 * @smb: pointer to smb347 charger instance
668 * You can enable/disable writing to the non-volatile configuration
669 * registers by calling this function.
671 * Returns %0 on success and negative errno in case of failure.
673 static int smb347_set_writable(struct smb347_charger *smb, bool writable)
675 return regmap_update_bits(smb->regmap, CMD_A, CMD_A_ALLOW_WRITE,
676 writable ? CMD_A_ALLOW_WRITE : 0);
679 static int smb347_hw_init(struct smb347_charger *smb)
681 unsigned int val;
682 int ret;
684 ret = smb347_set_writable(smb, true);
685 if (ret < 0)
686 return ret;
689 * Program the platform specific configuration values to the device
690 * first.
692 ret = smb347_set_charge_current(smb);
693 if (ret < 0)
694 goto fail;
696 ret = smb347_set_current_limits(smb);
697 if (ret < 0)
698 goto fail;
700 ret = smb347_set_voltage_limits(smb);
701 if (ret < 0)
702 goto fail;
704 ret = smb347_set_temp_limits(smb);
705 if (ret < 0)
706 goto fail;
708 /* If USB charging is disabled we put the USB in suspend mode */
709 if (!smb->use_usb) {
710 ret = regmap_update_bits(smb->regmap, CMD_A,
711 CMD_A_SUSPEND_ENABLED,
712 CMD_A_SUSPEND_ENABLED);
713 if (ret < 0)
714 goto fail;
718 * If configured by platform data, we enable hardware Auto-OTG
719 * support for driving VBUS. Otherwise we disable it.
721 ret = regmap_update_bits(smb->regmap, CFG_OTHER, CFG_OTHER_RID_MASK,
722 smb->use_usb_otg ? CFG_OTHER_RID_ENABLED_AUTO_OTG : 0);
723 if (ret < 0)
724 goto fail;
727 * Make the charging functionality controllable by a write to the
728 * command register unless pin control is specified in the platform
729 * data.
731 switch (smb->enable_control) {
732 case SMB3XX_CHG_ENABLE_PIN_ACTIVE_LOW:
733 val = CFG_PIN_EN_CTRL_ACTIVE_LOW;
734 break;
735 case SMB3XX_CHG_ENABLE_PIN_ACTIVE_HIGH:
736 val = CFG_PIN_EN_CTRL_ACTIVE_HIGH;
737 break;
738 default:
739 val = 0;
740 break;
743 ret = regmap_update_bits(smb->regmap, CFG_PIN, CFG_PIN_EN_CTRL_MASK,
744 val);
745 if (ret < 0)
746 goto fail;
748 /* Disable Automatic Power Source Detection (APSD) interrupt. */
749 ret = regmap_update_bits(smb->regmap, CFG_PIN, CFG_PIN_EN_APSD_IRQ, 0);
750 if (ret < 0)
751 goto fail;
753 ret = smb347_update_ps_status(smb);
754 if (ret < 0)
755 goto fail;
757 ret = smb347_start_stop_charging(smb);
759 fail:
760 smb347_set_writable(smb, false);
761 return ret;
764 static irqreturn_t smb347_interrupt(int irq, void *data)
766 struct smb347_charger *smb = data;
767 unsigned int stat_c, irqstat_c, irqstat_d, irqstat_e;
768 bool handled = false;
769 int ret;
771 /* SMB347 it needs at least 20ms for setting IRQSTAT_E_*IN_UV_IRQ */
772 usleep_range(25000, 35000);
774 ret = regmap_read(smb->regmap, STAT_C, &stat_c);
775 if (ret < 0) {
776 dev_warn(smb->dev, "reading STAT_C failed\n");
777 return IRQ_NONE;
780 ret = regmap_read(smb->regmap, IRQSTAT_C, &irqstat_c);
781 if (ret < 0) {
782 dev_warn(smb->dev, "reading IRQSTAT_C failed\n");
783 return IRQ_NONE;
786 ret = regmap_read(smb->regmap, IRQSTAT_D, &irqstat_d);
787 if (ret < 0) {
788 dev_warn(smb->dev, "reading IRQSTAT_D failed\n");
789 return IRQ_NONE;
792 ret = regmap_read(smb->regmap, IRQSTAT_E, &irqstat_e);
793 if (ret < 0) {
794 dev_warn(smb->dev, "reading IRQSTAT_E failed\n");
795 return IRQ_NONE;
799 * If we get charger error we report the error back to user.
800 * If the error is recovered charging will resume again.
802 if (stat_c & STAT_C_CHARGER_ERROR) {
803 dev_err(smb->dev, "charging stopped due to charger error\n");
804 if (smb->use_mains)
805 power_supply_changed(smb->mains);
806 if (smb->use_usb)
807 power_supply_changed(smb->usb);
808 handled = true;
812 * If we reached the termination current the battery is charged and
813 * we can update the status now. Charging is automatically
814 * disabled by the hardware.
816 if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ)) {
817 if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) {
818 if (smb->use_mains)
819 power_supply_changed(smb->mains);
820 if (smb->use_usb)
821 power_supply_changed(smb->usb);
823 dev_dbg(smb->dev, "going to HW maintenance mode\n");
824 handled = true;
828 * If we got a charger timeout INT that means the charge
829 * full is not detected with in charge timeout value.
831 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_IRQ) {
832 dev_dbg(smb->dev, "total Charge Timeout INT received\n");
834 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT)
835 dev_warn(smb->dev, "charging stopped due to timeout\n");
836 if (smb->use_mains)
837 power_supply_changed(smb->mains);
838 if (smb->use_usb)
839 power_supply_changed(smb->usb);
840 handled = true;
844 * If we got an under voltage interrupt it means that AC/USB input
845 * was connected or disconnected.
847 if (irqstat_e & (IRQSTAT_E_USBIN_UV_IRQ | IRQSTAT_E_DCIN_UV_IRQ)) {
848 if (smb347_update_ps_status(smb) > 0) {
849 smb347_start_stop_charging(smb);
850 if (smb->use_mains)
851 power_supply_changed(smb->mains);
852 if (smb->use_usb)
853 power_supply_changed(smb->usb);
855 handled = true;
858 return handled ? IRQ_HANDLED : IRQ_NONE;
861 static int smb347_irq_set(struct smb347_charger *smb, bool enable)
863 int ret;
865 ret = smb347_set_writable(smb, true);
866 if (ret < 0)
867 return ret;
870 * Enable/disable interrupts for:
871 * - under voltage
872 * - termination current reached
873 * - charger timeout
874 * - charger error
876 ret = regmap_update_bits(smb->regmap, CFG_FAULT_IRQ, 0xff,
877 enable ? CFG_FAULT_IRQ_DCIN_UV : 0);
878 if (ret < 0)
879 goto fail;
881 ret = regmap_update_bits(smb->regmap, CFG_STATUS_IRQ, 0xff,
882 enable ? (CFG_STATUS_IRQ_TERMINATION_OR_TAPER |
883 CFG_STATUS_IRQ_CHARGE_TIMEOUT) : 0);
884 if (ret < 0)
885 goto fail;
887 ret = regmap_update_bits(smb->regmap, CFG_PIN, CFG_PIN_EN_CHARGER_ERROR,
888 enable ? CFG_PIN_EN_CHARGER_ERROR : 0);
889 fail:
890 smb347_set_writable(smb, false);
891 return ret;
894 static inline int smb347_irq_enable(struct smb347_charger *smb)
896 return smb347_irq_set(smb, true);
899 static inline int smb347_irq_disable(struct smb347_charger *smb)
901 return smb347_irq_set(smb, false);
904 static int smb347_irq_init(struct smb347_charger *smb,
905 struct i2c_client *client)
907 int ret;
909 ret = devm_request_threaded_irq(smb->dev, client->irq, NULL,
910 smb347_interrupt, IRQF_ONESHOT,
911 client->name, smb);
912 if (ret < 0)
913 return ret;
915 ret = smb347_set_writable(smb, true);
916 if (ret < 0)
917 return ret;
920 * Configure the STAT output to be suitable for interrupts: disable
921 * all other output (except interrupts) and make it active low.
923 ret = regmap_update_bits(smb->regmap, CFG_STAT,
924 CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED,
925 CFG_STAT_DISABLED);
926 if (ret < 0)
927 client->irq = 0;
929 smb347_set_writable(smb, false);
931 return ret;
935 * Returns the constant charge current programmed
936 * into the charger in uA.
938 static int get_const_charge_current(struct smb347_charger *smb)
940 unsigned int id = smb->id;
941 int ret, intval;
942 unsigned int v;
944 if (!smb347_is_ps_online(smb))
945 return -ENODATA;
947 ret = regmap_read(smb->regmap, STAT_B, &v);
948 if (ret < 0)
949 return ret;
952 * The current value is composition of FCC and PCC values
953 * and we can detect which table to use from bit 5.
955 if (v & 0x20) {
956 intval = hw_to_current(fcc_tbl[id],
957 ARRAY_SIZE(fcc_tbl[id]), v & 7);
958 } else {
959 v >>= 3;
960 intval = hw_to_current(pcc_tbl[id],
961 ARRAY_SIZE(pcc_tbl[id]), v & 7);
964 return intval;
968 * Returns the constant charge voltage programmed
969 * into the charger in uV.
971 static int get_const_charge_voltage(struct smb347_charger *smb)
973 int ret, intval;
974 unsigned int v;
976 if (!smb347_is_ps_online(smb))
977 return -ENODATA;
979 ret = regmap_read(smb->regmap, STAT_A, &v);
980 if (ret < 0)
981 return ret;
983 v &= STAT_A_FLOAT_VOLTAGE_MASK;
984 if (v > 0x3d)
985 v = 0x3d;
987 intval = 3500000 + v * 20000;
989 return intval;
992 static int smb347_get_charging_status(struct smb347_charger *smb,
993 struct power_supply *psy)
995 int ret, status;
996 unsigned int val;
998 if (psy->desc->type == POWER_SUPPLY_TYPE_USB) {
999 if (!smb->usb_online)
1000 return POWER_SUPPLY_STATUS_DISCHARGING;
1001 } else {
1002 if (!smb->mains_online)
1003 return POWER_SUPPLY_STATUS_DISCHARGING;
1006 ret = regmap_read(smb->regmap, STAT_C, &val);
1007 if (ret < 0)
1008 return ret;
1010 if ((val & STAT_C_CHARGER_ERROR) ||
1011 (val & STAT_C_HOLDOFF_STAT)) {
1013 * set to NOT CHARGING upon charger error
1014 * or charging has stopped.
1016 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1017 } else {
1018 if ((val & STAT_C_CHG_MASK) >> STAT_C_CHG_SHIFT) {
1020 * set to charging if battery is in pre-charge,
1021 * fast charge or taper charging mode.
1023 status = POWER_SUPPLY_STATUS_CHARGING;
1024 } else if (val & STAT_C_CHG_TERM) {
1026 * set the status to FULL if battery is not in pre
1027 * charge, fast charge or taper charging mode AND
1028 * charging is terminated at least once.
1030 status = POWER_SUPPLY_STATUS_FULL;
1031 } else {
1033 * in this case no charger error or termination
1034 * occured but charging is not in progress!!!
1036 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1040 return status;
1043 static int smb347_get_property_locked(struct power_supply *psy,
1044 enum power_supply_property prop,
1045 union power_supply_propval *val)
1047 struct smb347_charger *smb = power_supply_get_drvdata(psy);
1048 int ret;
1050 switch (prop) {
1051 case POWER_SUPPLY_PROP_STATUS:
1052 ret = smb347_get_charging_status(smb, psy);
1053 if (ret < 0)
1054 return ret;
1055 val->intval = ret;
1056 break;
1058 case POWER_SUPPLY_PROP_CHARGE_TYPE:
1059 if (psy->desc->type == POWER_SUPPLY_TYPE_USB) {
1060 if (!smb->usb_online)
1061 return -ENODATA;
1062 } else {
1063 if (!smb->mains_online)
1064 return -ENODATA;
1068 * We handle trickle and pre-charging the same, and taper
1069 * and none the same.
1071 switch (smb347_charging_status(smb)) {
1072 case 1:
1073 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
1074 break;
1075 case 2:
1076 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
1077 break;
1078 default:
1079 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
1080 break;
1082 break;
1084 case POWER_SUPPLY_PROP_ONLINE:
1085 if (psy->desc->type == POWER_SUPPLY_TYPE_USB)
1086 val->intval = smb->usb_online;
1087 else
1088 val->intval = smb->mains_online;
1089 break;
1091 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
1092 ret = get_const_charge_voltage(smb);
1093 if (ret < 0)
1094 return ret;
1095 val->intval = ret;
1096 break;
1098 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
1099 ret = get_const_charge_current(smb);
1100 if (ret < 0)
1101 return ret;
1102 val->intval = ret;
1103 break;
1105 default:
1106 return -EINVAL;
1109 return 0;
1112 static int smb347_get_property(struct power_supply *psy,
1113 enum power_supply_property prop,
1114 union power_supply_propval *val)
1116 struct smb347_charger *smb = power_supply_get_drvdata(psy);
1117 struct i2c_client *client = to_i2c_client(smb->dev);
1118 int ret;
1120 disable_irq(client->irq);
1121 ret = smb347_get_property_locked(psy, prop, val);
1122 enable_irq(client->irq);
1124 return ret;
1127 static enum power_supply_property smb347_properties[] = {
1128 POWER_SUPPLY_PROP_STATUS,
1129 POWER_SUPPLY_PROP_CHARGE_TYPE,
1130 POWER_SUPPLY_PROP_ONLINE,
1131 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
1132 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
1135 static bool smb347_volatile_reg(struct device *dev, unsigned int reg)
1137 switch (reg) {
1138 case IRQSTAT_A:
1139 case IRQSTAT_C:
1140 case IRQSTAT_D:
1141 case IRQSTAT_E:
1142 case IRQSTAT_F:
1143 case STAT_A:
1144 case STAT_B:
1145 case STAT_C:
1146 case STAT_E:
1147 return true;
1150 return false;
1153 static bool smb347_readable_reg(struct device *dev, unsigned int reg)
1155 switch (reg) {
1156 case CFG_CHARGE_CURRENT:
1157 case CFG_CURRENT_LIMIT:
1158 case CFG_FLOAT_VOLTAGE:
1159 case CFG_STAT:
1160 case CFG_PIN:
1161 case CFG_THERM:
1162 case CFG_SYSOK:
1163 case CFG_OTHER:
1164 case CFG_OTG:
1165 case CFG_TEMP_LIMIT:
1166 case CFG_FAULT_IRQ:
1167 case CFG_STATUS_IRQ:
1168 case CFG_ADDRESS:
1169 case CMD_A:
1170 case CMD_B:
1171 case CMD_C:
1172 return true;
1175 return smb347_volatile_reg(dev, reg);
1178 static void smb347_dt_parse_dev_info(struct smb347_charger *smb)
1180 struct device *dev = smb->dev;
1182 smb->soft_temp_limit_compensation =
1183 SMB3XX_SOFT_TEMP_COMPENSATE_DEFAULT;
1185 * These properties come from the battery info, still we need to
1186 * pre-initialize the values. See smb347_get_battery_info() below.
1188 smb->soft_cold_temp_limit = SMB3XX_TEMP_USE_DEFAULT;
1189 smb->hard_cold_temp_limit = SMB3XX_TEMP_USE_DEFAULT;
1190 smb->soft_hot_temp_limit = SMB3XX_TEMP_USE_DEFAULT;
1191 smb->hard_hot_temp_limit = SMB3XX_TEMP_USE_DEFAULT;
1193 /* Charging constraints */
1194 device_property_read_u32(dev, "summit,fast-voltage-threshold-microvolt",
1195 &smb->pre_to_fast_voltage);
1196 device_property_read_u32(dev, "summit,mains-current-limit-microamp",
1197 &smb->mains_current_limit);
1198 device_property_read_u32(dev, "summit,usb-current-limit-microamp",
1199 &smb->usb_hc_current_limit);
1201 /* For thermometer monitoring */
1202 device_property_read_u32(dev, "summit,chip-temperature-threshold-celsius",
1203 &smb->chip_temp_threshold);
1204 device_property_read_u32(dev, "summit,soft-compensation-method",
1205 &smb->soft_temp_limit_compensation);
1206 device_property_read_u32(dev, "summit,charge-current-compensation-microamp",
1207 &smb->charge_current_compensation);
1209 /* Supported charging mode */
1210 smb->use_mains = device_property_read_bool(dev, "summit,enable-mains-charging");
1211 smb->use_usb = device_property_read_bool(dev, "summit,enable-usb-charging");
1212 smb->use_usb_otg = device_property_read_bool(dev, "summit,enable-otg-charging");
1214 /* Select charging control */
1215 device_property_read_u32(dev, "summit,enable-charge-control",
1216 &smb->enable_control);
1219 static int smb347_get_battery_info(struct smb347_charger *smb)
1221 struct power_supply_battery_info info = {};
1222 struct power_supply *supply;
1223 int err;
1225 if (smb->mains)
1226 supply = smb->mains;
1227 else
1228 supply = smb->usb;
1230 err = power_supply_get_battery_info(supply, &info);
1231 if (err == -ENXIO || err == -ENODEV)
1232 return 0;
1233 if (err)
1234 return err;
1236 if (info.constant_charge_current_max_ua != -EINVAL)
1237 smb->max_charge_current = info.constant_charge_current_max_ua;
1239 if (info.constant_charge_voltage_max_uv != -EINVAL)
1240 smb->max_charge_voltage = info.constant_charge_voltage_max_uv;
1242 if (info.precharge_current_ua != -EINVAL)
1243 smb->pre_charge_current = info.precharge_current_ua;
1245 if (info.charge_term_current_ua != -EINVAL)
1246 smb->termination_current = info.charge_term_current_ua;
1248 if (info.temp_alert_min != INT_MIN)
1249 smb->soft_cold_temp_limit = info.temp_alert_min;
1251 if (info.temp_alert_max != INT_MAX)
1252 smb->soft_hot_temp_limit = info.temp_alert_max;
1254 if (info.temp_min != INT_MIN)
1255 smb->hard_cold_temp_limit = info.temp_min;
1257 if (info.temp_max != INT_MAX)
1258 smb->hard_hot_temp_limit = info.temp_max;
1260 /* Suspend when battery temperature is outside hard limits */
1261 if (smb->hard_cold_temp_limit != SMB3XX_TEMP_USE_DEFAULT ||
1262 smb->hard_hot_temp_limit != SMB3XX_TEMP_USE_DEFAULT)
1263 smb->suspend_on_hard_temp_limit = true;
1265 return 0;
1268 static const struct regmap_config smb347_regmap = {
1269 .reg_bits = 8,
1270 .val_bits = 8,
1271 .max_register = SMB347_MAX_REGISTER,
1272 .volatile_reg = smb347_volatile_reg,
1273 .readable_reg = smb347_readable_reg,
1276 static const struct power_supply_desc smb347_mains_desc = {
1277 .name = "smb347-mains",
1278 .type = POWER_SUPPLY_TYPE_MAINS,
1279 .get_property = smb347_get_property,
1280 .properties = smb347_properties,
1281 .num_properties = ARRAY_SIZE(smb347_properties),
1284 static const struct power_supply_desc smb347_usb_desc = {
1285 .name = "smb347-usb",
1286 .type = POWER_SUPPLY_TYPE_USB,
1287 .get_property = smb347_get_property,
1288 .properties = smb347_properties,
1289 .num_properties = ARRAY_SIZE(smb347_properties),
1292 static int smb347_probe(struct i2c_client *client,
1293 const struct i2c_device_id *id)
1295 struct power_supply_config mains_usb_cfg = {};
1296 struct device *dev = &client->dev;
1297 struct smb347_charger *smb;
1298 int ret;
1300 smb = devm_kzalloc(dev, sizeof(*smb), GFP_KERNEL);
1301 if (!smb)
1302 return -ENOMEM;
1303 smb->dev = &client->dev;
1304 smb->id = id->driver_data;
1305 i2c_set_clientdata(client, smb);
1307 smb347_dt_parse_dev_info(smb);
1308 if (!smb->use_mains && !smb->use_usb)
1309 return -EINVAL;
1311 smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap);
1312 if (IS_ERR(smb->regmap))
1313 return PTR_ERR(smb->regmap);
1315 mains_usb_cfg.drv_data = smb;
1316 mains_usb_cfg.of_node = dev->of_node;
1317 if (smb->use_mains) {
1318 smb->mains = devm_power_supply_register(dev, &smb347_mains_desc,
1319 &mains_usb_cfg);
1320 if (IS_ERR(smb->mains))
1321 return PTR_ERR(smb->mains);
1324 if (smb->use_usb) {
1325 smb->usb = devm_power_supply_register(dev, &smb347_usb_desc,
1326 &mains_usb_cfg);
1327 if (IS_ERR(smb->usb))
1328 return PTR_ERR(smb->usb);
1331 ret = smb347_get_battery_info(smb);
1332 if (ret)
1333 return ret;
1335 ret = smb347_hw_init(smb);
1336 if (ret < 0)
1337 return ret;
1340 * Interrupt pin is optional. If it is connected, we setup the
1341 * interrupt support here.
1343 if (client->irq) {
1344 ret = smb347_irq_init(smb, client);
1345 if (ret < 0) {
1346 dev_warn(dev, "failed to initialize IRQ: %d\n", ret);
1347 dev_warn(dev, "disabling IRQ support\n");
1348 } else {
1349 smb347_irq_enable(smb);
1353 return 0;
1356 static int smb347_remove(struct i2c_client *client)
1358 struct smb347_charger *smb = i2c_get_clientdata(client);
1360 if (client->irq)
1361 smb347_irq_disable(smb);
1362 return 0;
1365 static const struct i2c_device_id smb347_id[] = {
1366 { "smb345", SMB345 },
1367 { "smb347", SMB347 },
1368 { "smb358", SMB358 },
1369 { },
1371 MODULE_DEVICE_TABLE(i2c, smb347_id);
1373 static const struct of_device_id smb3xx_of_match[] = {
1374 { .compatible = "summit,smb345" },
1375 { .compatible = "summit,smb347" },
1376 { .compatible = "summit,smb358" },
1377 { },
1379 MODULE_DEVICE_TABLE(of, smb3xx_of_match);
1381 static struct i2c_driver smb347_driver = {
1382 .driver = {
1383 .name = "smb347",
1384 .of_match_table = smb3xx_of_match,
1386 .probe = smb347_probe,
1387 .remove = smb347_remove,
1388 .id_table = smb347_id,
1391 module_i2c_driver(smb347_driver);
1393 MODULE_AUTHOR("Bruce E. Robertson <bruce.e.robertson@intel.com>");
1394 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
1395 MODULE_DESCRIPTION("SMB347 battery charger driver");
1396 MODULE_LICENSE("GPL");