From: Luca Ceresoli <luca.ceresoli@bootlin.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Jagan Teki <jagan@amarulasolutions.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Douglas Anderson <dianders@chromium.org>,
Chun-Kuang Hu <chunkuang.hu@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>
Cc: Anusha Srivatsa <asrivats@redhat.com>,
Paul Kocialkowski <paulk@sys-base.io>,
Dmitry Baryshkov <lumag@kernel.org>,
Hui Pu <Hui.Pu@gehealthcare.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
dri-devel@lists.freedesktop.org, asahi@lists.linux.dev,
linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-amlogic@lists.infradead.org,
linux-renesas-soc@vger.kernel.org,
platform-driver-x86@vger.kernel.org,
linux-samsung-soc@vger.kernel.org,
linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
linux-stm32@st-md-mailman.stormreply.com,
Luca Ceresoli <luca.ceresoli@bootlin.com>
Subject: [PATCH v3 19/22] drm/bridge: tc358767: convert to devm_drm_bridge_alloc() API
Date: Fri, 09 May 2025 15:53:45 +0200 [thread overview]
Message-ID: <20250509-drm-bridge-convert-to-alloc-api-v3-19-b8bc1f16d7aa@bootlin.com> (raw)
In-Reply-To: <20250509-drm-bridge-convert-to-alloc-api-v3-0-b8bc1f16d7aa@bootlin.com>
This is the new API for allocating DRM bridges.
Converting this driver is a bit convoluted because the drm_bridge funcs
pointer differs based on the bridge mode. So the current code does:
* tc_probe()
* devm_kzalloc() private struct embedding drm_bridge
* call tc_probe_bridge_endpoint() which
* parses DT description into struct fields
* computes the mode
* calls different bridge init functions based on the mode
* each sets a different bridge.funcs pointer
The new API expects the funcs pointer to be known at alloc time, which does
not fit in the current code structure.
Solve this by moving the part of tc_probe_bridge_endpoint() computing the
mode into a separate function, tc_probe_get_mode(), which does not need the
private driver structure. So now the mode is known before allocation and so
is the funcs pointer, while all other operations are still happening after
allocation, directly into the private struct data, as they used to.
This solution is chosen to minimize the changes in the driver logical code
flow. The drawback is we now iterate twice over the endpoints.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/tc358767.c | 56 ++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
index 7e5449fb86a3fcdae8255bc490d12c543ef3f8ae..61559467e2d22b4b1b4223c97766ca3bf58908fd 100644
--- a/drivers/gpu/drm/bridge/tc358767.c
+++ b/drivers/gpu/drm/bridge/tc358767.c
@@ -344,6 +344,14 @@
#define COLOR_BAR_MODE_BARS 2
#define PLL_DBG 0x0a04
+enum tc_mode {
+ mode_dpi_to_edp = BIT(1) | BIT(2),
+ mode_dpi_to_dp = BIT(1),
+ mode_dsi_to_edp = BIT(0) | BIT(2),
+ mode_dsi_to_dp = BIT(0),
+ mode_dsi_to_dpi = BIT(0) | BIT(1),
+};
+
static bool tc_test_pattern;
module_param_named(test, tc_test_pattern, bool, 0644);
@@ -2327,7 +2335,6 @@ static int tc_probe_dpi_bridge_endpoint(struct tc_data *tc)
if (bridge) {
tc->panel_bridge = bridge;
tc->bridge.type = DRM_MODE_CONNECTOR_DPI;
- tc->bridge.funcs = &tc_dpi_bridge_funcs;
return 0;
}
@@ -2360,7 +2367,6 @@ static int tc_probe_edp_bridge_endpoint(struct tc_data *tc)
tc->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
}
- tc->bridge.funcs = &tc_edp_bridge_funcs;
if (tc->hpd_pin >= 0)
tc->bridge.ops |= DRM_BRIDGE_OP_DETECT;
tc->bridge.ops |= DRM_BRIDGE_OP_EDID;
@@ -2368,17 +2374,11 @@ static int tc_probe_edp_bridge_endpoint(struct tc_data *tc)
return 0;
}
-static int tc_probe_bridge_endpoint(struct tc_data *tc)
+static enum tc_mode tc_probe_get_mode(struct device *dev)
{
- struct device *dev = tc->dev;
struct of_endpoint endpoint;
struct device_node *node = NULL;
- const u8 mode_dpi_to_edp = BIT(1) | BIT(2);
- const u8 mode_dpi_to_dp = BIT(1);
- const u8 mode_dsi_to_edp = BIT(0) | BIT(2);
- const u8 mode_dsi_to_dp = BIT(0);
- const u8 mode_dsi_to_dpi = BIT(0) | BIT(1);
- u8 mode = 0;
+ enum tc_mode mode = 0;
/*
* Determine bridge configuration.
@@ -2401,7 +2401,27 @@ static int tc_probe_bridge_endpoint(struct tc_data *tc)
return -EINVAL;
}
mode |= BIT(endpoint.port);
+ }
+
+ if (mode != mode_dpi_to_edp &&
+ mode != mode_dpi_to_dp &&
+ mode != mode_dsi_to_dpi &&
+ mode != mode_dsi_to_edp &&
+ mode != mode_dsi_to_dp) {
+ dev_warn(dev, "Invalid mode (0x%x) is not supported!\n", mode);
+ return -EINVAL;
+ }
+
+ return mode;
+}
+static int tc_probe_bridge_endpoint(struct tc_data *tc, enum tc_mode mode)
+{
+ struct device *dev = tc->dev;
+ struct of_endpoint endpoint;
+ struct device_node *node = NULL;
+
+ for_each_endpoint_of_node(dev->of_node, node) {
if (endpoint.port == 2) {
of_property_read_u8_array(node, "toshiba,pre-emphasis",
tc->pre_emphasis,
@@ -2427,24 +2447,28 @@ static int tc_probe_bridge_endpoint(struct tc_data *tc)
return tc_probe_edp_bridge_endpoint(tc);
}
- dev_warn(dev, "Invalid mode (0x%x) is not supported!\n", mode);
-
+ /* Should never happen, mode was validated by tc_probe_get_mode() */
return -EINVAL;
}
static int tc_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
+ const struct drm_bridge_funcs *funcs;
struct tc_data *tc;
+ int mode;
int ret;
- tc = devm_kzalloc(dev, sizeof(*tc), GFP_KERNEL);
- if (!tc)
- return -ENOMEM;
+ mode = tc_probe_get_mode(dev);
+ funcs = (mode == mode_dsi_to_dpi) ? &tc_dpi_bridge_funcs : &tc_edp_bridge_funcs;
+
+ tc = devm_drm_bridge_alloc(dev, struct tc_data, bridge, funcs);
+ if (IS_ERR(tc))
+ return PTR_ERR(tc);
tc->dev = dev;
- ret = tc_probe_bridge_endpoint(tc);
+ ret = tc_probe_bridge_endpoint(tc, mode);
if (ret)
return ret;
--
2.49.0
next prev parent reply other threads:[~2025-05-09 13:57 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 13:53 [PATCH v3 00/22] drm: convert all bridges to devm_drm_bridge_alloc() Luca Ceresoli
2025-05-09 13:53 ` [PATCH v3 01/22] Revert "drm/exynos: mic: convert to devm_drm_bridge_alloc() API" Luca Ceresoli
2025-05-09 13:53 ` [PATCH v3 02/22] drm: convert many bridge drivers from devm_kzalloc() to devm_drm_bridge_alloc() API Luca Ceresoli
2025-05-10 8:43 ` Maxime Ripard
2025-05-25 19:40 ` Adam Ford
2025-05-27 9:27 ` Luca Ceresoli
2025-05-09 13:53 ` [PATCH v3 03/22] drm/bridge: anx7625: convert " Luca Ceresoli
2025-05-10 8:43 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 04/22] drm/bridge: cdns-dsi: " Luca Ceresoli
2025-05-10 8:44 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 05/22] drm/bridge: megachips-stdpxxxx-ge-b850v3-fw: " Luca Ceresoli
2025-05-10 8:52 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 06/22] drm/bridge: nxp-ptn3460: " Luca Ceresoli
2025-05-10 8:52 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 07/22] drm/bridge: sii902x: " Luca Ceresoli
2025-05-10 8:52 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 08/22] drm/omap: dss: dpi: " Luca Ceresoli
2025-05-10 8:54 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 09/22] drm/omap: dss: dsi: " Luca Ceresoli
2025-05-10 8:54 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 10/22] drm/omap: dss: hdmi4: " Luca Ceresoli
2025-05-10 8:54 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 11/22] drm/omap: dss: hdmi5: " Luca Ceresoli
2025-05-10 8:54 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 12/22] drm/omap: dss: sdi: " Luca Ceresoli
2025-05-10 8:58 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 13/22] drm/omap: dss: venc: " Luca Ceresoli
2025-05-10 8:55 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 14/22] drm/rcar-du: dsi: " Luca Ceresoli
2025-05-10 8:56 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 15/22] drm/bridge: stm_lvds: " Luca Ceresoli
2025-05-10 8:56 ` Maxime Ripard
2025-05-20 11:37 ` Raphael Gallais-Pou
2025-05-09 13:53 ` [PATCH v3 16/22] drm/sti: dvo: " Luca Ceresoli
2025-05-10 8:57 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 17/22] drm: zynqmp_dp: " Luca Ceresoli
2025-05-10 8:57 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 18/22] drm/bridge: imx8qxp-pixel-combiner: " Luca Ceresoli
2025-05-27 1:48 ` Liu Ying
2025-05-09 13:53 ` Luca Ceresoli [this message]
2025-05-09 13:53 ` [PATCH v3 20/22] drm/bridge: add devm_drm_put_bridge() Luca Ceresoli
2025-05-10 9:15 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 21/22] drm/bridge: panel: convert to devm_drm_bridge_alloc() API Luca Ceresoli
2025-05-10 9:42 ` Maxime Ripard
2025-05-09 13:53 ` [PATCH v3 22/22] drm/todo: add entry to remove devm_drm_put_bridge() Luca Ceresoli
2025-05-10 9:42 ` Maxime Ripard
2025-05-21 14:22 ` [PATCH v3 00/22] drm: convert all bridges to devm_drm_bridge_alloc() Luca Ceresoli
2025-05-22 3:20 ` Liu Ying
2025-05-22 7:28 ` Luca Ceresoli
2025-05-22 15:01 ` Maxime Ripard
2025-05-22 14:57 ` Maxime Ripard
2025-05-22 15:56 ` Luca Ceresoli
2025-05-22 15:11 ` Inki Dae
2025-05-23 13:23 ` Luca Ceresoli
2025-05-27 10:21 ` (subset) " Luca Ceresoli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250509-drm-bridge-convert-to-alloc-api-v3-19-b8bc1f16d7aa@bootlin.com \
--to=luca.ceresoli@bootlin.com \
--cc=Hui.Pu@gehealthcare.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=asahi@lists.linux.dev \
--cc=asrivats@redhat.com \
--cc=chrome-platform@lists.linux.dev \
--cc=chunkuang.hu@kernel.org \
--cc=dianders@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=freedreno@lists.freedesktop.org \
--cc=imx@lists.linux.dev \
--cc=jagan@amarulasolutions.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel@pengutronix.de \
--cc=krzk@kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=lumag@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=paulk@sys-base.io \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rfoss@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=simona@ffwll.ch \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).