b2e8a8d736d177dd3939ac362015b2b617753d9f
[oweals/openwrt.git] /
1 From 9f05f9c3a564cedbb3c5f3dd0d5b95f247b63c71 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Thu, 6 Jul 2017 11:45:48 -0700
4 Subject: [PATCH 115/703] drm/vc4: Add support for setting DPMS in firmwarekms.
5
6 This ensures that the screen goes blank during DPMS (screensaver),
7 including the cursor.  Planes don't necessarily get disabled during
8 CRTC disable, so we need to be careful to not leave them on or turn
9 them back on early.
10
11 Signed-off-by: Eric Anholt <eric@anholt.net>
12 ---
13  drivers/gpu/drm/vc4/vc4_firmware_kms.c | 40 ++++++++++++++++++++++++--
14  1 file changed, 37 insertions(+), 3 deletions(-)
15
16 --- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
17 +++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
18 @@ -36,6 +36,8 @@ struct vc4_crtc {
19         struct drm_crtc base;
20         struct drm_encoder *encoder;
21         struct drm_connector *connector;
22 +       struct drm_plane *primary;
23 +       struct drm_plane *cursor;
24         void __iomem *regs;
25  
26         struct drm_pending_vblank_event *event;
27 @@ -123,8 +125,6 @@ static void vc4_primary_plane_atomic_upd
28         u32 bpp = 32;
29         int ret;
30  
31 -       vc4_plane_set_primary_blank(plane, false);
32 -
33         fbinfo->xres = state->crtc_w;
34         fbinfo->yres = state->crtc_h;
35         fbinfo->xres_virtual = state->crtc_w;
36 @@ -168,6 +168,12 @@ static void vc4_primary_plane_atomic_upd
37                                        vc4_plane->fbinfo_bus_addr);
38         WARN_ON_ONCE(fbinfo->pitch != fb->pitches[0]);
39         WARN_ON_ONCE(fbinfo->base != bo->paddr + fb->offsets[0]);
40 +
41 +       /* If the CRTC is on (or going to be on) and we're enabled,
42 +        * then unblank.  Otherwise, stay blank until CRTC enable.
43 +       */
44 +       if (state->crtc->state->active)
45 +               vc4_plane_set_primary_blank(plane, false);
46  }
47  
48  static void vc4_primary_plane_atomic_disable(struct drm_plane *plane,
49 @@ -184,7 +190,12 @@ static void vc4_cursor_plane_atomic_upda
50         struct drm_framebuffer *fb = state->fb;
51         struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
52         int ret;
53 -       u32 packet_state[] = { true, state->crtc_x, state->crtc_y, 0 };
54 +       u32 packet_state[] = {
55 +               state->crtc->state->active,
56 +               state->crtc_x,
57 +               state->crtc_y,
58 +               0
59 +       };
60         u32 packet_info[] = { state->crtc_w, state->crtc_h,
61                               0, /* unused */
62                               bo->paddr + fb->offsets[0],
63 @@ -321,10 +332,30 @@ static void vc4_crtc_mode_set_nofb(struc
64  
65  static void vc4_crtc_disable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
66  {
67 +       struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
68 +
69 +       /* Always turn the planes off on CRTC disable. In DRM, planes
70 +        * are enabled/disabled through the update/disable hooks
71 +        * above, and the CRTC enable/disable independently controls
72 +        * whether anything scans out at all, but the firmware doesn't
73 +        * give us a CRTC-level control for that.
74 +        */
75 +       vc4_cursor_plane_atomic_disable(vc4_crtc->cursor,
76 +                                       vc4_crtc->cursor->state);
77 +       vc4_plane_set_primary_blank(vc4_crtc->primary, true);
78  }
79  
80  static void vc4_crtc_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
81  {
82 +       struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
83 +
84 +       /* Unblank the planes (if they're supposed to be displayed). */
85 +       if (vc4_crtc->primary->state->fb)
86 +               vc4_plane_set_primary_blank(vc4_crtc->primary, false);
87 +       if (vc4_crtc->cursor->state->fb) {
88 +               vc4_cursor_plane_atomic_update(vc4_crtc->cursor,
89 +                                              vc4_crtc->cursor->state);
90 +       }
91  }
92  
93  static int vc4_crtc_atomic_check(struct drm_crtc *crtc,
94 @@ -618,6 +649,9 @@ static int vc4_fkms_bind(struct device *
95         primary_plane->crtc = crtc;
96         cursor_plane->crtc = crtc;
97  
98 +       vc4_crtc->primary = primary_plane;
99 +       vc4_crtc->cursor = cursor_plane;
100 +
101         vc4_encoder = devm_kzalloc(dev, sizeof(*vc4_encoder), GFP_KERNEL);
102         if (!vc4_encoder)
103                 return -ENOMEM;