linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] drm/panel: Make backlight attachment lazy
@ 2020-12-08  4:44 Bjorn Andersson
  2020-12-08  5:48 ` Sam Ravnborg
  2020-12-08 12:47 ` Thierry Reding
  0 siblings, 2 replies; 11+ messages in thread
From: Bjorn Andersson @ 2020-12-08  4:44 UTC (permalink / raw)
  To: Thierry Reding, Sam Ravnborg, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter
  Cc: dri-devel, linux-kernel

Some bridge chips, such as the TI SN65DSI86 DSI/eDP bridge, provides
means of generating a PWM signal for backlight control of the attached
panel. The provided PWM chip is typically controlled by the
pwm-backlight driver, which if tied to the panel will provide DPMS.

But with the current implementation the panel will refuse to probe
because the bridge driver has yet to probe and register the PWM chip,
and the bridge driver will refuse to probe because it's unable to find
the panel.

Mitigate this catch-22 situation by allowing the panel driver to probe
and retry the attachment of the backlight as the panel is turned on or
off.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/gpu/drm/drm_panel.c | 47 +++++++++++++++++++++++++++----------
 include/drm/drm_panel.h     |  8 +++++++
 2 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index f634371c717a..7487329bd22d 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -43,6 +43,34 @@ static LIST_HEAD(panel_list);
  * take look at drm_panel_bridge_add() and devm_drm_panel_bridge_add().
  */
 
+#if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
+static int drm_panel_of_backlight_lazy(struct drm_panel *panel)
+{
+	struct backlight_device *backlight;
+
+	if (!panel || !panel->dev)
+		return -EINVAL;
+
+	backlight = devm_of_find_backlight(panel->dev);
+
+	if (IS_ERR(backlight)) {
+		if (PTR_ERR(backlight) == -EPROBE_DEFER) {
+			panel->backlight_init_pending = true;
+			return 0;
+		}
+
+		return PTR_ERR(backlight);
+	}
+
+	panel->backlight = backlight;
+	panel->backlight_init_pending = false;
+
+	return 0;
+}
+#else
+static int drm_panel_of_backlight_lazy(struct drm_panel *panel) { return 0; }
+#endif
+
 /**
  * drm_panel_init - initialize a panel
  * @panel: DRM panel
@@ -161,6 +189,9 @@ int drm_panel_enable(struct drm_panel *panel)
 			return ret;
 	}
 
+	if (panel->backlight_init_pending)
+		drm_panel_of_backlight_lazy(panel);
+
 	ret = backlight_enable(panel->backlight);
 	if (ret < 0)
 		DRM_DEV_INFO(panel->dev, "failed to enable backlight: %d\n",
@@ -187,6 +218,9 @@ int drm_panel_disable(struct drm_panel *panel)
 	if (!panel)
 		return -EINVAL;
 
+	if (panel->backlight_init_pending)
+		drm_panel_of_backlight_lazy(panel);
+
 	ret = backlight_disable(panel->backlight);
 	if (ret < 0)
 		DRM_DEV_INFO(panel->dev, "failed to disable backlight: %d\n",
@@ -328,18 +362,7 @@ EXPORT_SYMBOL(of_drm_get_panel_orientation);
  */
 int drm_panel_of_backlight(struct drm_panel *panel)
 {
-	struct backlight_device *backlight;
-
-	if (!panel || !panel->dev)
-		return -EINVAL;
-
-	backlight = devm_of_find_backlight(panel->dev);
-
-	if (IS_ERR(backlight))
-		return PTR_ERR(backlight);
-
-	panel->backlight = backlight;
-	return 0;
+	return drm_panel_of_backlight_lazy(panel);
 }
 EXPORT_SYMBOL(drm_panel_of_backlight);
 #endif
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index 33605c3f0eba..b126abebb2f3 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -149,6 +149,14 @@ struct drm_panel {
 	 */
 	struct backlight_device *backlight;
 
+	/**
+	 * @backlight_init_pending
+	 *
+	 * Backlight driver is not yet available so further attempts to
+	 * initialize @backlight is necessary.
+	 */
+	bool backlight_init_pending;
+
 	/**
 	 * @funcs:
 	 *
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-12-10 17:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08  4:44 [RFC PATCH] drm/panel: Make backlight attachment lazy Bjorn Andersson
2020-12-08  5:48 ` Sam Ravnborg
2020-12-08 21:39   ` Bjorn Andersson
2020-12-08 12:47 ` Thierry Reding
2020-12-08 22:02   ` Bjorn Andersson
2020-12-08 23:52     ` Daniel Vetter
2020-12-09 20:28       ` Bjorn Andersson
2020-12-10 10:15         ` Daniel Vetter
2020-12-10 16:44           ` Thierry Reding
2020-12-10 16:50             ` Daniel Vetter
2020-12-10 17:18               ` Thierry Reding

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).