From patchwork Mon Mar 13 02:58:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 13171919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E294C6FD19 for ; Mon, 13 Mar 2023 02:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tVF6j+GAc18PFg//dIHY9Q+mqS2WfENWGf/tJueuX0A=; b=RXnWKDdRVBaZEb JDpnL15nY2lBuVFmemNuGbO/TdiqX3gXsG2SsAQHkcaIgsXRUIvc35PW1NtqzslEDbzHm3q9PnfWj JDWjQypeK5AdVapnoDTbiY2yvxKP3DYQyUaBBAAHX6ty+WEVI8FiJFHk7suRr4NHMu5FCWaO4y8fA +g96Mza8+Xu77X2PgQ0qwRrxKUFOjDaU0Vql6krsJcGIFrzrVtCS728O8ep5wa+QgOJH5kJzMv3TE +Vwfgq9DwZl+hYej1ECPPNPv4xY0hVw6MDGzwGI+W1KgALM8SRlF/86qD4RkfWhcrBSGUqrfW6bqK Sua0vMjOQPzfWZV42x6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOz-0045U1-9h; Mon, 13 Mar 2023 02:59:09 +0000 Received: from mail-m11879.qiye.163.com ([115.236.118.79]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOo-0045Q5-Lb for linux-rockchip@lists.infradead.org; Mon, 13 Mar 2023 02:59:02 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11879.qiye.163.com (Hmail) with ESMTPA id 4672668051F; Mon, 13 Mar 2023 10:58:45 +0800 (CST) From: Frank Wang To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, heiko@sntech.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, huangtao@rock-chips.com, william.wu@rock-chips.com, jianwei.zheng@rock-chips.com, yubing.zhang@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [PATCH 1/4] usb: typec: tcpm: fix cc role at port reset Date: Mon, 13 Mar 2023 10:58:40 +0800 Message-Id: <20230313025843.17162-2-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230313025843.17162-1-frank.wang@rock-chips.com> References: <20230313025843.17162-1-frank.wang@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGh1DSlZKGRlMHR0eSU5IT0NVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpDVUpLS1VLWQ Y+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NTI6Kio*Dj0ISC8oLhw*Tz0o FhEaChhVSlVKTUxDTUxNSElNSklIVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFJT09DNwY+ X-HM-Tid: 0a86d8e7f4c92eb5kusn4672668051f X-HM-MType: 1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_195858_900440_F5C87AF2 X-CRM114-Status: GOOD ( 10.32 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org In the current implementation, the tcpm set CC1/CC2 role to open when it do port reset would cause the VBUS removed by the Type-C partner. The Figure 4-20 in the TCPCI 2.0 specification show that the CC1/CC2 role should set to 01b (Rp) or 10b (Rd) at Power On or Reset stage in DRP initialization and connection detection. So set CC1/CC2 to Rd to fix it. Signed-off-by: Frank Wang --- drivers/usb/typec/tcpm/tcpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index a0d943d785800..66de02a56f512 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4851,7 +4851,7 @@ static void run_state_machine(struct tcpm_port *port) break; case PORT_RESET: tcpm_reset_port(port); - tcpm_set_cc(port, TYPEC_CC_OPEN); + tcpm_set_cc(port, TYPEC_CC_RD); tcpm_set_state(port, PORT_RESET_WAIT_OFF, PD_T_ERROR_RECOVERY); break; From patchwork Mon Mar 13 02:58:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 13171920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10CD6C6FD19 for ; Mon, 13 Mar 2023 02:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YEK7DRE3ipUvlZplvYha5GqP+meP8VgJdEQhYacDEcw=; b=0GlUp9DzQO8KqO KeEjrqNPckRf9eyNujOXypq0l6MLrwslXq1c3h4HuDh4fukQWihOLOGE6UP8MHlfgqlvh0MTX0zhO lPMik8pfIReemVLT880bEPd8WhxqcJ7xoj/O6mM/dwaR+SoBeUK4VWFeNJ+fMoIsj1dstsuGvs5zQ 7lKMHRDocmT1QSkBpcIqE3rxgEH7ayZz2efAGTAT3E93rXI/dG0UNe5MUhFlks+XGlHVKXprcQnc7 PMI0Vf7eUBfK1JNQ0WVdME8u2lSUSsDAVm1o58LAIufY0LAvI71K0KMg1g1u9A5GBx2nIWvaML6bj wCdzX8Q8f6DrBNV4yTgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOu-0045T2-D0; Mon, 13 Mar 2023 02:59:04 +0000 Received: from mail-m11879.qiye.163.com ([115.236.118.79]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOo-0045QA-IF for linux-rockchip@lists.infradead.org; Mon, 13 Mar 2023 02:59:00 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11879.qiye.163.com (Hmail) with ESMTPA id 2E60D6804B2; Mon, 13 Mar 2023 10:58:46 +0800 (CST) From: Frank Wang To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, heiko@sntech.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, huangtao@rock-chips.com, william.wu@rock-chips.com, jianwei.zheng@rock-chips.com, yubing.zhang@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [PATCH 2/4] usb: typec: tcpm: fix multiple times discover svids error Date: Mon, 13 Mar 2023 10:58:41 +0800 Message-Id: <20230313025843.17162-3-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230313025843.17162-1-frank.wang@rock-chips.com> References: <20230313025843.17162-1-frank.wang@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGkoYSlYYHx5JGEIZTUtJSh5VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpMVUpLS1VLWQ Y+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MSo6Djo*Mj0PTC8TEBM#Tz1D SQhPCQ1VSlVKTUxDTUxNSElNQkNCVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFISEJMNwY+ X-HM-Tid: 0a86d8e7f8442eb5kusn2e60d6804b2 X-HM-MType: 1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_195858_782671_46D77C8A X-CRM114-Status: GOOD ( 10.47 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org PD3.0 Spec 6.4.4.3.2 say that only Responder supports 12 or more SVIDs, the Discover SVIDs Command Shall be executed multiple times until a Discover SVIDs VDO is returned ending either with a SVID value of 0x0000 in the last part of the last VDO or with a VDO containing two SVIDs with values of 0x0000. In the current implementation, if the last VDO does not find that the Discover SVIDs Command would be executed multiple times even if the Responder SVIDs are less than 12, and we found some odd dockers just meet this case. So fix it. Signed-off-by: Frank Wang --- drivers/usb/typec/tcpm/tcpm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 66de02a56f512..2962f7c261976 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1515,7 +1515,21 @@ static bool svdm_consume_svids(struct tcpm_port *port, const u32 *p, int cnt) pmdata->svids[pmdata->nsvids++] = svid; tcpm_log(port, "SVID %d: 0x%x", pmdata->nsvids, svid); } - return true; + + /* + * PD3.0 Spec 6.4.4.3.2: The SVIDs are returned 2 per VDO (see Table + * 6-43), and can be returned maximum 6 VDOs per response (see Figure + * 6-19). If the Respondersupports 12 or more SVID then the Discover + * SVIDs Command Shall be executed multiple times until a Discover + * SVIDs VDO is returned ending either with a SVID value of 0x0000 in + * the last part of the last VDO or with a VDO containing two SVIDs + * with values of 0x0000. + * + * However, some odd dockers support SVIDs less than 12 but without + * 0x0000 in the last VDO, so we need to break the Discover SVIDs + * request and return false here. + */ + return cnt == 7 ? true : false; abort: tcpm_log(port, "SVID_DISCOVERY_MAX(%d) too low!", SVID_DISCOVERY_MAX); return false; From patchwork Mon Mar 13 02:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 13171918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABD83C6FD19 for ; Mon, 13 Mar 2023 02:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mXmGGlS1hxUNfUojWhB78DFAhMuJRI3Mpog+44NHaMA=; b=clOwstAc+xztLC pnpsI/6bNnmYdMRCAkWHFnursrcsiMcE7oyNd+MPtS6GhKEq25FacIBGS1MEnVdOLAJZkI4AgCGtc ZEI5hSKKWc8s1TIU64l+GkNFDhB8qPQbOmtIlWf5a7fwy17fN/G41qjvyTDYyLgMp8dqX2jdFJyzn ZODh0h9g6uQazagO3zdZygt98hz1sdoHjIzH4aufejrG66ySJviwW50X8KxX4dHqddeoC/MN5shF1 B1QLIXJjZELRFj/ltnwcq83gH4w8uOZQfwzBFDH4mU06yvYL+EfllhxdtvSHEeIyTB5Zr3ZFPgBll fNQ0M+W/wmx4qxif4Dkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOt-0045Sp-6w; Mon, 13 Mar 2023 02:59:03 +0000 Received: from mail-m11879.qiye.163.com ([115.236.118.79]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOo-0045Q7-HZ for linux-rockchip@lists.infradead.org; Mon, 13 Mar 2023 02:59:00 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11879.qiye.163.com (Hmail) with ESMTPA id 0A60B68051B; Mon, 13 Mar 2023 10:58:47 +0800 (CST) From: Frank Wang To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, heiko@sntech.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, huangtao@rock-chips.com, william.wu@rock-chips.com, jianwei.zheng@rock-chips.com, yubing.zhang@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [PATCH 3/4] usb: typec: tcpm: add get max power support Date: Mon, 13 Mar 2023 10:58:42 +0800 Message-Id: <20230313025843.17162-4-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230313025843.17162-1-frank.wang@rock-chips.com> References: <20230313025843.17162-1-frank.wang@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQklJHVZMHhoZHkpMSExOGB5VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpMVUpLS1VLWQ Y+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Nwg6PSo4Fz0OEy8UEBEBTzcj PD5PCjlVSlVKTUxDTUxNSElMQkpIVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFIS05NNwY+ X-HM-Tid: 0a86d8e7fb982eb5kusn0a60b68051b X-HM-MType: 1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_195858_765865_6A2FBFE5 X-CRM114-Status: GOOD ( 10.11 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT property. Signed-off-by: Frank Wang --- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 2962f7c261976..9e583060e64fc 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -6319,6 +6319,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port, return 0; } +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port, + union power_supply_propval *val) +{ + unsigned int src_mv, src_ma, max_src_mw = 0; + unsigned int i, tmp; + + for (i = 0; i < port->nr_source_caps; i++) { + u32 pdo = port->source_caps[i]; + + if (pdo_type(pdo) == PDO_TYPE_FIXED) { + src_mv = pdo_fixed_voltage(pdo); + src_ma = pdo_max_current(pdo); + tmp = src_mv * src_ma / 1000; + max_src_mw = tmp > max_src_mw ? tmp : max_src_mw; + } + } + + val->intval = max_src_mw; + return 0; +} + static int tcpm_psy_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -6348,6 +6369,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_CURRENT_NOW: ret = tcpm_psy_get_current_now(port, val); break; + case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT: + tcpm_psy_get_input_power_limit(port, val); + break; default: ret = -EINVAL; break; From patchwork Mon Mar 13 02:58:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wang X-Patchwork-Id: 13171921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78A9DC6FD1C for ; Mon, 13 Mar 2023 02:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YFU9K001mu14ERJljp/ZROugf0h9wI3SBQHE/vyWstw=; b=WPe3UczBMQ8jLW vOgGDVAypbyDWRhWgYSAKIKxyJ84Env8jKVV8BdSjW3gS9aKoIlLfrzXQrJz/dxHJqq8MjwoiQEKr cGG3AQJZDCoSCS0LnJv+7dc9saJf096ijBCh6E6b5UOTWxiEiFPVPEG7Su3NJO5maHO8TwDrkVLj0 MWXDK9/xt5RxDhHeuGHZPiXJ/jLoqm5reQGQ8NlK7w0XrFaBDlcP5RpZ8WTKv8Zh4Ycej4Lm7Dd8O AiluYoC9a+SDKCublqa2LteIeccfQQ15WkzPAANs1UQTYJ2ZSGReE8RaFNzgeAOaG8N5QNwh8KntN +ug9hiJ1pm7gmwIPZgsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYP2-0045Uo-KF; Mon, 13 Mar 2023 02:59:12 +0000 Received: from mail-m11879.qiye.163.com ([115.236.118.79]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbYOo-0045Q6-Kt for linux-rockchip@lists.infradead.org; Mon, 13 Mar 2023 02:59:02 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11879.qiye.163.com (Hmail) with ESMTPA id EC7F368054C; Mon, 13 Mar 2023 10:58:47 +0800 (CST) From: Frank Wang To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, heiko@sntech.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, huangtao@rock-chips.com, william.wu@rock-chips.com, jianwei.zheng@rock-chips.com, yubing.zhang@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [PATCH 4/4] usb: typec: tcpm: fix source caps may lost after soft reset Date: Mon, 13 Mar 2023 10:58:43 +0800 Message-Id: <20230313025843.17162-5-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230313025843.17162-1-frank.wang@rock-chips.com> References: <20230313025843.17162-1-frank.wang@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGU0fGlYYHhkeTB5ISExPHk5VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpMVUpLS1VLWQ Y+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NE06Hyo*GT0JIS9MURw0TzI* TCNPFBdVSlVKTUxDTUxNSElDQ0hJVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFITk1ONwY+ X-HM-Tid: 0a86d8e7ff4c2eb5kusnec7f368054c X-HM-MType: 1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_195858_907196_06A117F5 X-CRM114-Status: UNSURE ( 9.41 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Invoke set_pd_rx() may flush the RX FIFO of PD controller, so do set_pd_rx() before sending Soft Reset in case Source caps may be flushed at debounce time between SOFT_RESET_SEND and SNK_WAIT_CAPABILITIES state. Without this patch, in PD charger stress test, the FUSB302 driver may occur the following exceptions in power negotiation stage. [ ...] [ 4.512252] fusb302_irq_intn [ 4.512260] AMS SOFT_RESET_AMS finished [ 4.512269] state change SOFT_RESET_SEND ->SNK_WAIT_CAPABILITIES [rev3 NONE_AMS] [ 4.514511] pd := on [ 4.514516] pending state change SNK_WAIT_CAPABILITIES ->HARD_RESET_SEND @ 310 ms [rev3 NONE_AMS] [ 4.515428] IRQ: 0x51, a: 0x00, b: 0x01, status0: 0x93 [ 4.515431] IRQ: BC_LVL, handler pending [ 4.515435] IRQ: PD sent good CRC [ 4.516434] PD message header: 0 [ 4.516437] PD message len: 0 [ 4.516444] PD RX, header: 0x0 [1] Signed-off-by: Frank Wang --- drivers/usb/typec/tcpm/tcpm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 9e583060e64fc..ba6bf71838eed 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4321,10 +4321,12 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, unattached_state(port), 0); break; case SNK_WAIT_CAPABILITIES: - ret = port->tcpc->set_pd_rx(port->tcpc, true); - if (ret < 0) { - tcpm_set_state(port, SNK_READY, 0); - break; + if (port->prev_state != SOFT_RESET_SEND) { + ret = port->tcpc->set_pd_rx(port->tcpc, true); + if (ret < 0) { + tcpm_set_state(port, SNK_READY, 0); + break; + } } /* * If VBUS has never been low, and we time out waiting @@ -4603,6 +4605,7 @@ static void run_state_machine(struct tcpm_port *port) case SOFT_RESET_SEND: port->message_id = 0; port->rx_msgid = -1; + port->tcpc->set_pd_rx(port->tcpc, true); if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET)) tcpm_set_state_cond(port, hard_reset_state(port), 0); else