diff mbox series

[v2,3/5] drm/panel-simple: Retry if we timeout waiting for HPD

Message ID 20210115144345.v2.3.I6916959daa7c5c915e889442268d23338de17923@changeid (mailing list archive)
State New, archived
Headers show
Series drm/panel-simple: Patches for N116BCA-EA1 | expand

Commit Message

Doug Anderson Jan. 15, 2021, 10:44 p.m. UTC
On an Innolux N116BCA panel that I have in front of me, sometimes HPD
simply doesn't assert no matter how long you wait for it. As per the
very wise advice of The IT Crowd ("Have you tried turning it off and
on again?") it appears that power cycling is enough to kick this panel
back into a sane state.

From tests on this panel, it appears that leaving it powered off for a
while stimulates the problem. Adding a 6 second sleep at the start of
panel_simple_prepare_once() makes it happen fairly reliably and, with
this delay, I saw up to 3 retries needed sometimes. Without the 6
second sleep, however, the panel came up much more reliably the first
time or after only 1 retry.

While it's unknown what the problems are with this panel (and probably
the hardware should be debugged), adding a few retries to the power on
routine doesn't seem insane. Even if this panel's problems are
attributed to the fact that it's pre-production and/or can be fixed,
retries clearly can help in some cases and really don't hurt.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v2:
- ("drm/panel-simple: Retry if we timeout waiting for HPD") new for v2.

 drivers/gpu/drm/panel/panel-simple.c | 32 +++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

Comments

Stephen Boyd Jan. 25, 2021, 8:28 p.m. UTC | #1
Quoting Douglas Anderson (2021-01-15 14:44:18)
> On an Innolux N116BCA panel that I have in front of me, sometimes HPD
> simply doesn't assert no matter how long you wait for it. As per the
> very wise advice of The IT Crowd ("Have you tried turning it off and
> on again?") it appears that power cycling is enough to kick this panel
> back into a sane state.
> 
> From tests on this panel, it appears that leaving it powered off for a
> while stimulates the problem. Adding a 6 second sleep at the start of
> panel_simple_prepare_once() makes it happen fairly reliably and, with
> this delay, I saw up to 3 retries needed sometimes. Without the 6
> second sleep, however, the panel came up much more reliably the first
> time or after only 1 retry.
> 
> While it's unknown what the problems are with this panel (and probably
> the hardware should be debugged), adding a few retries to the power on
> routine doesn't seem insane. Even if this panel's problems are
> attributed to the fact that it's pre-production and/or can be fixed,
> retries clearly can help in some cases and really don't hurt.
> 
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

> @@ -440,6 +441,31 @@ static int panel_simple_prepare(struct drm_panel *panel)
>         return err;
>  }
>  
> +/*
> + * Some panels simply don't always come up and need to be power cycled to
> + * work properly.  We'll allow for a handful of retries.
> + */
> +#define MAX_PANEL_PREPARE_TRIES                5

Is this define used anywhere else? Feels like it would be better to
inline the constant and move the comment above the loop, but I guess
this is OK too.

> +
> +static int panel_simple_prepare(struct drm_panel *panel)
> +{
> +       int ret;
> +       int try;
> +
> +       for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
> +               ret = panel_simple_prepare_once(panel);
> +               if (ret != -ETIMEDOUT)
> +                       break;
> +       }
> +
> +       if (ret == -ETIMEDOUT)
> +               dev_err(panel->dev, "Prepare timeout after %d tries\n", try);
> +       else if (try)
> +               dev_warn(panel->dev, "Prepare needed %d retries\n", try);
> +
Doug Anderson Jan. 27, 2021, 9:11 p.m. UTC | #2
Hi,

On Mon, Jan 25, 2021 at 12:28 PM Stephen Boyd <swboyd@chromium.org> wrote:
>
> > +/*
> > + * Some panels simply don't always come up and need to be power cycled to
> > + * work properly.  We'll allow for a handful of retries.
> > + */
> > +#define MAX_PANEL_PREPARE_TRIES                5
>
> Is this define used anywhere else? Feels like it would be better to
> inline the constant and move the comment above the loop, but I guess
> this is OK too.

Hrm, usually I only add a #define like this when I need to use the
same number more than once, but I'm not doing that here.  Maybe I did
in an earlier version of the code and then didn't go back and remove
the #define when I reworked it?

Since this is a bit of a style issue, I will leave it to the
simple-panel maintainers to decide.  I'm happy to spin this and add
the comment before the loop and just hardcode "5" in the loop instead
of using MAX_PANEL_PREPARE_TRIES, so just let me know.

-Doug
diff mbox series

Patch

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 30842cf6d414..823177d89d1b 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -376,7 +376,7 @@  static int panel_simple_get_hpd_gpio(struct device *dev,
 	return 0;
 }
 
-static int panel_simple_prepare(struct drm_panel *panel)
+static int panel_simple_prepare_once(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
 	unsigned int delay;
@@ -422,8 +422,9 @@  static int panel_simple_prepare(struct drm_panel *panel)
 			err = hpd_asserted;
 
 		if (err) {
-			dev_err(panel->dev,
-				"error waiting for hpd GPIO: %d\n", err);
+			if (err != -ETIMEDOUT)
+				dev_err(panel->dev,
+					"error waiting for hpd GPIO: %d\n", err);
 			goto error;
 		}
 	}
@@ -440,6 +441,31 @@  static int panel_simple_prepare(struct drm_panel *panel)
 	return err;
 }
 
+/*
+ * Some panels simply don't always come up and need to be power cycled to
+ * work properly.  We'll allow for a handful of retries.
+ */
+#define MAX_PANEL_PREPARE_TRIES		5
+
+static int panel_simple_prepare(struct drm_panel *panel)
+{
+	int ret;
+	int try;
+
+	for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
+		ret = panel_simple_prepare_once(panel);
+		if (ret != -ETIMEDOUT)
+			break;
+	}
+
+	if (ret == -ETIMEDOUT)
+		dev_err(panel->dev, "Prepare timeout after %d tries\n", try);
+	else if (try)
+		dev_warn(panel->dev, "Prepare needed %d retries\n", try);
+
+	return ret;
+}
+
 static int panel_simple_enable(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);