From patchwork Fri Jul 30 12:43:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 12411205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0D9AC432BE for ; Fri, 30 Jul 2021 12:45:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D473C601FF for ; Fri, 30 Jul 2021 12:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238824AbhG3Mph (ORCPT ); Fri, 30 Jul 2021 08:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238887AbhG3Mor (ORCPT ); Fri, 30 Jul 2021 08:44:47 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DAC6C06179B for ; Fri, 30 Jul 2021 05:43:57 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id z16-20020ac87cb00000b029025bf786be09so112689qtv.20 for ; Fri, 30 Jul 2021 05:43:57 -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=kaUeOg4wMw2l7vTceRoyu4/OPISM5UcP9eJirJ9oM9Y=; b=MWnjHnvoqoYAt3FQds194USz9dVhS/WB5OxryNDxnP0BJFGA1sltN0eRhXDFJBh/om Dj4mlAX67YWNYYLhCbG1/tc+JtMFt4r7r+KY8MvBYe0NFSq/S4A5lVfDWxvTvAkvSIv9 gNf1L4GdiXsjMMTMub7kTWDLtAm+XTcIbB5R9omww6cZhja4yMF5AEQudIIzX3F2g1fm bZYUqlzR295HVO9uYBWHqof7FSIRQkggr7QI2YcFkg4BBPmekmqdO/hyvmfQJTSxmmwH vuSQUWQ22AqAnK/cgsIpfLRXNrspLK6XA+frjobDHHcyW6XMsyKzetuxQ2xTceSJsye2 1XaA== 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=kaUeOg4wMw2l7vTceRoyu4/OPISM5UcP9eJirJ9oM9Y=; b=CoEVv8bLZmEJ9CdzLD2jT7emFGwk5uXmCXRCfeMIdVKPJtPe6JK4YyjVDcEo9rvNbB C6o/wZGMrOka9mK4ee+RcEkXRcbExSJtKNdqGZEsXjX4IqfdGGAb8x0yIjr3/oT2ZLqa JlvjsNxedj2GrXBSxsWwHLKKq9/PlTKJXTZKBYHBa4Fu3XUeI7fDA0uXKh9mniX478rN P6YsG2clb4b/iySq6lpUiBMi9WpAfBPll3AGRiCbezvqTk8nFuVhjZ54o1XRpgN66ixD s26q07k759ZvQaZGE9GvJ2wKkYOCrHYsGCyyQoYLphslupcuuey2gJ2BG6p5GxbpBn7U brkw== X-Gm-Message-State: AOAM531cJ0dCG4PCQ280qkd+GAuR3j8hEYQ6GIbZx4O5ZzOor+0o3Kdf JdoJZXir+Fzkw3gLhvlbYdxVFkHuZxGd X-Google-Smtp-Source: ABdhPJw7QIaNo5xLOs4ReEDdoq0ozBmSokGCqKvMO19HHr9L4/Gush9xfvT7WQTK6GG+Cr80INWUAEzmaZFz X-Received: from kyletso.ntc.corp.google.com ([2401:fa00:fc:202:6892:a74:4970:a062]) (user=kyletso job=sendgmr) by 2002:a05:6214:1021:: with SMTP id k1mr2372695qvr.4.1627649036478; Fri, 30 Jul 2021 05:43:56 -0700 (PDT) Date: Fri, 30 Jul 2021 20:43:47 +0800 In-Reply-To: <20210730124348.1986638-1-kyletso@google.com> Message-Id: <20210730124348.1986638-2-kyletso@google.com> Mime-Version: 1.0 References: <20210730124348.1986638-1-kyletso@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [PATCH v5 1/2] dt-bindings: connector: Add pd-unsupported property From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Set "pd-unsupported" property if the Type-C connector has no power delivery support. Signed-off-by: Kyle Tso --- Changes since v4: - Corrected the subject .../devicetree/bindings/connector/usb-connector.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/connector/usb-connector.yaml b/Documentation/devicetree/bindings/connector/usb-connector.yaml index 92b49bc37939..21ec470117a6 100644 --- a/Documentation/devicetree/bindings/connector/usb-connector.yaml +++ b/Documentation/devicetree/bindings/connector/usb-connector.yaml @@ -111,6 +111,10 @@ properties: - 1.5A - 3.0A + pd-unsupported: + description: Set this property if the Type-C connector has no power delivery support. + type: boolean + # The following are optional properties for "usb-c-connector" with power # delivery support. source-pdos: From patchwork Fri Jul 30 12:43:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 12411207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 479E9C4338F for ; Fri, 30 Jul 2021 12:46:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3046860F00 for ; Fri, 30 Jul 2021 12:46:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238897AbhG3MqE (ORCPT ); Fri, 30 Jul 2021 08:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238893AbhG3Mos (ORCPT ); Fri, 30 Jul 2021 08:44:48 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E87C0617A1 for ; Fri, 30 Jul 2021 05:44:00 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id hf7-20020a0562140e87b02902dc988b8675so5891526qvb.3 for ; Fri, 30 Jul 2021 05:44:00 -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=Fjr35flNSax2Mvu6xm+ntxvO2laDJWlsIDTMRXVS8p8=; b=rAWAaIUEmf9gxaJGCK1qIL+bo0wKL9p0W0B1EGgP54yE9mlKOvp8WpE8iXrV6Xs5QT Lha0joAclhpF9IE6pKXMiNwCWXBoosuI8Fm9HZID5dBuEZlv+F7ZUJAXzrdUqV1sBDv8 LCT4LXjlRVBlwoOiLgejUybaNligpqxq7+j5FX3zYj/oGX/UswPFIk7rDPeXu8lE2d6L nLf25NDi/5lOZE9DfU5anBF5PW9l2vNAG7pvCEzuM1MticmOy5ZiQCalGOYf8UOVRJN6 6/AZiFpJ2k4E3tjkqeqHh5ZyrzbTpTmT8tQ7VAFpjCG9CCR3rdJJBaVztq0JN+P22MK8 lJTg== 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=Fjr35flNSax2Mvu6xm+ntxvO2laDJWlsIDTMRXVS8p8=; b=nzcAlkvu1gK8F0P7M5sfVStMgSRajgRBYHty01wiN6YIAQ+eFpgkUIMcvlAeaVid4i IO8SxM2te8U3T15mpxPA87ZuFuq672enwTs5KEpMcdcJbQXppkgFrFqL5YQE2aLYy8Pf gyXbNSp8bKB/aaHc7bXd4e1bI/zKuND9MM1hUvYG/BanodP1aeRXPW8nylEJVLdFWq+t 39T5zUFusazb7J+hSUekIZHB8PY//I7xDQ6Bq8HzqenVs8/QN7ZR10AaPNr5t9tNnqE3 mG/qtPhUKCQ+j00dJTsXNez/WsOc2Rqly5vKqZwcdVI/z7U2hdPWshZw8P61hWSBm69n +bZQ== X-Gm-Message-State: AOAM532n3WjzJChLT4wxUPf9MFLNPDTVZHLn1KJuMliiYUiBVtBMBqzs HdzC1zYwUhFXqKuNQ2/oA4uka4Jb5OIL X-Google-Smtp-Source: ABdhPJw/Ja/Uj1+lv3HeRn/iZUVtWrNbi1FBl2j3rpOmuJ0IEFiVwMavlDs67ZniUbV27+zDWl6AQWtfM9Mr X-Received: from kyletso.ntc.corp.google.com ([2401:fa00:fc:202:6892:a74:4970:a062]) (user=kyletso job=sendgmr) by 2002:a05:6214:a93:: with SMTP id ev19mr2561364qvb.27.1627649039802; Fri, 30 Jul 2021 05:43:59 -0700 (PDT) Date: Fri, 30 Jul 2021 20:43:48 +0800 In-Reply-To: <20210730124348.1986638-1-kyletso@google.com> Message-Id: <20210730124348.1986638-3-kyletso@google.com> Mime-Version: 1.0 References: <20210730124348.1986638-1-kyletso@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [PATCH v5 2/2] usb: typec: tcpm: Support non-PD mode From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Even if the Type-C controller supports PD, it is doable to disable PD capabilities with the current state machine in TCPM. Without enabling RX in low-level drivers and with skipping the power negotiation, the port is eligible to be a non-PD Type-C port. Use new flags whose values are populated from the device tree to decide the port PD capability. Adding "pd-unsupported" property in device tree indicates that the port does not support PD. If PD is not supported, the device tree property "typec-power-opmode" shall be added to specify the advertised Rp value if the port supports SRC role. Signed-off-by: Kyle Tso Reviewed-by: Guenter Roeck Acked-by: Heikki Krogerus --- Changes since v4: - Added Reviewed-by drivers/usb/typec/tcpm/tcpm.c | 87 +++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 5b22a1c931a9..faea1bf9dce0 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -316,6 +316,7 @@ struct tcpm_port { struct typec_partner *partner; enum typec_cc_status cc_req; + enum typec_cc_status src_rp; /* work only if pd_supported == false */ enum typec_cc_status cc1; enum typec_cc_status cc2; @@ -323,6 +324,7 @@ struct tcpm_port { bool attached; bool connected; + bool pd_supported; enum typec_port_type port_type; /* @@ -815,6 +817,9 @@ static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port) int nr_pdo = port->nr_src_pdo; int i; + if (!port->pd_supported) + return port->src_rp; + /* * Search for first entry with matching voltage. * It should report the maximum supported current. @@ -3568,9 +3573,11 @@ static int tcpm_src_attach(struct tcpm_port *port) if (ret < 0) return ret; - ret = port->tcpc->set_pd_rx(port->tcpc, true); - if (ret < 0) - goto out_disable_mux; + if (port->pd_supported) { + ret = port->tcpc->set_pd_rx(port->tcpc, true); + if (ret < 0) + goto out_disable_mux; + } /* * USB Type-C specification, version 1.2, @@ -3600,7 +3607,8 @@ static int tcpm_src_attach(struct tcpm_port *port) out_disable_vconn: tcpm_set_vconn(port, false); out_disable_pd: - port->tcpc->set_pd_rx(port->tcpc, false); + if (port->pd_supported) + port->tcpc->set_pd_rx(port->tcpc, false); out_disable_mux: tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE, TYPEC_ORIENTATION_NONE); @@ -3804,6 +3812,20 @@ static enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc) } } +static enum typec_cc_status tcpm_pwr_opmode_to_rp(enum typec_pwr_opmode opmode) +{ + switch (opmode) { + case TYPEC_PWR_MODE_USB: + return TYPEC_CC_RP_DEF; + case TYPEC_PWR_MODE_1_5A: + return TYPEC_CC_RP_1_5; + case TYPEC_PWR_MODE_3_0A: + case TYPEC_PWR_MODE_PD: + default: + return TYPEC_CC_RP_3_0; + } +} + static void run_state_machine(struct tcpm_port *port) { int ret; @@ -3914,6 +3936,10 @@ static void run_state_machine(struct tcpm_port *port) if (port->ams == POWER_ROLE_SWAP || port->ams == FAST_ROLE_SWAP) tcpm_ams_finish(port); + if (!port->pd_supported) { + tcpm_set_state(port, SRC_READY, 0); + break; + } port->upcoming_state = SRC_SEND_CAPABILITIES; tcpm_ams_start(port, POWER_NEGOTIATION); break; @@ -4161,7 +4187,10 @@ static void run_state_machine(struct tcpm_port *port) current_lim = PD_P_SNK_STDBY_MW / 5; tcpm_set_current_limit(port, current_lim, 5000); tcpm_set_charge(port, true); - tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0); + if (!port->pd_supported) + tcpm_set_state(port, SNK_READY, 0); + else + tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0); break; } /* @@ -4389,7 +4418,8 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_vbus(port, true); if (port->ams == HARD_RESET) tcpm_ams_finish(port); - port->tcpc->set_pd_rx(port->tcpc, true); + if (port->pd_supported) + port->tcpc->set_pd_rx(port->tcpc, true); tcpm_set_attached_state(port, true); tcpm_set_state(port, SRC_UNATTACHED, PD_T_PS_SOURCE_ON); break; @@ -5898,6 +5928,7 @@ EXPORT_SYMBOL_GPL(tcpm_tcpc_reset); static int tcpm_fw_get_caps(struct tcpm_port *port, struct fwnode_handle *fwnode) { + const char *opmode_str; const char *cap_str; int ret; u32 mw, frs_current; @@ -5932,22 +5963,37 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, return ret; port->typec_caps.type = ret; port->port_type = port->typec_caps.type; + port->pd_supported = !fwnode_property_read_bool(fwnode, "pd-unsupported"); port->slow_charger_loop = fwnode_property_read_bool(fwnode, "slow-charger-loop"); if (port->port_type == TYPEC_PORT_SNK) goto sink; - /* Get source pdos */ - ret = fwnode_property_count_u32(fwnode, "source-pdos"); - if (ret <= 0) - return -EINVAL; + /* Get Source PDOs for the PD port or Source Rp value for the non-PD port */ + if (port->pd_supported) { + ret = fwnode_property_count_u32(fwnode, "source-pdos"); + if (ret == 0) + return -EINVAL; + else if (ret < 0) + return ret; - port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS); - ret = fwnode_property_read_u32_array(fwnode, "source-pdos", - port->src_pdo, port->nr_src_pdo); - if ((ret < 0) || tcpm_validate_caps(port, port->src_pdo, - port->nr_src_pdo)) - return -EINVAL; + port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS); + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", + port->src_pdo, port->nr_src_pdo); + if (ret) + return ret; + ret = tcpm_validate_caps(port, port->src_pdo, port->nr_src_pdo); + if (ret) + return ret; + } else { + ret = fwnode_property_read_string(fwnode, "typec-power-opmode", &opmode_str); + if (ret) + return ret; + ret = typec_find_pwr_opmode(opmode_str); + if (ret < 0) + return ret; + port->src_rp = tcpm_pwr_opmode_to_rp(ret); + } if (port->port_type == TYPEC_PORT_SRC) return 0; @@ -5961,6 +6007,11 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, if (port->typec_caps.prefer_role < 0) return -EINVAL; sink: + port->self_powered = fwnode_property_read_bool(fwnode, "self-powered"); + + if (!port->pd_supported) + return 0; + /* Get sink pdos */ ret = fwnode_property_count_u32(fwnode, "sink-pdos"); if (ret <= 0) @@ -5977,9 +6028,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, return -EINVAL; port->operating_snk_mw = mw / 1000; - port->self_powered = fwnode_property_read_bool(fwnode, "self-powered"); - - /* FRS can only be supported byb DRP ports */ + /* FRS can only be supported by DRP ports */ if (port->port_type == TYPEC_PORT_DRP) { ret = fwnode_property_read_u32(fwnode, "new-source-frs-typec-current", &frs_current);