Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1004995pxf; Thu, 11 Mar 2021 22:36:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWId+fbkfemx40SQAJCOXa7Jf2SYhZtmsVIpiR7GF+G6rMyyYFoAK1mNIRm2RrQNJCF+Lp X-Received: by 2002:a17:906:d8c6:: with SMTP id re6mr6667189ejb.311.1615530981011; Thu, 11 Mar 2021 22:36:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615530981; cv=none; d=google.com; s=arc-20160816; b=Xg6Vrt/WObyLqNfkh51tblwRqlwM3+dYEYNGb+KwfqEGD+wrLjzkTySDDp7PRHAf8g h7LWqL8//mc0N4pWLL4fAK+ZujVBql296HDbAF7LKE2ncYumx5rEstfZ9yubKzseMdUW nhcRsJl55ODXr6jSAbQ3or8MKuRti57kA0zsApe9huYNgFZU4lW772qTNyumSSJcnabG 63AE6Ys39RIqAteN1ZJWwsEW/HFn3NV4d24BPsPu9BAbleX2aEhWYDXVuJppmR/d+Pq9 vAcszUcj2TETeTiLQk/2xr1V7Uo9eTOdBC3H3fxeBo5h68wpp4jVhKI28lVviaLnqt+t 2ztA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=2S11qT9RIwmKtMbHj/SRU+W48erwYAwCbBW3iK4A8WQ=; b=TiJVfHAM+xhsRsPljH43hYqESuYymbWy1Qm6HUuIaUd3J3FWIzeax/1TjnsYRArRli edr/NHacuq0ggEdh38ai+MODEfI5y/APehv8NKA8Lm99Q09SkEHbzFfl/b9odJsyuomt g65hMen/JJwA3pDERqJKPFmqOUdhMQE0cy0bhXADf1aZLKPZLd/yqNZcV43wgRo1nWjD IuWmBsc2Py35gUu6h2czkua2QBmVYr+NnV+1H3DCSxblV3hCGGBt6mrw2YLBGni/Wzwq wZISqGMi0+Yz+sCW1iGVfKVMU0N38+sz4lYJtNZ/CpEc5DM2m6g0J1JcnJHdiQyYLHcY /BRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aj4UIbgm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh28si3179724ejb.494.2021.03.11.22.35.58; Thu, 11 Mar 2021 22:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aj4UIbgm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbhCLFYx (ORCPT + 99 others); Fri, 12 Mar 2021 00:24:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbhCLFYu (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 8F1CCC061574 for ; Thu, 11 Mar 2021 21:24:50 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id n10so28166151ybb.12 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=ksYtMi5LR0MkkLmGB2VS50AycOwKF0pqjC6GddlFmiifnJt53zNQ0SmzlliN4+f/N0 jBARNygPqLMY0mPV7o2W8Ms00Ntk503JzJuHVWKB3I/BoWtkSrdPMIkukbjoipEBtcf/ pokCrzvZwaceui2v3njK16o2SZhSoEYlJ1Mv/bMpZk3su9bh+SgYr91FNDUUPqtJoxM6 WuRPYZrO77GzM+LNzQ6u6mGxapg/ftZxc54hV4VMAqtzXnrxezS/wtPxFJHNGt6LGX5L cNvnYI+lP5SU7Qx64z+p1F32l7sEzw+9l+DmXVdxEVY4plP/y5nMFd8FIhXpCLgn/egJ Hcog== X-Gm-Message-State: AOAM530dpFo8UxBczJETP1phq8n9BsNRBTzR/DrwYbCcIaAP7Jt3+Qnq 0/htU5wFD7Fnr+jtp0fxE9/+Ff9XzDc= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.31.0.rc2.261.g7f71774620-goog