From patchwork Thu Sep 13 02:11:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 10598635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F21514E5 for ; Thu, 13 Sep 2018 02:11:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62ACF2ADDA for ; Thu, 13 Sep 2018 02:11:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5359E2ADDC; Thu, 13 Sep 2018 02:11:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA6462ADDA for ; Thu, 13 Sep 2018 02:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726521AbeIMHSh (ORCPT ); Thu, 13 Sep 2018 03:18:37 -0400 Received: from mail-io1-f73.google.com ([209.85.166.73]:44617 "EHLO mail-io1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbeIMHSf (ORCPT ); Thu, 13 Sep 2018 03:18:35 -0400 Received: by mail-io1-f73.google.com with SMTP id s15-v6so2739709iob.11 for ; Wed, 12 Sep 2018 19:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=a7z2/GVC0GewoLAOj0ejoiGO7k0hgtIwfj4eCBu18w4=; b=jGrLBZQii+9GPVTGTz9sJJOGeoMtb8ANE4IY1JLudPEZQeUkKprISz1XND9ujd8HEd xVUszgnKIARu6qtDhF1nwj1AXunoZuNAnrDUunTAq0/jCPb/iXtBpXSlmcL6UcaCvkhZ jjw0UzJl5ar/pIvLbvjHzJ4bu4ECwYKlpL3rtvhXAsQe1W3ulSqLEvqGIojiFk2Bz8aG VD9aatOuKNhNm7PRBkVkPor+yo7drmkA4ijfiEoZ7eskiKrTRxMDDxHWuKcAK/FNZGOn 0VPQyozGSHe8h3YHNFspVBMYAY98Q6EwKzc85r2iHhuXI08b9eRPZCXR8ZsqDQ51sr+r V8Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=a7z2/GVC0GewoLAOj0ejoiGO7k0hgtIwfj4eCBu18w4=; b=rSeoYr5GJx6/Cvl97Yz2XJgjsrMlJjg1SHQKuCeOatpF+HWjcJBS8BlXoUb0gQqTES I2LajRYJM58VR61BheiICSWJSYkSqZApx8en6KrfgmyfniQRQhkfcoc/nVmoACW7ETYq GWmls2W9WgT4/4wfSVh8PGlOMGjD/VEFka/s9qXb/7uo0rkwtS1gxK/sOaAKIJPegnEq dAIHDSt9RMYMQMDQSepEafCvvySXddGi2ZJunhiQ7DkTLA31uvgse9semBUY2UoJs/jI tleY54fccCgFjSvR7xyTxbBKFs2oroUfYwQA/6sj/POmfByiS7Qoi1YvQrWHTaPR7zuL Lt9Q== X-Gm-Message-State: APzg51AhLZIJk6jlYdUAYQwLEoDno8jxPzsc0xjO7+eM2H2jJrihMD2y vNg006BOQcAyMZN2AiL9XhiASmV9/ew= X-Google-Smtp-Source: ANB0VdYv0PyMNckBneXsSawlFTyQAyu0/pgn3LyNjVO6SIS12h0m895hTI8+fHEcr74Xs3XDFpB3QE5HfQk= X-Received: by 2002:a24:9d43:: with SMTP id f64-v6mr4180845itd.17.1536804678091; Wed, 12 Sep 2018 19:11:18 -0700 (PDT) Date: Wed, 12 Sep 2018 19:11:12 -0700 Message-Id: <20180913021113.18150-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 1/2] typec: tcpm: Do not disconnect link for self powered devices From: Badhri Jagan Sridharan To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Badhri Jagan Sridharan , Badhri Jagan Sridharan Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP During HARD_RESET the data link is disconnected. For self powered device, the spec is advising against doing that. From USB_PD_R3_0 7.1.5 Response to Hard Resets Device operation during and after a Hard Reset is defined as follows: Self-powered devices Should Not disconnect from USB during a Hard Reset (see Section 9.1.2). Bus powered devices will disconnect from USB during a Hard Reset due to the loss of their power source. Tackle this by letting TCPM know whether the device is self or bus powered. This overcomes unnecessary port disconnections from hard reset. Also, speeds up the enumeration time when connected to Type-A ports. Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm.c | 6 +++++- include/linux/usb/tcpm.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index 4f1f4215f3d6..a4e0c027a2a9 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -3270,7 +3270,11 @@ static void run_state_machine(struct tcpm_port *port) memset(&port->pps_data, 0, sizeof(port->pps_data)); tcpm_set_vconn(port, false); tcpm_set_charge(port, false); - tcpm_set_roles(port, false, TYPEC_SINK, TYPEC_DEVICE); + + if (port->tcpc->config->self_powered) + tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE); + else + tcpm_set_roles(port, false, TYPEC_SINK, TYPEC_DEVICE); /* * VBUS may or may not toggle, depending on the adapter. * If it doesn't toggle, transition to SNK_HARD_RESET_SINK_ON diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 7e7fbfb84e8e..50c74a77db55 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -89,6 +89,7 @@ struct tcpc_config { enum typec_port_data data; enum typec_role default_role; bool try_role_hw; /* try.{src,snk} implemented in hardware */ + bool self_powered; /* port belongs to a self powered device */ const struct typec_altmode_desc *alt_modes; }; From patchwork Thu Sep 13 02:11:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 10598637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7C5014DB for ; Thu, 13 Sep 2018 02:11:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B761E2ADDA for ; Thu, 13 Sep 2018 02:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAE372ADDC; Thu, 13 Sep 2018 02:11:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55E3A2ADDA for ; Thu, 13 Sep 2018 02:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbeIMHSm (ORCPT ); Thu, 13 Sep 2018 03:18:42 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:36940 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbeIMHSl (ORCPT ); Thu, 13 Sep 2018 03:18:41 -0400 Received: by mail-pf1-f202.google.com with SMTP id v9-v6so2031474pff.4 for ; Wed, 12 Sep 2018 19:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Y+lqFgjfBWDSIKd36fnHL64GSJToWjw4TcaXPRFwfII=; b=Jh7s/VHB/3fScArZlz4IAzg0G2CTcknzXe0bNweFwHE3u06Me2j0C/Z6/v/8Zb0ccT 4E0o7lCs7m4oJ0VI/sbKb4LHNCcU25yNLLUNcEzdDb+DNbMvXnrclsMxqfzf4G3JgfMH 3Ipme7mCAjYW/Fvbv58FzOvPpa3A+oLP5q0ZAzc9J/4HfwGD8Sc/62gctt6WOrGojlRr 3cr6k0e7WjSgBWwNlAlvFw7sw3FsiUB1+ghlw74w7PieCtdiBY2sdWc6F6SGKDjvZRo6 PcxQ0xMBchOuIoGNNHlpdzrXEapKGaC/lWUc2ECuF/Mlqbu/1uAPLlszR8NCX2CNgxK7 y6Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Y+lqFgjfBWDSIKd36fnHL64GSJToWjw4TcaXPRFwfII=; b=BfBLG/GshdtSBMzAHV70Bw4ovLUgd+LOKgdYgB8zpoyMNOeB6W/xCnuK4waWtySaty JpyikpXX4aoZ5sQFFn7A/NnN0yf0Q+VtoeZw4b2KfSVCPcPUmDzkDarLS5YMbMTZnDQ6 hzhI7D5kY8WpnZ9DY94koNbgT6hVBVhqoAf2NAHS64yBt+mkcQufCEuubjphD7bmjRO4 1inaJXLNkIELdXyNj1vB9ogdM/nOBh7Jj8gIPmMjLW8DY0zRi6DoAQOG3jFGro4pEkTk tZ6sgWRpwOjAW8aX9vGJkjXxrzckezxsj0BRLi2VYPsgU+yFArgqRL3SQZ022UsihM0u PnUA== X-Gm-Message-State: APzg51AZ8NXsWhXRdufFnDjwFeEGwcSMmHiOTHqd5Jh7noE3HclUN6Ts F5duletXz9ZRFQbTUr8cLipxnB0fIDQ= X-Google-Smtp-Source: ANB0VdZAF3tAU/tOZbSxcJbJ+CG6vp5WeQRCip29nnoD/TGkhanxrjCQ0Rky0A7MyCNLchDTW/Ko8coK/ys= X-Received: by 2002:a63:445e:: with SMTP id t30-v6mr307974pgk.102.1536804685008; Wed, 12 Sep 2018 19:11:25 -0700 (PDT) Date: Wed, 12 Sep 2018 19:11:13 -0700 In-Reply-To: <20180913021113.18150-1-badhri@google.com> Message-Id: <20180913021113.18150-2-badhri@google.com> Mime-Version: 1.0 References: <20180913021113.18150-1-badhri@google.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 2/2] typec: tcpm: Add option to maintain current limit at Vsafe5V From: Badhri Jagan Sridharan To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Badhri Jagan Sridharan , Badhri Jagan Sridharan Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP During hard reset, TCPM turns off the charging path. The spec provides an option for Sink to either drop to vSafe5V or vSafe0V. From USB_PD_R3_0 2.6.2 Sink Operation .. Serious errors are handled by Hard Reset Signaling issued by either Port Partner. A Hard Reset: resets protocol as for a Soft Reset but also returns the power supply to USB Default Operation (vSafe0V or vSafe5V output) in order to protect the Sink. Add a config option to tcpc_dev and let the device specific driver decide what needs to be done. Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm.c | 7 ++++++- include/linux/usb/tcpm.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index a4e0c027a2a9..350d1a7c4543 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -3269,7 +3269,12 @@ static void run_state_machine(struct tcpm_port *port) case SNK_HARD_RESET_SINK_OFF: memset(&port->pps_data, 0, sizeof(port->pps_data)); tcpm_set_vconn(port, false); - tcpm_set_charge(port, false); + if (port->tcpc->config->vsafe_5v_hard_reset) + tcpm_set_current_limit(port, + tcpm_get_current_limit(port), + 5000); + else + tcpm_set_charge(port, false); if (port->tcpc->config->self_powered) tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE); diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 50c74a77db55..c6e3ccecba70 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -90,6 +90,7 @@ struct tcpc_config { enum typec_role default_role; bool try_role_hw; /* try.{src,snk} implemented in hardware */ bool self_powered; /* port belongs to a self powered device */ + bool vsafe_5v_hard_reset; /* Maintain VSAFE5V during hard reset */ const struct typec_altmode_desc *alt_modes; };