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: 12130777 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 D7B37C433E6 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 872C164F87 for ; Thu, 11 Mar 2021 10:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232194AbhCKKDj (ORCPT ); Thu, 11 Mar 2021 05:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbhCKKDU (ORCPT ); Thu, 11 Mar 2021 05:03:20 -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 09BA3C061574 for ; Thu, 11 Mar 2021 02:03:20 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id n10so24839383ybb.12 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=O53PfDtoIF7vow11eS863QA100ICS06RAgbZU5HKQSNVpYCaYFfJUY5yzvv7Qld3rD Wup+Ocgwaqsj7IBnhFpeI3NhrpHLy5BeLXZdjMNxxqXZxRMYar35lwejHCwXntKJqWdo sB7/N5anxjRkbJmtvx8mqGYRKTuYS5KoikRBopE/uvloz96rNdM278gucsvmxxAEIPXU GCtioRoYLs28xxmAExKOTyp3WKMD4gF/HohX6YsLnAeE9J84cOoJnt6oTeHFMsSZtInX Kles+ivvH5QeDMN4CcHJYwNQ42uJdnkSMp1RDdrd9d6Ux/knnBX1eCwqVrHAYuqVpvr7 HI6g== X-Gm-Message-State: AOAM532ko5uNa91yCKbsxRAwBZu98VIAdUW8YUjWau3BlLaH1sFmM2IZ OC3rhIUAJM+Rw3clc6i/ZeybXgk/b1E= 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: linux-usb@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: 12130779 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=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 52B7FC4332E 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 186D764F87 for ; Thu, 11 Mar 2021 10:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232209AbhCKKDk (ORCPT ); Thu, 11 Mar 2021 05:03:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232206AbhCKKDW (ORCPT ); Thu, 11 Mar 2021 05:03:22 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1152AC061761 for ; Thu, 11 Mar 2021 02:03:22 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id o70so14992567qke.16 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=hdU9wLPZLD2k/T52JVjpGz7BRnyrN7mG7GHy2j+b5gka3a8LaXAFwnwviXxJNYEk41 VPMEJ5OyGR8FWCDUqmjfI/gOICALu5fleD/lLc3KXHWufQQW21KpKzgWakRbVw+milXv lCrGiKEP9lhoIF28YZaN6JiNHSX0JWwsMNQ9OixNF9qFqJ5Dm5ci3FjIOp6PwdvEkRb/ zBJi9YDOi4T6FaO7kiITTIOxvbwPLiCV7UH8jdXhtY38q2uAuztpJo7f+O2OzjCLrpvT Hr7XCIssMZvPzLaVQOuspXj3yb0WxRfk1jnjgKPvIpzR6Sgb7kSqxiij9kduByNZ9Lzz PXfA== X-Gm-Message-State: AOAM531RwE4fpUE6Ko2/j4LnbfG5tTiqJJG4+Yu/NLvp+XxGxAReEpt2 26Nep3fxL9vu8yVsslDRD9rdGE5icKo= 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: linux-usb@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: 12130781 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 DE4EBC43331 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 9BEE564EB2 for ; Thu, 11 Mar 2021 10:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232212AbhCKKDl (ORCPT ); Thu, 11 Mar 2021 05:03:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232213AbhCKKDY (ORCPT ); Thu, 11 Mar 2021 05:03:24 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7197C061574 for ; Thu, 11 Mar 2021 02:03:23 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id e10so14765157qvr.17 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=T8Pm7/jk5eHiUl0fEbnMKdNObm/P+hd+0qzJTKY6tIee88wpnOtsBA018yFl94gP+q MXIl4Kux2c9WosLRncdYv+ZZuKNNrsZf9xTJ2dIMWjn1FpSHgjc/Zt5k/A1lu/LrsdpQ 3UsLtLkT2I58mggX5HNw5DtllpbkE9M3InZoXTIT1teAkCb0Phisg5iYlu+P4ke07R5l 1yXHzmPYTbze2P1IlI9Bn1a6B5WU1rIJ2J0sy57CMzzEEV2FB3/aCNVWx49emIWLGpra 5xunDYvKdm8gslqJnBddoO5eHksdF37hXJzNrWpajgmD3/iSYg7c7sZsJFti2s+mwf3j g0Pg== X-Gm-Message-State: AOAM531qzgX6n73HiwOsEdp5NQeJ718Y/qmneNNFUTlG02I/8KdEURkS 8QMH6WBk+aPfo5x4qL11dt/YSFIyMHc= 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: linux-usb@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: 12130783 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 D08D9C43332 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 3A9EB64F16 for ; Thu, 11 Mar 2021 10:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbhCKKDl (ORCPT ); Thu, 11 Mar 2021 05:03:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232215AbhCKKD0 (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 41707C061574 for ; Thu, 11 Mar 2021 02:03:26 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id v196so24973668ybv.3 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=k4bwT6+69VxZ0bch7/vwwgL0VG4cfdgYX90pXI+5wEzOqpdJAVCjkrQXQeWPmtG6q5 jIlRN8q4DqgpY89Vc2Z5oVUUUZPeKxz+RiiYwgDOEZX4zDXSqK1LzLU/VsvaZa3iizvx eXRwnkcVBYo/Itlmm5La/x1O3B4UjufCDGSpYpfC0y4x8HVLQUi8pF2NC05HqZ30CfXT iyUmSwWjPxJ7ychggAB82eHjTE5Yf0jWA/1z6vihzqQ+S46jMzP9d3Y/UnJ3TI0/NfyQ Kwrv/KTMqb9pIkPGsnissoQLGYGKGNH0o8RVJoExMBH2WuxA4rLCx4Q4ZjGK1Lv/txsX 0ZZA== X-Gm-Message-State: AOAM530TEj2SpZI+10LIYVApaPpZCSeFM9cYk6HKwKWlRx49vALuhLOG 1Y9M/qMeyTZJjqBTCCKzHOOE9OkLhh8= 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: linux-usb@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";