Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1042020ybh; Thu, 12 Mar 2020 16:06:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvnTFzd/Z3x/Mcm0nO4mYTkNYpmY6VPdFiJ9tIcx37MvJNq6hHeTSWg0oGQKu8+3h5O7dcw X-Received: by 2002:a54:4195:: with SMTP id 21mr4391743oiy.144.1584054384943; Thu, 12 Mar 2020 16:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584054384; cv=none; d=google.com; s=arc-20160816; b=hQh/4IQwVTJd370IW2elHQZxC+aAJxwVzdT2UWHLbJ+Y7QJHMpHJRnKwU1dT3s2sBz Q+Xv+GxLqBQ4PnLThCH4LPRbBmiwIi5f3cceGHEsSTAxmFHcqk+oQftpBhnmiCgSCVU+ s12KVCTAo1zhklxAUlcAtTapXyt2d+Fn0bVDXhEXjVSfU5SI9r61O3Vw23sRZvd1XyYq MBaYo4j8MxJBY91zTiZGhmlh8FKghXPpvWXouBd21geDtNJ4X4N76YVUAdr1mzRiHUrB fJKoq7l3y1afk4UPpVLggA18M92tclnqAb5jB46mPOprPb4+Eicapi5c9rhVN+FV5Sk5 AZpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ncunqT6Q2Vy6vrA/voMZUjSZG544U++p9lS8+YT4L9M=; b=EvreKnMFQ73Cd0WbvU7GYwqqdmLyc5jlOsyVty5LuB9w/62zsi3l17WJ7+PPgXM/kI EByr4f5IU7pKPX41AMPD71U7qpDeFqE/UVDfG7wm4Z9HBQJJL5utDYiYVMYfAjpwLzct 4QSziHZKyQffjeOGzQTcNYGoCjWGsRrwCc3c4cMJ/1DvYAIM26REwcY8tBZ5rk9GWzr7 K3t7ZGwKiAuG1gaZoCNz7PIt04FjTDadRCC/v+p1F8yb/jvsb1vOEa42zBdm0vrdUzvF OqbgkpxICf+p5o8CZJc9Q0n1Qjubx7f17Mvg8mA+PHSzy2JlES+XO1XBsnRChDJZKtT/ 9emw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=henknk4I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13si3457865oil.161.2020.03.12.16.06.12; Thu, 12 Mar 2020 16:06:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=henknk4I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbgCLXEl (ORCPT + 99 others); Thu, 12 Mar 2020 19:04:41 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45465 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLXEk (ORCPT ); Thu, 12 Mar 2020 19:04:40 -0400 Received: by mail-pg1-f196.google.com with SMTP id m15so3802354pgv.12 for ; Thu, 12 Mar 2020 16:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ncunqT6Q2Vy6vrA/voMZUjSZG544U++p9lS8+YT4L9M=; b=henknk4IkA91Io3No9BwOKGPjhOwM8HYAFx2yABedrp+UdqsI1XUrRgwwaNsazhAPJ y5uLtTIRYEJyh37eATF39A8GXBnnPxPrgZUlQs2bIn814FzuGTTpXd/8u4shYNbBUqM/ G7F85Lut0yNdmzV9Cdzw1dPhZTlFocw+zLFec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ncunqT6Q2Vy6vrA/voMZUjSZG544U++p9lS8+YT4L9M=; b=ObJKnzXJMTsiat5f4Q5WcFeVl8oXk+QE7GfwhlgHZfvQKUVMl8oCMbQFUcUSzJgrUv KLYhYsT1w4BYLFW8554bu851SJlj3vepWXPDCU+ecKpzyLF1AU8zKNvKGaGacFLPB+kj INxoCd446Ahx+nx8wPtyWZGJEDS8eLGPRgpRP7jYRjrJ0GWiiljCjhQ+YQA7jeT9keQM w+yqCu5S+vBFf24mGe4U1F/kF6MTvJnVo6q1kqyQpSDp4jNojwbWUcA46Hnsng6SMCKD w3Fle8EuMqX+P/UiVqgnDMEniluSui/YKOvSvCfpX5SK/n9J8zXazbZKyQB9C1UEyLnv Eh+w== X-Gm-Message-State: ANhLgQ2gLLFaGq50zxxSGB8iRbtVngGEeMcqcNljdsYpgiTf5dbNLok6 fB4bkmgtx4s01KrkyznRmhMahHDQ++Q= X-Received: by 2002:a62:15d3:: with SMTP id 202mr5310549pfv.231.1584054277481; Thu, 12 Mar 2020 16:04:37 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id v123sm28763161pfb.85.2020.03.12.16.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 16:04:36 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org Cc: Prashant Malani , Jon Flatley , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v4 4/4] platform/chrome: typec: Update port info from EC Date: Thu, 12 Mar 2020 15:57:19 -0700 Message-Id: <20200312225719.14753-5-pmalani@chromium.org> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200312225719.14753-1-pmalani@chromium.org> References: <20200312225719.14753-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After registering the ports at probe, get the current port information from EC and update the Type C connector class ports accordingly. Co-developed-by: Jon Flatley Signed-off-by: Prashant Malani --- Changes in v4: - No changes Changes in v3: - No changes. Changes in v2: - No changes drivers/platform/chrome/cros_ec_typec.c | 89 ++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 9f692eb78b322..874269c070739 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -172,6 +172,81 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, return ret; } +static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, + int port_num, struct ec_response_usb_pd_control *resp) +{ + struct typec_port *port = typec->ports[port_num]; + enum typec_orientation polarity; + + if (!resp->enabled) + polarity = TYPEC_ORIENTATION_NONE; + else if (!resp->polarity) + polarity = TYPEC_ORIENTATION_NORMAL; + else + polarity = TYPEC_ORIENTATION_REVERSE; + + typec_set_pwr_role(port, resp->role ? TYPEC_SOURCE : TYPEC_SINK); + typec_set_orientation(port, polarity); +} + +static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, + int port_num, struct ec_response_usb_pd_control_v1 *resp) +{ + struct typec_port *port = typec->ports[port_num]; + enum typec_orientation polarity; + + if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) + polarity = TYPEC_ORIENTATION_NONE; + else if (!resp->polarity) + polarity = TYPEC_ORIENTATION_NORMAL; + else + polarity = TYPEC_ORIENTATION_REVERSE; + typec_set_orientation(port, polarity); + typec_set_data_role(port, resp->role & PD_CTRL_RESP_ROLE_DATA ? + TYPEC_HOST : TYPEC_DEVICE); + typec_set_pwr_role(port, resp->role & PD_CTRL_RESP_ROLE_POWER ? + TYPEC_SOURCE : TYPEC_SINK); + typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? + TYPEC_SOURCE : TYPEC_SINK); +} + +static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) +{ + struct ec_params_usb_pd_control req; + struct ec_response_usb_pd_control_v1 resp; + int ret; + + if (port_num < 0 || port_num >= typec->num_ports) { + dev_err(typec->dev, "cannot get status for invalid port %d\n", + port_num); + return -EINVAL; + } + + req.port = port_num; + req.role = USB_PD_CTRL_ROLE_NO_CHANGE; + req.mux = USB_PD_CTRL_MUX_NO_CHANGE; + req.swap = USB_PD_CTRL_SWAP_NONE; + + ret = cros_typec_ec_command(typec, typec->cmd_ver, + EC_CMD_USB_PD_CONTROL, &req, sizeof(req), + &resp, sizeof(resp)); + if (ret < 0) + return ret; + + dev_dbg(typec->dev, "Enabled %d: 0x%hhx\n", port_num, resp.enabled); + dev_dbg(typec->dev, "Role %d: 0x%hhx\n", port_num, resp.role); + dev_dbg(typec->dev, "Polarity %d: 0x%hhx\n", port_num, resp.polarity); + dev_dbg(typec->dev, "State %d: %s\n", port_num, resp.state); + + if (typec->cmd_ver == 1) + cros_typec_set_port_params_v1(typec, port_num, &resp); + else + cros_typec_set_port_params_v0(typec, port_num, + (struct ec_response_usb_pd_control *) &resp); + + return 0; +} + static int cros_typec_get_cmd_version(struct cros_typec_data *typec) { struct ec_params_get_cmd_versions_v1 req_v1; @@ -218,7 +293,7 @@ static int cros_typec_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct cros_typec_data *typec; struct ec_response_usb_pd_ports resp; - int ret; + int ret, i; typec = devm_kzalloc(dev, sizeof(*typec), GFP_KERNEL); if (!typec) @@ -251,7 +326,19 @@ static int cros_typec_probe(struct platform_device *pdev) if (ret < 0) return ret; + for (i = 0; i < typec->num_ports; i++) { + ret = cros_typec_port_update(typec, i); + if (ret < 0) + goto unregister_ports; + } + return 0; + +unregister_ports: + for (i = 0; i < typec->num_ports; i++) + if (typec->ports[i]) + typec_unregister_port(typec->ports[i]); + return ret; } static struct platform_driver cros_typec_driver = { -- 2.25.1.481.gfbce0eb801-goog