Linux 4.19.133
[linux/fpc-iii.git] / drivers / power / supply / cpcap-charger.c
blob37be541e057d117d50fa631e788a08fdd13e4db7
1 /*
2 * Motorola CPCAP PMIC battery charger driver
4 * Copyright (C) 2017 Tony Lindgren <tony@atomide.com>
6 * Rewritten for Linux power framework with some parts based on
7 * on earlier driver found in the Motorola Linux kernel:
9 * Copyright (C) 2009-2010 Motorola, Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/atomic.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/err.h>
26 #include <linux/interrupt.h>
27 #include <linux/notifier.h>
28 #include <linux/of.h>
29 #include <linux/of_platform.h>
30 #include <linux/platform_device.h>
31 #include <linux/power_supply.h>
32 #include <linux/regmap.h>
34 #include <linux/gpio/consumer.h>
35 #include <linux/usb/phy_companion.h>
36 #include <linux/phy/omap_usb.h>
37 #include <linux/usb/otg.h>
38 #include <linux/iio/consumer.h>
39 #include <linux/mfd/motorola-cpcap.h>
42 * CPCAP_REG_CRM register bits. For documentation of somewhat similar hardware,
43 * see NXP "MC13783 Power Management and Audio Circuit Users's Guide"
44 * MC13783UG.pdf chapter "8.5 Battery Interface Register Summary". The registers
45 * and values for CPCAP are different, but some of the internal components seem
46 * similar. Also see the Motorola Linux kernel cpcap-regbits.h. CPCAP_REG_CHRGR_1
47 * bits that seem to describe the CRM register.
49 #define CPCAP_REG_CRM_UNUSED_641_15 BIT(15) /* 641 = register number */
50 #define CPCAP_REG_CRM_UNUSED_641_14 BIT(14) /* 641 = register number */
51 #define CPCAP_REG_CRM_CHRG_LED_EN BIT(13) /* Charger LED */
52 #define CPCAP_REG_CRM_RVRSMODE BIT(12) /* USB VBUS output enable */
53 #define CPCAP_REG_CRM_ICHRG_TR1 BIT(11) /* Trickle charge current */
54 #define CPCAP_REG_CRM_ICHRG_TR0 BIT(10)
55 #define CPCAP_REG_CRM_FET_OVRD BIT(9) /* 0 = hardware, 1 = FET_CTRL */
56 #define CPCAP_REG_CRM_FET_CTRL BIT(8) /* BPFET 1 if FET_OVRD set */
57 #define CPCAP_REG_CRM_VCHRG3 BIT(7) /* Charge voltage bits */
58 #define CPCAP_REG_CRM_VCHRG2 BIT(6)
59 #define CPCAP_REG_CRM_VCHRG1 BIT(5)
60 #define CPCAP_REG_CRM_VCHRG0 BIT(4)
61 #define CPCAP_REG_CRM_ICHRG3 BIT(3) /* Charge current bits */
62 #define CPCAP_REG_CRM_ICHRG2 BIT(2)
63 #define CPCAP_REG_CRM_ICHRG1 BIT(1)
64 #define CPCAP_REG_CRM_ICHRG0 BIT(0)
66 /* CPCAP_REG_CRM trickle charge voltages */
67 #define CPCAP_REG_CRM_TR(val) (((val) & 0x3) << 10)
68 #define CPCAP_REG_CRM_TR_0A00 CPCAP_REG_CRM_TR(0x0)
69 #define CPCAP_REG_CRM_TR_0A24 CPCAP_REG_CRM_TR(0x1)
70 #define CPCAP_REG_CRM_TR_0A48 CPCAP_REG_CRM_TR(0x2)
71 #define CPCAP_REG_CRM_TR_0A72 CPCAP_REG_CRM_TR(0x4)
74 * CPCAP_REG_CRM charge voltages based on the ADC channel 1 values.
75 * Note that these register bits don't match MC13783UG.pdf VCHRG
76 * register bits.
78 #define CPCAP_REG_CRM_VCHRG(val) (((val) & 0xf) << 4)
79 #define CPCAP_REG_CRM_VCHRG_3V80 CPCAP_REG_CRM_VCHRG(0x0)
80 #define CPCAP_REG_CRM_VCHRG_4V10 CPCAP_REG_CRM_VCHRG(0x1)
81 #define CPCAP_REG_CRM_VCHRG_4V12 CPCAP_REG_CRM_VCHRG(0x2)
82 #define CPCAP_REG_CRM_VCHRG_4V15 CPCAP_REG_CRM_VCHRG(0x3)
83 #define CPCAP_REG_CRM_VCHRG_4V17 CPCAP_REG_CRM_VCHRG(0x4)
84 #define CPCAP_REG_CRM_VCHRG_4V20 CPCAP_REG_CRM_VCHRG(0x5)
85 #define CPCAP_REG_CRM_VCHRG_4V23 CPCAP_REG_CRM_VCHRG(0x6)
86 #define CPCAP_REG_CRM_VCHRG_4V25 CPCAP_REG_CRM_VCHRG(0x7)
87 #define CPCAP_REG_CRM_VCHRG_4V27 CPCAP_REG_CRM_VCHRG(0x8)
88 #define CPCAP_REG_CRM_VCHRG_4V30 CPCAP_REG_CRM_VCHRG(0x9)
89 #define CPCAP_REG_CRM_VCHRG_4V33 CPCAP_REG_CRM_VCHRG(0xa)
90 #define CPCAP_REG_CRM_VCHRG_4V35 CPCAP_REG_CRM_VCHRG(0xb)
91 #define CPCAP_REG_CRM_VCHRG_4V38 CPCAP_REG_CRM_VCHRG(0xc)
92 #define CPCAP_REG_CRM_VCHRG_4V40 CPCAP_REG_CRM_VCHRG(0xd)
93 #define CPCAP_REG_CRM_VCHRG_4V42 CPCAP_REG_CRM_VCHRG(0xe)
94 #define CPCAP_REG_CRM_VCHRG_4V44 CPCAP_REG_CRM_VCHRG(0xf)
97 * CPCAP_REG_CRM charge currents. These seem to match MC13783UG.pdf
98 * values in "Table 8-3. Charge Path Regulator Current Limit
99 * Characteristics" for the nominal values.
101 #define CPCAP_REG_CRM_ICHRG(val) (((val) & 0xf) << 0)
102 #define CPCAP_REG_CRM_ICHRG_0A000 CPCAP_REG_CRM_ICHRG(0x0)
103 #define CPCAP_REG_CRM_ICHRG_0A070 CPCAP_REG_CRM_ICHRG(0x1)
104 #define CPCAP_REG_CRM_ICHRG_0A177 CPCAP_REG_CRM_ICHRG(0x2)
105 #define CPCAP_REG_CRM_ICHRG_0A266 CPCAP_REG_CRM_ICHRG(0x3)
106 #define CPCAP_REG_CRM_ICHRG_0A355 CPCAP_REG_CRM_ICHRG(0x4)
107 #define CPCAP_REG_CRM_ICHRG_0A443 CPCAP_REG_CRM_ICHRG(0x5)
108 #define CPCAP_REG_CRM_ICHRG_0A532 CPCAP_REG_CRM_ICHRG(0x6)
109 #define CPCAP_REG_CRM_ICHRG_0A621 CPCAP_REG_CRM_ICHRG(0x7)
110 #define CPCAP_REG_CRM_ICHRG_0A709 CPCAP_REG_CRM_ICHRG(0x8)
111 #define CPCAP_REG_CRM_ICHRG_0A798 CPCAP_REG_CRM_ICHRG(0x9)
112 #define CPCAP_REG_CRM_ICHRG_0A886 CPCAP_REG_CRM_ICHRG(0xa)
113 #define CPCAP_REG_CRM_ICHRG_0A975 CPCAP_REG_CRM_ICHRG(0xb)
114 #define CPCAP_REG_CRM_ICHRG_1A064 CPCAP_REG_CRM_ICHRG(0xc)
115 #define CPCAP_REG_CRM_ICHRG_1A152 CPCAP_REG_CRM_ICHRG(0xd)
116 #define CPCAP_REG_CRM_ICHRG_1A596 CPCAP_REG_CRM_ICHRG(0xe)
117 #define CPCAP_REG_CRM_ICHRG_NO_LIMIT CPCAP_REG_CRM_ICHRG(0xf)
119 enum {
120 CPCAP_CHARGER_IIO_BATTDET,
121 CPCAP_CHARGER_IIO_VOLTAGE,
122 CPCAP_CHARGER_IIO_VBUS,
123 CPCAP_CHARGER_IIO_CHRG_CURRENT,
124 CPCAP_CHARGER_IIO_BATT_CURRENT,
125 CPCAP_CHARGER_IIO_NR,
128 struct cpcap_charger_ddata {
129 struct device *dev;
130 struct regmap *reg;
131 struct list_head irq_list;
132 struct delayed_work detect_work;
133 struct delayed_work vbus_work;
134 struct gpio_desc *gpio[2]; /* gpio_reven0 & 1 */
136 struct iio_channel *channels[CPCAP_CHARGER_IIO_NR];
138 struct power_supply *usb;
140 struct phy_companion comparator; /* For USB VBUS */
141 bool vbus_enabled;
142 atomic_t active;
144 int status;
147 struct cpcap_interrupt_desc {
148 int irq;
149 struct list_head node;
150 const char *name;
153 struct cpcap_charger_ints_state {
154 bool chrg_det;
155 bool rvrs_chrg;
156 bool vbusov;
158 bool chrg_se1b;
159 bool rvrs_mode;
160 bool chrgcurr1;
161 bool vbusvld;
163 bool battdetb;
166 static enum power_supply_property cpcap_charger_props[] = {
167 POWER_SUPPLY_PROP_STATUS,
168 POWER_SUPPLY_PROP_ONLINE,
169 POWER_SUPPLY_PROP_VOLTAGE_NOW,
170 POWER_SUPPLY_PROP_CURRENT_NOW,
173 static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
175 struct iio_channel *channel;
176 int error, value;
178 channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
179 error = iio_read_channel_raw(channel, &value);
180 if (error < 0) {
181 dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
183 return false;
186 return value == 1;
189 static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
191 struct iio_channel *channel;
192 int error, value = 0;
194 channel = ddata->channels[CPCAP_CHARGER_IIO_VOLTAGE];
195 error = iio_read_channel_processed(channel, &value);
196 if (error < 0) {
197 dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
199 return 0;
202 return value;
205 static int cpcap_charger_get_charge_current(struct cpcap_charger_ddata *ddata)
207 struct iio_channel *channel;
208 int error, value = 0;
210 channel = ddata->channels[CPCAP_CHARGER_IIO_CHRG_CURRENT];
211 error = iio_read_channel_processed(channel, &value);
212 if (error < 0) {
213 dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
215 return 0;
218 return value;
221 static int cpcap_charger_get_property(struct power_supply *psy,
222 enum power_supply_property psp,
223 union power_supply_propval *val)
225 struct cpcap_charger_ddata *ddata = dev_get_drvdata(psy->dev.parent);
227 switch (psp) {
228 case POWER_SUPPLY_PROP_STATUS:
229 val->intval = ddata->status;
230 break;
231 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
232 if (ddata->status == POWER_SUPPLY_STATUS_CHARGING)
233 val->intval = cpcap_charger_get_charge_voltage(ddata) *
234 1000;
235 else
236 val->intval = 0;
237 break;
238 case POWER_SUPPLY_PROP_CURRENT_NOW:
239 if (ddata->status == POWER_SUPPLY_STATUS_CHARGING)
240 val->intval = cpcap_charger_get_charge_current(ddata) *
241 1000;
242 else
243 val->intval = 0;
244 break;
245 case POWER_SUPPLY_PROP_ONLINE:
246 val->intval = ddata->status == POWER_SUPPLY_STATUS_CHARGING;
247 break;
248 default:
249 return -EINVAL;
252 return 0;
255 static void cpcap_charger_set_cable_path(struct cpcap_charger_ddata *ddata,
256 bool enabled)
258 if (!ddata->gpio[0])
259 return;
261 gpiod_set_value(ddata->gpio[0], enabled);
264 static void cpcap_charger_set_inductive_path(struct cpcap_charger_ddata *ddata,
265 bool enabled)
267 if (!ddata->gpio[1])
268 return;
270 gpiod_set_value(ddata->gpio[1], enabled);
273 static int cpcap_charger_set_state(struct cpcap_charger_ddata *ddata,
274 int max_voltage, int charge_current,
275 int trickle_current)
277 bool enable;
278 int error;
280 enable = (charge_current || trickle_current);
281 dev_dbg(ddata->dev, "%s enable: %i\n", __func__, enable);
283 if (!enable) {
284 error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM,
285 0x3fff,
286 CPCAP_REG_CRM_FET_OVRD |
287 CPCAP_REG_CRM_FET_CTRL);
288 if (error) {
289 ddata->status = POWER_SUPPLY_STATUS_UNKNOWN;
290 goto out_err;
293 ddata->status = POWER_SUPPLY_STATUS_DISCHARGING;
295 return 0;
298 error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM, 0x3fff,
299 CPCAP_REG_CRM_CHRG_LED_EN |
300 trickle_current |
301 CPCAP_REG_CRM_FET_OVRD |
302 CPCAP_REG_CRM_FET_CTRL |
303 max_voltage |
304 charge_current);
305 if (error) {
306 ddata->status = POWER_SUPPLY_STATUS_UNKNOWN;
307 goto out_err;
310 ddata->status = POWER_SUPPLY_STATUS_CHARGING;
312 return 0;
314 out_err:
315 dev_err(ddata->dev, "%s failed with %i\n", __func__, error);
317 return error;
320 static bool cpcap_charger_vbus_valid(struct cpcap_charger_ddata *ddata)
322 int error, value = 0;
323 struct iio_channel *channel =
324 ddata->channels[CPCAP_CHARGER_IIO_VBUS];
326 error = iio_read_channel_processed(channel, &value);
327 if (error >= 0)
328 return value > 3900 ? true : false;
330 dev_err(ddata->dev, "error reading VBUS: %i\n", error);
332 return false;
335 /* VBUS control functions for the USB PHY companion */
337 static void cpcap_charger_vbus_work(struct work_struct *work)
339 struct cpcap_charger_ddata *ddata;
340 bool vbus = false;
341 int error;
343 ddata = container_of(work, struct cpcap_charger_ddata,
344 vbus_work.work);
346 if (ddata->vbus_enabled) {
347 vbus = cpcap_charger_vbus_valid(ddata);
348 if (vbus) {
349 dev_info(ddata->dev, "VBUS already provided\n");
351 return;
354 cpcap_charger_set_cable_path(ddata, false);
355 cpcap_charger_set_inductive_path(ddata, false);
357 error = cpcap_charger_set_state(ddata, 0, 0, 0);
358 if (error)
359 goto out_err;
361 error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM,
362 CPCAP_REG_CRM_RVRSMODE,
363 CPCAP_REG_CRM_RVRSMODE);
364 if (error)
365 goto out_err;
366 } else {
367 error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM,
368 CPCAP_REG_CRM_RVRSMODE, 0);
369 if (error)
370 goto out_err;
372 cpcap_charger_set_cable_path(ddata, true);
373 cpcap_charger_set_inductive_path(ddata, true);
376 return;
378 out_err:
379 dev_err(ddata->dev, "%s could not %s vbus: %i\n", __func__,
380 ddata->vbus_enabled ? "enable" : "disable", error);
383 static int cpcap_charger_set_vbus(struct phy_companion *comparator,
384 bool enabled)
386 struct cpcap_charger_ddata *ddata =
387 container_of(comparator, struct cpcap_charger_ddata,
388 comparator);
390 ddata->vbus_enabled = enabled;
391 schedule_delayed_work(&ddata->vbus_work, 0);
393 return 0;
396 /* Charger interrupt handling functions */
398 static int cpcap_charger_get_ints_state(struct cpcap_charger_ddata *ddata,
399 struct cpcap_charger_ints_state *s)
401 int val, error;
403 error = regmap_read(ddata->reg, CPCAP_REG_INTS1, &val);
404 if (error)
405 return error;
407 s->chrg_det = val & BIT(13);
408 s->rvrs_chrg = val & BIT(12);
409 s->vbusov = val & BIT(11);
411 error = regmap_read(ddata->reg, CPCAP_REG_INTS2, &val);
412 if (error)
413 return error;
415 s->chrg_se1b = val & BIT(13);
416 s->rvrs_mode = val & BIT(6);
417 s->chrgcurr1 = val & BIT(4);
418 s->vbusvld = val & BIT(3);
420 error = regmap_read(ddata->reg, CPCAP_REG_INTS4, &val);
421 if (error)
422 return error;
424 s->battdetb = val & BIT(6);
426 return 0;
429 static void cpcap_usb_detect(struct work_struct *work)
431 struct cpcap_charger_ddata *ddata;
432 struct cpcap_charger_ints_state s;
433 int error;
435 ddata = container_of(work, struct cpcap_charger_ddata,
436 detect_work.work);
438 error = cpcap_charger_get_ints_state(ddata, &s);
439 if (error)
440 return;
442 if (cpcap_charger_vbus_valid(ddata) && s.chrgcurr1) {
443 int max_current;
445 if (cpcap_charger_battery_found(ddata))
446 max_current = CPCAP_REG_CRM_ICHRG_1A596;
447 else
448 max_current = CPCAP_REG_CRM_ICHRG_0A532;
450 error = cpcap_charger_set_state(ddata,
451 CPCAP_REG_CRM_VCHRG_4V35,
452 max_current, 0);
453 if (error)
454 goto out_err;
455 } else {
456 error = cpcap_charger_set_state(ddata, 0, 0, 0);
457 if (error)
458 goto out_err;
461 power_supply_changed(ddata->usb);
462 return;
464 out_err:
465 dev_err(ddata->dev, "%s failed with %i\n", __func__, error);
468 static irqreturn_t cpcap_charger_irq_thread(int irq, void *data)
470 struct cpcap_charger_ddata *ddata = data;
472 if (!atomic_read(&ddata->active))
473 return IRQ_NONE;
475 schedule_delayed_work(&ddata->detect_work, 0);
477 return IRQ_HANDLED;
480 static int cpcap_usb_init_irq(struct platform_device *pdev,
481 struct cpcap_charger_ddata *ddata,
482 const char *name)
484 struct cpcap_interrupt_desc *d;
485 int irq, error;
487 irq = platform_get_irq_byname(pdev, name);
488 if (irq < 0)
489 return -ENODEV;
491 error = devm_request_threaded_irq(ddata->dev, irq, NULL,
492 cpcap_charger_irq_thread,
493 IRQF_SHARED,
494 name, ddata);
495 if (error) {
496 dev_err(ddata->dev, "could not get irq %s: %i\n",
497 name, error);
499 return error;
502 d = devm_kzalloc(ddata->dev, sizeof(*d), GFP_KERNEL);
503 if (!d)
504 return -ENOMEM;
506 d->name = name;
507 d->irq = irq;
508 list_add(&d->node, &ddata->irq_list);
510 return 0;
513 static const char * const cpcap_charger_irqs[] = {
514 /* REG_INT_0 */
515 "chrg_det", "rvrs_chrg",
517 /* REG_INT1 */
518 "chrg_se1b", "se0conn", "rvrs_mode", "chrgcurr1", "vbusvld",
520 /* REG_INT_3 */
521 "battdetb",
524 static int cpcap_usb_init_interrupts(struct platform_device *pdev,
525 struct cpcap_charger_ddata *ddata)
527 int i, error;
529 for (i = 0; i < ARRAY_SIZE(cpcap_charger_irqs); i++) {
530 error = cpcap_usb_init_irq(pdev, ddata, cpcap_charger_irqs[i]);
531 if (error)
532 return error;
535 return 0;
538 static void cpcap_charger_init_optional_gpios(struct cpcap_charger_ddata *ddata)
540 int i;
542 for (i = 0; i < 2; i++) {
543 ddata->gpio[i] = devm_gpiod_get_index(ddata->dev, "mode",
544 i, GPIOD_OUT_HIGH);
545 if (IS_ERR(ddata->gpio[i])) {
546 dev_info(ddata->dev, "no mode change GPIO%i: %li\n",
547 i, PTR_ERR(ddata->gpio[i]));
548 ddata->gpio[i] = NULL;
553 static int cpcap_charger_init_iio(struct cpcap_charger_ddata *ddata)
555 const char * const names[CPCAP_CHARGER_IIO_NR] = {
556 "battdetb", "battp", "vbus", "chg_isense", "batti",
558 int error, i;
560 for (i = 0; i < CPCAP_CHARGER_IIO_NR; i++) {
561 ddata->channels[i] = devm_iio_channel_get(ddata->dev,
562 names[i]);
563 if (IS_ERR(ddata->channels[i])) {
564 error = PTR_ERR(ddata->channels[i]);
565 goto out_err;
568 if (!ddata->channels[i]->indio_dev) {
569 error = -ENXIO;
570 goto out_err;
574 return 0;
576 out_err:
577 dev_err(ddata->dev, "could not initialize VBUS or ID IIO: %i\n",
578 error);
580 return error;
583 static const struct power_supply_desc cpcap_charger_usb_desc = {
584 .name = "usb",
585 .type = POWER_SUPPLY_TYPE_USB,
586 .properties = cpcap_charger_props,
587 .num_properties = ARRAY_SIZE(cpcap_charger_props),
588 .get_property = cpcap_charger_get_property,
591 #ifdef CONFIG_OF
592 static const struct of_device_id cpcap_charger_id_table[] = {
594 .compatible = "motorola,mapphone-cpcap-charger",
598 MODULE_DEVICE_TABLE(of, cpcap_charger_id_table);
599 #endif
601 static int cpcap_charger_probe(struct platform_device *pdev)
603 struct cpcap_charger_ddata *ddata;
604 const struct of_device_id *of_id;
605 struct power_supply_config psy_cfg = {};
606 int error;
608 of_id = of_match_device(of_match_ptr(cpcap_charger_id_table),
609 &pdev->dev);
610 if (!of_id)
611 return -EINVAL;
613 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
614 if (!ddata)
615 return -ENOMEM;
617 ddata->dev = &pdev->dev;
619 ddata->reg = dev_get_regmap(ddata->dev->parent, NULL);
620 if (!ddata->reg)
621 return -ENODEV;
623 INIT_LIST_HEAD(&ddata->irq_list);
624 INIT_DELAYED_WORK(&ddata->detect_work, cpcap_usb_detect);
625 INIT_DELAYED_WORK(&ddata->vbus_work, cpcap_charger_vbus_work);
626 platform_set_drvdata(pdev, ddata);
628 error = cpcap_charger_init_iio(ddata);
629 if (error)
630 return error;
632 atomic_set(&ddata->active, 1);
634 psy_cfg.of_node = pdev->dev.of_node;
635 psy_cfg.drv_data = ddata;
637 ddata->usb = devm_power_supply_register(ddata->dev,
638 &cpcap_charger_usb_desc,
639 &psy_cfg);
640 if (IS_ERR(ddata->usb)) {
641 error = PTR_ERR(ddata->usb);
642 dev_err(ddata->dev, "failed to register USB charger: %i\n",
643 error);
645 return error;
648 error = cpcap_usb_init_interrupts(pdev, ddata);
649 if (error)
650 return error;
652 ddata->comparator.set_vbus = cpcap_charger_set_vbus;
653 error = omap_usb2_set_comparator(&ddata->comparator);
654 if (error == -ENODEV) {
655 dev_info(ddata->dev, "charger needs phy, deferring probe\n");
656 return -EPROBE_DEFER;
659 cpcap_charger_init_optional_gpios(ddata);
661 schedule_delayed_work(&ddata->detect_work, 0);
663 return 0;
666 static int cpcap_charger_remove(struct platform_device *pdev)
668 struct cpcap_charger_ddata *ddata = platform_get_drvdata(pdev);
669 int error;
671 atomic_set(&ddata->active, 0);
672 error = omap_usb2_set_comparator(NULL);
673 if (error)
674 dev_warn(ddata->dev, "could not clear USB comparator: %i\n",
675 error);
677 error = cpcap_charger_set_state(ddata, 0, 0, 0);
678 if (error)
679 dev_warn(ddata->dev, "could not clear charger: %i\n",
680 error);
681 cancel_delayed_work_sync(&ddata->vbus_work);
682 cancel_delayed_work_sync(&ddata->detect_work);
684 return 0;
687 static struct platform_driver cpcap_charger_driver = {
688 .probe = cpcap_charger_probe,
689 .driver = {
690 .name = "cpcap-charger",
691 .of_match_table = of_match_ptr(cpcap_charger_id_table),
693 .remove = cpcap_charger_remove,
695 module_platform_driver(cpcap_charger_driver);
697 MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
698 MODULE_DESCRIPTION("CPCAP Battery Charger Interface driver");
699 MODULE_LICENSE("GPL v2");
700 MODULE_ALIAS("platform:cpcap-charger");