From patchwork Thu Mar 11 10:03:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 399053 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=ham 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 B3E07C433DB for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 601EE64F85 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232191AbhCKKDj (ORCPT ); Thu, 11 Mar 2021 05:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbhCKKDU (ORCPT ); Thu, 11 Mar 2021 05:03:20 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CCFFC061760 for ; Thu, 11 Mar 2021 02:03:20 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b127so24939421ybc.13 for ; Thu, 11 Mar 2021 02:03:20 -0800 (PST) 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=CRNU10dE7NxeMKiM3/VubFTm8e+uK3lL18S+85iKjKQ=; b=cafRhH+x5rWf2c1lFP7ECa+O9orzzMObUYfuqhXIXmH/8sFQniXUbst9qKGfCtmEWf a9HNw1JscmQ7zirvQHuy7/A5M/a+rLhr07xMt9dmJDG4OK0TLgR5HmRA7qBh0HjY07Mh q03Fwg+iXTz69Mf6m41BA+jhYp8iwfdFtTyA+q1/7qiG9Sl+swDTU/XVbIz4Dvognkfc rzt7za27zMn5qPrM1MOH/XnXChWw/uZixXNV00YsupuR9FLiucwlPXcZjYwWbf+wC+A2 VXVfct/++arONw8a01nW1ZovtwIKf855RZXOs5D0q5kh52MzzTpevn7fLLikbo/H/Mc2 8+dQ== 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=CRNU10dE7NxeMKiM3/VubFTm8e+uK3lL18S+85iKjKQ=; b=iU2r+8M7zRTb4VDsaSHLj7AWyeGhC6BsMekLazw9ru97wbmvLAqWXuvk+omGs8qsFC L8U3AF6qGK9YHgv8EORtP2TsNRwzEmhi4BCkiFutIVm/ttj9jOGDZ+EvydinAC0H7Tcs WyGol08EHptuIiIvPS7QkamnGchGFi0QBTmsEWxkD2V1o22w2QOwyMqug1o4MADKCzXQ qseyv2JxQ5khRCmfO6ihjaIvd5kD8FmHKOY5A8c2qT7DN+DjV01NrbwrKzQXR0Vvf3LE TMHJHwgo6VUbCuPtMVS8sy2xtm9TFpjFTsu3lK8fc3De6cw1z0G8GOOoxwuSJAi0bYhP NpLQ== X-Gm-Message-State: AOAM532rXpBahwMH/WQIBDhtc8prU5xvOP/rVAJHCfivZWOXKPjooO1s WdCLjZfe7jw0qZbMx1fNJR3PX9slz+8= X-Google-Smtp-Source: ABdhPJwGroWnEcfRIYk/XLlG3oXkauoNAbxeMmveVpOyyWibs3L0OWadMvmEoy35hkvGkUbumZvPAc/9EI4= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a5b:690:: with SMTP id j16mr10696794ybq.251.1615456999256; Thu, 11 Mar 2021 02:03:19 -0800 (PST) Date: Thu, 11 Mar 2021 02:03:10 -0800 Message-Id: <20210311100313.3591254-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 1/4] usb: typec: tcpm: Add callback to notify pd_capable partner From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Rob Herring Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , devicetree@vger.kernel.org, Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This change informs lower level tcpc drivers of pd_capable partner. This is useful while setting current limit for the charging path. Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm/tcpm.c | 20 +++++++++++++++----- include/linux/usb/tcpm.h | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 11d0c40bc47d..e9886e850b84 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -952,6 +952,16 @@ static int tcpm_set_current_limit(struct tcpm_port *port, u32 max_ma, u32 mv) return ret; } +static void tcpm_set_pd_capable(struct tcpm_port *port, bool capable) +{ + tcpm_log(port, "Partner pd capable %s", capable ? "true" : "false"); + + if (port->tcpc->set_pd_capable) + port->tcpc->set_pd_capable(port->tcpc, capable); + + port->pd_capable = capable; +} + static int tcpm_set_attached_state(struct tcpm_port *port, bool attached) { return port->tcpc->set_roles(port->tcpc, attached, port->pwr_role, @@ -3444,7 +3454,7 @@ static int tcpm_src_attach(struct tcpm_port *port) if (ret < 0) goto out_disable_vconn; - port->pd_capable = false; + tcpm_set_pd_capable(port, false); port->partner = NULL; @@ -3509,7 +3519,7 @@ static void tcpm_reset_port(struct tcpm_port *port) tcpm_unregister_altmodes(port); tcpm_typec_disconnect(port); port->attached = false; - port->pd_capable = false; + tcpm_set_pd_capable(port, false); port->pps_data.supported = false; tcpm_set_partner_usb_comm_capable(port, false); @@ -3583,7 +3593,7 @@ static int tcpm_snk_attach(struct tcpm_port *port) if (ret < 0) return ret; - port->pd_capable = false; + tcpm_set_pd_capable(port, false); port->partner = NULL; @@ -3813,7 +3823,7 @@ static void run_state_machine(struct tcpm_port *port) */ /* port->hard_reset_count = 0; */ port->caps_count = 0; - port->pd_capable = true; + tcpm_set_pd_capable(port, true); tcpm_set_state_cond(port, SRC_SEND_CAPABILITIES_TIMEOUT, PD_T_SEND_SOURCE_CAP); } @@ -4074,7 +4084,7 @@ static void run_state_machine(struct tcpm_port *port) } break; case SNK_NEGOTIATE_CAPABILITIES: - port->pd_capable = true; + tcpm_set_pd_capable(port, true); tcpm_set_partner_usb_comm_capable(port, !!(port->source_caps[0] & PDO_FIXED_USB_COMM)); port->hard_reset_count = 0; diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 42fcfbe10590..d5d7293bc34d 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -112,6 +112,8 @@ enum tcpm_transmit_type { * Optional; The USB Communications Capable bit indicates if port * partner is capable of communication over the USB data lines * (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit. + * @set_pd_capable: + * Optional; Called to notify if the partner is pd capable. */ struct tcpc_dev { struct fwnode_handle *fwnode; @@ -144,6 +146,7 @@ struct tcpc_dev { bool pps_active, u32 requested_vbus_voltage); bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev); void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable); + void (*set_pd_capable)(struct tcpc_dev *dev, bool enable); }; struct tcpm_port; From patchwork Thu Mar 11 10:03:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 397801 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=-23.5 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, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham 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 79103C433E0 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16FCC64E89 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232201AbhCKKDk (ORCPT ); Thu, 11 Mar 2021 05:03:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbhCKKDW (ORCPT ); Thu, 11 Mar 2021 05:03:22 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EFBC061760 for ; Thu, 11 Mar 2021 02:03:22 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id g18so15041326qki.15 for ; Thu, 11 Mar 2021 02:03:22 -0800 (PST) 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=l9CMWPdWDhliYrHN/g/05oM0suTsXVO5bL0BBWp8xVQ=; b=PWe712s1TPhf8Wes9gxc0mJgydqlFrhOqr/zVo/FIMQjUrI87BLhHdZJCQcG3U/3d4 2IdEJ2Bxsl7OLDluzj/zIZKsKcELdEQnW0Byo7Y/BxotOJ6XqhZgVjyLdttUnkauH+c5 irENCVF6E0IqCOjOsxkTCNlwhNkD35JWux8qiWNA2rRBKTaMDJhjFE6YzZI2t6Ehq2g9 48uhRwcuFJ6KRwxm2yIcrbUOuf6acW1UTXDJTpBJVsUSNexNPUCapGRtrJPqkvsH5Z5s RomwmVw+wJeK0hN+zU2VBWqOQn2JUiAvlMyh+/8viUBo4Xlf95a1gAdUDxEfZz8WhfqI gXyg== 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=l9CMWPdWDhliYrHN/g/05oM0suTsXVO5bL0BBWp8xVQ=; b=eLz5BRG/2CcpOpohXyqQh07LQdEAjDkki5Pu+yZ3FZRD8XWsP1CMMdBCHPRwC5/i/R fiHdM4SzXeEszREcNuT4ioJsXfF7XxPmnxVlIdC3IuEmbQxjJqx1i/Dxy3/i+l/AO8Xt DJzof8nF3/NTqVHLF2zYNlHGfZOXQori44zQmuCI0ETZemQgKOVhQ5x4nrK39scwkCHm 1NbiHqRyHXw+0x9h0qbFRymBejkO96gBD/XfJ8SROcJSa0niLy+DAMxur72CBp2W+NjB ML14x0shSVzMiq9Lf210icwSHpxXyrbn0v9fFtbmxA54lmjuaVkLUuH4O0agowuYAGuw 4XVQ== X-Gm-Message-State: AOAM531sK5ISyaU9F43KjLBykylrSNmnr7DPuMvBsKq07eqLk2Ifx+tT Ory+WDRsBhwJncXz9YkRZBpzHghiedQ= X-Google-Smtp-Source: ABdhPJxWJw52lTOHAorcVvKKdbDVGEprFZqCIR2v+1inSvJ2s/QvAEBJg6tupvELlAQ5ynL8cWwBGRO9OKs= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a05:6214:12a1:: with SMTP id w1mr6851339qvu.57.1615457001221; Thu, 11 Mar 2021 02:03:21 -0800 (PST) Date: Thu, 11 Mar 2021 02:03:11 -0800 In-Reply-To: <20210311100313.3591254-1-badhri@google.com> Message-Id: <20210311100313.3591254-2-badhri@google.com> Mime-Version: 1.0 References: <20210311100313.3591254-1-badhri@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 2/4] usb: typec: tcpci: Add tcpc chip level callbacks From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Rob Herring Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , devicetree@vger.kernel.org, Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This change adds chip callbacks for the following operations: 1. Setting/getting vbus voltage and current limits. 2. Notifying presence of PD capable partner 3. Notifying port role 4. Notifying orientation Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm/tcpci.c | 45 +++++++++++++++++++++++++++++++++- drivers/usb/typec/tcpm/tcpci.h | 7 ++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 027afd7dfdce..35f229d1dde8 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -265,9 +265,16 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, if (ret < 0) return ret; - return regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, + ret = regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, (polarity == TYPEC_POLARITY_CC2) ? TCPC_TCPC_CTRL_ORIENTATION : 0); + if (ret < 0) + return ret; + + if (tcpci->data->set_cc_polarity) + tcpci->data->set_cc_polarity(tcpci, tcpci->data, polarity); + + return ret; } static void tcpci_set_partner_usb_comm_capable(struct tcpc_dev *tcpc, bool capable) @@ -395,6 +402,9 @@ static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached, if (ret < 0) return ret; + if (tcpci->data->set_roles) + tcpci->data->set_roles(tcpci, tcpci->data, attached, role, data); + return 0; } @@ -439,6 +449,36 @@ static bool tcpci_is_vbus_vsafe0v(struct tcpc_dev *tcpc) return !!(reg & TCPC_EXTENDED_STATUS_VSAFE0V); } +static void tcpci_set_pd_capable(struct tcpc_dev *tcpc, bool capable) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + + if (tcpci->data->set_pd_capable) + tcpci->data->set_pd_capable(tcpci, tcpci->data, capable); +} + +static int tcpci_get_current_limit(struct tcpc_dev *tcpc) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + + if (tcpci->data->get_current_limit) + return tcpci->data->get_current_limit(tcpci, tcpci->data); + + return 0; +} + +static int tcpci_set_current_limit(struct tcpc_dev *tcpc, u32 max_ma, u32 mv) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + int ret = 0; + + if (tcpci->data->set_current_limit) + ret = tcpci->data->set_current_limit(tcpci, tcpci->data, max_ma, + mv); + + return ret; +} + static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -744,6 +784,9 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) tcpci->tcpc.enable_frs = tcpci_enable_frs; tcpci->tcpc.frs_sourcing_vbus = tcpci_frs_sourcing_vbus; tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable; + tcpci->tcpc.set_pd_capable = tcpci_set_pd_capable; + tcpci->tcpc.set_current_limit = tcpci_set_current_limit; + tcpci->tcpc.get_current_limit = tcpci_get_current_limit; if (tcpci->data->auto_discharge_disconnect) { tcpci->tcpc.enable_auto_vbus_discharge = tcpci_enable_auto_vbus_discharge; diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h index 57b6e24e0a0c..6fdad15ce1f2 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h @@ -181,6 +181,13 @@ struct tcpci_data { void (*frs_sourcing_vbus)(struct tcpci *tcpci, struct tcpci_data *data); void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data, bool capable); + void (*set_pd_capable)(struct tcpci *tcpci, struct tcpci_data *data, bool capable); + int (*get_current_limit)(struct tcpci *tcpci, struct tcpci_data *data); + int (*set_current_limit)(struct tcpci *tcpci, struct tcpci_data *data, u32 max_ma, u32 mv); + void (*set_roles)(struct tcpci *tcpci, struct tcpci_data *data, bool attached, + enum typec_role role, enum typec_data_role data_role); + void (*set_cc_polarity)(struct tcpci *tcpci, struct tcpci_data *data, + enum typec_cc_polarity polarity); }; struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data); From patchwork Thu Mar 11 10:03:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 399052 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=ham 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 30402C4332B for ; Thu, 11 Mar 2021 10:04:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4D7164FC4 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbhCKKDk (ORCPT ); Thu, 11 Mar 2021 05:03:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbhCKKDY (ORCPT ); Thu, 11 Mar 2021 05:03:24 -0500 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 E8A15C061761 for ; Thu, 11 Mar 2021 02:03:23 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id k4so15152269qtd.20 for ; Thu, 11 Mar 2021 02:03:23 -0800 (PST) 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=Hcg8ctscEa0t8SSV4gNeUgkygeqJTngQzkOo9fh7MZE=; b=pY/arfFlAeunr2gBLh/qaucb9n4p2jHJsMQdzw2R0zgMiyRNgPIwWwpkUiUoegcP+P CpjC5aws7kQ6Br4CxtAGk8WrVQLzvTR4VOQdO9DrPZZ98A1Qd5hXZmEwmUM4b0XJIc/r ZeyVwVAH0W4hI3oowy8Rbr8SIoecXf+kenzXVRBpGloiUhf6mj2ESUI9PsWhSqaiAyjb PooBa28gYPzLgTGnN9eDzMrQaBmCUKYtNVe3UOC6oNFRu6eBd8WItgfFeqVdBAuXEMPN 26O2UrXUUVritRYagYxDjMjpKzRQAo2zLNBwA7Y2xwKe7NEHVaxri6uMV5okxs9LT3Gh RduA== 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=Hcg8ctscEa0t8SSV4gNeUgkygeqJTngQzkOo9fh7MZE=; b=Gnl2ipEaUxI1nu/InvCtDCmZxCxyv0MBFB7U6PbvRwfnYYOXrUFlWLRR07iBmt9Uxb FZDlgOTwpBfonH2gCNqS62TdKh9YYTAr13NdAHaus1PeWIiMXw+fgmZbDJiQxlNo9Bm2 3MkvgonWs5KTjx9/tza4rb7uskGUpgwUL716BqWgpejiVSLutzpfZBR9Nu3mq3M5Q9Zj O8Md/5465DGsoYWLRwl7AoDHssq+z1wu6ZE5MkE8aYdb05EnD7aAwpTF/1T09rr09PK4 pN3ETbY9VwQ889b5Cu4TFROs1FPLCvLlkXXXq25s/eFGmvEOyU4s/c5eeUAFi0Th2ncb rebg== X-Gm-Message-State: AOAM530LXDIkkxpdObD8ApOJXoyfDjb8JeGyEf3SbiRFF6iY0EFaszNB OyZxk4EuU5WCp3xCb1GnnUaL1U3FyUU= X-Google-Smtp-Source: ABdhPJwJfpnB5Bcd8nZ5NGE+1+XjO3DvogRTxHoA3Kak2RVpj+77JMe/TjEqDy0XIv3k30GGMUVXeMgRX9E= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a05:6214:1085:: with SMTP id o5mr6988474qvr.5.1615457003120; Thu, 11 Mar 2021 02:03:23 -0800 (PST) Date: Thu, 11 Mar 2021 02:03:12 -0800 In-Reply-To: <20210311100313.3591254-1-badhri@google.com> Message-Id: <20210311100313.3591254-3-badhri@google.com> Mime-Version: 1.0 References: <20210311100313.3591254-1-badhri@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 3/4] usb: typec: tcpci_maxim: configure charging & data paths From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Rob Herring Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , devicetree@vger.kernel.org, Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This change allows the driver to configure input current/voltage limit for the charging path. The driver sets current_max and voltage_max values of the power supply identified through chg-psy-name. The change also exposes the data_role and the orientation as a extcon interface for configuring the USB data controller. Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm/tcpci_maxim.c | 126 ++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c b/drivers/usb/typec/tcpm/tcpci_maxim.c index 041a1c393594..365ff4c18146 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim.c @@ -7,8 +7,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -46,6 +49,10 @@ struct max_tcpci_chip { struct device *dev; struct i2c_client *client; struct tcpm_port *port; + bool pd_capable; + bool attached; + struct power_supply *chg_psy; + struct extcon_dev *extcon; }; static const struct regmap_range max_tcpci_tcpci_range[] = { @@ -439,11 +446,92 @@ static int tcpci_init(struct tcpci *tcpci, struct tcpci_data *data) return -1; } +static int max_tcpci_get_current_limit(struct tcpci *tcpci, struct tcpci_data *data) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + union power_supply_propval val = {0}; + int ret; + + if (!chip->chg_psy) + return 0; + + ret = power_supply_get_property(chip->chg_psy, POWER_SUPPLY_PROP_CURRENT_MAX, &val); + return ret < 0 ? ret : val.intval; +} + +static int max_tcpci_set_current_limit(struct tcpci *tcpci, struct tcpci_data *data, u32 max_ma, + u32 mv) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + union power_supply_propval val; + int ret; + + if (!chip->chg_psy) + return 0; + + val.intval = mv; + ret = power_supply_set_property(chip->chg_psy, POWER_SUPPLY_PROP_VOLTAGE_MAX, &val); + if (ret < 0) + return ret; + + /* + * Disregard 0mA vote for Rp-default value. Rp-default current values + * would be inferred from other sources such BC1.2 and data stack. + */ + if (!chip->pd_capable && max_ma == 0 && chip->attached) + return 0; + + val.intval = max_ma; + return power_supply_set_property(chip->chg_psy, POWER_SUPPLY_PROP_CURRENT_MAX, &val); +} + +static void max_tcpci_set_pd_capable(struct tcpci *tcpci, struct tcpci_data *data, bool capable) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + + chip->pd_capable = capable; +} + +static void max_tcpci_set_roles(struct tcpci *tcpci, struct tcpci_data *data, bool attached, + enum typec_role role, enum typec_data_role data_role) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + + chip->attached = attached; + + if (!attached) { + extcon_set_state_sync(chip->extcon, EXTCON_USB_HOST, 0); + extcon_set_state_sync(chip->extcon, EXTCON_USB, 0); + return; + } + + extcon_set_state_sync(chip->extcon, data_role == TYPEC_HOST ? EXTCON_USB_HOST : EXTCON_USB, + 1); +} + +static void max_tcpci_set_cc_polarity(struct tcpci *tcpci, struct tcpci_data *data, + enum typec_cc_polarity polarity) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + + extcon_set_property(chip->extcon, EXTCON_USB, EXTCON_PROP_USB_TYPEC_POLARITY, + (union extcon_property_value)(int)polarity); + extcon_set_property(chip->extcon, EXTCON_USB_HOST, EXTCON_PROP_USB_TYPEC_POLARITY, + (union extcon_property_value)(int)polarity); +} + +static const unsigned int usbpd_extcon[] = { + EXTCON_USB, + EXTCON_USB_HOST, +}; + static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id) { int ret; struct max_tcpci_chip *chip; u8 power_status; + char *chg_psy_name; + struct device_node *dn; chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) @@ -472,6 +560,11 @@ static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id chip->data.auto_discharge_disconnect = true; chip->data.vbus_vsafe0v = true; chip->data.set_partner_usb_comm_capable = max_tcpci_set_partner_usb_comm_capable; + chip->data.get_current_limit = max_tcpci_get_current_limit; + chip->data.set_current_limit = max_tcpci_set_current_limit; + chip->data.set_pd_capable = max_tcpci_set_pd_capable; + chip->data.set_roles = max_tcpci_set_roles; + chip->data.set_cc_polarity = max_tcpci_set_cc_polarity; max_tcpci_init_regs(chip); chip->tcpci = tcpci_register_port(chip->dev, &chip->data); @@ -484,9 +577,38 @@ static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id if (ret < 0) goto unreg_port; + dn = dev_of_node(&client->dev); + if (!dn) { + dev_err(&client->dev, "of node not found\n"); + ret = -EINVAL; + goto unreg_port; + } + chg_psy_name = (char *)of_get_property(dn, "chg-psy-name", NULL); + if (chg_psy_name) + chip->chg_psy = power_supply_get_by_name(chg_psy_name); + + chip->extcon = devm_extcon_dev_allocate(&client->dev, usbpd_extcon); + if (IS_ERR(chip->extcon)) { + dev_err(&client->dev, "Error allocating extcon: %ld\n", PTR_ERR(chip->extcon)); + ret = PTR_ERR(chip->extcon); + goto psy_put; + } + + ret = devm_extcon_dev_register(&client->dev, chip->extcon); + if (ret < 0) { + dev_err(&client->dev, "failed to register extcon device"); + goto psy_put; + } + + extcon_set_property_capability(chip->extcon, EXTCON_USB, EXTCON_PROP_USB_TYPEC_POLARITY); + extcon_set_property_capability(chip->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_TYPEC_POLARITY); + device_init_wakeup(chip->dev, true); return 0; - +psy_put: + if (chip->chg_psy) + power_supply_put(chip->chg_psy); unreg_port: tcpci_unregister_port(chip->tcpci); @@ -499,6 +621,8 @@ static int max_tcpci_remove(struct i2c_client *client) if (!IS_ERR_OR_NULL(chip->tcpci)) tcpci_unregister_port(chip->tcpci); + if (chip->chg_psy) + power_supply_put(chip->chg_psy); return 0; } From patchwork Thu Mar 11 10:03:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 397800 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=ham 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 E8605C43381 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8D1764E89 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbhCKKDl (ORCPT ); Thu, 11 Mar 2021 05:03:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbhCKKD0 (ORCPT ); Thu, 11 Mar 2021 05:03:26 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F63C061760 for ; Thu, 11 Mar 2021 02:03:26 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id b127so24939711ybc.13 for ; Thu, 11 Mar 2021 02:03:26 -0800 (PST) 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=534m+kMNorM/hxc5w1yoj67wqGOeEoCsnzauQdFx+kI=; b=hNK5MMo/C9ZN3cDfxO7yrRJqL9GpFKqI+Cia9i56YWy1blvKj3gV9r3pLgRe1ZRQb0 SkDAoZKYYwJmnhGVVYgZs50Gb7A5jDf4JcQ+YtxxYVkGMH9BbVCbvM+qQpggN5R+zb1l GMztgdyKxsaceqWsSiR4dhsIqUqjeHDU+qrTm6lCxLPCGy1X44ygRUDhpbspDNgQaFHl Xi2RsbmXmxrQMRg7A/yaZ/0A37ZCUKqpK1+UjtfpWprdtCpROsK94kMHxVAeO8dzOLsR 4O+plzviGgi5RDhzC5w8brTfSbXVRSLtTMSz0AFYwxR1rjm/VWdXBo92K0JHDipoz7jO iaCg== 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=534m+kMNorM/hxc5w1yoj67wqGOeEoCsnzauQdFx+kI=; b=jcKiTh2kwqKx2DWaRM+QzAh0ToBexqNIo5pXPQ3wBrtKJCHsZGhHNKZ5qmRiztbrMc sQ0ei/4QJuWEbo8QEdkYybMSxLC7H8BZ3V675KB2hpCq2LLfxagbVMX87YdkhsQKI97h B8oaw0bxSsa6sHTrjU8Z4+4WSk7ramcCEN3OoEcm6gxpN1UrlJy5zkxd3KhpSIxTRi9W TAE40S0sP45xI2+SbGOATeUhsxujNAjt8iXZMrFCUkom/Ou+Ug4VtvH6Tyi+xeKrtjG1 lab0fEUd0bgEqEWG6QAs80hYuzidNqPl1eQUn9Brpk6p87XvsWaVN+f1VbZ0GG3UIK1q X0zg== X-Gm-Message-State: AOAM5339n5/UnSrAgWLC1Y/o5CApYh4X6X1vnU3yvlK3QpsmbLiUnOOj 5FVbWwhbLCF7nHL83u4S5ttzuNOe1zw= X-Google-Smtp-Source: ABdhPJxZdwOgMxSl7Vlrpf5BitKDEqLo+2OgGyy6oevdllAkcbiHKMBiLtQ+sYMawxQxunE61Nuf7H4rZmM= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a25:918d:: with SMTP id w13mr9666411ybl.429.1615457005557; Thu, 11 Mar 2021 02:03:25 -0800 (PST) Date: Thu, 11 Mar 2021 02:03:13 -0800 In-Reply-To: <20210311100313.3591254-1-badhri@google.com> Message-Id: <20210311100313.3591254-4-badhri@google.com> Mime-Version: 1.0 References: <20210311100313.3591254-1-badhri@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 4/4] dt-bindings: usb: Add chg-psy-name property Maxim 33359 binding From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Rob Herring Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , devicetree@vger.kernel.org, Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org chg-psy-name is an optional string property used to indicate the power supply object for which the current/voltage_max limits have to be set. Signed-off-by: Badhri Jagan Sridharan --- Documentation/devicetree/bindings/usb/maxim,max33359.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/maxim,max33359.yaml b/Documentation/devicetree/bindings/usb/maxim,max33359.yaml index 93a19eda610b..3a278969109e 100644 --- a/Documentation/devicetree/bindings/usb/maxim,max33359.yaml +++ b/Documentation/devicetree/bindings/usb/maxim,max33359.yaml @@ -28,6 +28,11 @@ properties: description: Properties for usb c connector. + chg-psy-name: + description: Power supply whose current/voltage_max values to be + configured. + $ref: /schemas/types.yaml#definitions/string + required: - compatible - reg @@ -49,7 +54,7 @@ examples: reg = <0x25>; interrupt-parent = <&gpa8>; interrupts = <2 IRQ_TYPE_LEVEL_LOW>; - + chg-psy-name = "main_charger"; connector { compatible = "usb-c-connector"; label = "USB-C";