dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Andrzej Hajda <a.hajda@samsung.com>
Cc: Jernej Skrabec <jernej.skrabec@siol.net>,
	Martyn Welch <martyn.welch@collabora.co.uk>,
	Jonas Karlman <jonas@kwiboo.se>,
	Peter Senna Tschudin <peter.senna@gmail.com>,
	dri-devel@lists.freedesktop.org,
	Neil Armstrong <narmstrong@baylibre.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Martin Donnelly <martin.donnelly@ge.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	kbuild test robot <lkp@intel.com>
Subject: Re: [PATCH v4 04/15] drm/bridge: tc358764: add drm_panel_bridge support
Date: Thu, 3 Sep 2020 12:59:32 +0300	[thread overview]
Message-ID: <20200903095932.GC6492@pendragon.ideasonboard.com> (raw)
In-Reply-To: <cebb8200-db9e-5c3f-6808-f4e8068e4eeb@samsung.com>

Hi Andrzej,

On Thu, Sep 03, 2020 at 11:40:58AM +0200, Andrzej Hajda wrote:
> On 26.07.2020 22:33, Sam Ravnborg wrote:
> > Prepare the tc358764 bridge driver for use in a chained setup by
> > replacing direct use of drm_panel with drm_panel_bridge support.
> >
> > The bridge panel will use the connector type reported by the panel,
> > where the connector for this driver hardcodes DRM_MODE_CONNECTOR_LVDS.
> >
> > The tc358764 did not any additional info the the connector so the
> > connector creation is passed to the bridge panel driver.
> >
> > v3:
> >    - Merge with patch to make connector creation optional to avoid
> >      creating two connectors (Laurent)
> >    - Pass connector creation to bridge panel, as this bridge driver
> >      did not add any extra info to the connector.
> >    - Set bridge.type to DRM_MODE_CONNECTOR_LVDS.
> >
> > v2:
> >    - Use PTR_ERR_OR_ZERO() (kbuild test robot)
> >
> > Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Cc: kbuild test robot <lkp@intel.com>
> > Cc: Andrzej Hajda <a.hajda@samsung.com>
> > Cc: Neil Armstrong <narmstrong@baylibre.com>
> > Cc: Jonas Karlman <jonas@kwiboo.se>
> > Cc: Jernej Skrabec <jernej.skrabec@siol.net>
> > ---
> >   drivers/gpu/drm/bridge/tc358764.c | 107 +++++-------------------------
> >   1 file changed, 16 insertions(+), 91 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/tc358764.c b/drivers/gpu/drm/bridge/tc358764.c
> > index a277739fab58..fdde4cfdc724 100644
> > --- a/drivers/gpu/drm/bridge/tc358764.c
> > +++ b/drivers/gpu/drm/bridge/tc358764.c
> > @@ -153,10 +153,9 @@ static const char * const tc358764_supplies[] = {
> >   struct tc358764 {
> >   	struct device *dev;
> >   	struct drm_bridge bridge;
> > -	struct drm_connector connector;
> >   	struct regulator_bulk_data supplies[ARRAY_SIZE(tc358764_supplies)];
> >   	struct gpio_desc *gpio_reset;
> > -	struct drm_panel *panel;
> > +	struct drm_bridge *panel_bridge;
> >   	int error;
> >   };
> >   
> > @@ -210,12 +209,6 @@ static inline struct tc358764 *bridge_to_tc358764(struct drm_bridge *bridge)
> >   	return container_of(bridge, struct tc358764, bridge);
> >   }
> >   
> > -static inline
> > -struct tc358764 *connector_to_tc358764(struct drm_connector *connector)
> > -{
> > -	return container_of(connector, struct tc358764, connector);
> > -}
> > -
> >   static int tc358764_init(struct tc358764 *ctx)
> >   {
> >   	u32 v = 0;
> > @@ -278,43 +271,11 @@ static void tc358764_reset(struct tc358764 *ctx)
> >   	usleep_range(1000, 2000);
> >   }
> >   
> > -static int tc358764_get_modes(struct drm_connector *connector)
> > -{
> > -	struct tc358764 *ctx = connector_to_tc358764(connector);
> > -
> > -	return drm_panel_get_modes(ctx->panel, connector);
> > -}
> > -
> > -static const
> > -struct drm_connector_helper_funcs tc358764_connector_helper_funcs = {
> > -	.get_modes = tc358764_get_modes,
> > -};
> > -
> > -static const struct drm_connector_funcs tc358764_connector_funcs = {
> > -	.fill_modes = drm_helper_probe_single_connector_modes,
> > -	.destroy = drm_connector_cleanup,
> > -	.reset = drm_atomic_helper_connector_reset,
> > -	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> > -	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> > -};
> > -
> > -static void tc358764_disable(struct drm_bridge *bridge)
> > -{
> > -	struct tc358764 *ctx = bridge_to_tc358764(bridge);
> > -	int ret = drm_panel_disable(bridge_to_tc358764(bridge)->panel);
> > -
> > -	if (ret < 0)
> > -		dev_err(ctx->dev, "error disabling panel (%d)\n", ret);
> > -}
> > -
> >   static void tc358764_post_disable(struct drm_bridge *bridge)
> >   {
> >   	struct tc358764 *ctx = bridge_to_tc358764(bridge);
> >   	int ret;
> >   
> > -	ret = drm_panel_unprepare(ctx->panel);
> > -	if (ret < 0)
> > -		dev_err(ctx->dev, "error unpreparing panel (%d)\n", ret);
> 
> 
> Using this bridge_panel thing you reverse order of hw 
> initialization/de-initialization, this is incorrect.
> 
> For example:
> 
> - panel_unprepare should be called before tc35* turn off,
> 
> - panel_prepare should be called after tc35* on.
> 
> This is why I avoid the whole "bridge chaining" - it enforces ridiculous 
> order of initialization.
> 
> 
> >   	tc358764_reset(ctx);
> >   	usleep_range(10000, 15000);
> >   	ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
> > @@ -335,70 +296,28 @@ static void tc358764_pre_enable(struct drm_bridge *bridge)
> >   	ret = tc358764_init(ctx);
> >   	if (ret < 0)
> >   		dev_err(ctx->dev, "error initializing bridge (%d)\n", ret);
> > -	ret = drm_panel_prepare(ctx->panel);
> > -	if (ret < 0)
> > -		dev_err(ctx->dev, "error preparing panel (%d)\n", ret);
> > -}
> > -
> > -static void tc358764_enable(struct drm_bridge *bridge)
> > -{
> > -	struct tc358764 *ctx = bridge_to_tc358764(bridge);
> > -	int ret = drm_panel_enable(ctx->panel);
> > -
> > -	if (ret < 0)
> > -		dev_err(ctx->dev, "error enabling panel (%d)\n", ret);
> >   }
> >   
> >   static int tc358764_attach(struct drm_bridge *bridge,
> >   			   enum drm_bridge_attach_flags flags)
> > -{
> > -	struct tc358764 *ctx = bridge_to_tc358764(bridge);
> > -	struct drm_device *drm = bridge->dev;
> > -	int ret;
> > -
> > -	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
> > -		DRM_ERROR("Fix bridge driver to make connector optional!");
> > -		return -EINVAL;
> > -	}
> > -
> > -	ctx->connector.polled = DRM_CONNECTOR_POLL_HPD;
> > -	ret = drm_connector_init(drm, &ctx->connector,
> > -				 &tc358764_connector_funcs,
> > -				 DRM_MODE_CONNECTOR_LVDS);
> > -	if (ret) {
> > -		DRM_ERROR("Failed to initialize connector\n");
> > -		return ret;
> > -	}
> > -
> > -	drm_connector_helper_add(&ctx->connector,
> > -				 &tc358764_connector_helper_funcs);
> > -	drm_connector_attach_encoder(&ctx->connector, bridge->encoder);
> > -	drm_panel_attach(ctx->panel, &ctx->connector);
> > -	ctx->connector.funcs->reset(&ctx->connector);
> 
> 
> I guess lack of calling .reset here is direct cause of WARN reported by 
> Marek.
> 
> 
> Summarizing my findings:
> 
> 1. drm_panel_bridge does not fit to this scenario - it relays on 'bridge 
> chaining" which has crazy assumption that order of hw initalization in 
> the display chain follows the same fixed order of calls for all hw.

This would need to be addressed in the bridge core. I don't want to go
back to manual chaining of operations, that opens the door to creating
incompatibilities between bridges and display controllers. The pre/post
enable/disable operations probably need to be better defined, and if a
sink requires a smaller granularity, then new operations need to be
added.

> 2. tc35* bridge allocates/deallocates connector dynamically - to safely 
> handle drivers load/unload, and to avoid multiple deferred probe issues 
> , drm_panel_bridge does not support it.
> 
> This and previous patch violates both points.
> 
> > -
> > -	return 0;
> > -}
> > -
> > -static void tc358764_detach(struct drm_bridge *bridge)
> >   {
> >   	struct tc358764 *ctx = bridge_to_tc358764(bridge);
> >   
> > -	drm_panel_detach(ctx->panel);
> > -	ctx->panel = NULL;
> > +	return drm_bridge_attach(bridge->encoder, ctx->panel_bridge,
> > +				 bridge, flags);
> >   }
> >   
> >   static const struct drm_bridge_funcs tc358764_bridge_funcs = {
> > -	.disable = tc358764_disable,
> >   	.post_disable = tc358764_post_disable,
> > -	.enable = tc358764_enable,
> >   	.pre_enable = tc358764_pre_enable,
> >   	.attach = tc358764_attach,
> > -	.detach = tc358764_detach,
> >   };
> >   
> >   static int tc358764_parse_dt(struct tc358764 *ctx)
> >   {
> > +	struct drm_bridge *panel_bridge;
> >   	struct device *dev = ctx->dev;
> > +	struct drm_panel *panel;
> >   	int ret;
> >   
> >   	ctx->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
> > @@ -407,12 +326,17 @@ static int tc358764_parse_dt(struct tc358764 *ctx)
> >   		return PTR_ERR(ctx->gpio_reset);
> >   	}
> >   
> > -	ret = drm_of_find_panel_or_bridge(ctx->dev->of_node, 1, 0, &ctx->panel,
> > -					  NULL);
> > -	if (ret && ret != -EPROBE_DEFER)
> > -		dev_err(dev, "cannot find panel (%d)\n", ret);
> > +	ret = drm_of_find_panel_or_bridge(dev->of_node, 1, 0, &panel, NULL);
> > +	if (ret)
> > +		return ret;
> >   
> > -	return ret;
> > +	panel_bridge = devm_drm_panel_bridge_add(dev, panel);
> > +
> > +	if (IS_ERR(panel_bridge))
> > +		return PTR_ERR(panel_bridge);
> > +
> > +	ctx->panel_bridge = panel_bridge;
> > +	return 0;
> >   }
> >   
> >   static int tc358764_configure_regulators(struct tc358764 *ctx)
> > @@ -458,6 +382,7 @@ static int tc358764_probe(struct mipi_dsi_device *dsi)
> >   		return ret;
> >   
> >   	ctx->bridge.funcs = &tc358764_bridge_funcs;
> > +	ctx->bridge.type = DRM_MODE_CONNECTOR_LVDS;
> >   	ctx->bridge.of_node = dev->of_node;
> >   
> >   	drm_bridge_add(&ctx->bridge);

-- 
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-09-03  9:59 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-26 20:33 [PATCH v4 0/15] drm/bridge: support chained bridges + panel updates Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 01/15] drm/panel: panel-simple: validate panel description Sam Ravnborg
2020-07-26 21:24   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 02/15] drm/panel: panel-simple: add default connector_type Sam Ravnborg
2020-07-26 21:26   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 03/15] drm/bridge: tc358764: drop drm_connector_(un)register Sam Ravnborg
2020-09-02 16:48   ` Andrzej Hajda
2020-07-26 20:33 ` [PATCH v4 04/15] drm/bridge: tc358764: add drm_panel_bridge support Sam Ravnborg
2020-07-26 21:37   ` Laurent Pinchart
2020-08-27 11:39   ` [v4,04/15] " Marek Szyprowski
2020-08-30 20:42     ` Sam Ravnborg
2020-09-03  6:20       ` Andrzej Hajda
2020-09-03  9:40   ` [PATCH v4 04/15] " Andrzej Hajda
2020-09-03  9:59     ` Laurent Pinchart [this message]
2020-09-03 15:10       ` Andrzej Hajda
2020-07-26 20:33 ` [PATCH v4 05/15] drm/bridge: tc358767: add detect bridge operation Sam Ravnborg
2020-07-26 21:27   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 06/15] drm/bridge: tc358767: add get_edid " Sam Ravnborg
2020-07-26 21:40   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 07/15] drm/bridge: tc358767: add drm_panel_bridge support Sam Ravnborg
2020-07-26 21:48   ` Laurent Pinchart
2020-07-27  7:22     ` Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 08/15] drm/bridge: parade-ps8622: " Sam Ravnborg
2020-07-26 21:54   ` Laurent Pinchart
2020-07-27 15:23     ` Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 09/15] drm/bridge: megachips: add helper to create connector Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 10/15] drm/bridge: megachips: get drm_device from bridge Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 11/15] drm/bridge: megachips: enable detect bridge operation Sam Ravnborg
2020-07-26 20:33 ` [PATCH v4 12/15] drm/bridge: megachips: add get_edid " Sam Ravnborg
2020-07-26 21:57   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 13/15] drm/bridge: megachips: make connector creation optional Sam Ravnborg
2020-07-26 21:59   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 14/15] drm/bridge: nxp-ptn3460: add get_edid bridge operation Sam Ravnborg
2020-07-26 22:00   ` Laurent Pinchart
2020-07-26 20:33 ` [PATCH v4 15/15] drm/bridge: nxp-ptn3460: add drm_panel_bridge support Sam Ravnborg
2020-07-26 22:05   ` Laurent Pinchart
2020-07-27 16:56 ` [PATCH v4 0/15] drm/bridge: support chained bridges + panel updates Sam Ravnborg

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=20200903095932.GC6492@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=lkp@intel.com \
    --cc=martin.donnelly@ge.com \
    --cc=martyn.welch@collabora.co.uk \
    --cc=narmstrong@baylibre.com \
    --cc=peter.senna@gmail.com \
    --cc=sam@ravnborg.org \
    --cc=thierry.reding@gmail.com \
    /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