From nobody Mon Feb 9 11:47:49 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 2BE7413B580 for ; Sun, 1 Sep 2024 04:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163640; cv=none; b=HyZHDGMCLrfONBXbtQQ0vtfe+PjrNvq5T/RJ/Lb1cJez1TqRwVG0jtU67YzEcWrOY07sD+hkwnDJ0biY2MWENheA0EfyIoFdUTN0Y3p7Bk7QaqihqyhMXdcP3sV2adhQr2vpkMpoV8L7K2FtF55B3E6E6R/4zpQpLr/w2hlY+LU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163640; c=relaxed/simple; bh=qY6RFdgdEz4w9jQTLOHoc3XmVl5kjOyodlnHhwG34MY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u8NA3M63M6zbrmaf7xp3fgeyQ9FwJzucYq9TCHL2piOCmdFLL9i4UtxojQ5wLCZfrc+puYMut+hzW/nxKtXGQ5a70Q4XxXEW6eJBHXkz5jWyIMcKkBnSfLei4RIAH+SGs9kJQfl7QOWKrqL1RarYm/OaqES11Rw/k8777Gu5U9Q= 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=XosWRfMy; arc=none smtp.client-ip=209.85.214.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XosWRfMy" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-202376301e6so24761925ad.0 for ; Sat, 31 Aug 2024 21:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163637; x=1725768437; 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=EnT+TkOPiwvRqtG4XdBzNIXwEpZ2e3WbsaKfU3N0MOw=; b=XosWRfMy30FNjhHcntK0aamG16FStgjIk2sbxV07QZARrI1n/vWg1aB4t4LuC+1A2Z 6c8dWkr/eLO/FzqvkWNhVz4JWe/UwzOGU8KJS6U7wEPz1WkMTrHEltba5fxTWDBiD1M+ LNFY9UZv/PXJELNBF2s5Gl2guENOdT4m+mcGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163637; x=1725768437; 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=EnT+TkOPiwvRqtG4XdBzNIXwEpZ2e3WbsaKfU3N0MOw=; b=MxxWb17lPDJ7VSFWRdQDHC1mKNzbONpSFJvOf8lHz5l42hqFXkf4WNI85zA53xtt3y 9h/nTRwuUl/bXXO7xuoeUcq5fv7qUjF/BfzNFE67nOufPhliWoE052efLyItsNNyyhCL M1ucaeGKwh4tEeRTF0DARNZqaWd6vinimQ+PC8GPAC2PP+/gNU916B540bvBLh3DBV2b JKgveYONyQHWhNNQHLw6KA98/c2NtfbII4omxvO28eifLM6Yr9f+IbhHtjEEToZgvW/X d6Q/VsGxWITnXDenRH0TttyxHvOrPYUChcHOsQXWtAJ+nrI7h2t4oZgiDTfuK0EKG4pE CV4Q== X-Gm-Message-State: AOJu0YwJMBY5WT9gIwcfwbK92ebfuRcLiw6yhcpQW7fmyDzG9XEv+YAi uV5Kxhf0cTwM4uDsZM9y4VoGcxRLck9Lj8EWXHvx5PI7kTFEfBEpoosCQqFSXw== X-Google-Smtp-Source: AGHT+IFy6qneRh0JJN2K30z3cDl+DrJ4fLZ39NN7FVzA1lAH0njyn66SGUGcS/pbvoFHuvYriZC5zA== X-Received: by 2002:a17:903:1209:b0:1fa:1dd8:947a with SMTP id d9443c01a7336-2050c40deccmr100312495ad.46.1725163637193; Sat, 31 Aug 2024 21:07:17 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205152b12c7sm46853475ad.56.2024.08.31.21.07.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:16 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 07/18] drm/bridge: dp_typec: Support USB Type-C orientation Date: Sat, 31 Aug 2024 21:06:45 -0700 Message-ID: <20240901040658.157425-8-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register an orientation switch for each type-c output node to support flipping the lane mapping when the port is in reverse orientation. Only do this when the orientation-switch property is present. This is mostly useful for the case where the DP lanes are directly connected to the usb-c-connector and the device doesn't have an orientation switch wired down on the board between the connector and the DP controller. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Cc: Dmitry Baryshkov Signed-off-by: Stephen Boyd --- drivers/gpu/drm/bridge/aux-hpd-bridge.c | 77 +++++++++++++++++++++---- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/brid= ge/aux-hpd-bridge.c index 32565f88ade7..d2832e6481d7 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -47,12 +47,16 @@ struct drm_dp_typec_bridge_data; /** * struct drm_dp_typec_bridge_typec_port - USB type-c port associated with= DP bridge * @lane_mapping: Physical (array index) to logical (array value) USB type= -C lane mapping + * @orientation: Orientation of USB type-c port * @mode_switch: DP altmode switch + * @orientation_switch: USB type-c orientation switch * @typec_data: Back pointer to type-c bridge data */ struct drm_dp_typec_bridge_typec_port { u32 lane_mapping[NUM_USB_SS]; + enum typec_orientation orientation; struct typec_mux_dev *mode_switch; + struct typec_switch_dev *orientation_switch; struct drm_dp_typec_bridge_data *typec_data; }; =20 @@ -378,17 +382,35 @@ static int dp_lane_to_typec_lane(enum dp_lane lane) return -EINVAL; } =20 -static int typec_to_dp_lane(enum usb_ss_lane lane) +static int typec_to_dp_lane(enum usb_ss_lane lane, + enum typec_orientation orientation) { - switch (lane) { - case USB_SSRX1: - return DP_ML3; - case USB_SSTX1: - return DP_ML2; - case USB_SSTX2: - return DP_ML0; - case USB_SSRX2: - return DP_ML1; + switch (orientation) { + case TYPEC_ORIENTATION_NONE: + case TYPEC_ORIENTATION_NORMAL: + switch (lane) { + case USB_SSRX1: + return DP_ML3; + case USB_SSTX1: + return DP_ML2; + case USB_SSTX2: + return DP_ML0; + case USB_SSRX2: + return DP_ML1; + } + break; + case TYPEC_ORIENTATION_REVERSE: + switch (lane) { + case USB_SSRX1: + return DP_ML0; + case USB_SSTX1: + return DP_ML1; + case USB_SSTX2: + return DP_ML3; + case USB_SSRX2: + return DP_ML2; + } + break; } =20 return -EINVAL; @@ -413,6 +435,7 @@ drm_dp_typec_bridge_assign_pins(struct drm_dp_typec_bri= dge_dev *typec_bridge_dev u32 conf, struct drm_dp_typec_bridge_typec_port *port) { + enum typec_orientation orientation =3D port->orientation; enum usb_ss_lane *lane_mapping =3D port->lane_mapping; struct auxiliary_device *adev =3D &typec_bridge_dev->adev; struct drm_aux_hpd_bridge_data *hpd_data =3D auxiliary_get_drvdata(adev); @@ -448,7 +471,7 @@ drm_dp_typec_bridge_assign_pins(struct drm_dp_typec_bri= dge_dev *typec_bridge_dev typec_lane =3D lane_mapping[typec_lane]; =20 /* Map logical type-c lane to logical DP lane */ - dp_lanes[i] =3D typec_to_dp_lane(typec_lane); + dp_lanes[i] =3D typec_to_dp_lane(typec_lane, orientation); } =20 return 0; @@ -496,6 +519,23 @@ static const struct drm_bridge_funcs drm_dp_typec_brid= ge_funcs =3D { .atomic_destroy_state =3D drm_atomic_helper_bridge_destroy_state, }; =20 +static int drm_dp_typec_bridge_orientation_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct drm_dp_typec_bridge_typec_port *port; + + /* + * Lane remapping is in drm_dp_typec_bridge_mode_switch_set(). Whenever + * an orientation changes the mode will switch in and out of DP mode, + * HPD will deassert and reassert so that + * drm_dp_typec_bridge_atomic_check() sees the proper state. + */ + port =3D typec_switch_get_drvdata(sw); + port->orientation =3D orientation; + + return 0; +} + static int drm_dp_typec_bridge_mode_switch_set(struct typec_mux_dev *mode_switch, struct typec_mux_state *state) @@ -544,7 +584,9 @@ drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_typ= ec_bridge_data *typec_dat struct drm_dp_typec_bridge_typec_port *port; size_t num_ports =3D typec_bridge_dev->num_typec_ports; struct typec_mux_desc mode_switch_desc =3D { }; + struct typec_switch_desc orientation_switch_desc =3D { }; struct fwnode_handle *fwnode; + bool orientation =3D of_property_read_bool(np, "orientation-switch"); const char *name; =20 port =3D devm_kcalloc(dev, num_ports, sizeof(*port), GFP_KERNEL); @@ -587,6 +629,19 @@ drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_ty= pec_bridge_data *typec_dat return PTR_ERR(port->mode_switch); } =20 + if (orientation) { + orientation_switch_desc.set =3D drm_dp_typec_bridge_orientation_set, + orientation_switch_desc.fwnode =3D fwnode; + orientation_switch_desc.drvdata =3D port; + orientation_switch_desc.name =3D name; + port->orientation_switch =3D typec_switch_register(dev, + &orientation_switch_desc); + if (IS_ERR(port->orientation_switch)) { + kfree(name); + return PTR_ERR(port->orientation_switch); + } + } + kfree(name); port++; } --=20 https://chromeos.dev