mfd: fusb302: ignored the timeout if vdm got the message.
authorzain wang <wzz@rock-chips.com>
Wed, 10 May 2017 03:21:30 +0000 (11:21 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Thu, 11 May 2017 07:34:17 +0000 (15:34 +0800)
The PD spec define the source should ensure that a message requesting
a response is responded within 30ms(tSenderResponse). But if the
message responded is received close to 30ms, we may hit the case:

tcpm_get_message(); //get the data and close to 30ms
... takes about 600us, meanwhile the 30ms timer came.
auto_vdm_machine
vdm_send... //we get the message, but timeout.

So, let's ignored the timeout if we get the message.

Change-Id: I64ced1bd2d32d8ef996dcec27cf35c3e333386f8
Signed-off-by: zain wang <wzz@rock-chips.com>
drivers/mfd/fusb302.c

index 53b236b1dc0dd5d148210f3dc8af05a8bf3aaa43..aea504bbce32f59375b6d8b2e94d27ddb700d8f3 100644 (file)
@@ -1129,16 +1129,15 @@ static int vdm_send_discoveryid(struct fusb30x_chip *chip, int evt)
                if (chip->vdm_send_state != 2)
                        break;
        default:
-               if (evt & EVENT_TIMER_STATE) {
+               if (chip->vdm_id) {
+                       chip->vdm_send_state = 0;
+                       return 0;
+               } else if (evt & EVENT_TIMER_STATE) {
                        dev_warn(chip->dev, "VDM_DISCOVERY_ID time out\n");
                        chip->vdm_state = 0xff;
                        chip->work_continue = 1;
                }
-
-               if (!chip->vdm_id)
-                       break;
-               chip->vdm_send_state = 0;
-               return 0;
+               break;
        }
        return -EINPROGRESS;
 }
@@ -1170,16 +1169,15 @@ static int vdm_send_discoverysvid(struct fusb30x_chip *chip, int evt)
                if (chip->vdm_send_state != 2)
                        break;
        default:
-               if (evt & EVENT_TIMER_STATE) {
+               if (chip->vdm_svid_num) {
+                       chip->vdm_send_state = 0;
+                       return 0;
+               } else if (evt & EVENT_TIMER_STATE) {
                        dev_warn(chip->dev, "VDM_DISCOVERY_SVIDS time out\n");
                        chip->vdm_state = 0xff;
                        chip->work_continue = 1;
                }
-
-               if (!chip->vdm_svid_num)
-                       break;
-               chip->vdm_send_state = 0;
-               return 0;
+               break;
        }
        return -EINPROGRESS;
 }
@@ -1211,19 +1209,17 @@ static int vdm_send_discoverymodes(struct fusb30x_chip *chip, int evt)
                        if (chip->vdm_send_state != 2)
                                break;
                default:
-                       if (evt & EVENT_TIMER_STATE) {
+                       if (chip->val_tmp & 1) {
+                               chip->val_tmp &= 0xfe;
+                               chip->val_tmp += 2;
+                               chip->vdm_send_state = 0;
+                               chip->work_continue = 1;
+                       } else if (evt & EVENT_TIMER_STATE) {
                                dev_warn(chip->dev,
                                         "VDM_DISCOVERY_MODES time out\n");
                                chip->vdm_state = 0xff;
                                chip->work_continue = 1;
                        }
-
-                       if (!(chip->val_tmp & 1))
-                               break;
-                       chip->val_tmp &= 0xfe;
-                       chip->val_tmp += 2;
-                       chip->vdm_send_state = 0;
-                       chip->work_continue = 1;
                        break;
                }
        } else {
@@ -1260,17 +1256,16 @@ static int vdm_send_entermode(struct fusb30x_chip *chip, int evt)
                if (chip->vdm_send_state != 2)
                        break;
        default:
-               if (evt & EVENT_TIMER_STATE) {
+               if (chip->val_tmp) {
+                       chip->val_tmp = 0;
+                       chip->vdm_send_state = 0;
+                       return 0;
+               } else if (evt & EVENT_TIMER_STATE) {
                        dev_warn(chip->dev, "VDM_ENTER_MODE time out\n");
                        chip->vdm_state = 0xff;
                        chip->work_continue = 1;
                }
-
-               if (!chip->val_tmp)
-                       break;
-               chip->val_tmp = 0;
-               chip->vdm_send_state = 0;
-               return 0;
+               break;
        }
        return -EINPROGRESS;
 }
@@ -1301,17 +1296,16 @@ static int vdm_send_getdpstatus(struct fusb30x_chip *chip, int evt)
                if (chip->vdm_send_state != 2)
                        break;
        default:
-               if (evt & EVENT_TIMER_STATE) {
+               if (chip->val_tmp) {
+                       chip->val_tmp = 0;
+                       chip->vdm_send_state = 0;
+                       return 0;
+               } else if (evt & EVENT_TIMER_STATE) {
                        dev_warn(chip->dev, "VDM_DP_STATUS_UPDATE time out\n");
                        chip->vdm_state = 0xff;
                        chip->work_continue = 1;
                }
-
-               if (!chip->val_tmp)
-                       break;
-               chip->val_tmp = 0;
-               chip->vdm_send_state = 0;
-               return 0;
+               break;
        }
        return -EINPROGRESS;
 }
@@ -1341,17 +1335,16 @@ static int vdm_send_dpconfig(struct fusb30x_chip *chip, int evt)
                if (chip->vdm_send_state != 2)
                        break;
        default:
-               if (evt & EVENT_TIMER_STATE) {
+               if (chip->val_tmp) {
+                       chip->val_tmp = 0;
+                       chip->vdm_send_state = 0;
+                       return 0;
+               } else if (evt & EVENT_TIMER_STATE) {
                        dev_warn(chip->dev, "vdm_send_dpconfig time out\n");
                        chip->vdm_state = 0xff;
                        chip->work_continue = 1;
                }
-
-               if (!chip->val_tmp)
-                       break;
-               chip->val_tmp = 0;
-               chip->vdm_send_state = 0;
-               return 0;
+               break;
        }
        return -EINPROGRESS;
 }