Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1712518 > unrolled thread

[PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode

Started byBadhri Jagan Sridharan <badhri@google.com>
First post2017-08-16 01:30 +0200
Last post2017-08-16 05:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode Badhri Jagan Sridharan <badhri@google.com> - 2017-08-16 01:30 +0200
    Re: [PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode Guenter Roeck <linux@roeck-us.net> - 2017-08-16 05:30 +0200

#1712518 — [PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode

FromBadhri Jagan Sridharan <badhri@google.com>
Date2017-08-16 01:30 +0200
Subject[PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode
Message-ID<ueTrA-7KN-5@gated-at.bofh.it>
At present, TCPM does not take into account the actual resistor
value presented in the CC line and therefore reports TYPEC_PWR_MODE_USB
irrespective of the power_op_mode it is in.
This patch makes TCPM consider the actual value of Rp.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
---
 drivers/staging/typec/tcpm.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 20eb4ebcf8c3..a24e6bbb909c 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2123,9 +2123,23 @@ static void tcpm_swap_complete(struct tcpm_port *port, int result)
 	}
 }
 
+enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc)
+{
+	switch (cc) {
+	case TYPEC_CC_RP_1_5:
+		return TYPEC_PWR_MODE_1_5A;
+	case TYPEC_CC_RP_3_0:
+		return TYPEC_PWR_MODE_3_0A;
+	case TYPEC_CC_RP_DEF:
+	default:
+		return TYPEC_PWR_MODE_USB;
+	}
+}
+
 static void run_state_machine(struct tcpm_port *port)
 {
 	int ret;
+	enum typec_pwr_opmode opmode;
 
 	port->enter_state = port->state;
 	switch (port->state) {
@@ -2201,7 +2215,8 @@ static void run_state_machine(struct tcpm_port *port)
 			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
 		break;
 	case SRC_STARTUP:
-		typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB);
+		opmode =  tcpm_get_pwr_opmode(tcpm_rp_cc(port));
+		typec_set_pwr_opmode(port->typec_port, opmode);
 		port->pwr_opmode = TYPEC_PWR_MODE_USB;
 		port->caps_count = 0;
 		port->message_id = 0;
@@ -2362,7 +2377,9 @@ static void run_state_machine(struct tcpm_port *port)
 		break;
 	case SNK_STARTUP:
 		/* XXX: callback into infrastructure */
-		typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB);
+		opmode =  tcpm_get_pwr_opmode(port->polarity ?
+					      port->cc2 : port->cc1);
+		typec_set_pwr_opmode(port->typec_port, opmode);
 		port->pwr_opmode = TYPEC_PWR_MODE_USB;
 		port->message_id = 0;
 		port->rx_msgid = -1;
-- 
2.14.1.480.gb18f417b89-goog

[toc] | [next] | [standalone]


#1712631

FromGuenter Roeck <linux@roeck-us.net>
Date2017-08-16 05:30 +0200
Message-ID<ueXbP-1L3-5@gated-at.bofh.it>
In reply to#1712518
On 08/15/2017 04:22 PM, Badhri Jagan Sridharan wrote:
> At present, TCPM does not take into account the actual resistor
> value presented in the CC line and therefore reports TYPEC_PWR_MODE_USB
> irrespective of the power_op_mode it is in.
> This patch makes TCPM consider the actual value of Rp.
> 
> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/staging/typec/tcpm.c | 21 +++++++++++++++++++--
>   1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
> index 20eb4ebcf8c3..a24e6bbb909c 100644
> --- a/drivers/staging/typec/tcpm.c
> +++ b/drivers/staging/typec/tcpm.c
> @@ -2123,9 +2123,23 @@ static void tcpm_swap_complete(struct tcpm_port *port, int result)
>   	}
>   }
>   
> +enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc)
> +{
> +	switch (cc) {
> +	case TYPEC_CC_RP_1_5:
> +		return TYPEC_PWR_MODE_1_5A;
> +	case TYPEC_CC_RP_3_0:
> +		return TYPEC_PWR_MODE_3_0A;
> +	case TYPEC_CC_RP_DEF:
> +	default:
> +		return TYPEC_PWR_MODE_USB;
> +	}
> +}
> +
>   static void run_state_machine(struct tcpm_port *port)
>   {
>   	int ret;
> +	enum typec_pwr_opmode opmode;
>   
>   	port->enter_state = port->state;
>   	switch (port->state) {
> @@ -2201,7 +2215,8 @@ static void run_state_machine(struct tcpm_port *port)
>   			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
>   		break;
>   	case SRC_STARTUP:
> -		typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB);
> +		opmode =  tcpm_get_pwr_opmode(tcpm_rp_cc(port));
> +		typec_set_pwr_opmode(port->typec_port, opmode);
>   		port->pwr_opmode = TYPEC_PWR_MODE_USB;
>   		port->caps_count = 0;
>   		port->message_id = 0;
> @@ -2362,7 +2377,9 @@ static void run_state_machine(struct tcpm_port *port)
>   		break;
>   	case SNK_STARTUP:
>   		/* XXX: callback into infrastructure */
> -		typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB);
> +		opmode =  tcpm_get_pwr_opmode(port->polarity ?
> +					      port->cc2 : port->cc1);
> +		typec_set_pwr_opmode(port->typec_port, opmode);
>   		port->pwr_opmode = TYPEC_PWR_MODE_USB;
>   		port->message_id = 0;
>   		port->rx_msgid = -1;
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web