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