treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / power / supply / max77693_charger.c
bloba2c5c9858639fdedef73a3894745f8e365423a4d
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // max77693_charger.c - Battery charger driver for the Maxim 77693
4 //
5 // Copyright (C) 2014 Samsung Electronics
6 // Krzysztof Kozlowski <krzk@kernel.org>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/power_supply.h>
11 #include <linux/regmap.h>
12 #include <linux/mfd/max77693.h>
13 #include <linux/mfd/max77693-common.h>
14 #include <linux/mfd/max77693-private.h>
16 #define MAX77693_CHARGER_NAME "max77693-charger"
17 static const char *max77693_charger_model = "MAX77693";
18 static const char *max77693_charger_manufacturer = "Maxim Integrated";
20 struct max77693_charger {
21 struct device *dev;
22 struct max77693_dev *max77693;
23 struct power_supply *charger;
25 u32 constant_volt;
26 u32 min_system_volt;
27 u32 thermal_regulation_temp;
28 u32 batttery_overcurrent;
29 u32 charge_input_threshold_volt;
32 static int max77693_get_charger_state(struct regmap *regmap, int *val)
34 int ret;
35 unsigned int data;
37 ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data);
38 if (ret < 0)
39 return ret;
41 data &= CHG_DETAILS_01_CHG_MASK;
42 data >>= CHG_DETAILS_01_CHG_SHIFT;
44 switch (data) {
45 case MAX77693_CHARGING_PREQUALIFICATION:
46 case MAX77693_CHARGING_FAST_CONST_CURRENT:
47 case MAX77693_CHARGING_FAST_CONST_VOLTAGE:
48 case MAX77693_CHARGING_TOP_OFF:
49 /* In high temp the charging current is reduced, but still charging */
50 case MAX77693_CHARGING_HIGH_TEMP:
51 *val = POWER_SUPPLY_STATUS_CHARGING;
52 break;
53 case MAX77693_CHARGING_DONE:
54 *val = POWER_SUPPLY_STATUS_FULL;
55 break;
56 case MAX77693_CHARGING_TIMER_EXPIRED:
57 case MAX77693_CHARGING_THERMISTOR_SUSPEND:
58 *val = POWER_SUPPLY_STATUS_NOT_CHARGING;
59 break;
60 case MAX77693_CHARGING_OFF:
61 case MAX77693_CHARGING_OVER_TEMP:
62 case MAX77693_CHARGING_WATCHDOG_EXPIRED:
63 *val = POWER_SUPPLY_STATUS_DISCHARGING;
64 break;
65 case MAX77693_CHARGING_RESERVED:
66 default:
67 *val = POWER_SUPPLY_STATUS_UNKNOWN;
70 return 0;
73 static int max77693_get_charge_type(struct regmap *regmap, int *val)
75 int ret;
76 unsigned int data;
78 ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data);
79 if (ret < 0)
80 return ret;
82 data &= CHG_DETAILS_01_CHG_MASK;
83 data >>= CHG_DETAILS_01_CHG_SHIFT;
85 switch (data) {
86 case MAX77693_CHARGING_PREQUALIFICATION:
88 * Top-off: trickle or fast? In top-off the current varies between
89 * 100 and 250 mA. It is higher than prequalification current.
91 case MAX77693_CHARGING_TOP_OFF:
92 *val = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
93 break;
94 case MAX77693_CHARGING_FAST_CONST_CURRENT:
95 case MAX77693_CHARGING_FAST_CONST_VOLTAGE:
96 /* In high temp the charging current is reduced, but still charging */
97 case MAX77693_CHARGING_HIGH_TEMP:
98 *val = POWER_SUPPLY_CHARGE_TYPE_FAST;
99 break;
100 case MAX77693_CHARGING_DONE:
101 case MAX77693_CHARGING_TIMER_EXPIRED:
102 case MAX77693_CHARGING_THERMISTOR_SUSPEND:
103 case MAX77693_CHARGING_OFF:
104 case MAX77693_CHARGING_OVER_TEMP:
105 case MAX77693_CHARGING_WATCHDOG_EXPIRED:
106 *val = POWER_SUPPLY_CHARGE_TYPE_NONE;
107 break;
108 case MAX77693_CHARGING_RESERVED:
109 default:
110 *val = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
113 return 0;
117 * Supported health statuses:
118 * - POWER_SUPPLY_HEALTH_DEAD
119 * - POWER_SUPPLY_HEALTH_GOOD
120 * - POWER_SUPPLY_HEALTH_OVERVOLTAGE
121 * - POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
122 * - POWER_SUPPLY_HEALTH_UNKNOWN
123 * - POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
125 static int max77693_get_battery_health(struct regmap *regmap, int *val)
127 int ret;
128 unsigned int data;
130 ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data);
131 if (ret < 0)
132 return ret;
134 data &= CHG_DETAILS_01_BAT_MASK;
135 data >>= CHG_DETAILS_01_BAT_SHIFT;
137 switch (data) {
138 case MAX77693_BATTERY_NOBAT:
139 *val = POWER_SUPPLY_HEALTH_DEAD;
140 break;
141 case MAX77693_BATTERY_PREQUALIFICATION:
142 case MAX77693_BATTERY_GOOD:
143 case MAX77693_BATTERY_LOWVOLTAGE:
144 *val = POWER_SUPPLY_HEALTH_GOOD;
145 break;
146 case MAX77693_BATTERY_TIMER_EXPIRED:
148 * Took longer to charge than expected, charging suspended.
149 * Damaged battery?
151 *val = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE;
152 break;
153 case MAX77693_BATTERY_OVERVOLTAGE:
154 *val = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
155 break;
156 case MAX77693_BATTERY_OVERCURRENT:
157 *val = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
158 break;
159 case MAX77693_BATTERY_RESERVED:
160 default:
161 *val = POWER_SUPPLY_HEALTH_UNKNOWN;
162 break;
165 return 0;
168 static int max77693_get_present(struct regmap *regmap, int *val)
170 unsigned int data;
171 int ret;
174 * Read CHG_INT_OK register. High DETBAT bit here should be
175 * equal to value 0x0 in CHG_DETAILS_01/BAT field.
177 ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_INT_OK, &data);
178 if (ret < 0)
179 return ret;
181 *val = (data & CHG_INT_OK_DETBAT_MASK) ? 0 : 1;
183 return 0;
186 static int max77693_get_online(struct regmap *regmap, int *val)
188 unsigned int data;
189 int ret;
191 ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_INT_OK, &data);
192 if (ret < 0)
193 return ret;
195 *val = (data & CHG_INT_OK_CHGIN_MASK) ? 1 : 0;
197 return 0;
200 static enum power_supply_property max77693_charger_props[] = {
201 POWER_SUPPLY_PROP_STATUS,
202 POWER_SUPPLY_PROP_CHARGE_TYPE,
203 POWER_SUPPLY_PROP_HEALTH,
204 POWER_SUPPLY_PROP_PRESENT,
205 POWER_SUPPLY_PROP_ONLINE,
206 POWER_SUPPLY_PROP_MODEL_NAME,
207 POWER_SUPPLY_PROP_MANUFACTURER,
210 static int max77693_charger_get_property(struct power_supply *psy,
211 enum power_supply_property psp,
212 union power_supply_propval *val)
214 struct max77693_charger *chg = power_supply_get_drvdata(psy);
215 struct regmap *regmap = chg->max77693->regmap;
216 int ret = 0;
218 switch (psp) {
219 case POWER_SUPPLY_PROP_STATUS:
220 ret = max77693_get_charger_state(regmap, &val->intval);
221 break;
222 case POWER_SUPPLY_PROP_CHARGE_TYPE:
223 ret = max77693_get_charge_type(regmap, &val->intval);
224 break;
225 case POWER_SUPPLY_PROP_HEALTH:
226 ret = max77693_get_battery_health(regmap, &val->intval);
227 break;
228 case POWER_SUPPLY_PROP_PRESENT:
229 ret = max77693_get_present(regmap, &val->intval);
230 break;
231 case POWER_SUPPLY_PROP_ONLINE:
232 ret = max77693_get_online(regmap, &val->intval);
233 break;
234 case POWER_SUPPLY_PROP_MODEL_NAME:
235 val->strval = max77693_charger_model;
236 break;
237 case POWER_SUPPLY_PROP_MANUFACTURER:
238 val->strval = max77693_charger_manufacturer;
239 break;
240 default:
241 return -EINVAL;
244 return ret;
247 static const struct power_supply_desc max77693_charger_desc = {
248 .name = MAX77693_CHARGER_NAME,
249 .type = POWER_SUPPLY_TYPE_BATTERY,
250 .properties = max77693_charger_props,
251 .num_properties = ARRAY_SIZE(max77693_charger_props),
252 .get_property = max77693_charger_get_property,
255 static ssize_t device_attr_store(struct device *dev,
256 struct device_attribute *attr, const char *buf, size_t count,
257 int (*fn)(struct max77693_charger *, unsigned long))
259 struct max77693_charger *chg = dev_get_drvdata(dev);
260 unsigned long val;
261 int ret;
263 ret = kstrtoul(buf, 10, &val);
264 if (ret)
265 return ret;
267 ret = fn(chg, val);
268 if (ret)
269 return ret;
271 return count;
274 static ssize_t fast_charge_timer_show(struct device *dev,
275 struct device_attribute *attr, char *buf)
277 struct max77693_charger *chg = dev_get_drvdata(dev);
278 unsigned int data, val;
279 int ret;
281 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_01,
282 &data);
283 if (ret < 0)
284 return ret;
286 data &= CHG_CNFG_01_FCHGTIME_MASK;
287 data >>= CHG_CNFG_01_FCHGTIME_SHIFT;
288 switch (data) {
289 case 0x1 ... 0x7:
290 /* Starting from 4 hours, step by 2 hours */
291 val = 4 + (data - 1) * 2;
292 break;
293 case 0x0:
294 default:
295 val = 0;
296 break;
299 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
302 static int max77693_set_fast_charge_timer(struct max77693_charger *chg,
303 unsigned long hours)
305 unsigned int data;
308 * 0x00 - disable
309 * 0x01 - 4h
310 * 0x02 - 6h
311 * ...
312 * 0x07 - 16h
313 * Round down odd values.
315 switch (hours) {
316 case 4 ... 16:
317 data = (hours - 4) / 2 + 1;
318 break;
319 case 0:
320 /* Disable */
321 data = 0;
322 break;
323 default:
324 return -EINVAL;
326 data <<= CHG_CNFG_01_FCHGTIME_SHIFT;
328 return regmap_update_bits(chg->max77693->regmap,
329 MAX77693_CHG_REG_CHG_CNFG_01,
330 CHG_CNFG_01_FCHGTIME_MASK, data);
333 static ssize_t fast_charge_timer_store(struct device *dev,
334 struct device_attribute *attr, const char *buf, size_t count)
336 return device_attr_store(dev, attr, buf, count,
337 max77693_set_fast_charge_timer);
340 static ssize_t top_off_threshold_current_show(struct device *dev,
341 struct device_attribute *attr, char *buf)
343 struct max77693_charger *chg = dev_get_drvdata(dev);
344 unsigned int data, val;
345 int ret;
347 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03,
348 &data);
349 if (ret < 0)
350 return ret;
352 data &= CHG_CNFG_03_TOITH_MASK;
353 data >>= CHG_CNFG_03_TOITH_SHIFT;
355 if (data <= 0x04)
356 val = 100000 + data * 25000;
357 else
358 val = data * 50000;
360 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
363 static int max77693_set_top_off_threshold_current(struct max77693_charger *chg,
364 unsigned long uamp)
366 unsigned int data;
368 if (uamp < 100000 || uamp > 350000)
369 return -EINVAL;
371 if (uamp <= 200000)
372 data = (uamp - 100000) / 25000;
373 else
374 /* (200000, 350000> */
375 data = uamp / 50000;
377 data <<= CHG_CNFG_03_TOITH_SHIFT;
379 return regmap_update_bits(chg->max77693->regmap,
380 MAX77693_CHG_REG_CHG_CNFG_03,
381 CHG_CNFG_03_TOITH_MASK, data);
384 static ssize_t top_off_threshold_current_store(struct device *dev,
385 struct device_attribute *attr, const char *buf, size_t count)
387 return device_attr_store(dev, attr, buf, count,
388 max77693_set_top_off_threshold_current);
391 static ssize_t top_off_timer_show(struct device *dev,
392 struct device_attribute *attr, char *buf)
394 struct max77693_charger *chg = dev_get_drvdata(dev);
395 unsigned int data, val;
396 int ret;
398 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03,
399 &data);
400 if (ret < 0)
401 return ret;
403 data &= CHG_CNFG_03_TOTIME_MASK;
404 data >>= CHG_CNFG_03_TOTIME_SHIFT;
406 val = data * 10;
408 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
411 static int max77693_set_top_off_timer(struct max77693_charger *chg,
412 unsigned long minutes)
414 unsigned int data;
416 if (minutes > 70)
417 return -EINVAL;
419 data = minutes / 10;
420 data <<= CHG_CNFG_03_TOTIME_SHIFT;
422 return regmap_update_bits(chg->max77693->regmap,
423 MAX77693_CHG_REG_CHG_CNFG_03,
424 CHG_CNFG_03_TOTIME_MASK, data);
427 static ssize_t top_off_timer_store(struct device *dev,
428 struct device_attribute *attr, const char *buf, size_t count)
430 return device_attr_store(dev, attr, buf, count,
431 max77693_set_top_off_timer);
434 static DEVICE_ATTR_RW(fast_charge_timer);
435 static DEVICE_ATTR_RW(top_off_threshold_current);
436 static DEVICE_ATTR_RW(top_off_timer);
438 static int max77693_set_constant_volt(struct max77693_charger *chg,
439 unsigned int uvolt)
441 unsigned int data;
444 * 0x00 - 3.650 V
445 * 0x01 - 3.675 V
446 * ...
447 * 0x1b - 4.325 V
448 * 0x1c - 4.340 V
449 * 0x1d - 4.350 V
450 * 0x1e - 4.375 V
451 * 0x1f - 4.400 V
453 if (uvolt >= 3650000 && uvolt < 4340000)
454 data = (uvolt - 3650000) / 25000;
455 else if (uvolt >= 4340000 && uvolt < 4350000)
456 data = 0x1c;
457 else if (uvolt >= 4350000 && uvolt <= 4400000)
458 data = 0x1d + (uvolt - 4350000) / 25000;
459 else {
460 dev_err(chg->dev, "Wrong value for charging constant voltage\n");
461 return -EINVAL;
464 data <<= CHG_CNFG_04_CHGCVPRM_SHIFT;
466 dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt,
467 data);
469 return regmap_update_bits(chg->max77693->regmap,
470 MAX77693_CHG_REG_CHG_CNFG_04,
471 CHG_CNFG_04_CHGCVPRM_MASK, data);
474 static int max77693_set_min_system_volt(struct max77693_charger *chg,
475 unsigned int uvolt)
477 unsigned int data;
479 if (uvolt < 3000000 || uvolt > 3700000) {
480 dev_err(chg->dev, "Wrong value for minimum system regulation voltage\n");
481 return -EINVAL;
484 data = (uvolt - 3000000) / 100000;
486 data <<= CHG_CNFG_04_MINVSYS_SHIFT;
488 dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n",
489 uvolt, data);
491 return regmap_update_bits(chg->max77693->regmap,
492 MAX77693_CHG_REG_CHG_CNFG_04,
493 CHG_CNFG_04_MINVSYS_MASK, data);
496 static int max77693_set_thermal_regulation_temp(struct max77693_charger *chg,
497 unsigned int cels)
499 unsigned int data;
501 switch (cels) {
502 case 70:
503 case 85:
504 case 100:
505 case 115:
506 data = (cels - 70) / 15;
507 break;
508 default:
509 dev_err(chg->dev, "Wrong value for thermal regulation loop temperature\n");
510 return -EINVAL;
513 data <<= CHG_CNFG_07_REGTEMP_SHIFT;
515 dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n",
516 cels, data);
518 return regmap_update_bits(chg->max77693->regmap,
519 MAX77693_CHG_REG_CHG_CNFG_07,
520 CHG_CNFG_07_REGTEMP_MASK, data);
523 static int max77693_set_batttery_overcurrent(struct max77693_charger *chg,
524 unsigned int uamp)
526 unsigned int data;
528 if (uamp && (uamp < 2000000 || uamp > 3500000)) {
529 dev_err(chg->dev, "Wrong value for battery overcurrent\n");
530 return -EINVAL;
533 if (uamp)
534 data = ((uamp - 2000000) / 250000) + 1;
535 else
536 data = 0; /* disable */
538 data <<= CHG_CNFG_12_B2SOVRC_SHIFT;
540 dev_dbg(chg->dev, "Battery overcurrent: %u (0x%x)\n", uamp, data);
542 return regmap_update_bits(chg->max77693->regmap,
543 MAX77693_CHG_REG_CHG_CNFG_12,
544 CHG_CNFG_12_B2SOVRC_MASK, data);
547 static int max77693_set_charge_input_threshold_volt(struct max77693_charger *chg,
548 unsigned int uvolt)
550 unsigned int data;
552 switch (uvolt) {
553 case 4300000:
554 data = 0x0;
555 break;
556 case 4700000:
557 case 4800000:
558 case 4900000:
559 data = (uvolt - 4700000) / 100000;
560 break;
561 default:
562 dev_err(chg->dev, "Wrong value for charge input voltage regulation threshold\n");
563 return -EINVAL;
566 data <<= CHG_CNFG_12_VCHGINREG_SHIFT;
568 dev_dbg(chg->dev, "Charge input voltage regulation threshold: %u (0x%x)\n",
569 uvolt, data);
571 return regmap_update_bits(chg->max77693->regmap,
572 MAX77693_CHG_REG_CHG_CNFG_12,
573 CHG_CNFG_12_VCHGINREG_MASK, data);
577 * Sets charger registers to proper and safe default values.
579 static int max77693_reg_init(struct max77693_charger *chg)
581 int ret;
582 unsigned int data;
584 /* Unlock charger register protection */
585 data = (0x3 << CHG_CNFG_06_CHGPROT_SHIFT);
586 ret = regmap_update_bits(chg->max77693->regmap,
587 MAX77693_CHG_REG_CHG_CNFG_06,
588 CHG_CNFG_06_CHGPROT_MASK, data);
589 if (ret) {
590 dev_err(chg->dev, "Error unlocking registers: %d\n", ret);
591 return ret;
594 ret = max77693_set_fast_charge_timer(chg, DEFAULT_FAST_CHARGE_TIMER);
595 if (ret)
596 return ret;
598 ret = max77693_set_top_off_threshold_current(chg,
599 DEFAULT_TOP_OFF_THRESHOLD_CURRENT);
600 if (ret)
601 return ret;
603 ret = max77693_set_top_off_timer(chg, DEFAULT_TOP_OFF_TIMER);
604 if (ret)
605 return ret;
607 ret = max77693_set_constant_volt(chg, chg->constant_volt);
608 if (ret)
609 return ret;
611 ret = max77693_set_min_system_volt(chg, chg->min_system_volt);
612 if (ret)
613 return ret;
615 ret = max77693_set_thermal_regulation_temp(chg,
616 chg->thermal_regulation_temp);
617 if (ret)
618 return ret;
620 ret = max77693_set_batttery_overcurrent(chg, chg->batttery_overcurrent);
621 if (ret)
622 return ret;
624 return max77693_set_charge_input_threshold_volt(chg,
625 chg->charge_input_threshold_volt);
628 #ifdef CONFIG_OF
629 static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
631 struct device_node *np = dev->of_node;
633 if (!np) {
634 dev_err(dev, "no charger OF node\n");
635 return -EINVAL;
638 if (of_property_read_u32(np, "maxim,constant-microvolt",
639 &chg->constant_volt))
640 chg->constant_volt = DEFAULT_CONSTANT_VOLT;
642 if (of_property_read_u32(np, "maxim,min-system-microvolt",
643 &chg->min_system_volt))
644 chg->min_system_volt = DEFAULT_MIN_SYSTEM_VOLT;
646 if (of_property_read_u32(np, "maxim,thermal-regulation-celsius",
647 &chg->thermal_regulation_temp))
648 chg->thermal_regulation_temp = DEFAULT_THERMAL_REGULATION_TEMP;
650 if (of_property_read_u32(np, "maxim,battery-overcurrent-microamp",
651 &chg->batttery_overcurrent))
652 chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT;
654 if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt",
655 &chg->charge_input_threshold_volt))
656 chg->charge_input_threshold_volt =
657 DEFAULT_CHARGER_INPUT_THRESHOLD_VOLT;
659 return 0;
661 #else /* CONFIG_OF */
662 static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
664 return 0;
666 #endif /* CONFIG_OF */
668 static int max77693_charger_probe(struct platform_device *pdev)
670 struct max77693_charger *chg;
671 struct power_supply_config psy_cfg = {};
672 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
673 int ret;
675 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL);
676 if (!chg)
677 return -ENOMEM;
679 platform_set_drvdata(pdev, chg);
680 chg->dev = &pdev->dev;
681 chg->max77693 = max77693;
683 ret = max77693_dt_init(&pdev->dev, chg);
684 if (ret)
685 return ret;
687 ret = max77693_reg_init(chg);
688 if (ret)
689 return ret;
691 psy_cfg.drv_data = chg;
693 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer);
694 if (ret) {
695 dev_err(&pdev->dev, "failed: create fast charge timer sysfs entry\n");
696 goto err;
699 ret = device_create_file(&pdev->dev,
700 &dev_attr_top_off_threshold_current);
701 if (ret) {
702 dev_err(&pdev->dev, "failed: create top off current sysfs entry\n");
703 goto err;
706 ret = device_create_file(&pdev->dev, &dev_attr_top_off_timer);
707 if (ret) {
708 dev_err(&pdev->dev, "failed: create top off timer sysfs entry\n");
709 goto err;
712 chg->charger = power_supply_register(&pdev->dev,
713 &max77693_charger_desc,
714 &psy_cfg);
715 if (IS_ERR(chg->charger)) {
716 dev_err(&pdev->dev, "failed: power supply register\n");
717 ret = PTR_ERR(chg->charger);
718 goto err;
721 return 0;
723 err:
724 device_remove_file(&pdev->dev, &dev_attr_top_off_timer);
725 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current);
726 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
728 return ret;
731 static int max77693_charger_remove(struct platform_device *pdev)
733 struct max77693_charger *chg = platform_get_drvdata(pdev);
735 device_remove_file(&pdev->dev, &dev_attr_top_off_timer);
736 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current);
737 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
739 power_supply_unregister(chg->charger);
741 return 0;
744 static const struct platform_device_id max77693_charger_id[] = {
745 { "max77693-charger", 0, },
748 MODULE_DEVICE_TABLE(platform, max77693_charger_id);
750 static struct platform_driver max77693_charger_driver = {
751 .driver = {
752 .name = "max77693-charger",
754 .probe = max77693_charger_probe,
755 .remove = max77693_charger_remove,
756 .id_table = max77693_charger_id,
758 module_platform_driver(max77693_charger_driver);
760 MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
761 MODULE_DESCRIPTION("Maxim 77693 charger driver");
762 MODULE_LICENSE("GPL");