Skip to content

Commit

Permalink
drm: panel: simple: Defer unprepare delay till next prepare to shorte…
Browse files Browse the repository at this point in the history
…n it

It is believed that all of the current users of the "unprepare" delay
don't actually need to wait the amount of time specified directly in
the unprepare phase.  The purpose of the delay that's specified is to
allow the panel to fully power off so that we don't try to power it
back on before it's managed to full power down.

Let's use this observation to avoid the fixed delay that we currently
have.  Instead of delaying, we'll note the current time when the
unprepare happens.  If someone then tries to prepare the panel later
and not enough time has passed, we'll do the delay before starting the
prepare phase.

Signed-off-by: Douglas Anderson <[email protected]>
Signed-off-by: Sam Ravnborg <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/20201109170018.v4.2.I06a95d83e7fa1bd919c8edd63dacacb5436e495a@changeid
  • Loading branch information
dianders authored and sravnborg committed Nov 29, 2020
1 parent 131f909 commit e5e30df
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions drivers/gpu/drm/panel/panel-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ struct panel_desc {
*
* The time (in milliseconds) that it takes for the panel
* to power itself down completely.
*
* This time is used to prevent a future "prepare" from
* starting until at least this many milliseconds has passed.
* If at prepare time less time has passed since unprepare
* finished, the driver waits for the remaining time.
*/
unsigned int unprepare;
} delay;
Expand All @@ -130,6 +135,8 @@ struct panel_simple {
bool enabled;
bool no_hpd;

ktime_t unprepared_time;

const struct panel_desc *desc;

struct regulator *supply;
Expand Down Expand Up @@ -257,6 +264,20 @@ static int panel_simple_get_non_edid_modes(struct panel_simple *panel,
return num;
}

static void panel_simple_wait(ktime_t start_ktime, unsigned int min_ms)
{
ktime_t now_ktime, min_ktime;

if (!min_ms)
return;

min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms));
now_ktime = ktime_get();

if (ktime_before(now_ktime, min_ktime))
msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1);
}

static int panel_simple_disable(struct drm_panel *panel)
{
struct panel_simple *p = to_panel_simple(panel);
Expand All @@ -283,10 +304,8 @@ static int panel_simple_unprepare(struct drm_panel *panel)

regulator_disable(p->supply);

if (p->desc->delay.unprepare)
msleep(p->desc->delay.unprepare);

p->prepared = false;
p->unprepared_time = ktime_get();

return 0;
}
Expand Down Expand Up @@ -326,6 +345,8 @@ static int panel_simple_prepare(struct drm_panel *panel)
if (p->prepared)
return 0;

panel_simple_wait(p->unprepared_time, p->desc->delay.unprepare);

err = regulator_enable(p->supply);
if (err < 0) {
dev_err(panel->dev, "failed to enable supply: %d\n", err);
Expand Down

0 comments on commit e5e30df

Please sign in to comment.