Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
| 3 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. |
| 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 | |
| 10 | #include <linux/clk.h> |
Thierry Reding | 9eb9b22 | 2013-09-24 16:32:47 +0200 | [diff] [blame] | 11 | #include <linux/debugfs.h> |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 12 | #include <linux/iommu.h> |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 13 | #include <linux/reset.h> |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 14 | |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 15 | #include <soc/tegra/pmc.h> |
| 16 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 17 | #include "dc.h" |
| 18 | #include "drm.h" |
| 19 | #include "gem.h" |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 20 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 21 | #include <drm/drm_atomic_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 22 | #include <drm/drm_plane_helper.h> |
| 23 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 24 | struct tegra_dc_soc_info { |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 25 | bool supports_border_color; |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 26 | bool supports_interlacing; |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 27 | bool supports_cursor; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 28 | bool supports_block_linear; |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 29 | unsigned int pitch_align; |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 30 | bool has_powergate; |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 33 | struct tegra_plane { |
| 34 | struct drm_plane base; |
| 35 | unsigned int index; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 38 | static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane) |
| 39 | { |
| 40 | return container_of(plane, struct tegra_plane, base); |
| 41 | } |
| 42 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 43 | static void tegra_dc_window_commit(struct tegra_dc *dc, unsigned int index) |
| 44 | { |
| 45 | u32 value = WIN_A_ACT_REQ << index; |
| 46 | |
| 47 | tegra_dc_writel(dc, value << 8, DC_CMD_STATE_CONTROL); |
| 48 | tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); |
| 49 | } |
| 50 | |
| 51 | static void tegra_dc_cursor_commit(struct tegra_dc *dc) |
| 52 | { |
| 53 | tegra_dc_writel(dc, CURSOR_ACT_REQ << 8, DC_CMD_STATE_CONTROL); |
| 54 | tegra_dc_writel(dc, CURSOR_ACT_REQ, DC_CMD_STATE_CONTROL); |
| 55 | } |
| 56 | |
Thierry Reding | d700ba7 | 2014-12-08 15:50:04 +0100 | [diff] [blame] | 57 | /* |
Thierry Reding | 86df256 | 2014-12-08 16:03:53 +0100 | [diff] [blame] | 58 | * Reads the active copy of a register. This takes the dc->lock spinlock to |
| 59 | * prevent races with the VBLANK processing which also needs access to the |
| 60 | * active copy of some registers. |
| 61 | */ |
| 62 | static u32 tegra_dc_readl_active(struct tegra_dc *dc, unsigned long offset) |
| 63 | { |
| 64 | unsigned long flags; |
| 65 | u32 value; |
| 66 | |
| 67 | spin_lock_irqsave(&dc->lock, flags); |
| 68 | |
| 69 | tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); |
| 70 | value = tegra_dc_readl(dc, offset); |
| 71 | tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); |
| 72 | |
| 73 | spin_unlock_irqrestore(&dc->lock, flags); |
| 74 | return value; |
| 75 | } |
| 76 | |
| 77 | /* |
Thierry Reding | d700ba7 | 2014-12-08 15:50:04 +0100 | [diff] [blame] | 78 | * Double-buffered registers have two copies: ASSEMBLY and ACTIVE. When the |
| 79 | * *_ACT_REQ bits are set the ASSEMBLY copy is latched into the ACTIVE copy. |
| 80 | * Latching happens mmediately if the display controller is in STOP mode or |
| 81 | * on the next frame boundary otherwise. |
| 82 | * |
| 83 | * Triple-buffered registers have three copies: ASSEMBLY, ARM and ACTIVE. The |
| 84 | * ASSEMBLY copy is latched into the ARM copy immediately after *_UPDATE bits |
| 85 | * are written. When the *_ACT_REQ bits are written, the ARM copy is latched |
| 86 | * into the ACTIVE copy, either immediately if the display controller is in |
| 87 | * STOP mode, or at the next frame boundary otherwise. |
| 88 | */ |
Thierry Reding | 62b9e06 | 2014-11-21 17:33:33 +0100 | [diff] [blame] | 89 | void tegra_dc_commit(struct tegra_dc *dc) |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 90 | { |
| 91 | tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL); |
| 92 | tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL); |
| 93 | } |
| 94 | |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 95 | static unsigned int tegra_dc_format(uint32_t format, uint32_t *swap) |
| 96 | { |
| 97 | /* assume no swapping of fetched data */ |
| 98 | if (swap) |
| 99 | *swap = BYTE_SWAP_NOSWAP; |
| 100 | |
| 101 | switch (format) { |
| 102 | case DRM_FORMAT_XBGR8888: |
| 103 | return WIN_COLOR_DEPTH_R8G8B8A8; |
| 104 | |
| 105 | case DRM_FORMAT_XRGB8888: |
| 106 | return WIN_COLOR_DEPTH_B8G8R8A8; |
| 107 | |
| 108 | case DRM_FORMAT_RGB565: |
| 109 | return WIN_COLOR_DEPTH_B5G6R5; |
| 110 | |
| 111 | case DRM_FORMAT_UYVY: |
| 112 | return WIN_COLOR_DEPTH_YCbCr422; |
| 113 | |
| 114 | case DRM_FORMAT_YUYV: |
| 115 | if (swap) |
| 116 | *swap = BYTE_SWAP_SWAP2; |
| 117 | |
| 118 | return WIN_COLOR_DEPTH_YCbCr422; |
| 119 | |
| 120 | case DRM_FORMAT_YUV420: |
| 121 | return WIN_COLOR_DEPTH_YCbCr420P; |
| 122 | |
| 123 | case DRM_FORMAT_YUV422: |
| 124 | return WIN_COLOR_DEPTH_YCbCr422P; |
| 125 | |
| 126 | default: |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | WARN(1, "unsupported pixel format %u, using default\n", format); |
| 131 | return WIN_COLOR_DEPTH_B8G8R8A8; |
| 132 | } |
| 133 | |
| 134 | static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar) |
| 135 | { |
| 136 | switch (format) { |
| 137 | case WIN_COLOR_DEPTH_YCbCr422: |
| 138 | case WIN_COLOR_DEPTH_YUV422: |
| 139 | if (planar) |
| 140 | *planar = false; |
| 141 | |
| 142 | return true; |
| 143 | |
| 144 | case WIN_COLOR_DEPTH_YCbCr420P: |
| 145 | case WIN_COLOR_DEPTH_YUV420P: |
| 146 | case WIN_COLOR_DEPTH_YCbCr422P: |
| 147 | case WIN_COLOR_DEPTH_YUV422P: |
| 148 | case WIN_COLOR_DEPTH_YCbCr422R: |
| 149 | case WIN_COLOR_DEPTH_YUV422R: |
| 150 | case WIN_COLOR_DEPTH_YCbCr422RA: |
| 151 | case WIN_COLOR_DEPTH_YUV422RA: |
| 152 | if (planar) |
| 153 | *planar = true; |
| 154 | |
| 155 | return true; |
| 156 | } |
| 157 | |
Thierry Reding | fb35c6b | 2014-12-08 15:55:28 +0100 | [diff] [blame] | 158 | if (planar) |
| 159 | *planar = false; |
| 160 | |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 161 | return false; |
| 162 | } |
| 163 | |
| 164 | static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v, |
| 165 | unsigned int bpp) |
| 166 | { |
| 167 | fixed20_12 outf = dfixed_init(out); |
| 168 | fixed20_12 inf = dfixed_init(in); |
| 169 | u32 dda_inc; |
| 170 | int max; |
| 171 | |
| 172 | if (v) |
| 173 | max = 15; |
| 174 | else { |
| 175 | switch (bpp) { |
| 176 | case 2: |
| 177 | max = 8; |
| 178 | break; |
| 179 | |
| 180 | default: |
| 181 | WARN_ON_ONCE(1); |
| 182 | /* fallthrough */ |
| 183 | case 4: |
| 184 | max = 4; |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1)); |
| 190 | inf.full -= dfixed_const(1); |
| 191 | |
| 192 | dda_inc = dfixed_div(inf, outf); |
| 193 | dda_inc = min_t(u32, dda_inc, dfixed_const(max)); |
| 194 | |
| 195 | return dda_inc; |
| 196 | } |
| 197 | |
| 198 | static inline u32 compute_initial_dda(unsigned int in) |
| 199 | { |
| 200 | fixed20_12 inf = dfixed_init(in); |
| 201 | return dfixed_frac(inf); |
| 202 | } |
| 203 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 204 | static void tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, |
| 205 | const struct tegra_dc_window *window) |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 206 | { |
| 207 | unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp; |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 208 | unsigned long value, flags; |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 209 | bool yuv, planar; |
| 210 | |
| 211 | /* |
| 212 | * For YUV planar modes, the number of bytes per pixel takes into |
| 213 | * account only the luma component and therefore is 1. |
| 214 | */ |
| 215 | yuv = tegra_dc_format_is_yuv(window->format, &planar); |
| 216 | if (!yuv) |
| 217 | bpp = window->bits_per_pixel / 8; |
| 218 | else |
| 219 | bpp = planar ? 1 : 2; |
| 220 | |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 221 | spin_lock_irqsave(&dc->lock, flags); |
| 222 | |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 223 | value = WINDOW_A_SELECT << index; |
| 224 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 225 | |
| 226 | tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH); |
| 227 | tegra_dc_writel(dc, window->swap, DC_WIN_BYTE_SWAP); |
| 228 | |
| 229 | value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x); |
| 230 | tegra_dc_writel(dc, value, DC_WIN_POSITION); |
| 231 | |
| 232 | value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w); |
| 233 | tegra_dc_writel(dc, value, DC_WIN_SIZE); |
| 234 | |
| 235 | h_offset = window->src.x * bpp; |
| 236 | v_offset = window->src.y; |
| 237 | h_size = window->src.w * bpp; |
| 238 | v_size = window->src.h; |
| 239 | |
| 240 | value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size); |
| 241 | tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE); |
| 242 | |
| 243 | /* |
| 244 | * For DDA computations the number of bytes per pixel for YUV planar |
| 245 | * modes needs to take into account all Y, U and V components. |
| 246 | */ |
| 247 | if (yuv && planar) |
| 248 | bpp = 2; |
| 249 | |
| 250 | h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp); |
| 251 | v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp); |
| 252 | |
| 253 | value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda); |
| 254 | tegra_dc_writel(dc, value, DC_WIN_DDA_INC); |
| 255 | |
| 256 | h_dda = compute_initial_dda(window->src.x); |
| 257 | v_dda = compute_initial_dda(window->src.y); |
| 258 | |
| 259 | tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA); |
| 260 | tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA); |
| 261 | |
| 262 | tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE); |
| 263 | tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE); |
| 264 | |
| 265 | tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR); |
| 266 | |
| 267 | if (yuv && planar) { |
| 268 | tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U); |
| 269 | tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V); |
| 270 | value = window->stride[1] << 16 | window->stride[0]; |
| 271 | tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE); |
| 272 | } else { |
| 273 | tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE); |
| 274 | } |
| 275 | |
| 276 | if (window->bottom_up) |
| 277 | v_offset += window->src.h - 1; |
| 278 | |
| 279 | tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET); |
| 280 | tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET); |
| 281 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 282 | if (dc->soc->supports_block_linear) { |
| 283 | unsigned long height = window->tiling.value; |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 284 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 285 | switch (window->tiling.mode) { |
| 286 | case TEGRA_BO_TILING_MODE_PITCH: |
| 287 | value = DC_WINBUF_SURFACE_KIND_PITCH; |
| 288 | break; |
| 289 | |
| 290 | case TEGRA_BO_TILING_MODE_TILED: |
| 291 | value = DC_WINBUF_SURFACE_KIND_TILED; |
| 292 | break; |
| 293 | |
| 294 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 295 | value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) | |
| 296 | DC_WINBUF_SURFACE_KIND_BLOCK; |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND); |
| 301 | } else { |
| 302 | switch (window->tiling.mode) { |
| 303 | case TEGRA_BO_TILING_MODE_PITCH: |
| 304 | value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | |
| 305 | DC_WIN_BUFFER_ADDR_MODE_LINEAR; |
| 306 | break; |
| 307 | |
| 308 | case TEGRA_BO_TILING_MODE_TILED: |
| 309 | value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV | |
| 310 | DC_WIN_BUFFER_ADDR_MODE_TILE; |
| 311 | break; |
| 312 | |
| 313 | case TEGRA_BO_TILING_MODE_BLOCK: |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 314 | /* |
| 315 | * No need to handle this here because ->atomic_check |
| 316 | * will already have filtered it out. |
| 317 | */ |
| 318 | break; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE); |
| 322 | } |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 323 | |
| 324 | value = WIN_ENABLE; |
| 325 | |
| 326 | if (yuv) { |
| 327 | /* setup default colorspace conversion coefficients */ |
| 328 | tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF); |
| 329 | tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB); |
| 330 | tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR); |
| 331 | tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR); |
| 332 | tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG); |
| 333 | tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG); |
| 334 | tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB); |
| 335 | tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB); |
| 336 | |
| 337 | value |= CSC_ENABLE; |
| 338 | } else if (window->bits_per_pixel < 24) { |
| 339 | value |= COLOR_EXPAND; |
| 340 | } |
| 341 | |
| 342 | if (window->bottom_up) |
| 343 | value |= V_DIRECTION; |
| 344 | |
| 345 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 346 | |
| 347 | /* |
| 348 | * Disable blending and assume Window A is the bottom-most window, |
| 349 | * Window C is the top-most window and Window B is in the middle. |
| 350 | */ |
| 351 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY); |
| 352 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN); |
| 353 | |
| 354 | switch (index) { |
| 355 | case 0: |
| 356 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X); |
| 357 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); |
| 358 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); |
| 359 | break; |
| 360 | |
| 361 | case 1: |
| 362 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); |
| 363 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); |
| 364 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); |
| 365 | break; |
| 366 | |
| 367 | case 2: |
| 368 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); |
| 369 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y); |
| 370 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY); |
| 371 | break; |
| 372 | } |
| 373 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 374 | tegra_dc_window_commit(dc, index); |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 375 | |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 376 | spin_unlock_irqrestore(&dc->lock, flags); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static void tegra_plane_destroy(struct drm_plane *plane) |
| 380 | { |
| 381 | struct tegra_plane *p = to_tegra_plane(plane); |
| 382 | |
| 383 | drm_plane_cleanup(plane); |
| 384 | kfree(p); |
| 385 | } |
| 386 | |
| 387 | static const u32 tegra_primary_plane_formats[] = { |
| 388 | DRM_FORMAT_XBGR8888, |
| 389 | DRM_FORMAT_XRGB8888, |
| 390 | DRM_FORMAT_RGB565, |
| 391 | }; |
| 392 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 393 | static void tegra_primary_plane_destroy(struct drm_plane *plane) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 394 | { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 395 | tegra_plane_destroy(plane); |
| 396 | } |
| 397 | |
| 398 | static const struct drm_plane_funcs tegra_primary_plane_funcs = { |
| 399 | .update_plane = drm_plane_helper_update, |
| 400 | .disable_plane = drm_plane_helper_disable, |
| 401 | .destroy = tegra_primary_plane_destroy, |
| 402 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
| 403 | }; |
| 404 | |
| 405 | static int tegra_plane_prepare_fb(struct drm_plane *plane, |
| 406 | struct drm_framebuffer *fb) |
| 407 | { |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | static void tegra_plane_cleanup_fb(struct drm_plane *plane, |
| 412 | struct drm_framebuffer *fb) |
| 413 | { |
| 414 | } |
| 415 | |
| 416 | static int tegra_plane_atomic_check(struct drm_plane *plane, |
| 417 | struct drm_plane_state *state) |
| 418 | { |
| 419 | struct tegra_dc *dc = to_tegra_dc(state->crtc); |
| 420 | struct tegra_bo_tiling tiling; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 421 | int err; |
| 422 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 423 | /* no need for further checks if the plane is being disabled */ |
| 424 | if (!state->crtc) |
| 425 | return 0; |
| 426 | |
| 427 | err = tegra_fb_get_tiling(state->fb, &tiling); |
| 428 | if (err < 0) |
| 429 | return err; |
| 430 | |
| 431 | if (tiling.mode == TEGRA_BO_TILING_MODE_BLOCK && |
| 432 | !dc->soc->supports_block_linear) { |
| 433 | DRM_ERROR("hardware doesn't support block linear mode\n"); |
| 434 | return -EINVAL; |
| 435 | } |
| 436 | |
| 437 | /* |
| 438 | * Tegra doesn't support different strides for U and V planes so we |
| 439 | * error out if the user tries to display a framebuffer with such a |
| 440 | * configuration. |
| 441 | */ |
| 442 | if (drm_format_num_planes(state->fb->pixel_format) > 2) { |
| 443 | if (state->fb->pitches[2] != state->fb->pitches[1]) { |
| 444 | DRM_ERROR("unsupported UV-plane configuration\n"); |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static void tegra_plane_atomic_update(struct drm_plane *plane, |
| 453 | struct drm_plane_state *old_state) |
| 454 | { |
| 455 | struct tegra_dc *dc = to_tegra_dc(plane->state->crtc); |
| 456 | struct drm_framebuffer *fb = plane->state->fb; |
| 457 | struct tegra_plane *p = to_tegra_plane(plane); |
| 458 | struct tegra_dc_window window; |
| 459 | unsigned int i; |
| 460 | int err; |
| 461 | |
| 462 | /* rien ne va plus */ |
| 463 | if (!plane->state->crtc || !plane->state->fb) |
| 464 | return; |
| 465 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 466 | memset(&window, 0, sizeof(window)); |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 467 | window.src.x = plane->state->src_x >> 16; |
| 468 | window.src.y = plane->state->src_y >> 16; |
| 469 | window.src.w = plane->state->src_w >> 16; |
| 470 | window.src.h = plane->state->src_h >> 16; |
| 471 | window.dst.x = plane->state->crtc_x; |
| 472 | window.dst.y = plane->state->crtc_y; |
| 473 | window.dst.w = plane->state->crtc_w; |
| 474 | window.dst.h = plane->state->crtc_h; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 475 | window.format = tegra_dc_format(fb->pixel_format, &window.swap); |
| 476 | window.bits_per_pixel = fb->bits_per_pixel; |
| 477 | window.bottom_up = tegra_fb_is_bottom_up(fb); |
| 478 | |
| 479 | err = tegra_fb_get_tiling(fb, &window.tiling); |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 480 | WARN_ON(err < 0); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 481 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 482 | for (i = 0; i < drm_format_num_planes(fb->pixel_format); i++) { |
| 483 | struct tegra_bo *bo = tegra_fb_get_plane(fb, i); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 484 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 485 | window.base[i] = bo->paddr + fb->offsets[i]; |
| 486 | window.stride[i] = fb->pitches[i]; |
| 487 | } |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 488 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 489 | tegra_dc_setup_window(dc, p->index, &window); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 492 | static void tegra_plane_atomic_disable(struct drm_plane *plane, |
| 493 | struct drm_plane_state *old_state) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 494 | { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 495 | struct tegra_plane *p = to_tegra_plane(plane); |
| 496 | struct tegra_dc *dc; |
| 497 | unsigned long flags; |
| 498 | u32 value; |
| 499 | |
| 500 | /* rien ne va plus */ |
| 501 | if (!old_state || !old_state->crtc) |
| 502 | return; |
| 503 | |
| 504 | dc = to_tegra_dc(old_state->crtc); |
| 505 | |
| 506 | spin_lock_irqsave(&dc->lock, flags); |
| 507 | |
| 508 | value = WINDOW_A_SELECT << p->index; |
| 509 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 510 | |
| 511 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
| 512 | value &= ~WIN_ENABLE; |
| 513 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 514 | |
| 515 | tegra_dc_window_commit(dc, p->index); |
| 516 | |
| 517 | spin_unlock_irqrestore(&dc->lock, flags); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 520 | static const struct drm_plane_helper_funcs tegra_primary_plane_helper_funcs = { |
| 521 | .prepare_fb = tegra_plane_prepare_fb, |
| 522 | .cleanup_fb = tegra_plane_cleanup_fb, |
| 523 | .atomic_check = tegra_plane_atomic_check, |
| 524 | .atomic_update = tegra_plane_atomic_update, |
| 525 | .atomic_disable = tegra_plane_atomic_disable, |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | static struct drm_plane *tegra_dc_primary_plane_create(struct drm_device *drm, |
| 529 | struct tegra_dc *dc) |
| 530 | { |
Thierry Reding | 518e622 | 2014-12-16 18:04:08 +0100 | [diff] [blame] | 531 | /* |
| 532 | * Ideally this would use drm_crtc_mask(), but that would require the |
| 533 | * CRTC to already be in the mode_config's list of CRTCs. However, it |
| 534 | * will only be added to that list in the drm_crtc_init_with_planes() |
| 535 | * (in tegra_dc_init()), which in turn requires registration of these |
| 536 | * planes. So we have ourselves a nice little chicken and egg problem |
| 537 | * here. |
| 538 | * |
| 539 | * We work around this by manually creating the mask from the number |
| 540 | * of CRTCs that have been registered, and should therefore always be |
| 541 | * the same as drm_crtc_index() after registration. |
| 542 | */ |
| 543 | unsigned long possible_crtcs = 1 << drm->mode_config.num_crtc; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 544 | struct tegra_plane *plane; |
| 545 | unsigned int num_formats; |
| 546 | const u32 *formats; |
| 547 | int err; |
| 548 | |
| 549 | plane = kzalloc(sizeof(*plane), GFP_KERNEL); |
| 550 | if (!plane) |
| 551 | return ERR_PTR(-ENOMEM); |
| 552 | |
| 553 | num_formats = ARRAY_SIZE(tegra_primary_plane_formats); |
| 554 | formats = tegra_primary_plane_formats; |
| 555 | |
Thierry Reding | 518e622 | 2014-12-16 18:04:08 +0100 | [diff] [blame] | 556 | err = drm_universal_plane_init(drm, &plane->base, possible_crtcs, |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 557 | &tegra_primary_plane_funcs, formats, |
| 558 | num_formats, DRM_PLANE_TYPE_PRIMARY); |
| 559 | if (err < 0) { |
| 560 | kfree(plane); |
| 561 | return ERR_PTR(err); |
| 562 | } |
| 563 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 564 | drm_plane_helper_add(&plane->base, &tegra_primary_plane_helper_funcs); |
| 565 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 566 | return &plane->base; |
| 567 | } |
| 568 | |
| 569 | static const u32 tegra_cursor_plane_formats[] = { |
| 570 | DRM_FORMAT_RGBA8888, |
| 571 | }; |
| 572 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 573 | static int tegra_cursor_atomic_check(struct drm_plane *plane, |
| 574 | struct drm_plane_state *state) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 575 | { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 576 | /* no need for further checks if the plane is being disabled */ |
| 577 | if (!state->crtc) |
| 578 | return 0; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 579 | |
| 580 | /* scaling not supported for cursor */ |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 581 | if ((state->src_w >> 16 != state->crtc_w) || |
| 582 | (state->src_h >> 16 != state->crtc_h)) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 583 | return -EINVAL; |
| 584 | |
| 585 | /* only square cursors supported */ |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 586 | if (state->src_w != state->src_h) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 587 | return -EINVAL; |
| 588 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 589 | if (state->crtc_w != 32 && state->crtc_w != 64 && |
| 590 | state->crtc_w != 128 && state->crtc_w != 256) |
| 591 | return -EINVAL; |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static void tegra_cursor_atomic_update(struct drm_plane *plane, |
| 597 | struct drm_plane_state *old_state) |
| 598 | { |
| 599 | struct tegra_bo *bo = tegra_fb_get_plane(plane->state->fb, 0); |
| 600 | struct tegra_dc *dc = to_tegra_dc(plane->state->crtc); |
| 601 | struct drm_plane_state *state = plane->state; |
| 602 | u32 value = CURSOR_CLIP_DISPLAY; |
| 603 | |
| 604 | /* rien ne va plus */ |
| 605 | if (!plane->state->crtc || !plane->state->fb) |
| 606 | return; |
| 607 | |
| 608 | switch (state->crtc_w) { |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 609 | case 32: |
| 610 | value |= CURSOR_SIZE_32x32; |
| 611 | break; |
| 612 | |
| 613 | case 64: |
| 614 | value |= CURSOR_SIZE_64x64; |
| 615 | break; |
| 616 | |
| 617 | case 128: |
| 618 | value |= CURSOR_SIZE_128x128; |
| 619 | break; |
| 620 | |
| 621 | case 256: |
| 622 | value |= CURSOR_SIZE_256x256; |
| 623 | break; |
| 624 | |
| 625 | default: |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 626 | WARN(1, "cursor size %ux%u not supported\n", state->crtc_w, |
| 627 | state->crtc_h); |
| 628 | return; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | value |= (bo->paddr >> 10) & 0x3fffff; |
| 632 | tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR); |
| 633 | |
| 634 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 635 | value = (bo->paddr >> 32) & 0x3; |
| 636 | tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR_HI); |
| 637 | #endif |
| 638 | |
| 639 | /* enable cursor and set blend mode */ |
| 640 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 641 | value |= CURSOR_ENABLE; |
| 642 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 643 | |
| 644 | value = tegra_dc_readl(dc, DC_DISP_BLEND_CURSOR_CONTROL); |
| 645 | value &= ~CURSOR_DST_BLEND_MASK; |
| 646 | value &= ~CURSOR_SRC_BLEND_MASK; |
| 647 | value |= CURSOR_MODE_NORMAL; |
| 648 | value |= CURSOR_DST_BLEND_NEG_K1_TIMES_SRC; |
| 649 | value |= CURSOR_SRC_BLEND_K1_TIMES_SRC; |
| 650 | value |= CURSOR_ALPHA; |
| 651 | tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL); |
| 652 | |
| 653 | /* position the cursor */ |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 654 | value = (state->crtc_y & 0x3fff) << 16 | (state->crtc_x & 0x3fff); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 655 | tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION); |
| 656 | |
| 657 | /* apply changes */ |
| 658 | tegra_dc_cursor_commit(dc); |
| 659 | tegra_dc_commit(dc); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 662 | static void tegra_cursor_atomic_disable(struct drm_plane *plane, |
| 663 | struct drm_plane_state *old_state) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 664 | { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 665 | struct tegra_dc *dc; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 666 | u32 value; |
| 667 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 668 | /* rien ne va plus */ |
| 669 | if (!old_state || !old_state->crtc) |
| 670 | return; |
| 671 | |
| 672 | dc = to_tegra_dc(old_state->crtc); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 673 | |
| 674 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 675 | value &= ~CURSOR_ENABLE; |
| 676 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 677 | |
| 678 | tegra_dc_cursor_commit(dc); |
| 679 | tegra_dc_commit(dc); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static const struct drm_plane_funcs tegra_cursor_plane_funcs = { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 683 | .update_plane = drm_plane_helper_update, |
| 684 | .disable_plane = drm_plane_helper_disable, |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 685 | .destroy = tegra_plane_destroy, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 686 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
| 687 | }; |
| 688 | |
| 689 | static const struct drm_plane_helper_funcs tegra_cursor_plane_helper_funcs = { |
| 690 | .prepare_fb = tegra_plane_prepare_fb, |
| 691 | .cleanup_fb = tegra_plane_cleanup_fb, |
| 692 | .atomic_check = tegra_cursor_atomic_check, |
| 693 | .atomic_update = tegra_cursor_atomic_update, |
| 694 | .atomic_disable = tegra_cursor_atomic_disable, |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm, |
| 698 | struct tegra_dc *dc) |
| 699 | { |
| 700 | struct tegra_plane *plane; |
| 701 | unsigned int num_formats; |
| 702 | const u32 *formats; |
| 703 | int err; |
| 704 | |
| 705 | plane = kzalloc(sizeof(*plane), GFP_KERNEL); |
| 706 | if (!plane) |
| 707 | return ERR_PTR(-ENOMEM); |
| 708 | |
| 709 | num_formats = ARRAY_SIZE(tegra_cursor_plane_formats); |
| 710 | formats = tegra_cursor_plane_formats; |
| 711 | |
| 712 | err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe, |
| 713 | &tegra_cursor_plane_funcs, formats, |
| 714 | num_formats, DRM_PLANE_TYPE_CURSOR); |
| 715 | if (err < 0) { |
| 716 | kfree(plane); |
| 717 | return ERR_PTR(err); |
| 718 | } |
| 719 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 720 | drm_plane_helper_add(&plane->base, &tegra_cursor_plane_helper_funcs); |
| 721 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 722 | return &plane->base; |
| 723 | } |
| 724 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 725 | static void tegra_overlay_plane_destroy(struct drm_plane *plane) |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 726 | { |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 727 | tegra_plane_destroy(plane); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 730 | static const struct drm_plane_funcs tegra_overlay_plane_funcs = { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 731 | .update_plane = drm_plane_helper_update, |
| 732 | .disable_plane = drm_plane_helper_disable, |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 733 | .destroy = tegra_overlay_plane_destroy, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 734 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 735 | }; |
| 736 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 737 | static const uint32_t tegra_overlay_plane_formats[] = { |
Thierry Reding | dbe4d9a | 2013-03-22 15:37:30 +0100 | [diff] [blame] | 738 | DRM_FORMAT_XBGR8888, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 739 | DRM_FORMAT_XRGB8888, |
Thierry Reding | dbe4d9a | 2013-03-22 15:37:30 +0100 | [diff] [blame] | 740 | DRM_FORMAT_RGB565, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 741 | DRM_FORMAT_UYVY, |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 742 | DRM_FORMAT_YUYV, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 743 | DRM_FORMAT_YUV420, |
| 744 | DRM_FORMAT_YUV422, |
| 745 | }; |
| 746 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 747 | static const struct drm_plane_helper_funcs tegra_overlay_plane_helper_funcs = { |
| 748 | .prepare_fb = tegra_plane_prepare_fb, |
| 749 | .cleanup_fb = tegra_plane_cleanup_fb, |
| 750 | .atomic_check = tegra_plane_atomic_check, |
| 751 | .atomic_update = tegra_plane_atomic_update, |
| 752 | .atomic_disable = tegra_plane_atomic_disable, |
| 753 | }; |
| 754 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 755 | static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm, |
| 756 | struct tegra_dc *dc, |
| 757 | unsigned int index) |
| 758 | { |
| 759 | struct tegra_plane *plane; |
| 760 | unsigned int num_formats; |
| 761 | const u32 *formats; |
| 762 | int err; |
| 763 | |
| 764 | plane = kzalloc(sizeof(*plane), GFP_KERNEL); |
| 765 | if (!plane) |
| 766 | return ERR_PTR(-ENOMEM); |
| 767 | |
| 768 | plane->index = index; |
| 769 | |
| 770 | num_formats = ARRAY_SIZE(tegra_overlay_plane_formats); |
| 771 | formats = tegra_overlay_plane_formats; |
| 772 | |
| 773 | err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe, |
| 774 | &tegra_overlay_plane_funcs, formats, |
| 775 | num_formats, DRM_PLANE_TYPE_OVERLAY); |
| 776 | if (err < 0) { |
| 777 | kfree(plane); |
| 778 | return ERR_PTR(err); |
| 779 | } |
| 780 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 781 | drm_plane_helper_add(&plane->base, &tegra_overlay_plane_helper_funcs); |
| 782 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 783 | return &plane->base; |
| 784 | } |
| 785 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 786 | static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc) |
| 787 | { |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 788 | struct drm_plane *plane; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 789 | unsigned int i; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 790 | |
| 791 | for (i = 0; i < 2; i++) { |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 792 | plane = tegra_dc_overlay_plane_create(drm, dc, 1 + i); |
| 793 | if (IS_ERR(plane)) |
| 794 | return PTR_ERR(plane); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 800 | static int tegra_dc_set_base(struct tegra_dc *dc, int x, int y, |
| 801 | struct drm_framebuffer *fb) |
| 802 | { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 803 | struct tegra_bo *bo = tegra_fb_get_plane(fb, 0); |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 804 | unsigned int h_offset = 0, v_offset = 0; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 805 | struct tegra_bo_tiling tiling; |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 806 | unsigned long value, flags; |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 807 | unsigned int format, swap; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 808 | int err; |
| 809 | |
| 810 | err = tegra_fb_get_tiling(fb, &tiling); |
| 811 | if (err < 0) |
| 812 | return err; |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 813 | |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 814 | spin_lock_irqsave(&dc->lock, flags); |
| 815 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 816 | tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 817 | |
| 818 | value = fb->offsets[0] + y * fb->pitches[0] + |
| 819 | x * fb->bits_per_pixel / 8; |
| 820 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 821 | tegra_dc_writel(dc, bo->paddr + value, DC_WINBUF_START_ADDR); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 822 | tegra_dc_writel(dc, fb->pitches[0], DC_WIN_LINE_STRIDE); |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 823 | |
| 824 | format = tegra_dc_format(fb->pixel_format, &swap); |
Thierry Reding | ed683ae | 2013-04-22 21:31:15 +0200 | [diff] [blame] | 825 | tegra_dc_writel(dc, format, DC_WIN_COLOR_DEPTH); |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 826 | tegra_dc_writel(dc, swap, DC_WIN_BYTE_SWAP); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 827 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 828 | if (dc->soc->supports_block_linear) { |
| 829 | unsigned long height = tiling.value; |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 830 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 831 | switch (tiling.mode) { |
| 832 | case TEGRA_BO_TILING_MODE_PITCH: |
| 833 | value = DC_WINBUF_SURFACE_KIND_PITCH; |
| 834 | break; |
| 835 | |
| 836 | case TEGRA_BO_TILING_MODE_TILED: |
| 837 | value = DC_WINBUF_SURFACE_KIND_TILED; |
| 838 | break; |
| 839 | |
| 840 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 841 | value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) | |
| 842 | DC_WINBUF_SURFACE_KIND_BLOCK; |
| 843 | break; |
| 844 | } |
| 845 | |
| 846 | tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND); |
| 847 | } else { |
| 848 | switch (tiling.mode) { |
| 849 | case TEGRA_BO_TILING_MODE_PITCH: |
| 850 | value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | |
| 851 | DC_WIN_BUFFER_ADDR_MODE_LINEAR; |
| 852 | break; |
| 853 | |
| 854 | case TEGRA_BO_TILING_MODE_TILED: |
| 855 | value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV | |
| 856 | DC_WIN_BUFFER_ADDR_MODE_TILE; |
| 857 | break; |
| 858 | |
| 859 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 860 | DRM_ERROR("hardware doesn't support block linear mode\n"); |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 861 | spin_unlock_irqrestore(&dc->lock, flags); |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 862 | return -EINVAL; |
| 863 | } |
| 864 | |
| 865 | tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE); |
| 866 | } |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 867 | |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 868 | /* make sure bottom-up buffers are properly displayed */ |
| 869 | if (tegra_fb_is_bottom_up(fb)) { |
| 870 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
Thierry Reding | eba6650 | 2014-02-25 12:04:06 +0100 | [diff] [blame] | 871 | value |= V_DIRECTION; |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 872 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 873 | |
| 874 | v_offset += fb->height - 1; |
| 875 | } else { |
| 876 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
Thierry Reding | eba6650 | 2014-02-25 12:04:06 +0100 | [diff] [blame] | 877 | value &= ~V_DIRECTION; |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 878 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 879 | } |
| 880 | |
| 881 | tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET); |
| 882 | tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET); |
| 883 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 884 | value = GENERAL_ACT_REQ | WIN_A_ACT_REQ; |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 885 | tegra_dc_writel(dc, value << 8, DC_CMD_STATE_CONTROL); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 886 | tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); |
| 887 | |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 888 | spin_unlock_irqrestore(&dc->lock, flags); |
| 889 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 890 | return 0; |
| 891 | } |
| 892 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 893 | void tegra_dc_enable_vblank(struct tegra_dc *dc) |
| 894 | { |
| 895 | unsigned long value, flags; |
| 896 | |
| 897 | spin_lock_irqsave(&dc->lock, flags); |
| 898 | |
| 899 | value = tegra_dc_readl(dc, DC_CMD_INT_MASK); |
| 900 | value |= VBLANK_INT; |
| 901 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
| 902 | |
| 903 | spin_unlock_irqrestore(&dc->lock, flags); |
| 904 | } |
| 905 | |
| 906 | void tegra_dc_disable_vblank(struct tegra_dc *dc) |
| 907 | { |
| 908 | unsigned long value, flags; |
| 909 | |
| 910 | spin_lock_irqsave(&dc->lock, flags); |
| 911 | |
| 912 | value = tegra_dc_readl(dc, DC_CMD_INT_MASK); |
| 913 | value &= ~VBLANK_INT; |
| 914 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
| 915 | |
| 916 | spin_unlock_irqrestore(&dc->lock, flags); |
| 917 | } |
| 918 | |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 919 | static void tegra_dc_finish_page_flip(struct tegra_dc *dc) |
| 920 | { |
| 921 | struct drm_device *drm = dc->base.dev; |
| 922 | struct drm_crtc *crtc = &dc->base; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 923 | unsigned long flags, base; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 924 | struct tegra_bo *bo; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 925 | |
Thierry Reding | 6b59cc1 | 2014-12-16 16:33:27 +0100 | [diff] [blame] | 926 | spin_lock_irqsave(&drm->event_lock, flags); |
| 927 | |
| 928 | if (!dc->event) { |
| 929 | spin_unlock_irqrestore(&drm->event_lock, flags); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 930 | return; |
Thierry Reding | 6b59cc1 | 2014-12-16 16:33:27 +0100 | [diff] [blame] | 931 | } |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 932 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 933 | bo = tegra_fb_get_plane(crtc->primary->fb, 0); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 934 | |
Dan Carpenter | 8643bc6 | 2015-01-07 14:01:26 +0300 | [diff] [blame] | 935 | spin_lock(&dc->lock); |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 936 | |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 937 | /* check if new start address has been latched */ |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 938 | tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 939 | tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); |
| 940 | base = tegra_dc_readl(dc, DC_WINBUF_START_ADDR); |
| 941 | tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); |
| 942 | |
Dan Carpenter | 8643bc6 | 2015-01-07 14:01:26 +0300 | [diff] [blame] | 943 | spin_unlock(&dc->lock); |
Sean Paul | 93396d0 | 2014-11-19 13:04:49 -0500 | [diff] [blame] | 944 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 945 | if (base == bo->paddr + crtc->primary->fb->offsets[0]) { |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 946 | drm_crtc_send_vblank_event(crtc, dc->event); |
| 947 | drm_crtc_vblank_put(crtc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 948 | dc->event = NULL; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 949 | } |
Thierry Reding | 6b59cc1 | 2014-12-16 16:33:27 +0100 | [diff] [blame] | 950 | |
| 951 | spin_unlock_irqrestore(&drm->event_lock, flags); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file) |
| 955 | { |
| 956 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 957 | struct drm_device *drm = crtc->dev; |
| 958 | unsigned long flags; |
| 959 | |
| 960 | spin_lock_irqsave(&drm->event_lock, flags); |
| 961 | |
| 962 | if (dc->event && dc->event->base.file_priv == file) { |
| 963 | dc->event->base.destroy(&dc->event->base); |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 964 | drm_crtc_vblank_put(crtc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 965 | dc->event = NULL; |
| 966 | } |
| 967 | |
| 968 | spin_unlock_irqrestore(&drm->event_lock, flags); |
| 969 | } |
| 970 | |
| 971 | static int tegra_dc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Dave Airlie | a5b6f74 | 2013-09-02 09:47:56 +1000 | [diff] [blame] | 972 | struct drm_pending_vblank_event *event, uint32_t page_flip_flags) |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 973 | { |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 974 | unsigned int pipe = drm_crtc_index(crtc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 975 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 976 | |
| 977 | if (dc->event) |
| 978 | return -EBUSY; |
| 979 | |
| 980 | if (event) { |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 981 | event->pipe = pipe; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 982 | dc->event = event; |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 983 | drm_crtc_vblank_get(crtc); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | tegra_dc_set_base(dc, 0, 0, fb); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 987 | crtc->primary->fb = fb; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 992 | static void tegra_dc_destroy(struct drm_crtc *crtc) |
| 993 | { |
| 994 | drm_crtc_cleanup(crtc); |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 995 | } |
| 996 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 997 | static const struct drm_crtc_funcs tegra_crtc_funcs = { |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 998 | .page_flip = tegra_dc_page_flip, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 999 | .set_config = drm_crtc_helper_set_config, |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 1000 | .destroy = tegra_dc_destroy, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1001 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1002 | }; |
| 1003 | |
Thierry Reding | 86df256 | 2014-12-08 16:03:53 +0100 | [diff] [blame] | 1004 | static void tegra_dc_stop(struct tegra_dc *dc) |
| 1005 | { |
| 1006 | u32 value; |
| 1007 | |
| 1008 | /* stop the display controller */ |
| 1009 | value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND); |
| 1010 | value &= ~DISP_CTRL_MODE_MASK; |
| 1011 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND); |
| 1012 | |
| 1013 | tegra_dc_commit(dc); |
| 1014 | } |
| 1015 | |
| 1016 | static bool tegra_dc_idle(struct tegra_dc *dc) |
| 1017 | { |
| 1018 | u32 value; |
| 1019 | |
| 1020 | value = tegra_dc_readl_active(dc, DC_CMD_DISPLAY_COMMAND); |
| 1021 | |
| 1022 | return (value & DISP_CTRL_MODE_MASK) == 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int tegra_dc_wait_idle(struct tegra_dc *dc, unsigned long timeout) |
| 1026 | { |
| 1027 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 1028 | |
| 1029 | while (time_before(jiffies, timeout)) { |
| 1030 | if (tegra_dc_idle(dc)) |
| 1031 | return 0; |
| 1032 | |
| 1033 | usleep_range(1000, 2000); |
| 1034 | } |
| 1035 | |
| 1036 | dev_dbg(dc->dev, "timeout waiting for DC to become idle\n"); |
| 1037 | return -ETIMEDOUT; |
| 1038 | } |
| 1039 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1040 | static void tegra_crtc_disable(struct drm_crtc *crtc) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1041 | { |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 1042 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | 3b0e585 | 2014-12-16 18:30:16 +0100 | [diff] [blame] | 1043 | u32 value; |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 1044 | |
Thierry Reding | 86df256 | 2014-12-08 16:03:53 +0100 | [diff] [blame] | 1045 | if (!tegra_dc_idle(dc)) { |
| 1046 | tegra_dc_stop(dc); |
| 1047 | |
| 1048 | /* |
| 1049 | * Ignore the return value, there isn't anything useful to do |
| 1050 | * in case this fails. |
| 1051 | */ |
| 1052 | tegra_dc_wait_idle(dc, 100); |
| 1053 | } |
Thierry Reding | 36904ad | 2014-11-21 17:35:54 +0100 | [diff] [blame] | 1054 | |
Thierry Reding | 3b0e585 | 2014-12-16 18:30:16 +0100 | [diff] [blame] | 1055 | /* |
| 1056 | * This should really be part of the RGB encoder driver, but clearing |
| 1057 | * these bits has the side-effect of stopping the display controller. |
| 1058 | * When that happens no VBLANK interrupts will be raised. At the same |
| 1059 | * time the encoder is disabled before the display controller, so the |
| 1060 | * above code is always going to timeout waiting for the controller |
| 1061 | * to go idle. |
| 1062 | * |
| 1063 | * Given the close coupling between the RGB encoder and the display |
| 1064 | * controller doing it here is still kind of okay. None of the other |
| 1065 | * encoder drivers require these bits to be cleared. |
| 1066 | * |
| 1067 | * XXX: Perhaps given that the display controller is switched off at |
| 1068 | * this point anyway maybe clearing these bits isn't even useful for |
| 1069 | * the RGB encoder? |
| 1070 | */ |
| 1071 | if (dc->rgb) { |
| 1072 | value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL); |
| 1073 | value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | |
| 1074 | PW4_ENABLE | PM0_ENABLE | PM1_ENABLE); |
| 1075 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL); |
| 1076 | } |
| 1077 | |
Thierry Reding | 8ff64c1 | 2014-10-08 14:48:51 +0200 | [diff] [blame] | 1078 | drm_crtc_vblank_off(crtc); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1079 | tegra_dc_commit(dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc, |
| 1083 | const struct drm_display_mode *mode, |
| 1084 | struct drm_display_mode *adjusted) |
| 1085 | { |
| 1086 | return true; |
| 1087 | } |
| 1088 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1089 | static int tegra_dc_set_timings(struct tegra_dc *dc, |
| 1090 | struct drm_display_mode *mode) |
| 1091 | { |
Thierry Reding | 0444c0f | 2014-04-16 09:22:38 +0200 | [diff] [blame] | 1092 | unsigned int h_ref_to_sync = 1; |
| 1093 | unsigned int v_ref_to_sync = 1; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1094 | unsigned long value; |
| 1095 | |
| 1096 | tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS); |
| 1097 | |
| 1098 | value = (v_ref_to_sync << 16) | h_ref_to_sync; |
| 1099 | tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC); |
| 1100 | |
| 1101 | value = ((mode->vsync_end - mode->vsync_start) << 16) | |
| 1102 | ((mode->hsync_end - mode->hsync_start) << 0); |
| 1103 | tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH); |
| 1104 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1105 | value = ((mode->vtotal - mode->vsync_end) << 16) | |
| 1106 | ((mode->htotal - mode->hsync_end) << 0); |
Lucas Stach | 4049508 | 2012-12-19 21:38:52 +0000 | [diff] [blame] | 1107 | tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH); |
| 1108 | |
| 1109 | value = ((mode->vsync_start - mode->vdisplay) << 16) | |
| 1110 | ((mode->hsync_start - mode->hdisplay) << 0); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1111 | tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH); |
| 1112 | |
| 1113 | value = (mode->vdisplay << 16) | mode->hdisplay; |
| 1114 | tegra_dc_writel(dc, value, DC_DISP_ACTIVE); |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Thierry Reding | c5a107d | 2014-12-02 15:15:06 +0100 | [diff] [blame] | 1119 | int tegra_dc_setup_clock(struct tegra_dc *dc, struct clk *parent, |
| 1120 | unsigned long pclk, unsigned int div) |
| 1121 | { |
| 1122 | u32 value; |
| 1123 | int err; |
| 1124 | |
| 1125 | err = clk_set_parent(dc->clk, parent); |
| 1126 | if (err < 0) { |
| 1127 | dev_err(dc->dev, "failed to set parent clock: %d\n", err); |
| 1128 | return err; |
| 1129 | } |
| 1130 | |
| 1131 | DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk), div); |
| 1132 | |
| 1133 | value = SHIFT_CLK_DIVIDER(div) | PIXEL_CLK_DIVIDER_PCD1; |
| 1134 | tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL); |
| 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1139 | static void tegra_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1140 | { |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1141 | struct drm_display_mode *mode = &crtc->state->adjusted_mode; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1142 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 1143 | u32 value; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1144 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1145 | /* program display mode */ |
| 1146 | tegra_dc_set_timings(dc, mode); |
| 1147 | |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 1148 | if (dc->soc->supports_border_color) |
| 1149 | tegra_dc_writel(dc, 0, DC_DISP_BORDER_COLOR); |
| 1150 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1151 | /* interlacing isn't supported yet, so disable it */ |
| 1152 | if (dc->soc->supports_interlacing) { |
| 1153 | value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL); |
| 1154 | value &= ~INTERLACE_ENABLE; |
| 1155 | tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL); |
| 1156 | } |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1159 | static void tegra_crtc_prepare(struct drm_crtc *crtc) |
| 1160 | { |
| 1161 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 1162 | unsigned int syncpt; |
| 1163 | unsigned long value; |
| 1164 | |
Thierry Reding | 8ff64c1 | 2014-10-08 14:48:51 +0200 | [diff] [blame] | 1165 | drm_crtc_vblank_off(crtc); |
| 1166 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1167 | if (dc->pipe) |
| 1168 | syncpt = SYNCPT_VBLANK1; |
| 1169 | else |
| 1170 | syncpt = SYNCPT_VBLANK0; |
| 1171 | |
| 1172 | /* initialize display controller */ |
| 1173 | tegra_dc_writel(dc, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); |
| 1174 | tegra_dc_writel(dc, 0x100 | syncpt, DC_CMD_CONT_SYNCPT_VSYNC); |
| 1175 | |
| 1176 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | WIN_A_OF_INT; |
| 1177 | tegra_dc_writel(dc, value, DC_CMD_INT_TYPE); |
| 1178 | |
| 1179 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | |
| 1180 | WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; |
| 1181 | tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY); |
| 1182 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1183 | /* initialize timer */ |
| 1184 | value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) | |
| 1185 | WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20); |
| 1186 | tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY); |
| 1187 | |
| 1188 | value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) | |
| 1189 | WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1); |
| 1190 | tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); |
| 1191 | |
| 1192 | value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1193 | tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1194 | |
| 1195 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT; |
| 1196 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static void tegra_crtc_commit(struct drm_crtc *crtc) |
| 1200 | { |
| 1201 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1202 | |
Thierry Reding | 8ff64c1 | 2014-10-08 14:48:51 +0200 | [diff] [blame] | 1203 | drm_crtc_vblank_on(crtc); |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 1204 | tegra_dc_commit(dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1207 | static int tegra_crtc_atomic_check(struct drm_crtc *crtc, |
| 1208 | struct drm_crtc_state *state) |
| 1209 | { |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | static void tegra_crtc_atomic_begin(struct drm_crtc *crtc) |
| 1214 | { |
| 1215 | } |
| 1216 | |
| 1217 | static void tegra_crtc_atomic_flush(struct drm_crtc *crtc) |
| 1218 | { |
| 1219 | } |
| 1220 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1221 | static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = { |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1222 | .disable = tegra_crtc_disable, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1223 | .mode_fixup = tegra_crtc_mode_fixup, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1224 | .mode_set = drm_helper_crtc_mode_set, |
| 1225 | .mode_set_nofb = tegra_crtc_mode_set_nofb, |
| 1226 | .mode_set_base = drm_helper_crtc_mode_set_base, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1227 | .prepare = tegra_crtc_prepare, |
| 1228 | .commit = tegra_crtc_commit, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame^] | 1229 | .atomic_check = tegra_crtc_atomic_check, |
| 1230 | .atomic_begin = tegra_crtc_atomic_begin, |
| 1231 | .atomic_flush = tegra_crtc_atomic_flush, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1232 | }; |
| 1233 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1234 | static irqreturn_t tegra_dc_irq(int irq, void *data) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1235 | { |
| 1236 | struct tegra_dc *dc = data; |
| 1237 | unsigned long status; |
| 1238 | |
| 1239 | status = tegra_dc_readl(dc, DC_CMD_INT_STATUS); |
| 1240 | tegra_dc_writel(dc, status, DC_CMD_INT_STATUS); |
| 1241 | |
| 1242 | if (status & FRAME_END_INT) { |
| 1243 | /* |
| 1244 | dev_dbg(dc->dev, "%s(): frame end\n", __func__); |
| 1245 | */ |
| 1246 | } |
| 1247 | |
| 1248 | if (status & VBLANK_INT) { |
| 1249 | /* |
| 1250 | dev_dbg(dc->dev, "%s(): vertical blank\n", __func__); |
| 1251 | */ |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 1252 | drm_crtc_handle_vblank(&dc->base); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 1253 | tegra_dc_finish_page_flip(dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) { |
| 1257 | /* |
| 1258 | dev_dbg(dc->dev, "%s(): underflow\n", __func__); |
| 1259 | */ |
| 1260 | } |
| 1261 | |
| 1262 | return IRQ_HANDLED; |
| 1263 | } |
| 1264 | |
| 1265 | static int tegra_dc_show_regs(struct seq_file *s, void *data) |
| 1266 | { |
| 1267 | struct drm_info_node *node = s->private; |
| 1268 | struct tegra_dc *dc = node->info_ent->data; |
| 1269 | |
| 1270 | #define DUMP_REG(name) \ |
Thierry Reding | 03a6056 | 2014-10-21 13:48:48 +0200 | [diff] [blame] | 1271 | seq_printf(s, "%-40s %#05x %08x\n", #name, name, \ |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1272 | tegra_dc_readl(dc, name)) |
| 1273 | |
| 1274 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT); |
| 1275 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); |
| 1276 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR); |
| 1277 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT); |
| 1278 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL); |
| 1279 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR); |
| 1280 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT); |
| 1281 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL); |
| 1282 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR); |
| 1283 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT); |
| 1284 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL); |
| 1285 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR); |
| 1286 | DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC); |
| 1287 | DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0); |
| 1288 | DUMP_REG(DC_CMD_DISPLAY_COMMAND); |
| 1289 | DUMP_REG(DC_CMD_SIGNAL_RAISE); |
| 1290 | DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL); |
| 1291 | DUMP_REG(DC_CMD_INT_STATUS); |
| 1292 | DUMP_REG(DC_CMD_INT_MASK); |
| 1293 | DUMP_REG(DC_CMD_INT_ENABLE); |
| 1294 | DUMP_REG(DC_CMD_INT_TYPE); |
| 1295 | DUMP_REG(DC_CMD_INT_POLARITY); |
| 1296 | DUMP_REG(DC_CMD_SIGNAL_RAISE1); |
| 1297 | DUMP_REG(DC_CMD_SIGNAL_RAISE2); |
| 1298 | DUMP_REG(DC_CMD_SIGNAL_RAISE3); |
| 1299 | DUMP_REG(DC_CMD_STATE_ACCESS); |
| 1300 | DUMP_REG(DC_CMD_STATE_CONTROL); |
| 1301 | DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER); |
| 1302 | DUMP_REG(DC_CMD_REG_ACT_CONTROL); |
| 1303 | DUMP_REG(DC_COM_CRC_CONTROL); |
| 1304 | DUMP_REG(DC_COM_CRC_CHECKSUM); |
| 1305 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0)); |
| 1306 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1)); |
| 1307 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2)); |
| 1308 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3)); |
| 1309 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0)); |
| 1310 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1)); |
| 1311 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2)); |
| 1312 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3)); |
| 1313 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0)); |
| 1314 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1)); |
| 1315 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2)); |
| 1316 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3)); |
| 1317 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0)); |
| 1318 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1)); |
| 1319 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2)); |
| 1320 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3)); |
| 1321 | DUMP_REG(DC_COM_PIN_INPUT_DATA(0)); |
| 1322 | DUMP_REG(DC_COM_PIN_INPUT_DATA(1)); |
| 1323 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0)); |
| 1324 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1)); |
| 1325 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2)); |
| 1326 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3)); |
| 1327 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4)); |
| 1328 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5)); |
| 1329 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6)); |
| 1330 | DUMP_REG(DC_COM_PIN_MISC_CONTROL); |
| 1331 | DUMP_REG(DC_COM_PIN_PM0_CONTROL); |
| 1332 | DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE); |
| 1333 | DUMP_REG(DC_COM_PIN_PM1_CONTROL); |
| 1334 | DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE); |
| 1335 | DUMP_REG(DC_COM_SPI_CONTROL); |
| 1336 | DUMP_REG(DC_COM_SPI_START_BYTE); |
| 1337 | DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB); |
| 1338 | DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD); |
| 1339 | DUMP_REG(DC_COM_HSPI_CS_DC); |
| 1340 | DUMP_REG(DC_COM_SCRATCH_REGISTER_A); |
| 1341 | DUMP_REG(DC_COM_SCRATCH_REGISTER_B); |
| 1342 | DUMP_REG(DC_COM_GPIO_CTRL); |
| 1343 | DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER); |
| 1344 | DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED); |
| 1345 | DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 1346 | DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1); |
| 1347 | DUMP_REG(DC_DISP_DISP_WIN_OPTIONS); |
| 1348 | DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY); |
| 1349 | DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); |
| 1350 | DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS); |
| 1351 | DUMP_REG(DC_DISP_REF_TO_SYNC); |
| 1352 | DUMP_REG(DC_DISP_SYNC_WIDTH); |
| 1353 | DUMP_REG(DC_DISP_BACK_PORCH); |
| 1354 | DUMP_REG(DC_DISP_ACTIVE); |
| 1355 | DUMP_REG(DC_DISP_FRONT_PORCH); |
| 1356 | DUMP_REG(DC_DISP_H_PULSE0_CONTROL); |
| 1357 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_A); |
| 1358 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_B); |
| 1359 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_C); |
| 1360 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_D); |
| 1361 | DUMP_REG(DC_DISP_H_PULSE1_CONTROL); |
| 1362 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_A); |
| 1363 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_B); |
| 1364 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_C); |
| 1365 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_D); |
| 1366 | DUMP_REG(DC_DISP_H_PULSE2_CONTROL); |
| 1367 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_A); |
| 1368 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_B); |
| 1369 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_C); |
| 1370 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_D); |
| 1371 | DUMP_REG(DC_DISP_V_PULSE0_CONTROL); |
| 1372 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_A); |
| 1373 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_B); |
| 1374 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_C); |
| 1375 | DUMP_REG(DC_DISP_V_PULSE1_CONTROL); |
| 1376 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_A); |
| 1377 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_B); |
| 1378 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_C); |
| 1379 | DUMP_REG(DC_DISP_V_PULSE2_CONTROL); |
| 1380 | DUMP_REG(DC_DISP_V_PULSE2_POSITION_A); |
| 1381 | DUMP_REG(DC_DISP_V_PULSE3_CONTROL); |
| 1382 | DUMP_REG(DC_DISP_V_PULSE3_POSITION_A); |
| 1383 | DUMP_REG(DC_DISP_M0_CONTROL); |
| 1384 | DUMP_REG(DC_DISP_M1_CONTROL); |
| 1385 | DUMP_REG(DC_DISP_DI_CONTROL); |
| 1386 | DUMP_REG(DC_DISP_PP_CONTROL); |
| 1387 | DUMP_REG(DC_DISP_PP_SELECT_A); |
| 1388 | DUMP_REG(DC_DISP_PP_SELECT_B); |
| 1389 | DUMP_REG(DC_DISP_PP_SELECT_C); |
| 1390 | DUMP_REG(DC_DISP_PP_SELECT_D); |
| 1391 | DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL); |
| 1392 | DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL); |
| 1393 | DUMP_REG(DC_DISP_DISP_COLOR_CONTROL); |
| 1394 | DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS); |
| 1395 | DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS); |
| 1396 | DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS); |
| 1397 | DUMP_REG(DC_DISP_LCD_SPI_OPTIONS); |
| 1398 | DUMP_REG(DC_DISP_BORDER_COLOR); |
| 1399 | DUMP_REG(DC_DISP_COLOR_KEY0_LOWER); |
| 1400 | DUMP_REG(DC_DISP_COLOR_KEY0_UPPER); |
| 1401 | DUMP_REG(DC_DISP_COLOR_KEY1_LOWER); |
| 1402 | DUMP_REG(DC_DISP_COLOR_KEY1_UPPER); |
| 1403 | DUMP_REG(DC_DISP_CURSOR_FOREGROUND); |
| 1404 | DUMP_REG(DC_DISP_CURSOR_BACKGROUND); |
| 1405 | DUMP_REG(DC_DISP_CURSOR_START_ADDR); |
| 1406 | DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS); |
| 1407 | DUMP_REG(DC_DISP_CURSOR_POSITION); |
| 1408 | DUMP_REG(DC_DISP_CURSOR_POSITION_NS); |
| 1409 | DUMP_REG(DC_DISP_INIT_SEQ_CONTROL); |
| 1410 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A); |
| 1411 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B); |
| 1412 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C); |
| 1413 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D); |
| 1414 | DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL); |
| 1415 | DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST); |
| 1416 | DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST); |
| 1417 | DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST); |
| 1418 | DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST); |
| 1419 | DUMP_REG(DC_DISP_DAC_CRT_CTRL); |
| 1420 | DUMP_REG(DC_DISP_DISP_MISC_CONTROL); |
| 1421 | DUMP_REG(DC_DISP_SD_CONTROL); |
| 1422 | DUMP_REG(DC_DISP_SD_CSC_COEFF); |
| 1423 | DUMP_REG(DC_DISP_SD_LUT(0)); |
| 1424 | DUMP_REG(DC_DISP_SD_LUT(1)); |
| 1425 | DUMP_REG(DC_DISP_SD_LUT(2)); |
| 1426 | DUMP_REG(DC_DISP_SD_LUT(3)); |
| 1427 | DUMP_REG(DC_DISP_SD_LUT(4)); |
| 1428 | DUMP_REG(DC_DISP_SD_LUT(5)); |
| 1429 | DUMP_REG(DC_DISP_SD_LUT(6)); |
| 1430 | DUMP_REG(DC_DISP_SD_LUT(7)); |
| 1431 | DUMP_REG(DC_DISP_SD_LUT(8)); |
| 1432 | DUMP_REG(DC_DISP_SD_FLICKER_CONTROL); |
| 1433 | DUMP_REG(DC_DISP_DC_PIXEL_COUNT); |
| 1434 | DUMP_REG(DC_DISP_SD_HISTOGRAM(0)); |
| 1435 | DUMP_REG(DC_DISP_SD_HISTOGRAM(1)); |
| 1436 | DUMP_REG(DC_DISP_SD_HISTOGRAM(2)); |
| 1437 | DUMP_REG(DC_DISP_SD_HISTOGRAM(3)); |
| 1438 | DUMP_REG(DC_DISP_SD_HISTOGRAM(4)); |
| 1439 | DUMP_REG(DC_DISP_SD_HISTOGRAM(5)); |
| 1440 | DUMP_REG(DC_DISP_SD_HISTOGRAM(6)); |
| 1441 | DUMP_REG(DC_DISP_SD_HISTOGRAM(7)); |
| 1442 | DUMP_REG(DC_DISP_SD_BL_TF(0)); |
| 1443 | DUMP_REG(DC_DISP_SD_BL_TF(1)); |
| 1444 | DUMP_REG(DC_DISP_SD_BL_TF(2)); |
| 1445 | DUMP_REG(DC_DISP_SD_BL_TF(3)); |
| 1446 | DUMP_REG(DC_DISP_SD_BL_CONTROL); |
| 1447 | DUMP_REG(DC_DISP_SD_HW_K_VALUES); |
| 1448 | DUMP_REG(DC_DISP_SD_MAN_K_VALUES); |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1449 | DUMP_REG(DC_DISP_CURSOR_START_ADDR_HI); |
| 1450 | DUMP_REG(DC_DISP_BLEND_CURSOR_CONTROL); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1451 | DUMP_REG(DC_WIN_WIN_OPTIONS); |
| 1452 | DUMP_REG(DC_WIN_BYTE_SWAP); |
| 1453 | DUMP_REG(DC_WIN_BUFFER_CONTROL); |
| 1454 | DUMP_REG(DC_WIN_COLOR_DEPTH); |
| 1455 | DUMP_REG(DC_WIN_POSITION); |
| 1456 | DUMP_REG(DC_WIN_SIZE); |
| 1457 | DUMP_REG(DC_WIN_PRESCALED_SIZE); |
| 1458 | DUMP_REG(DC_WIN_H_INITIAL_DDA); |
| 1459 | DUMP_REG(DC_WIN_V_INITIAL_DDA); |
| 1460 | DUMP_REG(DC_WIN_DDA_INC); |
| 1461 | DUMP_REG(DC_WIN_LINE_STRIDE); |
| 1462 | DUMP_REG(DC_WIN_BUF_STRIDE); |
| 1463 | DUMP_REG(DC_WIN_UV_BUF_STRIDE); |
| 1464 | DUMP_REG(DC_WIN_BUFFER_ADDR_MODE); |
| 1465 | DUMP_REG(DC_WIN_DV_CONTROL); |
| 1466 | DUMP_REG(DC_WIN_BLEND_NOKEY); |
| 1467 | DUMP_REG(DC_WIN_BLEND_1WIN); |
| 1468 | DUMP_REG(DC_WIN_BLEND_2WIN_X); |
| 1469 | DUMP_REG(DC_WIN_BLEND_2WIN_Y); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1470 | DUMP_REG(DC_WIN_BLEND_3WIN_XY); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1471 | DUMP_REG(DC_WIN_HP_FETCH_CONTROL); |
| 1472 | DUMP_REG(DC_WINBUF_START_ADDR); |
| 1473 | DUMP_REG(DC_WINBUF_START_ADDR_NS); |
| 1474 | DUMP_REG(DC_WINBUF_START_ADDR_U); |
| 1475 | DUMP_REG(DC_WINBUF_START_ADDR_U_NS); |
| 1476 | DUMP_REG(DC_WINBUF_START_ADDR_V); |
| 1477 | DUMP_REG(DC_WINBUF_START_ADDR_V_NS); |
| 1478 | DUMP_REG(DC_WINBUF_ADDR_H_OFFSET); |
| 1479 | DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS); |
| 1480 | DUMP_REG(DC_WINBUF_ADDR_V_OFFSET); |
| 1481 | DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS); |
| 1482 | DUMP_REG(DC_WINBUF_UFLOW_STATUS); |
| 1483 | DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS); |
| 1484 | DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS); |
| 1485 | DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS); |
| 1486 | |
| 1487 | #undef DUMP_REG |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | static struct drm_info_list debugfs_files[] = { |
| 1493 | { "regs", tegra_dc_show_regs, 0, NULL }, |
| 1494 | }; |
| 1495 | |
| 1496 | static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor) |
| 1497 | { |
| 1498 | unsigned int i; |
| 1499 | char *name; |
| 1500 | int err; |
| 1501 | |
| 1502 | name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe); |
| 1503 | dc->debugfs = debugfs_create_dir(name, minor->debugfs_root); |
| 1504 | kfree(name); |
| 1505 | |
| 1506 | if (!dc->debugfs) |
| 1507 | return -ENOMEM; |
| 1508 | |
| 1509 | dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), |
| 1510 | GFP_KERNEL); |
| 1511 | if (!dc->debugfs_files) { |
| 1512 | err = -ENOMEM; |
| 1513 | goto remove; |
| 1514 | } |
| 1515 | |
| 1516 | for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) |
| 1517 | dc->debugfs_files[i].data = dc; |
| 1518 | |
| 1519 | err = drm_debugfs_create_files(dc->debugfs_files, |
| 1520 | ARRAY_SIZE(debugfs_files), |
| 1521 | dc->debugfs, minor); |
| 1522 | if (err < 0) |
| 1523 | goto free; |
| 1524 | |
| 1525 | dc->minor = minor; |
| 1526 | |
| 1527 | return 0; |
| 1528 | |
| 1529 | free: |
| 1530 | kfree(dc->debugfs_files); |
| 1531 | dc->debugfs_files = NULL; |
| 1532 | remove: |
| 1533 | debugfs_remove(dc->debugfs); |
| 1534 | dc->debugfs = NULL; |
| 1535 | |
| 1536 | return err; |
| 1537 | } |
| 1538 | |
| 1539 | static int tegra_dc_debugfs_exit(struct tegra_dc *dc) |
| 1540 | { |
| 1541 | drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files), |
| 1542 | dc->minor); |
| 1543 | dc->minor = NULL; |
| 1544 | |
| 1545 | kfree(dc->debugfs_files); |
| 1546 | dc->debugfs_files = NULL; |
| 1547 | |
| 1548 | debugfs_remove(dc->debugfs); |
| 1549 | dc->debugfs = NULL; |
| 1550 | |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1554 | static int tegra_dc_init(struct host1x_client *client) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1555 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1556 | struct drm_device *drm = dev_get_drvdata(client->parent); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1557 | struct tegra_dc *dc = host1x_client_to_dc(client); |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1558 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1559 | struct drm_plane *primary = NULL; |
| 1560 | struct drm_plane *cursor = NULL; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1561 | int err; |
| 1562 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 1563 | if (tegra->domain) { |
| 1564 | err = iommu_attach_device(tegra->domain, dc->dev); |
| 1565 | if (err < 0) { |
| 1566 | dev_err(dc->dev, "failed to attach to domain: %d\n", |
| 1567 | err); |
| 1568 | return err; |
| 1569 | } |
| 1570 | |
| 1571 | dc->domain = tegra->domain; |
| 1572 | } |
| 1573 | |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1574 | primary = tegra_dc_primary_plane_create(drm, dc); |
| 1575 | if (IS_ERR(primary)) { |
| 1576 | err = PTR_ERR(primary); |
| 1577 | goto cleanup; |
| 1578 | } |
| 1579 | |
| 1580 | if (dc->soc->supports_cursor) { |
| 1581 | cursor = tegra_dc_cursor_plane_create(drm, dc); |
| 1582 | if (IS_ERR(cursor)) { |
| 1583 | err = PTR_ERR(cursor); |
| 1584 | goto cleanup; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | err = drm_crtc_init_with_planes(drm, &dc->base, primary, cursor, |
| 1589 | &tegra_crtc_funcs); |
| 1590 | if (err < 0) |
| 1591 | goto cleanup; |
| 1592 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1593 | drm_mode_crtc_set_gamma_size(&dc->base, 256); |
| 1594 | drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs); |
| 1595 | |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1596 | /* |
| 1597 | * Keep track of the minimum pitch alignment across all display |
| 1598 | * controllers. |
| 1599 | */ |
| 1600 | if (dc->soc->pitch_align > tegra->pitch_align) |
| 1601 | tegra->pitch_align = dc->soc->pitch_align; |
| 1602 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1603 | err = tegra_dc_rgb_init(drm, dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1604 | if (err < 0 && err != -ENODEV) { |
| 1605 | dev_err(dc->dev, "failed to initialize RGB output: %d\n", err); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1606 | goto cleanup; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1609 | err = tegra_dc_add_planes(drm, dc); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1610 | if (err < 0) |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1611 | goto cleanup; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1612 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1613 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1614 | err = tegra_dc_debugfs_init(dc, drm->primary); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1615 | if (err < 0) |
| 1616 | dev_err(dc->dev, "debugfs setup failed: %d\n", err); |
| 1617 | } |
| 1618 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1619 | err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1620 | dev_name(dc->dev), dc); |
| 1621 | if (err < 0) { |
| 1622 | dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq, |
| 1623 | err); |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1624 | goto cleanup; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | return 0; |
Thierry Reding | c767930 | 2014-10-21 13:51:53 +0200 | [diff] [blame] | 1628 | |
| 1629 | cleanup: |
| 1630 | if (cursor) |
| 1631 | drm_plane_cleanup(cursor); |
| 1632 | |
| 1633 | if (primary) |
| 1634 | drm_plane_cleanup(primary); |
| 1635 | |
| 1636 | if (tegra->domain) { |
| 1637 | iommu_detach_device(tegra->domain, dc->dev); |
| 1638 | dc->domain = NULL; |
| 1639 | } |
| 1640 | |
| 1641 | return err; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1644 | static int tegra_dc_exit(struct host1x_client *client) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1645 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1646 | struct tegra_dc *dc = host1x_client_to_dc(client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1647 | int err; |
| 1648 | |
| 1649 | devm_free_irq(dc->dev, dc->irq, dc); |
| 1650 | |
| 1651 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
| 1652 | err = tegra_dc_debugfs_exit(dc); |
| 1653 | if (err < 0) |
| 1654 | dev_err(dc->dev, "debugfs cleanup failed: %d\n", err); |
| 1655 | } |
| 1656 | |
| 1657 | err = tegra_dc_rgb_exit(dc); |
| 1658 | if (err) { |
| 1659 | dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err); |
| 1660 | return err; |
| 1661 | } |
| 1662 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 1663 | if (dc->domain) { |
| 1664 | iommu_detach_device(dc->domain, dc->dev); |
| 1665 | dc->domain = NULL; |
| 1666 | } |
| 1667 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | static const struct host1x_client_ops dc_client_ops = { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1672 | .init = tegra_dc_init, |
| 1673 | .exit = tegra_dc_exit, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1674 | }; |
| 1675 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1676 | static const struct tegra_dc_soc_info tegra20_dc_soc_info = { |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 1677 | .supports_border_color = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1678 | .supports_interlacing = false, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1679 | .supports_cursor = false, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1680 | .supports_block_linear = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1681 | .pitch_align = 8, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1682 | .has_powergate = false, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1683 | }; |
| 1684 | |
| 1685 | static const struct tegra_dc_soc_info tegra30_dc_soc_info = { |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 1686 | .supports_border_color = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1687 | .supports_interlacing = false, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1688 | .supports_cursor = false, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1689 | .supports_block_linear = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1690 | .pitch_align = 8, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1691 | .has_powergate = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1692 | }; |
| 1693 | |
| 1694 | static const struct tegra_dc_soc_info tegra114_dc_soc_info = { |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 1695 | .supports_border_color = true, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1696 | .supports_interlacing = false, |
| 1697 | .supports_cursor = false, |
| 1698 | .supports_block_linear = false, |
| 1699 | .pitch_align = 64, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1700 | .has_powergate = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1701 | }; |
| 1702 | |
| 1703 | static const struct tegra_dc_soc_info tegra124_dc_soc_info = { |
Thierry Reding | 42d0659 | 2014-12-08 15:45:39 +0100 | [diff] [blame] | 1704 | .supports_border_color = false, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1705 | .supports_interlacing = true, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1706 | .supports_cursor = true, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1707 | .supports_block_linear = true, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1708 | .pitch_align = 64, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1709 | .has_powergate = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1710 | }; |
| 1711 | |
| 1712 | static const struct of_device_id tegra_dc_of_match[] = { |
| 1713 | { |
| 1714 | .compatible = "nvidia,tegra124-dc", |
| 1715 | .data = &tegra124_dc_soc_info, |
| 1716 | }, { |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1717 | .compatible = "nvidia,tegra114-dc", |
| 1718 | .data = &tegra114_dc_soc_info, |
| 1719 | }, { |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1720 | .compatible = "nvidia,tegra30-dc", |
| 1721 | .data = &tegra30_dc_soc_info, |
| 1722 | }, { |
| 1723 | .compatible = "nvidia,tegra20-dc", |
| 1724 | .data = &tegra20_dc_soc_info, |
| 1725 | }, { |
| 1726 | /* sentinel */ |
| 1727 | } |
| 1728 | }; |
Stephen Warren | ef70728 | 2014-06-18 16:21:55 -0600 | [diff] [blame] | 1729 | MODULE_DEVICE_TABLE(of, tegra_dc_of_match); |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1730 | |
Thierry Reding | 13411dd | 2014-01-09 17:08:36 +0100 | [diff] [blame] | 1731 | static int tegra_dc_parse_dt(struct tegra_dc *dc) |
| 1732 | { |
| 1733 | struct device_node *np; |
| 1734 | u32 value = 0; |
| 1735 | int err; |
| 1736 | |
| 1737 | err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value); |
| 1738 | if (err < 0) { |
| 1739 | dev_err(dc->dev, "missing \"nvidia,head\" property\n"); |
| 1740 | |
| 1741 | /* |
| 1742 | * If the nvidia,head property isn't present, try to find the |
| 1743 | * correct head number by looking up the position of this |
| 1744 | * display controller's node within the device tree. Assuming |
| 1745 | * that the nodes are ordered properly in the DTS file and |
| 1746 | * that the translation into a flattened device tree blob |
| 1747 | * preserves that ordering this will actually yield the right |
| 1748 | * head number. |
| 1749 | * |
| 1750 | * If those assumptions don't hold, this will still work for |
| 1751 | * cases where only a single display controller is used. |
| 1752 | */ |
| 1753 | for_each_matching_node(np, tegra_dc_of_match) { |
| 1754 | if (np == dc->dev->of_node) |
| 1755 | break; |
| 1756 | |
| 1757 | value++; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | dc->pipe = value; |
| 1762 | |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1766 | static int tegra_dc_probe(struct platform_device *pdev) |
| 1767 | { |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1768 | const struct of_device_id *id; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1769 | struct resource *regs; |
| 1770 | struct tegra_dc *dc; |
| 1771 | int err; |
| 1772 | |
| 1773 | dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL); |
| 1774 | if (!dc) |
| 1775 | return -ENOMEM; |
| 1776 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1777 | id = of_match_node(tegra_dc_of_match, pdev->dev.of_node); |
| 1778 | if (!id) |
| 1779 | return -ENODEV; |
| 1780 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1781 | spin_lock_init(&dc->lock); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1782 | INIT_LIST_HEAD(&dc->list); |
| 1783 | dc->dev = &pdev->dev; |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1784 | dc->soc = id->data; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1785 | |
Thierry Reding | 13411dd | 2014-01-09 17:08:36 +0100 | [diff] [blame] | 1786 | err = tegra_dc_parse_dt(dc); |
| 1787 | if (err < 0) |
| 1788 | return err; |
| 1789 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1790 | dc->clk = devm_clk_get(&pdev->dev, NULL); |
| 1791 | if (IS_ERR(dc->clk)) { |
| 1792 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 1793 | return PTR_ERR(dc->clk); |
| 1794 | } |
| 1795 | |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 1796 | dc->rst = devm_reset_control_get(&pdev->dev, "dc"); |
| 1797 | if (IS_ERR(dc->rst)) { |
| 1798 | dev_err(&pdev->dev, "failed to get reset\n"); |
| 1799 | return PTR_ERR(dc->rst); |
| 1800 | } |
| 1801 | |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1802 | if (dc->soc->has_powergate) { |
| 1803 | if (dc->pipe == 0) |
| 1804 | dc->powergate = TEGRA_POWERGATE_DIS; |
| 1805 | else |
| 1806 | dc->powergate = TEGRA_POWERGATE_DISB; |
| 1807 | |
| 1808 | err = tegra_powergate_sequence_power_up(dc->powergate, dc->clk, |
| 1809 | dc->rst); |
| 1810 | if (err < 0) { |
| 1811 | dev_err(&pdev->dev, "failed to power partition: %d\n", |
| 1812 | err); |
| 1813 | return err; |
| 1814 | } |
| 1815 | } else { |
| 1816 | err = clk_prepare_enable(dc->clk); |
| 1817 | if (err < 0) { |
| 1818 | dev_err(&pdev->dev, "failed to enable clock: %d\n", |
| 1819 | err); |
| 1820 | return err; |
| 1821 | } |
| 1822 | |
| 1823 | err = reset_control_deassert(dc->rst); |
| 1824 | if (err < 0) { |
| 1825 | dev_err(&pdev->dev, "failed to deassert reset: %d\n", |
| 1826 | err); |
| 1827 | return err; |
| 1828 | } |
| 1829 | } |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1830 | |
| 1831 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | d4ed602 | 2013-01-21 11:09:02 +0100 | [diff] [blame] | 1832 | dc->regs = devm_ioremap_resource(&pdev->dev, regs); |
| 1833 | if (IS_ERR(dc->regs)) |
| 1834 | return PTR_ERR(dc->regs); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1835 | |
| 1836 | dc->irq = platform_get_irq(pdev, 0); |
| 1837 | if (dc->irq < 0) { |
| 1838 | dev_err(&pdev->dev, "failed to get IRQ\n"); |
| 1839 | return -ENXIO; |
| 1840 | } |
| 1841 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1842 | INIT_LIST_HEAD(&dc->client.list); |
| 1843 | dc->client.ops = &dc_client_ops; |
| 1844 | dc->client.dev = &pdev->dev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1845 | |
| 1846 | err = tegra_dc_rgb_probe(dc); |
| 1847 | if (err < 0 && err != -ENODEV) { |
| 1848 | dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err); |
| 1849 | return err; |
| 1850 | } |
| 1851 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1852 | err = host1x_client_register(&dc->client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1853 | if (err < 0) { |
| 1854 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 1855 | err); |
| 1856 | return err; |
| 1857 | } |
| 1858 | |
| 1859 | platform_set_drvdata(pdev, dc); |
| 1860 | |
| 1861 | return 0; |
| 1862 | } |
| 1863 | |
| 1864 | static int tegra_dc_remove(struct platform_device *pdev) |
| 1865 | { |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1866 | struct tegra_dc *dc = platform_get_drvdata(pdev); |
| 1867 | int err; |
| 1868 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1869 | err = host1x_client_unregister(&dc->client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1870 | if (err < 0) { |
| 1871 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 1872 | err); |
| 1873 | return err; |
| 1874 | } |
| 1875 | |
Thierry Reding | 59d29c0 | 2013-10-14 14:26:42 +0200 | [diff] [blame] | 1876 | err = tegra_dc_rgb_remove(dc); |
| 1877 | if (err < 0) { |
| 1878 | dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err); |
| 1879 | return err; |
| 1880 | } |
| 1881 | |
Thierry Reding | 5482d75 | 2014-07-11 08:39:03 +0200 | [diff] [blame] | 1882 | reset_control_assert(dc->rst); |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1883 | |
| 1884 | if (dc->soc->has_powergate) |
| 1885 | tegra_powergate_power_off(dc->powergate); |
| 1886 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1887 | clk_disable_unprepare(dc->clk); |
| 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1892 | struct platform_driver tegra_dc_driver = { |
| 1893 | .driver = { |
| 1894 | .name = "tegra-dc", |
| 1895 | .owner = THIS_MODULE, |
| 1896 | .of_match_table = tegra_dc_of_match, |
| 1897 | }, |
| 1898 | .probe = tegra_dc_probe, |
| 1899 | .remove = tegra_dc_remove, |
| 1900 | }; |