All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count
@ 2020-12-01  4:22 Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 2/4] usb: typec: fusb302: Update retry count based on the negotiated rev Badhri Jagan Sridharan
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-01  4:22 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

nRetryCount was updated from 3 to 2 between PD2.0 and PD3.0 spec.
nRetryCount in "Table 6-34 Counter parameters" of the PD 2.0
spec is set to 3, whereas, nRetryCount in "Table 6-59 Counter
parameters" is set to 2.

Pass down negotiated rev in pd_transmit so that low level chip
drivers can update the retry count accordingly before attempting
packet transmission.

This helps in passing "TEST.PD.PORT.ALL.02" of the
"Power Delivery Merged" test suite which was initially failing
with "The UUT did not retransmit the message nReryCount times"

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 2 +-
 include/linux/usb/tcpm.h      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 3bbc1f10af49..c73bc3a8356a 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -667,7 +667,7 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
 		tcpm_log(port, "PD TX, type: %#x", type);
 
 	reinit_completion(&port->tx_complete);
-	ret = port->tcpc->pd_transmit(port->tcpc, type, msg);
+	ret = port->tcpc->pd_transmit(port->tcpc, type, msg, port->negotiated_rev);
 	if (ret < 0)
 		return ret;
 
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index e68aaa12886f..efaedd7e8a18 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -121,7 +121,7 @@ struct tcpc_dev {
 			      enum typec_cc_status cc);
 	int (*try_role)(struct tcpc_dev *dev, int role);
 	int (*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);
 	int (*set_bist_data)(struct tcpc_dev *dev, bool on);
 	int (*enable_frs)(struct tcpc_dev *dev, bool enable);
 	void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/4] usb: typec: fusb302: Update retry count based on the negotiated rev
  2020-12-01  4:22 [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Badhri Jagan Sridharan
@ 2020-12-01  4:22 ` Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 3/4] usb: typec: tcpci: " Badhri Jagan Sridharan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-01  4:22 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

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 <badhri@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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 3/4] usb: typec: tcpci: Update retry count based on the negotiated rev
  2020-12-01  4:22 [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 2/4] usb: typec: fusb302: Update retry count based on the negotiated rev Badhri Jagan Sridharan
@ 2020-12-01  4:22 ` Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 4/4] usb: typec: wcove: Update wcove_pd_transmit to include negoitated rev Badhri Jagan Sridharan
  2020-12-01 10:31 ` [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Heikki Krogerus
  3 siblings, 0 replies; 6+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-01  4:22 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

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 <badhri@google.com>
---
 drivers/usb/typec/tcpm/tcpci.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 12d983a75510..98a2455f779f 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -18,7 +18,8 @@
 
 #include "tcpci.h"
 
-#define	PD_RETRY_COUNT				3
+#define	PD_RETRY_COUNT_DEFAULT			3
+#define	PD_RETRY_COUNT_3_0_OR_HIGHER		2
 #define	AUTO_DISCHARGE_DEFAULT_THRESHOLD_MV	3500
 #define	AUTO_DISCHARGE_PD_HEADROOM_MV		850
 #define	AUTO_DISCHARGE_PPS_HEADROOM_MV		1250
@@ -447,9 +448,8 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)
 	return 0;
 }
 
-static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
-			     enum tcpm_transmit_type type,
-			     const struct pd_message *msg)
+static int tcpci_pd_transmit(struct tcpc_dev *tcpc, enum tcpm_transmit_type type,
+			     const struct pd_message *msg, unsigned int negotiated_rev)
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 	u16 header = msg ? le16_to_cpu(msg->header) : 0;
@@ -497,7 +497,9 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
 		}
 	}
 
-	reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) | (type << TCPC_TRANSMIT_TYPE_SHIFT);
+	/* nRetryCount is 3 in PD2.0 spec where 2 in PD3.0 spec */
+	reg = ((negotiated_rev > PD_REV20 ? PD_RETRY_COUNT_3_0_OR_HIGHER : PD_RETRY_COUNT_DEFAULT)
+	       << TCPC_TRANSMIT_RETRY_SHIFT) | (type << TCPC_TRANSMIT_TYPE_SHIFT);
 	ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg);
 	if (ret < 0)
 		return ret;
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 4/4] usb: typec: wcove: Update wcove_pd_transmit to include negoitated rev
  2020-12-01  4:22 [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 2/4] usb: typec: fusb302: Update retry count based on the negotiated rev Badhri Jagan Sridharan
  2020-12-01  4:22 ` [PATCH v1 3/4] usb: typec: tcpci: " Badhri Jagan Sridharan
@ 2020-12-01  4:22 ` Badhri Jagan Sridharan
  2020-12-01 10:31 ` [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Heikki Krogerus
  3 siblings, 0 replies; 6+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-01  4:22 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

pd_transmit callback now passes down negotiated_rev to set retry
count accordingly if needed.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/typec/tcpm/wcove.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
index 9b745f432c91..79ae63950050 100644
--- a/drivers/usb/typec/tcpm/wcove.c
+++ b/drivers/usb/typec/tcpm/wcove.c
@@ -356,7 +356,8 @@ static int wcove_set_pd_rx(struct tcpc_dev *tcpc, bool on)
 
 static int wcove_pd_transmit(struct tcpc_dev *tcpc,
 			     enum tcpm_transmit_type type,
-			     const struct pd_message *msg)
+			     const struct pd_message *msg,
+			     unsigned int negotiated_rev)
 {
 	struct wcove_typec *wcove = tcpc_to_wcove(tcpc);
 	unsigned int info = 0;
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count
  2020-12-01  4:22 [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Badhri Jagan Sridharan
                   ` (2 preceding siblings ...)
  2020-12-01  4:22 ` [PATCH v1 4/4] usb: typec: wcove: Update wcove_pd_transmit to include negoitated rev Badhri Jagan Sridharan
@ 2020-12-01 10:31 ` Heikki Krogerus
  2020-12-02  3:18   ` Badhri Jagan Sridharan
  3 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2020-12-01 10:31 UTC (permalink / raw)
  To: Badhri Jagan Sridharan
  Cc: Guenter Roeck, Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 30, 2020 at 08:22:34PM -0800, Badhri Jagan Sridharan wrote:
> nRetryCount was updated from 3 to 2 between PD2.0 and PD3.0 spec.
> nRetryCount in "Table 6-34 Counter parameters" of the PD 2.0
> spec is set to 3, whereas, nRetryCount in "Table 6-59 Counter
> parameters" is set to 2.
> 
> Pass down negotiated rev in pd_transmit so that low level chip
> drivers can update the retry count accordingly before attempting
> packet transmission.
> 
> This helps in passing "TEST.PD.PORT.ALL.02" of the
> "Power Delivery Merged" test suite which was initially failing
> with "The UUT did not retransmit the message nReryCount times"
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 2 +-
>  include/linux/usb/tcpm.h      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 3bbc1f10af49..c73bc3a8356a 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -667,7 +667,7 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
>  		tcpm_log(port, "PD TX, type: %#x", type);
>  
>  	reinit_completion(&port->tx_complete);
> -	ret = port->tcpc->pd_transmit(port->tcpc, type, msg);
> +	ret = port->tcpc->pd_transmit(port->tcpc, type, msg, port->negotiated_rev);
>  	if (ret < 0)
>  		return ret;
>  
> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> index e68aaa12886f..efaedd7e8a18 100644
> --- a/include/linux/usb/tcpm.h
> +++ b/include/linux/usb/tcpm.h
> @@ -121,7 +121,7 @@ struct tcpc_dev {
>  			      enum typec_cc_status cc);
>  	int (*try_role)(struct tcpc_dev *dev, int role);
>  	int (*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);
>  	int (*set_bist_data)(struct tcpc_dev *dev, bool on);
>  	int (*enable_frs)(struct tcpc_dev *dev, bool enable);
>  	void (*frs_sourcing_vbus)(struct tcpc_dev *dev);

I think this will break bisectability. You need to change the users of
that at in the same commit.

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count
  2020-12-01 10:31 ` [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Heikki Krogerus
@ 2020-12-02  3:18   ` Badhri Jagan Sridharan
  0 siblings, 0 replies; 6+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-02  3:18 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Guenter Roeck, Greg Kroah-Hartman, USB, LKML

Sure. Done ! Just sent out v2 version of the patch.

Thanks,
Badhri.


On Tue, Dec 1, 2020 at 2:32 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> On Mon, Nov 30, 2020 at 08:22:34PM -0800, Badhri Jagan Sridharan wrote:
> > nRetryCount was updated from 3 to 2 between PD2.0 and PD3.0 spec.
> > nRetryCount in "Table 6-34 Counter parameters" of the PD 2.0
> > spec is set to 3, whereas, nRetryCount in "Table 6-59 Counter
> > parameters" is set to 2.
> >
> > Pass down negotiated rev in pd_transmit so that low level chip
> > drivers can update the retry count accordingly before attempting
> > packet transmission.
> >
> > This helps in passing "TEST.PD.PORT.ALL.02" of the
> > "Power Delivery Merged" test suite which was initially failing
> > with "The UUT did not retransmit the message nReryCount times"
> >
> > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
> > ---
> >  drivers/usb/typec/tcpm/tcpm.c | 2 +-
> >  include/linux/usb/tcpm.h      | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > index 3bbc1f10af49..c73bc3a8356a 100644
> > --- a/drivers/usb/typec/tcpm/tcpm.c
> > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > @@ -667,7 +667,7 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
> >               tcpm_log(port, "PD TX, type: %#x", type);
> >
> >       reinit_completion(&port->tx_complete);
> > -     ret = port->tcpc->pd_transmit(port->tcpc, type, msg);
> > +     ret = port->tcpc->pd_transmit(port->tcpc, type, msg, port->negotiated_rev);
> >       if (ret < 0)
> >               return ret;
> >
> > diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> > index e68aaa12886f..efaedd7e8a18 100644
> > --- a/include/linux/usb/tcpm.h
> > +++ b/include/linux/usb/tcpm.h
> > @@ -121,7 +121,7 @@ struct tcpc_dev {
> >                             enum typec_cc_status cc);
> >       int (*try_role)(struct tcpc_dev *dev, int role);
> >       int (*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);
> >       int (*set_bist_data)(struct tcpc_dev *dev, bool on);
> >       int (*enable_frs)(struct tcpc_dev *dev, bool enable);
> >       void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
>
> I think this will break bisectability. You need to change the users of
> that at in the same commit.
>
> thanks,
>
> --
> heikki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-02  3:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01  4:22 [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Badhri Jagan Sridharan
2020-12-01  4:22 ` [PATCH v1 2/4] usb: typec: fusb302: Update retry count based on the negotiated rev Badhri Jagan Sridharan
2020-12-01  4:22 ` [PATCH v1 3/4] usb: typec: tcpci: " Badhri Jagan Sridharan
2020-12-01  4:22 ` [PATCH v1 4/4] usb: typec: wcove: Update wcove_pd_transmit to include negoitated rev Badhri Jagan Sridharan
2020-12-01 10:31 ` [PATCH v1 1/4] usb: typec: tcpm: Pass down negotiated rev to update retry count Heikki Krogerus
2020-12-02  3:18   ` Badhri Jagan Sridharan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.