Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbdHPD3j (ORCPT ); Tue, 15 Aug 2017 23:29:39 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:34716 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbdHPD3h (ORCPT ); Tue, 15 Aug 2017 23:29:37 -0400 Subject: Re: [PATCH 1/2] staging: typec: tcpm: Report right typec_pwr_opmode To: Badhri Jagan Sridharan , Greg Kroah-Hartman Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20170815232213.26194-1-Badhri@google.com> From: Guenter Roeck Message-ID: Date: Tue, 15 Aug 2017 20:29:35 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170815232213.26194-1-Badhri@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2219 Lines: 64 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 Reviewed-by: Guenter Roeck > --- > 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; >