By default the driver sets the retry count to 3 (Default for PD 2.0).
Update this to 2, if the negotiated rev is PD 3.0.

Signed-off-by: Badhri Jagan Sridharan <bad...@google.com>
---
 drivers/usb/typec/tcpm/fusb302.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index 99562cc65ca6..ebc46b9f776c 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -343,12 +343,11 @@ static int fusb302_sw_reset(struct fusb302_chip *chip)
        return ret;
 }
 
-static int fusb302_enable_tx_auto_retries(struct fusb302_chip *chip)
+static int fusb302_enable_tx_auto_retries(struct fusb302_chip *chip, u8 
retry_count)
 {
        int ret = 0;
 
-       ret = fusb302_i2c_set_bits(chip, FUSB_REG_CONTROL3,
-                                  FUSB_REG_CONTROL3_N_RETRIES_3 |
+       ret = fusb302_i2c_set_bits(chip, FUSB_REG_CONTROL3, retry_count |
                                   FUSB_REG_CONTROL3_AUTO_RETRY);
 
        return ret;
@@ -399,7 +398,7 @@ static int tcpm_init(struct tcpc_dev *dev)
        ret = fusb302_sw_reset(chip);
        if (ret < 0)
                return ret;
-       ret = fusb302_enable_tx_auto_retries(chip);
+       ret = fusb302_enable_tx_auto_retries(chip, 
FUSB_REG_CONTROL3_N_RETRIES_3);
        if (ret < 0)
                return ret;
        ret = fusb302_init_interrupt(chip);
@@ -1017,7 +1016,7 @@ static const char * const transmit_type_name[] = {
 };
 
 static int tcpm_pd_transmit(struct tcpc_dev *dev, enum tcpm_transmit_type type,
-                           const struct pd_message *msg)
+                           const struct pd_message *msg, unsigned int 
negotiated_rev)
 {
        struct fusb302_chip *chip = container_of(dev, struct fusb302_chip,
                                                 tcpc_dev);
@@ -1026,6 +1025,13 @@ static int tcpm_pd_transmit(struct tcpc_dev *dev, enum 
tcpm_transmit_type type,
        mutex_lock(&chip->lock);
        switch (type) {
        case TCPC_TX_SOP:
+               /* nRetryCount 3 in P2.0 spec, whereas 2 in PD3.0 spec */
+               ret = fusb302_enable_tx_auto_retries(chip, negotiated_rev > 
PD_REV20 ?
+                                                    
FUSB_REG_CONTROL3_N_RETRIES_2 :
+                                                    
FUSB_REG_CONTROL3_N_RETRIES_3);
+               if (ret < 0)
+                       fusb302_log(chip, "Cannot update retry count ret=%d", 
ret);
+
                ret = fusb302_pd_send_message(chip, msg);
                if (ret < 0)
                        fusb302_log(chip,
-- 
2.29.2.454.gaff20da3a2-goog

Reply via email to