From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 4BE651DD3BF for ; Mon, 19 Aug 2024 22:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107122; cv=none; b=aYx5bwCpJZI+ZUNz/5GurtRXa5Xv3bOLuHq1B1n0yOd8Dmc7BUC99Gfq6N3QJKzdXIEM/Lw4JolGFqmDwc7Co782WR8VdqnkPNFz6CXfMBv8sMiSrock5S79Tx+o9KZWX5GOf+UAjnwPtkA5TEfqtFJ9+EvDIwdm3mQca3cEfj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107122; c=relaxed/simple; bh=oz72Q0doCA/TDcpGgSX5zcBpwt/SNMECwtIx/YvZSjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FODWNLxghI3Lc3augnqek4J1v+fMxx4GmcKGpu3rG7jCbmTiRKAd9zRGrXD74e1VSKWpByyJBTQ+4sJ920irjXlcp/CsMV3LbqpBnqVzLHTOdgNgiPWk2f4L4tcA+AfM4sBcKouOP+hBQsP4P93NaIsnWBnc+e89sx3DTG9Ahw0= 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=VHqfJuv2; arc=none smtp.client-ip=209.85.214.180 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="VHqfJuv2" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-201fae21398so27537525ad.1 for ; Mon, 19 Aug 2024 15:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107119; x=1724711919; 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=h4epShKXY+hj6izJiuYDlNYe3lRcBUUzUpZVsUSgXYg=; b=VHqfJuv2twSE2IYIgTqX5JksntLZppO1+TTou/OvHTcU5wMnXPMR+kCggyM7G9IIOZ idNhOXIidVOHWT8uK3NKNcKCEb1BepmJtUdLbJ9jRVUA9S+xLeLY25aKYzwRPid9KVL9 tcqThN8rFStPpIrXT26E8HCX0i1VxAnM0YOas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107119; x=1724711919; 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=h4epShKXY+hj6izJiuYDlNYe3lRcBUUzUpZVsUSgXYg=; b=Pt8wx3lwqzwuZJx1XKImUzjAiRmeeTpcLGqW7xyj3ip7YXRKKUrZCGjDjWFMhn/jqh A7oi3h4I36wMLC28PXMm6yhbjIUj1MVSnlR8xTNa3N2zFcQxzLlJLGeOqMlF1wCHSz8q gxNKn9SaKMiBmDfy8lySxnVnAFWhFxol7wKPfuI0MyNV0z5lTQNGRAN6B+C3JK2Khq/4 QWF8V4BbUW8ohhIebSQvo+bg9WISoFTMEgmeDQBghsAYMDcO0ekOHcRzZxoFoGGJ7OYk CqovF5XGFtlwfEf5rFaeuiT5L29BE0cNlVGvsTPds8lkv7yMBEQB95SsXL0EmQbsxeI1 UAIQ== X-Gm-Message-State: AOJu0YyzVA+5p0Rp20GvuKwkypeFdrBr/w84jq/twj2JVRcVBpAKM3qi QHU3zQOiHUue8vMBcMTOOA7mRsNOl5Nz2WCs2esUgau1CoDZEGnRHnO/FCzH4w== X-Google-Smtp-Source: AGHT+IGpA/LzfoLsEqsJMHJfcUpzeVMRHpRXXvAFjX+lnlP4tWIDSijdKOHcbbCm+Y0fYngKipaQHw== X-Received: by 2002:a17:902:f547:b0:1fb:a077:a846 with SMTP id d9443c01a7336-20203e4f350mr122296765ad.3.1724107119275; Mon, 19 Aug 2024 15:38:39 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f02fff75sm67248655ad.13.2024.08.19.15.38.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:38 -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 v3 01/17] drm/atomic-helper: Introduce lane remapping support to bridges Date: Mon, 19 Aug 2024 15:38:15 -0700 Message-ID: <20240819223834.2049862-2-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Add support to the DRM atomic logic to support lane remapping between bridges, encoders and connectors. Typically lane mapping is handled statically in firmware, e.g. on DT we use the data-lanes property to assign lanes when connecting display bridges. Lane assignment is dynamic with USB-C DisplayPort altmodes, e.g. pin conf D assigns 2 lanes of DP to pins on the USB-C connector while pin conf C assigns 4 lanes of DP to pins on the USB-C connector. The lane assignment can't be set statically because the DP altmode repurposes USB-C pins for the DP lanes while also limiting the number of DP lanes or their pin assignment at runtime. Bridge drivers should point their 'struct drm_bus_cfg::lanes' pointer to an allocated array of 'struct drm_lane_cfg' structures and indicate the size of this allocated array with 'struct drm_bus_cfg::num_lanes' in their atomic_check() callback. The previous bridge in the bridge chain can look at this information by calling drm_bridge_next_bridge_lane_cfg() in their atomic_check() callback to figure out what lanes need to be logically assigned to the physical output lanes to satisfy the next bridge's lane assignment. Cc: Andrzej Hajda Cc: Neil Armstrong Cc: Robert Foss Cc: Laurent Pinchart Cc: Jonas Karlman Cc: Jernej Skrabec Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Daniel Vetter Cc: Cc: Pin-yen Lin Cc: Dmitry Baryshkov Signed-off-by: Stephen Boyd --- drivers/gpu/drm/drm_atomic_state_helper.c | 2 ++ drivers/gpu/drm/drm_bridge.c | 34 +++++++++++++++++++++++ include/drm/drm_atomic.h | 31 +++++++++++++++++++++ include/drm/drm_bridge.h | 4 +++ 4 files changed, 71 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/dr= m_atomic_state_helper.c index 519228eb1095..12d574458e7b 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -779,6 +779,8 @@ EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state); void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge, struct drm_bridge_state *state) { + kfree(state->input_bus_cfg.lanes); + kfree(state->output_bus_cfg.lanes); kfree(state); } EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state); diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index d44f055dbe3e..bd18c1e91dee 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -822,6 +822,40 @@ void drm_atomic_bridge_chain_enable(struct drm_bridge = *bridge, } EXPORT_SYMBOL(drm_atomic_bridge_chain_enable); =20 +/** + * drm_bridge_next_bridge_lane_cfg - get the lane configuration of the nex= t bridge + * @bridge: bridge control structure + * @state: new atomic state + * @num_lanes: will contain the size of the returned array + * + * This function is typically called from &drm_bridge_funcs.atomic_check(). + * The @bridge driver calls this function to determine what the next bridg= e in + * the bridge chain requires for the physical to logical lane assignments. + * + * Return: Lane configuration array of size @num_lanes for the next bridge + * after @bridge in the bridge chain, or NULL if the lane configuration is + * unchanged from the default. + */ +const struct drm_lane_cfg * +drm_bridge_next_bridge_lane_cfg(struct drm_bridge *bridge, + struct drm_atomic_state *state, + u8 *num_lanes) +{ + const struct drm_bridge_state *next_bridge_state; + struct drm_bridge *next_bridge =3D drm_bridge_get_next_bridge(bridge); + + next_bridge_state =3D drm_atomic_get_new_bridge_state(state, next_bridge); + if (!next_bridge_state) { + *num_lanes =3D 0; + return NULL; + } + + *num_lanes =3D next_bridge_state->input_bus_cfg.num_lanes; + + return next_bridge_state->input_bus_cfg.lanes; +} +EXPORT_SYMBOL(drm_bridge_next_bridge_lane_cfg); + static int drm_atomic_bridge_check(struct drm_bridge *bridge, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 4d7f4c5f2001..e1a38d0742f1 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -1122,6 +1122,27 @@ drm_atomic_crtc_effectively_active(const struct drm_= crtc_state *state) return state->active || state->self_refresh_active; } =20 +/** + * struct drm_lane_cfg - lane configuration + * + * This structure stores the lane configuration of a physical bus between + * two components in an output pipeline, usually between two bridges, an + * encoder and a bridge, or a bridge and a connector. + * + * The lane configuration is stored in &drm_bus_cfg. + */ +struct drm_lane_cfg { + /** + * @logical: Logical lane number + */ + u8 logical; + + /** + * @inverted: True if lane polarity is inverted, false otherwise + */ + bool inverted; +}; + /** * struct drm_bus_cfg - bus configuration * @@ -1152,6 +1173,16 @@ struct drm_bus_cfg { * @flags: DRM_BUS_* flags used on this bus */ u32 flags; + + /** + * @lanes: Lane mapping for this bus + */ + struct drm_lane_cfg *lanes; + + /** + * @num_lanes: Number of lanes in @lanes + */ + u8 num_lanes; }; =20 /** diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 75019d16be64..064d3c8600a9 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -963,6 +963,10 @@ drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_= bridge *bridge, struct drm_connector_state *conn_state, u32 output_fmt, unsigned int *num_input_fmts); +const struct drm_lane_cfg * +drm_bridge_next_bridge_lane_cfg(struct drm_bridge *bridge, + struct drm_atomic_state *state, + u8 *num_lanes); =20 enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge); int drm_bridge_get_modes(struct drm_bridge *bridge, --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 4AD071DF68A for ; Mon, 19 Aug 2024 22:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107124; cv=none; b=kGNmipkMZo7np72mQveBqRfcdprpdhK/z1MaTzCXj3lmz4jb7ErbDvsTbVAryWtlKthqmwkCgEdfw0vy8BGrr177qjzh0HRXCKzJsTM1YS2jjkTp6EjVmUbP2wlCpzUivnIiZyNUUbBc9/Aksvc+taMXJ1gAI4SYK9upsPvIAx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107124; c=relaxed/simple; bh=ahxFCtg/v93x1OwOq6O28bHFegCWP8HatZ1/V+oQ4yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bZb/tGbrD21UMEeOuGsVQQ+PzD2smIk1Kdg9dtJEemlFuxzBpXo4dboWsoKLw845FTu0NQk+qCIrbsO3c5QpCj4SPq7g1O73xMmzRrnuuqjJDm4Ae4I4BaKLbVRHVxN5Oef83hOw9jt4Dyb5nZv7XOcFaLCMK7NNGcvaiOJ70HM= 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=Gdw6S9oZ; arc=none smtp.client-ip=209.85.160.53 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="Gdw6S9oZ" Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-27046394c9bso1433021fac.2 for ; Mon, 19 Aug 2024 15:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107121; x=1724711921; 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=d8LFD02UwCQn/9JJcB/9igBsgy8I8NKOocEuza3szqI=; b=Gdw6S9oZlYemMYrOgkAJzj9uX9q6wQAq7qbR30/vbwStGCcWkFZhRzz/Me6OjLNX85 tsb29bAlljUZC9j1VWIVEBH/sN76XYCaXpnh6kqYPRa+ZNf6oYRm5AcD+gpgY7q2ZLAR TD8c8aYF6gWdrD1gvao7GfrCJAfWnoafmhDak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107121; x=1724711921; 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=d8LFD02UwCQn/9JJcB/9igBsgy8I8NKOocEuza3szqI=; b=s0Gbfvwvdm+/G0vGmC8rlgdvGp/u5l0X76q3zEffE4WXFQALi8RZfDiWUe/RMp3t19 DERoNZ6WwQHzLPIQsukTBEqHkE63oyU6iZGpcqgp81klhaJxcAkNczGZidJG9SkJvxN5 eEOPZ75Tq0Q3EpqB8ufzU8pwXrUd/r55MEOsecV+PsJ6fUEPq7C1VO/PyNPA7w9IGjX1 p0+j9hOQd35gW7pAsDzOpin/Nrw1F6McQUaFEc50B3k5EqLy9tabGeGgxfFGT9wfg2L3 X5CevDxdyvveq/UXroZ5X1ArhHX8pIWfr6mfPj298PL0WDBFlc7zI7P1C10ypTe9XmPT DJkA== X-Gm-Message-State: AOJu0Yw3BZeTNQ6FSNEkxj8ETxphgXauMA5u26kHWlzUFxviiHz0q9dI KTP7KsA86PkAV9oM53K9/jzzUkVd4u5N59SRk6PdM4oojisKX8DjgjAAmFSq9w== X-Google-Smtp-Source: AGHT+IFDmk+Cb+A4O+BimkRHrzSvMdF36gyn+FMQJb48HMVM/8Jd53btKUirm04S2dgcVAJXzm+t/g== X-Received: by 2002:a05:6870:c1d0:b0:267:dfce:95eb with SMTP id 586e51a60fabf-2701c345f49mr14663015fac.5.1724107121323; Mon, 19 Aug 2024 15:38:41 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7c6b61a6e9esm6929237a12.19.2024.08.19.15.38.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:41 -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 v3 02/17] drm/bridge: Verify lane assignment is going to work during atomic_check Date: Mon, 19 Aug 2024 15:38:16 -0700 Message-ID: <20240819223834.2049862-3-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Verify during drm_atomic_bridge_check() that the lane assignment set in a bridge's atomic_check() callback is going to be satisfied by the previous bridge. If the next bridge is requiring something besides the default 1:1 lane assignment on its input then there must be an output lane assignment on the previous bridge's output. Otherwise the next bridge won't get the lanes assigned that it needs. Cc: Andrzej Hajda Cc: Neil Armstrong Cc: Robert Foss Cc: Laurent Pinchart Cc: Jonas Karlman Cc: Jernej Skrabec Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Daniel Vetter Cc: Cc: Pin-yen Lin Cc: Dmitry Baryshkov Signed-off-by: Stephen Boyd --- drivers/gpu/drm/drm_bridge.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index bd18c1e91dee..68c7a321b9b3 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -860,6 +860,10 @@ static int drm_atomic_bridge_check(struct drm_bridge *= bridge, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { + u8 num_input_lanes, num_output_lanes =3D 0; + const struct drm_lane_cfg *input_lanes; + int i; + if (bridge->funcs->atomic_check) { struct drm_bridge_state *bridge_state; int ret; @@ -873,12 +877,24 @@ static int drm_atomic_bridge_check(struct drm_bridge = *bridge, crtc_state, conn_state); if (ret) return ret; + num_output_lanes =3D bridge_state->output_bus_cfg.num_lanes; } else if (bridge->funcs->mode_fixup) { if (!bridge->funcs->mode_fixup(bridge, &crtc_state->mode, &crtc_state->adjusted_mode)) return -EINVAL; } =20 + input_lanes =3D drm_bridge_next_bridge_lane_cfg(bridge, + crtc_state->state, + &num_input_lanes); + /* + * Ensure this bridge is aware that the next bridge wants to + * reassign lanes. + */ + for (i =3D 0; i < num_input_lanes; i++) + if (i !=3D input_lanes[i].logical && !num_output_lanes) + return -ENOTSUPP; + return 0; } =20 --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 33AC61E212F for ; Mon, 19 Aug 2024 22:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107127; cv=none; b=RGpE+bJux6zNj7FqiD8wXp8tblpiK6ISAm/0v3heR8NpvxOzclm11BpKJxXD+EYNOk2ZOJAv1zvqCacZA6y/+nc69mrfJ+CnQZxShNWD71HYzfE09u4wpP6e/xOx18XxeGH/417lgo4hH/Dao3NLsN2fhTW7+DNPOb/yHnwI3j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107127; c=relaxed/simple; bh=hmBdC6OuP0fFMyUtA27W3obsdBheUiPiVi+Dyq4Fm3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kt8T0HODthNEiGh67bf5uq6V14wJVf0QlGp4gKkrI2l+8G85RW9fPRTUjGsjiRT11msUYUNKs+XvMwY1F4Zp/R2uM3XCSoa5M0vSlNlN6UvQlonl28xp7b2cAk89eMJCAi7rPLkI2sJKKhsuPCHxOueO5HU7s/hAhwwDxb8uups= 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=ePdLa7Xc; arc=none smtp.client-ip=209.85.210.174 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="ePdLa7Xc" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71406aef24dso495391b3a.2 for ; Mon, 19 Aug 2024 15:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107124; x=1724711924; 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=tjBNYQFa86nn8t+X15a2kIDQUg5jYzam5K2eZ8YJJCA=; b=ePdLa7XcIVPNhQinKCFS4ITvYsMkVautP+zrmeNMl3a2U8Il4eNRRylSlgdzMYHl+o oAZq9lyFS1HlsNzQQVtklCAm5NFo/ZudmzbMfd3lSZcoYGXYEJMOkcPbdm8fOUJIHLQd 6+2Kuz52DX5vdqdojuu9lBevY1KFbQpNk79ZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107124; x=1724711924; 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=tjBNYQFa86nn8t+X15a2kIDQUg5jYzam5K2eZ8YJJCA=; b=le/FLX3Q5ri6pP30SnYrDvJvYQdLnoKPBZ9/RlcsvQ0jyl26nq9NQHEe04YPLV1dSg CUDTUtdNuxqGqEsnvJmQI58Cqy8D7b8XCd/YRXZH9UT/91Ml8xdJwI9QrX6wiBpKsYwe MwoXoXT693BcMaU82scvYzM1Qo0cYy6vamj1VWpmVPtFgZHuCsCCICIJv4NJ+8qlt99s zfxtbUUXb6auQiEGcSipTafozTr7RSPldDUMLDJ6fU98RLYqPO9g9QGdcWWAdPXPZFoM IM34berwZPxYkMlNGhIpegPeMnqC0Ab69HM8f/leIicci+RKnnDvZLIS9V24Ip8i8uNM dz/w== X-Gm-Message-State: AOJu0Yz3HcWb7AzaCrqC+ZTGepHVI9lXkz9uMpLrLoEB7jV1szmXWb9V bnlymKXSWu1Xo/z/zgo44J5aSoOPri4OLOmQPRu4dT2PjknRPg+/jrVu31KCyQ== X-Google-Smtp-Source: AGHT+IHN/xP/IACjD57PXeDLdL97bMvELyNSW6GYvHFV5SlTTara1vBX1rN2aloQvAb4+mpkicUw5g== X-Received: by 2002:a05:6a21:150b:b0:1c4:bbb8:5050 with SMTP id adf61e73a8af0-1c90502ae63mr11606193637.37.1724107123237; Mon, 19 Aug 2024 15:38:43 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7c6b61c6bb5sm7011137a12.33.2024.08.19.15.38.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:42 -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 v3 03/17] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Date: Mon, 19 Aug 2024 15:38:17 -0700 Message-ID: <20240819223834.2049862-4-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Ease driver development by adding stubs for the typec_switch APIs when CONFIG_TYPEC=3Dn. Copy the same method used for the typec_mux APIs to be consistent. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- include/linux/usb/typec_mux.h | 42 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index 2489a7857d8e..094585205264 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -24,16 +24,13 @@ struct typec_switch_desc { void *drvdata; }; =20 +#if IS_ENABLED(CONFIG_TYPEC) + struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode); void typec_switch_put(struct typec_switch *sw); int typec_switch_set(struct typec_switch *sw, enum typec_orientation orientation); =20 -static inline struct typec_switch *typec_switch_get(struct device *dev) -{ - return fwnode_typec_switch_get(dev_fwnode(dev)); -} - struct typec_switch_dev * typec_switch_register(struct device *parent, const struct typec_switch_desc *desc); @@ -42,6 +39,41 @@ void typec_switch_unregister(struct typec_switch_dev *sw= ); void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); void *typec_switch_get_drvdata(struct typec_switch_dev *sw); =20 +#else + +static inline struct typec_switch * +fwnode_typec_switch_get(struct fwnode_handle *fwnode) +{ + return NULL; +} +static inline void typec_switch_put(struct typec_switch *sw) {} +static inline int typec_switch_set(struct typec_switch *sw, + enum typec_orientation orientation) +{ + return 0; +} + +static inline struct typec_switch_dev * +typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + return ERR_PTR(-EOPNOTSUPP); +} +static inline void typec_switch_unregister(struct typec_switch_dev *sw) {} + +static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, v= oid *data) {} +static inline void *typec_switch_get_drvdata(struct typec_switch_dev *sw) +{ + return ERR_PTR(-EOPNOTSUPP); +} + +#endif /* CONFIG_TYPEC */ + +static inline struct typec_switch *typec_switch_get(struct device *dev) +{ + return fwnode_typec_switch_get(dev_fwnode(dev)); +} + struct typec_mux_state { struct typec_altmode *alt; unsigned long mode; --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 8B01B1E3CB2 for ; Mon, 19 Aug 2024 22:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107128; cv=none; b=thFE5PMut8hWfjFdN/TyLHTqgpCPdEbaMd1mQTs5/Rgbz1/GxHfeYCszMZupEChDgPzdeAy+Z3GKQbjpRB++64idEjEJElQbLwW4m2KN8AjKP+cPI21pZMQTNWw0ubTafD7rn7SY9Dm0u0+3vtsAXr4JCAyjlSbD/LC3DMgRgcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107128; c=relaxed/simple; bh=YZsJrlae73dDXQ7qQXUAfgucjjDnE3ixdZvtKilWId0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WL64ZURbxQSul74JVM5+yiip6VqwALart2MznNzGLkIXdD6Tm135Z9v3V8bdkf3LH2fvnzFerldHZNsxu3rfgw0xlWgAWrDacknCkXH5A4zNZ344ddv3uJwRX2EGWMGbGym71ln00SjfazzYE9kTdvE50MMnozUtXO0hLmPKuKM= 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=Q8F+oilX; arc=none smtp.client-ip=209.85.215.181 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="Q8F+oilX" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-70b2421471aso3013186a12.0 for ; Mon, 19 Aug 2024 15:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107126; x=1724711926; 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=TByAwKUM3v221HSwHXMGl0z/VgI2w0FSGFaz63ewMCc=; b=Q8F+oilXRY+BpeGI2IOZRfrDirq+ohw2DINZ29jM0siAkVZeORgdj84A1c6wkQky8p Qkq7hs0rNNI7mt296gtTw3/u5/HlNPFiiKAMJ8+VRIHtKiAqXw3s7Bm3IWgdlc0/gjrx dCa0wYYe5NHHcy+gBjEtYRDuuB33mCfm7gpXA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107126; x=1724711926; 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=TByAwKUM3v221HSwHXMGl0z/VgI2w0FSGFaz63ewMCc=; b=buyXZAoKJ4Unf6LiF1REK/rhBDxNbPFIsf+xpO3zJMcV1qYijS4gDcvKYQ68bR6h1n jygiE8Hpo0opyZq57CKTP+9l8oR1f6sGRJ305vOewNUndO3YBOpKHKdygwHidG4sZHjs IM1VMaxTMF695CBV/4CcJCoeHstgKQeDt1pKVicjj7ZJ4ARFO/9XMDNbAALuAjtGzzZA 6uivpbenWep1EORFTnNF7c8ZPdF6uPYttjPgk/zUmSQtQwSdFgtGZ4p2R7vo5nx7cwu6 b1MKth5yD0ts6QsRHnN5gM//vd08964JGddng/gyW50J5fsrTcOlhVB71EQcWpuQ9v6n baGw== X-Gm-Message-State: AOJu0Yxzx0p7V+paM6d/8v3fmtMrzmnqrwhfICvR7wMc0Ox/+NVXOUQ4 E0efW/jIEF+Ai8hCyqotmUroF3J/uaIQn84o4yU+RW0GZ5e52+D4ojnuRuWdGA== X-Google-Smtp-Source: AGHT+IE9mRUEWdSZz44bRNA1IsxkpeUvPxhXUID/IQ/pKL+AsxBfad4S7Hi4SBlwuRZq8RScQNUZsw== X-Received: by 2002:a05:6a20:9d92:b0:1c6:9fe9:c425 with SMTP id adf61e73a8af0-1c9050534fdmr13069748637.45.1724107125678; Mon, 19 Aug 2024 15:38:45 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127aef410esm7052463b3a.113.2024.08.19.15.38.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:45 -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 v3 04/17] usb: typec: Add device managed typec_mux_register() Date: Mon, 19 Aug 2024 15:38:18 -0700 Message-ID: <20240819223834.2049862-5-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Simplify driver error paths by adding devm_typec_mux_register() which will unregister the typec mux when the parent device is unbound. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/usb/typec/mux.c | 37 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 49926d6e72c7..65c60eb56428 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -457,6 +457,43 @@ void typec_mux_unregister(struct typec_mux_dev *mux_de= v) } EXPORT_SYMBOL_GPL(typec_mux_unregister); =20 +static void devm_typec_mux_unregister(struct device *dev, void *mux_dev) +{ + typec_mux_unregister(*(struct typec_mux_dev **)mux_dev); +} + +/** devm_typec_mux_register - resource managed typec_mux_register() + * @parent: Parent device + * @desc: Multiplexer description + * + * Register a typec mux and automatically unregister the typec mux + * when @parent is unbound from its driver. + * + * The arguments to this function are identical to typec_mux_register(). + * + * Return: the typec_mux_dev structure on success, else an error pointer. + */ +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc) +{ + struct typec_mux_dev **ptr, *mux_dev; + + ptr =3D devres_alloc(devm_typec_mux_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + mux_dev =3D typec_mux_register(parent ,desc); + if (!IS_ERR(mux_dev)) { + *ptr =3D mux_dev; + devres_add(parent, ptr); + } else { + devres_free(ptr); + } + + return mux_dev; +} +EXPORT_SYMBOL_GPL(devm_typec_mux_register); + void typec_mux_set_drvdata(struct typec_mux_dev *mux_dev, void *data) { dev_set_drvdata(&mux_dev->dev, data); diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index 094585205264..c6f49756530d 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -98,6 +98,8 @@ int typec_mux_set(struct typec_mux *mux, struct typec_mux= _state *state); =20 struct typec_mux_dev * typec_mux_register(struct device *parent, const struct typec_mux_desc *des= c); +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc); void typec_mux_unregister(struct typec_mux_dev *mux); =20 void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); @@ -122,6 +124,11 @@ typec_mux_register(struct device *parent, const struct= typec_mux_desc *desc) { return ERR_PTR(-EOPNOTSUPP); } +static inline struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc= *desc) +{ + return typec_mux_register(parent, desc); +} static inline void typec_mux_unregister(struct typec_mux_dev *mux) {} =20 static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *= data) {} --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 D95AC1E3CBA for ; Mon, 19 Aug 2024 22:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107130; cv=none; b=AGx+F4dM2vpQ82/zHxZ09Dd9hZyijZLZMxqwWoKhs6wsZwFGrA2SW4WfjtWHQCurzLkuijROMy15g1u6sY9tjZsZF6N7fy7Dqxr4UAvxMzOzoJMxv8e995QFn1P1OXjHLQrVjZnhqJevZAbjL+p/Qkhjqf7cs/SnlvL+EFW1Smw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107130; c=relaxed/simple; bh=HsvBWQDhlsn8H6zRFLK5T7gdVtCqYrCaBpLaZ8SUzbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IF4owlA9to2e7Jk7RU4+2LasvhF7ttgt+c71SPGncZQN5fGwysvGOKxfufj15sLG7QlCatnjRO/lLdUe67T5ew7Dt3Zu651MZ10ozVLZGJ2sqGh4M07wGcjhcOBhpywmHaYGYx/uIhhLglJSYzh29m11Npd/y+mWiyDIa0f7pgc= 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=Wx1gX1Kn; arc=none smtp.client-ip=209.85.214.182 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="Wx1gX1Kn" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2021c08b95cso16377755ad.0 for ; Mon, 19 Aug 2024 15:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107128; x=1724711928; 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=/QfY7K5G02ZDzjvxUav8uCOJkIdUZDTh+/duvHHbQ8k=; b=Wx1gX1KnMcmz8o2FEGEuGCpZVk23STosTETGBaJaCwEIEp/mG2/hxuBuek66I+vxpW niLp3JRkvWpcFJ1h0IiXJoEDp/WCh9L9uFSVqN+uqoj5Tt44tTCjFEQvW2GtsyQTnnO3 Ustxy06Rq4Zal2qWxCSu4Ix5Xwidi5B+Xt+rg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107128; x=1724711928; 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=/QfY7K5G02ZDzjvxUav8uCOJkIdUZDTh+/duvHHbQ8k=; b=KMTLOPuKeP04N4hiJwFFdNupDJsJB+zZ6usEqySnNbhmcLD0tPPOjQ96sJJnISBsHl l2sYUmWxgFufQenmou31RxOwlAD4Jy80NUkBwTlVpuNT49cK/h91vDv5EYmyPpY5PA8m CvmZGf2HX206EUGbSokSM9YNibI9BJXbMckBgir5C61Ol5++a972p7dI8hf0bklj3L+D 0u9WhKRy7oCMAQvUKosoGx+yxH85AH73JPm824X8uXPurl65dWQJ8OP7aHHV1PG5oSXV MQvCY1gPO9QHO+X1++Oy2YGww6jojBy9PaquI+EeR56e0GSauLLP60vBFKcqXiWj8MBR 8mzQ== X-Gm-Message-State: AOJu0YzdMyBxSf0D13atg9ein+9H+IBXnV+nFgGJUNEyMqiXA/T/Zi1F HxL+c0qbdL4WQzfTKcUkhIb2Uv2owW/E0QE71li0YD2vkh9PJl7NIxR2G2Yxag== X-Google-Smtp-Source: AGHT+IEjvBWy5ocnu/ktRfbxtIPTfv9LDJE/ruEiBfpU+qt4ZXlJ9XqOGFL2pdFVOCA7+gyynTnvVA== X-Received: by 2002:a17:902:da86:b0:200:79c1:a69f with SMTP id d9443c01a7336-2025f1c1077mr18748745ad.20.1724107127977; Mon, 19 Aug 2024 15:38:47 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f03758a6sm66871225ad.180.2024.08.19.15.38.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:47 -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 v3 05/17] usb: typec: Add device managed typec_switch_register() Date: Mon, 19 Aug 2024 15:38:19 -0700 Message-ID: <20240819223834.2049862-6-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Simplify driver error paths by adding devm_typec_switch_register() which will unregister the typec switch when the parent device is unbound. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/usb/typec/mux.c | 27 +++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 65c60eb56428..3531ab03bac4 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -235,6 +235,33 @@ void typec_switch_unregister(struct typec_switch_dev *= sw_dev) } EXPORT_SYMBOL_GPL(typec_switch_unregister); =20 +static void devm_typec_switch_unregister(struct device *dev, void *switch_= dev) +{ + typec_switch_unregister(*(struct typec_switch_dev **)switch_dev); +} + +struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + struct typec_switch_dev **ptr, *switch_dev; + + ptr =3D devres_alloc(devm_typec_switch_unregister, sizeof(*ptr), GFP_KERN= EL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + switch_dev =3D typec_switch_register(parent ,desc); + if (!IS_ERR(switch_dev)) { + *ptr =3D switch_dev; + devres_add(parent, ptr); + } else { + devres_free(ptr); + } + + return switch_dev; +} +EXPORT_SYMBOL_GPL(devm_typec_switch_register); + void typec_switch_set_drvdata(struct typec_switch_dev *sw_dev, void *data) { dev_set_drvdata(&sw_dev->dev, data); diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index c6f49756530d..fe7a05dd71c8 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -34,6 +34,9 @@ int typec_switch_set(struct typec_switch *sw, struct typec_switch_dev * typec_switch_register(struct device *parent, const struct typec_switch_desc *desc); +struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc); void typec_switch_unregister(struct typec_switch_dev *sw); =20 void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); @@ -59,6 +62,12 @@ typec_switch_register(struct device *parent, { return ERR_PTR(-EOPNOTSUPP); } +static inline struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + return typec_switch_register(parent, desc); +} static inline void typec_switch_unregister(struct typec_switch_dev *sw) {} =20 static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, v= oid *data) {} --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 085B31E4F14 for ; Mon, 19 Aug 2024 22:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107133; cv=none; b=pc4SpAmqSUgLEbsGfSJ83Ai3RfAzJ6d/SSjR2XkACU1YOdcV46hFrxVL/hKEhnNX267KWk6YbV9SgABBmOmVmw5+V44VnzcWXQVaN3aZRY3Ai1xOvgm5YQtk57YpP/CxK/sXVRN5YmKq9PwlMEniBz7zFbZyAfvSZTOWyqcPJE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107133; c=relaxed/simple; bh=L6Wb8OzgT7iKOYtvnAO+/Pykc3Ob4SJZIhXdCsFVUZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dsOzzKdnJajfF5cG3H7uhtxWiam+maFfo81rvlztE1FdQEF0dzeQVFjLhxlDi7P9L0V8GSZKr41gCXS2avcn1FWg/RKQy6trvrTi9MjBNpyCcDfVUXi5BcGp0CQzvMGiAFdhSz3xun46WVnm9eRPTjX7IBxXPuvFDNPJlTkuy8s= 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=GEQ1lt2H; arc=none smtp.client-ip=209.85.210.172 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="GEQ1lt2H" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-713dc00cf67so2288585b3a.1 for ; Mon, 19 Aug 2024 15:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107130; x=1724711930; 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=fvnzUY4BK4B5BH9YkZ71BQFnKnSd7lqBErkOxU3ODcU=; b=GEQ1lt2HbbD6DgMoZu6FHoI8Q1gspvuGbq3P5TW+1NdYUJfDrjYJx2auhXI0J1DYlK 4Y7UKKP9kJe5qDTMn0I31EJOnAXeBm96O1JyXDDDpaoTZxiJ686cpL6MMDZdIWEnc3m8 EncK7nUQeRuHHBrAaMp8xXZPppfOGcM5tYe2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107130; x=1724711930; 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=fvnzUY4BK4B5BH9YkZ71BQFnKnSd7lqBErkOxU3ODcU=; b=KWtP/RSNghMux9kP9b4cs/4Yp0ArYUFOuHMZNM1zKic5TBYOOcsQR5i8LXWr1ti7kU lEUPvV5kpzWBYbT5JXJKdgOKPGnGOZaiONgk0HHMOmCtdizo2Q7znc4hGVxs4CkB1zat PRhkhWemcKIThFPjJwdJ+L3wkN2MWLOEoVmv4LDmetfNXLY0NI3dCCSwQrHYUKQHtv3l daAK9q9QZ8mF7QTlGrM4HHo8VSCt0OVLuHQisVYAxAIjrPqFQ7aK9YFu1FLI3czGpu4Q 9z4ibpeG6zajBAjKtT8LbcNgAf5nO71j4GxfAZR0eeSJG8DV/rnxE/Fn+F+rwr/M8Oz1 m1oQ== X-Gm-Message-State: AOJu0YwkO5E2TXRRxXQc1plJY6R3WoTlKWqI75PGNqzRHFJ9NlmXA0w4 3QPKGznkJ2kVSJ3L2a5vwalTS0Zfzzvtpk6bRyh0pUsa6e71/5Q1g5Q7mQhsvw== X-Google-Smtp-Source: AGHT+IHIC4cN36BxMYjDgyWtYaTcEpk2oJPUdK8fHj5OyWsAyy+34+Bd33vpEYEeR+fPPaIWMDSgyg== X-Received: by 2002:a05:6a20:c799:b0:1ca:c673:9792 with SMTP id adf61e73a8af0-1cac6739a0dmr1351175637.10.1724107130148; Mon, 19 Aug 2024 15:38:50 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127af1ec36sm7053115b3a.180.2024.08.19.15.38.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:49 -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 v3 06/17] drm/bridge: aux-hpd: Support USB Type-C DP altmodes via DRM lane assignment Date: Mon, 19 Aug 2024 15:38:20 -0700 Message-ID: <20240819223834.2049862-7-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Extend the aux-hpd bridge driver to support assigning DP lanes to USB type-c pins based on typec mux state entry. Existing users of this driver only need the HPD signaling support, so leave that in place and wrap the code with a variant that supports more features of USB type-c DP altmode, i.e. pin configurations. Prefix that code with 'drm_dp_typec_bridge' to differentiate it from the existing 'drm_aux_hpd_bridge' code. Parse the struct typec_mux_state members to determine if DP altmode has been entered and if HPD is asserted or not. Signal HPD to the drm bridge chain when HPD is asserted. Similarly, parse the pin assignment and map the DP lanes to the usb-c output lanes, taking into account any lane remapping from the data-lanes endpoint property. Pass that lane mapping to the previous drm_bridge in the bridge chain during the atomic check phase. 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 | 476 +++++++++++++++++++++++- include/drm/bridge/aux-bridge.h | 17 + 2 files changed, 481 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/brid= ge/aux-hpd-bridge.c index 6886db2d9e00..47315a8077a3 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -7,8 +7,14 @@ #include #include #include +#include +#include +#include +#include =20 +#include #include +#include #include =20 static DEFINE_IDA(drm_aux_hpd_bridge_ida); @@ -18,6 +24,80 @@ struct drm_aux_hpd_bridge_data { struct device *dev; }; =20 +enum dp_lane { + DP_ML0 =3D 0, /* DP pins 1/3 */ + DP_ML1 =3D 1, /* DP pins 4/6 */ + DP_ML2 =3D 2, /* DP pins 7/9 */ + DP_ML3 =3D 3, /* DP pins 10/12 */ +}; + +#define NUM_DP_ML (DP_ML3 + 1) + +enum usb_ss_lane { + USB_SSRX1 =3D 0, /* Type-C pins B11/B10 */ + USB_SSTX1 =3D 1, /* Type-C pins A2/A3 */ + USB_SSTX2 =3D 2, /* Type-C pins A11/A10 */ + USB_SSRX2 =3D 3, /* Type-C pins B2/B3 */ +}; + +#define NUM_USB_SS (USB_SSRX2 + 1) + +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 + * @mode_switch: DP altmode switch + * @typec_data: Back pointer to type-c bridge data + */ +struct drm_dp_typec_bridge_typec_port { + u32 lane_mapping[NUM_USB_SS]; + struct typec_mux_dev *mode_switch; + struct drm_dp_typec_bridge_data *typec_data; +}; + +/** + * struct drm_dp_typec_bridge_data - DP over USB type-c drm_bridge + * @dp_lanes: Physical (array value) to logical (array index) DP lane mapp= ing + * @num_lanes: Number of valid lanes in @dp_lanes + * @hpd_bridge: hpd_bridge data + */ +struct drm_dp_typec_bridge_data { + u8 dp_lanes[NUM_DP_ML]; + size_t num_lanes; + struct drm_aux_hpd_bridge_data hpd_bridge; +}; + +static inline struct drm_dp_typec_bridge_data * +hpd_bridge_to_typec_bridge_data(struct drm_aux_hpd_bridge_data *hpd_data) +{ + return container_of(hpd_data, struct drm_dp_typec_bridge_data, hpd_bridge= ); +} + +static inline struct drm_dp_typec_bridge_data * +to_drm_dp_typec_bridge_data(struct drm_bridge *bridge) +{ + struct drm_aux_hpd_bridge_data *hpd_data; + + hpd_data =3D container_of(bridge, struct drm_aux_hpd_bridge_data, bridge); + + return hpd_bridge_to_typec_bridge_data(hpd_data); +} + +struct drm_dp_typec_bridge_dev { + struct auxiliary_device adev; + size_t max_lanes; + size_t num_typec_ports; +}; + +static inline struct drm_dp_typec_bridge_dev * +to_drm_dp_typec_bridge_dev(struct device *dev) +{ + struct auxiliary_device *adev =3D to_auxiliary_dev(dev); + + return container_of(adev, struct drm_dp_typec_bridge_dev, adev); +} + static void drm_aux_hpd_bridge_release(struct device *dev) { struct auxiliary_device *adev =3D to_auxiliary_dev(dev); @@ -30,6 +110,22 @@ static void drm_aux_hpd_bridge_release(struct device *d= ev) kfree(adev); } =20 +static void drm_dp_typec_bridge_release(struct device *dev) +{ + struct drm_dp_typec_bridge_dev *typec_bridge_dev; + struct auxiliary_device *adev; + + typec_bridge_dev =3D to_drm_dp_typec_bridge_dev(dev); + adev =3D &typec_bridge_dev->adev; + + ida_free(&drm_aux_hpd_bridge_ida, adev->id); + + of_node_put(adev->dev.platform_data); + of_node_put(adev->dev.of_node); + + kfree(typec_bridge_dev); +} + static void drm_aux_hpd_bridge_free_adev(void *_adev) { auxiliary_device_uninit(_adev); @@ -133,6 +229,111 @@ struct device *drm_dp_hpd_bridge_register(struct devi= ce *parent, struct device_n } EXPORT_SYMBOL_GPL(drm_dp_hpd_bridge_register); =20 +/** + * devm_drm_dp_typec_bridge_alloc - Allocate a USB type-c DisplayPort brid= ge + * @parent: device instance providing this bridge + * @np: device node pointer corresponding to this bridge instance + * + * Creates a DRM bridge with the type set to DRM_MODE_CONNECTOR_DisplayPor= t, + * which terminates the bridge chain and is able to send the HPD events al= ong + * with remap DP lanes to match USB type-c DP altmode pin assignments. + * + * Return: device instance that will handle created bridge or an error code + * encoded into the pointer. + */ +struct drm_dp_typec_bridge_dev * +devm_drm_dp_typec_bridge_alloc(struct device *parent, struct device_node *= np) +{ + struct drm_dp_typec_bridge_dev *typec_bridge_dev; + struct auxiliary_device *adev; + int ret, num_dp_lanes; + struct device_node *dp_ep __free(device_node) =3D NULL; + struct device_node *remote_ep; + struct device_node *ep_node; + struct of_endpoint ep; + + typec_bridge_dev =3D kzalloc(sizeof(*typec_bridge_dev), GFP_KERNEL); + if (!typec_bridge_dev) + return ERR_PTR(-ENOMEM); + adev =3D &typec_bridge_dev->adev; + + for_each_endpoint_of_node(np, ep_node) { + of_graph_parse_endpoint(ep_node, &ep); + /* Only consider available endpoints */ + if (!of_device_is_available(ep_node)) + continue; + /* Only consider connected nodes */ + remote_ep =3D of_graph_get_remote_endpoint(ep_node); + of_node_put(remote_ep); + if (!remote_ep) + continue; + + if (ep.port =3D=3D 2) + dp_ep =3D of_node_get(ep_node); + else if (ep.port =3D=3D 0) + typec_bridge_dev->num_typec_ports++; + } + + if (!typec_bridge_dev->num_typec_ports) { + kfree(adev); + return ERR_PTR(dev_err_probe(parent, -ENODEV, "Missing typec endpoint(s)= port@0\n")); + } + + if (!dp_ep) { + kfree(adev); + return ERR_PTR(dev_err_probe(parent, -ENODEV, "Missing DP endpoint port@= 2\n")); + } + + num_dp_lanes =3D of_property_count_u32_elems(dp_ep, "data-lanes"); + if (num_dp_lanes < 0) + num_dp_lanes =3D NUM_DP_ML; + + typec_bridge_dev->max_lanes =3D num_dp_lanes; + + ret =3D ida_alloc(&drm_aux_hpd_bridge_ida, GFP_KERNEL); + if (ret < 0) { + kfree(adev); + return ERR_PTR(ret); + } + + adev->id =3D ret; + adev->name =3D "dp_typec_bridge"; + adev->dev.parent =3D parent; + adev->dev.of_node =3D of_node_get(parent->of_node); + adev->dev.release =3D drm_dp_typec_bridge_release; + adev->dev.platform_data =3D of_node_get(np); + ret =3D auxiliary_device_init(adev); + if (ret) { + of_node_put(adev->dev.platform_data); + of_node_put(adev->dev.of_node); + ida_free(&drm_aux_hpd_bridge_ida, adev->id); + kfree(adev); + return ERR_PTR(ret); + } + + ret =3D devm_add_action_or_reset(parent, drm_aux_hpd_bridge_free_adev, ad= ev); + if (ret) + return ERR_PTR(ret); + + return typec_bridge_dev; +} +EXPORT_SYMBOL_GPL(devm_drm_dp_typec_bridge_alloc); + +/** + * devm_drm_dp_typec_bridge_add - register a USB type-c DisplayPort bridge + * @dev: struct device to tie registration lifetime to + * @typec_bridge_dev: USB type-c DisplayPort bridge to be registered + * + * Returns: zero on success or a negative errno + */ +int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_b= ridge_dev *typec_bridge_dev) +{ + struct auxiliary_device *adev =3D &typec_bridge_dev->adev; + + return devm_drm_dp_hpd_bridge_add(dev, adev); +} +EXPORT_SYMBOL_GPL(devm_drm_dp_typec_bridge_add); + /** * drm_aux_hpd_bridge_notify - notify hot plug detection events * @dev: device created for the HPD bridge @@ -161,32 +362,283 @@ static int drm_aux_hpd_bridge_attach(struct drm_brid= ge *bridge, return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL; } =20 +static int dp_lane_to_typec_lane(enum dp_lane lane) +{ + switch (lane) { + case DP_ML0: + return USB_SSTX2; + case DP_ML1: + return USB_SSRX2; + case DP_ML2: + return USB_SSTX1; + case DP_ML3: + return USB_SSRX1; + } + + return -EINVAL; +} + +static int typec_to_dp_lane(enum usb_ss_lane lane) +{ + 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; + } + + return -EINVAL; +} + +/** + * drm_dp_typec_bridge_assign_pins - Assign DisplayPort (DP) lanes to USB = type-c pins + * @typec_bridge_dev: Device created for the type-c bridge + * @conf: DisplayPort altmode configure command VDO content + * @port: The USB type-c output port to assign pins to + * + * Assign DP lanes to the @port's USB type-c pins for the DP altmode + * configuration @conf, while taking into account the USB type-c lane_mapp= ing. + * Future atomic checks on this bridge will request the lane assignment fr= om + * the previous bridge so that the DP signal is sent to the assigned USB t= ype-c + * pins. + * + * Return: 0 on success, negative value for failure. + */ +static int +drm_dp_typec_bridge_assign_pins(struct drm_dp_typec_bridge_dev *typec_brid= ge_dev, + u32 conf, + struct drm_dp_typec_bridge_typec_port *port) +{ + 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); + struct drm_dp_typec_bridge_data *data; + u8 *dp_lanes; + size_t num_lanes, max_lanes; + int i, typec_lane; + u8 pin_assign; + + if (!hpd_data) + return -EINVAL; + + data =3D hpd_bridge_to_typec_bridge_data(hpd_data); + dp_lanes =3D data->dp_lanes; + + pin_assign =3D DP_CONF_GET_PIN_ASSIGN(conf); + if (pin_assign =3D=3D DP_PIN_ASSIGN_D) + num_lanes =3D 2; + else + num_lanes =3D 4; + max_lanes =3D typec_bridge_dev->max_lanes; + data->num_lanes =3D num_lanes =3D min(num_lanes, max_lanes); + + for (i =3D 0; i < num_lanes; i++) { + /* Get physical type-c lane for DP lane */ + typec_lane =3D dp_lane_to_typec_lane(i); + if (typec_lane < 0) { + dev_err(&adev->dev, "Invalid type-c lane configuration at DP_ML%d\n", i= ); + return -EINVAL; + } + + /* Map physical to logical type-c lane */ + typec_lane =3D lane_mapping[typec_lane]; + + /* Map logical type-c lane to logical DP lane */ + dp_lanes[i] =3D typec_to_dp_lane(typec_lane); + } + + return 0; +} + +static int drm_dp_typec_bridge_atomic_check(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct drm_dp_typec_bridge_data *data; + struct drm_lane_cfg *in_lanes; + u8 *dp_lanes; + size_t num_lanes; + int i; + + data =3D to_drm_dp_typec_bridge_data(bridge); + num_lanes =3D data->num_lanes; + if (!num_lanes) + return 0; + dp_lanes =3D data->dp_lanes; + + in_lanes =3D kcalloc(num_lanes, sizeof(*in_lanes), GFP_KERNEL); + if (!in_lanes) + return -ENOMEM; + + bridge_state->input_bus_cfg.lanes =3D in_lanes; + bridge_state->input_bus_cfg.num_lanes =3D num_lanes; + + for (i =3D 0; i < num_lanes; i++) + in_lanes[i].logical =3D dp_lanes[i]; + + return 0; +} + static const struct drm_bridge_funcs drm_aux_hpd_bridge_funcs =3D { .attach =3D drm_aux_hpd_bridge_attach, }; =20 +static const struct drm_bridge_funcs drm_dp_typec_bridge_funcs =3D { + .attach =3D drm_aux_hpd_bridge_attach, + .atomic_check =3D drm_dp_typec_bridge_atomic_check, + .atomic_reset =3D drm_atomic_helper_bridge_reset, + .atomic_duplicate_state =3D drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state =3D drm_atomic_helper_bridge_destroy_state, +}; + +static int +drm_dp_typec_bridge_mode_switch_set(struct typec_mux_dev *mode_switch, + struct typec_mux_state *state) +{ + struct drm_dp_typec_bridge_typec_port *port; + const struct typec_displayport_data *dp_data; + struct drm_dp_typec_bridge_data *typec_data; + struct drm_dp_typec_bridge_dev *typec_bridge_dev; + struct device *dev; + int ret; + enum drm_connector_status status; + + port =3D typec_mux_get_drvdata(mode_switch); + typec_data =3D port->typec_data; + dev =3D typec_data->hpd_bridge.dev; + typec_bridge_dev =3D to_drm_dp_typec_bridge_dev(dev); + + if (state->mode =3D=3D TYPEC_STATE_SAFE || state->mode =3D=3D TYPEC_STATE= _USB) { + drm_aux_hpd_bridge_notify(dev, connector_status_disconnected); + } else if (state->alt && state->alt->svid =3D=3D USB_TYPEC_DP_SID) { + dp_data =3D state->data; + ret =3D drm_dp_typec_bridge_assign_pins(typec_bridge_dev, state->mode, p= ort); + if (ret) + return ret; + + if (dp_data->status & DP_STATUS_HPD_STATE) + status =3D connector_status_connected; + else + status =3D connector_status_disconnected; + + drm_aux_hpd_bridge_notify(dev, status); + } + + return 0; +} + +static int +drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_typec_bridge_data *typ= ec_data, + struct drm_dp_typec_bridge_dev *typec_bridge_dev, + struct device_node *np) +{ + struct device *dev =3D &typec_bridge_dev->adev.dev; + struct device_node *typec_ep, *remote_ep; + struct of_endpoint ep; + const u32 mapping[] =3D { 0, 1, 2, 3 }; + 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 fwnode_handle *fwnode; + + port =3D devm_kcalloc(dev, num_ports, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + for_each_endpoint_of_node(np, typec_ep) { + of_graph_parse_endpoint(typec_ep, &ep); + /* Only look at the usbc output port (port@0) */ + if (ep.port !=3D 0) + continue; + /* Only consider available endpoints */ + if (!of_device_is_available(typec_ep)) + continue; + /* Only consider connected nodes */ + remote_ep =3D of_graph_get_remote_endpoint(typec_ep); + of_node_put(remote_ep); + if (!remote_ep) + continue; + + port->typec_data =3D typec_data; + if (of_property_read_u32_array(ep.local_node, "data-lanes", + port->lane_mapping, + ARRAY_SIZE(port->lane_mapping))) { + memcpy(port->lane_mapping, mapping, sizeof(mapping)); + } + + fwnode =3D of_fwnode_handle(typec_ep); + + mode_switch_desc.set =3D drm_dp_typec_bridge_mode_switch_set; + mode_switch_desc.fwnode =3D fwnode; + mode_switch_desc.name =3D fwnode_get_name(fwnode); + mode_switch_desc.drvdata =3D port; + port->mode_switch =3D devm_typec_mux_register(dev, &mode_switch_desc); + if (IS_ERR(port->mode_switch)) + return PTR_ERR(port->mode_switch); + + port++; + } + + return 0; +} + +enum drm_aux_bridge_type { + DRM_AUX_HPD_BRIDGE, + DRM_AUX_TYPEC_BRIDGE, +}; + static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id) { - struct drm_aux_hpd_bridge_data *data; + struct device *dev =3D &auxdev->dev; + struct drm_aux_hpd_bridge_data *hpd_data; + struct drm_dp_typec_bridge_dev *typec_bridge_dev; + struct drm_dp_typec_bridge_data *typec_data; + struct drm_bridge *bridge; + struct device_node *np =3D dev_get_platdata(dev); + u8 dp_lanes[] =3D { DP_ML0, DP_ML1, DP_ML2, DP_ML3 }; + int ret; =20 - data =3D devm_kzalloc(&auxdev->dev, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; + if (id->driver_data =3D=3D DRM_AUX_HPD_BRIDGE) { + hpd_data =3D devm_kzalloc(dev, sizeof(*hpd_data), GFP_KERNEL); + if (!hpd_data) + return -ENOMEM; + bridge =3D &hpd_data->bridge; + bridge->funcs =3D &drm_aux_hpd_bridge_funcs; + } else if (id->driver_data =3D=3D DRM_AUX_TYPEC_BRIDGE) { + typec_data =3D devm_kzalloc(dev, sizeof(*typec_data), GFP_KERNEL); + if (!typec_data) + return -ENOMEM; + hpd_data =3D &typec_data->hpd_bridge; + bridge =3D &hpd_data->bridge; + bridge->funcs =3D &drm_dp_typec_bridge_funcs; + typec_bridge_dev =3D to_drm_dp_typec_bridge_dev(dev); + memcpy(typec_data->dp_lanes, dp_lanes, sizeof(typec_data->dp_lanes)); + ret =3D drm_dp_typec_bridge_probe_typec_ports(typec_data, typec_bridge_d= ev, np); + if (ret) + return ret; + } else { + return -ENODEV; + } =20 - data->dev =3D &auxdev->dev; - data->bridge.funcs =3D &drm_aux_hpd_bridge_funcs; - data->bridge.of_node =3D dev_get_platdata(data->dev); - data->bridge.ops =3D DRM_BRIDGE_OP_HPD; - data->bridge.type =3D id->driver_data; + hpd_data->dev =3D dev; + bridge->of_node =3D dev_get_platdata(dev); + bridge->ops =3D DRM_BRIDGE_OP_HPD; + bridge->type =3D DRM_MODE_CONNECTOR_DisplayPort; =20 - auxiliary_set_drvdata(auxdev, data); + auxiliary_set_drvdata(auxdev, hpd_data); =20 - return devm_drm_bridge_add(data->dev, &data->bridge); + return devm_drm_bridge_add(dev, bridge); } =20 static const struct auxiliary_device_id drm_aux_hpd_bridge_table[] =3D { - { .name =3D KBUILD_MODNAME ".dp_hpd_bridge", .driver_data =3D DRM_MODE_CO= NNECTOR_DisplayPort, }, + { .name =3D KBUILD_MODNAME ".dp_hpd_bridge", .driver_data =3D DRM_AUX_HPD= _BRIDGE, }, + { .name =3D KBUILD_MODNAME ".dp_typec_bridge", .driver_data =3D DRM_AUX_T= YPEC_BRIDGE, }, {}, }; MODULE_DEVICE_TABLE(auxiliary, drm_aux_hpd_bridge_table); diff --git a/include/drm/bridge/aux-bridge.h b/include/drm/bridge/aux-bridg= e.h index c2f5a855512f..73fc8582ec07 100644 --- a/include/drm/bridge/aux-bridge.h +++ b/include/drm/bridge/aux-bridge.h @@ -20,12 +20,17 @@ static inline int drm_aux_bridge_register(struct device= *parent) } #endif =20 +struct drm_dp_typec_bridge_dev; + #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE) struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *paren= t, struct device_node *np); int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device= *adev); struct device *drm_dp_hpd_bridge_register(struct device *parent, struct device_node *np); void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_stat= us status); +struct drm_dp_typec_bridge_dev *devm_drm_dp_typec_bridge_alloc(struct devi= ce *parent, + struct device_node *np); +int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_b= ridge_dev *typec_bridge_dev); #else static inline struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct= device *parent, struct device_node *np) @@ -44,6 +49,18 @@ static inline struct device *drm_dp_hpd_bridge_register(= struct device *parent, return NULL; } =20 +static inline struct drm_dp_typec_bridge_dev * +devm_drm_dp_typec_bridge_alloc(struct device *parent, struct device_node *= np) +{ + return NULL; +} + +static inline int devm_drm_dp_typec_bridge_add(struct device *dev, + struct drm_dp_typec_bridge_dev *typec_bridge_dev) +{ + return 0; +} + static inline void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_= connector_status status) { } --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 73A9A1E673E for ; Mon, 19 Aug 2024 22:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107135; cv=none; b=dvaWa5brC1clqjIyh8UvGa6ZP84xvHLJWActIUfpD9rEU6Mj6KDys8eVwUwALvZ+3ZILyQrm1znLM3hs22J4yPT9KMUMwb25IShzIOiQ30OoppxZlWO5VUBmnk1ZXgybsMrHU9BfFf/8Tq6FMwJ1DPrUZ6KtWD8qzVc6qbujQWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107135; c=relaxed/simple; bh=5K13Rr7Ye52MphZA4brc+qhak8CJv7kQslQnmneUWjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RZMr9XvxNzhoAO2hC5XTA+Enx1cqdUtLMTZ4fmfe+OQKQ6ejysiBX+rfgRJ9jKyxjhgfubeY70eVimvcvToY2X5pXHQowQcY7jGIYK1xK7lRquwAs7YaOTP9cKtcCbPpC/9Pmm+I/adu7kWWnGjL4U+U5peojtQIS/FVPNpHsB8= 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=fxb+wBoV; arc=none smtp.client-ip=209.85.167.174 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="fxb+wBoV" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3db145c8010so3131814b6e.3 for ; Mon, 19 Aug 2024 15:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107132; x=1724711932; 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=VbFRLEAP1yQ8phmhKg1xt4/PZ50JZmra4jTs/cBI9Fc=; b=fxb+wBoVYY9pJsjHGA4CAmK0CCV9eY3fvywPUff2C6rbNBNtbu8Os5ce82+072sL6W GyNOhQQymeg60fN/WdE9mxwa4JrEIiGgaNisGX4Fbii2mfBILkea2TE6uMWdhYFNfuxK g+LrCVRwWhl7VkWw2ciipweaPBU6aKmQfuNWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107132; x=1724711932; 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=VbFRLEAP1yQ8phmhKg1xt4/PZ50JZmra4jTs/cBI9Fc=; b=i70gBNIULXgrTa64adDhj3o6sIEPgnsTcnU5PG84CpIO4iorRTGkczuqxNobwwFopo mja7SSNYWCfX8qmXDAbZiIcGBe7UKYzmWko7sHKY4uIS7MgYfVySnbR0EFFfPEIYUj78 D+oJ9TMNYqQ+7SHIJSLaqwmThlYOHJBt7J1bef+nD0eqAO/IJDS4FQTIDJcIm1GECn3H KE/5Qlm5TTlHhddAEm3VviAb0tDrAqkwhfvc0D2VKq8UfGEiDp9jdMuD9Mpo1yqa7nlE kiQmdimqsO9GOuVDxlTJxmGG1m84h4cUbCghIXMwQK6GnzQJY2k33ZHs3+Z4PpVPC+6S OLkA== X-Gm-Message-State: AOJu0Ywuntf6ff03uhHBWSjbCQkdAOLFiwnpaQ1G3lYo0Tru+FCZge/b MkoF2IyW1NSM9dmuol4L2bABaVXnpehSYgOIQTDyR1yXmWxTYAgDMhtYSJpKLA== X-Google-Smtp-Source: AGHT+IGU+fzlXtM8B7VTp6DiytUOY+YJu/MAdpU9aLNWJBc8EuVBU83rDKxEo/rTgqaOBZmzP3dSGw== X-Received: by 2002:a05:6870:c1d0:b0:267:dfce:95eb with SMTP id 586e51a60fabf-2701c345f49mr14663404fac.5.1724107132395; Mon, 19 Aug 2024 15:38:52 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7c6b61c60f7sm8091519a12.22.2024.08.19.15.38.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:51 -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 v3 07/17] drm/bridge: dp_typec: Support USB Type-C orientation Date: Mon, 19 Aug 2024 15:38:21 -0700 Message-ID: <20240819223834.2049862-8-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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 | 74 +++++++++++++++++++++---- 1 file changed, 63 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 47315a8077a3..3d33f7936cbc 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -47,12 +47,15 @@ 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 * @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 +381,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 +434,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 +470,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 +518,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 +583,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"); =20 port =3D devm_kcalloc(dev, num_ports, sizeof(*port), GFP_KERNEL); if (!port) @@ -581,6 +622,17 @@ drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_ty= pec_bridge_data *typec_dat if (IS_ERR(port->mode_switch)) 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 fwnode_get_name(fwnode); + port->orientation_switch =3D typec_switch_register(dev, + &orientation_switch_desc); + if (IS_ERR(port->orientation_switch)) + return PTR_ERR(port->orientation_switch); + } + port++; } =20 --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 335E81E6757 for ; Mon, 19 Aug 2024 22:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107137; cv=none; b=Zb9Z0gM/osMIP0gOzFM59JCHKM8XTEfotTCODjIL31VhJN2niFJgOWHG/oX9QV9PTc9h528dCTOHZiKYudtwCfcknXPQbr4xEXWqAaos9tvPksv0FBItxiWAQODDamwgN+t8U/rV8p09A31qeJRvPRT3blTIafcp7pJosUTy0js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107137; c=relaxed/simple; bh=w0g28qwx8ttFAPV6ZVJOMX16jfJkNFs/UtJNKWMbmpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hp0grhWScKN19kGLPzVNwHIXAhiHmINV/xHJt38cgL68MPG7OA+s7RyHFcatvCmgoIRdMKLqpw5GA5Sm37rIP5QTA7OOsDt0lxuJoOVgaJmELQPHQ2jNfjy+xgiESJrSL1h2UuZvrXg1rRkzjSuSaOheQwjWyXPiB4kRur+c2jw= 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=kkhCjsck; arc=none smtp.client-ip=209.85.214.173 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="kkhCjsck" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20208830de8so26787165ad.1 for ; Mon, 19 Aug 2024 15:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107134; x=1724711934; 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=pt5zDRruoKDjEjtxbZ90FeaEpY41huFpHL2b0DQLSiI=; b=kkhCjsck75mmX+R9nnoNWwAc9TILHtvcuT5fK6SJh+mViCJbFV4HQu8hJgCJIF/Jsn eS2+HGQWp433jdCaDKxj5IdB2/stW3YhIAMVHuTIjECSjZRzbE5pq44+Znjhcb1Tsix5 r2Eo5gcJR3D3Go0qcpcaWntfIttiM299t04FA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107134; x=1724711934; 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=pt5zDRruoKDjEjtxbZ90FeaEpY41huFpHL2b0DQLSiI=; b=lPhJuPvk5n82ZNXzV0xMIqI6kB/GYXwfW+pLQ+Q/zC13PEe2Drzw7w/qJMkGpICTMk qo+s6UOgoBXLus142WPcBB4rBu5R4t7Ju2L9d4lWyNK5zwtONp4cNv/Nkne6U4c/VXek 6X+4CmAK5ff3x94uuYlCzQ1wiyCcuWoRlG2d1n74bt7zx+VznTRnciMkrBA333uQGWxT bWTENbUnjALZVaNtS/M3F6RYpf38xB2s/86kShgrRaYydJgjl/gdgH5R5qKnY7+qK4oI H14wnVtVudd9b8mzaanOBpJoFsKOa48Fg8da0U+yJozu1YEilA1e31V7PY4BQV49HU2b Qidw== X-Gm-Message-State: AOJu0YypC73kOBEWP/WFmJermwjyx/EEIf+ggbKXsjgwSX5avwIWWUAt glI3LwXf//vx3RXjVFQ/7574BvbQKpmYaC2OqRGetdFuJijLTYxi2ZY1R2g/kg== X-Google-Smtp-Source: AGHT+IGfZHELLF2y6L1aI/WGPxevrMzKOrLMaAgnD4U9RjeVY5g2VfRdfv/wemc3Z0vA24M/fT5EYw== X-Received: by 2002:a17:902:ecc7:b0:1fb:8e25:e631 with SMTP id d9443c01a7336-20308af2ef0mr6166935ad.8.1724107134306; Mon, 19 Aug 2024 15:38:54 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f038a84esm67020355ad.189.2024.08.19.15.38.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:53 -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 v3 08/17] drm/bridge: dp_typec: Add "no-hpd" support Date: Mon, 19 Aug 2024 15:38:22 -0700 Message-ID: <20240819223834.2049862-9-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Add support for HPD coming from somewhere else in the drm_bridge chain. Skip signaling HPD sate when "no-hpd" is present in the DT node backing the dp_typec bridge. Add this support because some EC firmwares on Trogdor/Strongbad boards don't properly indicate the state of the DP HPD level on a type-c port. The EC only indicates that DP mode is entered or exited for a type-c port. The HPD level is expressed to the DP controller via a pin on the AP that the EC drives high or low when the type-c port partner (i.e. monitor) asserts or deasserts HPD. 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/brid= ge/aux-hpd-bridge.c index 3d33f7936cbc..adafda4f128f 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -22,6 +22,7 @@ static DEFINE_IDA(drm_aux_hpd_bridge_ida); struct drm_aux_hpd_bridge_data { struct drm_bridge bridge; struct device *dev; + bool no_hpd; }; =20 enum dp_lane { @@ -354,6 +355,8 @@ void drm_aux_hpd_bridge_notify(struct device *dev, enum= drm_connector_status sta =20 if (!data) return; + if (data->no_hpd) + return; =20 drm_bridge_hpd_notify(&data->bridge, status); } @@ -662,6 +665,7 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_de= vice *auxdev, return -ENOMEM; bridge =3D &hpd_data->bridge; bridge->funcs =3D &drm_aux_hpd_bridge_funcs; + bridge->ops =3D DRM_BRIDGE_OP_HPD; } else if (id->driver_data =3D=3D DRM_AUX_TYPEC_BRIDGE) { typec_data =3D devm_kzalloc(dev, sizeof(*typec_data), GFP_KERNEL); if (!typec_data) @@ -670,6 +674,9 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_de= vice *auxdev, bridge =3D &hpd_data->bridge; bridge->funcs =3D &drm_dp_typec_bridge_funcs; typec_bridge_dev =3D to_drm_dp_typec_bridge_dev(dev); + hpd_data->no_hpd =3D of_property_read_bool(np, "no-hpd"); + if (!hpd_data->no_hpd) + bridge->ops =3D DRM_BRIDGE_OP_HPD; memcpy(typec_data->dp_lanes, dp_lanes, sizeof(typec_data->dp_lanes)); ret =3D drm_dp_typec_bridge_probe_typec_ports(typec_data, typec_bridge_d= ev, np); if (ret) @@ -679,8 +686,7 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_de= vice *auxdev, } =20 hpd_data->dev =3D dev; - bridge->of_node =3D dev_get_platdata(dev); - bridge->ops =3D DRM_BRIDGE_OP_HPD; + bridge->of_node =3D np; bridge->type =3D DRM_MODE_CONNECTOR_DisplayPort; =20 auxiliary_set_drvdata(auxdev, hpd_data); --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 3F86A1E7A42 for ; Mon, 19 Aug 2024 22:38:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107139; cv=none; b=cDQu1JRNbmtiCKh+sxwO5x4Y8ZwFnyC0ki9iH1VarIek0QVjEBLVHN3peltIx1ISJrrkBhWbL3PUmD8L38K/MTiZGURJ7Z1UYQS+inIDVcfrGcqB+rhdU0501oKnL50OG/XDqMOuhECFNSBhoBJTy5xzAIgnM/gB5Vs76UpqmTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107139; c=relaxed/simple; bh=4V2ipobc0QJANgLcRKLlZNLcULLuLPLzgIJNP1W0OjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qcbGMdIOpMaY+M2oeEtpUj+qPfM0dXd/ElTEKkio6/K2fdOglxz0/iZBTQO6H04qexeH83dQLKml3gFBEqh3y61cDYChiggbep1fhf0+TjJuOe38+jS/ZqeAZQ8EqCNcsalFcVWAbDTzMc73d6SfEg1+sjFNZ+iMjqBxnuWsH38= 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=cLXSIE7i; arc=none smtp.client-ip=209.85.214.171 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="cLXSIE7i" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2021537a8e6so27598065ad.2 for ; Mon, 19 Aug 2024 15:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107137; x=1724711937; 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=ywA8OaX1lKwB+QkeZviPO0tfv2glr07Z2pzYI3lLnXA=; b=cLXSIE7i3A5rPEePFBioba0Q6cg5DedcUbRQ5Ep89kFgATSdN8YkOJM4JdTTwtfd3f eiYd8bZfUBVRYy7icKJ+tDidWF8qqiOGOhip+2q1xnsPopErGzT6bWwK9zzRqe1RgTBv AxgRQDdCl2eUsVeXopvwwoRugsApweDA7vcGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107137; x=1724711937; 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=ywA8OaX1lKwB+QkeZviPO0tfv2glr07Z2pzYI3lLnXA=; b=McIu283rvPu3gVGLyYZbotiznUm7FJ2LRSlEgTgDFiUnOQxVz8+YEfP0jOAmf7jLAz 1NrLTG5meelzbnvEUO/nY1axcattQ1Yovje8hJXzy2O6JN0Y0st0rbEjPhMK7qNv9EF6 o6HoM8HLhe/3Kv7OcU6DnMAoqX0N+JlHqIxheHvJhjx8JxZv6XtzaCp95LlynEz3NPca twCyGuyR8TbkDV6XArfyrHcApmJGZjIopfx/3dMiuF67h4eAfbdcnbjcRCmCJjWOrDIb 8qbSm6cB+X4mEXXxS4Y6f6QEOcXkdrRg38kywps1HamUgRBdozgH3qRdepj0LTYJJNNX NxzQ== X-Gm-Message-State: AOJu0Yzh5W3z82ni8rMEbuUpfPTf8jGkxRIVmVbEkY82pEf9TLsZxe/8 tAsdYlt879ax41G7Z+TnOOD3edCrqKF8SESgImdTXzXspMXgof7SYk1gl3GdKg== X-Google-Smtp-Source: AGHT+IHU3fWl4J6FiNvoKYuzaU+U5zGX0CHN6uE8R8CkbVuBd7tiKsG0Va+2cgyvp5/pf3qE90i/nA== X-Received: by 2002:a17:902:d503:b0:201:f5e3:e36d with SMTP id d9443c01a7336-20203ea05d2mr143563805ad.25.1724107136555; Mon, 19 Aug 2024 15:38:56 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f03b2874sm66740535ad.308.2024.08.19.15.38.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:56 -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 v3 09/17] drm/bridge: dp_typec: Allow users to hook hpd notify path Date: Mon, 19 Aug 2024 15:38:23 -0700 Message-ID: <20240819223834.2049862-10-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" The previous patch added support for no-hpd to drm_dp_typec_bridge code. Allow users of this bridge to hook the HPD notification path of the bridge chain so that they can be made aware of the connector status changing. This helps HPD-less users of the bridge inject the HPD state into their code by using the connector status as a proxy for HPD being asserted or deasserted. In particular, this will help Trogdor/Strongbad boards that need to read the EC's analog mux which steers the DP signal to one or the other USB type-c ports to figure out which type-c port has HPD asserted. 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 | 30 +++++++++++++++++++++++++ include/drm/bridge/aux-bridge.h | 9 ++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/brid= ge/aux-hpd-bridge.c index adafda4f128f..815dc026718b 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -92,6 +92,8 @@ struct drm_dp_typec_bridge_dev { struct auxiliary_device adev; size_t max_lanes; size_t num_typec_ports; + void (*hpd_notify)(void *data, enum drm_connector_status status); + void *hpd_data; }; =20 static inline struct drm_dp_typec_bridge_dev * @@ -323,6 +325,20 @@ devm_drm_dp_typec_bridge_alloc(struct device *parent, = struct device_node *np) } EXPORT_SYMBOL_GPL(devm_drm_dp_typec_bridge_alloc); =20 +/** + * drm_dp_typec_bridge_add_hpd_notify: Register a callback called when the + * bridge chain hpd state changes + * @hpd_notify: callback for bridge hot plug detect events + * @hpd_data: data passed to @hpd_notify callback + */ +void drm_dp_typec_bridge_add_hpd_notify(struct drm_dp_typec_bridge_dev *ty= pec_bridge_dev, + hpd_notify_fn_t hpd_notify, void *hpd_data) +{ + typec_bridge_dev->hpd_notify =3D hpd_notify; + typec_bridge_dev->hpd_data =3D hpd_data; +} +EXPORT_SYMBOL_GPL(drm_dp_typec_bridge_add_hpd_notify); + /** * devm_drm_dp_typec_bridge_add - register a USB type-c DisplayPort bridge * @dev: struct device to tie registration lifetime to @@ -362,6 +378,19 @@ void drm_aux_hpd_bridge_notify(struct device *dev, enu= m drm_connector_status sta } EXPORT_SYMBOL_GPL(drm_aux_hpd_bridge_notify); =20 +static void drm_dp_typec_bridge_hpd_notify(struct drm_bridge *bridge, + enum drm_connector_status status) +{ + struct drm_dp_typec_bridge_data *data; + struct drm_dp_typec_bridge_dev *typec_bridge_dev; + + data =3D to_drm_dp_typec_bridge_data(bridge); + typec_bridge_dev =3D to_drm_dp_typec_bridge_dev(data->hpd_bridge.dev); + + if (typec_bridge_dev->hpd_notify) + typec_bridge_dev->hpd_notify(typec_bridge_dev->hpd_data, status); +} + static int drm_aux_hpd_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { @@ -519,6 +548,7 @@ static const struct drm_bridge_funcs drm_dp_typec_bridg= e_funcs =3D { .atomic_reset =3D drm_atomic_helper_bridge_reset, .atomic_duplicate_state =3D drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state =3D drm_atomic_helper_bridge_destroy_state, + .hpd_notify =3D drm_dp_typec_bridge_hpd_notify, }; =20 static int drm_dp_typec_bridge_orientation_set(struct typec_switch_dev *sw, diff --git a/include/drm/bridge/aux-bridge.h b/include/drm/bridge/aux-bridg= e.h index 73fc8582ec07..300f4a203a9b 100644 --- a/include/drm/bridge/aux-bridge.h +++ b/include/drm/bridge/aux-bridge.h @@ -22,6 +22,8 @@ static inline int drm_aux_bridge_register(struct device *= parent) =20 struct drm_dp_typec_bridge_dev; =20 +typedef void (*hpd_notify_fn_t)(void *data, enum drm_connector_status stat= us); + #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE) struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *paren= t, struct device_node *np); int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device= *adev); @@ -30,6 +32,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *= parent, void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_stat= us status); struct drm_dp_typec_bridge_dev *devm_drm_dp_typec_bridge_alloc(struct devi= ce *parent, struct device_node *np); +void drm_dp_typec_bridge_add_hpd_notify(struct drm_dp_typec_bridge_dev *ty= pec_bridge_dev, + hpd_notify_fn_t hpd_notify, void *hpd_data); int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_b= ridge_dev *typec_bridge_dev); #else static inline struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct= device *parent, @@ -55,6 +59,11 @@ devm_drm_dp_typec_bridge_alloc(struct device *parent, st= ruct device_node *np) return NULL; } =20 +static inline void drm_dp_typec_bridge_add_hpd_notify(struct drm_dp_typec_= bridge_dev *typec_bridge_dev, + hpd_notify_fn_t hpd_notify, void *hpd_data) +{ +} + static inline int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_bridge_dev *typec_bridge_dev) { --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 8190D1EB487 for ; Mon, 19 Aug 2024 22:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107141; cv=none; b=A2Kic9pCddRJOqKbghOYYbhdsV0nqUQRHleWZeyaGS1JGyVQMuyy/Tue/79V3zyv8ChICHEwayR/g2HlWumBHkJRHDc80e2PJBC6fhogjQMzR/l7vrKEuhNL6HmwPnBiFvvU2PY4XWzUbQydx2MEVv6OfhrRBTZXUMCpdLriUJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107141; c=relaxed/simple; bh=mxX0zurMaqjFAvwPTAYvbkHJDOrh+ogY61LYBsDimY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=THKRtzp2JK7N09xnW9qAZImdKUkdtlibNAQEt1ecU77StIgtbqG6/ahk0Q9IJvz1RAiE0IJCAHMwGmeo0UutI/opXvDr44eimk5oMCRibsp2NK4E+NtTCWeD7SqEDO0VENoB2vk9aCeQ1GG0TLnyEKq/g/XRa17yfk411WkQu+k= 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=TPjbauuX; arc=none smtp.client-ip=209.85.214.176 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="TPjbauuX" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20231aa8908so13930335ad.0 for ; Mon, 19 Aug 2024 15:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107139; x=1724711939; 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=hC911fBOHCsJMM7xcu9tR0EWsA9wFiTFaVVHtkvUAjk=; b=TPjbauuXLwswYIfgU4XKPckbyt4bWQRplbONiBpsOocVka0VmTyWO+x5xAK289W0Ls +awtyb2eSWgtplIUIGswiOQLHRsoGKt0YxF1XoaJMm6lduI0W//W8hTz3yQG7HcgX+RC DbCe+Gg9z9fO5gHBfK4M+3Pdbg5QJTQUMHBqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107139; x=1724711939; 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=hC911fBOHCsJMM7xcu9tR0EWsA9wFiTFaVVHtkvUAjk=; b=APiezaoyAvhJucVseaMbmywkh+E5AyRPOael6HK4+8uHvvF7AAhcWjFAKgSU/8X5ox 9+9KNS8UiXUNsTw5KLTeK6vTPTaW09pC/yip2Ig2dR3DkFhMfPah2OMFeSi/FjU832bv rhkpNpVgtIqf2vFNKJIFNCJTWWrz1XJN61Lc4MDdwL7GBJ0UzILxRFpErEbGy0sctHoL WvDE16JD8O7wp+DabdYW8zIhIWXGGCK6Czj4xnL+mxYorew9DTYVXs5NpLPOfQOh1p7F Yfp/42VmlyQBKR7rjro3OUFCDJYyNmw7Y9Cmr2mb7VcF10YgwH3NLBo8+Dn48x4kMzGZ 7LIQ== X-Gm-Message-State: AOJu0Ywd1c4Gjoa7Uld1hipn2Q4kl7+z2X/XUsvoYxsRqCh9c2Cj9pDH S9FtAsXUP+xJupIOjEBk8DRc2vtKkYYGtkSfuAf2b28gxsLryHu+X18H8FtBiA== X-Google-Smtp-Source: AGHT+IGLjuWtpZx7vqGNlEmVLbw+/jbA0jrqk36BQ9obYmr0oT4bTrUtSNP+SOsQgfFW6VfGITSwMw== X-Received: by 2002:a17:903:4345:b0:201:f8b4:3e3c with SMTP id d9443c01a7336-20203e49439mr92807475ad.12.1724107138748; Mon, 19 Aug 2024 15:38:58 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f038b4e9sm66612995ad.209.2024.08.19.15.38.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:38:58 -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 v3 10/17] device property: Add remote endpoint to devcon matcher Date: Mon, 19 Aug 2024 15:38:24 -0700 Message-ID: <20240819223834.2049862-11-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" When a single DT node has a graph connected to more than one usb-c-connector node we can't differentiate which typec switch registered for the device is associated with the USB connector because the devcon matcher code assumes a 1:1 relationship between remote node and typec switch. Furthermore, we don't have a #typec-switch-cells property so there can only be one node per typec switch. Support multiple USB typec switches exposed by one node by passing the remote endpoint node in addition to the remote node to the devcon matcher function (devcon_match_fn_t). With this change, typec switch drivers can register switches with the device node pointer for a graph endpoint so that they can support more than one typec switch if necessary. Either way, a DT property like 'mode-switch' is always in the graph's parent node and not in the endpoint node. Cc: Andy Shevchenko Cc: Daniel Scally Cc: Heikki Krogerus Cc: Sakari Ailus Cc: Greg Kroah-Hartman Cc: Vinod Koul Cc: "Rafael J. Wysocki" Cc: Mika Westerberg Cc: Alexandre Belloni Cc: Ivan Orlov Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/base/property.c | 7 +++++-- drivers/usb/roles/class.c | 4 ++-- drivers/usb/typec/mux.c | 8 ++++++++ drivers/usb/typec/retimer.c | 7 ++++++- include/linux/property.h | 5 +++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 837d77e3af2b..621de33f2956 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1284,6 +1284,7 @@ static unsigned int fwnode_graph_devcon_matches(const= struct fwnode_handle *fwno { struct fwnode_handle *node; struct fwnode_handle *ep; + struct fwnode_handle *remote_ep; unsigned int count =3D 0; void *ret; =20 @@ -1299,7 +1300,9 @@ static unsigned int fwnode_graph_devcon_matches(const= struct fwnode_handle *fwno continue; } =20 - ret =3D match(node, con_id, data); + remote_ep =3D fwnode_graph_get_remote_endpoint(ep); + ret =3D match(node, remote_ep, con_id, data); + fwnode_handle_put(remote_ep); fwnode_handle_put(node); if (ret) { if (matches) @@ -1329,7 +1332,7 @@ static unsigned int fwnode_devcon_matches(const struc= t fwnode_handle *fwnode, if (IS_ERR(node)) break; =20 - ret =3D match(node, NULL, data); + ret =3D match(node, NULL, NULL, data); fwnode_handle_put(node); if (ret) { if (matches) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index d7aa913ceb8a..d8bd5071d9d8 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -121,8 +121,8 @@ enum usb_role usb_role_switch_get_role(struct usb_role_= switch *sw) } EXPORT_SYMBOL_GPL(usb_role_switch_get_role); =20 -static void *usb_role_switch_match(const struct fwnode_handle *fwnode, con= st char *id, - void *data) +static void *usb_role_switch_match(const struct fwnode_handle *fwnode, con= st struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; =20 diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 3531ab03bac4..ab53532282ff 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -33,6 +33,7 @@ static int switch_fwnode_match(struct device *dev, const = void *fwnode) } =20 static void *typec_switch_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -55,6 +56,9 @@ static void *typec_switch_match(const struct fwnode_handl= e *fwnode, */ dev =3D class_find_device(&typec_mux_class, NULL, fwnode, switch_fwnode_match); + if (!dev) + dev =3D class_find_device(&typec_mux_class, NULL, endpoint, + switch_fwnode_match); =20 return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -290,6 +294,7 @@ static int mux_fwnode_match(struct device *dev, const v= oid *fwnode) } =20 static void *typec_mux_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -307,6 +312,9 @@ static void *typec_mux_match(const struct fwnode_handle= *fwnode, =20 dev =3D class_find_device(&typec_mux_class, NULL, fwnode, mux_fwnode_match); + if (!dev) + dev =3D class_find_device(&typec_mux_class, NULL, endpoint, + mux_fwnode_match); =20 return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c index b519fcf358ca..ee4e6312c2d9 100644 --- a/drivers/usb/typec/retimer.c +++ b/drivers/usb/typec/retimer.c @@ -22,7 +22,9 @@ static int retimer_fwnode_match(struct device *dev, const= void *fwnode) return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode); } =20 -static void *typec_retimer_match(const struct fwnode_handle *fwnode, const= char *id, void *data) +static void *typec_retimer_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; =20 @@ -31,6 +33,9 @@ static void *typec_retimer_match(const struct fwnode_hand= le *fwnode, const char =20 dev =3D class_find_device(&retimer_class, NULL, fwnode, retimer_fwnode_match); + if (!dev) + dev =3D class_find_device(&retimer_class, NULL, endpoint, + retimer_fwnode_match); =20 return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/include/linux/property.h b/include/linux/property.h index 61fc20e5f81f..3e27d7b76db9 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -507,8 +507,9 @@ unsigned int fwnode_graph_get_endpoint_count(const stru= ct fwnode_handle *fwnode, int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); =20 -typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, con= st char *id, - void *data); +typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, + const char *id, void *data); =20 void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, const char *con_id, void *data, --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 0481320010C for ; Mon, 19 Aug 2024 22:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107143; cv=none; b=AAja/aXapA7Eivh67any7DxN5ew95qSWVwpEOKrSrpiu9/GFbO+0SHnikt8LP8dQrpxR/w8ZSZW8C+cH+sJa2k9fyVZKTwvp99MMGHmn0wor+0H0phqTn/MIl53GQ7rOKlB51B/huE+JuUY2OfSDKr4RRMU3vkgJ9pA+9L3bMk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107143; c=relaxed/simple; bh=8tqmUj+sdPUk4dj2c30W8lWQ9x5+wvhFnf8zSNBC8MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fvnMG/PvAVOdfgJ18/sRcurloYVEzQqScIzY8qqiQwd9B2chm7W74slze76WPyKbhwaN/0zmMiCw9DY8DSGB6GHz55hizoY+MoU0wZX6LBt0aR4c4j05V9pqXaq1scaDqDKIvwKg+03iqPo1eenqkGCEvLaJsMk7D6BPZrKwZ2Y= 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=MKvtHV6E; arc=none smtp.client-ip=209.85.214.175 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="MKvtHV6E" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fec34f94abso42165045ad.2 for ; Mon, 19 Aug 2024 15:39:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107141; x=1724711941; 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=MEGuE2jPeE6QbHnwj3cv7uloVpjVvE++iKPlChg2NtM=; b=MKvtHV6E8vM4hJGZFZ6ewM50hyrKC8dTk+uCtC39eDILghokKBg0E6d29m+faFFKCL +FnP4RhLBfP/ofNBTCxfcIsA52XgTK1oqOB5UqG+iKiHdvh2rpnN7gi7d08MDHujKD1D sSOw1ey29Vt+wa/18I085T1nxVXBLfYSWG3wc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107141; x=1724711941; 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=MEGuE2jPeE6QbHnwj3cv7uloVpjVvE++iKPlChg2NtM=; b=sO2Iob4YwNs6lnsYE1DT0QxlLhhd7XBbOGF8H8cn7LHBI+xZYwJbOl+wStfeJzHQdc n7RGc/iEEpRBI4i62rB6SHSYS6EtbsSZ8b42sbijddLzLTqww4wDdLFAuIauW62GUcjU OfJp1zU4sZkv30TYW47iHsCU667qMfGkYoGEfhZGjf/sF2mVSa60itR4/CooQ5WAH+Nm 9RfF8jJ4T4rVoRg2Io6hdkh6bJqeqXvyu+pp0CpOhUQPZHZp+Iie6161k/9URIPcI8Gh dUtIXynejE7dCVKK4QZk8Kg3SK+xw+A63WlZ356PPIVfMo+kt7tsvC5NKmsu14bLdfrE 37dA== X-Gm-Message-State: AOJu0YyQFWRnkV+w+JkI00YUDt89uS6lWdC3qVvjrT7aHSJzhwMJRYgJ WjU2GUiONu6NykkOGlwlIAX31qKvXa9xIenRITZ4DlOUexFMOyVBxf6HPnlclQ== X-Google-Smtp-Source: AGHT+IE9StWMBY/V2J5PvOnUgBdk52braBes3M3nIXsSIZjwGAz5lGGOgioaoZfLakp02OBmpgHzZg== X-Received: by 2002:a17:902:e74b:b0:202:348d:4e85 with SMTP id d9443c01a7336-202348d51eemr70659895ad.39.1724107141155; Mon, 19 Aug 2024 15:39:01 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f03a3607sm67131795ad.250.2024.08.19.15.38.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:00 -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 v3 11/17] dt-bindings: usb-switch: Extract endpoints to defs Date: Mon, 19 Aug 2024 15:38:25 -0700 Message-ID: <20240819223834.2049862-12-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Move the usb-switch endpoint bindings to defs so that they can be reused by other bindings. Future users of this binding will have more than one type-c output node when they're muxing a single DP signal to more than one usb-c-connector. Add an example to show how this binding can be used and accelerate binding checks. Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Benson Leung Cc: Guenter Roeck Cc: Prashant Malani Cc: Tzung-Bi Shih Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring (Arm) --- .../devicetree/bindings/usb/usb-switch.yaml | 74 ++++++++++++++++--- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/usb-switch.yaml b/Docume= ntation/devicetree/bindings/usb/usb-switch.yaml index da76118e73a5..5fc031b56fad 100644 --- a/Documentation/devicetree/bindings/usb/usb-switch.yaml +++ b/Documentation/devicetree/bindings/usb/usb-switch.yaml @@ -35,9 +35,13 @@ properties: $ref: /schemas/graph.yaml#/properties/ports properties: port@0: - $ref: /schemas/graph.yaml#/properties/port - description: - Super Speed (SS) Output endpoint to the Type-C connector + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + + properties: + endpoint: + $ref: '#/$defs/usbc-out-endpoint' + unevaluatedProperties: false =20 port@1: $ref: /schemas/graph.yaml#/$defs/port-base @@ -47,16 +51,8 @@ properties: =20 properties: endpoint: - $ref: /schemas/graph.yaml#/$defs/endpoint-base + $ref: '#/$defs/usbc-in-endpoint' unevaluatedProperties: false - properties: - data-lanes: - $ref: /schemas/types.yaml#/definitions/uint32-array - minItems: 1 - maxItems: 8 - uniqueItems: true - items: - maximum: 8 =20 oneOf: - required: @@ -65,3 +61,57 @@ oneOf: - ports =20 additionalProperties: true + +$defs: + usbc-out-endpoint: + $ref: /schemas/graph.yaml#/$defs/endpoint-base + description: Super Speed (SS) output endpoint to a type-c connector + unevaluatedProperties: false + + usbc-in-endpoint: + $ref: /schemas/graph.yaml#/$defs/endpoint-base + description: Super Speed (SS) input endpoint from the Super Speed PHY + unevaluatedProperties: false + properties: + data-lanes: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 8 + uniqueItems: true + items: + maximum: 8 + +examples: + # A USB orientation switch which flips the pin orientation + # for a usb-c-connector node. + - | + device { + orientation-switch; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + endpoint { + remote-endpoint =3D <&usb_c_connector>; + }; + }; + + port@1 { + reg =3D <1>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + endpoint { + remote-endpoint =3D <&usb_ss_phy>; + }; + }; + }; + }; + +... --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 088F620012F for ; Mon, 19 Aug 2024 22:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107145; cv=none; b=ulTGD9+cWHOWGlUB84WPBy2sjdp4UtL4o8gze3qJkl+RptISdn/nhr+N0lWQcdQtUbbPEH/aKuaMiAAfWRG3u1hezXkRztT6nx/KM+qQy2WJEiNdF3/tMmNUi9hwbCBKtWNstgmPfWCnc1zkUUMXA+WvnzfbkJk9s7g+t5ILk8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107145; c=relaxed/simple; bh=OyfKCvFwATaUez+mf6fqverYicn9LjhxOLPnjc5Aioo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ITssGnwOYdM9vyYy6AhG/mz/rt29EYbDi2gvT7EXNJXXDKpkgzuuz9aGiNdxIdLDQ4THw4QUmv0cARJtcXOcdjjonpP+JDVCaJ6mZ2e+zKmfJTLTkpV9E28WteLSmaQiDuxSmVbqVEOYoBngrh0D8gzr4ehpLwQvBN2ENDeeVGk= 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=QEThiaFP; arc=none smtp.client-ip=209.85.210.178 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="QEThiaFP" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-712603f7ba5so3872819b3a.3 for ; Mon, 19 Aug 2024 15:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107143; x=1724711943; 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=+KXXy3QiBKqggoPFDIuBfkDFn401Aqji9aDGpL9/5hY=; b=QEThiaFPy3jMiwt3vGxKE5TNLpLw6/YcxtKVI3S/vuQAJ1U9tWv78tC4/bA4Ezt2Xr NcffNhI41xl5eXh80Du4uxt5DIy+FuMf/i8rBtc9q9s0SWdB8imCFYviMPwa9pE2H9TG eKQ55xG1sJXbPNEJU/GyKPAvFSqzrJiHkJ4Zw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107143; x=1724711943; 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=+KXXy3QiBKqggoPFDIuBfkDFn401Aqji9aDGpL9/5hY=; b=G9Fk2uOHJ8XMGpT7Xxyty792S9+M3D9EFgLvNtpD4cltGQ2kRvEcL7AlPiXVd2DmF8 bEg5yZBELNAwvE+025Mog3HsgjN+e2Sf5r2Z68HIpAllZlBy96zRJ7DOz73j10ig+RSO J8wXqn/ScnzVqXC8sN4sRMa2BJfzBV9FtaNoeV+aZsIepgECmynLJEvSC2s58Zy/Aho9 +cFWPT6pWFbkP6UvHRou4T9OR1zpaeBLnCZM2mZO4+a6cezAXfgQDwXeWJw6PrWXjZGy 5T8P05eTr1Xe24nN7LPLcKiP10JOPNiYW4CGrenaewRgbRBUbZ1dbqkouyM8BtT3Kifo YbVg== X-Gm-Message-State: AOJu0YyygGr8MLssfalccG2KzBNhOYecoRQmxjSPm1FieQxhwNnYOW8F xjPNmsTYg/OIOXGi/vfa1t/oSn9TcNMhHma/GxkEJqT4jCm4pbI3shiA981S1w== X-Google-Smtp-Source: AGHT+IHkcygBzOoFTnBwjvK9vCMx1AS2hQGHjZYX96J9FuIVU3ZRveOh/nk0VuMfJPp9k0jk6TfziQ== X-Received: by 2002:a05:6a20:3149:b0:1ca:c958:bf55 with SMTP id adf61e73a8af0-1cac958bf92mr516935637.0.1724107143200; Mon, 19 Aug 2024 15:39:03 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7c6b636bcabsm8080907a12.90.2024.08.19.15.39.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:02 -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 v3 12/17] dt-bindings: usb-switch: Extend for DisplayPort altmode Date: Mon, 19 Aug 2024 15:38:26 -0700 Message-ID: <20240819223834.2049862-13-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Extend the usb-switch binding to support DisplayPort (DP) alternate modes. A third port for the DP signal is necessary when a mode-switch is muxing USB and DP together onto a usb type-c connector. Add data-lanes to the usbc output node to allow a device using this binding to remap the data lanes on the output. Add an example to show how this new port can be used. Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Benson Leung Cc: Guenter Roeck Cc: Prashant Malani Cc: Tzung-Bi Shih Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring (Arm) --- .../devicetree/bindings/usb/usb-switch.yaml | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-switch.yaml b/Docume= ntation/devicetree/bindings/usb/usb-switch.yaml index 5fc031b56fad..7a932c638a90 100644 --- a/Documentation/devicetree/bindings/usb/usb-switch.yaml +++ b/Documentation/devicetree/bindings/usb/usb-switch.yaml @@ -54,6 +54,15 @@ properties: $ref: '#/$defs/usbc-in-endpoint' unevaluatedProperties: false =20 + port@2: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + + properties: + endpoint: + $ref: '#/$defs/dp-endpoint' + unevaluatedProperties: false + oneOf: - required: - port @@ -67,6 +76,19 @@ $defs: $ref: /schemas/graph.yaml#/$defs/endpoint-base description: Super Speed (SS) output endpoint to a type-c connector unevaluatedProperties: false + properties: + data-lanes: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + An array of physical USB Type-C data lane indexes. + - 0 is SSRX1 lane + - 1 is SSTX1 lane + - 2 is SSTX2 lane + - 3 is SSRX2 lane + minItems: 4 + maxItems: 4 + items: + maximum: 3 =20 usbc-in-endpoint: $ref: /schemas/graph.yaml#/$defs/endpoint-base @@ -81,7 +103,75 @@ $defs: items: maximum: 8 =20 + dp-endpoint: + $ref: /schemas/graph.yaml#/$defs/endpoint-base + description: DisplayPort (DP) input from the DP PHY + unevaluatedProperties: false + properties: + data-lanes: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + An array of physical DP data lane indexes + - 0 is DP ML0 lane + - 1 is DP ML1 lane + - 2 is DP ML2 lane + - 3 is DP ML3 lane + oneOf: + - items: + - const: 0 + - const: 1 + - items: + - const: 0 + - const: 1 + - const: 2 + - const: 3 + examples: + # A USB + DP mode and orientation switch which muxes DP altmode + # and USB onto a usb-c-connector node. + - | + device { + mode-switch; + orientation-switch; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + endpoint { + remote-endpoint =3D <&usb_c_connector>; + data-lanes =3D <0 1 2 3>; + }; + }; + + port@1 { + reg =3D <1>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + endpoint { + remote-endpoint =3D <&usb_ss_phy>; + }; + }; + + port@2 { + reg =3D <2>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + endpoint { + remote-endpoint =3D <&dp_phy>; + data-lanes =3D <0 1 2 3>; + }; + }; + }; + }; + # A USB orientation switch which flips the pin orientation # for a usb-c-connector node. - | --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 13617201251 for ; Mon, 19 Aug 2024 22:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107147; cv=none; b=tmPS2NQNmW8iCZhxRJkFxHpLLu3wzZEL9/bIABlyrUDI8sugxltKSM5+5MsBwmhq0+8UZG/l3ba77MnEWNqIohGrFtbsmMvaQ7rfKsvwuJGWkMiyYHK1U3ecjNx1eN30sJTs6S7uFltDvbFKbgbW+Vi2IH2SfIFARs7O74FZV4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107147; c=relaxed/simple; bh=Ti4xspzmJb0dyaL6KteaBPQDBI0NpBagPW8WNKTO9c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bJ6LluWgma2vhfPf6ivRS5yFwgwWn5NgdIOl4OEYBf/LLdojqk7IIrVFaGniuhkRYBnQtG50maeKkoTkd1zK+Zvc2+K45fx35AR/O/hX9LtmXEbykVQ+MmvLcsGLkC93wdo8IlZ34D0lB1+9zJ9r6qLC27mFLtvMNew41WzbC8s= 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=hnsZ6E9I; arc=none smtp.client-ip=209.85.210.177 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="hnsZ6E9I" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70cec4aa1e4so3245893b3a.1 for ; Mon, 19 Aug 2024 15:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107145; x=1724711945; 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=T31q96nI7HTHANhAbPDLeTjBqmklGP7ssi3aURXB78Y=; b=hnsZ6E9IBkGhSKmLHnPwTg9oSL9wZUydHI7JGaa7mXKpzyOpwINYhxstOPNI+NZYHf eNxR3aXYJHJvm7ORjktVfmfGeLvZrYJKzfGWUE9kvhxU7BMtzFzko9FFvNWI3zkU8uLZ N0cm7UVBklMh3fsMCpL3g8iFgVfChj/2MzLRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107145; x=1724711945; 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=T31q96nI7HTHANhAbPDLeTjBqmklGP7ssi3aURXB78Y=; b=Vk+sZTGH2OZm4WY1mGE967qRFoRzOLjD9gHppMHngCHUOAEkW+0NBDwa2aB5S310nf rokekDR1ZkIjNArrhDcmqE2aGot7oF5yUEeHfmHBJf0UU0EI9Qc9d5tfIE/N2GwIfTw8 laFTyYYdfFZ5DdE8dimqvGJgrmaroJZBPehgIt2+zE1Nr592HxDydmWNDlIBCN4HvQyJ J4N2nyfixaNWN7w0kSHFkwTMGmiWMZDHeu6eiIKTmhUIt+GzaLzEIgMXPfpp9TicIBCI vCkOUTBWzUxVN25fGGLWrpwSuRND00rJ2CRVbQPuV2g+NdU5VwOMM3jf8n/d9/qQvMkr 9Xqw== X-Gm-Message-State: AOJu0YzWuLK6Jv3LvQb7l8TP547ZOU888GO7SUSr2IXR3G0ITfSSXtsa b1MXH8+qBTAWIJDFU/9dnKPQ8EuZsWRppwucH0QvetrIxWXGQXUWGDy73XAccQ== X-Google-Smtp-Source: AGHT+IGkbe8vELlVZVdfm7iYACRe3TPZ4k2lnZ7T8LU4DsUAYy70X4jlTSj4PuE13uFvl6Gg6qUx3g== X-Received: by 2002:a05:6a00:6f68:b0:70d:2556:2b1 with SMTP id d2e1a72fcca58-713c4e73cccmr14140075b3a.13.1724107145269; Mon, 19 Aug 2024 15:39:05 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127add7660sm7040208b3a.38.2024.08.19.15.39.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:04 -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 , Krzysztof Kozlowski Subject: [PATCH v3 13/17] dt-bindings: Move google,cros-ec-typec binding to usb Date: Mon, 19 Aug 2024 15:38:27 -0700 Message-ID: <20240819223834.2049862-14-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" This binding is about USB type-c control. Move the binding to the usb directory as it's a better home than chrome. Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Lee Jones Cc: Benson Leung Cc: Guenter Roeck Cc: Prashant Malani Cc: Tzung-Bi Shih Cc: Cc: Cc: Pin-yen Lin Suggested-by: Krzysztof Kozlowski Signed-off-by: Stephen Boyd Acked-by: Lee Jones Reviewed-by: Rob Herring (Arm) --- Documentation/devicetree/bindings/mfd/google,cros-ec.yaml | 2 +- .../bindings/{chrome =3D> usb}/google,cros-ec-typec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename Documentation/devicetree/bindings/{chrome =3D> usb}/google,cros-ec-= typec.yaml (90%) diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Do= cumentation/devicetree/bindings/mfd/google,cros-ec.yaml index aac8819bd00b..c991626dc22b 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -99,7 +99,7 @@ properties: gpio-controller: true =20 typec: - $ref: /schemas/chrome/google,cros-ec-typec.yaml# + $ref: /schemas/usb/google,cros-ec-typec.yaml# =20 ec-pwm: $ref: /schemas/pwm/google,cros-ec-pwm.yaml# diff --git a/Documentation/devicetree/bindings/chrome/google,cros-ec-typec.= yaml b/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml similarity index 90% rename from Documentation/devicetree/bindings/chrome/google,cros-ec-typec.y= aml rename to Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml index 9f9816fbecbc..5ec4a9777ea1 100644 --- a/Documentation/devicetree/bindings/chrome/google,cros-ec-typec.yaml +++ b/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml @@ -1,10 +1,10 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 --- -$id: http://devicetree.org/schemas/chrome/google,cros-ec-typec.yaml# +$id: http://devicetree.org/schemas/usb/google,cros-ec-typec.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: Google Chrome OS EC(Embedded Controller) Type C port driver. +title: Google Chrome OS Embedded Controller (EC) USB type-c port driver =20 maintainers: - Benson Leung --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 5EE61205E07 for ; Mon, 19 Aug 2024 22:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107150; cv=none; b=WGxHTlVaIZBYSs5bfPSM1cbcFrC6c/wlSzXuWD2Sa+wfvmDlwXf5cMilR3ZHyEU3kOnjRBzSAEeYrygwTU8OXhuhz7LAA/LHbH+jLz84rT3a+dt0Y4SS3IBuH4Kpm6qVqx9AKR3J3IEm/FcXrlD3nVzMI2lnsfjBl+6PEsnfeQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107150; c=relaxed/simple; bh=/dI7MR+2Xs16wfk9NVoRInRnpjgI0wsZ+hkJsjkYxjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QHcOA9AatNWRqroqqQb7A7LIkpFo2egisR22XPF1gldSkIX36SkeRuiq2qbuCtlh75pRiE/9XBqw+nt0Zdj6eatE5z2+uTmIRBoSWWBrZmq1usgAPAJQmo9Rn3lMNjyf08vBYIyBBmWosIk6eNBWFLTLTkmk4xxTku4XrpKbOPU= 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=JhqrlOUd; arc=none smtp.client-ip=209.85.210.176 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="JhqrlOUd" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-70d316f0060so3910761b3a.1 for ; Mon, 19 Aug 2024 15:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107148; x=1724711948; 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=3olKCNMmm+bbLjPBrj+yuwpy+tnEYS3+fqAauOCcd9s=; b=JhqrlOUdZDP75Pr//TT8p40l8Mrwjqgh3B2KjpNgUVXNti+zWddC29GHRJ0cARutpI t6DebrGgHTjDaVG1sJmuDVEhTyS0kBdkiSmAgEQHoGRCVZXhPGbT4b63fLuEUUGlqiSm v4BRe8tFdbBXh3Adder1HZrQqT7ul+T9qkcco= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107148; x=1724711948; 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=3olKCNMmm+bbLjPBrj+yuwpy+tnEYS3+fqAauOCcd9s=; b=S9DWJ5ZaEnPYfV4RRY314Ta4ZXjZ9gFi/SdXJfklh0vtElPB+1htAaSC99YAtjVewh BD0ZQCWKknhCJjelPCv0ETC3zX75bXvI/pWr0AmpF0IjuoQOSIeXC22uWwLzg0IVV6my TRqwV608F9szk11oHscQoxH8Cx3/cKi6bUUbpEgI2+KDr7GYsJDsXNlCp49HQv/clhJh GPwjz6vxwEulwPTgbpEvodExuHWEDtMArHpSxFkOM+1Id4GpIJZVoiLH96F3E9p4hmT7 tHtB0wGUU5eZ3Mi7tyn2XskNrvbF3dEk0IU8ZeG0uTiAtZ/wGu4oZnd2M8nON+pbzcJu goWg== X-Gm-Message-State: AOJu0Yzk7+w9ku6F4TJNsS2UVJK/M+1G8zH1LbD6hLcN683G8CWNgP7/ 2XQt/KJajzvqQvAXaI7MPp8TifxmgOQXFyTD3E9fgtAmW5MLi6EkN1BmIMEO4w== X-Google-Smtp-Source: AGHT+IFuHobXwMpayN/T3l++MLdpiZSou9JMIsZXu7qiGwNDrozpjaxioFvym1cbtCUJdc/lyGhU6w== X-Received: by 2002:a05:6a21:3409:b0:1c0:f114:100c with SMTP id adf61e73a8af0-1cac701c654mr1375044637.17.1724107147591; Mon, 19 Aug 2024 15:39:07 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127add6de9sm7314417b3a.12.2024.08.19.15.39.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:07 -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 v3 14/17] dt-bindings: usb: Add ports to google,cros-ec-typec for DP altmode Date: Mon, 19 Aug 2024 15:38:28 -0700 Message-ID: <20240819223834.2049862-15-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Add a DT graph binding to google,cros-ec-typec so that it can combine DisplayPort (DP) and USB SuperSpeed (SS) data into a USB type-c endpoint that is connected to the usb-c-connector node's SS endpoint. This also allows us to connect the DP and USB nodes in the graph to the USB type-c connectors, providing the full picture of the USB type-c data flows in the system. Allow there to be multiple typec nodes underneath the EC node so that one DT graph exists per DP bridge. The EC is actually controlling TCPCs and redrivers that combine the DP and USB signals together so this more accurately reflects the hardware design without introducing yet another DT node underneath the EC for USB type-c. If the type-c ports are being shared between a single DP controller then the ports need to know about each other and determine a policy to drive DP to one type-c port. If the type-c ports each have their own dedicated DP controller then they're able to operate independently and enter/exit DP altmode independently as well. We can't connect the DP controller's endpoint to one usb-c-connector port@1 endpoint and the USB controller's endpoint to another usb-c-connector port@1 endpoint either because the DP muxing case would have DP connected to two usb-c-connector endpoints which the graph binding doesn't support. Therefore, one typec node is required per the capabilities of the type-c port(s) being managed. This also lets us indicate which type-c ports the DP controller is wired to. For example, if DP was connected to ports 0 and 2, while port 1 was connected to another DP controller we wouldn't be able to implement that without having some other DT property to indicate which output ports are connected to the DP endpoint. Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Lee Jones Cc: Benson Leung Cc: Guenter Roeck Cc: Prashant Malani Cc: Tzung-Bi Shih Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring (Arm) --- .../bindings/mfd/google,cros-ec.yaml | 7 +- .../bindings/usb/google,cros-ec-typec.yaml | 229 ++++++++++++++++++ 2 files changed, 233 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Do= cumentation/devicetree/bindings/mfd/google,cros-ec.yaml index c991626dc22b..bbe28047d0c0 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -98,9 +98,6 @@ properties: =20 gpio-controller: true =20 - typec: - $ref: /schemas/usb/google,cros-ec-typec.yaml# - ec-pwm: $ref: /schemas/pwm/google,cros-ec-pwm.yaml# deprecated: true @@ -166,6 +163,10 @@ patternProperties: type: object $ref: /schemas/extcon/extcon-usbc-cros-ec.yaml# =20 + "^typec(-[0-9])*$": + type: object + $ref: /schemas/usb/google,cros-ec-typec.yaml# + required: - compatible =20 diff --git a/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yam= l b/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml index 5ec4a9777ea1..d4c5c92c78ce 100644 --- a/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml +++ b/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml @@ -26,6 +26,106 @@ properties: '#size-cells': const: 0 =20 + mux-gpios: + description: GPIOs indicating which way the DP mux is steered + maxItems: 1 + + no-hpd: + description: Indicates this endpoint doesn't signal HPD for DisplayPort + type: boolean + + mode-switch: + $ref: usb-switch.yaml#properties/mode-switch + + orientation-switch: + $ref: usb-switch.yaml#properties/orientation-switch + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: Output ports for combined DP and USB SS data + patternProperties: + "^endpoint@([0-8])$": + $ref: usb-switch.yaml#/$defs/usbc-out-endpoint + unevaluatedProperties: false + + anyOf: + - required: + - endpoint@0 + - required: + - endpoint@1 + - required: + - endpoint@2 + - required: + - endpoint@3 + - required: + - endpoint@4 + - required: + - endpoint@5 + - required: + - endpoint@6 + - required: + - endpoint@7 + - required: + - endpoint@8 + + port@1: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: + Input port to receive USB SuperSpeed (SS) data + patternProperties: + "^endpoint@([0-8])$": + $ref: usb-switch.yaml#/$defs/usbc-in-endpoint + unevaluatedProperties: false + + anyOf: + - required: + - endpoint@0 + - required: + - endpoint@1 + - required: + - endpoint@2 + - required: + - endpoint@3 + - required: + - endpoint@4 + - required: + - endpoint@5 + - required: + - endpoint@6 + - required: + - endpoint@7 + - required: + - endpoint@8 + + port@2: + $ref: /schemas/graph.yaml#/$defs/port-base + description: + Input port to receive DisplayPort (DP) data + unevaluatedProperties: false + + properties: + endpoint: + $ref: usb-switch.yaml#/$defs/dp-endpoint + unevaluatedProperties: false + + required: + - endpoint + + required: + - port@0 + + anyOf: + - required: + - port@1 + - required: + - port@2 + patternProperties: '^connector@[0-9a-f]+$': $ref: /schemas/connector/usb-connector.yaml# @@ -35,6 +135,40 @@ patternProperties: required: - compatible =20 +allOf: + - if: + required: + - no-hpd + then: + properties: + ports: + required: + - port@2 + - if: + required: + - mux-gpios + then: + properties: + ports: + required: + - port@2 + - if: + required: + - orientation-switch + then: + properties: + ports: + required: + - port@2 + - if: + required: + - mode-switch + then: + properties: + ports: + required: + - port@2 + additionalProperties: false =20 examples: @@ -50,6 +184,8 @@ examples: =20 typec { compatible =3D "google,cros-ec-typec"; + orientation-switch; + mode-switch; =20 #address-cells =3D <1>; #size-cells =3D <0>; @@ -60,6 +196,99 @@ examples: power-role =3D "dual"; data-role =3D "dual"; try-power-role =3D "source"; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + usb_c0_hs: endpoint { + remote-endpoint =3D <&usb_hub_dfp3_hs>; + }; + }; + + port@1 { + reg =3D <1>; + usb_c0_ss: endpoint { + remote-endpoint =3D <&cros_typec_c0_ss>; + }; + }; + }; + }; + + connector@1 { + compatible =3D "usb-c-connector"; + reg =3D <1>; + power-role =3D "dual"; + data-role =3D "dual"; + try-power-role =3D "source"; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + usb_c1_hs: endpoint { + remote-endpoint =3D <&usb_hub_dfp2_hs>; + }; + }; + + port@1 { + reg =3D <1>; + usb_c1_ss: endpoint { + remote-endpoint =3D <&cros_typec_c1_ss>; + }; + }; + }; + }; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + cros_typec_c0_ss: endpoint@0 { + reg =3D <0>; + remote-endpoint =3D <&usb_c0_ss>; + data-lanes =3D <0 1 2 3>; + }; + + cros_typec_c1_ss: endpoint@1 { + reg =3D <1>; + remote-endpoint =3D <&usb_c1_ss>; + data-lanes =3D <2 3 0 1>; + }; + }; + + port@1 { + reg =3D <1>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + usb_in_0: endpoint@0 { + reg =3D <0>; + remote-endpoint =3D <&usb_ss_0_out>; + }; + + usb_in_1: endpoint@1 { + reg =3D <1>; + remote-endpoint =3D <&usb_ss_1_out>; + }; + }; + + port@2 { + reg =3D <2>; + dp_in: endpoint { + remote-endpoint =3D <&dp_phy>; + data-lanes =3D <0 1>; + }; + }; }; }; }; --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 70E55205E03 for ; Mon, 19 Aug 2024 22:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107152; cv=none; b=pMHuFhKjZ769YuUtxfEChrCkkdepb6u8Eq6hm+T/tI6yPCooLXnqjupIzxVxclrWOtaXi/LJadlzH/jUQZ7cWjb3VO7MuQI4Oq0xdj1O6tNhWI2AUQGJvjIKps7+mvZIxYR704wgLX15AaJFNfrcoyh8+r/4rhCXeX3JuqgrCxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107152; c=relaxed/simple; bh=Ocf0y9DeKbCb8IMstpuVVIk9CB4egB4AGDfEpk9BFL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DO+tsvnMifYLCvgF/7fvYO26YLC+vZeGZE0y3+fsPeJzmjzLih5xVWsqIABQJLhibyl89pwL2dVrQVZSxh5u9xwzuGsgYa9nXZvB+/Ly0hBse0JwapnRmDjujsLUHVj4X/Q8tBrz8Ciyz77gCUWTMQ6+qofh4kQvvDwY3hkQBSw= 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=hP75vm6s; arc=none smtp.client-ip=209.85.214.174 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="hP75vm6s" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2021c03c13aso16654205ad.1 for ; Mon, 19 Aug 2024 15:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107150; x=1724711950; 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=bRhGj4hsOpK3/zAD4jYvBQOmMIjTi8ZAOWRNwE6QbdU=; b=hP75vm6snTHsL4MI6Br+9x0d0pHUznMKpQNtyUXk8x9ZLNuQB4uu6RJFv/R37RbYBf iMsSd5MzCk/GN3CqVeGOZCdZCTUx3xPBTHXo6l3SjmT+7YbaVNcJZw0nqoLNiizX3hKl vjIKMgwgiEDv0dCzRBP6cziTa2wcO1AwyLInU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107150; x=1724711950; 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=bRhGj4hsOpK3/zAD4jYvBQOmMIjTi8ZAOWRNwE6QbdU=; b=dCch1WYiW0t2A4lH3L8UCQXERzyLXOSPOlnG69EtBxZDTTDOYuwa75sA7sHrj/RJ/3 zCmuWCGXs2tRy/RETs6mcF/GHBOfwe1BhzDEcEXXd6Z12pr5MshdnSW+waw+yWU7X9XG UDxDZlFaV4TpW953JfR15z4QodltCmewodoclfnqG3q3gS/4effOa3T6WfyvQbG+iJi7 kGovyowcNhR7c6qm3u9YKKJj8SyDxwX3R1KNaDKVzSy/nprfLyb7hMOwZfllxfxdm7ur 6qtLjPHt4YpPyXJgrmHWCQfYI5t9q7V2JJs7nHhRO4N9ODN/g/ubXETq29rQcVdrlteL nT+A== X-Gm-Message-State: AOJu0YxDY4qW4S4nFgwW1DrGIP6pwUYGxicj6Yr7rme8F82CgKUWvxuM ZEqFhcW1TMu5PlajBE7Jfzr2ScDwiq1QaJ0Z9gI5gsIyZtbYFle29Dfznf5Rgw== X-Google-Smtp-Source: AGHT+IECpg6q1pCGPOMeMy+hTlNtV0xfAl6tYuUPEYeVGiewuEEqh9SQLvKFnnMAaBqBbmDZNTygmg== X-Received: by 2002:a17:902:e80f:b0:201:f2bc:7784 with SMTP id d9443c01a7336-2025f08c087mr16594445ad.11.1724107149758; Mon, 19 Aug 2024 15:39:09 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201f03a587csm67150675ad.290.2024.08.19.15.39.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:09 -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 v3 15/17] platform/chrome: cros_ec_typec: Add support for signaling DP HPD via drm_bridge Date: Mon, 19 Aug 2024 15:38:29 -0700 Message-ID: <20240819223834.2049862-16-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" We can imagine that logically the EC is a device that has some number of DisplayPort (DP) connector inputs, some number of USB3 connector inputs, and some number of USB type-c connector outputs. If you squint enough it looks like a USB type-c dock. Logically there's a crossbar pin assignment capability within the EC that can assign USB and DP lanes to USB type-c lanes in the connector (i.e. USB type-c pin configurations). In reality, the EC is a microcontroller that has some TCPCs and redrivers connected to it over something like i2c and DP/USB from the AP is wired directly to those ICs, not the EC. This design allows the EC to abstract many possible USB and DP hardware configurations away from the AP (kernel) so that the AP can largely deal with USB and DP without thinking about USB Type-C much at all. The DP and USB data originate in the AP, not the EC, so it helps to think that the EC takes the DP and USB data as input to mux onto USB type-c ports even if it really doesn't do that. With this split design, the EC forwards the DP HPD state to the DP hardware via a GPIO that's connected to the DP phy. Having that HPD state signaled directly to the DP phy uses precious hardware resources, a pin or two and a wire, and it also forces the TCPM to live on the EC. If we want to save costs and move more control of USB type-c to the kernel it's in our interest to get rid of the HPD pin entirely and signal HPD to the DP phy some other way. Luckily, the EC already exposes information about the USB Type-C stack to the kernel via the host command interface in the "google,cros-ec-typec" compatible driver, which parses EC messages related to USB type-c and effectively "replays" those messages to the kernel's USB typec subsystem. This includes the state of HPD, which can be interrogated and acted upon by registering a 'struct typec_mux_dev' with the typec subsystem or by hooking directly into this cros_ec_typec driver. On DT based systems, the DP display pipeline is abstracted via a 'struct drm_bridge'. If we want to signal HPD state from within the kernel we need to hook into the drm_bridge framework somehow to call drm_bridge_hpd_notify() when HPD state changes in the typec framework. Use the newly added drm_dp_typec_bridge code to do this. When the EC notifies AP of a type-c event, look at the port state and set the connector state to connected or disconnected based on the HPD level when the port is in DP mode. Luckily all this logic is already handled by the drm_dp_typec bridge. Register a bridge when this DT node has the 'mode-switch' property. When cros_typec_configure_mux() puts a port into DP mode, the mode switch registered in the drm_dp_typec bridge driver will signal HPD state to the drm_bridge chain because the typec subsystem will configure the usbc switches connected to the port with the data this driver provides. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/platform/chrome/Kconfig | 1 + drivers/platform/chrome/cros_ec_typec.c | 43 +++++++++++++++++++++++++ drivers/platform/chrome/cros_ec_typec.h | 3 ++ 3 files changed, 47 insertions(+) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kcon= fig index 7dbeb786352a..0aee8a77f1d6 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -231,6 +231,7 @@ config CROS_EC_TYPEC depends on MFD_CROS_EC_DEV && TYPEC depends on CROS_USBPD_NOTIFY depends on USB_ROLE_SWITCH + select DRM_AUX_HPD_BRIDGE if DRM_BRIDGE && OF default MFD_CROS_EC_DEV help If you say Y here, you get support for accessing Type C connector diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index 4d305876ec08..f7e184fa90c5 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,11 +17,18 @@ #include #include =20 +#include + #include "cros_ec_typec.h" #include "cros_typec_vdm.h" =20 #define DRV_NAME "cros-ec-typec" =20 +struct cros_typec_dp_bridge { + struct cros_typec_data *typec_data; + struct drm_dp_typec_bridge_dev *dev; +}; + #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_= PIN_ASSIGN_D)) | \ DP_CAP_DFP_D | DP_CAP_RECEPTACLE) =20 @@ -334,6 +342,9 @@ static int cros_typec_init_ports(struct cros_typec_data= *typec) u32 port_num =3D 0; =20 nports =3D device_get_child_node_count(dev); + /* Don't count any 'ports' child node */ + if (of_graph_is_present(dev->of_node)) + nports--; if (nports =3D=3D 0) { dev_err(dev, "No port entries found.\n"); return -ENODEV; @@ -347,6 +358,10 @@ static int cros_typec_init_ports(struct cros_typec_dat= a *typec) /* DT uses "reg" to specify port number. */ port_prop =3D dev->of_node ? "reg" : "port-number"; device_for_each_child_node(dev, fwnode) { + /* An OF graph isn't a connector */ + if (fwnode_name_eq(fwnode, "ports")) + continue; + if (fwnode_property_read_u32(fwnode, port_prop, &port_num)) { ret =3D -EINVAL; dev_err(dev, "No port-number for port, aborting.\n"); @@ -413,6 +428,30 @@ static int cros_typec_init_ports(struct cros_typec_dat= a *typec) return ret; } =20 +static int cros_typec_init_dp_bridge(struct cros_typec_data *typec) +{ + struct device *dev =3D typec->dev; + struct cros_typec_dp_bridge *dp_bridge; + struct drm_dp_typec_bridge_dev *dp_dev; + + /* Not capable of DP altmode switching. Ignore. */ + if (!fwnode_property_read_bool(dev_fwnode(dev), "mode-switch")) + return 0; + + dp_bridge =3D devm_kzalloc(dev, sizeof(*dp_bridge), GFP_KERNEL); + if (!dp_bridge) + return -ENOMEM; + typec->dp_bridge =3D dp_bridge; + dp_bridge->typec_data =3D typec; + + dp_dev =3D devm_drm_dp_typec_bridge_alloc(dev, dev->of_node); + if (IS_ERR(dp_dev)) + return PTR_ERR(dp_dev); + dp_bridge->dev =3D dp_dev; + + return devm_drm_dp_typec_bridge_add(dev, dp_dev); +} + static int cros_typec_usb_safe_state(struct cros_typec_port *port) { int ret; @@ -1257,6 +1296,10 @@ static int cros_typec_probe(struct platform_device *= pdev) typec->num_ports =3D EC_USB_PD_MAX_PORTS; } =20 + ret =3D cros_typec_init_dp_bridge(typec); + if (ret < 0) + return ret; + ret =3D cros_typec_init_ports(typec); if (ret < 0) return ret; diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chr= ome/cros_ec_typec.h index deda180a646f..73d300427140 100644 --- a/drivers/platform/chrome/cros_ec_typec.h +++ b/drivers/platform/chrome/cros_ec_typec.h @@ -27,6 +27,8 @@ struct cros_typec_altmode_node { struct list_head list; }; =20 +struct cros_typec_dp_bridge; + /* Platform-specific data for the Chrome OS EC Type C controller. */ struct cros_typec_data { struct device *dev; @@ -35,6 +37,7 @@ struct cros_typec_data { unsigned int pd_ctrl_ver; /* Array of ports, indexed by port number. */ struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; + struct cros_typec_dp_bridge *dp_bridge; struct notifier_block nb; struct work_struct port_work; bool typec_cmd_supported; --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 74F6E20FAA0 for ; Mon, 19 Aug 2024 22:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107155; cv=none; b=gqw7HU+MGW3DUBdeWQ85lfRghi/phL4A4qyggAjOE+W/wwNn80FFAl61PqyAA5qmcU7OLCidgeMNqkvOxZCAEB355aFFrUdGznznDhrEH4QFOSbTldz87of8XMbkikYJWvC9AlthuvY0HZUJEastKKgi6iq3jKOx1OhPQoiyUC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107155; c=relaxed/simple; bh=PWQZK8LUdJIovz2CXETyEgisbeZbXkB19WFPBk87afw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ovfXPsgY3YrdQadgyM68vDgD+ChNypcpPKxkheTy1GR28kAdXnoukd+nTuK716pys7nqlOHM69KBkibF+vP3qPcYwsXHynjU/14GbpxnLsNTij8P+uD5eivvsl+CgqtwC9nA9QzCwKT5/S4oGmZt4Kga51plDCR1HTU9ADbVVsQ= 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=KNEYZorH; arc=none smtp.client-ip=209.85.210.177 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="KNEYZorH" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70d316f0060so3910821b3a.1 for ; Mon, 19 Aug 2024 15:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107153; x=1724711953; 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=Y7cnR4WAyiehupOqnyK769y5gghgqDmIgYp8VlO457I=; b=KNEYZorHsGGi3fPkeAxQhxz/KCIAB5KL/29jW6HyoemX5Jcz05Ni7Y4HYoma5TVNRL MaDeTknbpP5+SiUyY6S+aw4Cvsn9ULfao0oTG/IVvq7pkGvcfw2n6uoNjXgE5MMqCmzZ CsmaGqJDMcpZJZkuk4xxFofTkn6V0erMuxEHU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107153; x=1724711953; 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=Y7cnR4WAyiehupOqnyK769y5gghgqDmIgYp8VlO457I=; b=cN3tHdkBaet2u4haPBLJbvBsZ6APcWeyuRsC1q8kQ07+X4s7lhdMSMDeUaOzDnmytF mPZXx3izmb5SarHtlRten6lykHR0fE1d7yeQ3y+Q/xQrm/fsyYJ0xGfr5tmUmVMFm3wv +FPG3PiNrj1sPIeGL1Okx6+YRgxPmQP1dlApnRqy4IxRZwC/q+QjI7BWxpGOGDT5id/9 tAKBiBojW+KXbFbMM/MmYW7u7jKfoRSakCJv2mGVyudZrqINxQkGB0npXZInCPRkRe5j F1Qe5vf9bqKTILxA8MgYl3hufy7Tz8aHisnYeQUYU0kaSY+MGt4SYj2Buw+A+D0OpWab rkvg== X-Gm-Message-State: AOJu0YwByngvNYVeDDAmvYO/EV5H9cr7fMKASj1FzldT5JldC+Kqooaq rEx/gD02ispdZr7RO/iv/Rax4FchNB7F2cTnzobEgSiuDQFmXiu/k/fbBrx0rA== X-Google-Smtp-Source: AGHT+IFDMfmaDl5CQQB46DBVKM9LhEvDRklHtdC16bYuWrBxm7m9f2L+9KDIb+r21yZ+V1xXGO6uRg== X-Received: by 2002:a05:6a21:32a8:b0:1c6:9a3b:ba44 with SMTP id adf61e73a8af0-1cac7163b91mr1631501637.25.1724107152579; Mon, 19 Aug 2024 15:39:12 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7127add7660sm7040294b3a.38.2024.08.19.15.39.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:11 -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 v3 16/17] platform/chrome: cros_ec_typec: Support DP muxing Date: Mon, 19 Aug 2024 15:38:30 -0700 Message-ID: <20240819223834.2049862-17-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Most ARM based chromebooks with two usb-c-connector nodes and one DP controller are muxing the DP lanes between the two USB ports. This is done so that the type-c ports are at least equal in capability if not functionality. Either an analog mux is used to steer the DP signal to one or the other port, or a DP bridge chip has two lanes (e.g. DP ML0/ML1) wired to one type-c port while the other two (e.g. DP ML2/ML3) are wired to another type-c port. Implement the same algorithm that the EC has to figure out which type-c port has actually been muxed for DP altmode. Wait for the first type-c port to assert HPD, and treat that as the actively muxed port until the port exits DP altmode entirely. Allow HPD to be asserted or deasserted during this time. If the port isn't active, simply ignore those events and skip calling cros_typec_enable_dp(). Otherwise, pass the DP information to the typec subsystem so that the DP controller can respond to HPD events and pin configurations. The EC can mux the DP signal to any number of USB type-c ports. We only need to make sure that the active USB type-c port is tracked so that DP information about the other ports is ignored. Unfortunately, the EC doesn't hide these details from the AP so we have to reimplement the logic in the kernel. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/platform/chrome/cros_ec_typec.c | 27 +++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index f7e184fa90c5..b32abd14825c 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -27,6 +27,7 @@ struct cros_typec_dp_bridge { struct cros_typec_data *typec_data; struct drm_dp_typec_bridge_dev *dev; + struct cros_typec_port *active_port; }; =20 #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_= PIN_ASSIGN_D)) | \ @@ -651,6 +652,7 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, struct ec_response_usb_pd_control_v2 *pd_ctrl) { struct cros_typec_port *port =3D typec->ports[port_num]; + struct cros_typec_dp_bridge *dp_bridge =3D typec->dp_bridge; struct ec_response_usb_pd_mux_info resp; struct ec_params_usb_pd_mux_info req =3D { .port =3D port_num, @@ -658,6 +660,7 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, struct ec_params_usb_pd_mux_ack mux_ack; enum typec_orientation orientation; int ret; + bool dp_enabled, hpd_asserted, is_active_port; =20 ret =3D cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req, sizeof(req), &resp, sizeof(resp)); @@ -671,6 +674,20 @@ static int cros_typec_configure_mux(struct cros_typec_= data *typec, int port_num, if (port->mux_flags =3D=3D resp.flags && port->role =3D=3D pd_ctrl->role) return 0; =20 + dp_enabled =3D resp.flags & USB_PD_MUX_DP_ENABLED; + hpd_asserted =3D resp.flags & USB_PD_MUX_HPD_LVL; + /* + * Assume the first port to have HPD asserted is the one muxed to DP + * (i.e. active_port). When there's only one port this delays setting + * the active_port until HPD is asserted, but before that the + * drm_connector looks disconnected so active_port doesn't need to be + * set. + */ + if (dp_bridge && hpd_asserted && !dp_bridge->active_port) + dp_bridge->active_port =3D port; + + is_active_port =3D !dp_bridge || dp_bridge->active_port =3D=3D port; + port->mux_flags =3D resp.flags; port->role =3D pd_ctrl->role; =20 @@ -698,8 +715,11 @@ static int cros_typec_configure_mux(struct cros_typec_= data *typec, int port_num, ret =3D cros_typec_enable_usb4(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret =3D cros_typec_enable_tbt(typec, port_num, pd_ctrl); - } else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) { - ret =3D cros_typec_enable_dp(typec, port_num, pd_ctrl); + } else if (dp_enabled) { + ret =3D 0; + /* Ignore DP events for the non-active port */ + if (is_active_port) + ret =3D cros_typec_enable_dp(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) { ret =3D cros_typec_usb_safe_state(port); } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) { @@ -716,6 +736,9 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, } =20 mux_ack: + if (dp_bridge && !dp_enabled && is_active_port) + dp_bridge->active_port =3D NULL; + if (!typec->needs_mux_ack) return ret; =20 --=20 https://chromeos.dev From nobody Sun Feb 8 11:59:36 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 88619210182 for ; Mon, 19 Aug 2024 22:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107157; cv=none; b=WMjhssv7XWy7R9saq+Kxe3dulkYhw1LFMw4cVu+uHM4k47r81+jHhlKKy1vVllkz6mViwNlmNp0MsUpz62jYG2S1Ad44L280jQGxbE8doL69fjnWN+eIR5AEh4GZ2ACvrIYzjtIXimZlcqzaK6z6rKeNbWI3A63hKfbO6NbjHog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724107157; c=relaxed/simple; bh=ovt0XJ1mqNb5WMPAy+4sDJNNOziSSr2qxAdythLNoYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KKXxGWvMp/R8o9fL5uSbZ3U051CvhiV9oZ8Gv/JL6DXdxZE9B0qU5zzaZM7jMthltDe2Ap44nDwfgSjASvieNuRic4npDhZEehxH5TmXbyZdat1CdvDSia35F/qTcUvbk59fLGyFNseHPXrMdd1KTPWkuU9a/ZirAA+JFu6PfjY= 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=JkQVma+Q; arc=none smtp.client-ip=209.85.216.49 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="JkQVma+Q" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2d3c5f769d6so3327796a91.3 for ; Mon, 19 Aug 2024 15:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724107155; x=1724711955; 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=qqiNpgy6qhsHsbRqJzjRPUET6f40RWIPa40iMsEsB6U=; b=JkQVma+QxyD+qkrX8YofzuFJT6X5TKXDxRUgCAwtdXtzzLQKV7ajStIc8Zdt0ipM9t bkVSvvG9KgUygIXPTA5fXw6NBV99pyKFJCxkCJg/K5ttv/G2gH3ovH3bE/mtg9PeNzRi pqidocDUyh8BTBMQLVGdBkapGf7QAbeJi3L3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107155; x=1724711955; 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=qqiNpgy6qhsHsbRqJzjRPUET6f40RWIPa40iMsEsB6U=; b=k7OSeSn1kc8RtdiZEd57bmr9Z67+gWmbG3JE43XvEDwxtHmkhQshTXzRINzaZo93GW sVPCcxONrPVI9xp6CVMvdO2ZcmXVRD/FYPej4a0IFgp5xKsXz9W3P/2kuyje1OtRfBqg gCuUJEHArnLtBkoZfKRszebjitpTRH5Q0PDh6zKyidGJDy2NrUOA431ddgo2/SiFgXz9 YJ2BCGXu5Eo71iv5UQOI4wRGAdRjwXA5PgaBrMZ6YJ4onwpFUef9CF+qYCC3ka/tUZld 2Kx9F/weIYspB7iqFpk6OB15SRYyepIxw57MYDn/siw6F+h6i82WK31akXKxI5ztp+pb SvPQ== X-Gm-Message-State: AOJu0YzP+/2JUyGY55lfk5PC+7I1b5nxoA4WIZZzuoJVWGQa/kH+5orh WUprxzj0BMvHGCuAtZUtc0FlB4ql3ZMvmBjIl7zQ8Qi07TzkJ/OL1GSsbN/sQA== X-Google-Smtp-Source: AGHT+IGbD6wqCEPU07zp1VlQIl5l/bCLG6vLLJV+MCZulU1ILwbw1OtdCfW8oWf+Bxk7YL5dc7qdwQ== X-Received: by 2002:a17:90a:a887:b0:2c9:81a2:e8da with SMTP id 98e67ed59e1d1-2d3e03e8cd8mr10769468a91.35.1724107154768; Mon, 19 Aug 2024 15:39:14 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d3eb68d82asm7555063a91.4.2024.08.19.15.39.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Aug 2024 15:39:14 -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 v3 17/17] platform/chrome: cros_ec_typec: Handle lack of HPD information Date: Mon, 19 Aug 2024 15:38:31 -0700 Message-ID: <20240819223834.2049862-18-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819223834.2049862-1-swboyd@chromium.org> References: <20240819223834.2049862-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" Some EC firmwares on Trogdor/Strongbad boards don't properly indicate the state of DP HPD on a type-c port. Instead, the EC only indicates that a type-c port has entered or exited DP mode. To make matters worse, on these boards the DP signal is muxed between two USB type-c connectors, so we can't use the DP entry of a port to figure out which type-c port is actually displaying DP. Stash the HPD state in this case whenever the drm_bridge is notified of a connector status change and kick off the port worker so that the type-c port state can be re-evaluated. If an analog mux is in use, read the mux to figure out which type-c port signaled HPD. Once we know which port is actually signaling HPD, inject that state into the message received from the EC. This simplifies the rest of the logic as it can all stay the same with respect to picking the first port to assert HPD, etc. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/platform/chrome/cros_ec_typec.c | 79 +++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index b32abd14825c..991361abbc31 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -7,6 +7,7 @@ */ =20 #include +#include #include #include #include @@ -28,6 +29,8 @@ struct cros_typec_dp_bridge { struct cros_typec_data *typec_data; struct drm_dp_typec_bridge_dev *dev; struct cros_typec_port *active_port; + struct gpio_desc *mux_gpio; + bool hpd_asserted; }; =20 #define DP_PORT_VDO (DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_= PIN_ASSIGN_D)) | \ @@ -429,6 +432,18 @@ static int cros_typec_init_ports(struct cros_typec_dat= a *typec) return ret; } =20 +static void cros_typec_dp_bridge_hpd_notify(void *data, enum drm_connector= _status status) +{ + struct cros_typec_dp_bridge *dp_bridge =3D data; + struct cros_typec_data *typec =3D dp_bridge->typec_data; + + /* Proxy the connector status as the HPD state to replay later. */ + dp_bridge->hpd_asserted =3D status =3D=3D connector_status_connected; + + /* Refresh port state. */ + schedule_work(&typec->port_work); +} + static int cros_typec_init_dp_bridge(struct cros_typec_data *typec) { struct device *dev =3D typec->dev; @@ -445,9 +460,19 @@ static int cros_typec_init_dp_bridge(struct cros_typec= _data *typec) typec->dp_bridge =3D dp_bridge; dp_bridge->typec_data =3D typec; =20 + dp_bridge->mux_gpio =3D devm_gpiod_get_optional(dev, "mux", GPIOD_ASIS); + if (IS_ERR(dp_bridge->mux_gpio)) + return dev_err_probe(dev, PTR_ERR(dp_bridge->mux_gpio), "failed to get m= ux gpio\n"); + dp_dev =3D devm_drm_dp_typec_bridge_alloc(dev, dev->of_node); if (IS_ERR(dp_dev)) return PTR_ERR(dp_dev); + + if (fwnode_property_read_bool(dev_fwnode(dev), "no-hpd")) { + drm_dp_typec_bridge_add_hpd_notify(dp_dev, cros_typec_dp_bridge_hpd_noti= fy, + dp_bridge); + } + dp_bridge->dev =3D dp_dev; =20 return devm_drm_dp_typec_bridge_add(dev, dp_dev); @@ -648,6 +673,59 @@ static int cros_typec_enable_usb4(struct cros_typec_da= ta *typec, return typec_mux_set(port->mux, &port->state); } =20 +/* Inject HPD state into the EC's response if EC firmware is broken. */ +static void cros_typec_inject_hpd(struct ec_response_usb_pd_mux_info *resp, + struct cros_typec_port *port, + struct cros_typec_dp_bridge *dp_bridge) +{ + struct cros_typec_data *typec =3D port->typec_data; + struct gpio_desc *mux_gpio; + int val; + + if (!dp_bridge) + return; + + /* Don't need to inject HPD level when DP isn't enabled */ + if (!(resp->flags & USB_PD_MUX_DP_ENABLED)) + return; + + /* + * The default setting is HPD deasserted. Ignore if nothing to inject. + */ + if (!dp_bridge->hpd_asserted) + return; + + /* + * Some ECs don't notify AP when HPD goes high or low so we have to + * read the EC GPIO that controls the mux to figure out which type-c + * port is connected to DP by the EC. + */ + mux_gpio =3D dp_bridge->mux_gpio; + if (!mux_gpio) + return; + + /* + * Only read the mux GPIO setting if we need to change the active_port. + * Otherwise, an active_port is already set and HPD going high or low + * doesn't change the muxed port until DP mode is exited. + */ + if (!dp_bridge->active_port) { + val =3D gpiod_get_value_cansleep(mux_gpio); + if (val < 0) { + dev_err(typec->dev, "Failed to read mux gpio\n"); + return; + } + if (typec->ports[val] !=3D port) + return; + } else if (port !=3D dp_bridge->active_port) { + return; + } + + /* Inject HPD from the GPIO state if EC firmware is broken. */ + if (dp_bridge->hpd_asserted) + resp->flags |=3D USB_PD_MUX_HPD_LVL; +} + static int cros_typec_configure_mux(struct cros_typec_data *typec, int por= t_num, struct ec_response_usb_pd_control_v2 *pd_ctrl) { @@ -669,6 +747,7 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, port_num, ret); return ret; } + cros_typec_inject_hpd(&resp, port, dp_bridge); =20 /* No change needs to be made, let's exit early. */ if (port->mux_flags =3D=3D resp.flags && port->role =3D=3D pd_ctrl->role) --=20 https://chromeos.dev