From: wlf Date: Mon, 23 Jun 2014 09:46:59 +0000 (+0800) Subject: USB: Fix usb battery charger detect bug. X-Git-Tag: firefly_0821_release~5061 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9e0ae71d8d3061eed7d174f5febb21549635a34d;p=firefly-linux-kernel-4.4.55.git USB: Fix usb battery charger detect bug. In some case, if usb connect with otg cable, and set OTG_VBUS_DRV high to output 5V,it will lead to usb bc detecting wrongly. Check otg_id to avoid this bug. --- diff --git a/arch/arm/boot/dts/rk3188.dtsi b/arch/arm/boot/dts/rk3188.dtsi index 3a04341acee7..28a7d6c45f39 100755 --- a/arch/arm/boot/dts/rk3188.dtsi +++ b/arch/arm/boot/dts/rk3188.dtsi @@ -739,6 +739,7 @@ usb_bc{ compatible = "rockchip,ctrl"; rk_usb,bvalid = <0xac 10 1>; + rk_usb,iddig = <0xac 13 1>; rk_usb,line = <0xac 11 2>; rk_usb,softctrl = <0x114 2 1>; rk_usb,opmode = <0x118 1 2>; diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi index ae7e2c11a1ef..7921181153b3 100755 --- a/arch/arm/boot/dts/rk3288.dtsi +++ b/arch/arm/boot/dts/rk3288.dtsi @@ -1042,6 +1042,7 @@ compatible = "synopsys,phy"; /* offset bit mask */ rk_usb,bvalid = <0x288 14 1>; + rk_usb,iddig = <0x288 17 1>; rk_usb,dcdenb = <0x328 14 1>; rk_usb,vdatsrcenb = <0x328 7 1>; rk_usb,vdatdetenb = <0x328 6 1>; diff --git a/drivers/usb/dwc_otg_310/usbdev_bc.c b/drivers/usb/dwc_otg_310/usbdev_bc.c index d7443add91b6..ad382069033e 100755 --- a/drivers/usb/dwc_otg_310/usbdev_bc.c +++ b/drivers/usb/dwc_otg_310/usbdev_bc.c @@ -69,6 +69,7 @@ static inline void uoc_init_synop(struct device_node *np) GFP_ATOMIC); uoc_init_field(np, "rk_usb,bvalid", &pBC_UOC_FIELDS[SYNOP_BC_BVALID]); + uoc_init_field(np, "rk_usb,iddig", &pBC_UOC_FIELDS[SYNOP_BC_IDDIG]); uoc_init_field(np, "rk_usb,dcdenb", &pBC_UOC_FIELDS[SYNOP_BC_DCDENB]); uoc_init_field(np, "rk_usb,vdatsrcenb", &pBC_UOC_FIELDS[SYNOP_BC_VDATSRCENB]); @@ -88,6 +89,7 @@ static inline void uoc_init_rk(struct device_node *np) GFP_ATOMIC); uoc_init_field(np, "rk_usb,bvalid", &pBC_UOC_FIELDS[RK_BC_BVALID]); + uoc_init_field(np, "rk_usb,iddig", &pBC_UOC_FIELDS[RK_BC_IDDIG]); uoc_init_field(np, "rk_usb,line", &pBC_UOC_FIELDS[RK_BC_LINESTATE]); uoc_init_field(np, "rk_usb,softctrl", &pBC_UOC_FIELDS[RK_BC_SOFTCTRL]); uoc_init_field(np, "rk_usb,opmode", &pBC_UOC_FIELDS[RK_BC_OPMODE]); @@ -107,7 +109,8 @@ int usb_battery_charger_detect_rk(bool wait) int port_type = USB_BC_TYPE_DISCNT; - if (BC_GET(RK_BC_BVALID)) { + if (BC_GET(RK_BC_BVALID) && + BC_GET(RK_BC_IDDIG)) { mdelay(10); BC_SET(RK_BC_SOFTCTRL, 1); BC_SET(RK_BC_OPMODE, 0); @@ -149,10 +152,12 @@ int usb_battery_charger_detect_inno(bool wait) int usb_battery_charger_detect_synop(bool wait) { int port_type = USB_BC_TYPE_DISCNT; - int dcd_state; + int dcd_state = DCD_POSITIVE; int timeout = 0, i = 0; + /* VBUS Valid detect */ - if (BC_GET(SYNOP_BC_BVALID)) { + if (BC_GET(SYNOP_BC_BVALID) && + BC_GET(SYNOP_BC_IDDIG)) { if (wait) { /* Do DCD */ dcd_state = DCD_TIMEOUT; @@ -264,13 +269,15 @@ int dwc_otg_check_dpdm(bool wait) if (of_device_is_compatible(np, "rockchip,ctrl")) { if (!pBC_UOC_FIELDS) uoc_init_rk(np); - if (!BC_GET(RK_BC_BVALID)) + if (!BC_GET(RK_BC_BVALID) || + !BC_GET(RK_BC_IDDIG)) rk_usb_charger_status = USB_BC_TYPE_DISCNT; } else if (of_device_is_compatible(np, "synopsys,phy")) { if (!pBC_UOC_FIELDS) uoc_init_synop(np); - if (!BC_GET(SYNOP_BC_BVALID)) + if (!BC_GET(SYNOP_BC_BVALID) || + !BC_GET(SYNOP_BC_IDDIG)) rk_usb_charger_status = USB_BC_TYPE_DISCNT; } else if (of_device_is_compatible(np, "inno,phy")) { diff --git a/drivers/usb/dwc_otg_310/usbdev_bc.h b/drivers/usb/dwc_otg_310/usbdev_bc.h index 0299c625b89e..dff942c2c70e 100644 --- a/drivers/usb/dwc_otg_310/usbdev_bc.h +++ b/drivers/usb/dwc_otg_310/usbdev_bc.h @@ -10,6 +10,7 @@ enum { SYNOP_BC_BVALID = 0, + SYNOP_BC_IDDIG, SYNOP_BC_DCDENB, SYNOP_BC_VDATSRCENB, SYNOP_BC_VDATDETENB, @@ -22,6 +23,7 @@ enum { enum { RK_BC_BVALID = 0, + RK_BC_IDDIG, RK_BC_LINESTATE, RK_BC_SOFTCTRL, RK_BC_OPMODE,