diff mbox series

[v6,05/14] usb: typec: tcpci: Add set_vbus tcpci callback

Message ID 20200901025927.3596190-6-badhri@google.com
State New
Headers show
Series TCPM support for FRS and AutoDischarge Disconnect | expand

Commit Message

Badhri Jagan Sridharan Sept. 1, 2020, 2:59 a.m. UTC
set_vbus callback allows TCPC which are TCPCI based, however,
does not support turning on sink and source mode through
Command.SinkVbus and Command.SourceVbusDefaultVoltage.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
Changes since v1:
- Changing patch version to v6 to fix version number confusion.
---
 drivers/usb/typec/tcpm/tcpci.c | 7 +++++++
 drivers/usb/typec/tcpm/tcpci.h | 1 +
 2 files changed, 8 insertions(+)

Comments

Heikki Krogerus Sept. 15, 2020, 12:22 p.m. UTC | #1
On Mon, Aug 31, 2020 at 07:59:18PM -0700, Badhri Jagan Sridharan wrote:
> set_vbus callback allows TCPC which are TCPCI based, however,

> does not support turning on sink and source mode through

> Command.SinkVbus and Command.SourceVbusDefaultVoltage.

> 

> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

> ---

> Changes since v1:

> - Changing patch version to v6 to fix version number confusion.

> ---

>  drivers/usb/typec/tcpm/tcpci.c | 7 +++++++

>  drivers/usb/typec/tcpm/tcpci.h | 1 +

>  2 files changed, 8 insertions(+)

> 

> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c

> index b960fe5a0f28..d6a6fac82d48 100644

> --- a/drivers/usb/typec/tcpm/tcpci.c

> +++ b/drivers/usb/typec/tcpm/tcpci.c

> @@ -328,6 +328,13 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)

>  	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);

>  	int ret;

>  

> +	if (tcpci->data->set_vbus) {

> +		ret = tcpci->data->set_vbus(tcpci, tcpci->data, source, sink);

> +		/* Bypass when ret > 0 */

> +		if (ret != 0)

> +			return ret < 0 ? ret : 0;


Can it return positive value? What does positive value mean?

> +	}

> +

>  	/* Disable both source and sink first before enabling anything */

>  

>  	if (!source) {

> diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h

> index 04c49a0b0368..4d441bdf24d5 100644

> --- a/drivers/usb/typec/tcpm/tcpci.h

> +++ b/drivers/usb/typec/tcpm/tcpci.h

> @@ -144,6 +144,7 @@ struct tcpci_data {

>  			 bool enable);

>  	int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,

>  				  enum typec_cc_status cc);

> +	int (*set_vbus)(struct tcpci *tcpci, struct tcpci_data *data, bool source, bool sink);

>  };

>  

>  struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);

> -- 

> 2.28.0.402.g5ffc5be6b7-goog


-- 
heikki
Badhri Jagan Sridharan Sept. 16, 2020, 9:07 a.m. UTC | #2
On Tue, Sep 15, 2020 at 5:22 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>

> On Mon, Aug 31, 2020 at 07:59:18PM -0700, Badhri Jagan Sridharan wrote:

> > set_vbus callback allows TCPC which are TCPCI based, however,

> > does not support turning on sink and source mode through

> > Command.SinkVbus and Command.SourceVbusDefaultVoltage.

> >

> > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

> > ---

> > Changes since v1:

> > - Changing patch version to v6 to fix version number confusion.

> > ---

> >  drivers/usb/typec/tcpm/tcpci.c | 7 +++++++

> >  drivers/usb/typec/tcpm/tcpci.h | 1 +

> >  2 files changed, 8 insertions(+)

> >

> > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c

> > index b960fe5a0f28..d6a6fac82d48 100644

> > --- a/drivers/usb/typec/tcpm/tcpci.c

> > +++ b/drivers/usb/typec/tcpm/tcpci.c

> > @@ -328,6 +328,13 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)

> >       struct tcpci *tcpci = tcpc_to_tcpci(tcpc);

> >       int ret;

> >

> > +     if (tcpci->data->set_vbus) {

> > +             ret = tcpci->data->set_vbus(tcpci, tcpci->data, source, sink);

> > +             /* Bypass when ret > 0 */

> > +             if (ret != 0)

> > +                     return ret < 0 ? ret : 0;

>

> Can it return positive value? What does positive value mean?


When a positive value is returned, tcpci->data->set_vbus is indicating
the tcpci.c code to bypass
other commands here. i.e. tcpci->data->set_vbus completely handles
sinking/sourcing vbus and
does not want tcpc.c to execute any other TCPC_CMD_* command.
Open to suggestions if you are not happy with this. All I want is to
make tcpci code pass on the call
from TCPM to chip level TCPC driver (i.e.  tcpci_maxim.c in this case)
and not do anything else.

>

> > +     }

> > +

> >       /* Disable both source and sink first before enabling anything */

> >

> >       if (!source) {

> > diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h

> > index 04c49a0b0368..4d441bdf24d5 100644

> > --- a/drivers/usb/typec/tcpm/tcpci.h

> > +++ b/drivers/usb/typec/tcpm/tcpci.h

> > @@ -144,6 +144,7 @@ struct tcpci_data {

> >                        bool enable);

> >       int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,

> >                                 enum typec_cc_status cc);

> > +     int (*set_vbus)(struct tcpci *tcpci, struct tcpci_data *data, bool source, bool sink);

> >  };

> >

> >  struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);

> > --

> > 2.28.0.402.g5ffc5be6b7-goog

>

> --

> heikki
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index b960fe5a0f28..d6a6fac82d48 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -328,6 +328,13 @@  static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 	int ret;
 
+	if (tcpci->data->set_vbus) {
+		ret = tcpci->data->set_vbus(tcpci, tcpci->data, source, sink);
+		/* Bypass when ret > 0 */
+		if (ret != 0)
+			return ret < 0 ? ret : 0;
+	}
+
 	/* Disable both source and sink first before enabling anything */
 
 	if (!source) {
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 04c49a0b0368..4d441bdf24d5 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -144,6 +144,7 @@  struct tcpci_data {
 			 bool enable);
 	int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,
 				  enum typec_cc_status cc);
+	int (*set_vbus)(struct tcpci *tcpci, struct tcpci_data *data, bool source, bool sink);
 };
 
 struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);