1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2012
5 * Charger driver for AB8500
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/notifier.h>
19 #include <linux/slab.h>
20 #include <linux/platform_device.h>
21 #include <linux/power_supply.h>
22 #include <linux/completion.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/err.h>
25 #include <linux/workqueue.h>
26 #include <linux/kobject.h>
28 #include <linux/mfd/core.h>
29 #include <linux/mfd/abx500/ab8500.h>
30 #include <linux/mfd/abx500.h>
31 #include <linux/mfd/abx500/ab8500-bm.h>
32 #include <linux/mfd/abx500/ux500_chargalg.h>
33 #include <linux/usb/otg.h>
34 #include <linux/mutex.h>
35 #include <linux/iio/consumer.h>
37 /* Charger constants */
42 #define MAIN_WDOG_ENA 0x01
43 #define MAIN_WDOG_KICK 0x02
44 #define MAIN_WDOG_DIS 0x00
45 #define CHARG_WD_KICK 0x01
46 #define MAIN_CH_ENA 0x01
47 #define MAIN_CH_NO_OVERSHOOT_ENA_N 0x02
48 #define USB_CH_ENA 0x01
49 #define USB_CHG_NO_OVERSHOOT_ENA_N 0x02
50 #define MAIN_CH_DET 0x01
51 #define MAIN_CH_CV_ON 0x04
52 #define USB_CH_CV_ON 0x08
53 #define VBUS_DET_DBNC100 0x02
54 #define VBUS_DET_DBNC1 0x01
55 #define OTP_ENABLE_WD 0x01
56 #define DROP_COUNT_RESET 0x01
57 #define USB_CH_DET 0x01
59 #define MAIN_CH_INPUT_CURR_SHIFT 4
60 #define VBUS_IN_CURR_LIM_SHIFT 4
61 #define AUTO_VBUS_IN_CURR_LIM_SHIFT 4
62 #define VBUS_IN_CURR_LIM_RETRY_SET_TIME 30 /* seconds */
64 #define LED_INDICATOR_PWM_ENA 0x01
65 #define LED_INDICATOR_PWM_DIS 0x00
66 #define LED_IND_CUR_5MA 0x04
67 #define LED_INDICATOR_PWM_DUTY_252_256 0xBF
69 /* HW failure constants */
70 #define MAIN_CH_TH_PROT 0x02
71 #define VBUS_CH_NOK 0x08
72 #define USB_CH_TH_PROT 0x02
73 #define VBUS_OVV_TH 0x01
74 #define MAIN_CH_NOK 0x01
77 #define MAIN_CH_STATUS2_MAINCHGDROP 0x80
78 #define MAIN_CH_STATUS2_MAINCHARGERDETDBNC 0x40
79 #define USB_CH_VBUSDROP 0x40
80 #define USB_CH_VBUSDETDBNC 0x01
82 /* UsbLineStatus register bit masks */
83 #define AB8500_USB_LINK_STATUS 0x78
84 #define AB8505_USB_LINK_STATUS 0xF8
85 #define AB8500_STD_HOST_SUSP 0x18
86 #define USB_LINK_STATUS_SHIFT 3
88 /* Watchdog timeout constant */
89 #define WD_TIMER 0x30 /* 4min */
90 #define WD_KICK_INTERVAL (60 * HZ)
92 /* Lowest charger voltage is 3.39V -> 0x4E */
93 #define LOW_VOLT_REG 0x4E
95 /* Step up/down delay in us */
96 #define STEP_UDELAY 1000
98 #define CHARGER_STATUS_POLL 10 /* in ms */
100 #define CHG_WD_INTERVAL (60 * HZ)
102 #define AB8500_SW_CONTROL_FALLBACK 0x03
103 /* Wait for enumeration before charing in us */
104 #define WAIT_ACA_RID_ENUMERATION (5 * 1000)
105 /*External charger control*/
106 #define AB8500_SYS_CHARGER_CONTROL_REG 0x52
107 #define EXTERNAL_CHARGER_DISABLE_REG_VAL 0x03
108 #define EXTERNAL_CHARGER_ENABLE_REG_VAL 0x07
110 /* UsbLineStatus register - usb types */
111 enum ab8500_charger_link_status
{
112 USB_STAT_NOT_CONFIGURED
,
113 USB_STAT_STD_HOST_NC
,
114 USB_STAT_STD_HOST_C_NS
,
115 USB_STAT_STD_HOST_C_S
,
116 USB_STAT_HOST_CHG_NM
,
117 USB_STAT_HOST_CHG_HS
,
118 USB_STAT_HOST_CHG_HS_CHIRP
,
119 USB_STAT_DEDICATED_CHG
,
122 USB_STAT_ACA_RID_C_NM
,
123 USB_STAT_ACA_RID_C_HS
,
124 USB_STAT_ACA_RID_C_HS_CHIRP
,
127 USB_STAT_NOT_VALID_LINK
,
129 USB_STAT_SUP_NO_IDGND_VBUS
,
130 USB_STAT_SUP_IDGND_VBUS
,
131 USB_STAT_CHARGER_LINE_1
,
134 USB_STAT_ACA_DOCK_CHARGER
,
137 enum ab8500_usb_state
{
138 AB8500_BM_USB_STATE_RESET_HS
, /* HighSpeed Reset */
139 AB8500_BM_USB_STATE_RESET_FS
, /* FullSpeed/LowSpeed Reset */
140 AB8500_BM_USB_STATE_CONFIGURED
,
141 AB8500_BM_USB_STATE_SUSPEND
,
142 AB8500_BM_USB_STATE_RESUME
,
143 AB8500_BM_USB_STATE_MAX
,
146 /* VBUS input current limits supported in AB8500 in mA */
147 #define USB_CH_IP_CUR_LVL_0P05 50
148 #define USB_CH_IP_CUR_LVL_0P09 98
149 #define USB_CH_IP_CUR_LVL_0P19 193
150 #define USB_CH_IP_CUR_LVL_0P29 290
151 #define USB_CH_IP_CUR_LVL_0P38 380
152 #define USB_CH_IP_CUR_LVL_0P45 450
153 #define USB_CH_IP_CUR_LVL_0P5 500
154 #define USB_CH_IP_CUR_LVL_0P6 600
155 #define USB_CH_IP_CUR_LVL_0P7 700
156 #define USB_CH_IP_CUR_LVL_0P8 800
157 #define USB_CH_IP_CUR_LVL_0P9 900
158 #define USB_CH_IP_CUR_LVL_1P0 1000
159 #define USB_CH_IP_CUR_LVL_1P1 1100
160 #define USB_CH_IP_CUR_LVL_1P3 1300
161 #define USB_CH_IP_CUR_LVL_1P4 1400
162 #define USB_CH_IP_CUR_LVL_1P5 1500
164 #define VBAT_TRESH_IP_CUR_RED 3800
166 #define to_ab8500_charger_usb_device_info(x) container_of((x), \
167 struct ab8500_charger, usb_chg)
168 #define to_ab8500_charger_ac_device_info(x) container_of((x), \
169 struct ab8500_charger, ac_chg)
172 * struct ab8500_charger_interrupts - ab8500 interupts
173 * @name: name of the interrupt
174 * @isr function pointer to the isr
176 struct ab8500_charger_interrupts
{
178 irqreturn_t (*isr
)(int irq
, void *data
);
181 struct ab8500_charger_info
{
182 int charger_connected
;
190 struct ab8500_charger_event_flags
{
192 bool main_thermal_prot
;
193 bool usb_thermal_prot
;
195 bool usbchargernotok
;
201 struct ab8500_charger_usb_state
{
204 enum ab8500_usb_state state
;
205 enum ab8500_usb_state state_tmp
;
209 struct ab8500_charger_max_usb_in_curr
{
216 * struct ab8500_charger - ab8500 Charger device information
217 * @dev: Pointer to the structure device
218 * @vbus_detected: VBUS detected
219 * @vbus_detected_start:
220 * VBUS detected during startup
221 * @ac_conn: This will be true when the AC charger has been plugged
222 * @vddadc_en_ac: Indicate if VDD ADC supply is enabled because AC
224 * @vddadc_en_usb: Indicate if VDD ADC supply is enabled because USB
226 * @vbat Battery voltage
227 * @old_vbat Previously measured battery voltage
228 * @usb_device_is_unrecognised USB device is unrecognised by the hardware
229 * @autopower Indicate if we should have automatic pwron after pwrloss
230 * @autopower_cfg platform specific power config support for "pwron after pwrloss"
231 * @invalid_charger_detect_state State when forcing AB to use invalid charger
232 * @is_aca_rid: Incicate if accessory is ACA type
233 * @current_stepping_sessions:
234 * Counter for current stepping sessions
235 * @parent: Pointer to the struct ab8500
236 * @adc_main_charger_v ADC channel for main charger voltage
237 * @adc_main_charger_c ADC channel for main charger current
238 * @adc_vbus_v ADC channel for USB charger voltage
239 * @adc_usb_charger_c ADC channel for USB charger current
240 * @bm: Platform specific battery management information
241 * @flags: Structure for information about events triggered
242 * @usb_state: Structure for usb stack information
243 * @max_usb_in_curr: Max USB charger input current
244 * @ac_chg: AC charger power supply
245 * @usb_chg: USB charger power supply
246 * @ac: Structure that holds the AC charger properties
247 * @usb: Structure that holds the USB charger properties
248 * @regu: Pointer to the struct regulator
249 * @charger_wq: Work queue for the IRQs and checking HW state
250 * @usb_ipt_crnt_lock: Lock to protect VBUS input current setting from mutuals
251 * @pm_lock: Lock to prevent system to suspend
252 * @check_vbat_work Work for checking vbat threshold to adjust vbus current
253 * @check_hw_failure_work: Work for checking HW state
254 * @check_usbchgnotok_work: Work for checking USB charger not ok status
255 * @kick_wd_work: Work for kicking the charger watchdog in case
256 * of ABB rev 1.* due to the watchog logic bug
257 * @ac_charger_attached_work: Work for checking if AC charger is still
259 * @usb_charger_attached_work: Work for checking if USB charger is still
261 * @ac_work: Work for checking AC charger connection
262 * @detect_usb_type_work: Work for detecting the USB type connected
263 * @usb_link_status_work: Work for checking the new USB link status
264 * @usb_state_changed_work: Work for checking USB state
265 * @attach_work: Work for detecting USB type
266 * @vbus_drop_end_work: Work for detecting VBUS drop end
267 * @check_main_thermal_prot_work:
268 * Work for checking Main thermal status
269 * @check_usb_thermal_prot_work:
270 * Work for checking USB thermal status
271 * @charger_attached_mutex: For controlling the wakelock
273 struct ab8500_charger
{
276 bool vbus_detected_start
;
282 bool usb_device_is_unrecognised
;
285 int invalid_charger_detect_state
;
287 atomic_t current_stepping_sessions
;
288 struct ab8500
*parent
;
289 struct iio_channel
*adc_main_charger_v
;
290 struct iio_channel
*adc_main_charger_c
;
291 struct iio_channel
*adc_vbus_v
;
292 struct iio_channel
*adc_usb_charger_c
;
293 struct abx500_bm_data
*bm
;
294 struct ab8500_charger_event_flags flags
;
295 struct ab8500_charger_usb_state usb_state
;
296 struct ab8500_charger_max_usb_in_curr max_usb_in_curr
;
297 struct ux500_charger ac_chg
;
298 struct ux500_charger usb_chg
;
299 struct ab8500_charger_info ac
;
300 struct ab8500_charger_info usb
;
301 struct regulator
*regu
;
302 struct workqueue_struct
*charger_wq
;
303 struct mutex usb_ipt_crnt_lock
;
304 struct delayed_work check_vbat_work
;
305 struct delayed_work check_hw_failure_work
;
306 struct delayed_work check_usbchgnotok_work
;
307 struct delayed_work kick_wd_work
;
308 struct delayed_work usb_state_changed_work
;
309 struct delayed_work attach_work
;
310 struct delayed_work ac_charger_attached_work
;
311 struct delayed_work usb_charger_attached_work
;
312 struct delayed_work vbus_drop_end_work
;
313 struct work_struct ac_work
;
314 struct work_struct detect_usb_type_work
;
315 struct work_struct usb_link_status_work
;
316 struct work_struct check_main_thermal_prot_work
;
317 struct work_struct check_usb_thermal_prot_work
;
318 struct usb_phy
*usb_phy
;
319 struct notifier_block nb
;
320 struct mutex charger_attached_mutex
;
324 static enum power_supply_property ab8500_charger_ac_props
[] = {
325 POWER_SUPPLY_PROP_HEALTH
,
326 POWER_SUPPLY_PROP_PRESENT
,
327 POWER_SUPPLY_PROP_ONLINE
,
328 POWER_SUPPLY_PROP_VOLTAGE_NOW
,
329 POWER_SUPPLY_PROP_VOLTAGE_AVG
,
330 POWER_SUPPLY_PROP_CURRENT_NOW
,
334 static enum power_supply_property ab8500_charger_usb_props
[] = {
335 POWER_SUPPLY_PROP_HEALTH
,
336 POWER_SUPPLY_PROP_CURRENT_AVG
,
337 POWER_SUPPLY_PROP_PRESENT
,
338 POWER_SUPPLY_PROP_ONLINE
,
339 POWER_SUPPLY_PROP_VOLTAGE_NOW
,
340 POWER_SUPPLY_PROP_VOLTAGE_AVG
,
341 POWER_SUPPLY_PROP_CURRENT_NOW
,
345 * Function for enabling and disabling sw fallback mode
346 * should always be disabled when no charger is connected.
348 static void ab8500_enable_disable_sw_fallback(struct ab8500_charger
*di
,
357 dev_dbg(di
->dev
, "SW Fallback: %d\n", fallback
);
359 if (is_ab8500(di
->parent
)) {
364 bank
= AB8500_SYS_CTRL1_BLOCK
;
365 reg
= AB8500_SW_CONTROL_FALLBACK
;
369 /* read the register containing fallback bit */
370 ret
= abx500_get_register_interruptible(di
->dev
, bank
, reg
, &val
);
372 dev_err(di
->dev
, "%d read failed\n", __LINE__
);
376 if (is_ab8500(di
->parent
)) {
377 /* enable the OPT emulation registers */
378 ret
= abx500_set_register_interruptible(di
->dev
, 0x11, 0x00, 0x2);
380 dev_err(di
->dev
, "%d write failed\n", __LINE__
);
390 /* write back the changed fallback bit value to register */
391 ret
= abx500_set_register_interruptible(di
->dev
, bank
, reg
, val
);
393 dev_err(di
->dev
, "%d write failed\n", __LINE__
);
397 if (is_ab8500(di
->parent
)) {
398 /* disable the set OTP registers again */
399 ret
= abx500_set_register_interruptible(di
->dev
, 0x11, 0x00, 0x0);
401 dev_err(di
->dev
, "%d write failed\n", __LINE__
);
407 * ab8500_power_supply_changed - a wrapper with local extensions for
408 * power_supply_changed
409 * @di: pointer to the ab8500_charger structure
410 * @psy: pointer to power_supply_that have changed.
413 static void ab8500_power_supply_changed(struct ab8500_charger
*di
,
414 struct power_supply
*psy
)
416 if (di
->autopower_cfg
) {
417 if (!di
->usb
.charger_connected
&&
418 !di
->ac
.charger_connected
&&
420 di
->autopower
= false;
421 ab8500_enable_disable_sw_fallback(di
, false);
422 } else if (!di
->autopower
&&
423 (di
->ac
.charger_connected
||
424 di
->usb
.charger_connected
)) {
425 di
->autopower
= true;
426 ab8500_enable_disable_sw_fallback(di
, true);
429 power_supply_changed(psy
);
432 static void ab8500_charger_set_usb_connected(struct ab8500_charger
*di
,
435 if (connected
!= di
->usb
.charger_connected
) {
436 dev_dbg(di
->dev
, "USB connected:%i\n", connected
);
437 di
->usb
.charger_connected
= connected
;
440 di
->flags
.vbus_drop_end
= false;
442 sysfs_notify(&di
->usb_chg
.psy
->dev
.kobj
, NULL
, "present");
445 mutex_lock(&di
->charger_attached_mutex
);
446 mutex_unlock(&di
->charger_attached_mutex
);
448 if (is_ab8500(di
->parent
))
449 queue_delayed_work(di
->charger_wq
,
450 &di
->usb_charger_attached_work
,
453 cancel_delayed_work_sync(&di
->usb_charger_attached_work
);
454 mutex_lock(&di
->charger_attached_mutex
);
455 mutex_unlock(&di
->charger_attached_mutex
);
461 * ab8500_charger_get_ac_voltage() - get ac charger voltage
462 * @di: pointer to the ab8500_charger structure
464 * Returns ac charger voltage (on success)
466 static int ab8500_charger_get_ac_voltage(struct ab8500_charger
*di
)
470 /* Only measure voltage if the charger is connected */
471 if (di
->ac
.charger_connected
) {
472 ret
= iio_read_channel_processed(di
->adc_main_charger_v
, &vch
);
474 dev_err(di
->dev
, "%s ADC conv failed,\n", __func__
);
482 * ab8500_charger_ac_cv() - check if the main charger is in CV mode
483 * @di: pointer to the ab8500_charger structure
485 * Returns ac charger CV mode (on success) else error code
487 static int ab8500_charger_ac_cv(struct ab8500_charger
*di
)
492 /* Only check CV mode if the charger is online */
493 if (di
->ac
.charger_online
) {
494 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
495 AB8500_CH_STATUS1_REG
, &val
);
497 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
501 if (val
& MAIN_CH_CV_ON
)
511 * ab8500_charger_get_vbus_voltage() - get vbus voltage
512 * @di: pointer to the ab8500_charger structure
514 * This function returns the vbus voltage.
515 * Returns vbus voltage (on success)
517 static int ab8500_charger_get_vbus_voltage(struct ab8500_charger
*di
)
521 /* Only measure voltage if the charger is connected */
522 if (di
->usb
.charger_connected
) {
523 ret
= iio_read_channel_processed(di
->adc_vbus_v
, &vch
);
525 dev_err(di
->dev
, "%s ADC conv failed,\n", __func__
);
533 * ab8500_charger_get_usb_current() - get usb charger current
534 * @di: pointer to the ab8500_charger structure
536 * This function returns the usb charger current.
537 * Returns usb current (on success) and error code on failure
539 static int ab8500_charger_get_usb_current(struct ab8500_charger
*di
)
543 /* Only measure current if the charger is online */
544 if (di
->usb
.charger_online
) {
545 ret
= iio_read_channel_processed(di
->adc_usb_charger_c
, &ich
);
547 dev_err(di
->dev
, "%s ADC conv failed,\n", __func__
);
555 * ab8500_charger_get_ac_current() - get ac charger current
556 * @di: pointer to the ab8500_charger structure
558 * This function returns the ac charger current.
559 * Returns ac current (on success) and error code on failure.
561 static int ab8500_charger_get_ac_current(struct ab8500_charger
*di
)
565 /* Only measure current if the charger is online */
566 if (di
->ac
.charger_online
) {
567 ret
= iio_read_channel_processed(di
->adc_main_charger_c
, &ich
);
569 dev_err(di
->dev
, "%s ADC conv failed,\n", __func__
);
577 * ab8500_charger_usb_cv() - check if the usb charger is in CV mode
578 * @di: pointer to the ab8500_charger structure
580 * Returns ac charger CV mode (on success) else error code
582 static int ab8500_charger_usb_cv(struct ab8500_charger
*di
)
587 /* Only check CV mode if the charger is online */
588 if (di
->usb
.charger_online
) {
589 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
590 AB8500_CH_USBCH_STAT1_REG
, &val
);
592 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
596 if (val
& USB_CH_CV_ON
)
608 * ab8500_charger_detect_chargers() - Detect the connected chargers
609 * @di: pointer to the ab8500_charger structure
610 * @probe: if probe, don't delay and wait for HW
612 * Returns the type of charger connected.
613 * For USB it will not mean we can actually charge from it
614 * but that there is a USB cable connected that we have to
615 * identify. This is used during startup when we don't get
616 * interrupts of the charger detection
618 * Returns an integer value, that means,
619 * NO_PW_CONN no power supply is connected
620 * AC_PW_CONN if the AC power supply is connected
621 * USB_PW_CONN if the USB power supply is connected
622 * AC_PW_CONN + USB_PW_CONN if USB and AC power supplies are both connected
624 static int ab8500_charger_detect_chargers(struct ab8500_charger
*di
, bool probe
)
626 int result
= NO_PW_CONN
;
630 /* Check for AC charger */
631 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
632 AB8500_CH_STATUS1_REG
, &val
);
634 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
638 if (val
& MAIN_CH_DET
)
641 /* Check for USB charger */
645 * AB8500 says VBUS_DET_DBNC1 & VBUS_DET_DBNC100
646 * when disconnecting ACA even though no
647 * charger was connected. Try waiting a little
648 * longer than the 100 ms of VBUS_DET_DBNC100...
652 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
653 AB8500_CH_USBCH_STAT1_REG
, &val
);
655 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
659 "%s AB8500_CH_USBCH_STAT1_REG %x\n", __func__
,
661 if ((val
& VBUS_DET_DBNC1
) && (val
& VBUS_DET_DBNC100
))
662 result
|= USB_PW_CONN
;
668 * ab8500_charger_max_usb_curr() - get the max curr for the USB type
669 * @di: pointer to the ab8500_charger structure
670 * @link_status: the identified USB type
672 * Get the maximum current that is allowed to be drawn from the host
673 * based on the USB type.
674 * Returns error code in case of failure else 0 on success
676 static int ab8500_charger_max_usb_curr(struct ab8500_charger
*di
,
677 enum ab8500_charger_link_status link_status
)
681 di
->usb_device_is_unrecognised
= false;
684 * Platform only supports USB 2.0.
685 * This means that charging current from USB source
686 * is maximum 500 mA. Every occurrence of USB_STAT_*_HOST_*
687 * should set USB_CH_IP_CUR_LVL_0P5.
690 switch (link_status
) {
691 case USB_STAT_STD_HOST_NC
:
692 case USB_STAT_STD_HOST_C_NS
:
693 case USB_STAT_STD_HOST_C_S
:
694 dev_dbg(di
->dev
, "USB Type - Standard host is "
695 "detected through USB driver\n");
696 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
699 case USB_STAT_HOST_CHG_HS_CHIRP
:
700 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
703 case USB_STAT_HOST_CHG_HS
:
704 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
707 case USB_STAT_ACA_RID_C_HS
:
708 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P9
;
711 case USB_STAT_ACA_RID_A
:
713 * Dedicated charger level minus maximum current accessory
714 * can consume (900mA). Closest level is 500mA
716 dev_dbg(di
->dev
, "USB_STAT_ACA_RID_A detected\n");
717 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
720 case USB_STAT_ACA_RID_B
:
722 * Dedicated charger level minus 120mA (20mA for ACA and
723 * 100mA for potential accessory). Closest level is 1300mA
725 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_1P3
;
726 dev_dbg(di
->dev
, "USB Type - 0x%02x MaxCurr: %d", link_status
,
727 di
->max_usb_in_curr
.usb_type_max
);
730 case USB_STAT_HOST_CHG_NM
:
731 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
734 case USB_STAT_DEDICATED_CHG
:
735 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_1P5
;
738 case USB_STAT_ACA_RID_C_HS_CHIRP
:
739 case USB_STAT_ACA_RID_C_NM
:
740 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_1P5
;
743 case USB_STAT_NOT_CONFIGURED
:
744 if (di
->vbus_detected
) {
745 di
->usb_device_is_unrecognised
= true;
746 dev_dbg(di
->dev
, "USB Type - Legacy charger.\n");
747 di
->max_usb_in_curr
.usb_type_max
=
748 USB_CH_IP_CUR_LVL_1P5
;
752 case USB_STAT_HM_IDGND
:
753 dev_err(di
->dev
, "USB Type - Charging not allowed\n");
754 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P05
;
757 case USB_STAT_RESERVED
:
758 if (is_ab8500(di
->parent
)) {
759 di
->flags
.vbus_collapse
= true;
760 dev_err(di
->dev
, "USB Type - USB_STAT_RESERVED "
761 "VBUS has collapsed\n");
765 dev_dbg(di
->dev
, "USB Type - Charging not allowed\n");
766 di
->max_usb_in_curr
.usb_type_max
=
767 USB_CH_IP_CUR_LVL_0P05
;
768 dev_dbg(di
->dev
, "USB Type - 0x%02x MaxCurr: %d",
770 di
->max_usb_in_curr
.usb_type_max
);
774 case USB_STAT_CARKIT_1
:
775 case USB_STAT_CARKIT_2
:
776 case USB_STAT_ACA_DOCK_CHARGER
:
777 case USB_STAT_CHARGER_LINE_1
:
778 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
779 dev_dbg(di
->dev
, "USB Type - 0x%02x MaxCurr: %d", link_status
,
780 di
->max_usb_in_curr
.usb_type_max
);
782 case USB_STAT_NOT_VALID_LINK
:
783 dev_err(di
->dev
, "USB Type invalid - try charging anyway\n");
784 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
788 dev_err(di
->dev
, "USB Type - Unknown\n");
789 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P05
;
794 di
->max_usb_in_curr
.set_max
= di
->max_usb_in_curr
.usb_type_max
;
795 dev_dbg(di
->dev
, "USB Type - 0x%02x MaxCurr: %d",
796 link_status
, di
->max_usb_in_curr
.set_max
);
802 * ab8500_charger_read_usb_type() - read the type of usb connected
803 * @di: pointer to the ab8500_charger structure
805 * Detect the type of the plugged USB
806 * Returns error code in case of failure else 0 on success
808 static int ab8500_charger_read_usb_type(struct ab8500_charger
*di
)
813 ret
= abx500_get_register_interruptible(di
->dev
,
814 AB8500_INTERRUPT
, AB8500_IT_SOURCE21_REG
, &val
);
816 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
819 if (is_ab8500(di
->parent
))
820 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_USB
,
821 AB8500_USB_LINE_STAT_REG
, &val
);
823 ret
= abx500_get_register_interruptible(di
->dev
,
824 AB8500_USB
, AB8500_USB_LINK1_STAT_REG
, &val
);
826 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
830 /* get the USB type */
831 if (is_ab8500(di
->parent
))
832 val
= (val
& AB8500_USB_LINK_STATUS
) >> USB_LINK_STATUS_SHIFT
;
834 val
= (val
& AB8505_USB_LINK_STATUS
) >> USB_LINK_STATUS_SHIFT
;
835 ret
= ab8500_charger_max_usb_curr(di
,
836 (enum ab8500_charger_link_status
) val
);
842 * ab8500_charger_detect_usb_type() - get the type of usb connected
843 * @di: pointer to the ab8500_charger structure
845 * Detect the type of the plugged USB
846 * Returns error code in case of failure else 0 on success
848 static int ab8500_charger_detect_usb_type(struct ab8500_charger
*di
)
854 * On getting the VBUS rising edge detect interrupt there
855 * is a 250ms delay after which the register UsbLineStatus
856 * is filled with valid data.
858 for (i
= 0; i
< 10; i
++) {
860 ret
= abx500_get_register_interruptible(di
->dev
,
861 AB8500_INTERRUPT
, AB8500_IT_SOURCE21_REG
,
863 dev_dbg(di
->dev
, "%s AB8500_IT_SOURCE21_REG %x\n",
866 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
870 if (is_ab8500(di
->parent
))
871 ret
= abx500_get_register_interruptible(di
->dev
,
872 AB8500_USB
, AB8500_USB_LINE_STAT_REG
, &val
);
874 ret
= abx500_get_register_interruptible(di
->dev
,
875 AB8500_USB
, AB8500_USB_LINK1_STAT_REG
, &val
);
877 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
880 dev_dbg(di
->dev
, "%s AB8500_USB_LINE_STAT_REG %x\n", __func__
,
883 * Until the IT source register is read the UsbLineStatus
884 * register is not updated, hence doing the same
888 /* get the USB type */
889 if (is_ab8500(di
->parent
))
890 val
= (val
& AB8500_USB_LINK_STATUS
) >>
891 USB_LINK_STATUS_SHIFT
;
893 val
= (val
& AB8505_USB_LINK_STATUS
) >>
894 USB_LINK_STATUS_SHIFT
;
898 ret
= ab8500_charger_max_usb_curr(di
,
899 (enum ab8500_charger_link_status
) val
);
905 * This array maps the raw hex value to charger voltage used by the AB8500
906 * Values taken from the UM0836
908 static int ab8500_charger_voltage_map
[] = {
989 static int ab8500_voltage_to_regval(int voltage
)
993 /* Special case for voltage below 3.5V */
994 if (voltage
< ab8500_charger_voltage_map
[0])
997 for (i
= 1; i
< ARRAY_SIZE(ab8500_charger_voltage_map
); i
++) {
998 if (voltage
< ab8500_charger_voltage_map
[i
])
1002 /* If not last element, return error */
1003 i
= ARRAY_SIZE(ab8500_charger_voltage_map
) - 1;
1004 if (voltage
== ab8500_charger_voltage_map
[i
])
1010 static int ab8500_current_to_regval(struct ab8500_charger
*di
, int curr
)
1014 if (curr
< di
->bm
->chg_output_curr
[0])
1017 for (i
= 0; i
< di
->bm
->n_chg_out_curr
; i
++) {
1018 if (curr
< di
->bm
->chg_output_curr
[i
])
1022 /* If not last element, return error */
1023 i
= di
->bm
->n_chg_out_curr
- 1;
1024 if (curr
== di
->bm
->chg_output_curr
[i
])
1030 static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger
*di
, int curr
)
1034 if (curr
< di
->bm
->chg_input_curr
[0])
1037 for (i
= 0; i
< di
->bm
->n_chg_in_curr
; i
++) {
1038 if (curr
< di
->bm
->chg_input_curr
[i
])
1042 /* If not last element, return error */
1043 i
= di
->bm
->n_chg_in_curr
- 1;
1044 if (curr
== di
->bm
->chg_input_curr
[i
])
1051 * ab8500_charger_get_usb_cur() - get usb current
1052 * @di: pointer to the ab8500_charger structre
1054 * The usb stack provides the maximum current that can be drawn from
1055 * the standard usb host. This will be in mA.
1056 * This function converts current in mA to a value that can be written
1057 * to the register. Returns -1 if charging is not allowed
1059 static int ab8500_charger_get_usb_cur(struct ab8500_charger
*di
)
1062 switch (di
->usb_state
.usb_current
) {
1064 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P09
;
1067 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P19
;
1070 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P29
;
1073 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P38
;
1076 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P5
;
1079 di
->max_usb_in_curr
.usb_type_max
= USB_CH_IP_CUR_LVL_0P05
;
1083 di
->max_usb_in_curr
.set_max
= di
->max_usb_in_curr
.usb_type_max
;
1088 * ab8500_charger_check_continue_stepping() - Check to allow stepping
1089 * @di: pointer to the ab8500_charger structure
1090 * @reg: select what charger register to check
1092 * Check if current stepping should be allowed to continue.
1093 * Checks if charger source has not collapsed. If it has, further stepping
1096 static bool ab8500_charger_check_continue_stepping(struct ab8500_charger
*di
,
1099 if (reg
== AB8500_USBCH_IPT_CRNTLVL_REG
)
1100 return !di
->flags
.vbus_drop_end
;
1106 * ab8500_charger_set_current() - set charger current
1107 * @di: pointer to the ab8500_charger structure
1108 * @ich: charger current, in mA
1109 * @reg: select what charger register to set
1111 * Set charger current.
1112 * There is no state machine in the AB to step up/down the charger
1113 * current to avoid dips and spikes on MAIN, VBUS and VBAT when
1114 * charging is started. Instead we need to implement
1115 * this charger current step-up/down here.
1116 * Returns error code in case of failure else 0(on success)
1118 static int ab8500_charger_set_current(struct ab8500_charger
*di
,
1122 int curr_index
, prev_curr_index
, shift_value
, i
;
1125 bool no_stepping
= false;
1127 atomic_inc(&di
->current_stepping_sessions
);
1129 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
1132 dev_err(di
->dev
, "%s read failed\n", __func__
);
1133 goto exit_set_current
;
1137 case AB8500_MCH_IPT_CURLVL_REG
:
1138 shift_value
= MAIN_CH_INPUT_CURR_SHIFT
;
1139 prev_curr_index
= (reg_value
>> shift_value
);
1140 curr_index
= ab8500_current_to_regval(di
, ich
);
1141 step_udelay
= STEP_UDELAY
;
1142 if (!di
->ac
.charger_connected
)
1145 case AB8500_USBCH_IPT_CRNTLVL_REG
:
1146 shift_value
= VBUS_IN_CURR_LIM_SHIFT
;
1147 prev_curr_index
= (reg_value
>> shift_value
);
1148 curr_index
= ab8500_vbus_in_curr_to_regval(di
, ich
);
1149 step_udelay
= STEP_UDELAY
* 100;
1151 if (!di
->usb
.charger_connected
)
1154 case AB8500_CH_OPT_CRNTLVL_REG
:
1156 prev_curr_index
= (reg_value
>> shift_value
);
1157 curr_index
= ab8500_current_to_regval(di
, ich
);
1158 step_udelay
= STEP_UDELAY
;
1159 if (curr_index
&& (curr_index
- prev_curr_index
) > 1)
1162 if (!di
->usb
.charger_connected
&& !di
->ac
.charger_connected
)
1167 dev_err(di
->dev
, "%s current register not valid\n", __func__
);
1169 goto exit_set_current
;
1172 if (curr_index
< 0) {
1173 dev_err(di
->dev
, "requested current limit out-of-range\n");
1175 goto exit_set_current
;
1178 /* only update current if it's been changed */
1179 if (prev_curr_index
== curr_index
) {
1180 dev_dbg(di
->dev
, "%s current not changed for reg: 0x%02x\n",
1183 goto exit_set_current
;
1186 dev_dbg(di
->dev
, "%s set charger current: %d mA for reg: 0x%02x\n",
1187 __func__
, ich
, reg
);
1190 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1191 reg
, (u8
)curr_index
<< shift_value
);
1193 dev_err(di
->dev
, "%s write failed\n", __func__
);
1194 } else if (prev_curr_index
> curr_index
) {
1195 for (i
= prev_curr_index
- 1; i
>= curr_index
; i
--) {
1196 dev_dbg(di
->dev
, "curr change_1 to: %x for 0x%02x\n",
1197 (u8
) i
<< shift_value
, reg
);
1198 ret
= abx500_set_register_interruptible(di
->dev
,
1199 AB8500_CHARGER
, reg
, (u8
)i
<< shift_value
);
1201 dev_err(di
->dev
, "%s write failed\n", __func__
);
1202 goto exit_set_current
;
1204 if (i
!= curr_index
)
1205 usleep_range(step_udelay
, step_udelay
* 2);
1209 for (i
= prev_curr_index
+ 1; i
<= curr_index
&& allow
; i
++) {
1210 dev_dbg(di
->dev
, "curr change_2 to: %x for 0x%02x\n",
1211 (u8
)i
<< shift_value
, reg
);
1212 ret
= abx500_set_register_interruptible(di
->dev
,
1213 AB8500_CHARGER
, reg
, (u8
)i
<< shift_value
);
1215 dev_err(di
->dev
, "%s write failed\n", __func__
);
1216 goto exit_set_current
;
1218 if (i
!= curr_index
)
1219 usleep_range(step_udelay
, step_udelay
* 2);
1221 allow
= ab8500_charger_check_continue_stepping(di
, reg
);
1226 atomic_dec(&di
->current_stepping_sessions
);
1232 * ab8500_charger_set_vbus_in_curr() - set VBUS input current limit
1233 * @di: pointer to the ab8500_charger structure
1234 * @ich_in: charger input current limit
1236 * Sets the current that can be drawn from the USB host
1237 * Returns error code in case of failure else 0(on success)
1239 static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger
*di
,
1245 /* We should always use to lowest current limit */
1246 min_value
= min(di
->bm
->chg_params
->usb_curr_max
, ich_in
);
1247 if (di
->max_usb_in_curr
.set_max
> 0)
1248 min_value
= min(di
->max_usb_in_curr
.set_max
, min_value
);
1250 if (di
->usb_state
.usb_current
>= 0)
1251 min_value
= min(di
->usb_state
.usb_current
, min_value
);
1253 switch (min_value
) {
1255 if (di
->vbat
< VBAT_TRESH_IP_CUR_RED
)
1256 min_value
= USB_CH_IP_CUR_LVL_0P05
;
1259 if (di
->vbat
< VBAT_TRESH_IP_CUR_RED
)
1260 min_value
= USB_CH_IP_CUR_LVL_0P45
;
1266 dev_info(di
->dev
, "VBUS input current limit set to %d mA\n", min_value
);
1268 mutex_lock(&di
->usb_ipt_crnt_lock
);
1269 ret
= ab8500_charger_set_current(di
, min_value
,
1270 AB8500_USBCH_IPT_CRNTLVL_REG
);
1271 mutex_unlock(&di
->usb_ipt_crnt_lock
);
1277 * ab8500_charger_set_main_in_curr() - set main charger input current
1278 * @di: pointer to the ab8500_charger structure
1279 * @ich_in: input charger current, in mA
1281 * Set main charger input current.
1282 * Returns error code in case of failure else 0(on success)
1284 static int ab8500_charger_set_main_in_curr(struct ab8500_charger
*di
,
1287 return ab8500_charger_set_current(di
, ich_in
,
1288 AB8500_MCH_IPT_CURLVL_REG
);
1292 * ab8500_charger_set_output_curr() - set charger output current
1293 * @di: pointer to the ab8500_charger structure
1294 * @ich_out: output charger current, in mA
1296 * Set charger output current.
1297 * Returns error code in case of failure else 0(on success)
1299 static int ab8500_charger_set_output_curr(struct ab8500_charger
*di
,
1302 return ab8500_charger_set_current(di
, ich_out
,
1303 AB8500_CH_OPT_CRNTLVL_REG
);
1307 * ab8500_charger_led_en() - turn on/off chargign led
1308 * @di: pointer to the ab8500_charger structure
1309 * @on: flag to turn on/off the chargign led
1311 * Power ON/OFF charging LED indication
1312 * Returns error code in case of failure else 0(on success)
1314 static int ab8500_charger_led_en(struct ab8500_charger
*di
, int on
)
1319 /* Power ON charging LED indicator, set LED current to 5mA */
1320 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1321 AB8500_LED_INDICATOR_PWM_CTRL
,
1322 (LED_IND_CUR_5MA
| LED_INDICATOR_PWM_ENA
));
1324 dev_err(di
->dev
, "Power ON LED failed\n");
1327 /* LED indicator PWM duty cycle 252/256 */
1328 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1329 AB8500_LED_INDICATOR_PWM_DUTY
,
1330 LED_INDICATOR_PWM_DUTY_252_256
);
1332 dev_err(di
->dev
, "Set LED PWM duty cycle failed\n");
1336 /* Power off charging LED indicator */
1337 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1338 AB8500_LED_INDICATOR_PWM_CTRL
,
1339 LED_INDICATOR_PWM_DIS
);
1341 dev_err(di
->dev
, "Power-off LED failed\n");
1350 * ab8500_charger_ac_en() - enable or disable ac charging
1351 * @di: pointer to the ab8500_charger structure
1352 * @enable: enable/disable flag
1353 * @vset: charging voltage
1354 * @iset: charging current
1356 * Enable/Disable AC/Mains charging and turns on/off the charging led
1359 static int ab8500_charger_ac_en(struct ux500_charger
*charger
,
1360 int enable
, int vset
, int iset
)
1365 int input_curr_index
;
1368 struct ab8500_charger
*di
= to_ab8500_charger_ac_device_info(charger
);
1371 /* Check if AC is connected */
1372 if (!di
->ac
.charger_connected
) {
1373 dev_err(di
->dev
, "AC charger not connected\n");
1377 /* Enable AC charging */
1378 dev_dbg(di
->dev
, "Enable AC: %dmV %dmA\n", vset
, iset
);
1381 * Due to a bug in AB8500, BTEMP_HIGH/LOW interrupts
1382 * will be triggered every time we enable the VDD ADC supply.
1383 * This will turn off charging for a short while.
1384 * It can be avoided by having the supply on when
1385 * there is a charger enabled. Normally the VDD ADC supply
1386 * is enabled every time a GPADC conversion is triggered.
1387 * We will force it to be enabled from this driver to have
1388 * the GPADC module independent of the AB8500 chargers
1390 if (!di
->vddadc_en_ac
) {
1391 ret
= regulator_enable(di
->regu
);
1394 "Failed to enable regulator\n");
1396 di
->vddadc_en_ac
= true;
1399 /* Check if the requested voltage or current is valid */
1400 volt_index
= ab8500_voltage_to_regval(vset
);
1401 curr_index
= ab8500_current_to_regval(di
, iset
);
1402 input_curr_index
= ab8500_current_to_regval(di
,
1403 di
->bm
->chg_params
->ac_curr_max
);
1404 if (volt_index
< 0 || curr_index
< 0 || input_curr_index
< 0) {
1406 "Charger voltage or current too high, "
1407 "charging not started\n");
1411 /* ChVoltLevel: maximum battery charging voltage */
1412 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1413 AB8500_CH_VOLT_LVL_REG
, (u8
) volt_index
);
1415 dev_err(di
->dev
, "%s write failed\n", __func__
);
1418 /* MainChInputCurr: current that can be drawn from the charger*/
1419 ret
= ab8500_charger_set_main_in_curr(di
,
1420 di
->bm
->chg_params
->ac_curr_max
);
1422 dev_err(di
->dev
, "%s Failed to set MainChInputCurr\n",
1426 /* ChOutputCurentLevel: protected output current */
1427 ret
= ab8500_charger_set_output_curr(di
, iset
);
1429 dev_err(di
->dev
, "%s "
1430 "Failed to set ChOutputCurentLevel\n",
1435 /* Check if VBAT overshoot control should be enabled */
1436 if (!di
->bm
->enable_overshoot
)
1437 overshoot
= MAIN_CH_NO_OVERSHOOT_ENA_N
;
1439 /* Enable Main Charger */
1440 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1441 AB8500_MCH_CTRL1
, MAIN_CH_ENA
| overshoot
);
1443 dev_err(di
->dev
, "%s write failed\n", __func__
);
1447 /* Power on charging LED indication */
1448 ret
= ab8500_charger_led_en(di
, true);
1450 dev_err(di
->dev
, "failed to enable LED\n");
1452 di
->ac
.charger_online
= 1;
1454 /* Disable AC charging */
1455 if (is_ab8500_1p1_or_earlier(di
->parent
)) {
1457 * For ABB revision 1.0 and 1.1 there is a bug in the
1458 * watchdog logic. That means we have to continuously
1459 * kick the charger watchdog even when no charger is
1460 * connected. This is only valid once the AC charger
1461 * has been enabled. This is a bug that is not handled
1462 * by the algorithm and the watchdog have to be kicked
1463 * by the charger driver when the AC charger
1467 queue_delayed_work(di
->charger_wq
,
1469 round_jiffies(WD_KICK_INTERVAL
));
1473 * We can't turn off charging completely
1474 * due to a bug in AB8500 cut1.
1475 * If we do, charging will not start again.
1476 * That is why we set the lowest voltage
1477 * and current possible
1479 ret
= abx500_set_register_interruptible(di
->dev
,
1481 AB8500_CH_VOLT_LVL_REG
, CH_VOL_LVL_3P5
);
1484 "%s write failed\n", __func__
);
1488 ret
= ab8500_charger_set_output_curr(di
, 0);
1490 dev_err(di
->dev
, "%s "
1491 "Failed to set ChOutputCurentLevel\n",
1496 ret
= abx500_set_register_interruptible(di
->dev
,
1498 AB8500_MCH_CTRL1
, 0);
1501 "%s write failed\n", __func__
);
1506 ret
= ab8500_charger_led_en(di
, false);
1508 dev_err(di
->dev
, "failed to disable LED\n");
1510 di
->ac
.charger_online
= 0;
1511 di
->ac
.wd_expired
= false;
1513 /* Disable regulator if enabled */
1514 if (di
->vddadc_en_ac
) {
1515 regulator_disable(di
->regu
);
1516 di
->vddadc_en_ac
= false;
1519 dev_dbg(di
->dev
, "%s Disabled AC charging\n", __func__
);
1521 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
1527 * ab8500_charger_usb_en() - enable usb charging
1528 * @di: pointer to the ab8500_charger structure
1529 * @enable: enable/disable flag
1530 * @vset: charging voltage
1531 * @ich_out: charger output current
1533 * Enable/Disable USB charging and turns on/off the charging led respectively.
1534 * Returns error code in case of failure else 0(on success)
1536 static int ab8500_charger_usb_en(struct ux500_charger
*charger
,
1537 int enable
, int vset
, int ich_out
)
1544 struct ab8500_charger
*di
= to_ab8500_charger_usb_device_info(charger
);
1547 /* Check if USB is connected */
1548 if (!di
->usb
.charger_connected
) {
1549 dev_err(di
->dev
, "USB charger not connected\n");
1554 * Due to a bug in AB8500, BTEMP_HIGH/LOW interrupts
1555 * will be triggered every time we enable the VDD ADC supply.
1556 * This will turn off charging for a short while.
1557 * It can be avoided by having the supply on when
1558 * there is a charger enabled. Normally the VDD ADC supply
1559 * is enabled every time a GPADC conversion is triggered.
1560 * We will force it to be enabled from this driver to have
1561 * the GPADC module independent of the AB8500 chargers
1563 if (!di
->vddadc_en_usb
) {
1564 ret
= regulator_enable(di
->regu
);
1567 "Failed to enable regulator\n");
1569 di
->vddadc_en_usb
= true;
1572 /* Enable USB charging */
1573 dev_dbg(di
->dev
, "Enable USB: %dmV %dmA\n", vset
, ich_out
);
1575 /* Check if the requested voltage or current is valid */
1576 volt_index
= ab8500_voltage_to_regval(vset
);
1577 curr_index
= ab8500_current_to_regval(di
, ich_out
);
1578 if (volt_index
< 0 || curr_index
< 0) {
1580 "Charger voltage or current too high, "
1581 "charging not started\n");
1586 * ChVoltLevel: max voltage up to which battery can be
1589 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1590 AB8500_CH_VOLT_LVL_REG
, (u8
) volt_index
);
1592 dev_err(di
->dev
, "%s write failed\n", __func__
);
1595 /* Check if VBAT overshoot control should be enabled */
1596 if (!di
->bm
->enable_overshoot
)
1597 overshoot
= USB_CHG_NO_OVERSHOOT_ENA_N
;
1599 /* Enable USB Charger */
1601 "Enabling USB with write to AB8500_USBCH_CTRL1_REG\n");
1602 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1603 AB8500_USBCH_CTRL1_REG
, USB_CH_ENA
| overshoot
);
1605 dev_err(di
->dev
, "%s write failed\n", __func__
);
1609 /* If success power on charging LED indication */
1610 ret
= ab8500_charger_led_en(di
, true);
1612 dev_err(di
->dev
, "failed to enable LED\n");
1614 di
->usb
.charger_online
= 1;
1616 /* USBChInputCurr: current that can be drawn from the usb */
1617 ret
= ab8500_charger_set_vbus_in_curr(di
,
1618 di
->max_usb_in_curr
.usb_type_max
);
1620 dev_err(di
->dev
, "setting USBChInputCurr failed\n");
1624 /* ChOutputCurentLevel: protected output current */
1625 ret
= ab8500_charger_set_output_curr(di
, ich_out
);
1627 dev_err(di
->dev
, "%s "
1628 "Failed to set ChOutputCurentLevel\n",
1633 queue_delayed_work(di
->charger_wq
, &di
->check_vbat_work
, HZ
);
1636 /* Disable USB charging */
1637 dev_dbg(di
->dev
, "%s Disabled USB charging\n", __func__
);
1638 ret
= abx500_set_register_interruptible(di
->dev
,
1640 AB8500_USBCH_CTRL1_REG
, 0);
1643 "%s write failed\n", __func__
);
1647 ret
= ab8500_charger_led_en(di
, false);
1649 dev_err(di
->dev
, "failed to disable LED\n");
1650 /* USBChInputCurr: current that can be drawn from the usb */
1651 ret
= ab8500_charger_set_vbus_in_curr(di
, 0);
1653 dev_err(di
->dev
, "setting USBChInputCurr failed\n");
1657 /* ChOutputCurentLevel: protected output current */
1658 ret
= ab8500_charger_set_output_curr(di
, 0);
1660 dev_err(di
->dev
, "%s "
1661 "Failed to reset ChOutputCurentLevel\n",
1665 di
->usb
.charger_online
= 0;
1666 di
->usb
.wd_expired
= false;
1668 /* Disable regulator if enabled */
1669 if (di
->vddadc_en_usb
) {
1670 regulator_disable(di
->regu
);
1671 di
->vddadc_en_usb
= false;
1674 dev_dbg(di
->dev
, "%s Disabled USB charging\n", __func__
);
1676 /* Cancel any pending Vbat check work */
1677 cancel_delayed_work(&di
->check_vbat_work
);
1680 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
1685 static int ab8500_external_charger_prepare(struct notifier_block
*charger_nb
,
1686 unsigned long event
, void *data
)
1689 struct device
*dev
= data
;
1690 /*Toggle External charger control pin*/
1691 ret
= abx500_set_register_interruptible(dev
, AB8500_SYS_CTRL1_BLOCK
,
1692 AB8500_SYS_CHARGER_CONTROL_REG
,
1693 EXTERNAL_CHARGER_DISABLE_REG_VAL
);
1695 dev_err(dev
, "write reg failed %d\n", ret
);
1698 ret
= abx500_set_register_interruptible(dev
, AB8500_SYS_CTRL1_BLOCK
,
1699 AB8500_SYS_CHARGER_CONTROL_REG
,
1700 EXTERNAL_CHARGER_ENABLE_REG_VAL
);
1702 dev_err(dev
, "Write reg failed %d\n", ret
);
1709 * ab8500_charger_usb_check_enable() - enable usb charging
1710 * @charger: pointer to the ux500_charger structure
1711 * @vset: charging voltage
1712 * @iset: charger output current
1714 * Check if the VBUS charger has been disconnected and reconnected without
1715 * AB8500 rising an interrupt. Returns 0 on success.
1717 static int ab8500_charger_usb_check_enable(struct ux500_charger
*charger
,
1723 struct ab8500_charger
*di
= to_ab8500_charger_usb_device_info(charger
);
1725 if (!di
->usb
.charger_connected
)
1728 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
1729 AB8500_USBCH_CTRL1_REG
, &usbch_ctrl1
);
1731 dev_err(di
->dev
, "ab8500 read failed %d\n", __LINE__
);
1734 dev_dbg(di
->dev
, "USB charger ctrl: 0x%02x\n", usbch_ctrl1
);
1736 if (!(usbch_ctrl1
& USB_CH_ENA
)) {
1737 dev_info(di
->dev
, "Charging has been disabled abnormally and will be re-enabled\n");
1739 ret
= abx500_mask_and_set_register_interruptible(di
->dev
,
1740 AB8500_CHARGER
, AB8500_CHARGER_CTRL
,
1741 DROP_COUNT_RESET
, DROP_COUNT_RESET
);
1743 dev_err(di
->dev
, "ab8500 write failed %d\n", __LINE__
);
1747 ret
= ab8500_charger_usb_en(&di
->usb_chg
, true, vset
, iset
);
1749 dev_err(di
->dev
, "Failed to enable VBUS charger %d\n",
1758 * ab8500_charger_ac_check_enable() - enable usb charging
1759 * @charger: pointer to the ux500_charger structure
1760 * @vset: charging voltage
1761 * @iset: charger output current
1763 * Check if the AC charger has been disconnected and reconnected without
1764 * AB8500 rising an interrupt. Returns 0 on success.
1766 static int ab8500_charger_ac_check_enable(struct ux500_charger
*charger
,
1769 u8 mainch_ctrl1
= 0;
1772 struct ab8500_charger
*di
= to_ab8500_charger_ac_device_info(charger
);
1774 if (!di
->ac
.charger_connected
)
1777 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
1778 AB8500_MCH_CTRL1
, &mainch_ctrl1
);
1780 dev_err(di
->dev
, "ab8500 read failed %d\n", __LINE__
);
1783 dev_dbg(di
->dev
, "AC charger ctrl: 0x%02x\n", mainch_ctrl1
);
1785 if (!(mainch_ctrl1
& MAIN_CH_ENA
)) {
1786 dev_info(di
->dev
, "Charging has been disabled abnormally and will be re-enabled\n");
1788 ret
= abx500_mask_and_set_register_interruptible(di
->dev
,
1789 AB8500_CHARGER
, AB8500_CHARGER_CTRL
,
1790 DROP_COUNT_RESET
, DROP_COUNT_RESET
);
1793 dev_err(di
->dev
, "ab8500 write failed %d\n", __LINE__
);
1797 ret
= ab8500_charger_ac_en(&di
->usb_chg
, true, vset
, iset
);
1799 dev_err(di
->dev
, "failed to enable AC charger %d\n",
1808 * ab8500_charger_watchdog_kick() - kick charger watchdog
1809 * @di: pointer to the ab8500_charger structure
1811 * Kick charger watchdog
1812 * Returns error code in case of failure else 0(on success)
1814 static int ab8500_charger_watchdog_kick(struct ux500_charger
*charger
)
1817 struct ab8500_charger
*di
;
1819 if (charger
->psy
->desc
->type
== POWER_SUPPLY_TYPE_MAINS
)
1820 di
= to_ab8500_charger_ac_device_info(charger
);
1821 else if (charger
->psy
->desc
->type
== POWER_SUPPLY_TYPE_USB
)
1822 di
= to_ab8500_charger_usb_device_info(charger
);
1826 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1827 AB8500_CHARG_WD_CTRL
, CHARG_WD_KICK
);
1829 dev_err(di
->dev
, "Failed to kick WD!\n");
1835 * ab8500_charger_update_charger_current() - update charger current
1836 * @di: pointer to the ab8500_charger structure
1838 * Update the charger output current for the specified charger
1839 * Returns error code in case of failure else 0(on success)
1841 static int ab8500_charger_update_charger_current(struct ux500_charger
*charger
,
1845 struct ab8500_charger
*di
;
1847 if (charger
->psy
->desc
->type
== POWER_SUPPLY_TYPE_MAINS
)
1848 di
= to_ab8500_charger_ac_device_info(charger
);
1849 else if (charger
->psy
->desc
->type
== POWER_SUPPLY_TYPE_USB
)
1850 di
= to_ab8500_charger_usb_device_info(charger
);
1854 ret
= ab8500_charger_set_output_curr(di
, ich_out
);
1856 dev_err(di
->dev
, "%s "
1857 "Failed to set ChOutputCurentLevel\n",
1862 /* Reset the main and usb drop input current measurement counter */
1863 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
1864 AB8500_CHARGER_CTRL
, DROP_COUNT_RESET
);
1866 dev_err(di
->dev
, "%s write failed\n", __func__
);
1873 static int ab8500_charger_get_ext_psy_data(struct device
*dev
, void *data
)
1875 struct power_supply
*psy
;
1876 struct power_supply
*ext
= dev_get_drvdata(dev
);
1877 const char **supplicants
= (const char **)ext
->supplied_to
;
1878 struct ab8500_charger
*di
;
1879 union power_supply_propval ret
;
1881 struct ux500_charger
*usb_chg
;
1883 usb_chg
= (struct ux500_charger
*)data
;
1886 di
= to_ab8500_charger_usb_device_info(usb_chg
);
1888 /* For all psy where the driver name appears in any supplied_to */
1889 j
= match_string(supplicants
, ext
->num_supplicants
, psy
->desc
->name
);
1893 /* Go through all properties for the psy */
1894 for (j
= 0; j
< ext
->desc
->num_properties
; j
++) {
1895 enum power_supply_property prop
;
1896 prop
= ext
->desc
->properties
[j
];
1898 if (power_supply_get_property(ext
, prop
, &ret
))
1902 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
1903 switch (ext
->desc
->type
) {
1904 case POWER_SUPPLY_TYPE_BATTERY
:
1905 di
->vbat
= ret
.intval
/ 1000;
1919 * ab8500_charger_check_vbat_work() - keep vbus current within spec
1920 * @work pointer to the work_struct structure
1922 * Due to a asic bug it is necessary to lower the input current to the vbus
1923 * charger when charging with at some specific levels. This issue is only valid
1924 * for below a certain battery voltage. This function makes sure that the
1925 * the allowed current limit isn't exceeded.
1927 static void ab8500_charger_check_vbat_work(struct work_struct
*work
)
1930 struct ab8500_charger
*di
= container_of(work
,
1931 struct ab8500_charger
, check_vbat_work
.work
);
1933 class_for_each_device(power_supply_class
, NULL
,
1934 di
->usb_chg
.psy
, ab8500_charger_get_ext_psy_data
);
1936 /* First run old_vbat is 0. */
1937 if (di
->old_vbat
== 0)
1938 di
->old_vbat
= di
->vbat
;
1940 if (!((di
->old_vbat
<= VBAT_TRESH_IP_CUR_RED
&&
1941 di
->vbat
<= VBAT_TRESH_IP_CUR_RED
) ||
1942 (di
->old_vbat
> VBAT_TRESH_IP_CUR_RED
&&
1943 di
->vbat
> VBAT_TRESH_IP_CUR_RED
))) {
1945 dev_dbg(di
->dev
, "Vbat did cross threshold, curr: %d, new: %d,"
1946 " old: %d\n", di
->max_usb_in_curr
.usb_type_max
,
1947 di
->vbat
, di
->old_vbat
);
1948 ab8500_charger_set_vbus_in_curr(di
,
1949 di
->max_usb_in_curr
.usb_type_max
);
1950 power_supply_changed(di
->usb_chg
.psy
);
1953 di
->old_vbat
= di
->vbat
;
1956 * No need to check the battery voltage every second when not close to
1959 if (di
->vbat
< (VBAT_TRESH_IP_CUR_RED
+ 100) &&
1960 (di
->vbat
> (VBAT_TRESH_IP_CUR_RED
- 100)))
1963 queue_delayed_work(di
->charger_wq
, &di
->check_vbat_work
, t
* HZ
);
1967 * ab8500_charger_check_hw_failure_work() - check main charger failure
1968 * @work: pointer to the work_struct structure
1970 * Work queue function for checking the main charger status
1972 static void ab8500_charger_check_hw_failure_work(struct work_struct
*work
)
1977 struct ab8500_charger
*di
= container_of(work
,
1978 struct ab8500_charger
, check_hw_failure_work
.work
);
1980 /* Check if the status bits for HW failure is still active */
1981 if (di
->flags
.mainextchnotok
) {
1982 ret
= abx500_get_register_interruptible(di
->dev
,
1983 AB8500_CHARGER
, AB8500_CH_STATUS2_REG
, ®_value
);
1985 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
1988 if (!(reg_value
& MAIN_CH_NOK
)) {
1989 di
->flags
.mainextchnotok
= false;
1990 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
1993 if (di
->flags
.vbus_ovv
) {
1994 ret
= abx500_get_register_interruptible(di
->dev
,
1995 AB8500_CHARGER
, AB8500_CH_USBCH_STAT2_REG
,
1998 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
2001 if (!(reg_value
& VBUS_OVV_TH
)) {
2002 di
->flags
.vbus_ovv
= false;
2003 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2006 /* If we still have a failure, schedule a new check */
2007 if (di
->flags
.mainextchnotok
|| di
->flags
.vbus_ovv
) {
2008 queue_delayed_work(di
->charger_wq
,
2009 &di
->check_hw_failure_work
, round_jiffies(HZ
));
2014 * ab8500_charger_kick_watchdog_work() - kick the watchdog
2015 * @work: pointer to the work_struct structure
2017 * Work queue function for kicking the charger watchdog.
2019 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
2020 * logic. That means we have to continuously kick the charger
2021 * watchdog even when no charger is connected. This is only
2022 * valid once the AC charger has been enabled. This is
2023 * a bug that is not handled by the algorithm and the
2024 * watchdog have to be kicked by the charger driver
2025 * when the AC charger is disabled
2027 static void ab8500_charger_kick_watchdog_work(struct work_struct
*work
)
2031 struct ab8500_charger
*di
= container_of(work
,
2032 struct ab8500_charger
, kick_wd_work
.work
);
2034 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
2035 AB8500_CHARG_WD_CTRL
, CHARG_WD_KICK
);
2037 dev_err(di
->dev
, "Failed to kick WD!\n");
2039 /* Schedule a new watchdog kick */
2040 queue_delayed_work(di
->charger_wq
,
2041 &di
->kick_wd_work
, round_jiffies(WD_KICK_INTERVAL
));
2045 * ab8500_charger_ac_work() - work to get and set main charger status
2046 * @work: pointer to the work_struct structure
2048 * Work queue function for checking the main charger status
2050 static void ab8500_charger_ac_work(struct work_struct
*work
)
2054 struct ab8500_charger
*di
= container_of(work
,
2055 struct ab8500_charger
, ac_work
);
2058 * Since we can't be sure that the events are received
2059 * synchronously, we have the check if the main charger is
2060 * connected by reading the status register
2062 ret
= ab8500_charger_detect_chargers(di
, false);
2066 if (ret
& AC_PW_CONN
) {
2067 di
->ac
.charger_connected
= 1;
2070 di
->ac
.charger_connected
= 0;
2073 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
2074 sysfs_notify(&di
->ac_chg
.psy
->dev
.kobj
, NULL
, "present");
2077 static void ab8500_charger_usb_attached_work(struct work_struct
*work
)
2079 struct ab8500_charger
*di
= container_of(work
,
2080 struct ab8500_charger
,
2081 usb_charger_attached_work
.work
);
2082 int usbch
= (USB_CH_VBUSDROP
| USB_CH_VBUSDETDBNC
);
2086 for (i
= 0; i
< 10; i
++) {
2087 ret
= abx500_get_register_interruptible(di
->dev
,
2089 AB8500_CH_USBCH_STAT1_REG
,
2092 dev_err(di
->dev
, "ab8500 read failed %d\n", __LINE__
);
2095 if ((statval
& usbch
) != usbch
)
2098 msleep(CHARGER_STATUS_POLL
);
2101 ab8500_charger_usb_en(&di
->usb_chg
, 0, 0, 0);
2103 mutex_lock(&di
->charger_attached_mutex
);
2104 mutex_unlock(&di
->charger_attached_mutex
);
2109 queue_delayed_work(di
->charger_wq
,
2110 &di
->usb_charger_attached_work
,
2114 static void ab8500_charger_ac_attached_work(struct work_struct
*work
)
2117 struct ab8500_charger
*di
= container_of(work
,
2118 struct ab8500_charger
,
2119 ac_charger_attached_work
.work
);
2120 int mainch
= (MAIN_CH_STATUS2_MAINCHGDROP
|
2121 MAIN_CH_STATUS2_MAINCHARGERDETDBNC
);
2125 for (i
= 0; i
< 10; i
++) {
2126 ret
= abx500_get_register_interruptible(di
->dev
,
2128 AB8500_CH_STATUS2_REG
,
2131 dev_err(di
->dev
, "ab8500 read failed %d\n", __LINE__
);
2135 if ((statval
& mainch
) != mainch
)
2138 msleep(CHARGER_STATUS_POLL
);
2141 ab8500_charger_ac_en(&di
->ac_chg
, 0, 0, 0);
2142 queue_work(di
->charger_wq
, &di
->ac_work
);
2144 mutex_lock(&di
->charger_attached_mutex
);
2145 mutex_unlock(&di
->charger_attached_mutex
);
2150 queue_delayed_work(di
->charger_wq
,
2151 &di
->ac_charger_attached_work
,
2156 * ab8500_charger_detect_usb_type_work() - work to detect USB type
2157 * @work: Pointer to the work_struct structure
2159 * Detect the type of USB plugged
2161 static void ab8500_charger_detect_usb_type_work(struct work_struct
*work
)
2165 struct ab8500_charger
*di
= container_of(work
,
2166 struct ab8500_charger
, detect_usb_type_work
);
2169 * Since we can't be sure that the events are received
2170 * synchronously, we have the check if is
2171 * connected by reading the status register
2173 ret
= ab8500_charger_detect_chargers(di
, false);
2177 if (!(ret
& USB_PW_CONN
)) {
2178 dev_dbg(di
->dev
, "%s di->vbus_detected = false\n", __func__
);
2179 di
->vbus_detected
= false;
2180 ab8500_charger_set_usb_connected(di
, false);
2181 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2183 dev_dbg(di
->dev
, "%s di->vbus_detected = true\n", __func__
);
2184 di
->vbus_detected
= true;
2186 if (is_ab8500_1p1_or_earlier(di
->parent
)) {
2187 ret
= ab8500_charger_detect_usb_type(di
);
2189 ab8500_charger_set_usb_connected(di
, true);
2190 ab8500_power_supply_changed(di
,
2195 * For ABB cut2.0 and onwards we have an IRQ,
2196 * USB_LINK_STATUS that will be triggered when the USB
2197 * link status changes. The exception is USB connected
2198 * during startup. Then we don't get a
2199 * USB_LINK_STATUS IRQ
2201 if (di
->vbus_detected_start
) {
2202 di
->vbus_detected_start
= false;
2203 ret
= ab8500_charger_detect_usb_type(di
);
2205 ab8500_charger_set_usb_connected(di
,
2207 ab8500_power_supply_changed(di
,
2216 * ab8500_charger_usb_link_attach_work() - work to detect USB type
2217 * @work: pointer to the work_struct structure
2219 * Detect the type of USB plugged
2221 static void ab8500_charger_usb_link_attach_work(struct work_struct
*work
)
2223 struct ab8500_charger
*di
=
2224 container_of(work
, struct ab8500_charger
, attach_work
.work
);
2227 /* Update maximum input current if USB enumeration is not detected */
2228 if (!di
->usb
.charger_online
) {
2229 ret
= ab8500_charger_set_vbus_in_curr(di
,
2230 di
->max_usb_in_curr
.usb_type_max
);
2235 ab8500_charger_set_usb_connected(di
, true);
2236 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2240 * ab8500_charger_usb_link_status_work() - work to detect USB type
2241 * @work: pointer to the work_struct structure
2243 * Detect the type of USB plugged
2245 static void ab8500_charger_usb_link_status_work(struct work_struct
*work
)
2247 int detected_chargers
;
2252 struct ab8500_charger
*di
= container_of(work
,
2253 struct ab8500_charger
, usb_link_status_work
);
2256 * Since we can't be sure that the events are received
2257 * synchronously, we have the check if is
2258 * connected by reading the status register
2260 detected_chargers
= ab8500_charger_detect_chargers(di
, false);
2261 if (detected_chargers
< 0)
2265 * Some chargers that breaks the USB spec is
2266 * identified as invalid by AB8500 and it refuse
2267 * to start the charging process. but by jumping
2268 * through a few hoops it can be forced to start.
2270 if (is_ab8500(di
->parent
))
2271 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_USB
,
2272 AB8500_USB_LINE_STAT_REG
, &val
);
2274 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_USB
,
2275 AB8500_USB_LINK1_STAT_REG
, &val
);
2278 dev_dbg(di
->dev
, "UsbLineStatus register = 0x%02x\n", val
);
2280 dev_dbg(di
->dev
, "Error reading USB link status\n");
2282 if (is_ab8500(di
->parent
))
2283 link_status
= AB8500_USB_LINK_STATUS
;
2285 link_status
= AB8505_USB_LINK_STATUS
;
2287 if (detected_chargers
& USB_PW_CONN
) {
2288 if (((val
& link_status
) >> USB_LINK_STATUS_SHIFT
) ==
2289 USB_STAT_NOT_VALID_LINK
&&
2290 di
->invalid_charger_detect_state
== 0) {
2292 "Invalid charger detected, state= 0\n");
2294 abx500_mask_and_set_register_interruptible(di
->dev
,
2295 AB8500_CHARGER
, AB8500_USBCH_CTRL1_REG
,
2296 USB_CH_ENA
, USB_CH_ENA
);
2297 /*Enable charger detection*/
2298 abx500_mask_and_set_register_interruptible(di
->dev
,
2299 AB8500_USB
, AB8500_USB_LINE_CTRL2_REG
,
2300 USB_CH_DET
, USB_CH_DET
);
2301 di
->invalid_charger_detect_state
= 1;
2302 /*exit and wait for new link status interrupt.*/
2306 if (di
->invalid_charger_detect_state
== 1) {
2308 "Invalid charger detected, state= 1\n");
2309 /*Stop charger detection*/
2310 abx500_mask_and_set_register_interruptible(di
->dev
,
2311 AB8500_USB
, AB8500_USB_LINE_CTRL2_REG
,
2313 /*Check link status*/
2314 if (is_ab8500(di
->parent
))
2315 ret
= abx500_get_register_interruptible(di
->dev
,
2316 AB8500_USB
, AB8500_USB_LINE_STAT_REG
,
2319 ret
= abx500_get_register_interruptible(di
->dev
,
2320 AB8500_USB
, AB8500_USB_LINK1_STAT_REG
,
2323 dev_dbg(di
->dev
, "USB link status= 0x%02x\n",
2324 (val
& link_status
) >> USB_LINK_STATUS_SHIFT
);
2325 di
->invalid_charger_detect_state
= 2;
2328 di
->invalid_charger_detect_state
= 0;
2331 if (!(detected_chargers
& USB_PW_CONN
)) {
2332 di
->vbus_detected
= false;
2333 ab8500_charger_set_usb_connected(di
, false);
2334 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2338 dev_dbg(di
->dev
,"%s di->vbus_detected = true\n",__func__
);
2339 di
->vbus_detected
= true;
2340 ret
= ab8500_charger_read_usb_type(di
);
2342 if (ret
== -ENXIO
) {
2343 /* No valid charger type detected */
2344 ab8500_charger_set_usb_connected(di
, false);
2345 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2350 if (di
->usb_device_is_unrecognised
) {
2352 "Potential Legacy Charger device. "
2353 "Delay work for %d msec for USB enum "
2355 WAIT_ACA_RID_ENUMERATION
);
2356 queue_delayed_work(di
->charger_wq
,
2358 msecs_to_jiffies(WAIT_ACA_RID_ENUMERATION
));
2359 } else if (di
->is_aca_rid
== 1) {
2360 /* Only wait once */
2363 "%s Wait %d msec for USB enum to finish",
2364 __func__
, WAIT_ACA_RID_ENUMERATION
);
2365 queue_delayed_work(di
->charger_wq
,
2367 msecs_to_jiffies(WAIT_ACA_RID_ENUMERATION
));
2369 queue_delayed_work(di
->charger_wq
,
2375 static void ab8500_charger_usb_state_changed_work(struct work_struct
*work
)
2378 unsigned long flags
;
2380 struct ab8500_charger
*di
= container_of(work
,
2381 struct ab8500_charger
, usb_state_changed_work
.work
);
2383 if (!di
->vbus_detected
) {
2385 "%s !di->vbus_detected\n",
2390 spin_lock_irqsave(&di
->usb_state
.usb_lock
, flags
);
2391 di
->usb_state
.state
= di
->usb_state
.state_tmp
;
2392 di
->usb_state
.usb_current
= di
->usb_state
.usb_current_tmp
;
2393 spin_unlock_irqrestore(&di
->usb_state
.usb_lock
, flags
);
2395 dev_dbg(di
->dev
, "%s USB state: 0x%02x mA: %d\n",
2396 __func__
, di
->usb_state
.state
, di
->usb_state
.usb_current
);
2398 switch (di
->usb_state
.state
) {
2399 case AB8500_BM_USB_STATE_RESET_HS
:
2400 case AB8500_BM_USB_STATE_RESET_FS
:
2401 case AB8500_BM_USB_STATE_SUSPEND
:
2402 case AB8500_BM_USB_STATE_MAX
:
2403 ab8500_charger_set_usb_connected(di
, false);
2404 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2407 case AB8500_BM_USB_STATE_RESUME
:
2409 * when suspend->resume there should be delay
2410 * of 1sec for enabling charging
2414 case AB8500_BM_USB_STATE_CONFIGURED
:
2416 * USB is configured, enable charging with the charging
2417 * input current obtained from USB driver
2419 if (!ab8500_charger_get_usb_cur(di
)) {
2420 /* Update maximum input current */
2421 ret
= ab8500_charger_set_vbus_in_curr(di
,
2422 di
->max_usb_in_curr
.usb_type_max
);
2426 ab8500_charger_set_usb_connected(di
, true);
2427 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2437 * ab8500_charger_check_usbchargernotok_work() - check USB chg not ok status
2438 * @work: pointer to the work_struct structure
2440 * Work queue function for checking the USB charger Not OK status
2442 static void ab8500_charger_check_usbchargernotok_work(struct work_struct
*work
)
2448 struct ab8500_charger
*di
= container_of(work
,
2449 struct ab8500_charger
, check_usbchgnotok_work
.work
);
2451 /* Check if the status bit for usbchargernotok is still active */
2452 ret
= abx500_get_register_interruptible(di
->dev
,
2453 AB8500_CHARGER
, AB8500_CH_USBCH_STAT2_REG
, ®_value
);
2455 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
2458 prev_status
= di
->flags
.usbchargernotok
;
2460 if (reg_value
& VBUS_CH_NOK
) {
2461 di
->flags
.usbchargernotok
= true;
2462 /* Check again in 1sec */
2463 queue_delayed_work(di
->charger_wq
,
2464 &di
->check_usbchgnotok_work
, HZ
);
2466 di
->flags
.usbchargernotok
= false;
2467 di
->flags
.vbus_collapse
= false;
2470 if (prev_status
!= di
->flags
.usbchargernotok
)
2471 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2475 * ab8500_charger_check_main_thermal_prot_work() - check main thermal status
2476 * @work: pointer to the work_struct structure
2478 * Work queue function for checking the Main thermal prot status
2480 static void ab8500_charger_check_main_thermal_prot_work(
2481 struct work_struct
*work
)
2486 struct ab8500_charger
*di
= container_of(work
,
2487 struct ab8500_charger
, check_main_thermal_prot_work
);
2489 /* Check if the status bit for main_thermal_prot is still active */
2490 ret
= abx500_get_register_interruptible(di
->dev
,
2491 AB8500_CHARGER
, AB8500_CH_STATUS2_REG
, ®_value
);
2493 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
2496 if (reg_value
& MAIN_CH_TH_PROT
)
2497 di
->flags
.main_thermal_prot
= true;
2499 di
->flags
.main_thermal_prot
= false;
2501 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
2505 * ab8500_charger_check_usb_thermal_prot_work() - check usb thermal status
2506 * @work: pointer to the work_struct structure
2508 * Work queue function for checking the USB thermal prot status
2510 static void ab8500_charger_check_usb_thermal_prot_work(
2511 struct work_struct
*work
)
2516 struct ab8500_charger
*di
= container_of(work
,
2517 struct ab8500_charger
, check_usb_thermal_prot_work
);
2519 /* Check if the status bit for usb_thermal_prot is still active */
2520 ret
= abx500_get_register_interruptible(di
->dev
,
2521 AB8500_CHARGER
, AB8500_CH_USBCH_STAT2_REG
, ®_value
);
2523 dev_err(di
->dev
, "%s ab8500 read failed\n", __func__
);
2526 if (reg_value
& USB_CH_TH_PROT
)
2527 di
->flags
.usb_thermal_prot
= true;
2529 di
->flags
.usb_thermal_prot
= false;
2531 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2535 * ab8500_charger_mainchunplugdet_handler() - main charger unplugged
2536 * @irq: interrupt number
2537 * @_di: pointer to the ab8500_charger structure
2539 * Returns IRQ status(IRQ_HANDLED)
2541 static irqreturn_t
ab8500_charger_mainchunplugdet_handler(int irq
, void *_di
)
2543 struct ab8500_charger
*di
= _di
;
2545 dev_dbg(di
->dev
, "Main charger unplugged\n");
2546 queue_work(di
->charger_wq
, &di
->ac_work
);
2548 cancel_delayed_work_sync(&di
->ac_charger_attached_work
);
2549 mutex_lock(&di
->charger_attached_mutex
);
2550 mutex_unlock(&di
->charger_attached_mutex
);
2556 * ab8500_charger_mainchplugdet_handler() - main charger plugged
2557 * @irq: interrupt number
2558 * @_di: pointer to the ab8500_charger structure
2560 * Returns IRQ status(IRQ_HANDLED)
2562 static irqreturn_t
ab8500_charger_mainchplugdet_handler(int irq
, void *_di
)
2564 struct ab8500_charger
*di
= _di
;
2566 dev_dbg(di
->dev
, "Main charger plugged\n");
2567 queue_work(di
->charger_wq
, &di
->ac_work
);
2569 mutex_lock(&di
->charger_attached_mutex
);
2570 mutex_unlock(&di
->charger_attached_mutex
);
2572 if (is_ab8500(di
->parent
))
2573 queue_delayed_work(di
->charger_wq
,
2574 &di
->ac_charger_attached_work
,
2580 * ab8500_charger_mainextchnotok_handler() - main charger not ok
2581 * @irq: interrupt number
2582 * @_di: pointer to the ab8500_charger structure
2584 * Returns IRQ status(IRQ_HANDLED)
2586 static irqreturn_t
ab8500_charger_mainextchnotok_handler(int irq
, void *_di
)
2588 struct ab8500_charger
*di
= _di
;
2590 dev_dbg(di
->dev
, "Main charger not ok\n");
2591 di
->flags
.mainextchnotok
= true;
2592 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
2594 /* Schedule a new HW failure check */
2595 queue_delayed_work(di
->charger_wq
, &di
->check_hw_failure_work
, 0);
2601 * ab8500_charger_mainchthprotr_handler() - Die temp is above main charger
2602 * thermal protection threshold
2603 * @irq: interrupt number
2604 * @_di: pointer to the ab8500_charger structure
2606 * Returns IRQ status(IRQ_HANDLED)
2608 static irqreturn_t
ab8500_charger_mainchthprotr_handler(int irq
, void *_di
)
2610 struct ab8500_charger
*di
= _di
;
2613 "Die temp above Main charger thermal protection threshold\n");
2614 queue_work(di
->charger_wq
, &di
->check_main_thermal_prot_work
);
2620 * ab8500_charger_mainchthprotf_handler() - Die temp is below main charger
2621 * thermal protection threshold
2622 * @irq: interrupt number
2623 * @_di: pointer to the ab8500_charger structure
2625 * Returns IRQ status(IRQ_HANDLED)
2627 static irqreturn_t
ab8500_charger_mainchthprotf_handler(int irq
, void *_di
)
2629 struct ab8500_charger
*di
= _di
;
2632 "Die temp ok for Main charger thermal protection threshold\n");
2633 queue_work(di
->charger_wq
, &di
->check_main_thermal_prot_work
);
2638 static void ab8500_charger_vbus_drop_end_work(struct work_struct
*work
)
2640 struct ab8500_charger
*di
= container_of(work
,
2641 struct ab8500_charger
, vbus_drop_end_work
.work
);
2645 di
->flags
.vbus_drop_end
= false;
2647 /* Reset the drop counter */
2648 abx500_set_register_interruptible(di
->dev
,
2649 AB8500_CHARGER
, AB8500_CHARGER_CTRL
, 0x01);
2651 ret
= abx500_get_register_interruptible(di
->dev
, AB8500_CHARGER
,
2652 AB8500_CH_USBCH_STAT2_REG
, ®_value
);
2654 dev_err(di
->dev
, "%s read failed\n", __func__
);
2658 curr
= di
->bm
->chg_input_curr
[
2659 reg_value
>> AUTO_VBUS_IN_CURR_LIM_SHIFT
];
2661 if (di
->max_usb_in_curr
.calculated_max
!= curr
) {
2662 /* USB source is collapsing */
2663 di
->max_usb_in_curr
.calculated_max
= curr
;
2665 "VBUS input current limiting to %d mA\n",
2666 di
->max_usb_in_curr
.calculated_max
);
2669 * USB source can not give more than this amount.
2670 * Taking more will collapse the source.
2672 di
->max_usb_in_curr
.set_max
=
2673 di
->max_usb_in_curr
.calculated_max
;
2675 "VBUS input current limited to %d mA\n",
2676 di
->max_usb_in_curr
.set_max
);
2679 if (di
->usb
.charger_connected
)
2680 ab8500_charger_set_vbus_in_curr(di
,
2681 di
->max_usb_in_curr
.usb_type_max
);
2685 * ab8500_charger_vbusdetf_handler() - VBUS falling detected
2686 * @irq: interrupt number
2687 * @_di: pointer to the ab8500_charger structure
2689 * Returns IRQ status(IRQ_HANDLED)
2691 static irqreturn_t
ab8500_charger_vbusdetf_handler(int irq
, void *_di
)
2693 struct ab8500_charger
*di
= _di
;
2695 di
->vbus_detected
= false;
2696 dev_dbg(di
->dev
, "VBUS falling detected\n");
2697 queue_work(di
->charger_wq
, &di
->detect_usb_type_work
);
2703 * ab8500_charger_vbusdetr_handler() - VBUS rising detected
2704 * @irq: interrupt number
2705 * @_di: pointer to the ab8500_charger structure
2707 * Returns IRQ status(IRQ_HANDLED)
2709 static irqreturn_t
ab8500_charger_vbusdetr_handler(int irq
, void *_di
)
2711 struct ab8500_charger
*di
= _di
;
2713 di
->vbus_detected
= true;
2714 dev_dbg(di
->dev
, "VBUS rising detected\n");
2716 queue_work(di
->charger_wq
, &di
->detect_usb_type_work
);
2722 * ab8500_charger_usblinkstatus_handler() - USB link status has changed
2723 * @irq: interrupt number
2724 * @_di: pointer to the ab8500_charger structure
2726 * Returns IRQ status(IRQ_HANDLED)
2728 static irqreturn_t
ab8500_charger_usblinkstatus_handler(int irq
, void *_di
)
2730 struct ab8500_charger
*di
= _di
;
2732 dev_dbg(di
->dev
, "USB link status changed\n");
2734 queue_work(di
->charger_wq
, &di
->usb_link_status_work
);
2740 * ab8500_charger_usbchthprotr_handler() - Die temp is above usb charger
2741 * thermal protection threshold
2742 * @irq: interrupt number
2743 * @_di: pointer to the ab8500_charger structure
2745 * Returns IRQ status(IRQ_HANDLED)
2747 static irqreturn_t
ab8500_charger_usbchthprotr_handler(int irq
, void *_di
)
2749 struct ab8500_charger
*di
= _di
;
2752 "Die temp above USB charger thermal protection threshold\n");
2753 queue_work(di
->charger_wq
, &di
->check_usb_thermal_prot_work
);
2759 * ab8500_charger_usbchthprotf_handler() - Die temp is below usb charger
2760 * thermal protection threshold
2761 * @irq: interrupt number
2762 * @_di: pointer to the ab8500_charger structure
2764 * Returns IRQ status(IRQ_HANDLED)
2766 static irqreturn_t
ab8500_charger_usbchthprotf_handler(int irq
, void *_di
)
2768 struct ab8500_charger
*di
= _di
;
2771 "Die temp ok for USB charger thermal protection threshold\n");
2772 queue_work(di
->charger_wq
, &di
->check_usb_thermal_prot_work
);
2778 * ab8500_charger_usbchargernotokr_handler() - USB charger not ok detected
2779 * @irq: interrupt number
2780 * @_di: pointer to the ab8500_charger structure
2782 * Returns IRQ status(IRQ_HANDLED)
2784 static irqreturn_t
ab8500_charger_usbchargernotokr_handler(int irq
, void *_di
)
2786 struct ab8500_charger
*di
= _di
;
2788 dev_dbg(di
->dev
, "Not allowed USB charger detected\n");
2789 queue_delayed_work(di
->charger_wq
, &di
->check_usbchgnotok_work
, 0);
2795 * ab8500_charger_chwdexp_handler() - Charger watchdog expired
2796 * @irq: interrupt number
2797 * @_di: pointer to the ab8500_charger structure
2799 * Returns IRQ status(IRQ_HANDLED)
2801 static irqreturn_t
ab8500_charger_chwdexp_handler(int irq
, void *_di
)
2803 struct ab8500_charger
*di
= _di
;
2805 dev_dbg(di
->dev
, "Charger watchdog expired\n");
2808 * The charger that was online when the watchdog expired
2809 * needs to be restarted for charging to start again
2811 if (di
->ac
.charger_online
) {
2812 di
->ac
.wd_expired
= true;
2813 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
2815 if (di
->usb
.charger_online
) {
2816 di
->usb
.wd_expired
= true;
2817 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2824 * ab8500_charger_vbuschdropend_handler() - VBUS drop removed
2825 * @irq: interrupt number
2826 * @_di: pointer to the ab8500_charger structure
2828 * Returns IRQ status(IRQ_HANDLED)
2830 static irqreturn_t
ab8500_charger_vbuschdropend_handler(int irq
, void *_di
)
2832 struct ab8500_charger
*di
= _di
;
2834 dev_dbg(di
->dev
, "VBUS charger drop ended\n");
2835 di
->flags
.vbus_drop_end
= true;
2838 * VBUS might have dropped due to bad connection.
2839 * Schedule a new input limit set to the value SW requests.
2841 queue_delayed_work(di
->charger_wq
, &di
->vbus_drop_end_work
,
2842 round_jiffies(VBUS_IN_CURR_LIM_RETRY_SET_TIME
* HZ
));
2848 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected
2849 * @irq: interrupt number
2850 * @_di: pointer to the ab8500_charger structure
2852 * Returns IRQ status(IRQ_HANDLED)
2854 static irqreturn_t
ab8500_charger_vbusovv_handler(int irq
, void *_di
)
2856 struct ab8500_charger
*di
= _di
;
2858 dev_dbg(di
->dev
, "VBUS overvoltage detected\n");
2859 di
->flags
.vbus_ovv
= true;
2860 ab8500_power_supply_changed(di
, di
->usb_chg
.psy
);
2862 /* Schedule a new HW failure check */
2863 queue_delayed_work(di
->charger_wq
, &di
->check_hw_failure_work
, 0);
2869 * ab8500_charger_ac_get_property() - get the ac/mains properties
2870 * @psy: pointer to the power_supply structure
2871 * @psp: pointer to the power_supply_property structure
2872 * @val: pointer to the power_supply_propval union
2874 * This function gets called when an application tries to get the ac/mains
2875 * properties by reading the sysfs files.
2876 * AC/Mains properties are online, present and voltage.
2877 * online: ac/mains charging is in progress or not
2878 * present: presence of the ac/mains
2879 * voltage: AC/Mains voltage
2880 * Returns error code in case of failure else 0(on success)
2882 static int ab8500_charger_ac_get_property(struct power_supply
*psy
,
2883 enum power_supply_property psp
,
2884 union power_supply_propval
*val
)
2886 struct ab8500_charger
*di
;
2889 di
= to_ab8500_charger_ac_device_info(psy_to_ux500_charger(psy
));
2892 case POWER_SUPPLY_PROP_HEALTH
:
2893 if (di
->flags
.mainextchnotok
)
2894 val
->intval
= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
2895 else if (di
->ac
.wd_expired
|| di
->usb
.wd_expired
)
2896 val
->intval
= POWER_SUPPLY_HEALTH_DEAD
;
2897 else if (di
->flags
.main_thermal_prot
)
2898 val
->intval
= POWER_SUPPLY_HEALTH_OVERHEAT
;
2900 val
->intval
= POWER_SUPPLY_HEALTH_GOOD
;
2902 case POWER_SUPPLY_PROP_ONLINE
:
2903 val
->intval
= di
->ac
.charger_online
;
2905 case POWER_SUPPLY_PROP_PRESENT
:
2906 val
->intval
= di
->ac
.charger_connected
;
2908 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
2909 ret
= ab8500_charger_get_ac_voltage(di
);
2911 di
->ac
.charger_voltage
= ret
;
2912 /* On error, use previous value */
2913 val
->intval
= di
->ac
.charger_voltage
* 1000;
2915 case POWER_SUPPLY_PROP_VOLTAGE_AVG
:
2917 * This property is used to indicate when CV mode is entered
2918 * for the AC charger
2920 di
->ac
.cv_active
= ab8500_charger_ac_cv(di
);
2921 val
->intval
= di
->ac
.cv_active
;
2923 case POWER_SUPPLY_PROP_CURRENT_NOW
:
2924 ret
= ab8500_charger_get_ac_current(di
);
2926 di
->ac
.charger_current
= ret
;
2927 val
->intval
= di
->ac
.charger_current
* 1000;
2936 * ab8500_charger_usb_get_property() - get the usb properties
2937 * @psy: pointer to the power_supply structure
2938 * @psp: pointer to the power_supply_property structure
2939 * @val: pointer to the power_supply_propval union
2941 * This function gets called when an application tries to get the usb
2942 * properties by reading the sysfs files.
2943 * USB properties are online, present and voltage.
2944 * online: usb charging is in progress or not
2945 * present: presence of the usb
2946 * voltage: vbus voltage
2947 * Returns error code in case of failure else 0(on success)
2949 static int ab8500_charger_usb_get_property(struct power_supply
*psy
,
2950 enum power_supply_property psp
,
2951 union power_supply_propval
*val
)
2953 struct ab8500_charger
*di
;
2956 di
= to_ab8500_charger_usb_device_info(psy_to_ux500_charger(psy
));
2959 case POWER_SUPPLY_PROP_HEALTH
:
2960 if (di
->flags
.usbchargernotok
)
2961 val
->intval
= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
2962 else if (di
->ac
.wd_expired
|| di
->usb
.wd_expired
)
2963 val
->intval
= POWER_SUPPLY_HEALTH_DEAD
;
2964 else if (di
->flags
.usb_thermal_prot
)
2965 val
->intval
= POWER_SUPPLY_HEALTH_OVERHEAT
;
2966 else if (di
->flags
.vbus_ovv
)
2967 val
->intval
= POWER_SUPPLY_HEALTH_OVERVOLTAGE
;
2969 val
->intval
= POWER_SUPPLY_HEALTH_GOOD
;
2971 case POWER_SUPPLY_PROP_ONLINE
:
2972 val
->intval
= di
->usb
.charger_online
;
2974 case POWER_SUPPLY_PROP_PRESENT
:
2975 val
->intval
= di
->usb
.charger_connected
;
2977 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
2978 ret
= ab8500_charger_get_vbus_voltage(di
);
2980 di
->usb
.charger_voltage
= ret
;
2981 val
->intval
= di
->usb
.charger_voltage
* 1000;
2983 case POWER_SUPPLY_PROP_VOLTAGE_AVG
:
2985 * This property is used to indicate when CV mode is entered
2986 * for the USB charger
2988 di
->usb
.cv_active
= ab8500_charger_usb_cv(di
);
2989 val
->intval
= di
->usb
.cv_active
;
2991 case POWER_SUPPLY_PROP_CURRENT_NOW
:
2992 ret
= ab8500_charger_get_usb_current(di
);
2994 di
->usb
.charger_current
= ret
;
2995 val
->intval
= di
->usb
.charger_current
* 1000;
2997 case POWER_SUPPLY_PROP_CURRENT_AVG
:
2999 * This property is used to indicate when VBUS has collapsed
3000 * due to too high output current from the USB charger
3002 if (di
->flags
.vbus_collapse
)
3014 * ab8500_charger_init_hw_registers() - Set up charger related registers
3015 * @di: pointer to the ab8500_charger structure
3017 * Set up charger OVV, watchdog and maximum voltage registers as well as
3018 * charging of the backup battery
3020 static int ab8500_charger_init_hw_registers(struct ab8500_charger
*di
)
3024 /* Setup maximum charger current and voltage for ABB cut2.0 */
3025 if (!is_ab8500_1p1_or_earlier(di
->parent
)) {
3026 ret
= abx500_set_register_interruptible(di
->dev
,
3028 AB8500_CH_VOLT_LVL_MAX_REG
, CH_VOL_LVL_4P6
);
3031 "failed to set CH_VOLT_LVL_MAX_REG\n");
3035 ret
= abx500_set_register_interruptible(di
->dev
,
3036 AB8500_CHARGER
, AB8500_CH_OPT_CRNTLVL_MAX_REG
,
3040 "failed to set CH_OPT_CRNTLVL_MAX_REG\n");
3045 if (is_ab8505_2p0(di
->parent
))
3046 ret
= abx500_mask_and_set_register_interruptible(di
->dev
,
3048 AB8500_USBCH_CTRL2_REG
,
3049 VBUS_AUTO_IN_CURR_LIM_ENA
,
3050 VBUS_AUTO_IN_CURR_LIM_ENA
);
3053 * VBUS OVV set to 6.3V and enable automatic current limitation
3055 ret
= abx500_set_register_interruptible(di
->dev
,
3057 AB8500_USBCH_CTRL2_REG
,
3058 VBUS_OVV_SELECT_6P3V
| VBUS_AUTO_IN_CURR_LIM_ENA
);
3061 "failed to set automatic current limitation\n");
3065 /* Enable main watchdog in OTP */
3066 ret
= abx500_set_register_interruptible(di
->dev
,
3067 AB8500_OTP_EMUL
, AB8500_OTP_CONF_15
, OTP_ENABLE_WD
);
3069 dev_err(di
->dev
, "failed to enable main WD in OTP\n");
3073 /* Enable main watchdog */
3074 ret
= abx500_set_register_interruptible(di
->dev
,
3075 AB8500_SYS_CTRL2_BLOCK
,
3076 AB8500_MAIN_WDOG_CTRL_REG
, MAIN_WDOG_ENA
);
3078 dev_err(di
->dev
, "failed to enable main watchdog\n");
3083 * Due to internal synchronisation, Enable and Kick watchdog bits
3084 * cannot be enabled in a single write.
3085 * A minimum delay of 2*32 kHz period (62.5µs) must be inserted
3086 * between writing Enable then Kick bits.
3090 /* Kick main watchdog */
3091 ret
= abx500_set_register_interruptible(di
->dev
,
3092 AB8500_SYS_CTRL2_BLOCK
,
3093 AB8500_MAIN_WDOG_CTRL_REG
,
3094 (MAIN_WDOG_ENA
| MAIN_WDOG_KICK
));
3096 dev_err(di
->dev
, "failed to kick main watchdog\n");
3100 /* Disable main watchdog */
3101 ret
= abx500_set_register_interruptible(di
->dev
,
3102 AB8500_SYS_CTRL2_BLOCK
,
3103 AB8500_MAIN_WDOG_CTRL_REG
, MAIN_WDOG_DIS
);
3105 dev_err(di
->dev
, "failed to disable main watchdog\n");
3109 /* Set watchdog timeout */
3110 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
3111 AB8500_CH_WD_TIMER_REG
, WD_TIMER
);
3113 dev_err(di
->dev
, "failed to set charger watchdog timeout\n");
3117 ret
= ab8500_charger_led_en(di
, false);
3119 dev_err(di
->dev
, "failed to disable LED\n");
3123 ret
= abx500_set_register_interruptible(di
->dev
,
3125 AB8500_RTC_BACKUP_CHG_REG
,
3126 (di
->bm
->bkup_bat_v
& 0x3) | di
->bm
->bkup_bat_i
);
3128 dev_err(di
->dev
, "failed to setup backup battery charging\n");
3132 /* Enable backup battery charging */
3133 ret
= abx500_mask_and_set_register_interruptible(di
->dev
,
3134 AB8500_RTC
, AB8500_RTC_CTRL_REG
,
3135 RTC_BUP_CH_ENA
, RTC_BUP_CH_ENA
);
3137 dev_err(di
->dev
, "%s mask and set failed\n", __func__
);
3146 * ab8500 charger driver interrupts and their respective isr
3148 static struct ab8500_charger_interrupts ab8500_charger_irq
[] = {
3149 {"MAIN_CH_UNPLUG_DET", ab8500_charger_mainchunplugdet_handler
},
3150 {"MAIN_CHARGE_PLUG_DET", ab8500_charger_mainchplugdet_handler
},
3151 {"MAIN_EXT_CH_NOT_OK", ab8500_charger_mainextchnotok_handler
},
3152 {"MAIN_CH_TH_PROT_R", ab8500_charger_mainchthprotr_handler
},
3153 {"MAIN_CH_TH_PROT_F", ab8500_charger_mainchthprotf_handler
},
3154 {"VBUS_DET_F", ab8500_charger_vbusdetf_handler
},
3155 {"VBUS_DET_R", ab8500_charger_vbusdetr_handler
},
3156 {"USB_LINK_STATUS", ab8500_charger_usblinkstatus_handler
},
3157 {"USB_CH_TH_PROT_R", ab8500_charger_usbchthprotr_handler
},
3158 {"USB_CH_TH_PROT_F", ab8500_charger_usbchthprotf_handler
},
3159 {"USB_CHARGER_NOT_OKR", ab8500_charger_usbchargernotokr_handler
},
3160 {"VBUS_OVV", ab8500_charger_vbusovv_handler
},
3161 {"CH_WD_EXP", ab8500_charger_chwdexp_handler
},
3162 {"VBUS_CH_DROP_END", ab8500_charger_vbuschdropend_handler
},
3165 static int ab8500_charger_usb_notifier_call(struct notifier_block
*nb
,
3166 unsigned long event
, void *power
)
3168 struct ab8500_charger
*di
=
3169 container_of(nb
, struct ab8500_charger
, nb
);
3170 enum ab8500_usb_state bm_usb_state
;
3171 unsigned mA
= *((unsigned *)power
);
3176 if (event
!= USB_EVENT_VBUS
) {
3177 dev_dbg(di
->dev
, "not a standard host, returning\n");
3181 /* TODO: State is fabricate here. See if charger really needs USB
3182 * state or if mA is enough
3184 if ((di
->usb_state
.usb_current
== 2) && (mA
> 2))
3185 bm_usb_state
= AB8500_BM_USB_STATE_RESUME
;
3187 bm_usb_state
= AB8500_BM_USB_STATE_RESET_HS
;
3189 bm_usb_state
= AB8500_BM_USB_STATE_SUSPEND
;
3190 else if (mA
>= 8) /* 8, 100, 500 */
3191 bm_usb_state
= AB8500_BM_USB_STATE_CONFIGURED
;
3192 else /* Should never occur */
3193 bm_usb_state
= AB8500_BM_USB_STATE_RESET_FS
;
3195 dev_dbg(di
->dev
, "%s usb_state: 0x%02x mA: %d\n",
3196 __func__
, bm_usb_state
, mA
);
3198 spin_lock(&di
->usb_state
.usb_lock
);
3199 di
->usb_state
.state_tmp
= bm_usb_state
;
3200 di
->usb_state
.usb_current_tmp
= mA
;
3201 spin_unlock(&di
->usb_state
.usb_lock
);
3204 * wait for some time until you get updates from the usb stack
3205 * and negotiations are completed
3207 queue_delayed_work(di
->charger_wq
, &di
->usb_state_changed_work
, HZ
/2);
3212 static int __maybe_unused
ab8500_charger_resume(struct device
*dev
)
3215 struct ab8500_charger
*di
= dev_get_drvdata(dev
);
3218 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
3219 * logic. That means we have to continuously kick the charger
3220 * watchdog even when no charger is connected. This is only
3221 * valid once the AC charger has been enabled. This is
3222 * a bug that is not handled by the algorithm and the
3223 * watchdog have to be kicked by the charger driver
3224 * when the AC charger is disabled
3226 if (di
->ac_conn
&& is_ab8500_1p1_or_earlier(di
->parent
)) {
3227 ret
= abx500_set_register_interruptible(di
->dev
, AB8500_CHARGER
,
3228 AB8500_CHARG_WD_CTRL
, CHARG_WD_KICK
);
3230 dev_err(di
->dev
, "Failed to kick WD!\n");
3232 /* If not already pending start a new timer */
3233 queue_delayed_work(di
->charger_wq
, &di
->kick_wd_work
,
3234 round_jiffies(WD_KICK_INTERVAL
));
3237 /* If we still have a HW failure, schedule a new check */
3238 if (di
->flags
.mainextchnotok
|| di
->flags
.vbus_ovv
) {
3239 queue_delayed_work(di
->charger_wq
,
3240 &di
->check_hw_failure_work
, 0);
3243 if (di
->flags
.vbus_drop_end
)
3244 queue_delayed_work(di
->charger_wq
, &di
->vbus_drop_end_work
, 0);
3249 static int __maybe_unused
ab8500_charger_suspend(struct device
*dev
)
3251 struct ab8500_charger
*di
= dev_get_drvdata(dev
);
3253 /* Cancel any pending jobs */
3254 cancel_delayed_work(&di
->check_hw_failure_work
);
3255 cancel_delayed_work(&di
->vbus_drop_end_work
);
3257 flush_delayed_work(&di
->attach_work
);
3258 flush_delayed_work(&di
->usb_charger_attached_work
);
3259 flush_delayed_work(&di
->ac_charger_attached_work
);
3260 flush_delayed_work(&di
->check_usbchgnotok_work
);
3261 flush_delayed_work(&di
->check_vbat_work
);
3262 flush_delayed_work(&di
->kick_wd_work
);
3264 flush_work(&di
->usb_link_status_work
);
3265 flush_work(&di
->ac_work
);
3266 flush_work(&di
->detect_usb_type_work
);
3268 if (atomic_read(&di
->current_stepping_sessions
))
3274 static struct notifier_block charger_nb
= {
3275 .notifier_call
= ab8500_external_charger_prepare
,
3278 static int ab8500_charger_remove(struct platform_device
*pdev
)
3280 struct ab8500_charger
*di
= platform_get_drvdata(pdev
);
3283 /* Disable AC charging */
3284 ab8500_charger_ac_en(&di
->ac_chg
, false, 0, 0);
3286 /* Disable USB charging */
3287 ab8500_charger_usb_en(&di
->usb_chg
, false, 0, 0);
3289 /* Disable interrupts */
3290 for (i
= 0; i
< ARRAY_SIZE(ab8500_charger_irq
); i
++) {
3291 irq
= platform_get_irq_byname(pdev
, ab8500_charger_irq
[i
].name
);
3295 /* Backup battery voltage and current disable */
3296 ret
= abx500_mask_and_set_register_interruptible(di
->dev
,
3297 AB8500_RTC
, AB8500_RTC_CTRL_REG
, RTC_BUP_CH_ENA
, 0);
3299 dev_err(di
->dev
, "%s mask and set failed\n", __func__
);
3301 usb_unregister_notifier(di
->usb_phy
, &di
->nb
);
3302 usb_put_phy(di
->usb_phy
);
3304 /* Delete the work queue */
3305 destroy_workqueue(di
->charger_wq
);
3307 /* Unregister external charger enable notifier */
3308 if (!di
->ac_chg
.enabled
)
3309 blocking_notifier_chain_unregister(
3310 &charger_notifier_list
, &charger_nb
);
3312 flush_scheduled_work();
3313 if (di
->usb_chg
.enabled
)
3314 power_supply_unregister(di
->usb_chg
.psy
);
3316 if (di
->ac_chg
.enabled
&& !di
->ac_chg
.external
)
3317 power_supply_unregister(di
->ac_chg
.psy
);
3322 static char *supply_interface
[] = {
3328 static const struct power_supply_desc ab8500_ac_chg_desc
= {
3329 .name
= "ab8500_ac",
3330 .type
= POWER_SUPPLY_TYPE_MAINS
,
3331 .properties
= ab8500_charger_ac_props
,
3332 .num_properties
= ARRAY_SIZE(ab8500_charger_ac_props
),
3333 .get_property
= ab8500_charger_ac_get_property
,
3336 static const struct power_supply_desc ab8500_usb_chg_desc
= {
3337 .name
= "ab8500_usb",
3338 .type
= POWER_SUPPLY_TYPE_USB
,
3339 .properties
= ab8500_charger_usb_props
,
3340 .num_properties
= ARRAY_SIZE(ab8500_charger_usb_props
),
3341 .get_property
= ab8500_charger_usb_get_property
,
3344 static int ab8500_charger_probe(struct platform_device
*pdev
)
3346 struct device_node
*np
= pdev
->dev
.of_node
;
3347 struct abx500_bm_data
*plat
= pdev
->dev
.platform_data
;
3348 struct power_supply_config ac_psy_cfg
= {}, usb_psy_cfg
= {};
3349 struct ab8500_charger
*di
;
3350 int irq
, i
, charger_status
, ret
= 0, ch_stat
;
3351 struct device
*dev
= &pdev
->dev
;
3353 di
= devm_kzalloc(dev
, sizeof(*di
), GFP_KERNEL
);
3358 dev_err(dev
, "no battery management data supplied\n");
3364 ret
= ab8500_bm_of_probe(dev
, np
, di
->bm
);
3366 dev_err(dev
, "failed to get battery information\n");
3369 di
->autopower_cfg
= of_property_read_bool(np
, "autopower_cfg");
3371 di
->autopower_cfg
= false;
3373 /* get parent data */
3375 di
->parent
= dev_get_drvdata(pdev
->dev
.parent
);
3377 /* Get ADC channels */
3378 di
->adc_main_charger_v
= devm_iio_channel_get(dev
, "main_charger_v");
3379 if (IS_ERR(di
->adc_main_charger_v
)) {
3380 ret
= dev_err_probe(dev
, PTR_ERR(di
->adc_main_charger_v
),
3381 "failed to get ADC main charger voltage\n");
3384 di
->adc_main_charger_c
= devm_iio_channel_get(dev
, "main_charger_c");
3385 if (IS_ERR(di
->adc_main_charger_c
)) {
3386 ret
= dev_err_probe(dev
, PTR_ERR(di
->adc_main_charger_c
),
3387 "failed to get ADC main charger current\n");
3390 di
->adc_vbus_v
= devm_iio_channel_get(dev
, "vbus_v");
3391 if (IS_ERR(di
->adc_vbus_v
)) {
3392 ret
= dev_err_probe(dev
, PTR_ERR(di
->adc_vbus_v
),
3393 "failed to get ADC USB charger voltage\n");
3396 di
->adc_usb_charger_c
= devm_iio_channel_get(dev
, "usb_charger_c");
3397 if (IS_ERR(di
->adc_usb_charger_c
)) {
3398 ret
= dev_err_probe(dev
, PTR_ERR(di
->adc_usb_charger_c
),
3399 "failed to get ADC USB charger current\n");
3403 /* initialize lock */
3404 spin_lock_init(&di
->usb_state
.usb_lock
);
3405 mutex_init(&di
->usb_ipt_crnt_lock
);
3407 di
->autopower
= false;
3408 di
->invalid_charger_detect_state
= 0;
3410 /* AC and USB supply config */
3411 ac_psy_cfg
.supplied_to
= supply_interface
;
3412 ac_psy_cfg
.num_supplicants
= ARRAY_SIZE(supply_interface
);
3413 ac_psy_cfg
.drv_data
= &di
->ac_chg
;
3414 usb_psy_cfg
.supplied_to
= supply_interface
;
3415 usb_psy_cfg
.num_supplicants
= ARRAY_SIZE(supply_interface
);
3416 usb_psy_cfg
.drv_data
= &di
->usb_chg
;
3419 /* ux500_charger sub-class */
3420 di
->ac_chg
.ops
.enable
= &ab8500_charger_ac_en
;
3421 di
->ac_chg
.ops
.check_enable
= &ab8500_charger_ac_check_enable
;
3422 di
->ac_chg
.ops
.kick_wd
= &ab8500_charger_watchdog_kick
;
3423 di
->ac_chg
.ops
.update_curr
= &ab8500_charger_update_charger_current
;
3424 di
->ac_chg
.max_out_volt
= ab8500_charger_voltage_map
[
3425 ARRAY_SIZE(ab8500_charger_voltage_map
) - 1];
3426 di
->ac_chg
.max_out_curr
=
3427 di
->bm
->chg_output_curr
[di
->bm
->n_chg_out_curr
- 1];
3428 di
->ac_chg
.wdt_refresh
= CHG_WD_INTERVAL
;
3429 di
->ac_chg
.enabled
= di
->bm
->ac_enabled
;
3430 di
->ac_chg
.external
= false;
3432 /*notifier for external charger enabling*/
3433 if (!di
->ac_chg
.enabled
)
3434 blocking_notifier_chain_register(
3435 &charger_notifier_list
, &charger_nb
);
3438 /* ux500_charger sub-class */
3439 di
->usb_chg
.ops
.enable
= &ab8500_charger_usb_en
;
3440 di
->usb_chg
.ops
.check_enable
= &ab8500_charger_usb_check_enable
;
3441 di
->usb_chg
.ops
.kick_wd
= &ab8500_charger_watchdog_kick
;
3442 di
->usb_chg
.ops
.update_curr
= &ab8500_charger_update_charger_current
;
3443 di
->usb_chg
.max_out_volt
= ab8500_charger_voltage_map
[
3444 ARRAY_SIZE(ab8500_charger_voltage_map
) - 1];
3445 di
->usb_chg
.max_out_curr
=
3446 di
->bm
->chg_output_curr
[di
->bm
->n_chg_out_curr
- 1];
3447 di
->usb_chg
.wdt_refresh
= CHG_WD_INTERVAL
;
3448 di
->usb_chg
.enabled
= di
->bm
->usb_enabled
;
3449 di
->usb_chg
.external
= false;
3450 di
->usb_state
.usb_current
= -1;
3452 /* Create a work queue for the charger */
3453 di
->charger_wq
= alloc_ordered_workqueue("ab8500_charger_wq",
3455 if (di
->charger_wq
== NULL
) {
3456 dev_err(dev
, "failed to create work queue\n");
3460 mutex_init(&di
->charger_attached_mutex
);
3462 /* Init work for HW failure check */
3463 INIT_DEFERRABLE_WORK(&di
->check_hw_failure_work
,
3464 ab8500_charger_check_hw_failure_work
);
3465 INIT_DEFERRABLE_WORK(&di
->check_usbchgnotok_work
,
3466 ab8500_charger_check_usbchargernotok_work
);
3468 INIT_DELAYED_WORK(&di
->ac_charger_attached_work
,
3469 ab8500_charger_ac_attached_work
);
3470 INIT_DELAYED_WORK(&di
->usb_charger_attached_work
,
3471 ab8500_charger_usb_attached_work
);
3474 * For ABB revision 1.0 and 1.1 there is a bug in the watchdog
3475 * logic. That means we have to continuously kick the charger
3476 * watchdog even when no charger is connected. This is only
3477 * valid once the AC charger has been enabled. This is
3478 * a bug that is not handled by the algorithm and the
3479 * watchdog have to be kicked by the charger driver
3480 * when the AC charger is disabled
3482 INIT_DEFERRABLE_WORK(&di
->kick_wd_work
,
3483 ab8500_charger_kick_watchdog_work
);
3485 INIT_DEFERRABLE_WORK(&di
->check_vbat_work
,
3486 ab8500_charger_check_vbat_work
);
3488 INIT_DELAYED_WORK(&di
->attach_work
,
3489 ab8500_charger_usb_link_attach_work
);
3491 INIT_DELAYED_WORK(&di
->usb_state_changed_work
,
3492 ab8500_charger_usb_state_changed_work
);
3494 INIT_DELAYED_WORK(&di
->vbus_drop_end_work
,
3495 ab8500_charger_vbus_drop_end_work
);
3497 /* Init work for charger detection */
3498 INIT_WORK(&di
->usb_link_status_work
,
3499 ab8500_charger_usb_link_status_work
);
3500 INIT_WORK(&di
->ac_work
, ab8500_charger_ac_work
);
3501 INIT_WORK(&di
->detect_usb_type_work
,
3502 ab8500_charger_detect_usb_type_work
);
3504 /* Init work for checking HW status */
3505 INIT_WORK(&di
->check_main_thermal_prot_work
,
3506 ab8500_charger_check_main_thermal_prot_work
);
3507 INIT_WORK(&di
->check_usb_thermal_prot_work
,
3508 ab8500_charger_check_usb_thermal_prot_work
);
3511 * VDD ADC supply needs to be enabled from this driver when there
3512 * is a charger connected to avoid erroneous BTEMP_HIGH/LOW
3513 * interrupts during charging
3515 di
->regu
= devm_regulator_get(dev
, "vddadc");
3516 if (IS_ERR(di
->regu
)) {
3517 ret
= PTR_ERR(di
->regu
);
3518 dev_err(dev
, "failed to get vddadc regulator\n");
3519 goto free_charger_wq
;
3523 /* Initialize OVV, and other registers */
3524 ret
= ab8500_charger_init_hw_registers(di
);
3526 dev_err(dev
, "failed to initialize ABB registers\n");
3527 goto free_charger_wq
;
3530 /* Register AC charger class */
3531 if (di
->ac_chg
.enabled
) {
3532 di
->ac_chg
.psy
= power_supply_register(dev
,
3533 &ab8500_ac_chg_desc
,
3535 if (IS_ERR(di
->ac_chg
.psy
)) {
3536 dev_err(dev
, "failed to register AC charger\n");
3537 ret
= PTR_ERR(di
->ac_chg
.psy
);
3538 goto free_charger_wq
;
3542 /* Register USB charger class */
3543 if (di
->usb_chg
.enabled
) {
3544 di
->usb_chg
.psy
= power_supply_register(dev
,
3545 &ab8500_usb_chg_desc
,
3547 if (IS_ERR(di
->usb_chg
.psy
)) {
3548 dev_err(dev
, "failed to register USB charger\n");
3549 ret
= PTR_ERR(di
->usb_chg
.psy
);
3554 di
->usb_phy
= usb_get_phy(USB_PHY_TYPE_USB2
);
3555 if (IS_ERR_OR_NULL(di
->usb_phy
)) {
3556 dev_err(dev
, "failed to get usb transceiver\n");
3560 di
->nb
.notifier_call
= ab8500_charger_usb_notifier_call
;
3561 ret
= usb_register_notifier(di
->usb_phy
, &di
->nb
);
3563 dev_err(dev
, "failed to register usb notifier\n");
3567 /* Identify the connected charger types during startup */
3568 charger_status
= ab8500_charger_detect_chargers(di
, true);
3569 if (charger_status
& AC_PW_CONN
) {
3570 di
->ac
.charger_connected
= 1;
3572 ab8500_power_supply_changed(di
, di
->ac_chg
.psy
);
3573 sysfs_notify(&di
->ac_chg
.psy
->dev
.kobj
, NULL
, "present");
3576 if (charger_status
& USB_PW_CONN
) {
3577 di
->vbus_detected
= true;
3578 di
->vbus_detected_start
= true;
3579 queue_work(di
->charger_wq
,
3580 &di
->detect_usb_type_work
);
3583 /* Register interrupts */
3584 for (i
= 0; i
< ARRAY_SIZE(ab8500_charger_irq
); i
++) {
3585 irq
= platform_get_irq_byname(pdev
, ab8500_charger_irq
[i
].name
);
3591 ret
= request_threaded_irq(irq
, NULL
, ab8500_charger_irq
[i
].isr
,
3592 IRQF_SHARED
| IRQF_NO_SUSPEND
| IRQF_ONESHOT
,
3593 ab8500_charger_irq
[i
].name
, di
);
3596 dev_err(dev
, "failed to request %s IRQ %d: %d\n"
3597 , ab8500_charger_irq
[i
].name
, irq
, ret
);
3600 dev_dbg(dev
, "Requested %s IRQ %d: %d\n",
3601 ab8500_charger_irq
[i
].name
, irq
, ret
);
3604 platform_set_drvdata(pdev
, di
);
3606 mutex_lock(&di
->charger_attached_mutex
);
3608 ch_stat
= ab8500_charger_detect_chargers(di
, false);
3610 if ((ch_stat
& AC_PW_CONN
) == AC_PW_CONN
) {
3611 if (is_ab8500(di
->parent
))
3612 queue_delayed_work(di
->charger_wq
,
3613 &di
->ac_charger_attached_work
,
3616 if ((ch_stat
& USB_PW_CONN
) == USB_PW_CONN
) {
3617 if (is_ab8500(di
->parent
))
3618 queue_delayed_work(di
->charger_wq
,
3619 &di
->usb_charger_attached_work
,
3623 mutex_unlock(&di
->charger_attached_mutex
);
3628 usb_unregister_notifier(di
->usb_phy
, &di
->nb
);
3630 /* We also have to free all successfully registered irqs */
3631 for (i
= i
- 1; i
>= 0; i
--) {
3632 irq
= platform_get_irq_byname(pdev
, ab8500_charger_irq
[i
].name
);
3636 usb_put_phy(di
->usb_phy
);
3638 if (di
->usb_chg
.enabled
)
3639 power_supply_unregister(di
->usb_chg
.psy
);
3641 if (di
->ac_chg
.enabled
)
3642 power_supply_unregister(di
->ac_chg
.psy
);
3644 destroy_workqueue(di
->charger_wq
);
3648 static SIMPLE_DEV_PM_OPS(ab8500_charger_pm_ops
, ab8500_charger_suspend
, ab8500_charger_resume
);
3650 static const struct of_device_id ab8500_charger_match
[] = {
3651 { .compatible
= "stericsson,ab8500-charger", },
3655 static struct platform_driver ab8500_charger_driver
= {
3656 .probe
= ab8500_charger_probe
,
3657 .remove
= ab8500_charger_remove
,
3659 .name
= "ab8500-charger",
3660 .of_match_table
= ab8500_charger_match
,
3661 .pm
= &ab8500_charger_pm_ops
,
3665 static int __init
ab8500_charger_init(void)
3667 return platform_driver_register(&ab8500_charger_driver
);
3670 static void __exit
ab8500_charger_exit(void)
3672 platform_driver_unregister(&ab8500_charger_driver
);
3675 subsys_initcall_sync(ab8500_charger_init
);
3676 module_exit(ab8500_charger_exit
);
3678 MODULE_LICENSE("GPL v2");
3679 MODULE_AUTHOR("Johan Palsson, Karl Komierowski, Arun R Murthy");
3680 MODULE_ALIAS("platform:ab8500-charger");
3681 MODULE_DESCRIPTION("AB8500 charger management driver");