net: Remove casts to same type
[linux-2.6/libata-dev.git] / drivers / power / ab8500_charger.c
blobd2303d0b7c755669f7ab48b968e062474241997b
1 /*
2 * Copyright (C) ST-Ericsson SA 2012
4 * Charger driver for AB8500
6 * License Terms: GNU General Public License v2
7 * Author:
8 * Johan Palsson <johan.palsson@stericsson.com>
9 * Karl Komierowski <karl.komierowski@stericsson.com>
10 * Arun R Murthy <arun.murthy@stericsson.com>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/slab.h>
19 #include <linux/platform_device.h>
20 #include <linux/power_supply.h>
21 #include <linux/completion.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/err.h>
24 #include <linux/workqueue.h>
25 #include <linux/kobject.h>
26 #include <linux/mfd/abx500/ab8500.h>
27 #include <linux/mfd/abx500.h>
28 #include <linux/mfd/abx500/ab8500-bm.h>
29 #include <linux/mfd/abx500/ab8500-gpadc.h>
30 #include <linux/mfd/abx500/ux500_chargalg.h>
31 #include <linux/usb/otg.h>
33 /* Charger constants */
34 #define NO_PW_CONN 0
35 #define AC_PW_CONN 1
36 #define USB_PW_CONN 2
38 #define MAIN_WDOG_ENA 0x01
39 #define MAIN_WDOG_KICK 0x02
40 #define MAIN_WDOG_DIS 0x00
41 #define CHARG_WD_KICK 0x01
42 #define MAIN_CH_ENA 0x01
43 #define MAIN_CH_NO_OVERSHOOT_ENA_N 0x02
44 #define USB_CH_ENA 0x01
45 #define USB_CHG_NO_OVERSHOOT_ENA_N 0x02
46 #define MAIN_CH_DET 0x01
47 #define MAIN_CH_CV_ON 0x04
48 #define USB_CH_CV_ON 0x08
49 #define VBUS_DET_DBNC100 0x02
50 #define VBUS_DET_DBNC1 0x01
51 #define OTP_ENABLE_WD 0x01
53 #define MAIN_CH_INPUT_CURR_SHIFT 4
54 #define VBUS_IN_CURR_LIM_SHIFT 4
56 #define LED_INDICATOR_PWM_ENA 0x01
57 #define LED_INDICATOR_PWM_DIS 0x00
58 #define LED_IND_CUR_5MA 0x04
59 #define LED_INDICATOR_PWM_DUTY_252_256 0xBF
61 /* HW failure constants */
62 #define MAIN_CH_TH_PROT 0x02
63 #define VBUS_CH_NOK 0x08
64 #define USB_CH_TH_PROT 0x02
65 #define VBUS_OVV_TH 0x01
66 #define MAIN_CH_NOK 0x01
67 #define VBUS_DET 0x80
69 /* UsbLineStatus register bit masks */
70 #define AB8500_USB_LINK_STATUS 0x78
71 #define AB8500_STD_HOST_SUSP 0x18
73 /* Watchdog timeout constant */
74 #define WD_TIMER 0x30 /* 4min */
75 #define WD_KICK_INTERVAL (60 * HZ)
77 /* Lowest charger voltage is 3.39V -> 0x4E */
78 #define LOW_VOLT_REG 0x4E
80 /* UsbLineStatus register - usb types */
81 enum ab8500_charger_link_status {
82 USB_STAT_NOT_CONFIGURED,
83 USB_STAT_STD_HOST_NC,
84 USB_STAT_STD_HOST_C_NS,
85 USB_STAT_STD_HOST_C_S,
86 USB_STAT_HOST_CHG_NM,
87 USB_STAT_HOST_CHG_HS,
88 USB_STAT_HOST_CHG_HS_CHIRP,
89 USB_STAT_DEDICATED_CHG,
90 USB_STAT_ACA_RID_A,
91 USB_STAT_ACA_RID_B,
92 USB_STAT_ACA_RID_C_NM,
93 USB_STAT_ACA_RID_C_HS,
94 USB_STAT_ACA_RID_C_HS_CHIRP,
95 USB_STAT_HM_IDGND,
96 USB_STAT_RESERVED,
97 USB_STAT_NOT_VALID_LINK,
100 enum ab8500_usb_state {
101 AB8500_BM_USB_STATE_RESET_HS, /* HighSpeed Reset */
102 AB8500_BM_USB_STATE_RESET_FS, /* FullSpeed/LowSpeed Reset */
103 AB8500_BM_USB_STATE_CONFIGURED,
104 AB8500_BM_USB_STATE_SUSPEND,
105 AB8500_BM_USB_STATE_RESUME,
106 AB8500_BM_USB_STATE_MAX,
109 /* VBUS input current limits supported in AB8500 in mA */
110 #define USB_CH_IP_CUR_LVL_0P05 50
111 #define USB_CH_IP_CUR_LVL_0P09 98
112 #define USB_CH_IP_CUR_LVL_0P19 193
113 #define USB_CH_IP_CUR_LVL_0P29 290
114 #define USB_CH_IP_CUR_LVL_0P38 380
115 #define USB_CH_IP_CUR_LVL_0P45 450
116 #define USB_CH_IP_CUR_LVL_0P5 500
117 #define USB_CH_IP_CUR_LVL_0P6 600
118 #define USB_CH_IP_CUR_LVL_0P7 700
119 #define USB_CH_IP_CUR_LVL_0P8 800
120 #define USB_CH_IP_CUR_LVL_0P9 900
121 #define USB_CH_IP_CUR_LVL_1P0 1000
122 #define USB_CH_IP_CUR_LVL_1P1 1100
123 #define USB_CH_IP_CUR_LVL_1P3 1300
124 #define USB_CH_IP_CUR_LVL_1P4 1400
125 #define USB_CH_IP_CUR_LVL_1P5 1500
127 #define VBAT_TRESH_IP_CUR_RED 3800
129 #define to_ab8500_charger_usb_device_info(x) container_of((x), \
130 struct ab8500_charger, usb_chg)
131 #define to_ab8500_charger_ac_device_info(x) container_of((x), \
132 struct ab8500_charger, ac_chg)
135 * struct ab8500_charger_interrupts - ab8500 interupts
136 * @name: name of the interrupt
137 * @isr function pointer to the isr
139 struct ab8500_charger_interrupts {
140 char *name;
141 irqreturn_t (*isr)(int irq, void *data);
144 struct ab8500_charger_info {
145 int charger_connected;
146 int charger_online;
147 int charger_voltage;
148 int cv_active;
149 bool wd_expired;
152 struct ab8500_charger_event_flags {
153 bool mainextchnotok;
154 bool main_thermal_prot;
155 bool usb_thermal_prot;
156 bool vbus_ovv;
157 bool usbchargernotok;
158 bool chgwdexp;
159 bool vbus_collapse;
162 struct ab8500_charger_usb_state {
163 bool usb_changed;
164 int usb_current;
165 enum ab8500_usb_state state;
166 spinlock_t usb_lock;
170 * struct ab8500_charger - ab8500 Charger device information
171 * @dev: Pointer to the structure device
172 * @max_usb_in_curr: Max USB charger input current
173 * @vbus_detected: VBUS detected
174 * @vbus_detected_start:
175 * VBUS detected during startup
176 * @ac_conn: This will be true when the AC charger has been plugged
177 * @vddadc_en_ac: Indicate if VDD ADC supply is enabled because AC
178 * charger is enabled
179 * @vddadc_en_usb: Indicate if VDD ADC supply is enabled because USB
180 * charger is enabled
181 * @vbat Battery voltage
182 * @old_vbat Previously measured battery voltage
183 * @autopower Indicate if we should have automatic pwron after pwrloss
184 * @parent: Pointer to the struct ab8500
185 * @gpadc: Pointer to the struct gpadc
186 * @pdata: Pointer to the abx500_charger platform data
187 * @bat: Pointer to the abx500_bm platform data
188 * @flags: Structure for information about events triggered
189 * @usb_state: Structure for usb stack information
190 * @ac_chg: AC charger power supply
191 * @usb_chg: USB charger power supply
192 * @ac: Structure that holds the AC charger properties
193 * @usb: Structure that holds the USB charger properties
194 * @regu: Pointer to the struct regulator
195 * @charger_wq: Work queue for the IRQs and checking HW state
196 * @check_vbat_work Work for checking vbat threshold to adjust vbus current
197 * @check_hw_failure_work: Work for checking HW state
198 * @check_usbchgnotok_work: Work for checking USB charger not ok status
199 * @kick_wd_work: Work for kicking the charger watchdog in case
200 * of ABB rev 1.* due to the watchog logic bug
201 * @ac_work: Work for checking AC charger connection
202 * @detect_usb_type_work: Work for detecting the USB type connected
203 * @usb_link_status_work: Work for checking the new USB link status
204 * @usb_state_changed_work: Work for checking USB state
205 * @check_main_thermal_prot_work:
206 * Work for checking Main thermal status
207 * @check_usb_thermal_prot_work:
208 * Work for checking USB thermal status
210 struct ab8500_charger {
211 struct device *dev;
212 int max_usb_in_curr;
213 bool vbus_detected;
214 bool vbus_detected_start;
215 bool ac_conn;
216 bool vddadc_en_ac;
217 bool vddadc_en_usb;
218 int vbat;
219 int old_vbat;
220 bool autopower;
221 struct ab8500 *parent;
222 struct ab8500_gpadc *gpadc;
223 struct abx500_charger_platform_data *pdata;
224 struct abx500_bm_data *bat;
225 struct ab8500_charger_event_flags flags;
226 struct ab8500_charger_usb_state usb_state;
227 struct ux500_charger ac_chg;
228 struct ux500_charger usb_chg;
229 struct ab8500_charger_info ac;
230 struct ab8500_charger_info usb;
231 struct regulator *regu;
232 struct workqueue_struct *charger_wq;
233 struct delayed_work check_vbat_work;
234 struct delayed_work check_hw_failure_work;
235 struct delayed_work check_usbchgnotok_work;
236 struct delayed_work kick_wd_work;
237 struct work_struct ac_work;
238 struct work_struct detect_usb_type_work;
239 struct work_struct usb_link_status_work;
240 struct work_struct usb_state_changed_work;
241 struct work_struct check_main_thermal_prot_work;
242 struct work_struct check_usb_thermal_prot_work;
243 struct usb_phy *usb_phy;
244 struct notifier_block nb;
247 /* AC properties */
248 static enum power_supply_property ab8500_charger_ac_props[] = {
249 POWER_SUPPLY_PROP_HEALTH,
250 POWER_SUPPLY_PROP_PRESENT,
251 POWER_SUPPLY_PROP_ONLINE,
252 POWER_SUPPLY_PROP_VOLTAGE_NOW,
253 POWER_SUPPLY_PROP_VOLTAGE_AVG,
254 POWER_SUPPLY_PROP_CURRENT_NOW,
257 /* USB properties */
258 static enum power_supply_property ab8500_charger_usb_props[] = {
259 POWER_SUPPLY_PROP_HEALTH,
260 POWER_SUPPLY_PROP_CURRENT_AVG,
261 POWER_SUPPLY_PROP_PRESENT,
262 POWER_SUPPLY_PROP_ONLINE,
263 POWER_SUPPLY_PROP_VOLTAGE_NOW,
264 POWER_SUPPLY_PROP_VOLTAGE_AVG,
265 POWER_SUPPLY_PROP_CURRENT_NOW,
269 * ab8500_power_loss_handling - set how we handle powerloss.
270 * @di: pointer to the ab8500_charger structure
272 * Magic nummbers are from STE HW department.
274 static void ab8500_power_loss_handling(struct ab8500_charger *di)
276 u8 reg;
277 int ret;
279 dev_dbg(di->dev, "Autopower : %d\n", di->autopower);
281 /* read the autopower register */
282 ret = abx500_get_register_interruptible(di->dev, 0x15, 0x00, &reg);
283 if (ret) {
284 dev_err(di->dev, "%d write failed\n", __LINE__);
285 return;
288 /* enable the OPT emulation registers */
289 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x2);
290 if (ret) {
291 dev_err(di->dev, "%d write failed\n", __LINE__);
292 return;
295 if (di->autopower)
296 reg |= 0x8;
297 else
298 reg &= ~0x8;
300 /* write back the changed value to autopower reg */
301 ret = abx500_set_register_interruptible(di->dev, 0x15, 0x00, reg);
302 if (ret) {
303 dev_err(di->dev, "%d write failed\n", __LINE__);
304 return;
307 /* disable the set OTP registers again */
308 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x0);
309 if (ret) {
310 dev_err(di->dev, "%d write failed\n", __LINE__);
311 return;
316 * ab8500_power_supply_changed - a wrapper with local extentions for
317 * power_supply_changed
318 * @di: pointer to the ab8500_charger structure
319 * @psy: pointer to power_supply_that have changed.
322 static void ab8500_power_supply_changed(struct ab8500_charger *di,
323 struct power_supply *psy)
325 if (di->pdata->autopower_cfg) {
326 if (!di->usb.charger_connected &&
327 !di->ac.charger_connected &&
328 di->autopower) {
329 di->autopower = false;
330 ab8500_power_loss_handling(di);
331 } else if (!di->autopower &&
332 (di->ac.charger_connected ||
333 di->usb.charger_connected)) {
334 di->autopower = true;
335 ab8500_power_loss_handling(di);
338 power_supply_changed(psy);
341 static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,
342 bool connected)
344 if (connected != di->usb.charger_connected) {
345 dev_dbg(di->dev, "USB connected:%i\n", connected);
346 di->usb.charger_connected = connected;
347 sysfs_notify(&di->usb_chg.psy.dev->kobj, NULL, "present");
352 * ab8500_charger_get_ac_voltage() - get ac charger voltage
353 * @di: pointer to the ab8500_charger structure
355 * Returns ac charger voltage (on success)
357 static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di)
359 int vch;
361 /* Only measure voltage if the charger is connected */
362 if (di->ac.charger_connected) {
363 vch = ab8500_gpadc_convert(di->gpadc, MAIN_CHARGER_V);
364 if (vch < 0)
365 dev_err(di->dev, "%s gpadc conv failed,\n", __func__);
366 } else {
367 vch = 0;
369 return vch;
373 * ab8500_charger_ac_cv() - check if the main charger is in CV mode
374 * @di: pointer to the ab8500_charger structure
376 * Returns ac charger CV mode (on success) else error code
378 static int ab8500_charger_ac_cv(struct ab8500_charger *di)
380 u8 val;
381 int ret = 0;
383 /* Only check CV mode if the charger is online */
384 if (di->ac.charger_online) {
385 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
386 AB8500_CH_STATUS1_REG, &val);
387 if (ret < 0) {
388 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
389 return 0;
392 if (val & MAIN_CH_CV_ON)
393 ret = 1;
394 else
395 ret = 0;
398 return ret;
402 * ab8500_charger_get_vbus_voltage() - get vbus voltage
403 * @di: pointer to the ab8500_charger structure
405 * This function returns the vbus voltage.
406 * Returns vbus voltage (on success)
408 static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di)
410 int vch;
412 /* Only measure voltage if the charger is connected */
413 if (di->usb.charger_connected) {
414 vch = ab8500_gpadc_convert(di->gpadc, VBUS_V);
415 if (vch < 0)
416 dev_err(di->dev, "%s gpadc conv failed\n", __func__);
417 } else {
418 vch = 0;
420 return vch;
424 * ab8500_charger_get_usb_current() - get usb charger current
425 * @di: pointer to the ab8500_charger structure
427 * This function returns the usb charger current.
428 * Returns usb current (on success) and error code on failure
430 static int ab8500_charger_get_usb_current(struct ab8500_charger *di)
432 int ich;
434 /* Only measure current if the charger is online */
435 if (di->usb.charger_online) {
436 ich = ab8500_gpadc_convert(di->gpadc, USB_CHARGER_C);
437 if (ich < 0)
438 dev_err(di->dev, "%s gpadc conv failed\n", __func__);
439 } else {
440 ich = 0;
442 return ich;
446 * ab8500_charger_get_ac_current() - get ac charger current
447 * @di: pointer to the ab8500_charger structure
449 * This function returns the ac charger current.
450 * Returns ac current (on success) and error code on failure.
452 static int ab8500_charger_get_ac_current(struct ab8500_charger *di)
454 int ich;
456 /* Only measure current if the charger is online */
457 if (di->ac.charger_online) {
458 ich = ab8500_gpadc_convert(di->gpadc, MAIN_CHARGER_C);
459 if (ich < 0)
460 dev_err(di->dev, "%s gpadc conv failed\n", __func__);
461 } else {
462 ich = 0;
464 return ich;
468 * ab8500_charger_usb_cv() - check if the usb charger is in CV mode
469 * @di: pointer to the ab8500_charger structure
471 * Returns ac charger CV mode (on success) else error code
473 static int ab8500_charger_usb_cv(struct ab8500_charger *di)
475 int ret;
476 u8 val;
478 /* Only check CV mode if the charger is online */
479 if (di->usb.charger_online) {
480 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
481 AB8500_CH_USBCH_STAT1_REG, &val);
482 if (ret < 0) {
483 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
484 return 0;
487 if (val & USB_CH_CV_ON)
488 ret = 1;
489 else
490 ret = 0;
491 } else {
492 ret = 0;
495 return ret;
499 * ab8500_charger_detect_chargers() - Detect the connected chargers
500 * @di: pointer to the ab8500_charger structure
502 * Returns the type of charger connected.
503 * For USB it will not mean we can actually charge from it
504 * but that there is a USB cable connected that we have to
505 * identify. This is used during startup when we don't get
506 * interrupts of the charger detection
508 * Returns an integer value, that means,
509 * NO_PW_CONN no power supply is connected
510 * AC_PW_CONN if the AC power supply is connected
511 * USB_PW_CONN if the USB power supply is connected
512 * AC_PW_CONN + USB_PW_CONN if USB and AC power supplies are both connected
514 static int ab8500_charger_detect_chargers(struct ab8500_charger *di)
516 int result = NO_PW_CONN;
517 int ret;
518 u8 val;
520 /* Check for AC charger */
521 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
522 AB8500_CH_STATUS1_REG, &val);
523 if (ret < 0) {
524 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
525 return ret;
528 if (val & MAIN_CH_DET)
529 result = AC_PW_CONN;
531 /* Check for USB charger */
532 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
533 AB8500_CH_USBCH_STAT1_REG, &val);
534 if (ret < 0) {
535 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
536 return ret;
539 if ((val & VBUS_DET_DBNC1) && (val & VBUS_DET_DBNC100))
540 result |= USB_PW_CONN;
542 return result;
546 * ab8500_charger_max_usb_curr() - get the max curr for the USB type
547 * @di: pointer to the ab8500_charger structure
548 * @link_status: the identified USB type
550 * Get the maximum current that is allowed to be drawn from the host
551 * based on the USB type.
552 * Returns error code in case of failure else 0 on success
554 static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
555 enum ab8500_charger_link_status link_status)
557 int ret = 0;
559 switch (link_status) {
560 case USB_STAT_STD_HOST_NC:
561 case USB_STAT_STD_HOST_C_NS:
562 case USB_STAT_STD_HOST_C_S:
563 dev_dbg(di->dev, "USB Type - Standard host is "
564 "detected through USB driver\n");
565 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P09;
566 break;
567 case USB_STAT_HOST_CHG_HS_CHIRP:
568 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
569 break;
570 case USB_STAT_HOST_CHG_HS:
571 case USB_STAT_ACA_RID_C_HS:
572 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P9;
573 break;
574 case USB_STAT_ACA_RID_A:
576 * Dedicated charger level minus maximum current accessory
577 * can consume (300mA). Closest level is 1100mA
579 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P1;
580 break;
581 case USB_STAT_ACA_RID_B:
583 * Dedicated charger level minus 120mA (20mA for ACA and
584 * 100mA for potential accessory). Closest level is 1300mA
586 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P3;
587 break;
588 case USB_STAT_DEDICATED_CHG:
589 case USB_STAT_HOST_CHG_NM:
590 case USB_STAT_ACA_RID_C_HS_CHIRP:
591 case USB_STAT_ACA_RID_C_NM:
592 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5;
593 break;
594 case USB_STAT_RESERVED:
596 * This state is used to indicate that VBUS has dropped below
597 * the detection level 4 times in a row. This is due to the
598 * charger output current is set to high making the charger
599 * voltage collapse. This have to be propagated through to
600 * chargalg. This is done using the property
601 * POWER_SUPPLY_PROP_CURRENT_AVG = 1
603 di->flags.vbus_collapse = true;
604 dev_dbg(di->dev, "USB Type - USB_STAT_RESERVED "
605 "VBUS has collapsed\n");
606 ret = -1;
607 break;
608 case USB_STAT_HM_IDGND:
609 case USB_STAT_NOT_CONFIGURED:
610 case USB_STAT_NOT_VALID_LINK:
611 dev_err(di->dev, "USB Type - Charging not allowed\n");
612 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05;
613 ret = -ENXIO;
614 break;
615 default:
616 dev_err(di->dev, "USB Type - Unknown\n");
617 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05;
618 ret = -ENXIO;
619 break;
622 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d",
623 link_status, di->max_usb_in_curr);
625 return ret;
629 * ab8500_charger_read_usb_type() - read the type of usb connected
630 * @di: pointer to the ab8500_charger structure
632 * Detect the type of the plugged USB
633 * Returns error code in case of failure else 0 on success
635 static int ab8500_charger_read_usb_type(struct ab8500_charger *di)
637 int ret;
638 u8 val;
640 ret = abx500_get_register_interruptible(di->dev,
641 AB8500_INTERRUPT, AB8500_IT_SOURCE21_REG, &val);
642 if (ret < 0) {
643 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
644 return ret;
646 ret = abx500_get_register_interruptible(di->dev, AB8500_USB,
647 AB8500_USB_LINE_STAT_REG, &val);
648 if (ret < 0) {
649 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
650 return ret;
653 /* get the USB type */
654 val = (val & AB8500_USB_LINK_STATUS) >> 3;
655 ret = ab8500_charger_max_usb_curr(di,
656 (enum ab8500_charger_link_status) val);
658 return ret;
662 * ab8500_charger_detect_usb_type() - get the type of usb connected
663 * @di: pointer to the ab8500_charger structure
665 * Detect the type of the plugged USB
666 * Returns error code in case of failure else 0 on success
668 static int ab8500_charger_detect_usb_type(struct ab8500_charger *di)
670 int i, ret;
671 u8 val;
674 * On getting the VBUS rising edge detect interrupt there
675 * is a 250ms delay after which the register UsbLineStatus
676 * is filled with valid data.
678 for (i = 0; i < 10; i++) {
679 msleep(250);
680 ret = abx500_get_register_interruptible(di->dev,
681 AB8500_INTERRUPT, AB8500_IT_SOURCE21_REG,
682 &val);
683 if (ret < 0) {
684 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
685 return ret;
687 ret = abx500_get_register_interruptible(di->dev, AB8500_USB,
688 AB8500_USB_LINE_STAT_REG, &val);
689 if (ret < 0) {
690 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
691 return ret;
694 * Until the IT source register is read the UsbLineStatus
695 * register is not updated, hence doing the same
696 * Revisit this:
699 /* get the USB type */
700 val = (val & AB8500_USB_LINK_STATUS) >> 3;
701 if (val)
702 break;
704 ret = ab8500_charger_max_usb_curr(di,
705 (enum ab8500_charger_link_status) val);
707 return ret;
711 * This array maps the raw hex value to charger voltage used by the AB8500
712 * Values taken from the UM0836
714 static int ab8500_charger_voltage_map[] = {
715 3500 ,
716 3525 ,
717 3550 ,
718 3575 ,
719 3600 ,
720 3625 ,
721 3650 ,
722 3675 ,
723 3700 ,
724 3725 ,
725 3750 ,
726 3775 ,
727 3800 ,
728 3825 ,
729 3850 ,
730 3875 ,
731 3900 ,
732 3925 ,
733 3950 ,
734 3975 ,
735 4000 ,
736 4025 ,
737 4050 ,
738 4060 ,
739 4070 ,
740 4080 ,
741 4090 ,
742 4100 ,
743 4110 ,
744 4120 ,
745 4130 ,
746 4140 ,
747 4150 ,
748 4160 ,
749 4170 ,
750 4180 ,
751 4190 ,
752 4200 ,
753 4210 ,
754 4220 ,
755 4230 ,
756 4240 ,
757 4250 ,
758 4260 ,
759 4270 ,
760 4280 ,
761 4290 ,
762 4300 ,
763 4310 ,
764 4320 ,
765 4330 ,
766 4340 ,
767 4350 ,
768 4360 ,
769 4370 ,
770 4380 ,
771 4390 ,
772 4400 ,
773 4410 ,
774 4420 ,
775 4430 ,
776 4440 ,
777 4450 ,
778 4460 ,
779 4470 ,
780 4480 ,
781 4490 ,
782 4500 ,
783 4510 ,
784 4520 ,
785 4530 ,
786 4540 ,
787 4550 ,
788 4560 ,
789 4570 ,
790 4580 ,
791 4590 ,
792 4600 ,
796 * This array maps the raw hex value to charger current used by the AB8500
797 * Values taken from the UM0836
799 static int ab8500_charger_current_map[] = {
800 100 ,
801 200 ,
802 300 ,
803 400 ,
804 500 ,
805 600 ,
806 700 ,
807 800 ,
808 900 ,
809 1000 ,
810 1100 ,
811 1200 ,
812 1300 ,
813 1400 ,
814 1500 ,
818 * This array maps the raw hex value to VBUS input current used by the AB8500
819 * Values taken from the UM0836
821 static int ab8500_charger_vbus_in_curr_map[] = {
822 USB_CH_IP_CUR_LVL_0P05,
823 USB_CH_IP_CUR_LVL_0P09,
824 USB_CH_IP_CUR_LVL_0P19,
825 USB_CH_IP_CUR_LVL_0P29,
826 USB_CH_IP_CUR_LVL_0P38,
827 USB_CH_IP_CUR_LVL_0P45,
828 USB_CH_IP_CUR_LVL_0P5,
829 USB_CH_IP_CUR_LVL_0P6,
830 USB_CH_IP_CUR_LVL_0P7,
831 USB_CH_IP_CUR_LVL_0P8,
832 USB_CH_IP_CUR_LVL_0P9,
833 USB_CH_IP_CUR_LVL_1P0,
834 USB_CH_IP_CUR_LVL_1P1,
835 USB_CH_IP_CUR_LVL_1P3,
836 USB_CH_IP_CUR_LVL_1P4,
837 USB_CH_IP_CUR_LVL_1P5,
840 static int ab8500_voltage_to_regval(int voltage)
842 int i;
844 /* Special case for voltage below 3.5V */
845 if (voltage < ab8500_charger_voltage_map[0])
846 return LOW_VOLT_REG;
848 for (i = 1; i < ARRAY_SIZE(ab8500_charger_voltage_map); i++) {
849 if (voltage < ab8500_charger_voltage_map[i])
850 return i - 1;
853 /* If not last element, return error */
854 i = ARRAY_SIZE(ab8500_charger_voltage_map) - 1;
855 if (voltage == ab8500_charger_voltage_map[i])
856 return i;
857 else
858 return -1;
861 static int ab8500_current_to_regval(int curr)
863 int i;
865 if (curr < ab8500_charger_current_map[0])
866 return 0;
868 for (i = 0; i < ARRAY_SIZE(ab8500_charger_current_map); i++) {
869 if (curr < ab8500_charger_current_map[i])
870 return i - 1;
873 /* If not last element, return error */
874 i = ARRAY_SIZE(ab8500_charger_current_map) - 1;
875 if (curr == ab8500_charger_current_map[i])
876 return i;
877 else
878 return -1;
881 static int ab8500_vbus_in_curr_to_regval(int curr)
883 int i;
885 if (curr < ab8500_charger_vbus_in_curr_map[0])
886 return 0;
888 for (i = 0; i < ARRAY_SIZE(ab8500_charger_vbus_in_curr_map); i++) {
889 if (curr < ab8500_charger_vbus_in_curr_map[i])
890 return i - 1;
893 /* If not last element, return error */
894 i = ARRAY_SIZE(ab8500_charger_vbus_in_curr_map) - 1;
895 if (curr == ab8500_charger_vbus_in_curr_map[i])
896 return i;
897 else
898 return -1;
902 * ab8500_charger_get_usb_cur() - get usb current
903 * @di: pointer to the ab8500_charger structre
905 * The usb stack provides the maximum current that can be drawn from
906 * the standard usb host. This will be in mA.
907 * This function converts current in mA to a value that can be written
908 * to the register. Returns -1 if charging is not allowed
910 static int ab8500_charger_get_usb_cur(struct ab8500_charger *di)
912 switch (di->usb_state.usb_current) {
913 case 100:
914 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P09;
915 break;
916 case 200:
917 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P19;
918 break;
919 case 300:
920 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P29;
921 break;
922 case 400:
923 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P38;
924 break;
925 case 500:
926 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
927 break;
928 default:
929 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05;
930 return -1;
931 break;
933 return 0;
937 * ab8500_charger_set_vbus_in_curr() - set VBUS input current limit
938 * @di: pointer to the ab8500_charger structure
939 * @ich_in: charger input current limit
941 * Sets the current that can be drawn from the USB host
942 * Returns error code in case of failure else 0(on success)
944 static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di,
945 int ich_in)
947 int ret;
948 int input_curr_index;
949 int min_value;
951 /* We should always use to lowest current limit */
952 min_value = min(di->bat->chg_params->usb_curr_max, ich_in);
954 switch (min_value) {
955 case 100:
956 if (di->vbat < VBAT_TRESH_IP_CUR_RED)
957 min_value = USB_CH_IP_CUR_LVL_0P05;
958 break;
959 case 500:
960 if (di->vbat < VBAT_TRESH_IP_CUR_RED)
961 min_value = USB_CH_IP_CUR_LVL_0P45;
962 break;
963 default:
964 break;
967 input_curr_index = ab8500_vbus_in_curr_to_regval(min_value);
968 if (input_curr_index < 0) {
969 dev_err(di->dev, "VBUS input current limit too high\n");
970 return -ENXIO;
973 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
974 AB8500_USBCH_IPT_CRNTLVL_REG,
975 input_curr_index << VBUS_IN_CURR_LIM_SHIFT);
976 if (ret)
977 dev_err(di->dev, "%s write failed\n", __func__);
979 return ret;
983 * ab8500_charger_led_en() - turn on/off chargign led
984 * @di: pointer to the ab8500_charger structure
985 * @on: flag to turn on/off the chargign led
987 * Power ON/OFF charging LED indication
988 * Returns error code in case of failure else 0(on success)
990 static int ab8500_charger_led_en(struct ab8500_charger *di, int on)
992 int ret;
994 if (on) {
995 /* Power ON charging LED indicator, set LED current to 5mA */
996 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
997 AB8500_LED_INDICATOR_PWM_CTRL,
998 (LED_IND_CUR_5MA | LED_INDICATOR_PWM_ENA));
999 if (ret) {
1000 dev_err(di->dev, "Power ON LED failed\n");
1001 return ret;
1003 /* LED indicator PWM duty cycle 252/256 */
1004 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1005 AB8500_LED_INDICATOR_PWM_DUTY,
1006 LED_INDICATOR_PWM_DUTY_252_256);
1007 if (ret) {
1008 dev_err(di->dev, "Set LED PWM duty cycle failed\n");
1009 return ret;
1011 } else {
1012 /* Power off charging LED indicator */
1013 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1014 AB8500_LED_INDICATOR_PWM_CTRL,
1015 LED_INDICATOR_PWM_DIS);
1016 if (ret) {
1017 dev_err(di->dev, "Power-off LED failed\n");
1018 return ret;
1022 return ret;
1026 * ab8500_charger_ac_en() - enable or disable ac charging
1027 * @di: pointer to the ab8500_charger structure
1028 * @enable: enable/disable flag
1029 * @vset: charging voltage
1030 * @iset: charging current
1032 * Enable/Disable AC/Mains charging and turns on/off the charging led
1033 * respectively.
1035 static int ab8500_charger_ac_en(struct ux500_charger *charger,
1036 int enable, int vset, int iset)
1038 int ret;
1039 int volt_index;
1040 int curr_index;
1041 int input_curr_index;
1042 u8 overshoot = 0;
1044 struct ab8500_charger *di = to_ab8500_charger_ac_device_info(charger);
1046 if (enable) {
1047 /* Check if AC is connected */
1048 if (!di->ac.charger_connected) {
1049 dev_err(di->dev, "AC charger not connected\n");
1050 return -ENXIO;
1053 /* Enable AC charging */
1054 dev_dbg(di->dev, "Enable AC: %dmV %dmA\n", vset, iset);
1057 * Due to a bug in AB8500, BTEMP_HIGH/LOW interrupts
1058 * will be triggered everytime we enable the VDD ADC supply.
1059 * This will turn off charging for a short while.
1060 * It can be avoided by having the supply on when
1061 * there is a charger enabled. Normally the VDD ADC supply
1062 * is enabled everytime a GPADC conversion is triggered. We will
1063 * force it to be enabled from this driver to have
1064 * the GPADC module independant of the AB8500 chargers
1066 if (!di->vddadc_en_ac) {
1067 regulator_enable(di->regu);
1068 di->vddadc_en_ac = true;
1071 /* Check if the requested voltage or current is valid */
1072 volt_index = ab8500_voltage_to_regval(vset);
1073 curr_index = ab8500_current_to_regval(iset);
1074 input_curr_index = ab8500_current_to_regval(
1075 di->bat->chg_params->ac_curr_max);
1076 if (volt_index < 0 || curr_index < 0 || input_curr_index < 0) {
1077 dev_err(di->dev,
1078 "Charger voltage or current too high, "
1079 "charging not started\n");
1080 return -ENXIO;
1083 /* ChVoltLevel: maximum battery charging voltage */
1084 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1085 AB8500_CH_VOLT_LVL_REG, (u8) volt_index);
1086 if (ret) {
1087 dev_err(di->dev, "%s write failed\n", __func__);
1088 return ret;
1090 /* MainChInputCurr: current that can be drawn from the charger*/
1091 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1092 AB8500_MCH_IPT_CURLVL_REG,
1093 input_curr_index << MAIN_CH_INPUT_CURR_SHIFT);
1094 if (ret) {
1095 dev_err(di->dev, "%s write failed\n", __func__);
1096 return ret;
1098 /* ChOutputCurentLevel: protected output current */
1099 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1100 AB8500_CH_OPT_CRNTLVL_REG, (u8) curr_index);
1101 if (ret) {
1102 dev_err(di->dev, "%s write failed\n", __func__);
1103 return ret;
1106 /* Check if VBAT overshoot control should be enabled */
1107 if (!di->bat->enable_overshoot)
1108 overshoot = MAIN_CH_NO_OVERSHOOT_ENA_N;
1110 /* Enable Main Charger */
1111 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1112 AB8500_MCH_CTRL1, MAIN_CH_ENA | overshoot);
1113 if (ret) {
1114 dev_err(di->dev, "%s write failed\n", __func__);
1115 return ret;
1118 /* Power on charging LED indication */
1119 ret = ab8500_charger_led_en(di, true);
1120 if (ret < 0)
1121 dev_err(di->dev, "failed to enable LED\n");
1123 di->ac.charger_online = 1;
1124 } else {
1125 /* Disable AC charging */
1126 if (is_ab8500_1p1_or_earlier(di->parent)) {
1128 * For ABB revision 1.0 and 1.1 there is a bug in the
1129 * watchdog logic. That means we have to continously
1130 * kick the charger watchdog even when no charger is
1131 * connected. This is only valid once the AC charger
1132 * has been enabled. This is a bug that is not handled
1133 * by the algorithm and the watchdog have to be kicked
1134 * by the charger driver when the AC charger
1135 * is disabled
1137 if (di->ac_conn) {
1138 queue_delayed_work(di->charger_wq,
1139 &di->kick_wd_work,
1140 round_jiffies(WD_KICK_INTERVAL));
1144 * We can't turn off charging completely
1145 * due to a bug in AB8500 cut1.
1146 * If we do, charging will not start again.
1147 * That is why we set the lowest voltage
1148 * and current possible
1150 ret = abx500_set_register_interruptible(di->dev,
1151 AB8500_CHARGER,
1152 AB8500_CH_VOLT_LVL_REG, CH_VOL_LVL_3P5);
1153 if (ret) {
1154 dev_err(di->dev,
1155 "%s write failed\n", __func__);
1156 return ret;
1159 ret = abx500_set_register_interruptible(di->dev,
1160 AB8500_CHARGER,
1161 AB8500_CH_OPT_CRNTLVL_REG, CH_OP_CUR_LVL_0P1);
1162 if (ret) {
1163 dev_err(di->dev,
1164 "%s write failed\n", __func__);
1165 return ret;
1167 } else {
1168 ret = abx500_set_register_interruptible(di->dev,
1169 AB8500_CHARGER,
1170 AB8500_MCH_CTRL1, 0);
1171 if (ret) {
1172 dev_err(di->dev,
1173 "%s write failed\n", __func__);
1174 return ret;
1178 ret = ab8500_charger_led_en(di, false);
1179 if (ret < 0)
1180 dev_err(di->dev, "failed to disable LED\n");
1182 di->ac.charger_online = 0;
1183 di->ac.wd_expired = false;
1185 /* Disable regulator if enabled */
1186 if (di->vddadc_en_ac) {
1187 regulator_disable(di->regu);
1188 di->vddadc_en_ac = false;
1191 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__);
1193 ab8500_power_supply_changed(di, &di->ac_chg.psy);
1195 return ret;
1199 * ab8500_charger_usb_en() - enable usb charging
1200 * @di: pointer to the ab8500_charger structure
1201 * @enable: enable/disable flag
1202 * @vset: charging voltage
1203 * @ich_out: charger output current
1205 * Enable/Disable USB charging and turns on/off the charging led respectively.
1206 * Returns error code in case of failure else 0(on success)
1208 static int ab8500_charger_usb_en(struct ux500_charger *charger,
1209 int enable, int vset, int ich_out)
1211 int ret;
1212 int volt_index;
1213 int curr_index;
1214 u8 overshoot = 0;
1216 struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger);
1218 if (enable) {
1219 /* Check if USB is connected */
1220 if (!di->usb.charger_connected) {
1221 dev_err(di->dev, "USB charger not connected\n");
1222 return -ENXIO;
1226 * Due to a bug in AB8500, BTEMP_HIGH/LOW interrupts
1227 * will be triggered everytime we enable the VDD ADC supply.
1228 * This will turn off charging for a short while.
1229 * It can be avoided by having the supply on when
1230 * there is a charger enabled. Normally the VDD ADC supply
1231 * is enabled everytime a GPADC conversion is triggered. We will
1232 * force it to be enabled from this driver to have
1233 * the GPADC module independant of the AB8500 chargers
1235 if (!di->vddadc_en_usb) {
1236 regulator_enable(di->regu);
1237 di->vddadc_en_usb = true;
1240 /* Enable USB charging */
1241 dev_dbg(di->dev, "Enable USB: %dmV %dmA\n", vset, ich_out);
1243 /* Check if the requested voltage or current is valid */
1244 volt_index = ab8500_voltage_to_regval(vset);
1245 curr_index = ab8500_current_to_regval(ich_out);
1246 if (volt_index < 0 || curr_index < 0) {
1247 dev_err(di->dev,
1248 "Charger voltage or current too high, "
1249 "charging not started\n");
1250 return -ENXIO;
1253 /* ChVoltLevel: max voltage upto which battery can be charged */
1254 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1255 AB8500_CH_VOLT_LVL_REG, (u8) volt_index);
1256 if (ret) {
1257 dev_err(di->dev, "%s write failed\n", __func__);
1258 return ret;
1260 /* USBChInputCurr: current that can be drawn from the usb */
1261 ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr);
1262 if (ret) {
1263 dev_err(di->dev, "setting USBChInputCurr failed\n");
1264 return ret;
1266 /* ChOutputCurentLevel: protected output current */
1267 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1268 AB8500_CH_OPT_CRNTLVL_REG, (u8) curr_index);
1269 if (ret) {
1270 dev_err(di->dev, "%s write failed\n", __func__);
1271 return ret;
1273 /* Check if VBAT overshoot control should be enabled */
1274 if (!di->bat->enable_overshoot)
1275 overshoot = USB_CHG_NO_OVERSHOOT_ENA_N;
1277 /* Enable USB Charger */
1278 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1279 AB8500_USBCH_CTRL1_REG, USB_CH_ENA | overshoot);
1280 if (ret) {
1281 dev_err(di->dev, "%s write failed\n", __func__);
1282 return ret;
1285 /* If success power on charging LED indication */
1286 ret = ab8500_charger_led_en(di, true);
1287 if (ret < 0)
1288 dev_err(di->dev, "failed to enable LED\n");
1290 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ);
1292 di->usb.charger_online = 1;
1293 } else {
1294 /* Disable USB charging */
1295 ret = abx500_set_register_interruptible(di->dev,
1296 AB8500_CHARGER,
1297 AB8500_USBCH_CTRL1_REG, 0);
1298 if (ret) {
1299 dev_err(di->dev,
1300 "%s write failed\n", __func__);
1301 return ret;
1304 ret = ab8500_charger_led_en(di, false);
1305 if (ret < 0)
1306 dev_err(di->dev, "failed to disable LED\n");
1308 di->usb.charger_online = 0;
1309 di->usb.wd_expired = false;
1311 /* Disable regulator if enabled */
1312 if (di->vddadc_en_usb) {
1313 regulator_disable(di->regu);
1314 di->vddadc_en_usb = false;
1317 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__);
1319 /* Cancel any pending Vbat check work */
1320 if (delayed_work_pending(&di->check_vbat_work))
1321 cancel_delayed_work(&di->check_vbat_work);
1324 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1326 return ret;
1330 * ab8500_charger_watchdog_kick() - kick charger watchdog
1331 * @di: pointer to the ab8500_charger structure
1333 * Kick charger watchdog
1334 * Returns error code in case of failure else 0(on success)
1336 static int ab8500_charger_watchdog_kick(struct ux500_charger *charger)
1338 int ret;
1339 struct ab8500_charger *di;
1341 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS)
1342 di = to_ab8500_charger_ac_device_info(charger);
1343 else if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1344 di = to_ab8500_charger_usb_device_info(charger);
1345 else
1346 return -ENXIO;
1348 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1349 AB8500_CHARG_WD_CTRL, CHARG_WD_KICK);
1350 if (ret)
1351 dev_err(di->dev, "Failed to kick WD!\n");
1353 return ret;
1357 * ab8500_charger_update_charger_current() - update charger current
1358 * @di: pointer to the ab8500_charger structure
1360 * Update the charger output current for the specified charger
1361 * Returns error code in case of failure else 0(on success)
1363 static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
1364 int ich_out)
1366 int ret;
1367 int curr_index;
1368 struct ab8500_charger *di;
1370 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS)
1371 di = to_ab8500_charger_ac_device_info(charger);
1372 else if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1373 di = to_ab8500_charger_usb_device_info(charger);
1374 else
1375 return -ENXIO;
1377 curr_index = ab8500_current_to_regval(ich_out);
1378 if (curr_index < 0) {
1379 dev_err(di->dev,
1380 "Charger current too high, "
1381 "charging not started\n");
1382 return -ENXIO;
1385 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1386 AB8500_CH_OPT_CRNTLVL_REG, (u8) curr_index);
1387 if (ret) {
1388 dev_err(di->dev, "%s write failed\n", __func__);
1389 return ret;
1392 /* Reset the main and usb drop input current measurement counter */
1393 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1394 AB8500_CHARGER_CTRL,
1395 0x1);
1396 if (ret) {
1397 dev_err(di->dev, "%s write failed\n", __func__);
1398 return ret;
1401 return ret;
1404 static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
1406 struct power_supply *psy;
1407 struct power_supply *ext;
1408 struct ab8500_charger *di;
1409 union power_supply_propval ret;
1410 int i, j;
1411 bool psy_found = false;
1412 struct ux500_charger *usb_chg;
1414 usb_chg = (struct ux500_charger *)data;
1415 psy = &usb_chg->psy;
1417 di = to_ab8500_charger_usb_device_info(usb_chg);
1419 ext = dev_get_drvdata(dev);
1421 /* For all psy where the driver name appears in any supplied_to */
1422 for (i = 0; i < ext->num_supplicants; i++) {
1423 if (!strcmp(ext->supplied_to[i], psy->name))
1424 psy_found = true;
1427 if (!psy_found)
1428 return 0;
1430 /* Go through all properties for the psy */
1431 for (j = 0; j < ext->num_properties; j++) {
1432 enum power_supply_property prop;
1433 prop = ext->properties[j];
1435 if (ext->get_property(ext, prop, &ret))
1436 continue;
1438 switch (prop) {
1439 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1440 switch (ext->type) {
1441 case POWER_SUPPLY_TYPE_BATTERY:
1442 di->vbat = ret.intval / 1000;
1443 break;
1444 default:
1445 break;
1447 break;
1448 default:
1449 break;
1452 return 0;
1456 * ab8500_charger_check_vbat_work() - keep vbus current within spec
1457 * @work pointer to the work_struct structure
1459 * Due to a asic bug it is necessary to lower the input current to the vbus
1460 * charger when charging with at some specific levels. This issue is only valid
1461 * for below a certain battery voltage. This function makes sure that the
1462 * the allowed current limit isn't exceeded.
1464 static void ab8500_charger_check_vbat_work(struct work_struct *work)
1466 int t = 10;
1467 struct ab8500_charger *di = container_of(work,
1468 struct ab8500_charger, check_vbat_work.work);
1470 class_for_each_device(power_supply_class, NULL,
1471 &di->usb_chg.psy, ab8500_charger_get_ext_psy_data);
1473 /* First run old_vbat is 0. */
1474 if (di->old_vbat == 0)
1475 di->old_vbat = di->vbat;
1477 if (!((di->old_vbat <= VBAT_TRESH_IP_CUR_RED &&
1478 di->vbat <= VBAT_TRESH_IP_CUR_RED) ||
1479 (di->old_vbat > VBAT_TRESH_IP_CUR_RED &&
1480 di->vbat > VBAT_TRESH_IP_CUR_RED))) {
1482 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d,"
1483 " old: %d\n", di->max_usb_in_curr, di->vbat,
1484 di->old_vbat);
1485 ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr);
1486 power_supply_changed(&di->usb_chg.psy);
1489 di->old_vbat = di->vbat;
1492 * No need to check the battery voltage every second when not close to
1493 * the threshold.
1495 if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100) &&
1496 (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100)))
1497 t = 1;
1499 queue_delayed_work(di->charger_wq, &di->check_vbat_work, t * HZ);
1503 * ab8500_charger_check_hw_failure_work() - check main charger failure
1504 * @work: pointer to the work_struct structure
1506 * Work queue function for checking the main charger status
1508 static void ab8500_charger_check_hw_failure_work(struct work_struct *work)
1510 int ret;
1511 u8 reg_value;
1513 struct ab8500_charger *di = container_of(work,
1514 struct ab8500_charger, check_hw_failure_work.work);
1516 /* Check if the status bits for HW failure is still active */
1517 if (di->flags.mainextchnotok) {
1518 ret = abx500_get_register_interruptible(di->dev,
1519 AB8500_CHARGER, AB8500_CH_STATUS2_REG, &reg_value);
1520 if (ret < 0) {
1521 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
1522 return;
1524 if (!(reg_value & MAIN_CH_NOK)) {
1525 di->flags.mainextchnotok = false;
1526 ab8500_power_supply_changed(di, &di->ac_chg.psy);
1529 if (di->flags.vbus_ovv) {
1530 ret = abx500_get_register_interruptible(di->dev,
1531 AB8500_CHARGER, AB8500_CH_USBCH_STAT2_REG,
1532 &reg_value);
1533 if (ret < 0) {
1534 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
1535 return;
1537 if (!(reg_value & VBUS_OVV_TH)) {
1538 di->flags.vbus_ovv = false;
1539 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1542 /* If we still have a failure, schedule a new check */
1543 if (di->flags.mainextchnotok || di->flags.vbus_ovv) {
1544 queue_delayed_work(di->charger_wq,
1545 &di->check_hw_failure_work, round_jiffies(HZ));
1550 * ab8500_charger_kick_watchdog_work() - kick the watchdog
1551 * @work: pointer to the work_struct structure
1553 * Work queue function for kicking the charger watchdog.
1555 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
1556 * logic. That means we have to continously kick the charger
1557 * watchdog even when no charger is connected. This is only
1558 * valid once the AC charger has been enabled. This is
1559 * a bug that is not handled by the algorithm and the
1560 * watchdog have to be kicked by the charger driver
1561 * when the AC charger is disabled
1563 static void ab8500_charger_kick_watchdog_work(struct work_struct *work)
1565 int ret;
1567 struct ab8500_charger *di = container_of(work,
1568 struct ab8500_charger, kick_wd_work.work);
1570 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1571 AB8500_CHARG_WD_CTRL, CHARG_WD_KICK);
1572 if (ret)
1573 dev_err(di->dev, "Failed to kick WD!\n");
1575 /* Schedule a new watchdog kick */
1576 queue_delayed_work(di->charger_wq,
1577 &di->kick_wd_work, round_jiffies(WD_KICK_INTERVAL));
1581 * ab8500_charger_ac_work() - work to get and set main charger status
1582 * @work: pointer to the work_struct structure
1584 * Work queue function for checking the main charger status
1586 static void ab8500_charger_ac_work(struct work_struct *work)
1588 int ret;
1590 struct ab8500_charger *di = container_of(work,
1591 struct ab8500_charger, ac_work);
1594 * Since we can't be sure that the events are received
1595 * synchronously, we have the check if the main charger is
1596 * connected by reading the status register
1598 ret = ab8500_charger_detect_chargers(di);
1599 if (ret < 0)
1600 return;
1602 if (ret & AC_PW_CONN) {
1603 di->ac.charger_connected = 1;
1604 di->ac_conn = true;
1605 } else {
1606 di->ac.charger_connected = 0;
1609 ab8500_power_supply_changed(di, &di->ac_chg.psy);
1610 sysfs_notify(&di->ac_chg.psy.dev->kobj, NULL, "present");
1614 * ab8500_charger_detect_usb_type_work() - work to detect USB type
1615 * @work: Pointer to the work_struct structure
1617 * Detect the type of USB plugged
1619 static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
1621 int ret;
1623 struct ab8500_charger *di = container_of(work,
1624 struct ab8500_charger, detect_usb_type_work);
1627 * Since we can't be sure that the events are received
1628 * synchronously, we have the check if is
1629 * connected by reading the status register
1631 ret = ab8500_charger_detect_chargers(di);
1632 if (ret < 0)
1633 return;
1635 if (!(ret & USB_PW_CONN)) {
1636 di->vbus_detected = 0;
1637 ab8500_charger_set_usb_connected(di, false);
1638 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1639 } else {
1640 di->vbus_detected = 1;
1642 if (is_ab8500_1p1_or_earlier(di->parent)) {
1643 ret = ab8500_charger_detect_usb_type(di);
1644 if (!ret) {
1645 ab8500_charger_set_usb_connected(di, true);
1646 ab8500_power_supply_changed(di,
1647 &di->usb_chg.psy);
1649 } else {
1650 /* For ABB cut2.0 and onwards we have an IRQ,
1651 * USB_LINK_STATUS that will be triggered when the USB
1652 * link status changes. The exception is USB connected
1653 * during startup. Then we don't get a
1654 * USB_LINK_STATUS IRQ
1656 if (di->vbus_detected_start) {
1657 di->vbus_detected_start = false;
1658 ret = ab8500_charger_detect_usb_type(di);
1659 if (!ret) {
1660 ab8500_charger_set_usb_connected(di,
1661 true);
1662 ab8500_power_supply_changed(di,
1663 &di->usb_chg.psy);
1671 * ab8500_charger_usb_link_status_work() - work to detect USB type
1672 * @work: pointer to the work_struct structure
1674 * Detect the type of USB plugged
1676 static void ab8500_charger_usb_link_status_work(struct work_struct *work)
1678 int ret;
1680 struct ab8500_charger *di = container_of(work,
1681 struct ab8500_charger, usb_link_status_work);
1684 * Since we can't be sure that the events are received
1685 * synchronously, we have the check if is
1686 * connected by reading the status register
1688 ret = ab8500_charger_detect_chargers(di);
1689 if (ret < 0)
1690 return;
1692 if (!(ret & USB_PW_CONN)) {
1693 di->vbus_detected = 0;
1694 ab8500_charger_set_usb_connected(di, false);
1695 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1696 } else {
1697 di->vbus_detected = 1;
1698 ret = ab8500_charger_read_usb_type(di);
1699 if (!ret) {
1700 /* Update maximum input current */
1701 ret = ab8500_charger_set_vbus_in_curr(di,
1702 di->max_usb_in_curr);
1703 if (ret)
1704 return;
1706 ab8500_charger_set_usb_connected(di, true);
1707 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1708 } else if (ret == -ENXIO) {
1709 /* No valid charger type detected */
1710 ab8500_charger_set_usb_connected(di, false);
1711 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1716 static void ab8500_charger_usb_state_changed_work(struct work_struct *work)
1718 int ret;
1719 unsigned long flags;
1721 struct ab8500_charger *di = container_of(work,
1722 struct ab8500_charger, usb_state_changed_work);
1724 if (!di->vbus_detected)
1725 return;
1727 spin_lock_irqsave(&di->usb_state.usb_lock, flags);
1728 di->usb_state.usb_changed = false;
1729 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags);
1732 * wait for some time until you get updates from the usb stack
1733 * and negotiations are completed
1735 msleep(250);
1737 if (di->usb_state.usb_changed)
1738 return;
1740 dev_dbg(di->dev, "%s USB state: 0x%02x mA: %d\n",
1741 __func__, di->usb_state.state, di->usb_state.usb_current);
1743 switch (di->usb_state.state) {
1744 case AB8500_BM_USB_STATE_RESET_HS:
1745 case AB8500_BM_USB_STATE_RESET_FS:
1746 case AB8500_BM_USB_STATE_SUSPEND:
1747 case AB8500_BM_USB_STATE_MAX:
1748 ab8500_charger_set_usb_connected(di, false);
1749 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1750 break;
1752 case AB8500_BM_USB_STATE_RESUME:
1754 * when suspend->resume there should be delay
1755 * of 1sec for enabling charging
1757 msleep(1000);
1758 /* Intentional fall through */
1759 case AB8500_BM_USB_STATE_CONFIGURED:
1761 * USB is configured, enable charging with the charging
1762 * input current obtained from USB driver
1764 if (!ab8500_charger_get_usb_cur(di)) {
1765 /* Update maximum input current */
1766 ret = ab8500_charger_set_vbus_in_curr(di,
1767 di->max_usb_in_curr);
1768 if (ret)
1769 return;
1771 ab8500_charger_set_usb_connected(di, true);
1772 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1774 break;
1776 default:
1777 break;
1782 * ab8500_charger_check_usbchargernotok_work() - check USB chg not ok status
1783 * @work: pointer to the work_struct structure
1785 * Work queue function for checking the USB charger Not OK status
1787 static void ab8500_charger_check_usbchargernotok_work(struct work_struct *work)
1789 int ret;
1790 u8 reg_value;
1791 bool prev_status;
1793 struct ab8500_charger *di = container_of(work,
1794 struct ab8500_charger, check_usbchgnotok_work.work);
1796 /* Check if the status bit for usbchargernotok is still active */
1797 ret = abx500_get_register_interruptible(di->dev,
1798 AB8500_CHARGER, AB8500_CH_USBCH_STAT2_REG, &reg_value);
1799 if (ret < 0) {
1800 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
1801 return;
1803 prev_status = di->flags.usbchargernotok;
1805 if (reg_value & VBUS_CH_NOK) {
1806 di->flags.usbchargernotok = true;
1807 /* Check again in 1sec */
1808 queue_delayed_work(di->charger_wq,
1809 &di->check_usbchgnotok_work, HZ);
1810 } else {
1811 di->flags.usbchargernotok = false;
1812 di->flags.vbus_collapse = false;
1815 if (prev_status != di->flags.usbchargernotok)
1816 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1820 * ab8500_charger_check_main_thermal_prot_work() - check main thermal status
1821 * @work: pointer to the work_struct structure
1823 * Work queue function for checking the Main thermal prot status
1825 static void ab8500_charger_check_main_thermal_prot_work(
1826 struct work_struct *work)
1828 int ret;
1829 u8 reg_value;
1831 struct ab8500_charger *di = container_of(work,
1832 struct ab8500_charger, check_main_thermal_prot_work);
1834 /* Check if the status bit for main_thermal_prot is still active */
1835 ret = abx500_get_register_interruptible(di->dev,
1836 AB8500_CHARGER, AB8500_CH_STATUS2_REG, &reg_value);
1837 if (ret < 0) {
1838 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
1839 return;
1841 if (reg_value & MAIN_CH_TH_PROT)
1842 di->flags.main_thermal_prot = true;
1843 else
1844 di->flags.main_thermal_prot = false;
1846 ab8500_power_supply_changed(di, &di->ac_chg.psy);
1850 * ab8500_charger_check_usb_thermal_prot_work() - check usb thermal status
1851 * @work: pointer to the work_struct structure
1853 * Work queue function for checking the USB thermal prot status
1855 static void ab8500_charger_check_usb_thermal_prot_work(
1856 struct work_struct *work)
1858 int ret;
1859 u8 reg_value;
1861 struct ab8500_charger *di = container_of(work,
1862 struct ab8500_charger, check_usb_thermal_prot_work);
1864 /* Check if the status bit for usb_thermal_prot is still active */
1865 ret = abx500_get_register_interruptible(di->dev,
1866 AB8500_CHARGER, AB8500_CH_USBCH_STAT2_REG, &reg_value);
1867 if (ret < 0) {
1868 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
1869 return;
1871 if (reg_value & USB_CH_TH_PROT)
1872 di->flags.usb_thermal_prot = true;
1873 else
1874 di->flags.usb_thermal_prot = false;
1876 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1880 * ab8500_charger_mainchunplugdet_handler() - main charger unplugged
1881 * @irq: interrupt number
1882 * @_di: pointer to the ab8500_charger structure
1884 * Returns IRQ status(IRQ_HANDLED)
1886 static irqreturn_t ab8500_charger_mainchunplugdet_handler(int irq, void *_di)
1888 struct ab8500_charger *di = _di;
1890 dev_dbg(di->dev, "Main charger unplugged\n");
1891 queue_work(di->charger_wq, &di->ac_work);
1893 return IRQ_HANDLED;
1897 * ab8500_charger_mainchplugdet_handler() - main charger plugged
1898 * @irq: interrupt number
1899 * @_di: pointer to the ab8500_charger structure
1901 * Returns IRQ status(IRQ_HANDLED)
1903 static irqreturn_t ab8500_charger_mainchplugdet_handler(int irq, void *_di)
1905 struct ab8500_charger *di = _di;
1907 dev_dbg(di->dev, "Main charger plugged\n");
1908 queue_work(di->charger_wq, &di->ac_work);
1910 return IRQ_HANDLED;
1914 * ab8500_charger_mainextchnotok_handler() - main charger not ok
1915 * @irq: interrupt number
1916 * @_di: pointer to the ab8500_charger structure
1918 * Returns IRQ status(IRQ_HANDLED)
1920 static irqreturn_t ab8500_charger_mainextchnotok_handler(int irq, void *_di)
1922 struct ab8500_charger *di = _di;
1924 dev_dbg(di->dev, "Main charger not ok\n");
1925 di->flags.mainextchnotok = true;
1926 ab8500_power_supply_changed(di, &di->ac_chg.psy);
1928 /* Schedule a new HW failure check */
1929 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0);
1931 return IRQ_HANDLED;
1935 * ab8500_charger_mainchthprotr_handler() - Die temp is above main charger
1936 * thermal protection threshold
1937 * @irq: interrupt number
1938 * @_di: pointer to the ab8500_charger structure
1940 * Returns IRQ status(IRQ_HANDLED)
1942 static irqreturn_t ab8500_charger_mainchthprotr_handler(int irq, void *_di)
1944 struct ab8500_charger *di = _di;
1946 dev_dbg(di->dev,
1947 "Die temp above Main charger thermal protection threshold\n");
1948 queue_work(di->charger_wq, &di->check_main_thermal_prot_work);
1950 return IRQ_HANDLED;
1954 * ab8500_charger_mainchthprotf_handler() - Die temp is below main charger
1955 * thermal protection threshold
1956 * @irq: interrupt number
1957 * @_di: pointer to the ab8500_charger structure
1959 * Returns IRQ status(IRQ_HANDLED)
1961 static irqreturn_t ab8500_charger_mainchthprotf_handler(int irq, void *_di)
1963 struct ab8500_charger *di = _di;
1965 dev_dbg(di->dev,
1966 "Die temp ok for Main charger thermal protection threshold\n");
1967 queue_work(di->charger_wq, &di->check_main_thermal_prot_work);
1969 return IRQ_HANDLED;
1973 * ab8500_charger_vbusdetf_handler() - VBUS falling detected
1974 * @irq: interrupt number
1975 * @_di: pointer to the ab8500_charger structure
1977 * Returns IRQ status(IRQ_HANDLED)
1979 static irqreturn_t ab8500_charger_vbusdetf_handler(int irq, void *_di)
1981 struct ab8500_charger *di = _di;
1983 dev_dbg(di->dev, "VBUS falling detected\n");
1984 queue_work(di->charger_wq, &di->detect_usb_type_work);
1986 return IRQ_HANDLED;
1990 * ab8500_charger_vbusdetr_handler() - VBUS rising detected
1991 * @irq: interrupt number
1992 * @_di: pointer to the ab8500_charger structure
1994 * Returns IRQ status(IRQ_HANDLED)
1996 static irqreturn_t ab8500_charger_vbusdetr_handler(int irq, void *_di)
1998 struct ab8500_charger *di = _di;
2000 di->vbus_detected = true;
2001 dev_dbg(di->dev, "VBUS rising detected\n");
2002 queue_work(di->charger_wq, &di->detect_usb_type_work);
2004 return IRQ_HANDLED;
2008 * ab8500_charger_usblinkstatus_handler() - USB link status has changed
2009 * @irq: interrupt number
2010 * @_di: pointer to the ab8500_charger structure
2012 * Returns IRQ status(IRQ_HANDLED)
2014 static irqreturn_t ab8500_charger_usblinkstatus_handler(int irq, void *_di)
2016 struct ab8500_charger *di = _di;
2018 dev_dbg(di->dev, "USB link status changed\n");
2020 queue_work(di->charger_wq, &di->usb_link_status_work);
2022 return IRQ_HANDLED;
2026 * ab8500_charger_usbchthprotr_handler() - Die temp is above usb charger
2027 * thermal protection threshold
2028 * @irq: interrupt number
2029 * @_di: pointer to the ab8500_charger structure
2031 * Returns IRQ status(IRQ_HANDLED)
2033 static irqreturn_t ab8500_charger_usbchthprotr_handler(int irq, void *_di)
2035 struct ab8500_charger *di = _di;
2037 dev_dbg(di->dev,
2038 "Die temp above USB charger thermal protection threshold\n");
2039 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work);
2041 return IRQ_HANDLED;
2045 * ab8500_charger_usbchthprotf_handler() - Die temp is below usb charger
2046 * thermal protection threshold
2047 * @irq: interrupt number
2048 * @_di: pointer to the ab8500_charger structure
2050 * Returns IRQ status(IRQ_HANDLED)
2052 static irqreturn_t ab8500_charger_usbchthprotf_handler(int irq, void *_di)
2054 struct ab8500_charger *di = _di;
2056 dev_dbg(di->dev,
2057 "Die temp ok for USB charger thermal protection threshold\n");
2058 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work);
2060 return IRQ_HANDLED;
2064 * ab8500_charger_usbchargernotokr_handler() - USB charger not ok detected
2065 * @irq: interrupt number
2066 * @_di: pointer to the ab8500_charger structure
2068 * Returns IRQ status(IRQ_HANDLED)
2070 static irqreturn_t ab8500_charger_usbchargernotokr_handler(int irq, void *_di)
2072 struct ab8500_charger *di = _di;
2074 dev_dbg(di->dev, "Not allowed USB charger detected\n");
2075 queue_delayed_work(di->charger_wq, &di->check_usbchgnotok_work, 0);
2077 return IRQ_HANDLED;
2081 * ab8500_charger_chwdexp_handler() - Charger watchdog expired
2082 * @irq: interrupt number
2083 * @_di: pointer to the ab8500_charger structure
2085 * Returns IRQ status(IRQ_HANDLED)
2087 static irqreturn_t ab8500_charger_chwdexp_handler(int irq, void *_di)
2089 struct ab8500_charger *di = _di;
2091 dev_dbg(di->dev, "Charger watchdog expired\n");
2094 * The charger that was online when the watchdog expired
2095 * needs to be restarted for charging to start again
2097 if (di->ac.charger_online) {
2098 di->ac.wd_expired = true;
2099 ab8500_power_supply_changed(di, &di->ac_chg.psy);
2101 if (di->usb.charger_online) {
2102 di->usb.wd_expired = true;
2103 ab8500_power_supply_changed(di, &di->usb_chg.psy);
2106 return IRQ_HANDLED;
2110 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected
2111 * @irq: interrupt number
2112 * @_di: pointer to the ab8500_charger structure
2114 * Returns IRQ status(IRQ_HANDLED)
2116 static irqreturn_t ab8500_charger_vbusovv_handler(int irq, void *_di)
2118 struct ab8500_charger *di = _di;
2120 dev_dbg(di->dev, "VBUS overvoltage detected\n");
2121 di->flags.vbus_ovv = true;
2122 ab8500_power_supply_changed(di, &di->usb_chg.psy);
2124 /* Schedule a new HW failure check */
2125 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0);
2127 return IRQ_HANDLED;
2131 * ab8500_charger_ac_get_property() - get the ac/mains properties
2132 * @psy: pointer to the power_supply structure
2133 * @psp: pointer to the power_supply_property structure
2134 * @val: pointer to the power_supply_propval union
2136 * This function gets called when an application tries to get the ac/mains
2137 * properties by reading the sysfs files.
2138 * AC/Mains properties are online, present and voltage.
2139 * online: ac/mains charging is in progress or not
2140 * present: presence of the ac/mains
2141 * voltage: AC/Mains voltage
2142 * Returns error code in case of failure else 0(on success)
2144 static int ab8500_charger_ac_get_property(struct power_supply *psy,
2145 enum power_supply_property psp,
2146 union power_supply_propval *val)
2148 struct ab8500_charger *di;
2150 di = to_ab8500_charger_ac_device_info(psy_to_ux500_charger(psy));
2152 switch (psp) {
2153 case POWER_SUPPLY_PROP_HEALTH:
2154 if (di->flags.mainextchnotok)
2155 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
2156 else if (di->ac.wd_expired || di->usb.wd_expired)
2157 val->intval = POWER_SUPPLY_HEALTH_DEAD;
2158 else if (di->flags.main_thermal_prot)
2159 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
2160 else
2161 val->intval = POWER_SUPPLY_HEALTH_GOOD;
2162 break;
2163 case POWER_SUPPLY_PROP_ONLINE:
2164 val->intval = di->ac.charger_online;
2165 break;
2166 case POWER_SUPPLY_PROP_PRESENT:
2167 val->intval = di->ac.charger_connected;
2168 break;
2169 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
2170 di->ac.charger_voltage = ab8500_charger_get_ac_voltage(di);
2171 val->intval = di->ac.charger_voltage * 1000;
2172 break;
2173 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
2175 * This property is used to indicate when CV mode is entered
2176 * for the AC charger
2178 di->ac.cv_active = ab8500_charger_ac_cv(di);
2179 val->intval = di->ac.cv_active;
2180 break;
2181 case POWER_SUPPLY_PROP_CURRENT_NOW:
2182 val->intval = ab8500_charger_get_ac_current(di) * 1000;
2183 break;
2184 default:
2185 return -EINVAL;
2187 return 0;
2191 * ab8500_charger_usb_get_property() - get the usb properties
2192 * @psy: pointer to the power_supply structure
2193 * @psp: pointer to the power_supply_property structure
2194 * @val: pointer to the power_supply_propval union
2196 * This function gets called when an application tries to get the usb
2197 * properties by reading the sysfs files.
2198 * USB properties are online, present and voltage.
2199 * online: usb charging is in progress or not
2200 * present: presence of the usb
2201 * voltage: vbus voltage
2202 * Returns error code in case of failure else 0(on success)
2204 static int ab8500_charger_usb_get_property(struct power_supply *psy,
2205 enum power_supply_property psp,
2206 union power_supply_propval *val)
2208 struct ab8500_charger *di;
2210 di = to_ab8500_charger_usb_device_info(psy_to_ux500_charger(psy));
2212 switch (psp) {
2213 case POWER_SUPPLY_PROP_HEALTH:
2214 if (di->flags.usbchargernotok)
2215 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
2216 else if (di->ac.wd_expired || di->usb.wd_expired)
2217 val->intval = POWER_SUPPLY_HEALTH_DEAD;
2218 else if (di->flags.usb_thermal_prot)
2219 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
2220 else if (di->flags.vbus_ovv)
2221 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
2222 else
2223 val->intval = POWER_SUPPLY_HEALTH_GOOD;
2224 break;
2225 case POWER_SUPPLY_PROP_ONLINE:
2226 val->intval = di->usb.charger_online;
2227 break;
2228 case POWER_SUPPLY_PROP_PRESENT:
2229 val->intval = di->usb.charger_connected;
2230 break;
2231 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
2232 di->usb.charger_voltage = ab8500_charger_get_vbus_voltage(di);
2233 val->intval = di->usb.charger_voltage * 1000;
2234 break;
2235 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
2237 * This property is used to indicate when CV mode is entered
2238 * for the USB charger
2240 di->usb.cv_active = ab8500_charger_usb_cv(di);
2241 val->intval = di->usb.cv_active;
2242 break;
2243 case POWER_SUPPLY_PROP_CURRENT_NOW:
2244 val->intval = ab8500_charger_get_usb_current(di) * 1000;
2245 break;
2246 case POWER_SUPPLY_PROP_CURRENT_AVG:
2248 * This property is used to indicate when VBUS has collapsed
2249 * due to too high output current from the USB charger
2251 if (di->flags.vbus_collapse)
2252 val->intval = 1;
2253 else
2254 val->intval = 0;
2255 break;
2256 default:
2257 return -EINVAL;
2259 return 0;
2263 * ab8500_charger_init_hw_registers() - Set up charger related registers
2264 * @di: pointer to the ab8500_charger structure
2266 * Set up charger OVV, watchdog and maximum voltage registers as well as
2267 * charging of the backup battery
2269 static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2271 int ret = 0;
2273 /* Setup maximum charger current and voltage for ABB cut2.0 */
2274 if (!is_ab8500_1p1_or_earlier(di->parent)) {
2275 ret = abx500_set_register_interruptible(di->dev,
2276 AB8500_CHARGER,
2277 AB8500_CH_VOLT_LVL_MAX_REG, CH_VOL_LVL_4P6);
2278 if (ret) {
2279 dev_err(di->dev,
2280 "failed to set CH_VOLT_LVL_MAX_REG\n");
2281 goto out;
2284 ret = abx500_set_register_interruptible(di->dev,
2285 AB8500_CHARGER,
2286 AB8500_CH_OPT_CRNTLVL_MAX_REG, CH_OP_CUR_LVL_1P6);
2287 if (ret) {
2288 dev_err(di->dev,
2289 "failed to set CH_OPT_CRNTLVL_MAX_REG\n");
2290 goto out;
2294 /* VBUS OVV set to 6.3V and enable automatic current limitiation */
2295 ret = abx500_set_register_interruptible(di->dev,
2296 AB8500_CHARGER,
2297 AB8500_USBCH_CTRL2_REG,
2298 VBUS_OVV_SELECT_6P3V | VBUS_AUTO_IN_CURR_LIM_ENA);
2299 if (ret) {
2300 dev_err(di->dev, "failed to set VBUS OVV\n");
2301 goto out;
2304 /* Enable main watchdog in OTP */
2305 ret = abx500_set_register_interruptible(di->dev,
2306 AB8500_OTP_EMUL, AB8500_OTP_CONF_15, OTP_ENABLE_WD);
2307 if (ret) {
2308 dev_err(di->dev, "failed to enable main WD in OTP\n");
2309 goto out;
2312 /* Enable main watchdog */
2313 ret = abx500_set_register_interruptible(di->dev,
2314 AB8500_SYS_CTRL2_BLOCK,
2315 AB8500_MAIN_WDOG_CTRL_REG, MAIN_WDOG_ENA);
2316 if (ret) {
2317 dev_err(di->dev, "faile to enable main watchdog\n");
2318 goto out;
2322 * Due to internal synchronisation, Enable and Kick watchdog bits
2323 * cannot be enabled in a single write.
2324 * A minimum delay of 2*32 kHz period (62.5µs) must be inserted
2325 * between writing Enable then Kick bits.
2327 udelay(63);
2329 /* Kick main watchdog */
2330 ret = abx500_set_register_interruptible(di->dev,
2331 AB8500_SYS_CTRL2_BLOCK,
2332 AB8500_MAIN_WDOG_CTRL_REG,
2333 (MAIN_WDOG_ENA | MAIN_WDOG_KICK));
2334 if (ret) {
2335 dev_err(di->dev, "failed to kick main watchdog\n");
2336 goto out;
2339 /* Disable main watchdog */
2340 ret = abx500_set_register_interruptible(di->dev,
2341 AB8500_SYS_CTRL2_BLOCK,
2342 AB8500_MAIN_WDOG_CTRL_REG, MAIN_WDOG_DIS);
2343 if (ret) {
2344 dev_err(di->dev, "failed to disable main watchdog\n");
2345 goto out;
2348 /* Set watchdog timeout */
2349 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
2350 AB8500_CH_WD_TIMER_REG, WD_TIMER);
2351 if (ret) {
2352 dev_err(di->dev, "failed to set charger watchdog timeout\n");
2353 goto out;
2356 /* Backup battery voltage and current */
2357 ret = abx500_set_register_interruptible(di->dev,
2358 AB8500_RTC,
2359 AB8500_RTC_BACKUP_CHG_REG,
2360 di->bat->bkup_bat_v |
2361 di->bat->bkup_bat_i);
2362 if (ret) {
2363 dev_err(di->dev, "failed to setup backup battery charging\n");
2364 goto out;
2367 /* Enable backup battery charging */
2368 abx500_mask_and_set_register_interruptible(di->dev,
2369 AB8500_RTC, AB8500_RTC_CTRL_REG,
2370 RTC_BUP_CH_ENA, RTC_BUP_CH_ENA);
2371 if (ret < 0)
2372 dev_err(di->dev, "%s mask and set failed\n", __func__);
2374 out:
2375 return ret;
2379 * ab8500 charger driver interrupts and their respective isr
2381 static struct ab8500_charger_interrupts ab8500_charger_irq[] = {
2382 {"MAIN_CH_UNPLUG_DET", ab8500_charger_mainchunplugdet_handler},
2383 {"MAIN_CHARGE_PLUG_DET", ab8500_charger_mainchplugdet_handler},
2384 {"MAIN_EXT_CH_NOT_OK", ab8500_charger_mainextchnotok_handler},
2385 {"MAIN_CH_TH_PROT_R", ab8500_charger_mainchthprotr_handler},
2386 {"MAIN_CH_TH_PROT_F", ab8500_charger_mainchthprotf_handler},
2387 {"VBUS_DET_F", ab8500_charger_vbusdetf_handler},
2388 {"VBUS_DET_R", ab8500_charger_vbusdetr_handler},
2389 {"USB_LINK_STATUS", ab8500_charger_usblinkstatus_handler},
2390 {"USB_CH_TH_PROT_R", ab8500_charger_usbchthprotr_handler},
2391 {"USB_CH_TH_PROT_F", ab8500_charger_usbchthprotf_handler},
2392 {"USB_CHARGER_NOT_OKR", ab8500_charger_usbchargernotokr_handler},
2393 {"VBUS_OVV", ab8500_charger_vbusovv_handler},
2394 {"CH_WD_EXP", ab8500_charger_chwdexp_handler},
2397 static int ab8500_charger_usb_notifier_call(struct notifier_block *nb,
2398 unsigned long event, void *power)
2400 struct ab8500_charger *di =
2401 container_of(nb, struct ab8500_charger, nb);
2402 enum ab8500_usb_state bm_usb_state;
2403 unsigned mA = *((unsigned *)power);
2405 if (event != USB_EVENT_VBUS) {
2406 dev_dbg(di->dev, "not a standard host, returning\n");
2407 return NOTIFY_DONE;
2410 /* TODO: State is fabricate here. See if charger really needs USB
2411 * state or if mA is enough
2413 if ((di->usb_state.usb_current == 2) && (mA > 2))
2414 bm_usb_state = AB8500_BM_USB_STATE_RESUME;
2415 else if (mA == 0)
2416 bm_usb_state = AB8500_BM_USB_STATE_RESET_HS;
2417 else if (mA == 2)
2418 bm_usb_state = AB8500_BM_USB_STATE_SUSPEND;
2419 else if (mA >= 8) /* 8, 100, 500 */
2420 bm_usb_state = AB8500_BM_USB_STATE_CONFIGURED;
2421 else /* Should never occur */
2422 bm_usb_state = AB8500_BM_USB_STATE_RESET_FS;
2424 dev_dbg(di->dev, "%s usb_state: 0x%02x mA: %d\n",
2425 __func__, bm_usb_state, mA);
2427 spin_lock(&di->usb_state.usb_lock);
2428 di->usb_state.usb_changed = true;
2429 spin_unlock(&di->usb_state.usb_lock);
2431 di->usb_state.state = bm_usb_state;
2432 di->usb_state.usb_current = mA;
2434 queue_work(di->charger_wq, &di->usb_state_changed_work);
2436 return NOTIFY_OK;
2439 #if defined(CONFIG_PM)
2440 static int ab8500_charger_resume(struct platform_device *pdev)
2442 int ret;
2443 struct ab8500_charger *di = platform_get_drvdata(pdev);
2446 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
2447 * logic. That means we have to continously kick the charger
2448 * watchdog even when no charger is connected. This is only
2449 * valid once the AC charger has been enabled. This is
2450 * a bug that is not handled by the algorithm and the
2451 * watchdog have to be kicked by the charger driver
2452 * when the AC charger is disabled
2454 if (di->ac_conn && is_ab8500_1p1_or_earlier(di->parent)) {
2455 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
2456 AB8500_CHARG_WD_CTRL, CHARG_WD_KICK);
2457 if (ret)
2458 dev_err(di->dev, "Failed to kick WD!\n");
2460 /* If not already pending start a new timer */
2461 if (!delayed_work_pending(
2462 &di->kick_wd_work)) {
2463 queue_delayed_work(di->charger_wq, &di->kick_wd_work,
2464 round_jiffies(WD_KICK_INTERVAL));
2468 /* If we still have a HW failure, schedule a new check */
2469 if (di->flags.mainextchnotok || di->flags.vbus_ovv) {
2470 queue_delayed_work(di->charger_wq,
2471 &di->check_hw_failure_work, 0);
2474 return 0;
2477 static int ab8500_charger_suspend(struct platform_device *pdev,
2478 pm_message_t state)
2480 struct ab8500_charger *di = platform_get_drvdata(pdev);
2482 /* Cancel any pending HW failure check */
2483 if (delayed_work_pending(&di->check_hw_failure_work))
2484 cancel_delayed_work(&di->check_hw_failure_work);
2486 return 0;
2488 #else
2489 #define ab8500_charger_suspend NULL
2490 #define ab8500_charger_resume NULL
2491 #endif
2493 static int __devexit ab8500_charger_remove(struct platform_device *pdev)
2495 struct ab8500_charger *di = platform_get_drvdata(pdev);
2496 int i, irq, ret;
2498 /* Disable AC charging */
2499 ab8500_charger_ac_en(&di->ac_chg, false, 0, 0);
2501 /* Disable USB charging */
2502 ab8500_charger_usb_en(&di->usb_chg, false, 0, 0);
2504 /* Disable interrupts */
2505 for (i = 0; i < ARRAY_SIZE(ab8500_charger_irq); i++) {
2506 irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name);
2507 free_irq(irq, di);
2510 /* disable the regulator */
2511 regulator_put(di->regu);
2513 /* Backup battery voltage and current disable */
2514 ret = abx500_mask_and_set_register_interruptible(di->dev,
2515 AB8500_RTC, AB8500_RTC_CTRL_REG, RTC_BUP_CH_ENA, 0);
2516 if (ret < 0)
2517 dev_err(di->dev, "%s mask and set failed\n", __func__);
2519 usb_unregister_notifier(di->usb_phy, &di->nb);
2520 usb_put_transceiver(di->usb_phy);
2522 /* Delete the work queue */
2523 destroy_workqueue(di->charger_wq);
2525 flush_scheduled_work();
2526 power_supply_unregister(&di->usb_chg.psy);
2527 power_supply_unregister(&di->ac_chg.psy);
2528 platform_set_drvdata(pdev, NULL);
2529 kfree(di);
2531 return 0;
2534 static int __devinit ab8500_charger_probe(struct platform_device *pdev)
2536 int irq, i, charger_status, ret = 0;
2537 struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data;
2538 struct ab8500_charger *di;
2540 if (!plat_data) {
2541 dev_err(&pdev->dev, "No platform data\n");
2542 return -EINVAL;
2545 di = kzalloc(sizeof(*di), GFP_KERNEL);
2546 if (!di)
2547 return -ENOMEM;
2549 /* get parent data */
2550 di->dev = &pdev->dev;
2551 di->parent = dev_get_drvdata(pdev->dev.parent);
2552 di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2554 /* initialize lock */
2555 spin_lock_init(&di->usb_state.usb_lock);
2557 /* get charger specific platform data */
2558 di->pdata = plat_data->charger;
2559 if (!di->pdata) {
2560 dev_err(di->dev, "no charger platform data supplied\n");
2561 ret = -EINVAL;
2562 goto free_device_info;
2565 /* get battery specific platform data */
2566 di->bat = plat_data->battery;
2567 if (!di->bat) {
2568 dev_err(di->dev, "no battery platform data supplied\n");
2569 ret = -EINVAL;
2570 goto free_device_info;
2573 di->autopower = false;
2575 /* AC supply */
2576 /* power_supply base class */
2577 di->ac_chg.psy.name = "ab8500_ac";
2578 di->ac_chg.psy.type = POWER_SUPPLY_TYPE_MAINS;
2579 di->ac_chg.psy.properties = ab8500_charger_ac_props;
2580 di->ac_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_ac_props);
2581 di->ac_chg.psy.get_property = ab8500_charger_ac_get_property;
2582 di->ac_chg.psy.supplied_to = di->pdata->supplied_to;
2583 di->ac_chg.psy.num_supplicants = di->pdata->num_supplicants;
2584 /* ux500_charger sub-class */
2585 di->ac_chg.ops.enable = &ab8500_charger_ac_en;
2586 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
2587 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current;
2588 di->ac_chg.max_out_volt = ab8500_charger_voltage_map[
2589 ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
2590 di->ac_chg.max_out_curr = ab8500_charger_current_map[
2591 ARRAY_SIZE(ab8500_charger_current_map) - 1];
2593 /* USB supply */
2594 /* power_supply base class */
2595 di->usb_chg.psy.name = "ab8500_usb";
2596 di->usb_chg.psy.type = POWER_SUPPLY_TYPE_USB;
2597 di->usb_chg.psy.properties = ab8500_charger_usb_props;
2598 di->usb_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_usb_props);
2599 di->usb_chg.psy.get_property = ab8500_charger_usb_get_property;
2600 di->usb_chg.psy.supplied_to = di->pdata->supplied_to;
2601 di->usb_chg.psy.num_supplicants = di->pdata->num_supplicants;
2602 /* ux500_charger sub-class */
2603 di->usb_chg.ops.enable = &ab8500_charger_usb_en;
2604 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
2605 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current;
2606 di->usb_chg.max_out_volt = ab8500_charger_voltage_map[
2607 ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
2608 di->usb_chg.max_out_curr = ab8500_charger_current_map[
2609 ARRAY_SIZE(ab8500_charger_current_map) - 1];
2612 /* Create a work queue for the charger */
2613 di->charger_wq =
2614 create_singlethread_workqueue("ab8500_charger_wq");
2615 if (di->charger_wq == NULL) {
2616 dev_err(di->dev, "failed to create work queue\n");
2617 goto free_device_info;
2620 /* Init work for HW failure check */
2621 INIT_DELAYED_WORK_DEFERRABLE(&di->check_hw_failure_work,
2622 ab8500_charger_check_hw_failure_work);
2623 INIT_DELAYED_WORK_DEFERRABLE(&di->check_usbchgnotok_work,
2624 ab8500_charger_check_usbchargernotok_work);
2627 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
2628 * logic. That means we have to continously kick the charger
2629 * watchdog even when no charger is connected. This is only
2630 * valid once the AC charger has been enabled. This is
2631 * a bug that is not handled by the algorithm and the
2632 * watchdog have to be kicked by the charger driver
2633 * when the AC charger is disabled
2635 INIT_DELAYED_WORK_DEFERRABLE(&di->kick_wd_work,
2636 ab8500_charger_kick_watchdog_work);
2638 INIT_DELAYED_WORK_DEFERRABLE(&di->check_vbat_work,
2639 ab8500_charger_check_vbat_work);
2641 /* Init work for charger detection */
2642 INIT_WORK(&di->usb_link_status_work,
2643 ab8500_charger_usb_link_status_work);
2644 INIT_WORK(&di->ac_work, ab8500_charger_ac_work);
2645 INIT_WORK(&di->detect_usb_type_work,
2646 ab8500_charger_detect_usb_type_work);
2648 INIT_WORK(&di->usb_state_changed_work,
2649 ab8500_charger_usb_state_changed_work);
2651 /* Init work for checking HW status */
2652 INIT_WORK(&di->check_main_thermal_prot_work,
2653 ab8500_charger_check_main_thermal_prot_work);
2654 INIT_WORK(&di->check_usb_thermal_prot_work,
2655 ab8500_charger_check_usb_thermal_prot_work);
2658 * VDD ADC supply needs to be enabled from this driver when there
2659 * is a charger connected to avoid erroneous BTEMP_HIGH/LOW
2660 * interrupts during charging
2662 di->regu = regulator_get(di->dev, "vddadc");
2663 if (IS_ERR(di->regu)) {
2664 ret = PTR_ERR(di->regu);
2665 dev_err(di->dev, "failed to get vddadc regulator\n");
2666 goto free_charger_wq;
2670 /* Initialize OVV, and other registers */
2671 ret = ab8500_charger_init_hw_registers(di);
2672 if (ret) {
2673 dev_err(di->dev, "failed to initialize ABB registers\n");
2674 goto free_regulator;
2677 /* Register AC charger class */
2678 ret = power_supply_register(di->dev, &di->ac_chg.psy);
2679 if (ret) {
2680 dev_err(di->dev, "failed to register AC charger\n");
2681 goto free_regulator;
2684 /* Register USB charger class */
2685 ret = power_supply_register(di->dev, &di->usb_chg.psy);
2686 if (ret) {
2687 dev_err(di->dev, "failed to register USB charger\n");
2688 goto free_ac;
2691 di->usb_phy = usb_get_transceiver();
2692 if (!di->usb_phy) {
2693 dev_err(di->dev, "failed to get usb transceiver\n");
2694 ret = -EINVAL;
2695 goto free_usb;
2697 di->nb.notifier_call = ab8500_charger_usb_notifier_call;
2698 ret = usb_register_notifier(di->usb_phy, &di->nb);
2699 if (ret) {
2700 dev_err(di->dev, "failed to register usb notifier\n");
2701 goto put_usb_phy;
2704 /* Identify the connected charger types during startup */
2705 charger_status = ab8500_charger_detect_chargers(di);
2706 if (charger_status & AC_PW_CONN) {
2707 di->ac.charger_connected = 1;
2708 di->ac_conn = true;
2709 ab8500_power_supply_changed(di, &di->ac_chg.psy);
2710 sysfs_notify(&di->ac_chg.psy.dev->kobj, NULL, "present");
2713 if (charger_status & USB_PW_CONN) {
2714 dev_dbg(di->dev, "VBUS Detect during startup\n");
2715 di->vbus_detected = true;
2716 di->vbus_detected_start = true;
2717 queue_work(di->charger_wq,
2718 &di->detect_usb_type_work);
2721 /* Register interrupts */
2722 for (i = 0; i < ARRAY_SIZE(ab8500_charger_irq); i++) {
2723 irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name);
2724 ret = request_threaded_irq(irq, NULL, ab8500_charger_irq[i].isr,
2725 IRQF_SHARED | IRQF_NO_SUSPEND,
2726 ab8500_charger_irq[i].name, di);
2728 if (ret != 0) {
2729 dev_err(di->dev, "failed to request %s IRQ %d: %d\n"
2730 , ab8500_charger_irq[i].name, irq, ret);
2731 goto free_irq;
2733 dev_dbg(di->dev, "Requested %s IRQ %d: %d\n",
2734 ab8500_charger_irq[i].name, irq, ret);
2737 platform_set_drvdata(pdev, di);
2739 return ret;
2741 free_irq:
2742 usb_unregister_notifier(di->usb_phy, &di->nb);
2744 /* We also have to free all successfully registered irqs */
2745 for (i = i - 1; i >= 0; i--) {
2746 irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name);
2747 free_irq(irq, di);
2749 put_usb_phy:
2750 usb_put_transceiver(di->usb_phy);
2751 free_usb:
2752 power_supply_unregister(&di->usb_chg.psy);
2753 free_ac:
2754 power_supply_unregister(&di->ac_chg.psy);
2755 free_regulator:
2756 regulator_put(di->regu);
2757 free_charger_wq:
2758 destroy_workqueue(di->charger_wq);
2759 free_device_info:
2760 kfree(di);
2762 return ret;
2765 static struct platform_driver ab8500_charger_driver = {
2766 .probe = ab8500_charger_probe,
2767 .remove = __devexit_p(ab8500_charger_remove),
2768 .suspend = ab8500_charger_suspend,
2769 .resume = ab8500_charger_resume,
2770 .driver = {
2771 .name = "ab8500-charger",
2772 .owner = THIS_MODULE,
2776 static int __init ab8500_charger_init(void)
2778 return platform_driver_register(&ab8500_charger_driver);
2781 static void __exit ab8500_charger_exit(void)
2783 platform_driver_unregister(&ab8500_charger_driver);
2786 subsys_initcall_sync(ab8500_charger_init);
2787 module_exit(ab8500_charger_exit);
2789 MODULE_LICENSE("GPL v2");
2790 MODULE_AUTHOR("Johan Palsson, Karl Komierowski, Arun R Murthy");
2791 MODULE_ALIAS("platform:ab8500-charger");
2792 MODULE_DESCRIPTION("AB8500 charger management driver");