From patchwork Sun Sep 1 04:06:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786307 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 13D5128DC3 for ; Sun, 1 Sep 2024 04:07:04 +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=1725163627; cv=none; b=r32PN9AZQzhchWdhd0dlEY42c3bvAsrVEmeMrYINyRk+N2sNznP5Z/Kl6sbSN1tfzzUtAjCyzbya98EmYsScUQvj2HnfS8R/aqwnwGzMxjquxvbVrb8vbb4j7cP+5z1xfaiCOV/iQ2Lt6jT/jxAW8L9Rz7/8QFP4e+mI6U407Y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163627; c=relaxed/simple; bh=oz72Q0doCA/TDcpGgSX5zcBpwt/SNMECwtIx/YvZSjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dOMgB7mruFApMJop3roOTeZz52M+Py3mLYTKc4EnIlb1kfW/kBGWTtyMXQvCvU0pu6eI68akULhwVmEE277Kh74n6tN/lGsEB4ddTrUhsbvJk9f75/TG29fV14QvwV8ydxEJSu5gWM9+kIn4C3zIDLM8fUFW2aj2cefxxZvFGfg= 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=fIxoIVwg; 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="fIxoIVwg" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2d86f71353dso1357903a91.2 for ; Sat, 31 Aug 2024 21:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163624; x=1725768424; 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=fIxoIVwgZ2tcvqoazgKfGLIDyW588S3IkQxV+OJPy0ulheu9u9jjdtl/mS7z+NoXXJ zgjRodL+yhONICb6HmhJHIeWY8ABkjOfjDErDWeGzlBrEvvW6Du0i1C9UVyMb6M89nYn T5+9GsPlpku8aj7aDIqYzL2toq9+v5BQ3bX6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163624; x=1725768424; 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=h5NP5NgE4OeWEIBYORR/TBwikdjUJZPzWTyhYE/8090H81CFPB7fceGVe4Ng4VYB4+ OCz5SYHJru99suxCDqvSdydJPTGU/0aT/It4wI7xJxVxXj813wl/69wPBP5P4usvfIvB ABanit4wfh3V4mFXqZCB7QUmldvjKt651idd8FVm3MGIUnsCALbInuBGMjRZS0E6wNWQ 15PsN3J6Zc9GB9LWgEtMH+g+JXjdyn+jrileqmcy7W/ZWaOD1YqA32XYeen8ZTcfqK85 PXn1YpNqebFPHABbrxjWezc1sCWjJswXPIl8wgCmANXOrKK8Q1qVFEABXFz9C0gmKvzE LNRQ== X-Forwarded-Encrypted: i=1; AJvYcCW5x7LUXUVgrRh2SYLRszzmEqcSqKF5VqnNg6Z5lTLWnXk8bG3FCfkO73iUd6DbmSHFfmZCOv1heas=@vger.kernel.org X-Gm-Message-State: AOJu0YxXHxXTTM7TfV/g6TD+au3lhE61xvexgqICWA0NhFy6UsFU1ozj ojcVV8iG2jgPpTszMfuzz9kmVd+OqITfONnKcdQDrnVXD6YvwFWzX4e1PXMn2g== X-Google-Smtp-Source: AGHT+IGNVmA7VWhk62f3LFtg2+v2Z6maXACsQbPztg1sx/IxxPw8hvbJri39WvmDmQ2WFOhjt1g07Q== X-Received: by 2002:a17:90a:a88a:b0:2c9:5ecd:e3c5 with SMTP id 98e67ed59e1d1-2d8563922b8mr11419814a91.33.1725163624128; Sat, 31 Aug 2024 21:07:04 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d8446c5880sm8970224a91.42.2024.08.31.21.07.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:03 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 01/18] drm/atomic-helper: Introduce lane remapping support to bridges Date: Sat, 31 Aug 2024 21:06:39 -0700 Message-ID: <20240901040658.157425-2-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/drm_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); +/** + * drm_bridge_next_bridge_lane_cfg - get the lane configuration of the next 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 bridge 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 = drm_bridge_get_next_bridge(bridge); + + next_bridge_state = drm_atomic_get_new_bridge_state(state, next_bridge); + if (!next_bridge_state) { + *num_lanes = 0; + return NULL; + } + + *num_lanes = 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; } +/** + * 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; }; /** 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); enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge); int drm_bridge_get_modes(struct drm_bridge *bridge, From patchwork Sun Sep 1 04:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786308 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 6ECFF3D994 for ; Sun, 1 Sep 2024 04:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163630; cv=none; b=jcuBnHb3Pa7RKvr/T89IfMe1KznJr+yy0UW2gmHMT3FV7AD7pTSKJ6qbaKnblSON3FzpO+BPI4PRUOWGYVNaaEE8+l7lRmYEMm5xC8hUGBDaf2t58fOHrshiBEdrjTxGnmG9+PbbYn31XgyoBWLMJov8/fbNdgAx+5TlSdSw7nA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163630; c=relaxed/simple; bh=pZ7ktacniNaKMda1L3Z6XilrG7hHXha97/67GYjaAzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bPpPM/VHtJ9Wew7wo/AaZpoJOMYRsfFji2bhhLHHIFgNTK8B7KEXWbuHHJe8kULDmMfATSCNvXjn0hQNeiwAqkZ3T7DkyehPY/3e3IJ1VN+QptIKNsNAEYPfVEZTNlmPjtJ8k2tz6hb9KSczl2cmXoPxtBKRdYedA1v7hxeuCMs= 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=aNzUSEg9; arc=none smtp.client-ip=209.85.161.46 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="aNzUSEg9" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5dfa315ccf1so1833011eaf.3 for ; Sat, 31 Aug 2024 21:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163626; x=1725768426; 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=bsT6Pyy4WdREZdfc6RLc4+Jmxiv/uouJ028bXKINCs8=; b=aNzUSEg9pnhOYvMbwY8uXM54dt3waMRYHfrCn1Q9WYJddI6w/2XUMqHZfn+hD7X/jM lQgdXnWHpGftkb9CtOPfsVrIiTuwcKPpYTmLqrggWePT5ix1sh8JfHbOteFezbhim9vZ 3IxaMeNrDJ1daKoVHjUtcGdi4q8V+zH4zzQpU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163626; x=1725768426; 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=bsT6Pyy4WdREZdfc6RLc4+Jmxiv/uouJ028bXKINCs8=; b=JSceb1JRfSrpfkGOAYw2D1mI2CtrKLa3lgK1B2pgjt0SmF1pT4RnhQah512BiI0G5p JTaqvcK1gaAbp/QXQX2WazMzbv2pHUYGW0IJJuP9E+XcIUOnv+uUEYevkU4tiHWZj8HI VB2AEDGEImXFgnMJdk68239YjzrMCDZHbDlZBX9AFrHAJTzXdzRXDCU+K5uK0Ax1P2NT LPE+GXAiNnWIzwV9M6r6MJ3OHhjREatekjBO++LJuVJkowhUoYCo8AELCIenSjAI+0kU T8Tcqqm1d0w0JAa+/mmoScFzC6GnSsbTdBYI6hRA7rCc+QFiRDKExX58fwVzvU6nkMSi wH9A== X-Forwarded-Encrypted: i=1; AJvYcCUOU4shwtjgGJv2w70IzpQt7tuPKgkKeOqwKMTzlOnfTZSIjtc5RMhPC/vgWLjniS+V865apqpkedU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0MkdZQ4W3UvkyGmCU4WIrtWc5e3Cv5iQHVWVIWihbhDVn3SOB b1J1Zph6bV/DODXtilNNqcqwV5QKpFBxNLpIotdCLyKXkDnbSnPo3vypdfl4pg== X-Google-Smtp-Source: AGHT+IHtz1LVfFf3gG+hTwV6UQ2tt7nrnC8wrXqjk3Bxp7NafXmwM2C1wRlTdUffnPNfcbRmXcHwSg== X-Received: by 2002:a05:6358:24aa:b0:1ac:65e7:919b with SMTP id e5c5f4694b2df-1b603beb8afmr1222369855d.6.1725163626398; Sat, 31 Aug 2024 21:07:06 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-715e56d78e4sm4847550b3a.163.2024.08.31.21.07.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:06 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 02/18] drm/bridge: Verify lane assignment is going to work during atomic_check Date: Sat, 31 Aug 2024 21:06:40 -0700 Message-ID: <20240901040658.157425-3-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index bd18c1e91dee..e350248ba5c2 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 = 0; + const struct drm_lane_cfg *input_lanes; + unsigned int i; + if (bridge->funcs->atomic_check) { struct drm_bridge_state *bridge_state; int ret; @@ -873,12 +877,25 @@ static int drm_atomic_bridge_check(struct drm_bridge *bridge, crtc_state, conn_state); if (ret) return ret; + num_output_lanes = 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; } + input_lanes = 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 = 0; i < num_input_lanes; i++) { + if (i != input_lanes[i].logical && !num_output_lanes) + return -ENOTSUPP; + } + return 0; } From patchwork Sun Sep 1 04:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786309 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 6352F4F88C for ; Sun, 1 Sep 2024 04:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163631; cv=none; b=uMVPhXlF9amUimDP5L9QUuTgeEgJBjWftO8NVtgzHGF5LxC8KagRmdLplvJdQugEGWP47DUGlUapBRMzs98Vd7zijwn+lNEQcN7B9mP25sSQlewO6GQRgTF0vBTrP/DOgG3W/B4Qzdx5M1uyaHRdoARgvFDwSqyd0X7IS3/wZcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163631; c=relaxed/simple; bh=aDCeN3nN9nRcFYme+ATD3OdKxYtiWgyuQ3zp7dza4rA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=clvUq1q9qZoN4IGWtkWHEJvplszknhZBFFN9KbRDQjLP3GZfCfs/u3h+BN/vutcM1Ol6LlLEk/jWYDdJvJblEvm0OgNzT4Vy2AkrAU7k8hCUHHX/H3sCiZHMPAkRmb+b9U2nPuZmW0AJI+eySm1Jj7hbpaltX/byj56DdOqjK2M= 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=WJTLa3qo; arc=none smtp.client-ip=209.85.210.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="WJTLa3qo" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-714187df604so2471280b3a.1 for ; Sat, 31 Aug 2024 21:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163629; x=1725768429; 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=q5JhzkdOpb5d78Mk6klz+de8MRC1bwTsy8AL/60ewZg=; b=WJTLa3qoyk0o8c8bwUolzy0fd7V/v74p6T3zDATul4ZbEYLBTXuQeWy4vQC1oKPTVm oyBVmGEzoj8ncVtbDcdvxB18H4y9aL+dsRdcWGnK8MiyIq6uXdOHVkoxfcWirgDaFtRO rFeVGLMbcQfwGlIuWGPm7LC3NYi4f15QmIxLw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163629; x=1725768429; 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=q5JhzkdOpb5d78Mk6klz+de8MRC1bwTsy8AL/60ewZg=; b=aMXelz9GWAyxgMVElm4tmxBtlYQlFkNONVbgt2PyUGy5UsRFOXJNbNM+TAW2cOYISN O2VoZGFaBJBwStXxoWNBOMyDQin5v2ZDQyignbB+p2Sea135d76piqOzMLu4poEGTBA/ 7p9vTne0KxwAFEAP5lF01EcVJx4nxh4A8ErrarhZXKEi/GEdzXnNXMgOT52tLnGc+43C 8LsLoiv3Xsj57PBUh0eRaqnLaVKSMZgeb7ZztBWJ+JWKsNsNBH9cbdfzkGP5AbMJBfa3 Z59aXN4Z+3UdwlRtt5dclQinNGKBTK+mC+8QXTKSbyhjagUi4yUN4jvYmfDP4C05hMPv mkYg== X-Forwarded-Encrypted: i=1; AJvYcCV11BOri+REBPhi86Hld2TI/Xj1EZJAiLSQKLF3d6/e9KV+RwSMahVxOH+2mPr6WeP9NJFi7wtRCP4=@vger.kernel.org X-Gm-Message-State: AOJu0YwS2iFmnp+lVUJJWLJjrxS6AUjhN0D1E3Z0mxHlPTvOYNWYjuSu k9NeVSJR2Bd05OqTq4y9V8VqqAmGnyEy961tE3k9/zZsc+6zxyXiDs4xIZSiNA== X-Google-Smtp-Source: AGHT+IH443VeMjk4kx1Ih8MoClHHt+0Hz48LB1+P16Pb5YXD9rscHzWsBcV2jb1oYKBn+g57FtSFdA== X-Received: by 2002:a05:6a21:9211:b0:1cc:e0de:c75a with SMTP id adf61e73a8af0-1cce1613874mr11265457637.8.1725163628444; Sat, 31 Aug 2024 21:07:08 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e9d4b77sm4590630a12.79.2024.08.31.21.07.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:08 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 03/18] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Date: Sat, 31 Aug 2024 21:06:41 -0700 Message-ID: <20240901040658.157425-4-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ease driver development by adding stubs for the typec_switch APIs when CONFIG_TYPEC=n. 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 Reviewed-by: Heikki Krogerus --- include/linux/usb/typec_mux.h | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index 2489a7857d8e..efb5ed32b813 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -3,6 +3,7 @@ #ifndef __USB_TYPEC_MUX #define __USB_TYPEC_MUX +#include #include #include @@ -24,16 +25,13 @@ struct typec_switch_desc { void *drvdata; }; +#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); -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 +40,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); +#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, void *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; From patchwork Sun Sep 1 04:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786310 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 845676F2FA for ; Sun, 1 Sep 2024 04:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163633; cv=none; b=reI3TmqwqJi/yQZEMIvgRnx04K5/uNG80LbKaEfAKuFCTMqlNZp5b9E1XvArDlJIbxzMlIOMzbJcwIx72XtzkJqjQjLqVLB+LNBRDKjOs/Ct6FawMsQ3yHfafhgrCYRThjKoKHY7EtLeB/rDI0kPNUL42TsWwz+yfEKBB2f9rBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163633; c=relaxed/simple; bh=lQuo9VmpRTMEUSypDAVnMcCD781MhPSwWoCv0Ud9eec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QjnBrpxxCxLRygqbQtLW/FbX7nYc3l3xt5212gIgAOIgoyM3OxH2Ohmqwk4ddR2BAvSU+94i3oX90ysR7k7lbyqacCDQGKYn32ikzyX67qB7Ol2omiJ+bXLl/f0I9/JEramQRDEcLs+MFrwY2yQV+IAEaTPVmzLOcVTxGGyrBns= 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=XXUBv+CG; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XXUBv+CG" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5dc93fa5639so1904603eaf.1 for ; Sat, 31 Aug 2024 21:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163631; x=1725768431; 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=2N8vS/njRh59NN9Hhbqh05Yl3HU3mcBshclMsZjbFEo=; b=XXUBv+CGuy3CD5Jb251OYi4bH6NRFL8hhKhRN+LccXoDWdaNtsaE7P7Os2YnehRkya LeblKHIvjH/dRZ/eSwOqRlZKRkvJXh1qTQSu+l5Gm8Htxk54v4f4gWXeZoCia305gNXh XyZUKfsI/VNTFC2iruBY195KOQqTKp8FEjpnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163631; x=1725768431; 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=2N8vS/njRh59NN9Hhbqh05Yl3HU3mcBshclMsZjbFEo=; b=lc7OIJ7NX4pVY9EK2dgS+YKoVCLC/UMesTNSZCwdcWBO4C8xBKWNaUwkT0L7v7zNOe nHxclIqQxdkPxJYYQ4MAgtHFxVN21fYUxwEUQwodr8XXNk1J+25GUrvoxG0zeSTRau/Z M9/F0ZX2/kTPq3Hsv/IWpIoAKo9dDemATr1xd/zQ6bgH/IHU6QD5YxqTED0c47TuphPU 1631KxKqE8XKAPLMj/mL6UpyQlaC9HOfYE5IDC2p86iZYgAi8Le7xrN/SUDtUAda+8AA 4mvcKwOmMcREOiOwGKb7Kmu/buZLMxFXkWYvYenVZElq3V9gBKnqN4nuqtN+vs8bzbLi AGHg== X-Forwarded-Encrypted: i=1; AJvYcCXnO+p/lJpnVn1DcxrhgghCafcNhycLMm8UypSXWeJ0Q5IUGBeT4ZfTF00hzU8tx1bmfNfJxO4aIMg=@vger.kernel.org X-Gm-Message-State: AOJu0YyNbkWHb6XyhAXu2kk96wESosnkxcVM3dXPJkdi0q96j4LtzoH8 kdWYk0JZ/OgRT0MyKw/qrZs7GtzlblMqk+mZzBT2HmIy5EGhv/Gj6gD0cye1mA== X-Google-Smtp-Source: AGHT+IGn0G5AiONQD8K5yi4LzBmU8yqa6VFEQOeNXV9U2Ho8xKtvyvDtSksQxtqrZ7RRI09TCw6qDQ== X-Received: by 2002:a05:6830:7310:b0:709:5601:abea with SMTP id 46e09a7af769-70f72bb320amr3883433a34.10.1725163630581; Sat, 31 Aug 2024 21:07:10 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e77a7besm5341681a12.37.2024.08.31.21.07.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:10 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 04/18] usb: typec: Add device managed typec_mux_register() Date: Sat, 31 Aug 2024 21:06:42 -0700 Message-ID: <20240901040658.157425-5-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 35 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 49926d6e72c7..db644bec862c 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -457,6 +457,41 @@ void typec_mux_unregister(struct typec_mux_dev *mux_dev) } EXPORT_SYMBOL_GPL(typec_mux_unregister); +static void devm_typec_mux_unregister(void *mux_dev) +{ + typec_mux_unregister(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 or error pointer on error. + */ +struct typec_mux_dev * +devm_typec_mux_register(struct device *parent, const struct typec_mux_desc *desc) +{ + int ret; + struct typec_mux_dev *mux_dev; + + mux_dev = typec_mux_register(parent, desc); + if (IS_ERR(mux_dev)) + return mux_dev; + + ret = devm_add_action_or_reset(parent, devm_typec_mux_unregister, mux_dev); + if (ret) + return ERR_PTR(ret); + + 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 efb5ed32b813..08431f0896d5 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -99,6 +99,8 @@ int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); struct typec_mux_dev * typec_mux_register(struct device *parent, const struct typec_mux_desc *desc); +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); void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); @@ -123,6 +125,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) {} static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {} From patchwork Sun Sep 1 04:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786311 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 75B5881205 for ; Sun, 1 Sep 2024 04:07: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=1725163635; cv=none; b=gpkWdpPPdjNdwwJBRJ+OYcJ1nzQPrZDCZ+JGjBqAVfTr+JjzEGO8jFWZNDjMpXwMkAeSh1+h51DJH9qZHFoNiudWnKVoMNEfbfASSFmjfv3a4VCE0TSmHteYxXhHO7uCWpFOXLsIr241yE3zcoH2aJSCLn6+XxCp9RD29VLZp8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163635; c=relaxed/simple; bh=3V7619Mxma8Aeax8LSroAiPwdTZh9etPyCL5UGAdaDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z3tjBd/Ax/64OUTm75YtBJV5rmVOKn2pz/HPAIz9Sx0ssgbyyZdKp8eu//a0tKFBkvdjSkhCx9HTTfDeiaVi9EKXhcwWNRnynrFft0RmGiF6T6amMng/vEOuKXzWNqi2C3KRj2m9LUMPLcYhX7Cv6EETXsqbXqPZ5d71/SK1LDU= 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=Fjn6GT0z; 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="Fjn6GT0z" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-714187df604so2471292b3a.1 for ; Sat, 31 Aug 2024 21:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163633; x=1725768433; 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=Sko4acOmndCniAhhaR8U/EXx+Ad9ii+FHZslBTejwPk=; b=Fjn6GT0ze9jkBg6J3ysjfDtV3HtMJ52+EXoFOTljJy78xDJiVuCwLLSFKBnCRi/2Sj lhV94FS5v/+1DW8X3sZXXzvGAldu4MgEsXdBIztfOHEcH0Mn/c2/jJv3PqTy/YabnbBz 6eOA8hgVGjJSbTJm8oh127ckpYtOTiwjbNCFo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163633; x=1725768433; 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=Sko4acOmndCniAhhaR8U/EXx+Ad9ii+FHZslBTejwPk=; b=V4QqH4dPnqghGMOdH92p8kow2nc6o39Y9IOkNAm+QbYW6NR9RjzXpw3VL+44f/vHP2 dcFTN8jotg7VWx+MEnHDBndJxT6ocAQAq6pZsBZc6QLLVY2DcsdQojwMdH2ifEJmozPe gKbHIqFfHxbS78NoCzc1KcEG+JBNSf405aa2hJMV/hzG+5dy8IxrdwP6c7xD8zXJPbCa 3jEtw2Et5GtvBJJfltf3HSjBy1YTz5n4d4gz7YUw0VNTxoa1lYl9bCpNfmbCCWof/Amq PH8p9xXST2brvbYGXTzfBbH5B5h6F+Eivb5t5bHltg6AAWzffve+sxr9XFSl3GUgW6DC OyPQ== X-Forwarded-Encrypted: i=1; AJvYcCXMgA0rf7nhZYtLnaVSkcW+FhD9ksc1Gwgz7d16EV8LyFjjgsGmzipxUtC+ylkz8RbelFJBbQyTwP0=@vger.kernel.org X-Gm-Message-State: AOJu0YzKFJyeE3okHtHLnncNT5ZMU12ktp5qgtry9hY0bNiRWHyxZ2aP lF73oSefrK6DWTRXLMqtfaeY4eITSbu0Bkm+HJT1L8lYJJShdMJkKFzLEZlpug== X-Google-Smtp-Source: AGHT+IEupx5MlVbtKwKg6yvd5EiB5c1xx+gvkZPhgQaQWXBcBa4Tm7HItPIXvwrtuhd2v5lBCFGh8g== X-Received: by 2002:a17:902:f60a:b0:1ff:4a01:43f7 with SMTP id d9443c01a7336-2050e97bf7bmr144975245ad.10.1725163632654; Sat, 31 Aug 2024 21:07:12 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205155673a2sm47107365ad.303.2024.08.31.21.07.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:12 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 05/18] usb: typec: Add device managed typec_switch_register() Date: Sat, 31 Aug 2024 21:06:43 -0700 Message-ID: <20240901040658.157425-6-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 36 +++++++++++++++++++++++++++++++++++ include/linux/usb/typec_mux.h | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index db644bec862c..f420185e36e3 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -235,6 +235,42 @@ void typec_switch_unregister(struct typec_switch_dev *sw_dev) } EXPORT_SYMBOL_GPL(typec_switch_unregister); +static void devm_typec_switch_unregister(void *switch_dev) +{ + typec_switch_unregister(switch_dev); +} + +/** + * devm_typec_switch_register - resource managed typec_switch_register() + * @parent: Parent device + * @desc: Multiplexer description + * + * Register a typec switch and automatically unregister the typec switch + * when @parent is unbound from its driver. + * + * The arguments to this function are identical to typec_switch_register(). + * + * Return: the typec_switch_dev structure on success or error pointer on error. + */ +struct typec_switch_dev * +devm_typec_switch_register(struct device *parent, + const struct typec_switch_desc *desc) +{ + int ret; + struct typec_switch_dev *switch_dev; + + switch_dev = typec_switch_register(parent ,desc); + if (IS_ERR(switch_dev)) + return switch_dev; + + ret = devm_add_action_or_reset(parent, devm_typec_switch_unregister, switch_dev); + if (ret) + return ERR_PTR(ret); + + 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 08431f0896d5..c30fc7f4441f 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -35,6 +35,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); void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); @@ -60,6 +63,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) {} static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {} From patchwork Sun Sep 1 04:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786312 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.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 1592113A40F for ; Sun, 1 Sep 2024 04:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163638; cv=none; b=Ogi+4/ri/eQ5zwA1i+/QfWZr1kfTk4DXefIJBfM2Xrn3j0yb2TiOIsQEHagt6D8KnLc9sgCu4gkcqcwx5QiVf0vhH5fSDsryJELp5bgMbz3dyUJjr0nrk5El3RRyixTKJi3ReyjQP23nZtWB4VtTq1PZpcYfmTMHDv1CSw+DQp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163638; c=relaxed/simple; bh=wSeatNei0A7Ebd8UljCyLcHxVvUbnWOD9TWjcptS84U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dajqHP+HGVp3f4HFYQS4CzJvt7pGyoVdiYS46+Phgn91KnzEdvqye5Z9uD0sfSNWX6EQg8SD5sZUJ9OeBBamDHLFDtb0vhUR7ySNOZQhCeAmwlfw7LKgH0aluhzTFLJBMd6SLwp58gLzfoYctPN3tiQtPvLW3cxz/2KbY4HYkYI= 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=AKmdKUNh; arc=none smtp.client-ip=209.85.210.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="AKmdKUNh" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-70f794cd0e3so426851a34.2 for ; Sat, 31 Aug 2024 21:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163635; x=1725768435; 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=DuEX+B1LPDkO0gwsNaxgdZWm0YsScz9kUEVqR8xaDPo=; b=AKmdKUNhkyggy8Wf50Fxl5z29mTkhy0vyYr9Y8BhjSE7iTzW+AZgxwF3FOSbtsIe6N mq/ApKxaNmCIoK42yYJo8ZmAULp76RJ9lCsLzYOk85/rwnqg4gpB9N5J5YtEiBTN8U0A i3EEjSCf34IHYTdjvL7v4rrWPuVxAN5BVqwlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163635; x=1725768435; 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=DuEX+B1LPDkO0gwsNaxgdZWm0YsScz9kUEVqR8xaDPo=; b=fmM91pW6LRNUpQMA6FuGmYKR7XP01aUiYAi7AZWk4MT0ut0rA+BeEzsXSbdDmjwu7s 0CA5s4H+fgUQ/3Ezxo5x6LZXOx+Oi3Be8XhARHbHSd15+WOo4l+U3D46QTQxHpfqJMj7 5Gtl2jro+M0XUZgsBpoY1jAE6bzq7DljQjWbRYYxqd0FRhdzQks0H8gfSS08c/NhwLdj 2WMHwv4FWK23ePhSvRfyUhjXFPJC26m5BZcLWM5IrHgpNXlrD1Jm14KeJCS/ITVZYQhE yeCKfUDTVkbknpeiu/Jm2A1joFMSwuPDsbBxQoLhWM1cJed+kI9mYm7VdxVKV3lczymd Jkww== X-Forwarded-Encrypted: i=1; AJvYcCX8QygKpbyjw64KxGg8ndf7tTv95xXpLv3EB79tKq6vS5L0hIHxjFTBx9v0EgyskABB507rjAK4xzQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwN3goFl8Na9iiacfZR/e0dqWjqeSCCS/Ck3ZBaGK6VYNxcSfLJ RjQJSbmJHvi/qi6SlsRezhf3fon/u5ModDchvFTGxDnAlKgS5szszWhiMhqyOw== X-Google-Smtp-Source: AGHT+IFhd/v0o75TM3Av0ILjq1OZC+BzETv/i1P77qiiQwfgv/wDUywsLFLtblWnZq5CeTacIW+EAQ== X-Received: by 2002:a05:6358:60cc:b0:1b5:fa48:5973 with SMTP id e5c5f4694b2df-1b7ef5fd67cmr625729455d.4.1725163634887; Sat, 31 Aug 2024 21:07: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-2d85b119c26sm6611649a91.14.2024.08.31.21.07.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07: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 v4 06/18] drm/bridge: aux-hpd: Support USB Type-C DP altmodes via DRM lane assignment Date: Sat, 31 Aug 2024 21:06:44 -0700 Message-ID: <20240901040658.157425-7-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 483 +++++++++++++++++++++++- include/drm/bridge/aux-bridge.h | 17 + 2 files changed, 488 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/bridge/aux-hpd-bridge.c index 6886db2d9e00..32565f88ade7 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 +#include #include +#include #include static DEFINE_IDA(drm_aux_hpd_bridge_ida); @@ -18,6 +24,80 @@ struct drm_aux_hpd_bridge_data { struct device *dev; }; +enum dp_lane { + DP_ML0 = 0, /* DP pins 1/3 */ + DP_ML1 = 1, /* DP pins 4/6 */ + DP_ML2 = 2, /* DP pins 7/9 */ + DP_ML3 = 3, /* DP pins 10/12 */ +}; + +#define NUM_DP_ML (DP_ML3 + 1) + +enum usb_ss_lane { + USB_SSRX1 = 0, /* Type-C pins B11/B10 */ + USB_SSTX1 = 1, /* Type-C pins A2/A3 */ + USB_SSTX2 = 2, /* Type-C pins A11/A10 */ + USB_SSRX2 = 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 mapping + * @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 = 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 = 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 = to_auxiliary_dev(dev); @@ -30,6 +110,22 @@ static void drm_aux_hpd_bridge_release(struct device *dev) kfree(adev); } +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 = to_drm_dp_typec_bridge_dev(dev); + adev = &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 device *parent, struct device_n } EXPORT_SYMBOL_GPL(drm_dp_hpd_bridge_register); +/** + * devm_drm_dp_typec_bridge_alloc - Allocate a USB type-c DisplayPort bridge + * @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_DisplayPort, + * which terminates the bridge chain and is able to send the HPD events along + * 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) = NULL; + struct device_node *remote_ep; + struct device_node *ep_node; + struct of_endpoint ep; + + typec_bridge_dev = kzalloc(sizeof(*typec_bridge_dev), GFP_KERNEL); + if (!typec_bridge_dev) + return ERR_PTR(-ENOMEM); + adev = &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 = of_graph_get_remote_endpoint(ep_node); + of_node_put(remote_ep); + if (!remote_ep) + continue; + + if (ep.port == 2) + dp_ep = of_node_get(ep_node); + else if (ep.port == 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 = of_property_count_u32_elems(dp_ep, "data-lanes"); + if (num_dp_lanes < 0) + num_dp_lanes = NUM_DP_ML; + + typec_bridge_dev->max_lanes = num_dp_lanes; + + ret = ida_alloc(&drm_aux_hpd_bridge_ida, GFP_KERNEL); + if (ret < 0) { + kfree(adev); + return ERR_PTR(ret); + } + + adev->id = ret; + adev->name = "dp_typec_bridge"; + adev->dev.parent = parent; + adev->dev.of_node = of_node_get(parent->of_node); + adev->dev.release = drm_dp_typec_bridge_release; + adev->dev.platform_data = of_node_get(np); + ret = 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 = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_free_adev, adev); + 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_bridge_dev *typec_bridge_dev) +{ + struct auxiliary_device *adev = &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,290 @@ static int drm_aux_hpd_bridge_attach(struct drm_bridge *bridge, return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL; } +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: USB type-c DisplayPort 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_mapping. + * Future atomic checks on this bridge will request the lane assignment from + * the previous bridge so that the DP signal is sent to the assigned USB type-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_bridge_dev, + u32 conf, + struct drm_dp_typec_bridge_typec_port *port) +{ + enum usb_ss_lane *lane_mapping = port->lane_mapping; + struct auxiliary_device *adev = &typec_bridge_dev->adev; + struct drm_aux_hpd_bridge_data *hpd_data = 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 = hpd_bridge_to_typec_bridge_data(hpd_data); + dp_lanes = data->dp_lanes; + + pin_assign = DP_CONF_GET_PIN_ASSIGN(conf); + if (pin_assign == DP_PIN_ASSIGN_D) + num_lanes = 2; + else + num_lanes = 4; + max_lanes = typec_bridge_dev->max_lanes; + data->num_lanes = num_lanes = min(num_lanes, max_lanes); + + for (i = 0; i < num_lanes; i++) { + /* Get physical type-c lane for DP lane */ + typec_lane = 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 = lane_mapping[typec_lane]; + + /* Map logical type-c lane to logical DP lane */ + dp_lanes[i] = 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 = to_drm_dp_typec_bridge_data(bridge); + num_lanes = data->num_lanes; + if (!num_lanes) + return 0; + dp_lanes = data->dp_lanes; + + in_lanes = kcalloc(num_lanes, sizeof(*in_lanes), GFP_KERNEL); + if (!in_lanes) + return -ENOMEM; + + bridge_state->input_bus_cfg.lanes = in_lanes; + bridge_state->input_bus_cfg.num_lanes = num_lanes; + + for (i = 0; i < num_lanes; i++) + in_lanes[i].logical = dp_lanes[i]; + + return 0; +} + static const struct drm_bridge_funcs drm_aux_hpd_bridge_funcs = { .attach = drm_aux_hpd_bridge_attach, }; +static const struct drm_bridge_funcs drm_dp_typec_bridge_funcs = { + .attach = drm_aux_hpd_bridge_attach, + .atomic_check = drm_dp_typec_bridge_atomic_check, + .atomic_reset = drm_atomic_helper_bridge_reset, + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state = 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 = typec_mux_get_drvdata(mode_switch); + typec_data = port->typec_data; + dev = typec_data->hpd_bridge.dev; + typec_bridge_dev = to_drm_dp_typec_bridge_dev(dev); + + if (state->mode == TYPEC_STATE_SAFE || state->mode == TYPEC_STATE_USB) { + drm_aux_hpd_bridge_notify(dev, connector_status_disconnected); + } else if (state->alt && state->alt->svid == USB_TYPEC_DP_SID) { + dp_data = state->data; + ret = drm_dp_typec_bridge_assign_pins(typec_bridge_dev, state->mode, port); + if (ret) + return ret; + + if (dp_data->status & DP_STATUS_HPD_STATE) + status = connector_status_connected; + else + status = 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 *typec_data, + struct drm_dp_typec_bridge_dev *typec_bridge_dev, + struct device_node *np) +{ + struct device *dev = &typec_bridge_dev->adev.dev; + struct device_node *typec_ep, *remote_ep; + struct of_endpoint ep; + const u32 mapping[] = { 0, 1, 2, 3 }; + struct drm_dp_typec_bridge_typec_port *port; + size_t num_ports = typec_bridge_dev->num_typec_ports; + struct typec_mux_desc mode_switch_desc = { }; + struct fwnode_handle *fwnode; + const char *name; + + port = 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 != 0) + continue; + /* Only consider available endpoints */ + if (!of_device_is_available(typec_ep)) + continue; + /* Only consider connected nodes */ + remote_ep = of_graph_get_remote_endpoint(typec_ep); + of_node_put(remote_ep); + if (!remote_ep) + continue; + + port->typec_data = 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 = of_fwnode_handle(typec_ep); + name = kasprintf(GFP_KERNEL, "%s-%d", dev_name(dev), ep.id); + if (!name) + return -ENOMEM; + + mode_switch_desc.set = drm_dp_typec_bridge_mode_switch_set; + mode_switch_desc.fwnode = fwnode; + mode_switch_desc.name = name; + mode_switch_desc.drvdata = port; + port->mode_switch = devm_typec_mux_register(dev, &mode_switch_desc); + if (IS_ERR(port->mode_switch)) { + kfree(name); + return PTR_ERR(port->mode_switch); + } + + kfree(name); + 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 = &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 = dev_get_platdata(dev); + u8 dp_lanes[] = { DP_ML0, DP_ML1, DP_ML2, DP_ML3 }; + int ret; - data = devm_kzalloc(&auxdev->dev, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; + if (id->driver_data == DRM_AUX_HPD_BRIDGE) { + hpd_data = devm_kzalloc(dev, sizeof(*hpd_data), GFP_KERNEL); + if (!hpd_data) + return -ENOMEM; + bridge = &hpd_data->bridge; + bridge->funcs = &drm_aux_hpd_bridge_funcs; + } else if (id->driver_data == DRM_AUX_TYPEC_BRIDGE) { + typec_data = devm_kzalloc(dev, sizeof(*typec_data), GFP_KERNEL); + if (!typec_data) + return -ENOMEM; + hpd_data = &typec_data->hpd_bridge; + bridge = &hpd_data->bridge; + bridge->funcs = &drm_dp_typec_bridge_funcs; + typec_bridge_dev = to_drm_dp_typec_bridge_dev(dev); + memcpy(typec_data->dp_lanes, dp_lanes, sizeof(typec_data->dp_lanes)); + ret = drm_dp_typec_bridge_probe_typec_ports(typec_data, typec_bridge_dev, np); + if (ret) + return ret; + } else { + return -ENODEV; + } - data->dev = &auxdev->dev; - data->bridge.funcs = &drm_aux_hpd_bridge_funcs; - data->bridge.of_node = dev_get_platdata(data->dev); - data->bridge.ops = DRM_BRIDGE_OP_HPD; - data->bridge.type = id->driver_data; + hpd_data->dev = dev; + bridge->of_node = dev_get_platdata(dev); + bridge->ops = DRM_BRIDGE_OP_HPD; + bridge->type = DRM_MODE_CONNECTOR_DisplayPort; - auxiliary_set_drvdata(auxdev, data); + auxiliary_set_drvdata(auxdev, hpd_data); - return devm_drm_bridge_add(data->dev, &data->bridge); + return devm_drm_bridge_add(dev, bridge); } static const struct auxiliary_device_id drm_aux_hpd_bridge_table[] = { - { .name = KBUILD_MODNAME ".dp_hpd_bridge", .driver_data = DRM_MODE_CONNECTOR_DisplayPort, }, + { .name = KBUILD_MODNAME ".dp_hpd_bridge", .driver_data = DRM_AUX_HPD_BRIDGE, }, + { .name = KBUILD_MODNAME ".dp_typec_bridge", .driver_data = DRM_AUX_TYPEC_BRIDGE, }, {}, }; MODULE_DEVICE_TABLE(auxiliary, drm_aux_hpd_bridge_table); diff --git a/include/drm/bridge/aux-bridge.h b/include/drm/bridge/aux-bridge.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 +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 *parent, 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_status status); +struct drm_dp_typec_bridge_dev *devm_drm_dp_typec_bridge_alloc(struct device *parent, + struct device_node *np); +int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_bridge_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; } +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) { } From patchwork Sun Sep 1 04:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786313 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 2C00513B586 for ; Sun, 1 Sep 2024 04:07:17 +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=1725163640; cv=none; b=dA0lp95UL+FC8ic1oqTAG+FTc4hATTvODVpq3U+d3799WfXx6dxCMmxDsyl8QttdKsA+2+zG5jNwlr+zkPH/glK3OYxshhXNkzwwLhaPyY7K4aHZ9UToCvaMizh2aoPg8HGyexb8vsnilSogRruYy5hm3dXHspdJ28wC7tqIw10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163640; c=relaxed/simple; bh=qY6RFdgdEz4w9jQTLOHoc3XmVl5kjOyodlnHhwG34MY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u8NA3M63M6zbrmaf7xp3fgeyQ9FwJzucYq9TCHL2piOCmdFLL9i4UtxojQ5wLCZfrc+puYMut+hzW/nxKtXGQ5a70Q4XxXEW6eJBHXkz5jWyIMcKkBnSfLei4RIAH+SGs9kJQfl7QOWKrqL1RarYm/OaqES11Rw/k8777Gu5U9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XosWRfMy; arc=none smtp.client-ip=209.85.214.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="XosWRfMy" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20536dcc6e9so11102465ad.2 for ; Sat, 31 Aug 2024 21:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163637; x=1725768437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EnT+TkOPiwvRqtG4XdBzNIXwEpZ2e3WbsaKfU3N0MOw=; b=XosWRfMy30FNjhHcntK0aamG16FStgjIk2sbxV07QZARrI1n/vWg1aB4t4LuC+1A2Z 6c8dWkr/eLO/FzqvkWNhVz4JWe/UwzOGU8KJS6U7wEPz1WkMTrHEltba5fxTWDBiD1M+ LNFY9UZv/PXJELNBF2s5Gl2guENOdT4m+mcGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163637; x=1725768437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EnT+TkOPiwvRqtG4XdBzNIXwEpZ2e3WbsaKfU3N0MOw=; b=YtbRbFQqV7+Bv13CeCWlLEczY5tOomhSjjalr9oOEeIoKl1TN3wJ5TEGEsdt+mFCSQ HP2l0VH8CF3yUTy5lsw+QxLC64jNfcZWNAlRGJkrSoDkAj+ya3dVB0KaSeByMJviLqel arGc3qUpXcI87CBIpxREL94lzpngaftBXFT3LPZP1Yqp6Yo8AhmsmcFQ83FIql0ITy27 8lawwZsD0rnA9pXLxx6p7FgIbQGg++5esVH+xNThPZCbNNdAa1kE8sryuP0xwAlTCW+j JtRFEQXlK/U17oNBfRA2P6pfAbHkflkFLuzuxv7koYaPwZ5I6JZcwDfH13n0JtFaK0hZ KqPA== X-Forwarded-Encrypted: i=1; AJvYcCXUdASSrmx+GAhwbatImG4lpDgwcbU7CpxmcxKPr++OOJuy6ij7U7HWr7nu90AE1Ax9z/pAAdVltPA=@vger.kernel.org X-Gm-Message-State: AOJu0YwC5FgA7hwoEHRvIAwaj7aMhFEOzHH6jiZmuJ53OXKzGq0pUn7r z6BzVrPlyQpW4msi9rGKH2NnFvZJc7PWreBaPHr9ciPN1MmMcUF8H/nuk6mkMw== X-Google-Smtp-Source: AGHT+IFy6qneRh0JJN2K30z3cDl+DrJ4fLZ39NN7FVzA1lAH0njyn66SGUGcS/pbvoFHuvYriZC5zA== X-Received: by 2002:a17:903:1209:b0:1fa:1dd8:947a with SMTP id d9443c01a7336-2050c40deccmr100312495ad.46.1725163637193; Sat, 31 Aug 2024 21:07:17 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205152b12c7sm46853475ad.56.2024.08.31.21.07.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:16 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 07/18] drm/bridge: dp_typec: Support USB Type-C orientation Date: Sat, 31 Aug 2024 21:06:45 -0700 Message-ID: <20240901040658.157425-8-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Register an orientation switch for each type-c output node to support flipping the lane mapping when the port is in reverse orientation. Only do this when the orientation-switch property is present. This is mostly useful for the case where the DP lanes are directly connected to the usb-c-connector and the device doesn't have an orientation switch wired down on the board between the connector and the DP controller. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Cc: Dmitry Baryshkov Signed-off-by: Stephen Boyd --- drivers/gpu/drm/bridge/aux-hpd-bridge.c | 77 +++++++++++++++++++++---- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/bridge/aux-hpd-bridge.c index 32565f88ade7..d2832e6481d7 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -47,12 +47,16 @@ struct drm_dp_typec_bridge_data; /** * struct drm_dp_typec_bridge_typec_port - USB type-c port associated with DP bridge * @lane_mapping: Physical (array index) to logical (array value) USB type-C lane mapping + * @orientation: Orientation of USB type-c port * @mode_switch: DP altmode switch + * @orientation_switch: USB type-c orientation switch * @typec_data: Back pointer to type-c bridge data */ struct drm_dp_typec_bridge_typec_port { u32 lane_mapping[NUM_USB_SS]; + enum typec_orientation orientation; struct typec_mux_dev *mode_switch; + struct typec_switch_dev *orientation_switch; struct drm_dp_typec_bridge_data *typec_data; }; @@ -378,17 +382,35 @@ static int dp_lane_to_typec_lane(enum dp_lane lane) return -EINVAL; } -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; } return -EINVAL; @@ -413,6 +435,7 @@ drm_dp_typec_bridge_assign_pins(struct drm_dp_typec_bridge_dev *typec_bridge_dev u32 conf, struct drm_dp_typec_bridge_typec_port *port) { + enum typec_orientation orientation = port->orientation; enum usb_ss_lane *lane_mapping = port->lane_mapping; struct auxiliary_device *adev = &typec_bridge_dev->adev; struct drm_aux_hpd_bridge_data *hpd_data = auxiliary_get_drvdata(adev); @@ -448,7 +471,7 @@ drm_dp_typec_bridge_assign_pins(struct drm_dp_typec_bridge_dev *typec_bridge_dev typec_lane = lane_mapping[typec_lane]; /* Map logical type-c lane to logical DP lane */ - dp_lanes[i] = typec_to_dp_lane(typec_lane); + dp_lanes[i] = typec_to_dp_lane(typec_lane, orientation); } return 0; @@ -496,6 +519,23 @@ static const struct drm_bridge_funcs drm_dp_typec_bridge_funcs = { .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, }; +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 = typec_switch_get_drvdata(sw); + port->orientation = orientation; + + return 0; +} + static int drm_dp_typec_bridge_mode_switch_set(struct typec_mux_dev *mode_switch, struct typec_mux_state *state) @@ -544,7 +584,9 @@ drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_typec_bridge_data *typec_dat struct drm_dp_typec_bridge_typec_port *port; size_t num_ports = typec_bridge_dev->num_typec_ports; struct typec_mux_desc mode_switch_desc = { }; + struct typec_switch_desc orientation_switch_desc = { }; struct fwnode_handle *fwnode; + bool orientation = of_property_read_bool(np, "orientation-switch"); const char *name; port = devm_kcalloc(dev, num_ports, sizeof(*port), GFP_KERNEL); @@ -587,6 +629,19 @@ drm_dp_typec_bridge_probe_typec_ports(struct drm_dp_typec_bridge_data *typec_dat return PTR_ERR(port->mode_switch); } + if (orientation) { + orientation_switch_desc.set = drm_dp_typec_bridge_orientation_set, + orientation_switch_desc.fwnode = fwnode; + orientation_switch_desc.drvdata = port; + orientation_switch_desc.name = name; + port->orientation_switch = typec_switch_register(dev, + &orientation_switch_desc); + if (IS_ERR(port->orientation_switch)) { + kfree(name); + return PTR_ERR(port->orientation_switch); + } + } + kfree(name); port++; } From patchwork Sun Sep 1 04:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786314 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 3DA8C13A41F for ; Sun, 1 Sep 2024 04:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163641; cv=none; b=Q1FmpmfrO2L0rCBqQBjWFQcDHdGvNfi7GUiZKGe7GcFUNs6crUVGxI3JirWYb2UjOiISDyKw6Z3noe0D1Nt+vzTHwjcPYISeWIhc9rXtgDJOq1SZW4B56fuTalp2r5bUbvPhTtOLMVIcrUV+X9hmH7q7RlUvmpwAKmlsMwqVIBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163641; c=relaxed/simple; bh=K0vY/b3gdQJ7BbfGBTXVjSZjUjMpNMzLu+iBHhG2UV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CvLMUEXHTuHI+MgxifvEppHUux+H2dFezqN//4JRGKXYHDIjZdQx62igtFjCMrDbXvcgcSyzze73hDBthQMevF5zOBWeAhGr8upPvjszrP+O/0dcohAu9q21joc1pWpTKS4n3SImJ5wLHHKVfIQLZI8lUq3EVas1XeGzOGylSOU= 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=Ral7CfPc; arc=none smtp.client-ip=209.85.215.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="Ral7CfPc" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-70b2421471aso1737292a12.0 for ; Sat, 31 Aug 2024 21:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163639; x=1725768439; 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=dihu8n2PjcWrFXOuwWbECc9MpTZcbkDtMAPCx56QCc0=; b=Ral7CfPcE6I6JLLwGDbrbf4VdCpLJLd5VBeL1JQx0Lv8LiHAedN3a7Bms6VpMfNzWc Kl1Wn9QeF8uuenIS2n7WiIOKf84cEXhFlfHq3jMkphgzxHRZKBv0exPUdxrgC/AFPz88 NcPU+uj3U3hGPuZC5zyaNGTqRdJ9vevZACJM4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163639; x=1725768439; 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=dihu8n2PjcWrFXOuwWbECc9MpTZcbkDtMAPCx56QCc0=; b=vTceeuEaRO/ROHDEgRvQVT/d7xnrfzb9+jZMTrxegZ45p2VoYxP0PTROVNSFjB6Z9L b06fZWWv7zNt/D8Yiyu7in5nncCVuZU6nCR0LGN/3LFpGTkUYf+xBL+udtRf70nVSZTb /LRoKbFr6LiCMQ31vk8xR3ti9rGpb3JmlZG56Qh41PH38W7LnSRyEEcH3yN02mQVLYG/ M2GdBl9IAgzXYnAKCOcaebsKuZQHsGap7sRLllu+mz2qCpHrbalXRWdU9/ZAaNUwr+lK xMBE9FeY2yc+iOqf/xoja7xd+Xrf4QvkiRwKQvDjiS5Rb722275TQiYb9egszIPTuOm4 ahZw== X-Forwarded-Encrypted: i=1; AJvYcCVsbaWMLbqCay30dtBoKu1Caeij0qeayDyl3qmxcSRGjDCUiFRtplm/QYnex+7TsTOrHhv1dtoA4cE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9R7A4JWaTn1F0SUM/ZTBeNnxoMZyml5WxqL+1FRUx/CfvsrLV +8LOpF0mxks4jb5SeeWpJn8LGgsnvPCcU7bdXmTnb07dXe5pqVqDnKs3T7eMCw== X-Google-Smtp-Source: AGHT+IGUB6+86RHnw08wq757NS4DSJb/B5ixBOuB5HoLx7W2xOHzGQ0pL/7XrZLrWwYk0S+0GfQauw== X-Received: by 2002:a05:6a21:3213:b0:1c4:a8a6:a85f with SMTP id adf61e73a8af0-1ced62a2b24mr2056687637.30.1725163639331; Sat, 31 Aug 2024 21:07:19 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d8aba505bfsm1381042a91.8.2024.08.31.21.07.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:19 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 08/18] drm/bridge: dp_typec: Add "no-hpd" support Date: Sat, 31 Aug 2024 21:06:46 -0700 Message-ID: <20240901040658.157425-9-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/bridge/aux-hpd-bridge.c index d2832e6481d7..52db36aa190b 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; }; enum dp_lane { @@ -355,6 +356,8 @@ void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status sta if (!data) return; + if (data->no_hpd) + return; drm_bridge_hpd_notify(&data->bridge, status); } @@ -672,6 +675,7 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev, return -ENOMEM; bridge = &hpd_data->bridge; bridge->funcs = &drm_aux_hpd_bridge_funcs; + bridge->ops = DRM_BRIDGE_OP_HPD; } else if (id->driver_data == DRM_AUX_TYPEC_BRIDGE) { typec_data = devm_kzalloc(dev, sizeof(*typec_data), GFP_KERNEL); if (!typec_data) @@ -680,6 +684,9 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev, bridge = &hpd_data->bridge; bridge->funcs = &drm_dp_typec_bridge_funcs; typec_bridge_dev = to_drm_dp_typec_bridge_dev(dev); + hpd_data->no_hpd = of_property_read_bool(np, "no-hpd"); + if (!hpd_data->no_hpd) + bridge->ops = DRM_BRIDGE_OP_HPD; memcpy(typec_data->dp_lanes, dp_lanes, sizeof(typec_data->dp_lanes)); ret = drm_dp_typec_bridge_probe_typec_ports(typec_data, typec_bridge_dev, np); if (ret) @@ -689,8 +696,7 @@ static int drm_aux_hpd_bridge_probe(struct auxiliary_device *auxdev, } hpd_data->dev = dev; - bridge->of_node = dev_get_platdata(dev); - bridge->ops = DRM_BRIDGE_OP_HPD; + bridge->of_node = np; bridge->type = DRM_MODE_CONNECTOR_DisplayPort; auxiliary_set_drvdata(auxdev, hpd_data); From patchwork Sun Sep 1 04:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786315 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 397AD13D51C for ; Sun, 1 Sep 2024 04:07:22 +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=1725163644; cv=none; b=tPNYbWXGl4U1iu51jS+RJOhwO5kl5GaS8suTXWmmCVsYhYDNyA6ZtCzKL7OBNnSO0UqJUsYbcC6xqY+FbWpFMvk0F17sCZFZVzwd3D78nq3xCZ2/Ll1JcdUrhvemwgIeLhFgMxtIQ335Y0hks2iOtF6hqFxlQQz/IdcD/Nf7NQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163644; c=relaxed/simple; bh=gQLHbxZ7YqvGpXB1p1t8XiyRzrvBZDrPBVB81RgQmGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wc9pSC7MIFGvWf+3f8Hrln6E2uAq3EqZmwoJaeCfsRDodbTdYXZ+7iS4m/v5yb6RlmAMOw4W9efx9nJ9YAZZR5Rxdzo11zlmkpgCmSEoX9E4HgSAbYAhTdlCvkYmcAAJJ37VMyPJTLWq8aj1psw0NXs5p42TtA1OgSIqTKri4KQ= 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=S8zuDPVT; 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="S8zuDPVT" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2d8818337a5so1040888a91.1 for ; Sat, 31 Aug 2024 21:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163641; x=1725768441; 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=7B0A+gjnynDK46J7Z91Ni0fcqv7iZd2DyUsBegaNPWE=; b=S8zuDPVTyNgTPBT5xmfI7JnkR2MPpsEBl2aSzyDE28ke/BJctB9C+R3KUIzEUoWGUt XI0UJIUY3OyfFvoCmNKyUgywIoKuAtPmfSetjKg7LNCcoCbLbPqmy4v2Q6g87Z/gahH0 innRoIpzlwKiIR7BfhtrYZgB5dxmVQ7rQ0EDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163641; x=1725768441; 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=7B0A+gjnynDK46J7Z91Ni0fcqv7iZd2DyUsBegaNPWE=; b=dHTDORBJpCMiEm7yymMD5oN1xu+QZTkKESZ/FL12fBqpuyfd92CH/kiVIB4iNh+sNP cJooSRTjpM3vGgFNhhCRJRX0jh2uFmsXJ9CWyCTqB7Ubk6Ln8pacpOn1FUc6NIZ9zkfg SWOI0PBeB9OzZXMjNuDhap6mmu1pfVgijd9hfCVda9EoSrOXvQXlZWAMDZIG/qBATCm/ sNHTMSQQ8c4SGmbblUk3s43f3/T9y/TvwY4chSDXzVOZPH3m2dkMFsS1Q2w+oewGh+5I UtTaw9VDWc5w/4RHaG6QJk2zCaGJ/n+a9C4EBuq1ZjPPL9u4azR4SGf3pBayNTd8Wz8a c+WA== X-Forwarded-Encrypted: i=1; AJvYcCXA5T5njCFWk/aKp7Sn4y8udzsDDZSTXhogcosj4rThWWMvvHvNEAedfr4ql4OOKKp/jkIgezOBKaw=@vger.kernel.org X-Gm-Message-State: AOJu0YwOf+Cpts7exU3ZYamn63krvWmhfBq7sPyJrKeIQsn82BtuBXvg i17zk8TO5HNzgdhTzPfWpFuQnz0BpilFdFgsYQdhXzaDL2LNsICLrzmWzi9HCQ== X-Google-Smtp-Source: AGHT+IGSmH/wnxTJNBBOPKMZLyVY9PSbNYj6DYaZsk5ViTxQvzorla6wmYK6YTGx9bSlm2MFyUGXzg== X-Received: by 2002:a17:90a:d310:b0:2cf:f860:f13b with SMTP id 98e67ed59e1d1-2d86b04e9eemr10621245a91.17.1725163641373; Sat, 31 Aug 2024 21:07:21 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d844611384sm8985683a91.27.2024.08.31.21.07.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:21 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 09/18] drm/bridge: dp_typec: Allow users to hook hpd notify path Date: Sat, 31 Aug 2024 21:06:47 -0700 Message-ID: <20240901040658.157425-10-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 31 +++++++++++++++++++++++++ include/drm/bridge/aux-bridge.h | 9 +++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/gpu/drm/bridge/aux-hpd-bridge.c b/drivers/gpu/drm/bridge/aux-hpd-bridge.c index 52db36aa190b..8ff8716b2630 100644 --- a/drivers/gpu/drm/bridge/aux-hpd-bridge.c +++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c @@ -93,6 +93,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; }; static inline struct drm_dp_typec_bridge_dev * @@ -324,6 +326,21 @@ devm_drm_dp_typec_bridge_alloc(struct device *parent, struct device_node *np) } EXPORT_SYMBOL_GPL(devm_drm_dp_typec_bridge_alloc); +/** + * drm_dp_typec_bridge_add_hpd_notify: Register a callback called when the + * bridge chain hpd state changes + * @typec_bridge_dev: USB type-c DisplayPort bridge + * @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 *typec_bridge_dev, + hpd_notify_fn_t hpd_notify, void *hpd_data) +{ + typec_bridge_dev->hpd_notify = hpd_notify; + typec_bridge_dev->hpd_data = 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 @@ -363,6 +380,19 @@ void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status sta } EXPORT_SYMBOL_GPL(drm_aux_hpd_bridge_notify); +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 = to_drm_dp_typec_bridge_data(bridge); + typec_bridge_dev = 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) { @@ -520,6 +550,7 @@ static const struct drm_bridge_funcs drm_dp_typec_bridge_funcs = { .atomic_reset = drm_atomic_helper_bridge_reset, .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, + .hpd_notify = drm_dp_typec_bridge_hpd_notify, }; 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-bridge.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) struct drm_dp_typec_bridge_dev; +typedef void (*hpd_notify_fn_t)(void *data, enum drm_connector_status status); + #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE) struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, 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_status status); struct drm_dp_typec_bridge_dev *devm_drm_dp_typec_bridge_alloc(struct device *parent, struct device_node *np); +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); int devm_drm_dp_typec_bridge_add(struct device *dev, struct drm_dp_typec_bridge_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, struct device_node *np) return NULL; } +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) { From patchwork Sun Sep 1 04:06:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786316 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 58AB913F43B for ; Sun, 1 Sep 2024 04:07:24 +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=1725163646; cv=none; b=S5ZjP75b7ZVnLoAbVcJagJ04pwNRO445msDN8Wb6OQFcdGWw4WnFBGze1akJSVSTCUNXWI82+1geox6c+ROSZdUplcFLkdG1HAvLA5FUylaZeq6FaqKhhjU22MptH4AX68vmcLmtQpAPE+4OrLmqqM8j9FhYCt3gVw4mMMO9Zus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163646; c=relaxed/simple; bh=2tAlkjfeIOfQ7pqxJw2iSfNqPK9cXn4z7367eyq0Rjg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8FhhF5WfsD3krWfCebTQD0ulC2PsfAETjQ8/JFjWJ8xTytVwQBCkJUKF3DHLTY30FJx8L0U42gHDSaDXH31OVWPEVUiaJbKaJflH72M2/AJpoi8MGgqheYyk3TKeNaOwLhvIYjoktfbNoOfeIDW3VLQJSiWSPeVJgky1viLsqg= 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=b35c02Nz; 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="b35c02Nz" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-715e64ea7d1so2744262b3a.0 for ; Sat, 31 Aug 2024 21:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163644; x=1725768444; 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=nad3jYq+zuMNkdjkLGBBGQbMhdXY1+s1WlyYMjA8ho4=; b=b35c02NzFzR6or7KCjz/JT3hJrf37zKeLbWgTGlp16fZ0Ts4DAduISZ+lmV220xwPN bSa3mYlBa13/Efam+Yz8CuMHwKTbi+yNX7kjy0Bu34WsSUFwTjH3Uh1qbN3a3A5OZ9dZ zzVSXn119IcN9TGua3ZOfMV3x8CbX762/j1vY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163644; x=1725768444; 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=nad3jYq+zuMNkdjkLGBBGQbMhdXY1+s1WlyYMjA8ho4=; b=ZTENLDy5ZPAPnkm8KCMxG0JbhDPB50t0E4ieZnOKkW/2qO1ujJ9AJpCyaKxLHkdLGn k2gyY7GNgo7lz3KDWGDWd08zabboOD42F0VCcmSe/BCbs/hdRD7VCyJAOjwc2ub1+R/z BZ9DucXnl8IyEb4xEGHu/YSkFzUAg1agP5MbSO/q06VRcb6Y5wCJG9NooLmFAcLjaBZR nP983aBkt/Al4hRiayGEbldMFI0d/tBQr8yRtKXdSJqC/oBUDF4N6gyND/stNJnyv9Gk 1g1Ek2bSHT7ksXhwHiwcglPd+tC7fiGKzIvxf7gsLdFv95l5pAvl+rCN5e52Hbrnkxno VE0w== X-Forwarded-Encrypted: i=1; AJvYcCVlVD/F4SoTMdskp90WL72l7kVD9YNrvpA9IOSyCBoUwmYScRF1en9u9XpBXWtKtswiL0g40ZXRIHA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0pfq+2qPqidkCIzvi4TJl6W/1OcN4Wyq2ynw9L+z7pHq/0bGq XdcZJ6akTofOGOYqeZQGSV73lx+27eYixlIhQ6Ec+J6Uizg4ezm9j54lxB+GGg== X-Google-Smtp-Source: AGHT+IE4gRNS1Wle0dhusZLk2Qf9YkMQZghXHbtMZ6oKKSwEP4ondmRftvf+lk7yL+f1D9vFEqjyTA== X-Received: by 2002:a05:6a00:91d8:b0:714:147c:1377 with SMTP id d2e1a72fcca58-7173b5c8556mr4671065b3a.7.1725163643536; Sat, 31 Aug 2024 21:07:23 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-715e569ef39sm4828452b3a.122.2024.08.31.21.07.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:23 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 10/18] devcon property: Document devcon_match_fn_t Date: Sat, 31 Aug 2024 21:06:48 -0700 Message-ID: <20240901040658.157425-11-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The usage of this match function is hard to understand at a glance. Document the arguments and the return value so it is clear how to implement the function. Suggested-by: Andy Shevchenko Signed-off-by: Stephen Boyd --- include/linux/property.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index 61fc20e5f81f..797b1eeda7d2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -507,8 +507,25 @@ unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); -typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, - void *data); +/** + * devcon_match_fn_t - device connection match function + * @fwnode: Remote connection's device node + * @con_id: Identifier for the connection + * @data: Match function caller specific data + * + * Implement a callback with this function signature to search a fwnode's + * connections for a match with a function like device_connection_find_match(). + * This function will be called possibly multiple times, once for each + * connection. The match function should inspect the @fwnode to look for a + * match. The @con_id and @data provided are the same as the @con_id and @data + * arguments passed to the functions that take a devcon_match_fn_t argument. + * + * Note: This function can be called multiple times. + * + * Return: Pointer to match or NULL if no match found. + */ +typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, + const char *con_id, void *data); void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, const char *con_id, void *data, From patchwork Sun Sep 1 04:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786317 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 82B09142E86 for ; Sun, 1 Sep 2024 04:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163648; cv=none; b=Wg5GbMwAPHLJwUMQZzXU0nUVR+RwfmC60Om+iSjKK2XwNn/IzFmZsN7PFnfhaCuVC+/zasfKmurOIZEHyzHaGcF88g7rr0yuNV+dQ06yjtq9syTc0iuJS8tEWfVuE8xSSvyced0I1hXeztCdg55DV9Su3R5m4Cnq2zcAjFUSIeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163648; c=relaxed/simple; bh=+zyMv3RGe6S6LrOSBHIbaRGTiGQgsHff7zfMdzmNV+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kdK6iyK5niAs1cn0NaHdYztYoortdaKZSmbRovVK5eLTzwxNXO+vyNSeUJUWevYNWoFGlvgvJUndJ2JE67JE/IIKDwf4HSOLMwTj/h/U3vJulAljqCG2rS2xP7mu37a4U4AnaK7nFaugMTZKPxStV7J3nh5SIBsptWBDTGtSDKg= 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=jNrnS3/H; arc=none smtp.client-ip=209.85.214.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="jNrnS3/H" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20202df1c2fso26896125ad.1 for ; Sat, 31 Aug 2024 21:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163646; x=1725768446; 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=Pmo3/yU2P8LsM22CtkppGBhBN/HDkEIQ1oKrtDKPQrs=; b=jNrnS3/HimaxMvA3EauzTnFPMy4sOxxrLLNN5813raFgVRZYY1qX8ylHvu9IaU38iD pbltwDKot7MWvEox1riPfx4nq2Y1D+n/3iXi+tlr432FTyz63lUt20kWzzsISvm9TqWB JAx3l2ZY9eJz3ye8fCsK34DKIbf9igs925XNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163646; x=1725768446; 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=Pmo3/yU2P8LsM22CtkppGBhBN/HDkEIQ1oKrtDKPQrs=; b=CjwNXVb7hFRvLe+JPhSqrBUG2A1TRtVJS8fATcJCkYOxdEMp/qayH0J/VaeuyOfdyS SrcpEu8dlWG7MMQRgRRnrX2XLXKExxvPUMYAQsvk+iBzsBfc6Gedx+6NY+8Ng0TXuVp7 2ztEerhX64hi56C0fcHai4AHy+VigIfRtv1LT8VgUJA7bRkCwyk/rcnflaopdNy+EWpq +ToKk24qjbKjzQDF4ch0HlNpVc/FVwX9Xp8oqI26jB/TldGDu9RmZbqx6nfb2W7knKLs /YuJCLSuVLcYNnls50pGQkFAW/5Z2shf/K6I3a5yooxW7fIBSz5BacyuZVEwAnHd3yqQ bbwA== X-Forwarded-Encrypted: i=1; AJvYcCXKR3Wlp3mIZig+eObFmWEmISM0WtHVw8UUhB1pkEwvNczG4U0v1EAej+FxBctnOdlekLfS2pDwjFc=@vger.kernel.org X-Gm-Message-State: AOJu0YzTFVAA5DXSL/ERf4+Ha8yu0uvP3rJhvUqW1qA/EEM+8mjfs35D /VfnbA3LiJrGJ7exsq9R87ucJXcoAyX4JgW6uOcjrn6u711GBlPz929dMV7oeQ== X-Google-Smtp-Source: AGHT+IGkEvNKrwf9vzljH1qmOoDG+G58iNPsfXL5CyX8XTHyhIjQ2Mn1eF6oxR0BUcemUEp0so8ADQ== X-Received: by 2002:a17:903:181:b0:1fb:2ebc:d17a with SMTP id d9443c01a7336-205286bb7cemr101990685ad.23.1725163645599; Sat, 31 Aug 2024 21:07:25 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-205155338bcsm47111615ad.177.2024.08.31.21.07.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:25 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 11/18] device property: Add remote endpoint to devcon matcher Date: Sat, 31 Aug 2024 21:06:49 -0700 Message-ID: <20240901040658.157425-12-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 11 +++++++---- 5 files changed, 28 insertions(+), 9 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 = 0; void *ret; @@ -1299,7 +1300,9 @@ static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwno continue; } - ret = match(node, con_id, data); + remote_ep = fwnode_graph_get_remote_endpoint(ep); + ret = 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 struct fwnode_handle *fwnode, if (IS_ERR(node)) break; - ret = match(node, NULL, data); + ret = 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); -static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const char *id, - void *data) +static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index f420185e36e3..9ddb6ec54325 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) } 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_handle *fwnode, */ dev = class_find_device(&typec_mux_class, NULL, fwnode, switch_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + switch_fwnode_match); return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -299,6 +303,7 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode) } static void *typec_mux_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -316,6 +321,9 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode, dev = class_find_device(&typec_mux_class, NULL, fwnode, mux_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + mux_fwnode_match); 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); } -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; @@ -31,6 +33,9 @@ static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char dev = class_find_device(&retimer_class, NULL, fwnode, retimer_fwnode_match); + if (!dev) + dev = class_find_device(&retimer_class, NULL, endpoint, + retimer_fwnode_match); return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/include/linux/property.h b/include/linux/property.h index 797b1eeda7d2..72a89cd410db 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -510,22 +510,25 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /** * devcon_match_fn_t - device connection match function * @fwnode: Remote connection's device node + * @endpoint: Remote connection's endpoint node * @con_id: Identifier for the connection * @data: Match function caller specific data * * Implement a callback with this function signature to search a fwnode's * connections for a match with a function like device_connection_find_match(). * This function will be called possibly multiple times, once for each - * connection. The match function should inspect the @fwnode to look for a - * match. The @con_id and @data provided are the same as the @con_id and @data - * arguments passed to the functions that take a devcon_match_fn_t argument. + * connection. The match function should inspect the connection's @fwnode + * and/or @endpoint to look for a match. The @con_id and @data provided are the + * same as the @con_id and @data arguments passed to the functions that take a + * devcon_match_fn_t argument. * * Note: This function can be called multiple times. * * Return: Pointer to match or NULL if no match found. */ typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, - const char *con_id, void *data); + const struct fwnode_handle *endpoint, + const char *id, void *data); void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, const char *con_id, void *data, From patchwork Sun Sep 1 04:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786318 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.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 B0140145345 for ; Sun, 1 Sep 2024 04:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163650; cv=none; b=eNJBtr9TDQ6e0ItIx6ajGV7pcTf1VDF2J0RAHc5No6EM0gQR1veVNLLSUSr1YaQxiMPL8eREQpPPX6QGswnKcRHqWDnAtC15qH0xppayMMmjEEog3QZBG0eh5mUgjRNQKuF0kz9Nt5nr1mZo4uXIEYLAdlmWfgWHXjcqCVBGzEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163650; c=relaxed/simple; bh=aHxbXooyxcUO5JwBCTNyqni3GmuKJP5ay9S/7oeiMaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cUKcQsVzmgAr3mjdp5lLEfOQCfquqyOa0RqE05QMS18CQ+FtBkP3M4cXJLgnOYpTnNSnH5PZJoluUgNRyqrHK0TrbMTMVPBPJxmqA28Km66WBbYC9LzcYcDUmafizqVgIkYvjoDuKau09AJfMlFUzGBZpfrgzBQUmyhYEpVAwNc= 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=jqDSt4Mz; arc=none smtp.client-ip=209.85.166.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="jqDSt4Mz" Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-39d47a9ffd5so12044315ab.2 for ; Sat, 31 Aug 2024 21:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163648; x=1725768448; 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=lVAbaFTBXgnW+fAYVEBW9D2cgqLAHsvQgjfJBzfAY3s=; b=jqDSt4Mz/biw9kj12Y2zxy1j2029nTuT14V9Hb6g5SLODgcCJDIGRQW8bH9n0OCQXV wjbMhdMDAmjjmSDPDiDQi1uapih5tpg6sMoVRNU/Gl9dQBx5JDx+ksRyPUEQup8nHyHj gVed2iWGCP0QwN2vTUCTW5TIdDbASSI2lVjX4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163648; x=1725768448; 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=lVAbaFTBXgnW+fAYVEBW9D2cgqLAHsvQgjfJBzfAY3s=; b=KOQO25hYa/bqUJQXG66MnW0FnzQQMM4uaZZxxiaMgXk32MkgJjRhNlWUxxxV1JUKDw WfN+OM6OwLC7RLNZhZAmBd0OUsCdC5I4tiRbQPQCV1YvPpidIBBdqIuf6461NPykp3fG 7lWN2UYM1pWZWWUSYJdjnWgYmKrvP0HypM85T5kJ28QjqVRf4YuIzU3VIItYn7/uk3lB r2iRl4swCHnSG/Bix7+fi2B7PT7fYS08omtyw4DA+7IJVxXGLZBc+BIxXB1TiaxmubZK EvA1mZ7tD9i84K7I+paVpnAb7i3adPLYwSCgPgcblHUOxLUGZ2fVIQbO+obWInYgKezU kL1A== X-Forwarded-Encrypted: i=1; AJvYcCXY/FA2iwkjN8d0Zpas5vm5sfL6kNBx3fmURuiXBB45nqazFtAr8bhxQ4bjHuTprJNlDAC6HomOAUg=@vger.kernel.org X-Gm-Message-State: AOJu0YwLiY/MTNk/Iw6rn6pvtwCQCT875KV4SO6vDsqI3hAMAkR7Bux4 fxuabmEhXEnKuSwS1ufTCfvm3AbWFVWallJPgSLrc/GYc59cPgvC2fDL5PIdeA== X-Google-Smtp-Source: AGHT+IFsOTewMNJ0BJt0tAvMG/AJBfDBb9as9o8BHiOu5PQfrktxWGnHk+Ahlp9K/S8f1Bq4n28w/g== X-Received: by 2002:a05:6e02:1c42:b0:39f:5646:97da with SMTP id e9e14a558f8ab-39f56469978mr14867835ab.20.1725163647832; Sat, 31 Aug 2024 21:07:27 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e9d77f2sm5333884a12.89.2024.08.31.21.07.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:27 -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 , "Rob Herring (Arm)" Subject: [PATCH v4 12/18] dt-bindings: usb-switch: Extract endpoints to defs Date: Sat, 31 Aug 2024 21:06:50 -0700 Message-ID: <20240901040658.157425-13-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Rob Herring (Arm) 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 --- .../devicetree/bindings/usb/usb-switch.yaml | 74 +++++++++++++++---- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/usb-switch.yaml b/Documentation/devicetree/bindings/usb/usb-switch.yaml index da76118e73a5..f5dc7e23b134 100644 --- a/Documentation/devicetree/bindings/usb/usb-switch.yaml +++ b/Documentation/devicetree/bindings/usb/usb-switch.yaml @@ -35,9 +35,12 @@ 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' port@1: $ref: /schemas/graph.yaml#/$defs/port-base @@ -47,16 +50,7 @@ properties: properties: endpoint: - $ref: /schemas/graph.yaml#/$defs/endpoint-base - unevaluatedProperties: false - properties: - data-lanes: - $ref: /schemas/types.yaml#/definitions/uint32-array - minItems: 1 - maxItems: 8 - uniqueItems: true - items: - maximum: 8 + $ref: '#/$defs/usbc-in-endpoint' oneOf: - required: @@ -65,3 +59,57 @@ oneOf: - ports 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 = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + endpoint { + remote-endpoint = <&usb_c_connector>; + }; + }; + + port@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + endpoint { + remote-endpoint = <&usb_ss_phy>; + }; + }; + }; + }; + +... From patchwork Sun Sep 1 04:06:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786319 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.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 25270149C76 for ; Sun, 1 Sep 2024 04:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163652; cv=none; b=RzCEiaakzGGk2U0YTL5X5tXle/QB4Nb4vokjGGg3ghglhrCTJ7vRciQWNtIb+zPzs6roL3JRdcPpRC0ooUGMZiCqhzTkXZAJm6H3lMKp5Jy/5XbuJVyjoGML2AJ4LzGCeZMIvWqBiVEAToRQXudWjJydUyxeGhkjQ+e1U0X/SV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163652; c=relaxed/simple; bh=RUpzr9ZKBqIyyOycrXXNoFY+qDo5GiSWo5OPRiGL5UY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZZhU7XiZbvO2L0FWYGu49TMl949AnVBwmM3KqNfM7r/lCXVmZeNC84+krEyhWtnGb74mZZqbeMH4rp3CUTvGgGlXnUlviytK3VSX509cMgAG4Thb4RRuxEvSQRpypOLa57GWkDOF4rNEW557SBwh8JrvyZkevmjJObJOAGVEaaY= 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=hS0ZCq3W; arc=none smtp.client-ip=209.85.167.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="hS0ZCq3W" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3df16ece2c2so995647b6e.2 for ; Sat, 31 Aug 2024 21:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163650; x=1725768450; 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=Wd502yvg5fXt4u5g230ZTpdeyPtCH4Yq39fj6qZgjT4=; b=hS0ZCq3WU51NbOpI4w0Y13/ZE7ykW4L8Kj4Klg8o5BeGkCcrN2TlUWzKg3ELQ/BIRK x5KfeZDgICv4TjRQozf/ombUMn/aC45yskW3Mo7XKPpSYFxhTPYvPXrbzrd9ZSPldJWT Cf01E0gPnKW1WGqAeUeyLsnvYKABf6Pz5nPso= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163650; x=1725768450; 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=Wd502yvg5fXt4u5g230ZTpdeyPtCH4Yq39fj6qZgjT4=; b=REpbaLsV/r2yfqbPOMvROz3npZzt5Nfm6PSdjINaaDpW1tlpOBeXkwIsxgJSbtVd2E 8ei2YmGQbR/j5WBqXlF8dTVOebMc5WKQvO44LWXPSyL/g5D5BvsQ5/ZwE6ZWGSbUJFIH CHOyTpRg6pxZUnMBbH9BnvPfLXUfD3V/CdQbiFQyaXOOTtaDZHHVVRNv3l4aSXCKRIUb AkEbnAUm1oY2Vkll+VonbbTvo7fkMsNOYH8EaVSDxHGMBaARGPoW03Kf5rP0TOTpNDsl Rea5PHuDHxWC4QwR9pyZjf5rQD7i5oOR9QyHyT5R8+gQiRFOcJoH7T6Rfyl07XYDbBby hY7A== X-Forwarded-Encrypted: i=1; AJvYcCUBy/UUolqeXDmMK1cveiQ89+GvXZg30IfMGSZoIDxX3BtI16T3n2IprnGEwOHZpM2bX5C12edIDLg=@vger.kernel.org X-Gm-Message-State: AOJu0YxMmqHBcmA3cfEsNNy8ACd8jE8CHoQJZGeROihE2dGe2ScZIsnj tlKE8cez0Jqdk6w2S/jh2pY7dWerHREzPtRaDskMH9aisPRQ7FZxDZj8Q3IcQQ== X-Google-Smtp-Source: AGHT+IGL4OiCHHZFsgZPnNJ0c3FJUh9XkC9nxzYLew8976ZXhgGWIxU50B53RDoHj8H5q7Hy8p3c6w== X-Received: by 2002:a05:6808:318c:b0:3dc:299d:c505 with SMTP id 5614622812f47-3df22d06635mr3681624b6e.37.1725163650076; Sat, 31 Aug 2024 21:07:30 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-715e5763a67sm4833459b3a.216.2024.08.31.21.07.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:29 -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 , "Rob Herring (Arm)" Subject: [PATCH v4 13/18] dt-bindings: usb-switch: Extend for DisplayPort altmode Date: Sat, 31 Aug 2024 21:06:51 -0700 Message-ID: <20240901040658.157425-14-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Rob Herring (Arm) 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 --- .../devicetree/bindings/usb/usb-switch.yaml | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-switch.yaml b/Documentation/devicetree/bindings/usb/usb-switch.yaml index f5dc7e23b134..816f295f322f 100644 --- a/Documentation/devicetree/bindings/usb/usb-switch.yaml +++ b/Documentation/devicetree/bindings/usb/usb-switch.yaml @@ -52,6 +52,14 @@ properties: endpoint: $ref: '#/$defs/usbc-in-endpoint' + port@2: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + + properties: + endpoint: + $ref: '#/$defs/dp-endpoint' + oneOf: - required: - port @@ -65,6 +73,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 usbc-in-endpoint: $ref: /schemas/graph.yaml#/$defs/endpoint-base @@ -79,7 +100,75 @@ $defs: items: maximum: 8 + 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 = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + endpoint { + remote-endpoint = <&usb_c_connector>; + data-lanes = <0 1 2 3>; + }; + }; + + port@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + endpoint { + remote-endpoint = <&usb_ss_phy>; + }; + }; + + port@2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + + endpoint { + remote-endpoint = <&dp_phy>; + data-lanes = <0 1 2 3>; + }; + }; + }; + }; + # A USB orientation switch which flips the pin orientation # for a usb-c-connector node. - | From patchwork Sun Sep 1 04:06:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786320 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 3812714AD30 for ; Sun, 1 Sep 2024 04:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163655; cv=none; b=o6PW18jWVOLUUImreQfLJG2V9L4Tz4AUS7uzmEyR7cGvbBi1/+/dEyGse5NkgojLzjDx7t+F4ZRj9dTsPu39GsrG3f6lI+KciKmQqLXVG281ncpn03VvLEtr8SLbeZka7jel/3/1Gwakr5apWVyv3H0qPm9R3TsRA7PyBIAz2RE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163655; c=relaxed/simple; bh=bHSm/FEpQTjOcYpuqVvRWkTQn5fPAWRWSsjkb7Wydpg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ao+pkb7uGGGzByrk4dGjJe0bR1GtpCe6foI9++2CGAaTQNeZEq+f55vFuhD1yUAMHPyhLmckqm5Go7qeOm9Vwxu96lOND9MlnBxoDy9HJvw/J4WMvguQRW5DgLtQEbfCs7cEiDVfjyw7xAJLcO0FBZljjbB/jBXQciTu8avfXTU= 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=MtHlbcCl; arc=none smtp.client-ip=209.85.215.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="MtHlbcCl" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7cb3db0932cso2320161a12.1 for ; Sat, 31 Aug 2024 21:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163652; x=1725768452; 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=bM6GJPpKkvUSSBy7VkQZRdWnaSLWrHTVpkTkbaZHopw=; b=MtHlbcCln3qEnn2YtZXv+ZqXeEHbB4jdFtfytehXtjGGEHJImtraFeHMN6oLL/exax r0/bqu2GH9wacI9D96XovObBerMDmkRKMisuIKjjJUh6tOMldqJy9eesKPPrbTMiliy+ g7rM0713DkY3N2+/GQc79Tw32l5uIQ3gs4xdY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163652; x=1725768452; 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=bM6GJPpKkvUSSBy7VkQZRdWnaSLWrHTVpkTkbaZHopw=; b=j5LYeUo7EGr7O4/9N8vNrofPLHoC9bP4TswFs69yqRe3TNKSXInsxWtzrKPiHCmRwp +BJJ1ecekvTXp0hnsjTonjE0dcYS2k5mGgbcshSfQnCRhCAYZlfb2PZ3O+lzRbaiXIYj j64XIXbeYf2igv05RNgSMrfOY3tGjfXVfhODkAh9OZESwdEPXUJvDXka1BL2gJdqGqC6 HJCT3gM+xTBeGxAblXaAro8Y1NUOvs3ZVWFgTmZsLeXuASOfBDRF2vfG+9hYQverExsV dJLM2wBer03kYHUutRdPBZPsLEwQKvqyszcRaOTRi52oCIUKNhnFm/HrmRxBcrSME/yO SYKA== X-Forwarded-Encrypted: i=1; AJvYcCUXmGaLfk984oF7FNkujEcNzUpAcHBnD1zi4jWitVbbf64zhtw8W4DALBDafS9L+9xoh+JkRrE6Lq0=@vger.kernel.org X-Gm-Message-State: AOJu0YwapTZBvfHlGlCbzvCAK8NDEv9QgQ/RuaUCM9ovNOW6gghYbyOc xBeLp8XmjpwaQhpQfRLlnMvmQ0u/8hdnApTObRxxB61foKP+0HSZnqIHcCYb3g== X-Google-Smtp-Source: AGHT+IEBZFVJryLmpEcn+rd/P1ffgAono4nzaKo7Lu5B6szTV31kzRn9qLEAbPf1ik2MymYrUHGCHA== X-Received: by 2002:a17:903:41cf:b0:205:489d:2b22 with SMTP id d9443c01a7336-205489d2dd3mr38959905ad.23.1725163652216; Sat, 31 Aug 2024 21:07:32 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2056595564fsm3120865ad.229.2024.08.31.21.07.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:31 -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 , "Rob Herring (Arm)" , Krzysztof Kozlowski Subject: [PATCH v4 14/18] dt-bindings: Move google,cros-ec-typec binding to usb Date: Sat, 31 Aug 2024 21:06:52 -0700 Message-ID: <20240901040658.157425-15-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This binding is about USB type-c control. Move the binding to the usb directory as it's a better home than chrome. Reviewed-by: Rob Herring (Arm) 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 --- Documentation/devicetree/bindings/mfd/google,cros-ec.yaml | 2 +- .../bindings/{chrome => usb}/google,cros-ec-typec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename Documentation/devicetree/bindings/{chrome => usb}/google,cros-ec-typec.yaml (90%) diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/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 typec: - $ref: /schemas/chrome/google,cros-ec-typec.yaml# + $ref: /schemas/usb/google,cros-ec-typec.yaml# 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.yaml rename to Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml index 9f9816fbecbc..365523a63179 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# -title: Google Chrome OS EC(Embedded Controller) Type C port driver. +title: Google ChromeOS Embedded Controller (EC) USB type-c port driver maintainers: - Benson Leung From patchwork Sun Sep 1 04:06:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786321 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 3355B14D719 for ; Sun, 1 Sep 2024 04:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163657; cv=none; b=Ag06epzwCVTlCQ9+nijV+8CYLfk6klwpD6sUiT6Kah9xUMDOe7lqVldfv/H707aQ0njLZtX6SygsKyztvZraQGBbfSpEI9MCP5OfR9j6vfLPkhh5o0qOOC0ED9HZuemDhsiC+o1X0m84Setc3RrTPV4dz2UU5YKSbfBTzxZIh20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163657; c=relaxed/simple; bh=WOQQCDCTDzH1gapFAgaMeUAT0zwZNlWAdNWqIr5X/+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMyA+vYTPMF4af+qqX3OSE+HMzWFawI3edPacVWzXD62GDFomh7zOX0ZA6DXc/iP7fjdnOXL5Phlc1tN7jft93uBvDnErP8CDve3+3OQxa8TYmgWoUjy+5M1IKfDKLNSjAc1cMcvI/F33b48DuEC4w8Q4vd87I860e1oBRJfMPs= 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=ncchSkBG; arc=none smtp.client-ip=209.85.214.170 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="ncchSkBG" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20202df1c2fso26896415ad.1 for ; Sat, 31 Aug 2024 21:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163654; x=1725768454; 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=PbprL3O5uRtoBez6xE8gNyhklG4JEaVa8fjN58vGWmo=; b=ncchSkBGbdGXzCfaid9u9lL08aKGZVshICgJfN9AMNf+91AMyddBB5uMJVrKc4QSh+ qi4tpgYPu/3TQvx2l+Oybo/k7zhClxCQZEMTJqR85uMhpT5O15tWE3+wyVXjP4l8vjB/ yK2fj+t7JNfGfArZbr67hOz5oyWhwLeSjw4uo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163654; x=1725768454; 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=PbprL3O5uRtoBez6xE8gNyhklG4JEaVa8fjN58vGWmo=; b=K/2U7s7wSiZY4EjmAWROFMAa+rxpysQACRVf0XDthRZSEjRuaPwmUNKM1OFYtPQcWA ElniX4VNpL4qpMtIX0bApTzDJaWO6Rje6f/ZfxBBIiuXDMIACO1HjqH3GAnbk7d74Shs dsdbMmIpG3/R2MVPfmBpxxzdb5C4enHLcxudEOXlagQoZhBXjbjNzrXbo01BW60OEm6h Yrf80B6YOQN5xzB8P3MzSHSa60H2nDnLV4psOpRYynMGlZZzdmn1NLTYKnEEVPli1x+U BgiyabNqTejG3UX4iYsDMSni3ub60pOzyhHqPqI9feU3JkiEPF/g2AJMBTRlKJTdKl05 vItg== X-Forwarded-Encrypted: i=1; AJvYcCX51wn4qLFoAZxE7rOfdtP3w2Eoynef8jUhq8yJprrep+dIRP5PUFerPZOtQwyOAP983Y9uiyhR5rg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4OqSsUwh7lF5qXS86wlwEect//rE7uFP4KROg0hw8VEHyCZW9 cog001flBgzxspG+c26bOc14zhZESVhW6tZOzyxFm4nMnPXN/sJxJ35LfTlNAw== X-Google-Smtp-Source: AGHT+IHMnQiUjN9f1YWEGM0JdOjALu7X8K8AbH1Oilpa9S51nEUs+XXgha5QPmoQddesTYlXreZjQQ== X-Received: by 2002:a17:902:ce01:b0:203:a10a:9887 with SMTP id d9443c01a7336-205276c2e26mr115311825ad.3.1725163654329; Sat, 31 Aug 2024 21:07:34 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20568d21dd4sm2338785ad.155.2024.08.31.21.07.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:34 -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 , "Rob Herring (Arm)" Subject: [PATCH v4 15/18] dt-bindings: usb: Add ports to google,cros-ec-typec for DP altmode Date: Sat, 31 Aug 2024 21:06:53 -0700 Message-ID: <20240901040658.157425-16-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Rob Herring (Arm) Cc: Krzysztof Kozlowski Cc: Conor Dooley Acked-by: 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 Acked-by: Lee Jones --- .../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/Documentation/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: gpio-controller: true - 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# + "^typec(-[0-9])*$": + type: object + $ref: /schemas/usb/google,cros-ec-typec.yaml# + required: - compatible diff --git a/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml b/Documentation/devicetree/bindings/usb/google,cros-ec-typec.yaml index 365523a63179..235b86da3cdd 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 + 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 +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 examples: @@ -50,6 +184,8 @@ examples: typec { compatible = "google,cros-ec-typec"; + orientation-switch; + mode-switch; #address-cells = <1>; #size-cells = <0>; @@ -60,6 +196,99 @@ examples: power-role = "dual"; data-role = "dual"; try-power-role = "source"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + usb_c0_hs: endpoint { + remote-endpoint = <&usb_hub_dfp3_hs>; + }; + }; + + port@1 { + reg = <1>; + usb_c0_ss: endpoint { + remote-endpoint = <&cros_typec_c0_ss>; + }; + }; + }; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "dual"; + data-role = "dual"; + try-power-role = "source"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + usb_c1_hs: endpoint { + remote-endpoint = <&usb_hub_dfp2_hs>; + }; + }; + + port@1 { + reg = <1>; + usb_c1_ss: endpoint { + remote-endpoint = <&cros_typec_c1_ss>; + }; + }; + }; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + cros_typec_c0_ss: endpoint@0 { + reg = <0>; + remote-endpoint = <&usb_c0_ss>; + data-lanes = <0 1 2 3>; + }; + + cros_typec_c1_ss: endpoint@1 { + reg = <1>; + remote-endpoint = <&usb_c1_ss>; + data-lanes = <2 3 0 1>; + }; + }; + + port@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + usb_in_0: endpoint@0 { + reg = <0>; + remote-endpoint = <&usb_ss_0_out>; + }; + + usb_in_1: endpoint@1 { + reg = <1>; + remote-endpoint = <&usb_ss_1_out>; + }; + }; + + port@2 { + reg = <2>; + dp_in: endpoint { + remote-endpoint = <&dp_phy>; + data-lanes = <0 1>; + }; + }; }; }; }; From patchwork Sun Sep 1 04:06:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786322 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.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 36ACE155A24 for ; Sun, 1 Sep 2024 04:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163659; cv=none; b=SZs/zHCvJo9vAAobkwY4or5arSr/rqiZhgabghE9qprnCilzCqAuISSKNTPrE/n9fKoXTiEKk9LgQ3Ns8HLj1ziVS1e2v4qW71llJg8sF9Od9OmNIXU0cOdMdxVZrLd03lQ8UG1UT9iFnQuHSt8cac30quxF5VIlDDyPXcDR0t4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163659; c=relaxed/simple; bh=VrN82hoQt0wLVQI0aCC1SR5A2ibWGb0NJymP0pIp9xU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Od2sUzVzzhV7P2kiZD2ksoIVrRrgwpc2x1v07eVjaBvg0vvv8/JsAcjUL8rjAH0JT2U1UPTE8ZhnDIXWwQYk9tL+rJkFHZ9A1IsYohN+slltGn76Lj+kzn66yYVOFIJsA8kWeobpjFPuK91vUnagrYz37OX8wODZTvsiWCMVN3g= 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=dNqWQ8Fv; arc=none smtp.client-ip=209.85.210.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="dNqWQ8Fv" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-714262f1bb4so2431415b3a.3 for ; Sat, 31 Aug 2024 21:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163656; x=1725768456; 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=lp4qb/KS90Tir3i25BqLGfP+MrbWuhnQKUX2LR6B8LU=; b=dNqWQ8FvRRcyt/vhqfHfNSL4Oo29DaIIRpF41DHFYeGRuH3GGDKyFx7zhZb1HOrFwk 4sKlTE0zPdh1UrkpNx0C4bCgAdHE/9Ga+o7FTWGw6b8hsITjURZbh/X1wzJgw7XZI2KV lQv8L/B+otZvjhKkmR/nuWpq+Q6JFoUbpPUnc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163656; x=1725768456; 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=lp4qb/KS90Tir3i25BqLGfP+MrbWuhnQKUX2LR6B8LU=; b=ZA4mDbG/wSHIPWVjrfqKfr+FNETFmlcRuE5id38PJpoU+C3oy9vgWceSd0W21ACCNO OKInUSiKGZCm2SvkYjH5VKx293fo/s6U9J7fmqzdPD8Bwj4iAn/habp7trZuIJ43V+ix 5F6r9bS1HZphP1PMD25ScXzT13Vx5fTWCwSGbNEu1Y7fKxM4M0o9Ojfkz9vdwiz6Wgu7 PKaN3IcPc6/XPulwl6AafwdnisQurgoqC9Am1zLMZlArdDkOxYFH5ZJdMa0giTN9wLcp aQ+OCNjA83kFLyYDYxY2jxOKyPjPvHiY+6HqMp8wg/vb852f2bhwzizvWE4XRcxz33YD X2Zg== X-Forwarded-Encrypted: i=1; AJvYcCVTOSxx9jD8lW6YUYTg4F9PTju3SyUFRSi1EdpECDKbJutTwgaQsLSL2h8Wx7OdMjEgb9+2bFivcog=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/hBj6w7XB0ZIQuMTvxZeJ9dq/AeZytDWmnZFneKJE6ccAF4EK cda/j7GNQS3WVJmLQPWdcSKK2plJyErqf41xowmW8ZeFfeYSaiRHqZkirqmJ7w== X-Google-Smtp-Source: AGHT+IE8Kiz0yS+drOGbUHSHPEFKkSlIzC8nDgi3dGGbxuwIctLm8xLCZLhIj6Ez6yfo2U5IiO9Iyw== X-Received: by 2002:a05:6a21:3a93:b0:1c0:e49a:6900 with SMTP id adf61e73a8af0-1cece4d7233mr3894641637.7.1725163656376; Sat, 31 Aug 2024 21:07:36 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d8445d5ea9sm9130058a91.8.2024.08.31.21.07.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:36 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 16/18] platform/chrome: cros_ec_typec: Add support for signaling DP HPD via drm_bridge Date: Sat, 31 Aug 2024 21:06:54 -0700 Message-ID: <20240901040658.157425-17-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Tzung-Bi Shih --- drivers/platform/chrome/Kconfig | 1 + drivers/platform/chrome/cros_ec_typec.c | 31 +++++++++++++++++++++++++ drivers/platform/chrome/cros_ec_typec.h | 1 + 3 files changed, 33 insertions(+) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig 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/chrome/cros_ec_typec.c index 4d305876ec08..a57053bdec18 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,6 +17,8 @@ #include #include +#include + #include "cros_ec_typec.h" #include "cros_typec_vdm.h" @@ -334,6 +337,9 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) u32 port_num = 0; nports = device_get_child_node_count(dev); + /* Don't count any 'ports' child node */ + if (of_graph_is_present(dev->of_node)) + nports--; if (nports == 0) { dev_err(dev, "No port entries found.\n"); return -ENODEV; @@ -347,6 +353,10 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) /* DT uses "reg" to specify port number. */ port_prop = 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 = -EINVAL; dev_err(dev, "No port-number for port, aborting.\n"); @@ -413,6 +423,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) return ret; } +static int cros_typec_init_dp_bridge(struct cros_typec_data *typec) +{ + struct device *dev = typec->dev; + 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_dev = devm_drm_dp_typec_bridge_alloc(dev, dev->of_node); + if (IS_ERR(dp_dev)) + return PTR_ERR(dp_dev); + typec->dp_bridge = 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 +1284,10 @@ static int cros_typec_probe(struct platform_device *pdev) typec->num_ports = EC_USB_PD_MAX_PORTS; } + ret = cros_typec_init_dp_bridge(typec); + if (ret < 0) + return ret; + ret = cros_typec_init_ports(typec); if (ret < 0) return ret; diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chrome/cros_ec_typec.h index deda180a646f..eb816d30d880 100644 --- a/drivers/platform/chrome/cros_ec_typec.h +++ b/drivers/platform/chrome/cros_ec_typec.h @@ -35,6 +35,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 drm_dp_typec_bridge_dev *dp_bridge; struct notifier_block nb; struct work_struct port_work; bool typec_cmd_supported; From patchwork Sun Sep 1 04:06:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786323 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DF0416ABC6 for ; Sun, 1 Sep 2024 04:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163660; cv=none; b=OjpeC/NSmnzjXytD2PuYEXUjstytJnf8A5i6C7kPFvdxGugQ62CbNzXPkEFyrh5eWKfww3rEb33UTvhE104wl8B5TMssWTfxHrt34ZYBvQK12GhVN4kWmpRYqTSR/jrrDXBfE5kJ2xFKqtLAsKLF9Wye9p2f5EEj2cW7igs3pXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163660; c=relaxed/simple; bh=qwK70bPxM8LVw7h8REHJPsZb7kjgcSJTEZGj411FeVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+mZD5zAI0laBPVLNs9+BzSdPfsDyva3ExOtZigJloQC0z3o2H49VmnQCAT0KFSyUxRFZNUqlIFL76dSq4JJZWZ0ix/2OA51BOvrleop/b016mF36GUVZL1HARvdfqrfJRlmj5ykTA8whlvzs44lVF+vmBkLSoq42ArtE+yuc0I= 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=l3lUZVHB; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="l3lUZVHB" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2d8b68bddeaso273898a91.1 for ; Sat, 31 Aug 2024 21:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163658; x=1725768458; 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=dYPu0stqsRx0TqGeKhWWj5HPmBRIxzjpP9BbfW7c5l4=; b=l3lUZVHBGpeWo8z0DCFWbN8xo3pRDVV3leP4l65ciq6vwW5c0pfvRTB0HOUuKvgwlq ziDo8CyvNct66fG1ypiWj8ZDtXjx6U+tlP7V6xbG6md3aaLtvgf+m8+8EHxXkMfwus6M N2dPOQ5zhLX2oFhfMxExu1rX2pLCjSLQQRAE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163658; x=1725768458; 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=dYPu0stqsRx0TqGeKhWWj5HPmBRIxzjpP9BbfW7c5l4=; b=L76ZdXn9snwWIXmM4CyIR/CBdXmfSU4sTomi1NJ4zRPgtaaGS/u/awt5FvtHvYOrr/ SHlXjgx6y1bN2u/fkXk4Jv0VEUtNenJCFGhDbMVs5+BMT5CUs6WwVbR7+lhTHcuzedJn 1/gLFOlbKzB2nQdBUw6xLZUlik4zcn1Q12Qe3uDalAf0aMm6GMtD3zFoKimVaHOPDsNG n55fqehJIqQ/NEGIPQL6axOzZE5TWBgs3KK1qe/gzjzC3v1ujsEClG698dZSgS2RQiX6 DP4Yrj6sjU2vqeFVsJwTIP4WjOiywc1hVRgY5e6WkbqLqoXM4H2U/aiZ5EW5lO8BXAMB ipJg== X-Forwarded-Encrypted: i=1; AJvYcCXLJMMQZs6mglwtGDEgdEmXYcHs6R+EFeCILXGB5/YhP9FnMpZymajbQzPmcSUifvnn/NTX2J+e6j8=@vger.kernel.org X-Gm-Message-State: AOJu0YwiP41g4UtK11/cZcTgbBeERe6/Tm8+DRV+suyjSiZuJAo6em80 1WiKJIVpxstSOQ/u8g2nBlDblTx3hJ/KW/XLU87X/lYxokG2PoJDlsPiOBibyQ== X-Google-Smtp-Source: AGHT+IERU9m/9viKAFaj9S2/X/9qEFrt7tD0EJG/4IvRq2IeDeMrMQQYu9a1+hSVg3+cqHjT5jopKg== X-Received: by 2002:a17:90a:ea93:b0:2d3:bd6f:a31e with SMTP id 98e67ed59e1d1-2d88e3e64dcmr4070632a91.28.1725163658424; Sat, 31 Aug 2024 21:07:38 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e9d92a5sm4530018a12.90.2024.08.31.21.07.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07: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 v4 17/18] platform/chrome: cros_ec_typec: Support DP muxing Date: Sat, 31 Aug 2024 21:06:55 -0700 Message-ID: <20240901040658.157425-18-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_typec.c | 31 +++++++++++++++++++++++-- drivers/platform/chrome/cros_ec_typec.h | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index a57053bdec18..57d1484ce1ef 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -639,6 +639,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, struct ec_response_usb_pd_control_v2 *pd_ctrl) { struct cros_typec_port *port = typec->ports[port_num]; + bool has_dp_bridge = !!typec->dp_bridge; struct ec_response_usb_pd_mux_info resp; struct ec_params_usb_pd_mux_info req = { .port = port_num, @@ -646,6 +647,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *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; ret = cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req, sizeof(req), &resp, sizeof(resp)); @@ -659,6 +661,25 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, if (port->mux_flags == resp.flags && port->role == pd_ctrl->role) return 0; + dp_enabled = resp.flags & USB_PD_MUX_DP_ENABLED; + hpd_asserted = 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 (has_dp_bridge && hpd_asserted && !typec->active_dp_port) + typec->active_dp_port = port; + + /* + * Skip calling cros_typec_enable_dp() for the non-active type-c port + * when muxing one DP to multiple type-c ports. This is only the case + * on platforms using a drm_bridge. + */ + is_active_port = !has_dp_bridge || typec->active_dp_port == port; + port->mux_flags = resp.flags; port->role = pd_ctrl->role; @@ -686,8 +707,11 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl); - } else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) { - ret = cros_typec_enable_dp(typec, port_num, pd_ctrl); + } else if (dp_enabled) { + ret = 0; + /* Ignore DP events for the non-active port */ + if (is_active_port) + ret = cros_typec_enable_dp(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) { ret = cros_typec_usb_safe_state(port); } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) { @@ -704,6 +728,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, } mux_ack: + if (has_dp_bridge && !dp_enabled && is_active_port) + typec->active_dp_port = NULL; + if (!typec->needs_mux_ack) return ret; diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chrome/cros_ec_typec.h index eb816d30d880..f3a2b67df07c 100644 --- a/drivers/platform/chrome/cros_ec_typec.h +++ b/drivers/platform/chrome/cros_ec_typec.h @@ -36,6 +36,7 @@ struct cros_typec_data { /* Array of ports, indexed by port number. */ struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; struct drm_dp_typec_bridge_dev *dp_bridge; + struct cros_typec_port *active_dp_port; struct notifier_block nb; struct work_struct port_work; bool typec_cmd_supported; From patchwork Sun Sep 1 04:06:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13786324 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (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 038CC16ABC6 for ; Sun, 1 Sep 2024 04:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163665; cv=none; b=mtY/mDHlvfmiU0BSUvsL2YV6pI461qho2hs4uDj1bdHVelVOKx76UfdM1eTsBPj1xQINU15Z6FQHP0W4Sx6DVMTXbAJgPdTbUlcwar4cVq7Pl2vSivd2sqQ55B7P1bxhVwtEtyO/eRqS8VT1Vz8AwbXznC2KMDOSndfuTGin8YU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725163665; c=relaxed/simple; bh=P5j7Fr9LGu/zW4lsyx25BQTDaO9/OJeLxNTA5aeJAcw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bNxMoqIBc7uVY2tMDQtrHEU6dap+k++5QyXvAiHR1GWTS3SsOKe1ZyPmKlZztvOlKOrkpI5haHYwSA7ONXeyXGHl0Q89IV9zoz5YjA8w06+PZHNkVQbEdonOx9LA+/WmEk4uCop/oUiER3fU3SyLpYe/Mrt+Dyvqub5o2m5ld4M= 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=ee6LlgHa; arc=none smtp.client-ip=209.85.160.48 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="ee6LlgHa" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-27051f63018so2105316fac.3 for ; Sat, 31 Aug 2024 21:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725163660; x=1725768460; 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=YAnr/CInUuanIGWaUDroB3xFD+9prT3yLYHDcJ6D0Bo=; b=ee6LlgHaGVqQRT8JyDtXEOZvOfyLA0jJVUjmnBFK6A9W2slezUpeL06d7pwIc2Pba8 kl9w9ZDiOawTFfPRoyDGiq1ojlWyMV91zkuLYi03gkwlzmCAz7ob55upzZbnF1+fT25q n7/bFUWfyAOqFU/EldPqXJcBhl4CyhHBBnJXA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725163660; x=1725768460; 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=YAnr/CInUuanIGWaUDroB3xFD+9prT3yLYHDcJ6D0Bo=; b=kj6xoqRhIRLgaaOvxm72eYWOsaFtOdM4zptnxSM4msAIMEYCDbnt/SursHawbpvsCg WZvJ7dwOB2lrSohrYilHi8hVzn9j+5/6PcWsn876s9hx1wnK/zf6nisT5ck3iKpmTFBW 2AmcJxDZe+eGk4Y6jnYeGq1PkdMEw61C2k3IUo/yiKZBPzRJj7WiklT7wmS6BaQtZ9V3 hIqnwWAGhfZNxROUnr1Umn7eaTX/ert1d3Mr40Y5XWA0dmiknYeND/0Xyqu/uTp7ZzJb SRV2j59lDK2GYb+t0u7Q0F7pZ4tejayjmNcnel86q2gvueTSCrDCB5isWmWdU1lhMqKW C2mQ== X-Forwarded-Encrypted: i=1; AJvYcCVi3uDqYF6o5+jxiL0BN3xF5NMxXuKmMvYKD+v8Lql6NEJzEkqk0qVKAG8BK8Ft2vkPwsY4Ckw34CA=@vger.kernel.org X-Gm-Message-State: AOJu0YyU+B+qElmdrXPyyincn9hTfRtxwxYSZD6CtPfu5Ebp2MVxFddc 0OPLgz/PnUoWVwU3tb1tmLnCUgS4kYySIR1DIYaC5cfLA45ololSoNwl6sDk8w== X-Google-Smtp-Source: AGHT+IEJat/MH0aH5PxrzEOzEVWfG27VMiaK42He6BskeDGxOOCnFMowYgglO9wA7c39ubb74K4njg== X-Received: by 2002:a05:6870:c14c:b0:25e:d62:f297 with SMTP id 586e51a60fabf-277d06c6446mr3278885fac.45.1725163660389; Sat, 31 Aug 2024 21:07:40 -0700 (PDT) Received: from localhost (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-715e55aa11fsm4854824b3a.85.2024.08.31.21.07.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 31 Aug 2024 21:07:40 -0700 (PDT) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andrzej Hajda , Benson Leung , Conor Dooley , Daniel Vetter , David Airlie , Dmitry Baryshkov , dri-devel@lists.freedesktop.org, Guenter Roeck , Jernej Skrabec , Jonas Karlman , Krzysztof Kozlowski , Laurent Pinchart , Lee Jones , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Prashant Malani , Robert Foss , Rob Herring , Thomas Zimmermann , Tzung-Bi Shih , Alexandre Belloni , Andy Shevchenko , Daniel Scally , Greg Kroah-Hartman , Heikki Krogerus , Ivan Orlov , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, Mika Westerberg , "Rafael J . Wysocki" , Sakari Ailus , Vinod Koul Subject: [PATCH v4 18/18] platform/chrome: cros_ec_typec: Handle lack of HPD information Date: Sat, 31 Aug 2024 21:06:56 -0700 Message-ID: <20240901040658.157425-19-swboyd@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240901040658.157425-1-swboyd@chromium.org> References: <20240901040658.157425-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 74 +++++++++++++++++++++++++ drivers/platform/chrome/cros_ec_typec.h | 2 + 2 files changed, 76 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 57d1484ce1ef..731b485634af 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -423,6 +424,17 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) return ret; } +static void cros_typec_dp_bridge_hpd_notify(void *data, enum drm_connector_status status) +{ + struct cros_typec_data *typec = data; + + /* Proxy the connector status as the HPD state to replay later. */ + typec->hpd_asserted = status == 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 = typec->dev; @@ -432,9 +444,17 @@ static int cros_typec_init_dp_bridge(struct cros_typec_data *typec) if (!fwnode_property_read_bool(dev_fwnode(dev), "mode-switch")) return 0; + typec->mux_gpio = devm_gpiod_get_optional(dev, "mux", GPIOD_ASIS); + if (IS_ERR(typec->mux_gpio)) + return dev_err_probe(dev, PTR_ERR(typec->mux_gpio), "failed to get mux gpio\n"); + dp_dev = 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_notify, typec); + typec->dp_bridge = dp_dev; return devm_drm_dp_typec_bridge_add(dev, dp_dev); @@ -635,6 +655,59 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec, return typec_mux_set(port->mux, &port->state); } +/* + * Some ECs don't notify AP when HPD goes high or low because their firmware is + * broken. Capture the state of HPD in cros_typec_dp_bridge_hpd_notify() and + * inject the asserted state into the EC's response (deasserted is the + * default). + */ +static void cros_typec_inject_hpd(struct cros_typec_data *typec, + struct ec_response_usb_pd_mux_info *resp, + struct cros_typec_port *port) +{ + struct gpio_desc *mux_gpio = typec->mux_gpio; + int val; + + /* Never registered a drm_bridge. Skip. */ + if (!typec->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 (!typec->hpd_asserted) + 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 (!typec->active_dp_port) { + if (mux_gpio) { + val = gpiod_get_value_cansleep(mux_gpio); + if (val < 0) { + dev_err(typec->dev, "Failed to read mux gpio\n"); + return; + } + /* Ignore HPD changes for non-active port. */ + if (typec->ports[val] != port) + return; + } + } else if (port != typec->active_dp_port) { + /* Ignore HPD changes for non-active port. */ + return; + } + + /* Inject HPD from the GPIO state if EC firmware is broken. */ + if (typec->hpd_asserted) + resp->flags |= USB_PD_MUX_HPD_LVL; +} + static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, struct ec_response_usb_pd_control_v2 *pd_ctrl) { @@ -656,6 +729,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, port_num, ret); return ret; } + cros_typec_inject_hpd(typec, &resp, port); /* No change needs to be made, let's exit early. */ if (port->mux_flags == resp.flags && port->role == pd_ctrl->role) diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chrome/cros_ec_typec.h index f3a2b67df07c..4ccd3d014aa6 100644 --- a/drivers/platform/chrome/cros_ec_typec.h +++ b/drivers/platform/chrome/cros_ec_typec.h @@ -37,6 +37,8 @@ struct cros_typec_data { struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; struct drm_dp_typec_bridge_dev *dp_bridge; struct cros_typec_port *active_dp_port; + struct gpio_desc *mux_gpio; + bool hpd_asserted; struct notifier_block nb; struct work_struct port_work; bool typec_cmd_supported;