[PATCH v4 3/5] drm: panel: simple: Allow specifying the delay from prepare to enable

From: Douglas Anderson
Date: Mon Nov 09 2020 - 20:01:36 EST


On the panel I'm looking at, there's an 80 ms minimum time between HPD
being asserted by the panel and setting the backlight enable GPIO.
While we could just add an 80 ms "enable" delay, this is not ideal.
Link training is allowed to happen in parallel with this delay so the
fixed 80 ms delay over-delays.

We'll support this by logging the time at the end of prepare and then
delaying in enable if enough time hasn't passed.

Signed-off-by: Douglas Anderson <dianders@xxxxxxxxxxxx>
---

Changes in v4:
- Split ("Allow timing constraints, not fixed delays") into 2 patches.
- Fixed kerneldoc.

drivers/gpu/drm/panel/panel-simple.c | 44 ++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 4bc61d71f068..a54f42cb3adc 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -93,6 +93,36 @@ struct panel_desc {
*/
unsigned int hpd_absent_delay;

+ /**
+ * @delay.prepare_to_enable: Time between prepare and enable.
+ *
+ * The minimum time, in milliseconds, that needs to have passed
+ * between when prepare finished and enable may begin. If at
+ * enable time less time has passed since prepare finished,
+ * the driver waits for the remaining time.
+ *
+ * If a fixed enable delay is also specified, we'll start
+ * counting before delaying for the fixed delay.
+ *
+ * If a fixed prepare delay is also specified, we won't start
+ * counting until after the fixed delay. We can't overlap this
+ * fixed delay with the min time because the fixed delay
+ * doesn't happen at the end of the function if a HPD GPIO was
+ * specified.
+ *
+ * In other words:
+ * prepare()
+ * ...
+ * // do fixed prepare delay
+ * // wait for HPD GPIO if applicable
+ * // start counting for prepare_to_enable
+ *
+ * enable()
+ * // do fixed enable delay
+ * // enforce prepare_to_enable min time
+ */
+ unsigned int prepare_to_enable;
+
/**
* @delay.enable: Time for the panel to display a valid frame.
*
@@ -131,10 +161,10 @@ struct panel_desc {

struct panel_simple {
struct drm_panel base;
- bool prepared;
bool enabled;
bool no_hpd;

+ ktime_t prepared_time;
ktime_t unprepared_time;

const struct panel_desc *desc;
@@ -297,14 +327,14 @@ static int panel_simple_unprepare(struct drm_panel *panel)
{
struct panel_simple *p = to_panel_simple(panel);

- if (!p->prepared)
+ if (p->prepared_time == 0)
return 0;

gpiod_set_value_cansleep(p->enable_gpio, 0);

regulator_disable(p->supply);

- p->prepared = false;
+ p->prepared_time = 0;
p->unprepared_time = ktime_get();

return 0;
@@ -342,7 +372,7 @@ static int panel_simple_prepare(struct drm_panel *panel)
int err;
int hpd_asserted;

- if (p->prepared)
+ if (p->prepared_time != 0)
return 0;

panel_simple_wait(p->unprepared_time, p->desc->delay.unprepare);
@@ -381,7 +411,7 @@ static int panel_simple_prepare(struct drm_panel *panel)
}
}

- p->prepared = true;
+ p->prepared_time = ktime_get();

return 0;
}
@@ -396,6 +426,8 @@ static int panel_simple_enable(struct drm_panel *panel)
if (p->desc->delay.enable)
msleep(p->desc->delay.enable);

+ panel_simple_wait(p->prepared_time, p->desc->delay.prepare_to_enable);
+
p->enabled = true;

return 0;
@@ -562,7 +594,7 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
return -ENOMEM;

panel->enabled = false;
- panel->prepared = false;
+ panel->prepared_time = 0;
panel->desc = desc;

panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
--
2.29.2.222.g5d2a92d10f8-goog