From patchwork Fri Mar 12 05:24:42 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: 12133675 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 7449FC433DB for ; Fri, 12 Mar 2021 05:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22D1964F84 for ; Fri, 12 Mar 2021 05:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbhCLFYv (ORCPT ); Fri, 12 Mar 2021 00:24:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbhCLFYt (ORCPT ); Fri, 12 Mar 2021 00:24:49 -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 9F88DC061574 for ; Thu, 11 Mar 2021 21:24:49 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id t5so17228313qti.5 for ; Thu, 11 Mar 2021 21:24:49 -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=9hWh3mPPnMd+7sgA4bB4jM0VJmsYOSTpWV6kivY/w7E=; b=Hg5mX1cINvIihpuUY2ieD0jNJTtxVNv/hp0fSVy5nAJFPqF3Em4k41fBrc+F9CRuDo Bt2CM5Hl2yy5XGQLb3AocKOExxdHgblnCKasIOxbrXxWcEOQFtqEzaEgzGmX/kd0AJaG BgPWpr8oZzPdbpo+imT8XBf+uiQbDu8ZHTNXl+/uyZ3GwPBpwRPCRMhVdfg98x7OEY3d kFyS5RWDGi23lmnFgIoF9vSvvoqraqJdhCZl+m1XHEtO8duTeH5xkSrRg0vD4twKWvNR 1uAnzbuVBVfCNsRSs/zo/e43SrxJ2o41yPoBUF20h4albWrM0oqM0r71yAV81MEmiGO6 8MqA== 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=9hWh3mPPnMd+7sgA4bB4jM0VJmsYOSTpWV6kivY/w7E=; b=kh2I0DG04inK+ZaBsGcUie3NGZjgkhjQSaAcAQ2caOuAJvFPx6ZxXYlU8LhyUBy7vX X8RhDkzUxfhngJu5Ui0qmnKg/Bw0SMfjn/l5+bwyPyuPRP0YFl+Iu04WB2hHeR0F2AKc SNOktmRkLxIjuGRjHMoko3oEW4BOLHsIQXKxZMEtfplTtTQ49yoNn0+swp0k/1DsZW5W lSMlJkBTmygergobkICIpVa900fkzsTQJSlnI2U0Q6Ztvh61l3Mq/Ou5PIvjMbZWvn54 eEL3mKNZf/UT2VjiLMNP4NRXSyoKdSERl1ijn2Uqc/0kk1hfytHitSOanyHOO9iPQ5fO fnVg== X-Gm-Message-State: AOAM5329BcGGhXVieGk3STHjnTeUtJNvE6dRPN/u87zWGmY3VjBYkqRa emPjJv3W0PN6gbWQZ8KFjjZ3Hz5sKv8= X-Google-Smtp-Source: ABdhPJx1KL5uJPgcPfK8l/iWCtj8fel/ejPIwTJbt3G4JxwxOrZYyB1k7MQ0rPxvKf3N1sPLFwByhAqpX0I= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a05:6214:20ed:: with SMTP id 13mr10835104qvk.34.1615526687598; Thu, 11 Mar 2021 21:24:47 -0800 (PST) Date: Thu, 11 Mar 2021 21:24:42 -0800 Message-Id: <20210312052443.3797674-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 1/2] usb: typec: tcpci: Add tcpc chip level callbacks From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , 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. Notifying port role 2. Notifying orientation Signed-off-by: Badhri Jagan Sridharan --- Changes since V1: - Dropped changes related to get_/set_current_limit and pd_capable callback. Will send them in as separate patches. --- drivers/usb/typec/tcpm/tcpci.c | 12 +++++++++++- drivers/usb/typec/tcpm/tcpci.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 027afd7dfdce..c37bbb2e9961 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; } diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h index 57b6e24e0a0c..75a2c9b575b5 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h @@ -165,6 +165,12 @@ struct tcpci; * 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_roles: + * Optional; This callback notifies the TCPC driver of the resolved + * port role and attached status. + * @set_cc_polarity: + * Optional; This callback notifies the TCPC driver of the resolved + * polarity. */ struct tcpci_data { struct regmap *regmap; @@ -181,6 +187,10 @@ 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_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 Fri Mar 12 05:24:43 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: 12133677 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 95B18C433E9 for ; Fri, 12 Mar 2021 05:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57B6264F9A for ; Fri, 12 Mar 2021 05:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbhCLFYw (ORCPT ); Fri, 12 Mar 2021 00:24:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbhCLFYu (ORCPT ); Fri, 12 Mar 2021 00:24:50 -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 9A310C061761 for ; Thu, 11 Mar 2021 21:24:50 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id l10so28621849ybt.6 for ; Thu, 11 Mar 2021 21:24:50 -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=2S11qT9RIwmKtMbHj/SRU+W48erwYAwCbBW3iK4A8WQ=; b=aj4UIbgmGvYsEQWbjl9Vsd2HPvBeEwmASkBiqHcWT/rT89Zr6eUN1EjPTx0NtfJSli zdgzENaiEQFVSHCRacIuwKDofT7lP3lPXTekCmhXsVhDAx0ieW3vWZuXFqu7tDELu+3V 2clHbPNLSJSJupHclZIQr3MhGiAWomG/1N3N872h5XutJC7Ed6AfoCOfjVtsNcsknwZ1 2iLE2vrB3oCcFv7tVt/bmliGt6pnE1FUBX9cfW55MbOMWvpoeGjz4XaXgvGYTVPx3T6V aBxC9h9K+nskhpWdZHjiiAATgSuxdxQJHLygQYpsG1tNjuU6t+vnI7orOvn8hreCbBGA 5Rdw== 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=2S11qT9RIwmKtMbHj/SRU+W48erwYAwCbBW3iK4A8WQ=; b=b6N25FV1xqIutgXTOxUljYu5+YZ1fNvbxQcw5rM1nPiv3UiCfUBVbhl8bK6Sl3Qj4Y VcBtKBOtnrrhNSps+9s/g6VbmBRtcfBhNuh/DoD9gJVXWqRzpoFFcxdZszmNJtd2GA+N f+bFG+B7OxO96R9WYxYw0E6ZkOhe3NjKDdm9GsAP5i7P/pwQfQQfH4Cs3j7P9rokFgjF GVyXYbYS3I/yImbiW6vvyvJZROh7vg67P4PSbi8TwgGMHz305HufLq62dJVik3kjMhpb MFGb0BdYaO1cM6ga2Dv8feCX4EbqXqYP/janbOXJALx3jQXMwC7vRuSZEejBKwmunJeL zjeg== X-Gm-Message-State: AOAM533IyGzIuka6i4Izvf+aL8ZUw5fHM7WCEavwCM2h6EedZu1zYb1+ 5t1qAZdIUs05N6e+BLZe5lztUdvEHh0= X-Google-Smtp-Source: ABdhPJxWpuxqeI1jL5K9FwPmRrhsrAxOTQFEjo47De27XUVhg780+oU6yuN8CevAgt0j1+UM5fe8nws51yY= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:39e6:8b30:8665:4bec]) (user=badhri job=sendgmr) by 2002:a25:d3ca:: with SMTP id e193mr16651418ybf.379.1615526689690; Thu, 11 Mar 2021 21:24:49 -0800 (PST) Date: Thu, 11 Mar 2021 21:24:43 -0800 In-Reply-To: <20210312052443.3797674-1-badhri@google.com> Message-Id: <20210312052443.3797674-2-badhri@google.com> Mime-Version: 1.0 References: <20210312052443.3797674-1-badhri@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 2/2] usb: typec: tcpci_maxim: configure charging & data paths From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The change exposes the data_role and the orientation as a extcon interface for configuring the USB data controller. Signed-off-by: Badhri Jagan Sridharan --- Changes since V1: - Dropped changes related to get_/set_current_limit and pd_capable callback. Will send them in as separate patches. --- drivers/usb/typec/tcpm/tcpci_maxim.c | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c b/drivers/usb/typec/tcpm/tcpci_maxim.c index 041a1c393594..1210445713ee 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include #include @@ -46,6 +48,8 @@ struct max_tcpci_chip { struct device *dev; struct i2c_client *client; struct tcpm_port *port; + bool attached; + struct extcon_dev *extcon; }; static const struct regmap_range max_tcpci_tcpci_range[] = { @@ -439,6 +443,39 @@ static int tcpci_init(struct tcpci *tcpci, struct tcpci_data *data) return -1; } +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; @@ -472,6 +509,8 @@ 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.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,6 +523,23 @@ static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id if (ret < 0) goto unreg_port; + 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 unreg_port; + } + + ret = devm_extcon_dev_register(&client->dev, chip->extcon); + if (ret < 0) { + dev_err(&client->dev, "failed to register extcon device"); + goto unreg_port; + } + + 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;