Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 1 | /* |
Rob Clark | 8bb0daf | 2013-02-11 12:43:09 -0500 | [diff] [blame] | 2 | * drivers/gpu/drm/omapdrm/omap_plane.c |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011 Texas Instruments |
| 5 | * Author: Rob Clark <rob.clark@linaro.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 20 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 21 | #include <drm/drm_plane_helper.h> |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 22 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 23 | #include "omap_dmm_tiler.h" |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 24 | #include "omap_drv.h" |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 25 | |
| 26 | /* some hackery because omapdss has an 'enum omap_plane' (which would be |
| 27 | * better named omap_plane_id).. and compiler seems unhappy about having |
| 28 | * both a 'struct omap_plane' and 'enum omap_plane' |
| 29 | */ |
| 30 | #define omap_plane _omap_plane |
| 31 | |
| 32 | /* |
| 33 | * plane funcs |
| 34 | */ |
| 35 | |
| 36 | #define to_omap_plane(x) container_of(x, struct omap_plane, base) |
| 37 | |
| 38 | struct omap_plane { |
| 39 | struct drm_plane base; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 40 | int id; /* TODO rename omap_plane -> omap_plane_id in omapdss so I can use the enum */ |
| 41 | const char *name; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 42 | struct omap_overlay_info info; |
| 43 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 44 | /* position/orientation of scanout within the fb: */ |
| 45 | struct omap_drm_window win; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 46 | bool enabled; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 47 | |
| 48 | /* last fb that we pinned: */ |
| 49 | struct drm_framebuffer *pinned_fb; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 50 | |
Rob Clark | a890e66 | 2012-03-05 10:48:31 -0600 | [diff] [blame] | 51 | uint32_t nformats; |
| 52 | uint32_t formats[32]; |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 53 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 54 | struct omap_drm_irq error_irq; |
Rob Clark | a890e66 | 2012-03-05 10:48:31 -0600 | [diff] [blame] | 55 | }; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 56 | |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 57 | /* update which fb (if any) is pinned for scanout */ |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 58 | static int omap_plane_update_pin(struct drm_plane *plane) |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 59 | { |
| 60 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 61 | struct drm_framebuffer *pinned_fb = omap_plane->pinned_fb; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 62 | struct drm_framebuffer *fb = omap_plane->enabled ? plane->fb : NULL; |
| 63 | int ret = 0; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 64 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 65 | if (pinned_fb == fb) |
| 66 | return 0; |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 67 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 68 | DBG("%p -> %p", pinned_fb, fb); |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 69 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 70 | if (fb) { |
| 71 | drm_framebuffer_reference(fb); |
| 72 | ret = omap_framebuffer_pin(fb); |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 73 | } |
| 74 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 75 | if (pinned_fb) |
| 76 | omap_crtc_queue_unpin(plane->crtc, pinned_fb); |
| 77 | |
| 78 | if (ret) { |
| 79 | dev_err(plane->dev->dev, "could not swap %p -> %p\n", |
| 80 | omap_plane->pinned_fb, fb); |
| 81 | drm_framebuffer_unreference(fb); |
| 82 | omap_plane->pinned_fb = NULL; |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | omap_plane->pinned_fb = fb; |
| 87 | |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 88 | return 0; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 89 | } |
| 90 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 91 | static int __omap_plane_setup(struct omap_plane *omap_plane, |
| 92 | struct drm_crtc *crtc, |
| 93 | struct drm_framebuffer *fb) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 94 | { |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 95 | struct omap_overlay_info *info = &omap_plane->info; |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 96 | struct drm_device *dev = omap_plane->base.dev; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 97 | int ret; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 98 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 99 | DBG("%s, enabled=%d", omap_plane->name, omap_plane->enabled); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 100 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 101 | if (!omap_plane->enabled) { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 102 | dispc_ovl_enable(omap_plane->id, false); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 103 | return 0; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 104 | } |
| 105 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 106 | /* update scanout: */ |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 107 | omap_framebuffer_update_scanout(fb, &omap_plane->win, info); |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 108 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 109 | DBG("%dx%d -> %dx%d (%d)", info->width, info->height, |
| 110 | info->out_width, info->out_height, |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 111 | info->screen_width); |
Russell King | 2d31ca3 | 2014-07-12 10:53:41 +0100 | [diff] [blame] | 112 | DBG("%d,%d %pad %pad", info->pos_x, info->pos_y, |
| 113 | &info->paddr, &info->p_uv_addr); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 114 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 115 | dispc_ovl_set_channel_out(omap_plane->id, |
| 116 | omap_crtc_channel(crtc)); |
Tomi Valkeinen | 2dd3887 | 2014-10-03 15:14:08 +0000 | [diff] [blame] | 117 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 118 | /* and finally, update omapdss: */ |
Laurent Pinchart | 9c660b7 | 2015-01-12 16:44:03 +0200 | [diff] [blame] | 119 | ret = dispc_ovl_setup(omap_plane->id, info, false, |
| 120 | omap_crtc_timings(crtc), false); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 121 | if (ret) { |
| 122 | dev_err(dev->dev, "dispc_ovl_setup failed: %d\n", ret); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 123 | return ret; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | dispc_ovl_enable(omap_plane->id, true); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 127 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static int omap_plane_setup(struct omap_plane *omap_plane) |
| 132 | { |
| 133 | struct drm_plane *plane = &omap_plane->base; |
| 134 | int ret; |
| 135 | |
| 136 | ret = omap_plane_update_pin(plane); |
| 137 | if (ret < 0) |
| 138 | return ret; |
| 139 | |
| 140 | dispc_runtime_get(); |
| 141 | ret = __omap_plane_setup(omap_plane, plane->crtc, plane->fb); |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 142 | dispc_runtime_put(); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 143 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 144 | return ret; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 145 | } |
| 146 | |
Rob Clark | 2f53700 | 2012-01-16 12:51:18 -0600 | [diff] [blame] | 147 | int omap_plane_mode_set(struct drm_plane *plane, |
Laurent Pinchart | a350da8 | 2015-01-17 22:31:42 +0200 | [diff] [blame] | 148 | struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 149 | int crtc_x, int crtc_y, |
| 150 | unsigned int crtc_w, unsigned int crtc_h, |
| 151 | unsigned int src_x, unsigned int src_y, |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 152 | unsigned int src_w, unsigned int src_h) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 153 | { |
| 154 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 155 | struct omap_drm_window *win = &omap_plane->win; |
| 156 | |
| 157 | win->crtc_x = crtc_x; |
| 158 | win->crtc_y = crtc_y; |
| 159 | win->crtc_w = crtc_w; |
| 160 | win->crtc_h = crtc_h; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 161 | |
Laurent Pinchart | a350da8 | 2015-01-17 22:31:42 +0200 | [diff] [blame] | 162 | win->src_x = src_x; |
| 163 | win->src_y = src_y; |
| 164 | win->src_w = src_w; |
| 165 | win->src_h = src_h; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 166 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 167 | return omap_plane_setup(omap_plane); |
| 168 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 169 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 170 | int omap_plane_set_enable(struct drm_plane *plane, bool enable) |
| 171 | { |
| 172 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 173 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 174 | if (enable == omap_plane->enabled) |
| 175 | return 0; |
| 176 | |
| 177 | omap_plane->enabled = enable; |
| 178 | return omap_plane_setup(omap_plane); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 179 | } |
| 180 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 181 | static int omap_plane_prepare_fb(struct drm_plane *plane, |
| 182 | struct drm_framebuffer *fb, |
| 183 | const struct drm_plane_state *new_state) |
| 184 | { |
| 185 | return omap_framebuffer_pin(fb); |
| 186 | } |
| 187 | |
| 188 | static void omap_plane_cleanup_fb(struct drm_plane *plane, |
| 189 | struct drm_framebuffer *fb, |
| 190 | const struct drm_plane_state *old_state) |
| 191 | { |
| 192 | omap_framebuffer_unpin(fb); |
| 193 | } |
| 194 | |
| 195 | static void omap_plane_atomic_update(struct drm_plane *plane, |
| 196 | struct drm_plane_state *old_state) |
Rob Clark | 2f53700 | 2012-01-16 12:51:18 -0600 | [diff] [blame] | 197 | { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 198 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 199 | struct omap_drm_window *win = &omap_plane->win; |
| 200 | struct drm_plane_state *state = plane->state; |
| 201 | uint32_t src_w; |
| 202 | uint32_t src_h; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 203 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 204 | if (!state->fb || !state->crtc) |
| 205 | return; |
Archit Taneja | b03e14f | 2013-04-09 15:26:00 +0300 | [diff] [blame] | 206 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 207 | /* omap_framebuffer_update_scanout() takes adjusted src */ |
Grazvydas Ignotas | d458660 | 2014-04-05 21:33:51 +0300 | [diff] [blame] | 208 | switch (omap_plane->win.rotation & 0xf) { |
| 209 | case BIT(DRM_ROTATE_90): |
| 210 | case BIT(DRM_ROTATE_270): |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 211 | src_w = state->src_h; |
| 212 | src_h = state->src_w; |
| 213 | break; |
| 214 | default: |
| 215 | src_w = state->src_w; |
| 216 | src_h = state->src_h; |
Grazvydas Ignotas | d458660 | 2014-04-05 21:33:51 +0300 | [diff] [blame] | 217 | break; |
| 218 | } |
| 219 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 220 | /* src values are in Q16 fixed point, convert to integer. */ |
| 221 | win->crtc_x = state->crtc_x; |
| 222 | win->crtc_y = state->crtc_y; |
| 223 | win->crtc_w = state->crtc_w; |
| 224 | win->crtc_h = state->crtc_h; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 225 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 226 | win->src_x = state->src_x >> 16; |
| 227 | win->src_y = state->src_y >> 16; |
| 228 | win->src_w = src_w >> 16; |
| 229 | win->src_h = src_h >> 16; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 230 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 231 | omap_plane->enabled = true; |
| 232 | __omap_plane_setup(omap_plane, state->crtc, state->fb); |
Rob Clark | 2f53700 | 2012-01-16 12:51:18 -0600 | [diff] [blame] | 233 | } |
| 234 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 235 | static void omap_plane_atomic_disable(struct drm_plane *plane, |
| 236 | struct drm_plane_state *old_state) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 237 | { |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 238 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Laurent Pinchart | 2debab9 | 2015-01-12 22:38:16 +0200 | [diff] [blame] | 239 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 240 | omap_plane->win.rotation = BIT(DRM_ROTATE_0); |
Laurent Pinchart | 82e58855 | 2015-01-12 23:56:57 +0200 | [diff] [blame] | 241 | omap_plane->info.zorder = plane->type == DRM_PLANE_TYPE_PRIMARY |
| 242 | ? 0 : omap_plane->id; |
| 243 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 244 | if (!omap_plane->enabled) |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 245 | return; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 246 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 247 | omap_plane->enabled = false; |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 248 | __omap_plane_setup(omap_plane, NULL, NULL); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 249 | } |
| 250 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 251 | static const struct drm_plane_helper_funcs omap_plane_helper_funcs = { |
| 252 | .prepare_fb = omap_plane_prepare_fb, |
| 253 | .cleanup_fb = omap_plane_cleanup_fb, |
| 254 | .atomic_update = omap_plane_atomic_update, |
| 255 | .atomic_disable = omap_plane_atomic_disable, |
| 256 | }; |
| 257 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 258 | static void omap_plane_destroy(struct drm_plane *plane) |
| 259 | { |
| 260 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 261 | |
| 262 | DBG("%s", omap_plane->name); |
| 263 | |
| 264 | omap_irq_unregister(plane->dev, &omap_plane->error_irq); |
| 265 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 266 | drm_plane_cleanup(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 267 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 268 | kfree(omap_plane); |
| 269 | } |
| 270 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 271 | /* helper to install properties which are common to planes and crtcs */ |
| 272 | void omap_plane_install_properties(struct drm_plane *plane, |
| 273 | struct drm_mode_object *obj) |
| 274 | { |
| 275 | struct drm_device *dev = plane->dev; |
| 276 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 277 | |
Rob Clark | c2a6a55 | 2012-10-25 17:14:13 -0500 | [diff] [blame] | 278 | if (priv->has_dmm) { |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 279 | struct drm_property *prop = dev->mode_config.rotation_property; |
| 280 | |
Rob Clark | c2a6a55 | 2012-10-25 17:14:13 -0500 | [diff] [blame] | 281 | drm_object_attach_property(obj, prop, 0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 282 | } |
Andre Renaud | 8451b5a | 2012-08-15 15:18:02 -0500 | [diff] [blame] | 283 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 284 | drm_object_attach_property(obj, priv->zorder_prop, 0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | int omap_plane_set_property(struct drm_plane *plane, |
| 288 | struct drm_property *property, uint64_t val) |
| 289 | { |
| 290 | struct omap_plane *omap_plane = to_omap_plane(plane); |
| 291 | struct omap_drm_private *priv = plane->dev->dev_private; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 292 | int ret; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 293 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 294 | if (property == plane->dev->mode_config.rotation_property) { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 295 | DBG("%s: rotation: %02x", omap_plane->name, (uint32_t)val); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 296 | omap_plane->win.rotation = val; |
Andre Renaud | 8451b5a | 2012-08-15 15:18:02 -0500 | [diff] [blame] | 297 | } else if (property == priv->zorder_prop) { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 298 | DBG("%s: zorder: %02x", omap_plane->name, (uint32_t)val); |
Andre Renaud | 8451b5a | 2012-08-15 15:18:02 -0500 | [diff] [blame] | 299 | omap_plane->info.zorder = val; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 300 | } else { |
| 301 | return -EINVAL; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 304 | /* |
| 305 | * We're done if the plane is disabled, properties will be applied the |
| 306 | * next time it becomes enabled. |
| 307 | */ |
| 308 | if (!omap_plane->enabled) |
| 309 | return 0; |
| 310 | |
| 311 | ret = omap_plane_setup(omap_plane); |
| 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
| 315 | return omap_crtc_flush(plane->crtc); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 318 | static const struct drm_plane_funcs omap_plane_funcs = { |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame^] | 319 | .update_plane = drm_atomic_helper_update_plane, |
| 320 | .disable_plane = drm_atomic_helper_disable_plane, |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 321 | .reset = drm_atomic_helper_plane_reset, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 322 | .destroy = omap_plane_destroy, |
| 323 | .set_property = omap_plane_set_property, |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 324 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
| 325 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 326 | }; |
| 327 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 328 | static void omap_plane_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus) |
| 329 | { |
| 330 | struct omap_plane *omap_plane = |
| 331 | container_of(irq, struct omap_plane, error_irq); |
Tomi Valkeinen | 3b143fc | 2014-11-19 12:50:13 +0200 | [diff] [blame] | 332 | DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_plane->name, |
| 333 | irqstatus); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static const char *plane_names[] = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 337 | [OMAP_DSS_GFX] = "gfx", |
| 338 | [OMAP_DSS_VIDEO1] = "vid1", |
| 339 | [OMAP_DSS_VIDEO2] = "vid2", |
| 340 | [OMAP_DSS_VIDEO3] = "vid3", |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | static const uint32_t error_irqs[] = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 344 | [OMAP_DSS_GFX] = DISPC_IRQ_GFX_FIFO_UNDERFLOW, |
| 345 | [OMAP_DSS_VIDEO1] = DISPC_IRQ_VID1_FIFO_UNDERFLOW, |
| 346 | [OMAP_DSS_VIDEO2] = DISPC_IRQ_VID2_FIFO_UNDERFLOW, |
| 347 | [OMAP_DSS_VIDEO3] = DISPC_IRQ_VID3_FIFO_UNDERFLOW, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 348 | }; |
| 349 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 350 | /* initialize plane */ |
| 351 | struct drm_plane *omap_plane_init(struct drm_device *dev, |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 352 | int id, enum drm_plane_type type) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 353 | { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 354 | struct omap_drm_private *priv = dev->dev_private; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 355 | struct drm_plane *plane; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 356 | struct omap_plane *omap_plane; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 357 | struct omap_overlay_info *info; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 358 | int ret; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 359 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 360 | DBG("%s: type=%d", plane_names[id], type); |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 361 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 362 | omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 363 | if (!omap_plane) |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 364 | return ERR_PTR(-ENOMEM); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 365 | |
Rob Clark | a890e66 | 2012-03-05 10:48:31 -0600 | [diff] [blame] | 366 | omap_plane->nformats = omap_framebuffer_get_formats( |
| 367 | omap_plane->formats, ARRAY_SIZE(omap_plane->formats), |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 368 | dss_feat_get_supported_color_modes(id)); |
| 369 | omap_plane->id = id; |
| 370 | omap_plane->name = plane_names[id]; |
| 371 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 372 | plane = &omap_plane->base; |
| 373 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 374 | omap_plane->error_irq.irqmask = error_irqs[id]; |
| 375 | omap_plane->error_irq.irq = omap_plane_error_irq; |
| 376 | omap_irq_register(dev, &omap_plane->error_irq); |
| 377 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 378 | ret = drm_universal_plane_init(dev, plane, (1 << priv->num_crtcs) - 1, |
| 379 | &omap_plane_funcs, omap_plane->formats, |
| 380 | omap_plane->nformats, type); |
| 381 | if (ret < 0) |
| 382 | goto error; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 383 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 384 | drm_plane_helper_add(plane, &omap_plane_helper_funcs); |
| 385 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 386 | omap_plane_install_properties(plane, &plane->base); |
| 387 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 388 | /* get our starting configuration, set defaults for parameters |
| 389 | * we don't currently use, etc: |
| 390 | */ |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 391 | info = &omap_plane->info; |
| 392 | info->rotation_type = OMAP_DSS_ROT_DMA; |
| 393 | info->rotation = OMAP_DSS_ROT_0; |
| 394 | info->global_alpha = 0xff; |
| 395 | info->mirror = 0; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 396 | |
| 397 | /* Set defaults depending on whether we are a CRTC or overlay |
| 398 | * layer. |
| 399 | * TODO add ioctl to give userspace an API to change this.. this |
| 400 | * will come in a subsequent patch. |
| 401 | */ |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 402 | if (type == DRM_PLANE_TYPE_PRIMARY) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 403 | omap_plane->info.zorder = 0; |
| 404 | else |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 405 | omap_plane->info.zorder = id; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 406 | |
| 407 | return plane; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 408 | |
| 409 | error: |
| 410 | omap_irq_unregister(plane->dev, &omap_plane->error_irq); |
| 411 | kfree(omap_plane); |
| 412 | return NULL; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 413 | } |