14 #include <linux/module.h>
15 #include <linux/device.h>
18 #include <linux/slab.h>
38 #define MAIN_WDOG_ENA 0x01
39 #define MAIN_WDOG_KICK 0x02
40 #define MAIN_WDOG_DIS 0x00
41 #define CHARG_WD_KICK 0x01
42 #define MAIN_CH_ENA 0x01
43 #define MAIN_CH_NO_OVERSHOOT_ENA_N 0x02
44 #define USB_CH_ENA 0x01
45 #define USB_CHG_NO_OVERSHOOT_ENA_N 0x02
46 #define MAIN_CH_DET 0x01
47 #define MAIN_CH_CV_ON 0x04
48 #define USB_CH_CV_ON 0x08
49 #define VBUS_DET_DBNC100 0x02
50 #define VBUS_DET_DBNC1 0x01
51 #define OTP_ENABLE_WD 0x01
53 #define MAIN_CH_INPUT_CURR_SHIFT 4
54 #define VBUS_IN_CURR_LIM_SHIFT 4
56 #define LED_INDICATOR_PWM_ENA 0x01
57 #define LED_INDICATOR_PWM_DIS 0x00
58 #define LED_IND_CUR_5MA 0x04
59 #define LED_INDICATOR_PWM_DUTY_252_256 0xBF
62 #define MAIN_CH_TH_PROT 0x02
63 #define VBUS_CH_NOK 0x08
64 #define USB_CH_TH_PROT 0x02
65 #define VBUS_OVV_TH 0x01
66 #define MAIN_CH_NOK 0x01
70 #define AB8500_USB_LINK_STATUS 0x78
71 #define AB8500_STD_HOST_SUSP 0x18
75 #define WD_KICK_INTERVAL (60 * HZ)
78 #define LOW_VOLT_REG 0x4E
110 #define USB_CH_IP_CUR_LVL_0P05 50
111 #define USB_CH_IP_CUR_LVL_0P09 98
112 #define USB_CH_IP_CUR_LVL_0P19 193
113 #define USB_CH_IP_CUR_LVL_0P29 290
114 #define USB_CH_IP_CUR_LVL_0P38 380
115 #define USB_CH_IP_CUR_LVL_0P45 450
116 #define USB_CH_IP_CUR_LVL_0P5 500
117 #define USB_CH_IP_CUR_LVL_0P6 600
118 #define USB_CH_IP_CUR_LVL_0P7 700
119 #define USB_CH_IP_CUR_LVL_0P8 800
120 #define USB_CH_IP_CUR_LVL_0P9 900
121 #define USB_CH_IP_CUR_LVL_1P0 1000
122 #define USB_CH_IP_CUR_LVL_1P1 1100
123 #define USB_CH_IP_CUR_LVL_1P3 1300
124 #define USB_CH_IP_CUR_LVL_1P4 1400
125 #define USB_CH_IP_CUR_LVL_1P5 1500
127 #define VBAT_TRESH_IP_CUR_RED 3800
129 #define to_ab8500_charger_usb_device_info(x) container_of((x), \
130 struct ab8500_charger, usb_chg)
131 #define to_ab8500_charger_ac_device_info(x) container_of((x), \
132 struct ab8500_charger, ac_chg)
284 dev_err(di->
dev,
"%d write failed\n", __LINE__);
291 dev_err(di->
dev,
"%d write failed\n", __LINE__);
303 dev_err(di->
dev,
"%d write failed\n", __LINE__);
310 dev_err(di->
dev,
"%d write failed\n", __LINE__);
322 static void ab8500_power_supply_changed(
struct ab8500_charger *di,
325 if (di->
pdata->autopower_cfg) {
326 if (!di->
usb.charger_connected &&
327 !di->
ac.charger_connected &&
330 ab8500_power_loss_handling(di);
332 (di->
ac.charger_connected ||
333 di->
usb.charger_connected)) {
335 ab8500_power_loss_handling(di);
341 static void ab8500_charger_set_usb_connected(
struct ab8500_charger *di,
344 if (connected != di->
usb.charger_connected) {
345 dev_dbg(di->
dev,
"USB connected:%i\n", connected);
346 di->
usb.charger_connected = connected;
357 static int ab8500_charger_get_ac_voltage(
struct ab8500_charger *di)
362 if (di->
ac.charger_connected) {
365 dev_err(di->
dev,
"%s gpadc conv failed,\n", __func__);
384 if (di->
ac.charger_online) {
388 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
408 static int ab8500_charger_get_vbus_voltage(
struct ab8500_charger *di)
413 if (di->
usb.charger_connected) {
416 dev_err(di->
dev,
"%s gpadc conv failed\n", __func__);
430 static int ab8500_charger_get_usb_current(
struct ab8500_charger *di)
435 if (di->
usb.charger_online) {
438 dev_err(di->
dev,
"%s gpadc conv failed\n", __func__);
452 static int ab8500_charger_get_ac_current(
struct ab8500_charger *di)
457 if (di->
ac.charger_online) {
460 dev_err(di->
dev,
"%s gpadc conv failed\n", __func__);
479 if (di->
usb.charger_online) {
483 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
514 static int ab8500_charger_detect_chargers(
struct ab8500_charger *di)
524 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
535 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
559 switch (link_status) {
563 dev_dbg(di->
dev,
"USB Type - Standard host is "
564 "detected through USB driver\n");
603 di->
flags.vbus_collapse =
true;
604 dev_dbg(di->
dev,
"USB Type - USB_STAT_RESERVED "
605 "VBUS has collapsed\n");
611 dev_err(di->
dev,
"USB Type - Charging not allowed\n");
622 dev_dbg(di->
dev,
"USB Type - 0x%02x MaxCurr: %d",
635 static int ab8500_charger_read_usb_type(
struct ab8500_charger *di)
643 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
649 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
655 ret = ab8500_charger_max_usb_curr(di,
668 static int ab8500_charger_detect_usb_type(
struct ab8500_charger *di)
678 for (i = 0; i < 10; i++) {
684 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
690 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
704 ret = ab8500_charger_max_usb_curr(di,
714 static int ab8500_charger_voltage_map[] = {
799 static int ab8500_charger_current_map[] = {
821 static int ab8500_charger_vbus_in_curr_map[] = {
840 static int ab8500_voltage_to_regval(
int voltage)
845 if (voltage < ab8500_charger_voltage_map[0])
848 for (i = 1; i <
ARRAY_SIZE(ab8500_charger_voltage_map); i++) {
849 if (voltage < ab8500_charger_voltage_map[i])
854 i =
ARRAY_SIZE(ab8500_charger_voltage_map) - 1;
855 if (voltage == ab8500_charger_voltage_map[i])
861 static int ab8500_current_to_regval(
int curr)
865 if (curr < ab8500_charger_current_map[0])
868 for (i = 0; i <
ARRAY_SIZE(ab8500_charger_current_map); i++) {
869 if (curr < ab8500_charger_current_map[i])
874 i =
ARRAY_SIZE(ab8500_charger_current_map) - 1;
875 if (curr == ab8500_charger_current_map[i])
881 static int ab8500_vbus_in_curr_to_regval(
int curr)
885 if (curr < ab8500_charger_vbus_in_curr_map[0])
888 for (i = 0; i <
ARRAY_SIZE(ab8500_charger_vbus_in_curr_map); i++) {
889 if (curr < ab8500_charger_vbus_in_curr_map[i])
894 i =
ARRAY_SIZE(ab8500_charger_vbus_in_curr_map) - 1;
895 if (curr == ab8500_charger_vbus_in_curr_map[i])
944 static int ab8500_charger_set_vbus_in_curr(
struct ab8500_charger *di,
948 int input_curr_index;
952 min_value =
min(di->
bat->chg_params->usb_curr_max, ich_in);
967 input_curr_index = ab8500_vbus_in_curr_to_regval(min_value);
968 if (input_curr_index < 0) {
969 dev_err(di->
dev,
"VBUS input current limit too high\n");
977 dev_err(di->
dev,
"%s write failed\n", __func__);
990 static int ab8500_charger_led_en(
struct ab8500_charger *di,
int on)
1008 dev_err(di->
dev,
"Set LED PWM duty cycle failed\n");
1035 static int ab8500_charger_ac_en(
struct ux500_charger *charger,
1041 int input_curr_index;
1048 if (!di->
ac.charger_connected) {
1049 dev_err(di->
dev,
"AC charger not connected\n");
1054 dev_dbg(di->
dev,
"Enable AC: %dmV %dmA\n", vset, iset);
1072 volt_index = ab8500_voltage_to_regval(vset);
1073 curr_index = ab8500_current_to_regval(iset);
1074 input_curr_index = ab8500_current_to_regval(
1075 di->
bat->chg_params->ac_curr_max);
1076 if (volt_index < 0 || curr_index < 0 || input_curr_index < 0) {
1078 "Charger voltage or current too high, "
1079 "charging not started\n");
1087 dev_err(di->
dev,
"%s write failed\n", __func__);
1095 dev_err(di->
dev,
"%s write failed\n", __func__);
1102 dev_err(di->
dev,
"%s write failed\n", __func__);
1107 if (!di->
bat->enable_overshoot)
1114 dev_err(di->
dev,
"%s write failed\n", __func__);
1119 ret = ab8500_charger_led_en(di,
true);
1123 di->
ac.charger_online = 1;
1126 if (is_ab8500_1p1_or_earlier(di->
parent)) {
1155 "%s write failed\n", __func__);
1164 "%s write failed\n", __func__);
1173 "%s write failed\n", __func__);
1178 ret = ab8500_charger_led_en(di,
false);
1182 di->
ac.charger_online = 0;
1183 di->
ac.wd_expired =
false;
1191 dev_dbg(di->
dev,
"%s Disabled AC charging\n", __func__);
1193 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
1208 static int ab8500_charger_usb_en(
struct ux500_charger *charger,
1209 int enable,
int vset,
int ich_out)
1220 if (!di->
usb.charger_connected) {
1221 dev_err(di->
dev,
"USB charger not connected\n");
1241 dev_dbg(di->
dev,
"Enable USB: %dmV %dmA\n", vset, ich_out);
1244 volt_index = ab8500_voltage_to_regval(vset);
1245 curr_index = ab8500_current_to_regval(ich_out);
1246 if (volt_index < 0 || curr_index < 0) {
1248 "Charger voltage or current too high, "
1249 "charging not started\n");
1257 dev_err(di->
dev,
"%s write failed\n", __func__);
1263 dev_err(di->
dev,
"setting USBChInputCurr failed\n");
1270 dev_err(di->
dev,
"%s write failed\n", __func__);
1274 if (!di->
bat->enable_overshoot)
1281 dev_err(di->
dev,
"%s write failed\n", __func__);
1286 ret = ab8500_charger_led_en(di,
true);
1292 di->
usb.charger_online = 1;
1300 "%s write failed\n", __func__);
1304 ret = ab8500_charger_led_en(di,
false);
1308 di->
usb.charger_online = 0;
1309 di->
usb.wd_expired =
false;
1317 dev_dbg(di->
dev,
"%s Disabled USB charging\n", __func__);
1324 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1336 static int ab8500_charger_watchdog_kick(
struct ux500_charger *charger)
1363 static int ab8500_charger_update_charger_current(
struct ux500_charger *charger,
1377 curr_index = ab8500_current_to_regval(ich_out);
1378 if (curr_index < 0) {
1380 "Charger current too high, "
1381 "charging not started\n");
1388 dev_err(di->
dev,
"%s write failed\n", __func__);
1397 dev_err(di->
dev,
"%s write failed\n", __func__);
1404 static int ab8500_charger_get_ext_psy_data(
struct device *
dev,
void *
data)
1411 bool psy_found =
false;
1415 psy = &usb_chg->
psy;
1440 switch (ext->
type) {
1442 di->
vbat = ret.intval / 1000;
1471 &di->
usb_chg.psy, ab8500_charger_get_ext_psy_data);
1482 dev_dbg(di->
dev,
"Vbat did cross threshold, curr: %d, new: %d,"
1508 static void ab8500_charger_check_hw_failure_work(
struct work_struct *work)
1517 if (di->
flags.mainextchnotok) {
1521 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1525 di->
flags.mainextchnotok =
false;
1526 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
1529 if (di->
flags.vbus_ovv) {
1534 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1538 di->
flags.vbus_ovv =
false;
1539 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1543 if (di->
flags.mainextchnotok || di->
flags.vbus_ovv) {
1563 static void ab8500_charger_kick_watchdog_work(
struct work_struct *work)
1586 static void ab8500_charger_ac_work(
struct work_struct *work)
1598 ret = ab8500_charger_detect_chargers(di);
1603 di->
ac.charger_connected = 1;
1606 di->
ac.charger_connected = 0;
1609 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
1619 static void ab8500_charger_detect_usb_type_work(
struct work_struct *work)
1631 ret = ab8500_charger_detect_chargers(di);
1637 ab8500_charger_set_usb_connected(di,
false);
1638 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1642 if (is_ab8500_1p1_or_earlier(di->
parent)) {
1643 ret = ab8500_charger_detect_usb_type(di);
1645 ab8500_charger_set_usb_connected(di,
true);
1646 ab8500_power_supply_changed(di,
1658 ret = ab8500_charger_detect_usb_type(di);
1660 ab8500_charger_set_usb_connected(di,
1662 ab8500_power_supply_changed(di,
1676 static void ab8500_charger_usb_link_status_work(
struct work_struct *work)
1688 ret = ab8500_charger_detect_chargers(di);
1692 if (!(ret & USB_PW_CONN)) {
1694 ab8500_charger_set_usb_connected(di,
false);
1695 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1698 ret = ab8500_charger_read_usb_type(di);
1701 ret = ab8500_charger_set_vbus_in_curr(di,
1706 ab8500_charger_set_usb_connected(di,
true);
1707 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1708 }
else if (ret == -
ENXIO) {
1710 ab8500_charger_set_usb_connected(di,
false);
1711 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1716 static void ab8500_charger_usb_state_changed_work(
struct work_struct *work)
1719 unsigned long flags;
1729 spin_unlock_irqrestore(&di->
usb_state.usb_lock, flags);
1740 dev_dbg(di->
dev,
"%s USB state: 0x%02x mA: %d\n",
1748 ab8500_charger_set_usb_connected(di,
false);
1749 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1764 if (!ab8500_charger_get_usb_cur(di)) {
1766 ret = ab8500_charger_set_vbus_in_curr(di,
1771 ab8500_charger_set_usb_connected(di,
true);
1772 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1787 static void ab8500_charger_check_usbchargernotok_work(
struct work_struct *work)
1800 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1803 prev_status = di->
flags.usbchargernotok;
1806 di->
flags.usbchargernotok =
true;
1811 di->
flags.usbchargernotok =
false;
1812 di->
flags.vbus_collapse =
false;
1815 if (prev_status != di->
flags.usbchargernotok)
1816 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1825 static void ab8500_charger_check_main_thermal_prot_work(
1838 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1842 di->
flags.main_thermal_prot =
true;
1844 di->
flags.main_thermal_prot =
false;
1846 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
1855 static void ab8500_charger_check_usb_thermal_prot_work(
1868 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1872 di->
flags.usb_thermal_prot =
true;
1874 di->
flags.usb_thermal_prot =
false;
1876 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
1886 static irqreturn_t ab8500_charger_mainchunplugdet_handler(
int irq,
void *_di)
1890 dev_dbg(di->
dev,
"Main charger unplugged\n");
1903 static irqreturn_t ab8500_charger_mainchplugdet_handler(
int irq,
void *_di)
1920 static irqreturn_t ab8500_charger_mainextchnotok_handler(
int irq,
void *_di)
1925 di->
flags.mainextchnotok =
true;
1926 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
1942 static irqreturn_t ab8500_charger_mainchthprotr_handler(
int irq,
void *_di)
1947 "Die temp above Main charger thermal protection threshold\n");
1961 static irqreturn_t ab8500_charger_mainchthprotf_handler(
int irq,
void *_di)
1966 "Die temp ok for Main charger thermal protection threshold\n");
1979 static irqreturn_t ab8500_charger_vbusdetf_handler(
int irq,
void *_di)
1996 static irqreturn_t ab8500_charger_vbusdetr_handler(
int irq,
void *_di)
2014 static irqreturn_t ab8500_charger_usblinkstatus_handler(
int irq,
void *_di)
2018 dev_dbg(di->
dev,
"USB link status changed\n");
2033 static irqreturn_t ab8500_charger_usbchthprotr_handler(
int irq,
void *_di)
2038 "Die temp above USB charger thermal protection threshold\n");
2052 static irqreturn_t ab8500_charger_usbchthprotf_handler(
int irq,
void *_di)
2057 "Die temp ok for USB charger thermal protection threshold\n");
2070 static irqreturn_t ab8500_charger_usbchargernotokr_handler(
int irq,
void *_di)
2074 dev_dbg(di->
dev,
"Not allowed USB charger detected\n");
2087 static irqreturn_t ab8500_charger_chwdexp_handler(
int irq,
void *_di)
2091 dev_dbg(di->
dev,
"Charger watchdog expired\n");
2097 if (di->
ac.charger_online) {
2098 di->
ac.wd_expired =
true;
2099 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
2101 if (di->
usb.charger_online) {
2102 di->
usb.wd_expired =
true;
2103 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
2116 static irqreturn_t ab8500_charger_vbusovv_handler(
int irq,
void *_di)
2120 dev_dbg(di->
dev,
"VBUS overvoltage detected\n");
2121 di->
flags.vbus_ovv =
true;
2122 ab8500_power_supply_changed(di, &di->
usb_chg.psy);
2144 static int ab8500_charger_ac_get_property(
struct power_supply *psy,
2154 if (di->
flags.mainextchnotok)
2156 else if (di->
ac.wd_expired || di->
usb.wd_expired)
2158 else if (di->
flags.main_thermal_prot)
2164 val->
intval = di->
ac.charger_online;
2167 val->
intval = di->
ac.charger_connected;
2170 di->
ac.charger_voltage = ab8500_charger_get_ac_voltage(di);
2171 val->
intval = di->
ac.charger_voltage * 1000;
2178 di->
ac.cv_active = ab8500_charger_ac_cv(di);
2182 val->
intval = ab8500_charger_get_ac_current(di) * 1000;
2204 static int ab8500_charger_usb_get_property(
struct power_supply *psy,
2214 if (di->
flags.usbchargernotok)
2216 else if (di->
ac.wd_expired || di->
usb.wd_expired)
2218 else if (di->
flags.usb_thermal_prot)
2220 else if (di->
flags.vbus_ovv)
2229 val->
intval = di->
usb.charger_connected;
2232 di->
usb.charger_voltage = ab8500_charger_get_vbus_voltage(di);
2233 val->
intval = di->
usb.charger_voltage * 1000;
2240 di->
usb.cv_active = ab8500_charger_usb_cv(di);
2244 val->
intval = ab8500_charger_get_usb_current(di) * 1000;
2251 if (di->
flags.vbus_collapse)
2269 static int ab8500_charger_init_hw_registers(
struct ab8500_charger *di)
2274 if (!is_ab8500_1p1_or_earlier(di->
parent)) {
2280 "failed to set CH_VOLT_LVL_MAX_REG\n");
2289 "failed to set CH_OPT_CRNTLVL_MAX_REG\n");
2300 dev_err(di->
dev,
"failed to set VBUS OVV\n");
2308 dev_err(di->
dev,
"failed to enable main WD in OTP\n");
2317 dev_err(di->
dev,
"faile to enable main watchdog\n");
2335 dev_err(di->
dev,
"failed to kick main watchdog\n");
2344 dev_err(di->
dev,
"failed to disable main watchdog\n");
2352 dev_err(di->
dev,
"failed to set charger watchdog timeout\n");
2360 di->
bat->bkup_bat_v |
2361 di->
bat->bkup_bat_i);
2363 dev_err(di->
dev,
"failed to setup backup battery charging\n");
2372 dev_err(di->
dev,
"%s mask and set failed\n", __func__);
2382 {
"MAIN_CH_UNPLUG_DET", ab8500_charger_mainchunplugdet_handler},
2383 {
"MAIN_CHARGE_PLUG_DET", ab8500_charger_mainchplugdet_handler},
2384 {
"MAIN_EXT_CH_NOT_OK", ab8500_charger_mainextchnotok_handler},
2385 {
"MAIN_CH_TH_PROT_R", ab8500_charger_mainchthprotr_handler},
2386 {
"MAIN_CH_TH_PROT_F", ab8500_charger_mainchthprotf_handler},
2387 {
"VBUS_DET_F", ab8500_charger_vbusdetf_handler},
2388 {
"VBUS_DET_R", ab8500_charger_vbusdetr_handler},
2389 {
"USB_LINK_STATUS", ab8500_charger_usblinkstatus_handler},
2390 {
"USB_CH_TH_PROT_R", ab8500_charger_usbchthprotr_handler},
2391 {
"USB_CH_TH_PROT_F", ab8500_charger_usbchthprotf_handler},
2392 {
"USB_CHARGER_NOT_OKR", ab8500_charger_usbchargernotokr_handler},
2393 {
"VBUS_OVV", ab8500_charger_vbusovv_handler},
2394 {
"CH_WD_EXP", ab8500_charger_chwdexp_handler},
2397 static int ab8500_charger_usb_notifier_call(
struct notifier_block *nb,
2398 unsigned long event,
void *power)
2403 unsigned mA = *((
unsigned *)power);
2406 dev_dbg(di->
dev,
"not a standard host, returning\n");
2413 if ((di->
usb_state.usb_current == 2) && (mA > 2))
2424 dev_dbg(di->
dev,
"%s usb_state: 0x%02x mA: %d\n",
2425 __func__, bm_usb_state, mA);
2439 #if defined(CONFIG_PM)
2469 if (di->
flags.mainextchnotok || di->
flags.vbus_ovv) {
2489 #define ab8500_charger_suspend NULL
2490 #define ab8500_charger_resume NULL
2499 ab8500_charger_ac_en(&di->
ac_chg,
false, 0, 0);
2502 ab8500_charger_usb_en(&di->
usb_chg,
false, 0, 0);
2505 for (i = 0; i <
ARRAY_SIZE(ab8500_charger_irq); i++) {
2517 dev_err(di->
dev,
"%s mask and set failed\n", __func__);
2519 usb_unregister_notifier(di->
usb_phy, &di->
nb);
2528 platform_set_drvdata(pdev,
NULL);
2536 int irq,
i, charger_status, ret = 0;
2560 dev_err(di->
dev,
"no charger platform data supplied\n");
2562 goto free_device_info;
2568 dev_err(di->
dev,
"no battery platform data supplied\n");
2570 goto free_device_info;
2577 di->
ac_chg.psy.name =
"ab8500_ac";
2579 di->
ac_chg.psy.properties = ab8500_charger_ac_props;
2581 di->
ac_chg.psy.get_property = ab8500_charger_ac_get_property;
2582 di->
ac_chg.psy.supplied_to = di->
pdata->supplied_to;
2583 di->
ac_chg.psy.num_supplicants = di->
pdata->num_supplicants;
2585 di->
ac_chg.ops.enable = &ab8500_charger_ac_en;
2586 di->
ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
2587 di->
ac_chg.ops.update_curr = &ab8500_charger_update_charger_current;
2588 di->
ac_chg.max_out_volt = ab8500_charger_voltage_map[
2590 di->
ac_chg.max_out_curr = ab8500_charger_current_map[
2595 di->
usb_chg.psy.name =
"ab8500_usb";
2597 di->
usb_chg.psy.properties = ab8500_charger_usb_props;
2599 di->
usb_chg.psy.get_property = ab8500_charger_usb_get_property;
2601 di->
usb_chg.psy.num_supplicants = di->
pdata->num_supplicants;
2603 di->
usb_chg.ops.enable = &ab8500_charger_usb_en;
2604 di->
usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
2605 di->
usb_chg.ops.update_curr = &ab8500_charger_update_charger_current;
2606 di->
usb_chg.max_out_volt = ab8500_charger_voltage_map[
2608 di->
usb_chg.max_out_curr = ab8500_charger_current_map[
2616 dev_err(di->
dev,
"failed to create work queue\n");
2618 goto free_device_info;
2623 ab8500_charger_check_hw_failure_work);
2625 ab8500_charger_check_usbchargernotok_work);
2637 ab8500_charger_kick_watchdog_work);
2640 ab8500_charger_check_vbat_work);
2644 ab8500_charger_usb_link_status_work);
2647 ab8500_charger_detect_usb_type_work);
2650 ab8500_charger_usb_state_changed_work);
2654 ab8500_charger_check_main_thermal_prot_work);
2656 ab8500_charger_check_usb_thermal_prot_work);
2664 if (IS_ERR(di->
regu)) {
2665 ret = PTR_ERR(di->
regu);
2666 dev_err(di->
dev,
"failed to get vddadc regulator\n");
2667 goto free_charger_wq;
2672 ret = ab8500_charger_init_hw_registers(di);
2674 dev_err(di->
dev,
"failed to initialize ABB registers\n");
2675 goto free_regulator;
2681 dev_err(di->
dev,
"failed to register AC charger\n");
2682 goto free_regulator;
2688 dev_err(di->
dev,
"failed to register USB charger\n");
2693 if (IS_ERR_OR_NULL(di->
usb_phy)) {
2694 dev_err(di->
dev,
"failed to get usb transceiver\n");
2698 di->
nb.notifier_call = ab8500_charger_usb_notifier_call;
2699 ret = usb_register_notifier(di->
usb_phy, &di->
nb);
2701 dev_err(di->
dev,
"failed to register usb notifier\n");
2706 charger_status = ab8500_charger_detect_chargers(di);
2708 di->
ac.charger_connected = 1;
2710 ab8500_power_supply_changed(di, &di->
ac_chg.psy);
2714 if (charger_status & USB_PW_CONN) {
2715 dev_dbg(di->
dev,
"VBUS Detect during startup\n");
2723 for (i = 0; i <
ARRAY_SIZE(ab8500_charger_irq); i++) {
2727 ab8500_charger_irq[i].
name, di);
2730 dev_err(di->
dev,
"failed to request %s IRQ %d: %d\n"
2731 , ab8500_charger_irq[i].
name, irq, ret);
2734 dev_dbg(di->
dev,
"Requested %s IRQ %d: %d\n",
2735 ab8500_charger_irq[i].
name, irq, ret);
2738 platform_set_drvdata(pdev, di);
2743 usb_unregister_notifier(di->
usb_phy, &di->
nb);
2746 for (i = i - 1; i >= 0; i--) {
2767 .probe = ab8500_charger_probe,
2772 .name =
"ab8500-charger",
2777 static int __init ab8500_charger_init(
void)
2782 static void __exit ab8500_charger_exit(
void)
2791 MODULE_AUTHOR(
"Johan Palsson, Karl Komierowski, Arun R Murthy");