From patchwork Sat Feb 10 07:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 199221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1337942dyd; Fri, 9 Feb 2024 23:17:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPqhjVRQSy1S7EdeTxh0hynMVDmsGpKAJEzL7/93/zrAqggh+zeBUyakTO7uzFmYniNgB8 X-Received: by 2002:a50:ee03:0:b0:560:fd6c:e52d with SMTP id g3-20020a50ee03000000b00560fd6ce52dmr676361eds.11.1707549448596; Fri, 09 Feb 2024 23:17:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707549448; cv=pass; d=google.com; s=arc-20160816; b=1EkGroY8DWgT52beQOmX1axmEdmjhuIPCHDSiqNdBNCvfdgUuEbcHSqrYjkPTawzcH x09KupzkFJ3Go/yN7s6seDRw/hRm5ox+ccErcRUGcE7qGi/U0p7iC9xqa9vIGkJjbS55 UIVFmoqErUNG0nnsA8W4ZRZQ/OMJoT/biW/wd1/hGKOjxxpdOsat9OlUAakazVGBCnwj PD7JxaxI7pFIDeomwUYt/af6mk7ewN3dAIBfRTq5BSyW1hbSzcAIHGP+ZGR/fazvsBSm QZgcJeLMS536p2z4j2aKODcaXG45jRb1OQgb1wLVxuzOlVq1XQY5VDQIn1VMb68Hpj+p C/Cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=y6V0amUOjUWvw6MQgN3h/VqwRga/J7+mYEIAgmrb0/c=; fh=yLQVKMbCAJYQ0i8mGRdeIxhBKz7KZ5VDmiBdZsEomzE=; b=QToyimUjUr42rmj+PQ82EeByQmgwrRmk9XA5GQv5ZaG4OgxdfSgexyhYYCjBGjnW7Z lzDPLgGGFbPySPvK+KSs3SU5xj5gS3PgnlPooStF/9TXu9a3G9OU22oM4kmFjo7uwC2T 6Rgf1rX/UVlMdj4MStdmNWsLgGnQqrpWsqk1Y1DB2iBlUO7P0Y9CAlahcad1xlHdtWM3 HbJJLPUwyrXhUuWqM5qpAGiJSVshGSUIu2qAV1O89UY/XUKPkjUvDE8Oim5tXJWREf21 M7jrO5Y5XroiYZdpRVTPc5j4hyhBqrI/ucB4AkCWFeQacyXZhyWNSzOGChs/LOEqt2LD pjcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mAJpPFaX; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60322-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60322-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCU2MTBmzkUVq8Grc1WhnuqSl/H1wY71LTEige2vQF8h1VOuG7UdM0bS5QQx7oAmRlfyMOvNS8ueK+SExWbiYwHn1IZRXQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a3-20020a05640233c300b0055fe8b45abesi571014edc.569.2024.02.09.23.17.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 23:17:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60322-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mAJpPFaX; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60322-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60322-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 47EBB1F22F0B for ; Sat, 10 Feb 2024 07:16:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF77B3D0B8; Sat, 10 Feb 2024 07:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mAJpPFaX" Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A53003B7AC for ; Sat, 10 Feb 2024 07:10:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707549010; cv=none; b=iHDqsKFRT+jcMMhc9XhlsktxIQOHg3/rTKlVHYHCHZl/+6jMbtFHyu/VBDmCX9ps7qZGFdlEwwV2xQHqRf/sMpPrVNaSo3PxSPyQ1VMxj/QlPc3Tq9iDeHfLb2Cq7cLlFvjBx0m93/k+ZfTESrjtPyshTFja0WSQHX3X9kDUNn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707549010; c=relaxed/simple; bh=EG0cKUa80lUC/mdhsPXkhNNLPHcQfpDmZUDBjhurXzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RJyhlaS/J/rpefsIsraP0Rzb/0O1pX0TGOwe3NO7GZhulhpdGazQXymBsTzQA3u2oijnKy2em67ZDIsBF42+/5WmfxgUaz3Oq0nN0s4TCyp7QsjtR3Ir+5sV49GzS9le3QB+tV1iD5nkbi6eDdC1l80az3NW2XOylhZUqLU/yBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=mAJpPFaX; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e1270e8cd3so692920a34.1 for ; Fri, 09 Feb 2024 23:10:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707549007; x=1708153807; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y6V0amUOjUWvw6MQgN3h/VqwRga/J7+mYEIAgmrb0/c=; b=mAJpPFaXHex+H0NNLvG47iF4lNzSiieP4pUS3X8cCwmMzqbzyLdzFHhGsK+cH7yg3z WmiIpqqsMbhMUCBAVDYKwKFKgDZ1OZ4AUPS3NdqdegjUR5j+A5yi+zaikr+hatHpfH0O 828MP+Q+a6WiotnIil0ppKxJN11DSMpClRGTI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707549007; x=1708153807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y6V0amUOjUWvw6MQgN3h/VqwRga/J7+mYEIAgmrb0/c=; b=bA/Flk/0etK/BU7rz+SEHRSkLf9oLePApICGb2dnsEwCA6HfGzg4j6hvWjE9g+orFK JqfrBg8C+wDcYr4b5ucnIlCAOXmZDt4Zami4654ddVGOSfL1UC3mebUMPT2Jk1kqIdQZ ihtlCqLhys4WF2hRLQ1N3CGbTm/I1e1AkEcuuF+sw/KkpXHurs4j15A7mXyRsUZXlYEm rwiY3uZXUivgUPmCEjE1m+8+r0FE4HDyW00GvlG/HUDUYCKMFmcoHEyLP1Y0NT4aYOYT qSjwseFfJhlZcGOLC9sb8lnM/gmVnHKTDw6U8X3zZ8UKIV68V5yxXpp/vGpc3Eq5NWW5 MA2A== X-Gm-Message-State: AOJu0YzAJP/WvV2mg+VwSx3ZGBBs/fUc+vwI8CLEbLHRGkP+Hz9C80Za 4xumvnbgRhqZqj5JALb5UCF5xxrYKTMKawnVKlGO+BTbZKX61tr2UqqY1aNWuA== X-Received: by 2002:a05:6358:33a5:b0:178:94bc:72f1 with SMTP id i37-20020a05635833a500b0017894bc72f1mr2096204rwd.22.1707549006715; Fri, 09 Feb 2024 23:10:06 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWaLSbKYBfB1kta5BCH5EdLApsxMVyPshOqjiQkEGr1RgU09aCNI7J26PA5y6zB52NocFHPNEZcSqExxzEebPG0kVUARyga8iDavpXgO/KXj20AkjZcB7wdsTX1/URZ2Nur6K2cfRUMcMqxIorJHw4CLpKd98bgpdp3nq0wUCa3LZzrKJVnVn10AIP2QIsykTSet7oZaAoJxUbbOPTk6nl2OQS0uBX0yVVG6x7OyBWN+x2TGSPTlG+d3mtxW22pMdHjnxeFjLBP9FoLjOJcpjpoBIoDVEv7UUdvnBICbxgiDOO/v3HZVimalG+xqyrgCAwkwHxZ6TDG4Ak651HwlJTFEu+Jah1s+9B9qu0tLmRn08YMO+1n1A== Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id p6-20020a625b06000000b006db05eb1301sm1726988pfb.21.2024.02.09.23.10.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 23:10:06 -0800 (PST) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Prashant Malani , Benson Leung , Tzung-Bi Shih Subject: [PATCH 16/22] platform/chrome: cros_typec_switch: Support orientation-switch Date: Fri, 9 Feb 2024 23:09:27 -0800 Message-ID: <20240210070934.2549994-17-swboyd@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org> References: <20240210070934.2549994-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790495370254476308 X-GMAIL-MSGID: 1790495370254476308 Register an orientation switch with the typec subsystem when the 'orientation-switch' DT property is present. In these sorts of hardware designs, the DP phy lanes are wired directly to the usb-c-connector. The EC signals entry and exit of DP mode on the port, and the DP phy lanes are assigned to the pins based on the port orientation (normal or reverse). Stash the orientation of the port and simply wait for the atomic_check phase to request the desired DP lane assignment (normal or reverse). Don't restrict this to the presence of the mode-switch property because it's possible for this device to only be an orientation-switch, in which case the DP mode entry is signaled externally (e.g. through an HPD pin on the DP source). Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/platform/chrome/cros_typec_switch.c | 84 ++++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index adcbf8f44c98..c22c2531327a 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -38,9 +38,11 @@ struct cros_typec_dp_bridge { struct cros_typec_port { int port_num; struct typec_mux_dev *mode_switch; + struct typec_switch_dev *orientation_switch; struct typec_retimer *retimer; size_t num_dp_lanes; u32 lane_mapping[USBC_LANES_COUNT]; + enum typec_orientation orientation; struct cros_typec_switch_data *sdata; }; @@ -245,6 +247,21 @@ static int cros_typec_mode_switch_set(struct typec_mux_dev *mode_switch, return 0; } +static int cros_typec_dp_port_orientation_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct cros_typec_port *port = typec_switch_get_drvdata(sw); + + /* + * Lane remapping is in cros_typec_dp_bridge_atomic_check(). Whenever + * an orientation changes HPD will go low and then high again so the + * atomic check handles the orientation change. + */ + port->orientation = orientation; + + return 0; +} + static int cros_typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) { struct cros_typec_port *port = typec_retimer_get_drvdata(retimer); @@ -280,6 +297,21 @@ static int cros_typec_register_mode_switch(struct cros_typec_port *port, return PTR_ERR_OR_ZERO(port->mode_switch); } +static int cros_typec_register_orientation_switch(struct cros_typec_port *port, + struct fwnode_handle *fwnode) +{ + struct typec_switch_desc orientation_switch_desc = { + .fwnode = fwnode, + .drvdata = port, + .name = fwnode_get_name(fwnode), + .set = cros_typec_dp_port_orientation_set, + }; + + port->orientation_switch = typec_switch_register(port->sdata->dev, &orientation_switch_desc); + + return PTR_ERR_OR_ZERO(port->orientation_switch); +} + static int cros_typec_register_retimer(struct cros_typec_port *port, struct fwnode_handle *fwnode) { struct typec_retimer_desc retimer_desc = { @@ -328,17 +360,35 @@ static int dp_lane_to_typec_lane(unsigned int dp_lane) return -EINVAL; } -static int typec_to_dp_lane(unsigned int typec_lane) +static int typec_to_dp_lane(unsigned int typec_lane, + enum typec_orientation orientation) { - switch (typec_lane) { - case 0: - return 3; - case 1: - return 2; - case 2: - return 0; - case 3: - return 1; + switch (orientation) { + case TYPEC_ORIENTATION_NONE: + case TYPEC_ORIENTATION_NORMAL: + switch (typec_lane) { + case 0: + return 3; + case 1: + return 2; + case 2: + return 0; + case 3: + return 1; + } + break; + case TYPEC_ORIENTATION_REVERSE: + switch (typec_lane) { + case 0: + return 0; + case 1: + return 1; + case 2: + return 3; + case 3: + return 2; + } + break; } return -EINVAL; @@ -381,7 +431,7 @@ static int cros_typec_dp_bridge_atomic_check(struct drm_bridge *bridge, typec_lane = port->lane_mapping[typec_lane]; /* Map logical type-c lane to logical DP lane */ - in_lanes[i].logical = typec_to_dp_lane(typec_lane); + in_lanes[i].logical = typec_to_dp_lane(typec_lane, port->orientation); } return 0; @@ -509,6 +559,15 @@ static int cros_typec_register_port(struct cros_typec_switch_data *sdata, dev_dbg(dev, "Mode switch registered for index %u\n", index); } + if (fwnode_property_present(fwnode, "orientation-switch")) { + ret = cros_typec_register_orientation_switch(port, port_node); + if (ret) { + dev_err(dev, "Orientation switch register failed\n"); + goto out; + } + + dev_dbg(dev, "Orientation switch registered for index %u\n", index); + } out: if (np) @@ -556,7 +615,8 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) } } - if (fwnode_property_present(devnode, "mode-switch")) { + if (fwnode_property_present(devnode, "mode-switch") || + fwnode_property_present(devnode, "orientation-switch")) { fwnode = fwnode_graph_get_endpoint_by_id(devnode, 0, 0, 0); if (fwnode) { ret = cros_typec_register_dp_bridge(sdata, fwnode);