+extern int dwc_vbus_status(void);
+
+static void usb_detect_work_func(struct work_struct *work)
+{
+ struct delayed_work *delayed_work = (struct delayed_work *)container_of(work, struct delayed_work, work);
+ struct rt5025_power_info *pi = (struct rt5025_power_info *)container_of(delayed_work, struct rt5025_power_info, usb_detect_work);
+
+ pr_info("rt5025: %s ++", __func__);
+
+ mutex_lock(&pi->var_lock);
+ if (pi->ac_online)
+ {
+ rt5025_set_charging_current(pi->i2c, 1000);
+ pi->usb_cnt = 0;
+ }
+ else if (pi->usb_online)
+ {
+ pr_info("%s: usb_cnt %d\n", __func__, pi->usb_cnt);
+ switch(dwc_vbus_status())
+ {
+ case 2: // USB Wall charger
+ rt5025_set_charging_current(pi->i2c, 1000);
+ pr_info("rt5025: detect usb wall charger\n");
+ break;
+ case 1: //normal USB
+ default:
+ rt5025_set_charging_current(pi->i2c, 500);
+ pr_info("rt5025: detect normal usb\n");
+ break;
+ }
+ if (pi->usb_cnt++ < 60)
+ schedule_delayed_work(&pi->usb_detect_work, 1*HZ);
+ }
+ else
+ {
+ //default to prevent over current charging
+ rt5025_set_charging_current(pi->i2c, 500);
+ //reset usb_cnt;
+ pi->usb_cnt = 0;
+ }
+ mutex_unlock(&pi->var_lock);
+
+ pr_info("rt5025: %s --", __func__);
+}
+