Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Russell King |
| 3 | * Rewritten from the dovefb driver, and Armada510 manuals. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | #include <drm/drmP.h> |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 10 | #include <drm/drm_plane_helper.h> |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 11 | #include "armada_crtc.h" |
| 12 | #include "armada_drm.h" |
| 13 | #include "armada_fb.h" |
| 14 | #include "armada_gem.h" |
| 15 | #include "armada_hw.h" |
| 16 | #include <drm/armada_drm.h> |
| 17 | #include "armada_ioctlP.h" |
| 18 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 19 | struct armada_ovl_plane_properties { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 20 | uint32_t colorkey_yr; |
| 21 | uint32_t colorkey_ug; |
| 22 | uint32_t colorkey_vb; |
| 23 | #define K2R(val) (((val) >> 0) & 0xff) |
| 24 | #define K2G(val) (((val) >> 8) & 0xff) |
| 25 | #define K2B(val) (((val) >> 16) & 0xff) |
| 26 | int16_t brightness; |
| 27 | uint16_t contrast; |
| 28 | uint16_t saturation; |
| 29 | uint32_t colorkey_mode; |
| 30 | }; |
| 31 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 32 | struct armada_ovl_plane { |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 33 | struct armada_plane base; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 34 | struct drm_framebuffer *old_fb; |
| 35 | uint32_t src_hw; |
| 36 | uint32_t dst_hw; |
| 37 | uint32_t dst_yx; |
| 38 | uint32_t ctrl0; |
| 39 | struct { |
| 40 | struct armada_vbl_event update; |
| 41 | struct armada_regs regs[13]; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 42 | } vbl; |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 43 | struct armada_ovl_plane_properties prop; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 44 | }; |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 45 | #define drm_to_armada_ovl_plane(p) \ |
| 46 | container_of(p, struct armada_ovl_plane, base.base) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 47 | |
| 48 | |
| 49 | static void |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 50 | armada_ovl_update_attr(struct armada_ovl_plane_properties *prop, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 51 | struct armada_crtc *dcrtc) |
| 52 | { |
| 53 | writel_relaxed(prop->colorkey_yr, dcrtc->base + LCD_SPU_COLORKEY_Y); |
| 54 | writel_relaxed(prop->colorkey_ug, dcrtc->base + LCD_SPU_COLORKEY_U); |
| 55 | writel_relaxed(prop->colorkey_vb, dcrtc->base + LCD_SPU_COLORKEY_V); |
| 56 | |
| 57 | writel_relaxed(prop->brightness << 16 | prop->contrast, |
| 58 | dcrtc->base + LCD_SPU_CONTRAST); |
| 59 | /* Docs say 15:0, but it seems to actually be 31:16 on Armada 510 */ |
| 60 | writel_relaxed(prop->saturation << 16, |
| 61 | dcrtc->base + LCD_SPU_SATURATION); |
| 62 | writel_relaxed(0x00002000, dcrtc->base + LCD_SPU_CBSH_HUE); |
| 63 | |
| 64 | spin_lock_irq(&dcrtc->irq_lock); |
| 65 | armada_updatel(prop->colorkey_mode | CFG_ALPHAM_GRA, |
| 66 | CFG_CKMODE_MASK | CFG_ALPHAM_MASK | CFG_ALPHA_MASK, |
| 67 | dcrtc->base + LCD_SPU_DMA_CTRL1); |
| 68 | |
| 69 | armada_updatel(ADV_GRACOLORKEY, 0, dcrtc->base + LCD_SPU_ADV_REG); |
| 70 | spin_unlock_irq(&dcrtc->irq_lock); |
| 71 | } |
| 72 | |
Russell King | fecfdb2 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 73 | static void armada_ovl_retire_fb(struct armada_ovl_plane *dplane, |
| 74 | struct drm_framebuffer *fb) |
| 75 | { |
| 76 | struct drm_framebuffer *old_fb; |
| 77 | |
Russell King | 66377ef | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 78 | old_fb = xchg(&dplane->old_fb, fb); |
Russell King | fecfdb2 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 79 | |
| 80 | if (old_fb) |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 81 | armada_drm_queue_unref_work(dplane->base.base.dev, old_fb); |
Russell King | fecfdb2 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 84 | /* === Plane support === */ |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 85 | static void armada_ovl_plane_vbl(struct armada_crtc *dcrtc, void *data) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 86 | { |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 87 | struct armada_ovl_plane *dplane = data; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 88 | |
| 89 | armada_drm_crtc_update_regs(dcrtc, dplane->vbl.regs); |
Russell King | fecfdb2 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 90 | armada_ovl_retire_fb(dplane, NULL); |
Russell King | 070f3f6 | 2015-06-15 10:13:29 +0100 | [diff] [blame] | 91 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame^] | 92 | wake_up(&dplane->base.frame_wait); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 95 | static int |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 96 | armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 97 | struct drm_framebuffer *fb, |
| 98 | int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h, |
| 99 | uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h) |
| 100 | { |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 101 | struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 102 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 103 | struct drm_rect src = { |
| 104 | .x1 = src_x, |
| 105 | .y1 = src_y, |
| 106 | .x2 = src_x + src_w, |
| 107 | .y2 = src_y + src_h, |
| 108 | }; |
| 109 | struct drm_rect dest = { |
| 110 | .x1 = crtc_x, |
| 111 | .y1 = crtc_y, |
| 112 | .x2 = crtc_x + crtc_w, |
| 113 | .y2 = crtc_y + crtc_h, |
| 114 | }; |
| 115 | const struct drm_rect clip = { |
| 116 | .x2 = crtc->mode.hdisplay, |
| 117 | .y2 = crtc->mode.vdisplay, |
| 118 | }; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 119 | uint32_t val, ctrl0; |
| 120 | unsigned idx = 0; |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 121 | bool visible; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 122 | int ret; |
| 123 | |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 124 | ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip, |
| 125 | 0, INT_MAX, true, false, &visible); |
| 126 | if (ret) |
| 127 | return ret; |
| 128 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 129 | ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) | |
| 130 | CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) | |
| 131 | CFG_CBSH_ENA | CFG_DMA_HSMOOTH | CFG_DMA_ENA; |
| 132 | |
| 133 | /* Does the position/size result in nothing to display? */ |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 134 | if (!visible) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 135 | ctrl0 &= ~CFG_DMA_ENA; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 136 | |
| 137 | if (!dcrtc->plane) { |
| 138 | dcrtc->plane = plane; |
| 139 | armada_ovl_update_attr(&dplane->prop, dcrtc); |
| 140 | } |
| 141 | |
| 142 | /* FIXME: overlay on an interlaced display */ |
| 143 | /* Just updating the position/size? */ |
| 144 | if (plane->fb == fb && dplane->ctrl0 == ctrl0) { |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 145 | val = (drm_rect_height(&src) & 0xffff0000) | |
| 146 | drm_rect_width(&src) >> 16; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 147 | dplane->src_hw = val; |
| 148 | writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_HPXL_VLN); |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 149 | |
| 150 | val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 151 | dplane->dst_hw = val; |
| 152 | writel_relaxed(val, dcrtc->base + LCD_SPU_DZM_HPXL_VLN); |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 153 | |
| 154 | val = dest.y1 << 16 | dest.x1; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 155 | dplane->dst_yx = val; |
| 156 | writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_OVSA_HPXL_VLN); |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 157 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 158 | return 0; |
| 159 | } else if (~dplane->ctrl0 & ctrl0 & CFG_DMA_ENA) { |
| 160 | /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */ |
| 161 | armada_updatel(0, CFG_PDWN16x66 | CFG_PDWN32x66, |
| 162 | dcrtc->base + LCD_SPU_SRAM_PARA1); |
| 163 | } |
| 164 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame^] | 165 | wait_event_timeout(dplane->base.frame_wait, |
Russell King | 070f3f6 | 2015-06-15 10:13:29 +0100 | [diff] [blame] | 166 | list_empty(&dplane->vbl.update.node), |
| 167 | HZ/25); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 168 | |
| 169 | if (plane->fb != fb) { |
| 170 | struct armada_gem_object *obj = drm_fb_obj(fb); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 171 | uint32_t addr[3], pixel_format; |
| 172 | int i, num_planes, hsub; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Take a reference on the new framebuffer - we want to |
| 176 | * hold on to it while the hardware is displaying it. |
| 177 | */ |
| 178 | drm_framebuffer_reference(fb); |
| 179 | |
Russell King | fecfdb2 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 180 | if (plane->fb) |
| 181 | armada_ovl_retire_fb(dplane, plane->fb); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 182 | |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 183 | src_y = src.y1 >> 16; |
| 184 | src_x = src.x1 >> 16; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 185 | |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 186 | pixel_format = fb->pixel_format; |
| 187 | hsub = drm_format_horz_chroma_subsampling(pixel_format); |
| 188 | num_planes = drm_format_num_planes(pixel_format); |
| 189 | |
| 190 | /* |
| 191 | * Annoyingly, shifting a YUYV-format image by one pixel |
| 192 | * causes the U/V planes to toggle. Toggle the UV swap. |
| 193 | * (Unfortunately, this causes momentary colour flickering.) |
| 194 | */ |
| 195 | if (src_x & (hsub - 1) && num_planes == 1) |
| 196 | ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV); |
| 197 | |
| 198 | for (i = 0; i < num_planes; i++) |
| 199 | addr[i] = obj->dev_addr + fb->offsets[i] + |
| 200 | src_y * fb->pitches[i] + |
| 201 | src_x * drm_format_plane_cpp(pixel_format, i); |
| 202 | for (; i < ARRAY_SIZE(addr); i++) |
| 203 | addr[i] = 0; |
| 204 | |
| 205 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[0], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 206 | LCD_SPU_DMA_START_ADDR_Y0); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 207 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[1], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 208 | LCD_SPU_DMA_START_ADDR_U0); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 209 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[2], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 210 | LCD_SPU_DMA_START_ADDR_V0); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 211 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[0], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 212 | LCD_SPU_DMA_START_ADDR_Y1); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 213 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[1], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 214 | LCD_SPU_DMA_START_ADDR_U1); |
Russell King | 73068ce | 2015-06-15 10:18:02 +0100 | [diff] [blame] | 215 | armada_reg_queue_set(dplane->vbl.regs, idx, addr[2], |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 216 | LCD_SPU_DMA_START_ADDR_V1); |
| 217 | |
| 218 | val = fb->pitches[0] << 16 | fb->pitches[0]; |
| 219 | armada_reg_queue_set(dplane->vbl.regs, idx, val, |
| 220 | LCD_SPU_DMA_PITCH_YC); |
| 221 | val = fb->pitches[1] << 16 | fb->pitches[2]; |
| 222 | armada_reg_queue_set(dplane->vbl.regs, idx, val, |
| 223 | LCD_SPU_DMA_PITCH_UV); |
| 224 | } |
| 225 | |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 226 | val = (drm_rect_height(&src) & 0xffff0000) | drm_rect_width(&src) >> 16; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 227 | if (dplane->src_hw != val) { |
| 228 | dplane->src_hw = val; |
| 229 | armada_reg_queue_set(dplane->vbl.regs, idx, val, |
| 230 | LCD_SPU_DMA_HPXL_VLN); |
| 231 | } |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 232 | |
| 233 | val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 234 | if (dplane->dst_hw != val) { |
| 235 | dplane->dst_hw = val; |
| 236 | armada_reg_queue_set(dplane->vbl.regs, idx, val, |
| 237 | LCD_SPU_DZM_HPXL_VLN); |
| 238 | } |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 239 | |
| 240 | val = dest.y1 << 16 | dest.x1; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 241 | if (dplane->dst_yx != val) { |
| 242 | dplane->dst_yx = val; |
| 243 | armada_reg_queue_set(dplane->vbl.regs, idx, val, |
| 244 | LCD_SPU_DMA_OVSA_HPXL_VLN); |
| 245 | } |
Russell King | 98fb74f | 2015-06-15 10:17:57 +0100 | [diff] [blame] | 246 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 247 | if (dplane->ctrl0 != ctrl0) { |
| 248 | dplane->ctrl0 = ctrl0; |
| 249 | armada_reg_queue_mod(dplane->vbl.regs, idx, ctrl0, |
| 250 | CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE | |
| 251 | CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE | |
| 252 | CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU | |
| 253 | CFG_YUV2RGB) | CFG_DMA_ENA, |
| 254 | LCD_SPU_DMA_CTRL0); |
| 255 | } |
| 256 | if (idx) { |
| 257 | armada_reg_queue_end(dplane->vbl.regs, idx); |
| 258 | armada_drm_vbl_event_add(dcrtc, &dplane->vbl.update); |
| 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 263 | static int armada_ovl_plane_disable(struct drm_plane *plane) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 264 | { |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 265 | struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 266 | struct drm_framebuffer *fb; |
| 267 | struct armada_crtc *dcrtc; |
| 268 | |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 269 | if (!dplane->base.base.crtc) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 270 | return 0; |
| 271 | |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 272 | dcrtc = drm_to_armada_crtc(dplane->base.base.crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 273 | dcrtc->plane = NULL; |
| 274 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 275 | armada_drm_vbl_event_remove(dcrtc, &dplane->vbl.update); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 276 | |
Russell King | 5c8752c | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 277 | dplane->ctrl0 = 0; |
| 278 | |
Russell King | 5832680 | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 279 | armada_drm_crtc_plane_disable(dcrtc, plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 280 | |
Russell King | 66377ef | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 281 | fb = xchg(&dplane->old_fb, NULL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 282 | if (fb) |
| 283 | drm_framebuffer_unreference(fb); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 288 | static void armada_ovl_plane_destroy(struct drm_plane *plane) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 289 | { |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 290 | struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane); |
Russell King | 41dbb2d | 2015-06-15 10:13:30 +0100 | [diff] [blame] | 291 | |
| 292 | drm_plane_cleanup(plane); |
| 293 | |
| 294 | kfree(dplane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 297 | static int armada_ovl_plane_set_property(struct drm_plane *plane, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 298 | struct drm_property *property, uint64_t val) |
| 299 | { |
| 300 | struct armada_private *priv = plane->dev->dev_private; |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 301 | struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 302 | bool update_attr = false; |
| 303 | |
| 304 | if (property == priv->colorkey_prop) { |
| 305 | #define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8) |
| 306 | dplane->prop.colorkey_yr = CCC(K2R(val)); |
| 307 | dplane->prop.colorkey_ug = CCC(K2G(val)); |
| 308 | dplane->prop.colorkey_vb = CCC(K2B(val)); |
| 309 | #undef CCC |
| 310 | update_attr = true; |
| 311 | } else if (property == priv->colorkey_min_prop) { |
| 312 | dplane->prop.colorkey_yr &= ~0x00ff0000; |
| 313 | dplane->prop.colorkey_yr |= K2R(val) << 16; |
| 314 | dplane->prop.colorkey_ug &= ~0x00ff0000; |
| 315 | dplane->prop.colorkey_ug |= K2G(val) << 16; |
| 316 | dplane->prop.colorkey_vb &= ~0x00ff0000; |
| 317 | dplane->prop.colorkey_vb |= K2B(val) << 16; |
| 318 | update_attr = true; |
| 319 | } else if (property == priv->colorkey_max_prop) { |
| 320 | dplane->prop.colorkey_yr &= ~0xff000000; |
| 321 | dplane->prop.colorkey_yr |= K2R(val) << 24; |
| 322 | dplane->prop.colorkey_ug &= ~0xff000000; |
| 323 | dplane->prop.colorkey_ug |= K2G(val) << 24; |
| 324 | dplane->prop.colorkey_vb &= ~0xff000000; |
| 325 | dplane->prop.colorkey_vb |= K2B(val) << 24; |
| 326 | update_attr = true; |
| 327 | } else if (property == priv->colorkey_val_prop) { |
| 328 | dplane->prop.colorkey_yr &= ~0x0000ff00; |
| 329 | dplane->prop.colorkey_yr |= K2R(val) << 8; |
| 330 | dplane->prop.colorkey_ug &= ~0x0000ff00; |
| 331 | dplane->prop.colorkey_ug |= K2G(val) << 8; |
| 332 | dplane->prop.colorkey_vb &= ~0x0000ff00; |
| 333 | dplane->prop.colorkey_vb |= K2B(val) << 8; |
| 334 | update_attr = true; |
| 335 | } else if (property == priv->colorkey_alpha_prop) { |
| 336 | dplane->prop.colorkey_yr &= ~0x000000ff; |
| 337 | dplane->prop.colorkey_yr |= K2R(val); |
| 338 | dplane->prop.colorkey_ug &= ~0x000000ff; |
| 339 | dplane->prop.colorkey_ug |= K2G(val); |
| 340 | dplane->prop.colorkey_vb &= ~0x000000ff; |
| 341 | dplane->prop.colorkey_vb |= K2B(val); |
| 342 | update_attr = true; |
| 343 | } else if (property == priv->colorkey_mode_prop) { |
| 344 | dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK; |
| 345 | dplane->prop.colorkey_mode |= CFG_CKMODE(val); |
| 346 | update_attr = true; |
| 347 | } else if (property == priv->brightness_prop) { |
| 348 | dplane->prop.brightness = val - 256; |
| 349 | update_attr = true; |
| 350 | } else if (property == priv->contrast_prop) { |
| 351 | dplane->prop.contrast = val; |
| 352 | update_attr = true; |
| 353 | } else if (property == priv->saturation_prop) { |
| 354 | dplane->prop.saturation = val; |
| 355 | update_attr = true; |
| 356 | } |
| 357 | |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 358 | if (update_attr && dplane->base.base.crtc) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 359 | armada_ovl_update_attr(&dplane->prop, |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 360 | drm_to_armada_crtc(dplane->base.base.crtc)); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 365 | static const struct drm_plane_funcs armada_ovl_plane_funcs = { |
| 366 | .update_plane = armada_ovl_plane_update, |
| 367 | .disable_plane = armada_ovl_plane_disable, |
| 368 | .destroy = armada_ovl_plane_destroy, |
| 369 | .set_property = armada_ovl_plane_set_property, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 370 | }; |
| 371 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 372 | static const uint32_t armada_ovl_formats[] = { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 373 | DRM_FORMAT_UYVY, |
| 374 | DRM_FORMAT_YUYV, |
| 375 | DRM_FORMAT_YUV420, |
| 376 | DRM_FORMAT_YVU420, |
| 377 | DRM_FORMAT_YUV422, |
| 378 | DRM_FORMAT_YVU422, |
| 379 | DRM_FORMAT_VYUY, |
| 380 | DRM_FORMAT_YVYU, |
| 381 | DRM_FORMAT_ARGB8888, |
| 382 | DRM_FORMAT_ABGR8888, |
| 383 | DRM_FORMAT_XRGB8888, |
| 384 | DRM_FORMAT_XBGR8888, |
| 385 | DRM_FORMAT_RGB888, |
| 386 | DRM_FORMAT_BGR888, |
| 387 | DRM_FORMAT_ARGB1555, |
| 388 | DRM_FORMAT_ABGR1555, |
| 389 | DRM_FORMAT_RGB565, |
| 390 | DRM_FORMAT_BGR565, |
| 391 | }; |
| 392 | |
| 393 | static struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = { |
| 394 | { CKMODE_DISABLE, "disabled" }, |
| 395 | { CKMODE_Y, "Y component" }, |
| 396 | { CKMODE_U, "U component" }, |
| 397 | { CKMODE_V, "V component" }, |
| 398 | { CKMODE_RGB, "RGB" }, |
| 399 | { CKMODE_R, "R component" }, |
| 400 | { CKMODE_G, "G component" }, |
| 401 | { CKMODE_B, "B component" }, |
| 402 | }; |
| 403 | |
| 404 | static int armada_overlay_create_properties(struct drm_device *dev) |
| 405 | { |
| 406 | struct armada_private *priv = dev->dev_private; |
| 407 | |
| 408 | if (priv->colorkey_prop) |
| 409 | return 0; |
| 410 | |
| 411 | priv->colorkey_prop = drm_property_create_range(dev, 0, |
| 412 | "colorkey", 0, 0xffffff); |
| 413 | priv->colorkey_min_prop = drm_property_create_range(dev, 0, |
| 414 | "colorkey_min", 0, 0xffffff); |
| 415 | priv->colorkey_max_prop = drm_property_create_range(dev, 0, |
| 416 | "colorkey_max", 0, 0xffffff); |
| 417 | priv->colorkey_val_prop = drm_property_create_range(dev, 0, |
| 418 | "colorkey_val", 0, 0xffffff); |
| 419 | priv->colorkey_alpha_prop = drm_property_create_range(dev, 0, |
| 420 | "colorkey_alpha", 0, 0xffffff); |
| 421 | priv->colorkey_mode_prop = drm_property_create_enum(dev, 0, |
| 422 | "colorkey_mode", |
| 423 | armada_drm_colorkey_enum_list, |
| 424 | ARRAY_SIZE(armada_drm_colorkey_enum_list)); |
| 425 | priv->brightness_prop = drm_property_create_range(dev, 0, |
| 426 | "brightness", 0, 256 + 255); |
| 427 | priv->contrast_prop = drm_property_create_range(dev, 0, |
| 428 | "contrast", 0, 0x7fff); |
| 429 | priv->saturation_prop = drm_property_create_range(dev, 0, |
| 430 | "saturation", 0, 0x7fff); |
| 431 | |
| 432 | if (!priv->colorkey_prop) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs) |
| 439 | { |
| 440 | struct armada_private *priv = dev->dev_private; |
| 441 | struct drm_mode_object *mobj; |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 442 | struct armada_ovl_plane *dplane; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 443 | int ret; |
| 444 | |
| 445 | ret = armada_overlay_create_properties(dev); |
| 446 | if (ret) |
| 447 | return ret; |
| 448 | |
| 449 | dplane = kzalloc(sizeof(*dplane), GFP_KERNEL); |
| 450 | if (!dplane) |
| 451 | return -ENOMEM; |
| 452 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame^] | 453 | ret = armada_drm_plane_init(&dplane->base); |
| 454 | if (ret) { |
| 455 | kfree(dplane); |
| 456 | return ret; |
| 457 | } |
| 458 | |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 459 | armada_drm_vbl_event_init(&dplane->vbl.update, armada_ovl_plane_vbl, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 460 | dplane); |
| 461 | |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 462 | ret = drm_universal_plane_init(dev, &dplane->base.base, crtcs, |
Russell King | d563c24 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 463 | &armada_ovl_plane_funcs, |
| 464 | armada_ovl_formats, |
| 465 | ARRAY_SIZE(armada_ovl_formats), |
| 466 | DRM_PLANE_TYPE_OVERLAY); |
Russell King | 28a2aeb | 2015-07-15 18:11:23 +0100 | [diff] [blame] | 467 | if (ret) { |
| 468 | kfree(dplane); |
| 469 | return ret; |
| 470 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 471 | |
| 472 | dplane->prop.colorkey_yr = 0xfefefe00; |
| 473 | dplane->prop.colorkey_ug = 0x01010100; |
| 474 | dplane->prop.colorkey_vb = 0x01010100; |
| 475 | dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB); |
| 476 | dplane->prop.brightness = 0; |
| 477 | dplane->prop.contrast = 0x4000; |
| 478 | dplane->prop.saturation = 0x4000; |
| 479 | |
Russell King | 561f60b | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 480 | mobj = &dplane->base.base.base; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 481 | drm_object_attach_property(mobj, priv->colorkey_prop, |
| 482 | 0x0101fe); |
| 483 | drm_object_attach_property(mobj, priv->colorkey_min_prop, |
| 484 | 0x0101fe); |
| 485 | drm_object_attach_property(mobj, priv->colorkey_max_prop, |
| 486 | 0x0101fe); |
| 487 | drm_object_attach_property(mobj, priv->colorkey_val_prop, |
| 488 | 0x0101fe); |
| 489 | drm_object_attach_property(mobj, priv->colorkey_alpha_prop, |
| 490 | 0x000000); |
| 491 | drm_object_attach_property(mobj, priv->colorkey_mode_prop, |
| 492 | CKMODE_RGB); |
| 493 | drm_object_attach_property(mobj, priv->brightness_prop, 256); |
| 494 | drm_object_attach_property(mobj, priv->contrast_prop, |
| 495 | dplane->prop.contrast); |
| 496 | drm_object_attach_property(mobj, priv->saturation_prop, |
| 497 | dplane->prop.saturation); |
| 498 | |
| 499 | return 0; |
| 500 | } |