Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) STMicroelectronics SA 2014 |
| 3 | * Authors: Vincent Abriou <vincent.abriou@st.com> |
| 4 | * Fabien Dessenne <fabien.dessenne@st.com> |
| 5 | * for STMicroelectronics. |
| 6 | * License terms: GNU General Public License (GPL), version 2 |
| 7 | */ |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 8 | |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 9 | #include <drm/drm_atomic.h> |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 10 | #include <drm/drm_fb_cma_helper.h> |
| 11 | #include <drm/drm_gem_cma_helper.h> |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 12 | |
| 13 | #include "sti_compositor.h" |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 14 | #include "sti_cursor.h" |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 15 | #include "sti_plane.h" |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 16 | #include "sti_vtg.h" |
| 17 | |
| 18 | /* Registers */ |
| 19 | #define CUR_CTL 0x00 |
| 20 | #define CUR_VPO 0x0C |
| 21 | #define CUR_PML 0x14 |
| 22 | #define CUR_PMP 0x18 |
| 23 | #define CUR_SIZE 0x1C |
| 24 | #define CUR_CML 0x20 |
| 25 | #define CUR_AWS 0x28 |
| 26 | #define CUR_AWE 0x2C |
| 27 | |
| 28 | #define CUR_CTL_CLUT_UPDATE BIT(1) |
| 29 | |
| 30 | #define STI_CURS_MIN_SIZE 1 |
| 31 | #define STI_CURS_MAX_SIZE 128 |
| 32 | |
| 33 | /* |
| 34 | * pixmap dma buffer stucture |
| 35 | * |
| 36 | * @paddr: physical address |
| 37 | * @size: buffer size |
| 38 | * @base: virtual address |
| 39 | */ |
| 40 | struct dma_pixmap { |
| 41 | dma_addr_t paddr; |
| 42 | size_t size; |
| 43 | void *base; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * STI Cursor structure |
| 48 | * |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 49 | * @sti_plane: sti_plane structure |
| 50 | * @dev: driver device |
| 51 | * @regs: cursor registers |
| 52 | * @width: cursor width |
| 53 | * @height: cursor height |
| 54 | * @clut: color look up table |
| 55 | * @clut_paddr: color look up table physical address |
| 56 | * @pixmap: pixmap dma buffer (clut8-format cursor) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 57 | */ |
| 58 | struct sti_cursor { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 59 | struct sti_plane plane; |
| 60 | struct device *dev; |
| 61 | void __iomem *regs; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 62 | unsigned int width; |
| 63 | unsigned int height; |
| 64 | unsigned short *clut; |
| 65 | dma_addr_t clut_paddr; |
| 66 | struct dma_pixmap pixmap; |
| 67 | }; |
| 68 | |
| 69 | static const uint32_t cursor_supported_formats[] = { |
| 70 | DRM_FORMAT_ARGB8888, |
| 71 | }; |
| 72 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 73 | #define to_sti_cursor(x) container_of(x, struct sti_cursor, plane) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 74 | |
Vincent Abriou | f46f3be | 2016-02-04 16:35:45 +0100 | [diff] [blame] | 75 | #define DBGFS_DUMP(reg) seq_printf(s, "\n %-25s 0x%08X", #reg, \ |
| 76 | readl(cursor->regs + reg)) |
| 77 | |
| 78 | static void cursor_dbg_vpo(struct seq_file *s, u32 val) |
| 79 | { |
| 80 | seq_printf(s, "\txdo:%4d\tydo:%4d", val & 0x0FFF, (val >> 16) & 0x0FFF); |
| 81 | } |
| 82 | |
| 83 | static void cursor_dbg_size(struct seq_file *s, u32 val) |
| 84 | { |
| 85 | seq_printf(s, "\t%d x %d", val & 0x07FF, (val >> 16) & 0x07FF); |
| 86 | } |
| 87 | |
| 88 | static void cursor_dbg_pml(struct seq_file *s, |
| 89 | struct sti_cursor *cursor, u32 val) |
| 90 | { |
| 91 | if (cursor->pixmap.paddr == val) |
| 92 | seq_printf(s, "\tVirt @: %p", cursor->pixmap.base); |
| 93 | } |
| 94 | |
| 95 | static void cursor_dbg_cml(struct seq_file *s, |
| 96 | struct sti_cursor *cursor, u32 val) |
| 97 | { |
| 98 | if (cursor->clut_paddr == val) |
| 99 | seq_printf(s, "\tVirt @: %p", cursor->clut); |
| 100 | } |
| 101 | |
| 102 | static int cursor_dbg_show(struct seq_file *s, void *data) |
| 103 | { |
| 104 | struct drm_info_node *node = s->private; |
| 105 | struct sti_cursor *cursor = (struct sti_cursor *)node->info_ent->data; |
| 106 | struct drm_device *dev = node->minor->dev; |
| 107 | int ret; |
| 108 | |
| 109 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 110 | if (ret) |
| 111 | return ret; |
| 112 | |
| 113 | seq_printf(s, "%s: (vaddr = 0x%p)", |
| 114 | sti_plane_to_str(&cursor->plane), cursor->regs); |
| 115 | |
| 116 | DBGFS_DUMP(CUR_CTL); |
| 117 | DBGFS_DUMP(CUR_VPO); |
| 118 | cursor_dbg_vpo(s, readl(cursor->regs + CUR_VPO)); |
| 119 | DBGFS_DUMP(CUR_PML); |
| 120 | cursor_dbg_pml(s, cursor, readl(cursor->regs + CUR_PML)); |
| 121 | DBGFS_DUMP(CUR_PMP); |
| 122 | DBGFS_DUMP(CUR_SIZE); |
| 123 | cursor_dbg_size(s, readl(cursor->regs + CUR_SIZE)); |
| 124 | DBGFS_DUMP(CUR_CML); |
| 125 | cursor_dbg_cml(s, cursor, readl(cursor->regs + CUR_CML)); |
| 126 | DBGFS_DUMP(CUR_AWS); |
| 127 | DBGFS_DUMP(CUR_AWE); |
| 128 | seq_puts(s, "\n"); |
| 129 | |
| 130 | mutex_unlock(&dev->struct_mutex); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static struct drm_info_list cursor_debugfs_files[] = { |
| 135 | { "cursor", cursor_dbg_show, 0, NULL }, |
| 136 | }; |
| 137 | |
| 138 | static int cursor_debugfs_init(struct sti_cursor *cursor, |
| 139 | struct drm_minor *minor) |
| 140 | { |
| 141 | unsigned int i; |
| 142 | |
| 143 | for (i = 0; i < ARRAY_SIZE(cursor_debugfs_files); i++) |
| 144 | cursor_debugfs_files[i].data = cursor; |
| 145 | |
| 146 | return drm_debugfs_create_files(cursor_debugfs_files, |
| 147 | ARRAY_SIZE(cursor_debugfs_files), |
| 148 | minor->debugfs_root, minor); |
| 149 | } |
| 150 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 151 | static void sti_cursor_argb8888_to_clut8(struct sti_cursor *cursor, u32 *src) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 152 | { |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 153 | u8 *dst = cursor->pixmap.base; |
| 154 | unsigned int i, j; |
| 155 | u32 a, r, g, b; |
| 156 | |
| 157 | for (i = 0; i < cursor->height; i++) { |
| 158 | for (j = 0; j < cursor->width; j++) { |
| 159 | /* Pick the 2 higher bits of each component */ |
| 160 | a = (*src >> 30) & 3; |
| 161 | r = (*src >> 22) & 3; |
| 162 | g = (*src >> 14) & 3; |
| 163 | b = (*src >> 6) & 3; |
| 164 | *dst = a << 6 | r << 4 | g << 2 | b; |
| 165 | src++; |
| 166 | dst++; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 171 | static void sti_cursor_init(struct sti_cursor *cursor) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 172 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 173 | unsigned short *base = cursor->clut; |
| 174 | unsigned int a, r, g, b; |
| 175 | |
| 176 | /* Assign CLUT values, ARGB444 format */ |
| 177 | for (a = 0; a < 4; a++) |
| 178 | for (r = 0; r < 4; r++) |
| 179 | for (g = 0; g < 4; g++) |
| 180 | for (b = 0; b < 4; b++) |
| 181 | *base++ = (a * 5) << 12 | |
| 182 | (r * 5) << 8 | |
| 183 | (g * 5) << 4 | |
| 184 | (b * 5); |
| 185 | } |
| 186 | |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 187 | static int sti_cursor_atomic_check(struct drm_plane *drm_plane, |
| 188 | struct drm_plane_state *state) |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 189 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 190 | struct sti_plane *plane = to_sti_plane(drm_plane); |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 191 | struct sti_cursor *cursor = to_sti_cursor(plane); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 192 | struct drm_crtc *crtc = state->crtc; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 193 | struct drm_framebuffer *fb = state->fb; |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 194 | struct drm_crtc_state *crtc_state; |
| 195 | struct drm_display_mode *mode; |
| 196 | int dst_x, dst_y, dst_w, dst_h; |
| 197 | int src_w, src_h; |
| 198 | |
| 199 | /* no need for further checks if the plane is being disabled */ |
| 200 | if (!crtc || !fb) |
| 201 | return 0; |
| 202 | |
| 203 | crtc_state = drm_atomic_get_crtc_state(state->state, crtc); |
| 204 | mode = &crtc_state->mode; |
| 205 | dst_x = state->crtc_x; |
| 206 | dst_y = state->crtc_y; |
| 207 | dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x); |
| 208 | dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 209 | /* src_x are in 16.16 format */ |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 210 | src_w = state->src_w >> 16; |
| 211 | src_h = state->src_h >> 16; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 212 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 213 | if (src_w < STI_CURS_MIN_SIZE || |
| 214 | src_h < STI_CURS_MIN_SIZE || |
| 215 | src_w > STI_CURS_MAX_SIZE || |
| 216 | src_h > STI_CURS_MAX_SIZE) { |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 217 | DRM_ERROR("Invalid cursor size (%dx%d)\n", |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 218 | src_w, src_h); |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 219 | return -EINVAL; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* If the cursor size has changed, re-allocated the pixmap */ |
| 223 | if (!cursor->pixmap.base || |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 224 | (cursor->width != src_w) || |
| 225 | (cursor->height != src_h)) { |
| 226 | cursor->width = src_w; |
| 227 | cursor->height = src_h; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 228 | |
| 229 | if (cursor->pixmap.base) |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 230 | dma_free_writecombine(cursor->dev, |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 231 | cursor->pixmap.size, |
| 232 | cursor->pixmap.base, |
| 233 | cursor->pixmap.paddr); |
| 234 | |
| 235 | cursor->pixmap.size = cursor->width * cursor->height; |
| 236 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 237 | cursor->pixmap.base = dma_alloc_writecombine(cursor->dev, |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 238 | cursor->pixmap.size, |
| 239 | &cursor->pixmap.paddr, |
| 240 | GFP_KERNEL | GFP_DMA); |
| 241 | if (!cursor->pixmap.base) { |
| 242 | DRM_ERROR("Failed to allocate memory for pixmap\n"); |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 243 | return -EINVAL; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 247 | if (!drm_fb_cma_get_gem_obj(fb, 0)) { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 248 | DRM_ERROR("Can't get CMA GEM object for fb\n"); |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 249 | return -EINVAL; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 252 | DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n", |
| 253 | crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)), |
| 254 | drm_plane->base.id, sti_plane_to_str(plane)); |
| 255 | DRM_DEBUG_KMS("(%dx%d)@(%d,%d)\n", dst_w, dst_h, dst_x, dst_y); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void sti_cursor_atomic_update(struct drm_plane *drm_plane, |
| 261 | struct drm_plane_state *oldstate) |
| 262 | { |
| 263 | struct drm_plane_state *state = drm_plane->state; |
| 264 | struct sti_plane *plane = to_sti_plane(drm_plane); |
| 265 | struct sti_cursor *cursor = to_sti_cursor(plane); |
| 266 | struct drm_crtc *crtc = state->crtc; |
| 267 | struct drm_framebuffer *fb = state->fb; |
| 268 | struct drm_display_mode *mode; |
| 269 | int dst_x, dst_y; |
| 270 | struct drm_gem_cma_object *cma_obj; |
| 271 | u32 y, x; |
| 272 | u32 val; |
| 273 | |
| 274 | if (!crtc || !fb) |
| 275 | return; |
| 276 | |
| 277 | mode = &crtc->mode; |
| 278 | dst_x = state->crtc_x; |
| 279 | dst_y = state->crtc_y; |
| 280 | |
| 281 | cma_obj = drm_fb_cma_get_gem_obj(fb, 0); |
| 282 | |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 283 | /* Convert ARGB8888 to CLUT8 */ |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 284 | sti_cursor_argb8888_to_clut8(cursor, (u32 *)cma_obj->vaddr); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 285 | |
| 286 | /* AWS and AWE depend on the mode */ |
| 287 | y = sti_vtg_get_line_number(*mode, 0); |
| 288 | x = sti_vtg_get_pixel_number(*mode, 0); |
| 289 | val = y << 16 | x; |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 290 | writel(val, cursor->regs + CUR_AWS); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 291 | y = sti_vtg_get_line_number(*mode, mode->vdisplay - 1); |
| 292 | x = sti_vtg_get_pixel_number(*mode, mode->hdisplay - 1); |
| 293 | val = y << 16 | x; |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 294 | writel(val, cursor->regs + CUR_AWE); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 295 | |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 296 | /* Set memory location, size, and position */ |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 297 | writel(cursor->pixmap.paddr, cursor->regs + CUR_PML); |
| 298 | writel(cursor->width, cursor->regs + CUR_PMP); |
| 299 | writel(cursor->height << 16 | cursor->width, cursor->regs + CUR_SIZE); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 300 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 301 | y = sti_vtg_get_line_number(*mode, dst_y); |
benjamin.gaignard@linaro.org | b83a8b5 | 2016-01-07 14:51:06 +0100 | [diff] [blame] | 302 | x = sti_vtg_get_pixel_number(*mode, dst_x); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 303 | writel((y << 16) | x, cursor->regs + CUR_VPO); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 304 | |
Fabien Dessenne | 0b9d041 | 2016-01-25 17:58:48 +0100 | [diff] [blame] | 305 | /* Set and fetch CLUT */ |
| 306 | writel(cursor->clut_paddr, cursor->regs + CUR_CML); |
| 307 | writel(CUR_CTL_CLUT_UPDATE, cursor->regs + CUR_CTL); |
| 308 | |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame^] | 309 | sti_plane_update_fps(plane, true, false); |
| 310 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 311 | plane->status = STI_PLANE_UPDATED; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 314 | static void sti_cursor_atomic_disable(struct drm_plane *drm_plane, |
| 315 | struct drm_plane_state *oldstate) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 316 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 317 | struct sti_plane *plane = to_sti_plane(drm_plane); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 318 | |
| 319 | if (!drm_plane->crtc) { |
| 320 | DRM_DEBUG_DRIVER("drm plane:%d not enabled\n", |
| 321 | drm_plane->base.id); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n", |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 326 | drm_plane->crtc->base.id, |
| 327 | sti_mixer_to_str(to_sti_mixer(drm_plane->crtc)), |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 328 | drm_plane->base.id, sti_plane_to_str(plane)); |
| 329 | |
| 330 | plane->status = STI_PLANE_DISABLING; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 333 | static const struct drm_plane_helper_funcs sti_cursor_helpers_funcs = { |
Vincent Abriou | dd86dc2 | 2016-02-10 10:48:20 +0100 | [diff] [blame] | 334 | .atomic_check = sti_cursor_atomic_check, |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 335 | .atomic_update = sti_cursor_atomic_update, |
| 336 | .atomic_disable = sti_cursor_atomic_disable, |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 337 | }; |
| 338 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 339 | struct drm_plane *sti_cursor_create(struct drm_device *drm_dev, |
| 340 | struct device *dev, int desc, |
| 341 | void __iomem *baseaddr, |
| 342 | unsigned int possible_crtcs) |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 343 | { |
| 344 | struct sti_cursor *cursor; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 345 | size_t size; |
| 346 | int res; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 347 | |
| 348 | cursor = devm_kzalloc(dev, sizeof(*cursor), GFP_KERNEL); |
| 349 | if (!cursor) { |
| 350 | DRM_ERROR("Failed to allocate memory for cursor\n"); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | /* Allocate clut buffer */ |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 355 | size = 0x100 * sizeof(unsigned short); |
| 356 | cursor->clut = dma_alloc_writecombine(dev, size, &cursor->clut_paddr, |
| 357 | GFP_KERNEL | GFP_DMA); |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 358 | |
| 359 | if (!cursor->clut) { |
| 360 | DRM_ERROR("Failed to allocate memory for cursor clut\n"); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 361 | goto err_clut; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 364 | cursor->dev = dev; |
| 365 | cursor->regs = baseaddr; |
| 366 | cursor->plane.desc = desc; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 367 | cursor->plane.status = STI_PLANE_DISABLED; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 368 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 369 | sti_cursor_init(cursor); |
| 370 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 371 | res = drm_universal_plane_init(drm_dev, &cursor->plane.drm_plane, |
| 372 | possible_crtcs, |
| 373 | &sti_plane_helpers_funcs, |
| 374 | cursor_supported_formats, |
| 375 | ARRAY_SIZE(cursor_supported_formats), |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 376 | DRM_PLANE_TYPE_CURSOR, NULL); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 377 | if (res) { |
| 378 | DRM_ERROR("Failed to initialize universal plane\n"); |
| 379 | goto err_plane; |
| 380 | } |
| 381 | |
| 382 | drm_plane_helper_add(&cursor->plane.drm_plane, |
| 383 | &sti_cursor_helpers_funcs); |
| 384 | |
| 385 | sti_plane_init_property(&cursor->plane, DRM_PLANE_TYPE_CURSOR); |
| 386 | |
Vincent Abriou | f46f3be | 2016-02-04 16:35:45 +0100 | [diff] [blame] | 387 | if (cursor_debugfs_init(cursor, drm_dev->primary)) |
| 388 | DRM_ERROR("CURSOR debugfs setup failed\n"); |
| 389 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 390 | return &cursor->plane.drm_plane; |
| 391 | |
| 392 | err_plane: |
| 393 | dma_free_writecombine(dev, size, cursor->clut, cursor->clut_paddr); |
| 394 | err_clut: |
| 395 | devm_kfree(dev, cursor); |
| 396 | return NULL; |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 397 | } |