|
|
@@ -79,7 +79,7 @@ struct s1d_device {
|
|
|
struct i2c_client *client;
|
|
|
struct s1d_config cfg;
|
|
|
|
|
|
- /* touched only by the worker, or with the worker stopped */
|
|
|
+ /* touched only by the worker, or by whoever set panel_busy */
|
|
|
struct s1d_panel panel;
|
|
|
u8 *work_frame;
|
|
|
bool panel_ready; /* controller initialised and still powered */
|
|
|
@@ -87,10 +87,11 @@ struct s1d_device {
|
|
|
|
|
|
struct delayed_work flush_work;
|
|
|
|
|
|
- struct mutex lock; /* protects pending_frame, dirty_*, bl_on */
|
|
|
+ struct mutex lock; /* protects pending_frame, dirty_*, bl_on, panel_busy */
|
|
|
u8 *pending_frame;
|
|
|
unsigned int dirty_y0, dirty_y1;
|
|
|
bool bl_on; /* requested; the worker drives the pin */
|
|
|
+ bool panel_busy; /* CRTC enable/disable owns the panel; worker waits */
|
|
|
};
|
|
|
|
|
|
static struct s1d_device *to_s1d(struct drm_device *drm)
|
|
|
@@ -128,9 +129,14 @@ static void s1d_flush_work(struct work_struct *work)
|
|
|
flush_work);
|
|
|
unsigned int stride = s->panel.stride, y0, y1;
|
|
|
bool bl_on;
|
|
|
- int idx, ret;
|
|
|
+ int idx, ret = 0, bl_ret = 0;
|
|
|
|
|
|
mutex_lock(&s->lock);
|
|
|
+ /* a transaction is under way; s1d_panel_release() queues us again */
|
|
|
+ if (s->panel_busy) {
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
+ return;
|
|
|
+ }
|
|
|
bl_on = s->bl_on;
|
|
|
y0 = s->dirty_y0;
|
|
|
y1 = s->dirty_y1;
|
|
|
@@ -144,34 +150,39 @@ static void s1d_flush_work(struct work_struct *work)
|
|
|
if (!drm_dev_enter(&s->drm, &idx))
|
|
|
return;
|
|
|
|
|
|
- /* before the first init this only records the level for init */
|
|
|
+ /*
|
|
|
+ * Between transactions, so a request made during one waits for this.
|
|
|
+ * Before the first init this only records the level for init.
|
|
|
+ */
|
|
|
if (bl_on != s->panel.backlight) {
|
|
|
- ret = s1d_panel_backlight(&s->panel, bl_on);
|
|
|
- if (ret)
|
|
|
- drm_err_ratelimited(&s->drm, "backlight failed: %d\n", ret);
|
|
|
- }
|
|
|
- if (y1 <= y0) {
|
|
|
- drm_dev_exit(idx);
|
|
|
- return;
|
|
|
+ bl_ret = s1d_panel_backlight(&s->panel, bl_on);
|
|
|
+ if (bl_ret)
|
|
|
+ drm_err_ratelimited(&s->drm, "backlight failed: %d\n", bl_ret);
|
|
|
}
|
|
|
|
|
|
- ret = s->panel_ready ? 0 : s1d_panel_init(&s->panel);
|
|
|
- if (!ret) {
|
|
|
- s->panel_ready = true;
|
|
|
- /* on failure the core rewrites the whole frame on the next update */
|
|
|
- ret = s1d_panel_update(&s->panel, s->work_frame, y0, y1);
|
|
|
+ if (y1 > y0) {
|
|
|
+ ret = s->panel_ready ? 0 : s1d_panel_init(&s->panel);
|
|
|
+ if (!ret) {
|
|
|
+ s->panel_ready = true;
|
|
|
+ /* on failure the core rewrites the whole frame next time */
|
|
|
+ ret = s1d_panel_update(&s->panel, s->work_frame, y0, y1);
|
|
|
+ }
|
|
|
+ if (ret) {
|
|
|
+ drm_err_ratelimited(&s->drm, "panel update failed: %d\n", ret);
|
|
|
+ /*
|
|
|
+ * Retry even if no new damage arrives. Marking everything
|
|
|
+ * dirty also refreshes all of work_frame, which a re-init
|
|
|
+ * needs.
|
|
|
+ */
|
|
|
+ mutex_lock(&s->lock);
|
|
|
+ s->dirty_y0 = 0;
|
|
|
+ s->dirty_y1 = s->cfg.height;
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (ret) {
|
|
|
- drm_err_ratelimited(&s->drm, "panel update failed: %d\n", ret);
|
|
|
- /*
|
|
|
- * Retry even if no new damage arrives. Marking everything dirty
|
|
|
- * also refreshes all of work_frame, which a re-init needs.
|
|
|
- */
|
|
|
- mutex_lock(&s->lock);
|
|
|
- s->dirty_y0 = 0;
|
|
|
- s->dirty_y1 = s->cfg.height;
|
|
|
- mutex_unlock(&s->lock);
|
|
|
+ /* a failed backlight write left panel.backlight unchanged: retried too */
|
|
|
+ if (ret || bl_ret) {
|
|
|
queue_delayed_work(system_long_wq, &s->flush_work,
|
|
|
msecs_to_jiffies(s->retry_ms));
|
|
|
s->retry_ms = min(s->retry_ms * 2, RETRY_MAX_MS);
|
|
|
@@ -268,6 +279,33 @@ static const struct drm_plane_funcs s1d_plane_funcs = {
|
|
|
|
|
|
/* ---- CRTC --------------------------------------------------------------- */
|
|
|
|
|
|
+/*
|
|
|
+ * Take the panel from the worker for a transaction of our own. Backlight
|
|
|
+ * requests made meanwhile are only recorded; the worker would otherwise
|
|
|
+ * interleave its writes with ours in the shared transfer buffer.
|
|
|
+ */
|
|
|
+static void s1d_panel_claim(struct s1d_device *s)
|
|
|
+{
|
|
|
+ mutex_lock(&s->lock);
|
|
|
+ s->panel_busy = true;
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
+ /* a worker already running finishes first; one starting now backs off */
|
|
|
+ cancel_delayed_work_sync(&s->flush_work);
|
|
|
+}
|
|
|
+
|
|
|
+/* Hand the panel back, and let the worker apply what queued meanwhile */
|
|
|
+static void s1d_panel_release(struct s1d_device *s)
|
|
|
+{
|
|
|
+ bool kick;
|
|
|
+
|
|
|
+ mutex_lock(&s->lock);
|
|
|
+ s->panel_busy = false;
|
|
|
+ kick = s->bl_on != s->panel.backlight || s->dirty_y1 > s->dirty_y0;
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
+ if (kick)
|
|
|
+ mod_delayed_work(system_long_wq, &s->flush_work, 0);
|
|
|
+}
|
|
|
+
|
|
|
static void s1d_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
|
|
|
{
|
|
|
struct s1d_device *s = to_s1d(crtc->dev);
|
|
|
@@ -281,7 +319,7 @@ static void s1d_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_stat
|
|
|
* damage is not queued yet; a dropped retry is covered by the full
|
|
|
* damage a modeset brings.
|
|
|
*/
|
|
|
- cancel_delayed_work_sync(&s->flush_work);
|
|
|
+ s1d_panel_claim(s);
|
|
|
s->retry_ms = RETRY_MIN_MS;
|
|
|
|
|
|
/* VRAM survives a plain disable, so only the display needs turning on */
|
|
|
@@ -300,6 +338,7 @@ static void s1d_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_stat
|
|
|
s->panel_ready = !ret;
|
|
|
memset(s->work_frame, 0, s->panel.size);
|
|
|
out:
|
|
|
+ s1d_panel_release(s);
|
|
|
drm_dev_exit(idx);
|
|
|
}
|
|
|
|
|
|
@@ -311,9 +350,11 @@ static void s1d_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_sta
|
|
|
if (!drm_dev_enter(crtc->dev, &idx))
|
|
|
return;
|
|
|
|
|
|
- cancel_delayed_work_sync(&s->flush_work);
|
|
|
+ s1d_panel_claim(s);
|
|
|
if (s->panel_ready)
|
|
|
s1d_panel_display(&s->panel, false);
|
|
|
+ /* the backlight stays usable with the display off */
|
|
|
+ s1d_panel_release(s);
|
|
|
|
|
|
drm_dev_exit(idx);
|
|
|
}
|
|
|
@@ -438,7 +479,10 @@ static int s1d_kms_init(struct s1d_device *s)
|
|
|
|
|
|
/* ---- backlight ---------------------------------------------------------- */
|
|
|
|
|
|
-/* The panel belongs to the worker, so only record the request and kick it */
|
|
|
+/*
|
|
|
+ * Only record the request and kick the worker. It applies it between panel
|
|
|
+ * transactions: after a frame in progress, or once enable/disable is done.
|
|
|
+ */
|
|
|
static int s1d_bl_update(struct backlight_device *bd)
|
|
|
{
|
|
|
struct s1d_device *s = bl_get_data(bd);
|
|
|
@@ -600,7 +644,12 @@ static int s1d_suspend(struct device *dev)
|
|
|
ret = drm_mode_config_helper_suspend(&s->drm);
|
|
|
if (ret)
|
|
|
return ret;
|
|
|
- /* the CRTC is off and the worker stopped; the controller may lose power */
|
|
|
+ /*
|
|
|
+ * The backlight's own suspend ran first and asked for it off; send
|
|
|
+ * that, then stop the worker before the controller may lose power.
|
|
|
+ */
|
|
|
+ flush_delayed_work(&s->flush_work);
|
|
|
+ cancel_delayed_work_sync(&s->flush_work);
|
|
|
s->panel_ready = false;
|
|
|
return 0;
|
|
|
}
|