USB: Fix usb battery charger detect bug.
authorwlf <wulf@rock-chips.com>
Mon, 23 Jun 2014 09:46:59 +0000 (17:46 +0800)
committerwlf <wulf@rock-chips.com>
Mon, 23 Jun 2014 09:46:59 +0000 (17:46 +0800)
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.

arch/arm/boot/dts/rk3188.dtsi
arch/arm/boot/dts/rk3288.dtsi
drivers/usb/dwc_otg_310/usbdev_bc.c
drivers/usb/dwc_otg_310/usbdev_bc.h

index 3a04341acee7b00b6b05e034077d24205ca33085..28a7d6c45f3927ee1e9f2d4a2242e5672a8dd486 100755 (executable)
                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>;
index ae7e2c11a1ef4b7434fe1f75dea713f0d80f26a7..7921181153b35b4110fe591219a045a32872145f 100755 (executable)
                        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>;
index d7443add91b6f05a3b13eb9a81d1b4ad5c87ec8d..ad382069033e8f79fd66117e10e0c8ba73cbfba8 100755 (executable)
@@ -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")) {
index 0299c625b89e24f9149f7c206896d85aa22b20c7..dff942c2c70e4ab53e52b57b8fc97550bd749c10 100644 (file)
@@ -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,