Re: [PATCH 11/11] drm/bridge: tc358768: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support

From: Sam Ravnborg
Date: Mon Aug 14 2023 - 06:12:00 EST


Hi Tomi,

> From c13c691bd8826b978325575be9a87f577b83b86b Mon Sep 17 00:00:00 2001
> From: Tomi Valkeinen <tomi.valkeinen@xxxxxxxxxxxxxxxx>
> Date: Mon, 14 Aug 2023 13:02:23 +0300
> Subject: [PATCH] drm/bridge: tc358768: fix 'Add DRM_BRIDGE_ATTACH_NO_CONNECTOR
> support'
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@xxxxxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/bridge/tc358768.c | 56 +++++++++++++------------------
> 1 file changed, 24 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c
> index 82ea4d9a814a..9705ce1bd028 100644
> --- a/drivers/gpu/drm/bridge/tc358768.c
> +++ b/drivers/gpu/drm/bridge/tc358768.c
> @@ -455,8 +455,6 @@ static int tc358768_dsi_host_detach(struct mipi_dsi_host *host,
> struct tc358768_priv *priv = dsi_host_to_tc358768(host);
>
> drm_bridge_remove(&priv->bridge);
> - if (priv->output.panel)
> - drm_panel_bridge_remove(priv->output.next_bridge);
>
> return 0;
> }
> @@ -531,49 +529,42 @@ static int tc358768_bridge_attach(struct drm_bridge *bridge,
> enum drm_bridge_attach_flags flags)
> {
> struct tc358768_priv *priv = bridge_to_tc358768(bridge);
> + struct drm_bridge *next_bridge;
> + struct drm_panel *panel;
> + int ret;
>
> if (!drm_core_check_feature(bridge->dev, DRIVER_ATOMIC)) {
> dev_err(priv->dev, "needs atomic updates support\n");
> return -ENOTSUPP;
> }
>
> - if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
> - struct device_node *node;
> -
> - /* Get the next bridge, connected to port@1. */
> - node = of_graph_get_remote_node(priv->dev->of_node, 1, -1);
> - if (!node)
> - return -ENODEV;
> -
> - priv->output.next_bridge = of_drm_find_bridge(node);
> - of_node_put(node);
> - if (!priv->output.next_bridge)
> - return -EPROBE_DEFER;
> - } else {
> - struct drm_bridge *bridge;
> - struct drm_panel *panel;
> - int ret;
> -
> - ret = drm_of_find_panel_or_bridge(priv->dev->of_node, 1, 0,
> - &panel, &bridge);
> - if (ret)
> - return ret;
> -
> - if (panel) {
> - bridge = drm_panel_bridge_add_typed(panel,
> - DRM_MODE_CONNECTOR_DSI);
> - if (IS_ERR(bridge))
> - return PTR_ERR(bridge);
> - }
> + ret = drm_of_find_panel_or_bridge(priv->dev->of_node, 1, -1, &panel,
> + &next_bridge);

I think the right way is to wrap the panel in a bridge,
so something like:

next_bridge = devm_drm_of_get_bridge(dev, priv->dev->of_node, 1, -1)

if (IS_ERR(next_bridge))
return ...
priv->output.next_bridge = next_bridge;


Sam


> + if (ret)
> + return ret;
>
> - priv->output.next_bridge = bridge;
> - priv->output.panel = panel;
> + if (panel) {
> + next_bridge = drm_panel_bridge_add_typed(panel,
> + DRM_MODE_CONNECTOR_DSI);
> + if (IS_ERR(next_bridge))
> + return PTR_ERR(next_bridge);
> }
>
> + priv->output.next_bridge = next_bridge;
> + priv->output.panel = panel;
> +
> return drm_bridge_attach(bridge->encoder, priv->output.next_bridge, bridge,
> flags);
> }
>
> +void tc358768_bridge_detach(struct drm_bridge *bridge)
> +{
> + struct tc358768_priv *priv = bridge_to_tc358768(bridge);
> +
> + if (priv->output.panel)
> + drm_panel_bridge_remove(priv->output.next_bridge);
> +}
> +
> static enum drm_mode_status
> tc358768_bridge_mode_valid(struct drm_bridge *bridge,
> const struct drm_display_info *info,
> @@ -1156,6 +1147,7 @@ tc358768_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
>
> static const struct drm_bridge_funcs tc358768_bridge_funcs = {
> .attach = tc358768_bridge_attach,
> + .detach = tc358768_bridge_detach,
> .mode_valid = tc358768_bridge_mode_valid,
> .pre_enable = tc358768_bridge_pre_enable,
> .enable = tc358768_bridge_enable,
> --
> 2.34.1
>