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 | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 21 | struct tegra_dc_soc_info { |
| 22 | bool supports_interlacing; |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 23 | bool supports_cursor; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 24 | bool supports_block_linear; |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 25 | unsigned int pitch_align; |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 26 | bool has_powergate; |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 29 | struct tegra_plane { |
| 30 | struct drm_plane base; |
| 31 | unsigned int index; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 34 | static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane) |
| 35 | { |
| 36 | return container_of(plane, struct tegra_plane, base); |
| 37 | } |
| 38 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 39 | static void tegra_dc_window_commit(struct tegra_dc *dc, unsigned int index) |
| 40 | { |
| 41 | u32 value = WIN_A_ACT_REQ << index; |
| 42 | |
| 43 | tegra_dc_writel(dc, value << 8, DC_CMD_STATE_CONTROL); |
| 44 | tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); |
| 45 | } |
| 46 | |
| 47 | static void tegra_dc_cursor_commit(struct tegra_dc *dc) |
| 48 | { |
| 49 | tegra_dc_writel(dc, CURSOR_ACT_REQ << 8, DC_CMD_STATE_CONTROL); |
| 50 | tegra_dc_writel(dc, CURSOR_ACT_REQ, DC_CMD_STATE_CONTROL); |
| 51 | } |
| 52 | |
| 53 | static void tegra_dc_commit(struct tegra_dc *dc) |
| 54 | { |
| 55 | tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL); |
| 56 | tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL); |
| 57 | } |
| 58 | |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 59 | static unsigned int tegra_dc_format(uint32_t format, uint32_t *swap) |
| 60 | { |
| 61 | /* assume no swapping of fetched data */ |
| 62 | if (swap) |
| 63 | *swap = BYTE_SWAP_NOSWAP; |
| 64 | |
| 65 | switch (format) { |
| 66 | case DRM_FORMAT_XBGR8888: |
| 67 | return WIN_COLOR_DEPTH_R8G8B8A8; |
| 68 | |
| 69 | case DRM_FORMAT_XRGB8888: |
| 70 | return WIN_COLOR_DEPTH_B8G8R8A8; |
| 71 | |
| 72 | case DRM_FORMAT_RGB565: |
| 73 | return WIN_COLOR_DEPTH_B5G6R5; |
| 74 | |
| 75 | case DRM_FORMAT_UYVY: |
| 76 | return WIN_COLOR_DEPTH_YCbCr422; |
| 77 | |
| 78 | case DRM_FORMAT_YUYV: |
| 79 | if (swap) |
| 80 | *swap = BYTE_SWAP_SWAP2; |
| 81 | |
| 82 | return WIN_COLOR_DEPTH_YCbCr422; |
| 83 | |
| 84 | case DRM_FORMAT_YUV420: |
| 85 | return WIN_COLOR_DEPTH_YCbCr420P; |
| 86 | |
| 87 | case DRM_FORMAT_YUV422: |
| 88 | return WIN_COLOR_DEPTH_YCbCr422P; |
| 89 | |
| 90 | default: |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | WARN(1, "unsupported pixel format %u, using default\n", format); |
| 95 | return WIN_COLOR_DEPTH_B8G8R8A8; |
| 96 | } |
| 97 | |
| 98 | static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar) |
| 99 | { |
| 100 | switch (format) { |
| 101 | case WIN_COLOR_DEPTH_YCbCr422: |
| 102 | case WIN_COLOR_DEPTH_YUV422: |
| 103 | if (planar) |
| 104 | *planar = false; |
| 105 | |
| 106 | return true; |
| 107 | |
| 108 | case WIN_COLOR_DEPTH_YCbCr420P: |
| 109 | case WIN_COLOR_DEPTH_YUV420P: |
| 110 | case WIN_COLOR_DEPTH_YCbCr422P: |
| 111 | case WIN_COLOR_DEPTH_YUV422P: |
| 112 | case WIN_COLOR_DEPTH_YCbCr422R: |
| 113 | case WIN_COLOR_DEPTH_YUV422R: |
| 114 | case WIN_COLOR_DEPTH_YCbCr422RA: |
| 115 | case WIN_COLOR_DEPTH_YUV422RA: |
| 116 | if (planar) |
| 117 | *planar = true; |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v, |
| 126 | unsigned int bpp) |
| 127 | { |
| 128 | fixed20_12 outf = dfixed_init(out); |
| 129 | fixed20_12 inf = dfixed_init(in); |
| 130 | u32 dda_inc; |
| 131 | int max; |
| 132 | |
| 133 | if (v) |
| 134 | max = 15; |
| 135 | else { |
| 136 | switch (bpp) { |
| 137 | case 2: |
| 138 | max = 8; |
| 139 | break; |
| 140 | |
| 141 | default: |
| 142 | WARN_ON_ONCE(1); |
| 143 | /* fallthrough */ |
| 144 | case 4: |
| 145 | max = 4; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1)); |
| 151 | inf.full -= dfixed_const(1); |
| 152 | |
| 153 | dda_inc = dfixed_div(inf, outf); |
| 154 | dda_inc = min_t(u32, dda_inc, dfixed_const(max)); |
| 155 | |
| 156 | return dda_inc; |
| 157 | } |
| 158 | |
| 159 | static inline u32 compute_initial_dda(unsigned int in) |
| 160 | { |
| 161 | fixed20_12 inf = dfixed_init(in); |
| 162 | return dfixed_frac(inf); |
| 163 | } |
| 164 | |
| 165 | static int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index, |
| 166 | const struct tegra_dc_window *window) |
| 167 | { |
| 168 | unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp; |
| 169 | unsigned long value; |
| 170 | bool yuv, planar; |
| 171 | |
| 172 | /* |
| 173 | * For YUV planar modes, the number of bytes per pixel takes into |
| 174 | * account only the luma component and therefore is 1. |
| 175 | */ |
| 176 | yuv = tegra_dc_format_is_yuv(window->format, &planar); |
| 177 | if (!yuv) |
| 178 | bpp = window->bits_per_pixel / 8; |
| 179 | else |
| 180 | bpp = planar ? 1 : 2; |
| 181 | |
| 182 | value = WINDOW_A_SELECT << index; |
| 183 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 184 | |
| 185 | tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH); |
| 186 | tegra_dc_writel(dc, window->swap, DC_WIN_BYTE_SWAP); |
| 187 | |
| 188 | value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x); |
| 189 | tegra_dc_writel(dc, value, DC_WIN_POSITION); |
| 190 | |
| 191 | value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w); |
| 192 | tegra_dc_writel(dc, value, DC_WIN_SIZE); |
| 193 | |
| 194 | h_offset = window->src.x * bpp; |
| 195 | v_offset = window->src.y; |
| 196 | h_size = window->src.w * bpp; |
| 197 | v_size = window->src.h; |
| 198 | |
| 199 | value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size); |
| 200 | tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE); |
| 201 | |
| 202 | /* |
| 203 | * For DDA computations the number of bytes per pixel for YUV planar |
| 204 | * modes needs to take into account all Y, U and V components. |
| 205 | */ |
| 206 | if (yuv && planar) |
| 207 | bpp = 2; |
| 208 | |
| 209 | h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp); |
| 210 | v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp); |
| 211 | |
| 212 | value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda); |
| 213 | tegra_dc_writel(dc, value, DC_WIN_DDA_INC); |
| 214 | |
| 215 | h_dda = compute_initial_dda(window->src.x); |
| 216 | v_dda = compute_initial_dda(window->src.y); |
| 217 | |
| 218 | tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA); |
| 219 | tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA); |
| 220 | |
| 221 | tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE); |
| 222 | tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE); |
| 223 | |
| 224 | tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR); |
| 225 | |
| 226 | if (yuv && planar) { |
| 227 | tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U); |
| 228 | tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V); |
| 229 | value = window->stride[1] << 16 | window->stride[0]; |
| 230 | tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE); |
| 231 | } else { |
| 232 | tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE); |
| 233 | } |
| 234 | |
| 235 | if (window->bottom_up) |
| 236 | v_offset += window->src.h - 1; |
| 237 | |
| 238 | tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET); |
| 239 | tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET); |
| 240 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 241 | if (dc->soc->supports_block_linear) { |
| 242 | unsigned long height = window->tiling.value; |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 243 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 244 | switch (window->tiling.mode) { |
| 245 | case TEGRA_BO_TILING_MODE_PITCH: |
| 246 | value = DC_WINBUF_SURFACE_KIND_PITCH; |
| 247 | break; |
| 248 | |
| 249 | case TEGRA_BO_TILING_MODE_TILED: |
| 250 | value = DC_WINBUF_SURFACE_KIND_TILED; |
| 251 | break; |
| 252 | |
| 253 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 254 | value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) | |
| 255 | DC_WINBUF_SURFACE_KIND_BLOCK; |
| 256 | break; |
| 257 | } |
| 258 | |
| 259 | tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND); |
| 260 | } else { |
| 261 | switch (window->tiling.mode) { |
| 262 | case TEGRA_BO_TILING_MODE_PITCH: |
| 263 | value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | |
| 264 | DC_WIN_BUFFER_ADDR_MODE_LINEAR; |
| 265 | break; |
| 266 | |
| 267 | case TEGRA_BO_TILING_MODE_TILED: |
| 268 | value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV | |
| 269 | DC_WIN_BUFFER_ADDR_MODE_TILE; |
| 270 | break; |
| 271 | |
| 272 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 273 | DRM_ERROR("hardware doesn't support block linear mode\n"); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
| 277 | tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE); |
| 278 | } |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 279 | |
| 280 | value = WIN_ENABLE; |
| 281 | |
| 282 | if (yuv) { |
| 283 | /* setup default colorspace conversion coefficients */ |
| 284 | tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF); |
| 285 | tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB); |
| 286 | tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR); |
| 287 | tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR); |
| 288 | tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG); |
| 289 | tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG); |
| 290 | tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB); |
| 291 | tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB); |
| 292 | |
| 293 | value |= CSC_ENABLE; |
| 294 | } else if (window->bits_per_pixel < 24) { |
| 295 | value |= COLOR_EXPAND; |
| 296 | } |
| 297 | |
| 298 | if (window->bottom_up) |
| 299 | value |= V_DIRECTION; |
| 300 | |
| 301 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 302 | |
| 303 | /* |
| 304 | * Disable blending and assume Window A is the bottom-most window, |
| 305 | * Window C is the top-most window and Window B is in the middle. |
| 306 | */ |
| 307 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY); |
| 308 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN); |
| 309 | |
| 310 | switch (index) { |
| 311 | case 0: |
| 312 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X); |
| 313 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); |
| 314 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); |
| 315 | break; |
| 316 | |
| 317 | case 1: |
| 318 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); |
| 319 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y); |
| 320 | tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY); |
| 321 | break; |
| 322 | |
| 323 | case 2: |
| 324 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X); |
| 325 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y); |
| 326 | tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY); |
| 327 | break; |
| 328 | } |
| 329 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 330 | tegra_dc_window_commit(dc, index); |
Thierry Reding | 10288ee | 2014-03-14 09:54:58 +0100 | [diff] [blame] | 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 335 | static int tegra_plane_update(struct drm_plane *plane, struct drm_crtc *crtc, |
| 336 | struct drm_framebuffer *fb, int crtc_x, |
| 337 | int crtc_y, unsigned int crtc_w, |
| 338 | unsigned int crtc_h, uint32_t src_x, |
| 339 | uint32_t src_y, uint32_t src_w, uint32_t src_h) |
| 340 | { |
| 341 | struct tegra_plane *p = to_tegra_plane(plane); |
| 342 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 343 | struct tegra_dc_window window; |
| 344 | unsigned int i; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 345 | int err; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 346 | |
| 347 | memset(&window, 0, sizeof(window)); |
| 348 | window.src.x = src_x >> 16; |
| 349 | window.src.y = src_y >> 16; |
| 350 | window.src.w = src_w >> 16; |
| 351 | window.src.h = src_h >> 16; |
| 352 | window.dst.x = crtc_x; |
| 353 | window.dst.y = crtc_y; |
| 354 | window.dst.w = crtc_w; |
| 355 | window.dst.h = crtc_h; |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 356 | window.format = tegra_dc_format(fb->pixel_format, &window.swap); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 357 | window.bits_per_pixel = fb->bits_per_pixel; |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 358 | window.bottom_up = tegra_fb_is_bottom_up(fb); |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 359 | |
| 360 | err = tegra_fb_get_tiling(fb, &window.tiling); |
| 361 | if (err < 0) |
| 362 | return err; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 363 | |
| 364 | for (i = 0; i < drm_format_num_planes(fb->pixel_format); i++) { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 365 | struct tegra_bo *bo = tegra_fb_get_plane(fb, i); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 366 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 367 | window.base[i] = bo->paddr + fb->offsets[i]; |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * Tegra doesn't support different strides for U and V planes |
| 371 | * so we display a warning if the user tries to display a |
| 372 | * framebuffer with such a configuration. |
| 373 | */ |
| 374 | if (i >= 2) { |
| 375 | if (fb->pitches[i] != window.stride[1]) |
| 376 | DRM_ERROR("unsupported UV-plane configuration\n"); |
| 377 | } else { |
| 378 | window.stride[i] = fb->pitches[i]; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return tegra_dc_setup_window(dc, p->index, &window); |
| 383 | } |
| 384 | |
| 385 | static int tegra_plane_disable(struct drm_plane *plane) |
| 386 | { |
| 387 | struct tegra_dc *dc = to_tegra_dc(plane->crtc); |
| 388 | struct tegra_plane *p = to_tegra_plane(plane); |
| 389 | unsigned long value; |
| 390 | |
Thierry Reding | 2678aeb | 2013-03-18 11:09:13 +0100 | [diff] [blame] | 391 | if (!plane->crtc) |
| 392 | return 0; |
| 393 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 394 | value = WINDOW_A_SELECT << p->index; |
| 395 | tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 396 | |
| 397 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
| 398 | value &= ~WIN_ENABLE; |
| 399 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 400 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 401 | tegra_dc_window_commit(dc, p->index); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static void tegra_plane_destroy(struct drm_plane *plane) |
| 407 | { |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 408 | struct tegra_plane *p = to_tegra_plane(plane); |
| 409 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 410 | tegra_plane_disable(plane); |
| 411 | drm_plane_cleanup(plane); |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 412 | kfree(p); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static const struct drm_plane_funcs tegra_plane_funcs = { |
| 416 | .update_plane = tegra_plane_update, |
| 417 | .disable_plane = tegra_plane_disable, |
| 418 | .destroy = tegra_plane_destroy, |
| 419 | }; |
| 420 | |
| 421 | static const uint32_t plane_formats[] = { |
Thierry Reding | dbe4d9a | 2013-03-22 15:37:30 +0100 | [diff] [blame] | 422 | DRM_FORMAT_XBGR8888, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 423 | DRM_FORMAT_XRGB8888, |
Thierry Reding | dbe4d9a | 2013-03-22 15:37:30 +0100 | [diff] [blame] | 424 | DRM_FORMAT_RGB565, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 425 | DRM_FORMAT_UYVY, |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 426 | DRM_FORMAT_YUYV, |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 427 | DRM_FORMAT_YUV420, |
| 428 | DRM_FORMAT_YUV422, |
| 429 | }; |
| 430 | |
| 431 | static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc) |
| 432 | { |
| 433 | unsigned int i; |
| 434 | int err = 0; |
| 435 | |
| 436 | for (i = 0; i < 2; i++) { |
| 437 | struct tegra_plane *plane; |
| 438 | |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 439 | plane = kzalloc(sizeof(*plane), GFP_KERNEL); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 440 | if (!plane) |
| 441 | return -ENOMEM; |
| 442 | |
| 443 | plane->index = 1 + i; |
| 444 | |
| 445 | err = drm_plane_init(drm, &plane->base, 1 << dc->pipe, |
| 446 | &tegra_plane_funcs, plane_formats, |
| 447 | ARRAY_SIZE(plane_formats), false); |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 448 | if (err < 0) { |
| 449 | kfree(plane); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 450 | return err; |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 451 | } |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 457 | static int tegra_dc_set_base(struct tegra_dc *dc, int x, int y, |
| 458 | struct drm_framebuffer *fb) |
| 459 | { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 460 | struct tegra_bo *bo = tegra_fb_get_plane(fb, 0); |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 461 | unsigned int h_offset = 0, v_offset = 0; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 462 | struct tegra_bo_tiling tiling; |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 463 | unsigned int format, swap; |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 464 | unsigned long value; |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 465 | int err; |
| 466 | |
| 467 | err = tegra_fb_get_tiling(fb, &tiling); |
| 468 | if (err < 0) |
| 469 | return err; |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 470 | |
| 471 | tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER); |
| 472 | |
| 473 | value = fb->offsets[0] + y * fb->pitches[0] + |
| 474 | x * fb->bits_per_pixel / 8; |
| 475 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 476 | tegra_dc_writel(dc, bo->paddr + value, DC_WINBUF_START_ADDR); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 477 | tegra_dc_writel(dc, fb->pitches[0], DC_WIN_LINE_STRIDE); |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 478 | |
| 479 | format = tegra_dc_format(fb->pixel_format, &swap); |
Thierry Reding | ed683ae | 2013-04-22 21:31:15 +0200 | [diff] [blame] | 480 | tegra_dc_writel(dc, format, DC_WIN_COLOR_DEPTH); |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 481 | tegra_dc_writel(dc, swap, DC_WIN_BYTE_SWAP); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 482 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 483 | if (dc->soc->supports_block_linear) { |
| 484 | unsigned long height = tiling.value; |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 485 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 486 | switch (tiling.mode) { |
| 487 | case TEGRA_BO_TILING_MODE_PITCH: |
| 488 | value = DC_WINBUF_SURFACE_KIND_PITCH; |
| 489 | break; |
| 490 | |
| 491 | case TEGRA_BO_TILING_MODE_TILED: |
| 492 | value = DC_WINBUF_SURFACE_KIND_TILED; |
| 493 | break; |
| 494 | |
| 495 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 496 | value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) | |
| 497 | DC_WINBUF_SURFACE_KIND_BLOCK; |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND); |
| 502 | } else { |
| 503 | switch (tiling.mode) { |
| 504 | case TEGRA_BO_TILING_MODE_PITCH: |
| 505 | value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | |
| 506 | DC_WIN_BUFFER_ADDR_MODE_LINEAR; |
| 507 | break; |
| 508 | |
| 509 | case TEGRA_BO_TILING_MODE_TILED: |
| 510 | value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV | |
| 511 | DC_WIN_BUFFER_ADDR_MODE_TILE; |
| 512 | break; |
| 513 | |
| 514 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 515 | DRM_ERROR("hardware doesn't support block linear mode\n"); |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | |
| 519 | tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE); |
| 520 | } |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 521 | |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 522 | /* make sure bottom-up buffers are properly displayed */ |
| 523 | if (tegra_fb_is_bottom_up(fb)) { |
| 524 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
Thierry Reding | eba6650 | 2014-02-25 12:04:06 +0100 | [diff] [blame] | 525 | value |= V_DIRECTION; |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 526 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 527 | |
| 528 | v_offset += fb->height - 1; |
| 529 | } else { |
| 530 | value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS); |
Thierry Reding | eba6650 | 2014-02-25 12:04:06 +0100 | [diff] [blame] | 531 | value &= ~V_DIRECTION; |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 532 | tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS); |
| 533 | } |
| 534 | |
| 535 | tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET); |
| 536 | tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET); |
| 537 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 538 | value = GENERAL_ACT_REQ | WIN_A_ACT_REQ; |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 539 | tegra_dc_writel(dc, value << 8, DC_CMD_STATE_CONTROL); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 540 | tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 545 | void tegra_dc_enable_vblank(struct tegra_dc *dc) |
| 546 | { |
| 547 | unsigned long value, flags; |
| 548 | |
| 549 | spin_lock_irqsave(&dc->lock, flags); |
| 550 | |
| 551 | value = tegra_dc_readl(dc, DC_CMD_INT_MASK); |
| 552 | value |= VBLANK_INT; |
| 553 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
| 554 | |
| 555 | spin_unlock_irqrestore(&dc->lock, flags); |
| 556 | } |
| 557 | |
| 558 | void tegra_dc_disable_vblank(struct tegra_dc *dc) |
| 559 | { |
| 560 | unsigned long value, flags; |
| 561 | |
| 562 | spin_lock_irqsave(&dc->lock, flags); |
| 563 | |
| 564 | value = tegra_dc_readl(dc, DC_CMD_INT_MASK); |
| 565 | value &= ~VBLANK_INT; |
| 566 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
| 567 | |
| 568 | spin_unlock_irqrestore(&dc->lock, flags); |
| 569 | } |
| 570 | |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 571 | static int tegra_dc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file, |
| 572 | uint32_t handle, uint32_t width, |
| 573 | uint32_t height, int32_t hot_x, int32_t hot_y) |
| 574 | { |
| 575 | unsigned long value = CURSOR_CLIP_DISPLAY; |
| 576 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 577 | struct drm_gem_object *gem; |
| 578 | struct tegra_bo *bo = NULL; |
| 579 | |
| 580 | if (!dc->soc->supports_cursor) |
| 581 | return -ENXIO; |
| 582 | |
| 583 | if (width != height) |
| 584 | return -EINVAL; |
| 585 | |
| 586 | switch (width) { |
| 587 | case 32: |
| 588 | value |= CURSOR_SIZE_32x32; |
| 589 | break; |
| 590 | |
| 591 | case 64: |
| 592 | value |= CURSOR_SIZE_64x64; |
| 593 | break; |
| 594 | |
| 595 | case 128: |
| 596 | value |= CURSOR_SIZE_128x128; |
| 597 | |
| 598 | case 256: |
| 599 | value |= CURSOR_SIZE_256x256; |
| 600 | break; |
| 601 | |
| 602 | default: |
| 603 | return -EINVAL; |
| 604 | } |
| 605 | |
| 606 | if (handle) { |
| 607 | gem = drm_gem_object_lookup(crtc->dev, file, handle); |
| 608 | if (!gem) |
| 609 | return -ENOENT; |
| 610 | |
| 611 | bo = to_tegra_bo(gem); |
| 612 | } |
| 613 | |
| 614 | if (bo) { |
| 615 | unsigned long addr = (bo->paddr & 0xfffffc00) >> 10; |
| 616 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 617 | unsigned long high = (bo->paddr & 0xfffffffc) >> 32; |
| 618 | #endif |
| 619 | |
| 620 | tegra_dc_writel(dc, value | addr, DC_DISP_CURSOR_START_ADDR); |
| 621 | |
| 622 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 623 | tegra_dc_writel(dc, high, DC_DISP_CURSOR_START_ADDR_HI); |
| 624 | #endif |
| 625 | |
| 626 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 627 | value |= CURSOR_ENABLE; |
| 628 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 629 | |
| 630 | value = tegra_dc_readl(dc, DC_DISP_BLEND_CURSOR_CONTROL); |
| 631 | value &= ~CURSOR_DST_BLEND_MASK; |
| 632 | value &= ~CURSOR_SRC_BLEND_MASK; |
| 633 | value |= CURSOR_MODE_NORMAL; |
| 634 | value |= CURSOR_DST_BLEND_NEG_K1_TIMES_SRC; |
| 635 | value |= CURSOR_SRC_BLEND_K1_TIMES_SRC; |
| 636 | value |= CURSOR_ALPHA; |
| 637 | tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL); |
| 638 | } else { |
| 639 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 640 | value &= ~CURSOR_ENABLE; |
| 641 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 642 | } |
| 643 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 644 | tegra_dc_cursor_commit(dc); |
| 645 | tegra_dc_commit(dc); |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | static int tegra_dc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 651 | { |
| 652 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 653 | unsigned long value; |
| 654 | |
| 655 | if (!dc->soc->supports_cursor) |
| 656 | return -ENXIO; |
| 657 | |
| 658 | value = ((y & 0x3fff) << 16) | (x & 0x3fff); |
| 659 | tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION); |
| 660 | |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 661 | tegra_dc_cursor_commit(dc); |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 662 | /* XXX: only required on generations earlier than Tegra124? */ |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 663 | tegra_dc_commit(dc); |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 668 | static void tegra_dc_finish_page_flip(struct tegra_dc *dc) |
| 669 | { |
| 670 | struct drm_device *drm = dc->base.dev; |
| 671 | struct drm_crtc *crtc = &dc->base; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 672 | unsigned long flags, base; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 673 | struct tegra_bo *bo; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 674 | |
| 675 | if (!dc->event) |
| 676 | return; |
| 677 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 678 | bo = tegra_fb_get_plane(crtc->primary->fb, 0); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 679 | |
| 680 | /* check if new start address has been latched */ |
| 681 | tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); |
| 682 | base = tegra_dc_readl(dc, DC_WINBUF_START_ADDR); |
| 683 | tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); |
| 684 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 685 | if (base == bo->paddr + crtc->primary->fb->offsets[0]) { |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 686 | spin_lock_irqsave(&drm->event_lock, flags); |
| 687 | drm_send_vblank_event(drm, dc->pipe, dc->event); |
| 688 | drm_vblank_put(drm, dc->pipe); |
| 689 | dc->event = NULL; |
| 690 | spin_unlock_irqrestore(&drm->event_lock, flags); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file) |
| 695 | { |
| 696 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 697 | struct drm_device *drm = crtc->dev; |
| 698 | unsigned long flags; |
| 699 | |
| 700 | spin_lock_irqsave(&drm->event_lock, flags); |
| 701 | |
| 702 | if (dc->event && dc->event->base.file_priv == file) { |
| 703 | dc->event->base.destroy(&dc->event->base); |
| 704 | drm_vblank_put(drm, dc->pipe); |
| 705 | dc->event = NULL; |
| 706 | } |
| 707 | |
| 708 | spin_unlock_irqrestore(&drm->event_lock, flags); |
| 709 | } |
| 710 | |
| 711 | 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] | 712 | struct drm_pending_vblank_event *event, uint32_t page_flip_flags) |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 713 | { |
| 714 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 715 | struct drm_device *drm = crtc->dev; |
| 716 | |
| 717 | if (dc->event) |
| 718 | return -EBUSY; |
| 719 | |
| 720 | if (event) { |
| 721 | event->pipe = dc->pipe; |
| 722 | dc->event = event; |
| 723 | drm_vblank_get(drm, dc->pipe); |
| 724 | } |
| 725 | |
| 726 | tegra_dc_set_base(dc, 0, 0, fb); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 727 | crtc->primary->fb = fb; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 732 | static void drm_crtc_clear(struct drm_crtc *crtc) |
| 733 | { |
| 734 | memset(crtc, 0, sizeof(*crtc)); |
| 735 | } |
| 736 | |
| 737 | static void tegra_dc_destroy(struct drm_crtc *crtc) |
| 738 | { |
| 739 | drm_crtc_cleanup(crtc); |
| 740 | drm_crtc_clear(crtc); |
| 741 | } |
| 742 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 743 | static const struct drm_crtc_funcs tegra_crtc_funcs = { |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 744 | .cursor_set2 = tegra_dc_cursor_set2, |
| 745 | .cursor_move = tegra_dc_cursor_move, |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 746 | .page_flip = tegra_dc_page_flip, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 747 | .set_config = drm_crtc_helper_set_config, |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 748 | .destroy = tegra_dc_destroy, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 749 | }; |
| 750 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 751 | static void tegra_crtc_disable(struct drm_crtc *crtc) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 752 | { |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 753 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 754 | struct drm_device *drm = crtc->dev; |
| 755 | struct drm_plane *plane; |
| 756 | |
Daniel Vetter | 2b4c366 | 2014-04-23 15:15:32 +0200 | [diff] [blame] | 757 | drm_for_each_legacy_plane(plane, &drm->mode_config.plane_list) { |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 758 | if (plane->crtc == crtc) { |
| 759 | tegra_plane_disable(plane); |
| 760 | plane->crtc = NULL; |
| 761 | |
| 762 | if (plane->fb) { |
| 763 | drm_framebuffer_unreference(plane->fb); |
| 764 | plane->fb = NULL; |
| 765 | } |
| 766 | } |
| 767 | } |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 768 | |
| 769 | drm_vblank_off(drm, dc->pipe); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc, |
| 773 | const struct drm_display_mode *mode, |
| 774 | struct drm_display_mode *adjusted) |
| 775 | { |
| 776 | return true; |
| 777 | } |
| 778 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 779 | static int tegra_dc_set_timings(struct tegra_dc *dc, |
| 780 | struct drm_display_mode *mode) |
| 781 | { |
Thierry Reding | 0444c0f | 2014-04-16 09:22:38 +0200 | [diff] [blame] | 782 | unsigned int h_ref_to_sync = 1; |
| 783 | unsigned int v_ref_to_sync = 1; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 784 | unsigned long value; |
| 785 | |
| 786 | tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS); |
| 787 | |
| 788 | value = (v_ref_to_sync << 16) | h_ref_to_sync; |
| 789 | tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC); |
| 790 | |
| 791 | value = ((mode->vsync_end - mode->vsync_start) << 16) | |
| 792 | ((mode->hsync_end - mode->hsync_start) << 0); |
| 793 | tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH); |
| 794 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 795 | value = ((mode->vtotal - mode->vsync_end) << 16) | |
| 796 | ((mode->htotal - mode->hsync_end) << 0); |
Lucas Stach | 4049508 | 2012-12-19 21:38:52 +0000 | [diff] [blame] | 797 | tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH); |
| 798 | |
| 799 | value = ((mode->vsync_start - mode->vdisplay) << 16) | |
| 800 | ((mode->hsync_start - mode->hdisplay) << 0); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 801 | tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH); |
| 802 | |
| 803 | value = (mode->vdisplay << 16) | mode->hdisplay; |
| 804 | tegra_dc_writel(dc, value, DC_DISP_ACTIVE); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int tegra_crtc_setup_clk(struct drm_crtc *crtc, |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 810 | struct drm_display_mode *mode) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 811 | { |
Thierry Reding | 91eded9 | 2014-03-26 13:32:21 +0100 | [diff] [blame] | 812 | unsigned long pclk = mode->clock * 1000; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 813 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 814 | struct tegra_output *output = NULL; |
| 815 | struct drm_encoder *encoder; |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 816 | unsigned int div; |
| 817 | u32 value; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 818 | long err; |
| 819 | |
| 820 | list_for_each_entry(encoder, &crtc->dev->mode_config.encoder_list, head) |
| 821 | if (encoder->crtc == crtc) { |
| 822 | output = encoder_to_output(encoder); |
| 823 | break; |
| 824 | } |
| 825 | |
| 826 | if (!output) |
| 827 | return -ENODEV; |
| 828 | |
| 829 | /* |
Thierry Reding | 91eded9 | 2014-03-26 13:32:21 +0100 | [diff] [blame] | 830 | * This assumes that the parent clock is pll_d_out0 or pll_d2_out |
| 831 | * respectively, each of which divides the base pll_d by 2. |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 832 | */ |
Thierry Reding | 91eded9 | 2014-03-26 13:32:21 +0100 | [diff] [blame] | 833 | err = tegra_output_setup_clock(output, dc->clk, pclk, &div); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 834 | if (err < 0) { |
| 835 | dev_err(dc->dev, "failed to setup clock: %ld\n", err); |
| 836 | return err; |
| 837 | } |
| 838 | |
Thierry Reding | 91eded9 | 2014-03-26 13:32:21 +0100 | [diff] [blame] | 839 | DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk), div); |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 840 | |
| 841 | value = SHIFT_CLK_DIVIDER(div) | PIXEL_CLK_DIVIDER_PCD1; |
| 842 | tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static int tegra_crtc_mode_set(struct drm_crtc *crtc, |
| 848 | struct drm_display_mode *mode, |
| 849 | struct drm_display_mode *adjusted, |
| 850 | int x, int y, struct drm_framebuffer *old_fb) |
| 851 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 852 | struct tegra_bo *bo = tegra_fb_get_plane(crtc->primary->fb, 0); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 853 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 854 | struct tegra_dc_window window; |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 855 | u32 value; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 856 | int err; |
| 857 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 858 | drm_vblank_pre_modeset(crtc->dev, dc->pipe); |
| 859 | |
Thierry Reding | dbb3f2f | 2014-03-26 12:32:14 +0100 | [diff] [blame] | 860 | err = tegra_crtc_setup_clk(crtc, mode); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 861 | if (err) { |
| 862 | dev_err(dc->dev, "failed to setup clock for CRTC: %d\n", err); |
| 863 | return err; |
| 864 | } |
| 865 | |
| 866 | /* program display mode */ |
| 867 | tegra_dc_set_timings(dc, mode); |
| 868 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 869 | /* interlacing isn't supported yet, so disable it */ |
| 870 | if (dc->soc->supports_interlacing) { |
| 871 | value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL); |
| 872 | value &= ~INTERLACE_ENABLE; |
| 873 | tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL); |
| 874 | } |
| 875 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 876 | /* setup window parameters */ |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 877 | memset(&window, 0, sizeof(window)); |
| 878 | window.src.x = 0; |
| 879 | window.src.y = 0; |
| 880 | window.src.w = mode->hdisplay; |
| 881 | window.src.h = mode->vdisplay; |
| 882 | window.dst.x = 0; |
| 883 | window.dst.y = 0; |
| 884 | window.dst.w = mode->hdisplay; |
| 885 | window.dst.h = mode->vdisplay; |
Thierry Reding | f925390 | 2014-01-29 20:31:17 +0100 | [diff] [blame] | 886 | window.format = tegra_dc_format(crtc->primary->fb->pixel_format, |
| 887 | &window.swap); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 888 | window.bits_per_pixel = crtc->primary->fb->bits_per_pixel; |
| 889 | window.stride[0] = crtc->primary->fb->pitches[0]; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 890 | window.base[0] = bo->paddr; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 891 | |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 892 | err = tegra_dc_setup_window(dc, 0, &window); |
| 893 | if (err < 0) |
| 894 | dev_err(dc->dev, "failed to enable root plane\n"); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 899 | static int tegra_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 900 | struct drm_framebuffer *old_fb) |
| 901 | { |
| 902 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 903 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 904 | return tegra_dc_set_base(dc, x, y, crtc->primary->fb); |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 907 | static void tegra_crtc_prepare(struct drm_crtc *crtc) |
| 908 | { |
| 909 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 910 | unsigned int syncpt; |
| 911 | unsigned long value; |
| 912 | |
| 913 | /* hardware initialization */ |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 914 | reset_control_deassert(dc->rst); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 915 | usleep_range(10000, 20000); |
| 916 | |
| 917 | if (dc->pipe) |
| 918 | syncpt = SYNCPT_VBLANK1; |
| 919 | else |
| 920 | syncpt = SYNCPT_VBLANK0; |
| 921 | |
| 922 | /* initialize display controller */ |
| 923 | tegra_dc_writel(dc, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); |
| 924 | tegra_dc_writel(dc, 0x100 | syncpt, DC_CMD_CONT_SYNCPT_VSYNC); |
| 925 | |
| 926 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | WIN_A_OF_INT; |
| 927 | tegra_dc_writel(dc, value, DC_CMD_INT_TYPE); |
| 928 | |
| 929 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | |
| 930 | WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT; |
| 931 | tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY); |
| 932 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 933 | /* initialize timer */ |
| 934 | value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) | |
| 935 | WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20); |
| 936 | tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY); |
| 937 | |
| 938 | value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) | |
| 939 | WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1); |
| 940 | tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); |
| 941 | |
| 942 | 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] | 943 | tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 944 | |
| 945 | value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT; |
| 946 | tegra_dc_writel(dc, value, DC_CMD_INT_MASK); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | static void tegra_crtc_commit(struct drm_crtc *crtc) |
| 950 | { |
| 951 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 952 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 953 | drm_vblank_post_modeset(crtc->dev, dc->pipe); |
Thierry Reding | 205d48e | 2014-10-21 13:41:46 +0200 | [diff] [blame] | 954 | tegra_dc_commit(dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | static void tegra_crtc_load_lut(struct drm_crtc *crtc) |
| 958 | { |
| 959 | } |
| 960 | |
| 961 | static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = { |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 962 | .disable = tegra_crtc_disable, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 963 | .mode_fixup = tegra_crtc_mode_fixup, |
| 964 | .mode_set = tegra_crtc_mode_set, |
Thierry Reding | 23fb474 | 2012-11-28 11:38:24 +0100 | [diff] [blame] | 965 | .mode_set_base = tegra_crtc_mode_set_base, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 966 | .prepare = tegra_crtc_prepare, |
| 967 | .commit = tegra_crtc_commit, |
| 968 | .load_lut = tegra_crtc_load_lut, |
| 969 | }; |
| 970 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 971 | static irqreturn_t tegra_dc_irq(int irq, void *data) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 972 | { |
| 973 | struct tegra_dc *dc = data; |
| 974 | unsigned long status; |
| 975 | |
| 976 | status = tegra_dc_readl(dc, DC_CMD_INT_STATUS); |
| 977 | tegra_dc_writel(dc, status, DC_CMD_INT_STATUS); |
| 978 | |
| 979 | if (status & FRAME_END_INT) { |
| 980 | /* |
| 981 | dev_dbg(dc->dev, "%s(): frame end\n", __func__); |
| 982 | */ |
| 983 | } |
| 984 | |
| 985 | if (status & VBLANK_INT) { |
| 986 | /* |
| 987 | dev_dbg(dc->dev, "%s(): vertical blank\n", __func__); |
| 988 | */ |
| 989 | drm_handle_vblank(dc->base.dev, dc->pipe); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 990 | tegra_dc_finish_page_flip(dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) { |
| 994 | /* |
| 995 | dev_dbg(dc->dev, "%s(): underflow\n", __func__); |
| 996 | */ |
| 997 | } |
| 998 | |
| 999 | return IRQ_HANDLED; |
| 1000 | } |
| 1001 | |
| 1002 | static int tegra_dc_show_regs(struct seq_file *s, void *data) |
| 1003 | { |
| 1004 | struct drm_info_node *node = s->private; |
| 1005 | struct tegra_dc *dc = node->info_ent->data; |
| 1006 | |
| 1007 | #define DUMP_REG(name) \ |
Thierry Reding | 03a6056 | 2014-10-21 13:48:48 +0200 | [diff] [blame^] | 1008 | seq_printf(s, "%-40s %#05x %08x\n", #name, name, \ |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1009 | tegra_dc_readl(dc, name)) |
| 1010 | |
| 1011 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT); |
| 1012 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL); |
| 1013 | DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR); |
| 1014 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT); |
| 1015 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL); |
| 1016 | DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR); |
| 1017 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT); |
| 1018 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL); |
| 1019 | DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR); |
| 1020 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT); |
| 1021 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL); |
| 1022 | DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR); |
| 1023 | DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC); |
| 1024 | DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0); |
| 1025 | DUMP_REG(DC_CMD_DISPLAY_COMMAND); |
| 1026 | DUMP_REG(DC_CMD_SIGNAL_RAISE); |
| 1027 | DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL); |
| 1028 | DUMP_REG(DC_CMD_INT_STATUS); |
| 1029 | DUMP_REG(DC_CMD_INT_MASK); |
| 1030 | DUMP_REG(DC_CMD_INT_ENABLE); |
| 1031 | DUMP_REG(DC_CMD_INT_TYPE); |
| 1032 | DUMP_REG(DC_CMD_INT_POLARITY); |
| 1033 | DUMP_REG(DC_CMD_SIGNAL_RAISE1); |
| 1034 | DUMP_REG(DC_CMD_SIGNAL_RAISE2); |
| 1035 | DUMP_REG(DC_CMD_SIGNAL_RAISE3); |
| 1036 | DUMP_REG(DC_CMD_STATE_ACCESS); |
| 1037 | DUMP_REG(DC_CMD_STATE_CONTROL); |
| 1038 | DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER); |
| 1039 | DUMP_REG(DC_CMD_REG_ACT_CONTROL); |
| 1040 | DUMP_REG(DC_COM_CRC_CONTROL); |
| 1041 | DUMP_REG(DC_COM_CRC_CHECKSUM); |
| 1042 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0)); |
| 1043 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1)); |
| 1044 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2)); |
| 1045 | DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3)); |
| 1046 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0)); |
| 1047 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1)); |
| 1048 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2)); |
| 1049 | DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3)); |
| 1050 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0)); |
| 1051 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1)); |
| 1052 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2)); |
| 1053 | DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3)); |
| 1054 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0)); |
| 1055 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1)); |
| 1056 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2)); |
| 1057 | DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3)); |
| 1058 | DUMP_REG(DC_COM_PIN_INPUT_DATA(0)); |
| 1059 | DUMP_REG(DC_COM_PIN_INPUT_DATA(1)); |
| 1060 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0)); |
| 1061 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1)); |
| 1062 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2)); |
| 1063 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3)); |
| 1064 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4)); |
| 1065 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5)); |
| 1066 | DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6)); |
| 1067 | DUMP_REG(DC_COM_PIN_MISC_CONTROL); |
| 1068 | DUMP_REG(DC_COM_PIN_PM0_CONTROL); |
| 1069 | DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE); |
| 1070 | DUMP_REG(DC_COM_PIN_PM1_CONTROL); |
| 1071 | DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE); |
| 1072 | DUMP_REG(DC_COM_SPI_CONTROL); |
| 1073 | DUMP_REG(DC_COM_SPI_START_BYTE); |
| 1074 | DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB); |
| 1075 | DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD); |
| 1076 | DUMP_REG(DC_COM_HSPI_CS_DC); |
| 1077 | DUMP_REG(DC_COM_SCRATCH_REGISTER_A); |
| 1078 | DUMP_REG(DC_COM_SCRATCH_REGISTER_B); |
| 1079 | DUMP_REG(DC_COM_GPIO_CTRL); |
| 1080 | DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER); |
| 1081 | DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED); |
| 1082 | DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 1083 | DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1); |
| 1084 | DUMP_REG(DC_DISP_DISP_WIN_OPTIONS); |
| 1085 | DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY); |
| 1086 | DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER); |
| 1087 | DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS); |
| 1088 | DUMP_REG(DC_DISP_REF_TO_SYNC); |
| 1089 | DUMP_REG(DC_DISP_SYNC_WIDTH); |
| 1090 | DUMP_REG(DC_DISP_BACK_PORCH); |
| 1091 | DUMP_REG(DC_DISP_ACTIVE); |
| 1092 | DUMP_REG(DC_DISP_FRONT_PORCH); |
| 1093 | DUMP_REG(DC_DISP_H_PULSE0_CONTROL); |
| 1094 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_A); |
| 1095 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_B); |
| 1096 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_C); |
| 1097 | DUMP_REG(DC_DISP_H_PULSE0_POSITION_D); |
| 1098 | DUMP_REG(DC_DISP_H_PULSE1_CONTROL); |
| 1099 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_A); |
| 1100 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_B); |
| 1101 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_C); |
| 1102 | DUMP_REG(DC_DISP_H_PULSE1_POSITION_D); |
| 1103 | DUMP_REG(DC_DISP_H_PULSE2_CONTROL); |
| 1104 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_A); |
| 1105 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_B); |
| 1106 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_C); |
| 1107 | DUMP_REG(DC_DISP_H_PULSE2_POSITION_D); |
| 1108 | DUMP_REG(DC_DISP_V_PULSE0_CONTROL); |
| 1109 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_A); |
| 1110 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_B); |
| 1111 | DUMP_REG(DC_DISP_V_PULSE0_POSITION_C); |
| 1112 | DUMP_REG(DC_DISP_V_PULSE1_CONTROL); |
| 1113 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_A); |
| 1114 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_B); |
| 1115 | DUMP_REG(DC_DISP_V_PULSE1_POSITION_C); |
| 1116 | DUMP_REG(DC_DISP_V_PULSE2_CONTROL); |
| 1117 | DUMP_REG(DC_DISP_V_PULSE2_POSITION_A); |
| 1118 | DUMP_REG(DC_DISP_V_PULSE3_CONTROL); |
| 1119 | DUMP_REG(DC_DISP_V_PULSE3_POSITION_A); |
| 1120 | DUMP_REG(DC_DISP_M0_CONTROL); |
| 1121 | DUMP_REG(DC_DISP_M1_CONTROL); |
| 1122 | DUMP_REG(DC_DISP_DI_CONTROL); |
| 1123 | DUMP_REG(DC_DISP_PP_CONTROL); |
| 1124 | DUMP_REG(DC_DISP_PP_SELECT_A); |
| 1125 | DUMP_REG(DC_DISP_PP_SELECT_B); |
| 1126 | DUMP_REG(DC_DISP_PP_SELECT_C); |
| 1127 | DUMP_REG(DC_DISP_PP_SELECT_D); |
| 1128 | DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL); |
| 1129 | DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL); |
| 1130 | DUMP_REG(DC_DISP_DISP_COLOR_CONTROL); |
| 1131 | DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS); |
| 1132 | DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS); |
| 1133 | DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS); |
| 1134 | DUMP_REG(DC_DISP_LCD_SPI_OPTIONS); |
| 1135 | DUMP_REG(DC_DISP_BORDER_COLOR); |
| 1136 | DUMP_REG(DC_DISP_COLOR_KEY0_LOWER); |
| 1137 | DUMP_REG(DC_DISP_COLOR_KEY0_UPPER); |
| 1138 | DUMP_REG(DC_DISP_COLOR_KEY1_LOWER); |
| 1139 | DUMP_REG(DC_DISP_COLOR_KEY1_UPPER); |
| 1140 | DUMP_REG(DC_DISP_CURSOR_FOREGROUND); |
| 1141 | DUMP_REG(DC_DISP_CURSOR_BACKGROUND); |
| 1142 | DUMP_REG(DC_DISP_CURSOR_START_ADDR); |
| 1143 | DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS); |
| 1144 | DUMP_REG(DC_DISP_CURSOR_POSITION); |
| 1145 | DUMP_REG(DC_DISP_CURSOR_POSITION_NS); |
| 1146 | DUMP_REG(DC_DISP_INIT_SEQ_CONTROL); |
| 1147 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A); |
| 1148 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B); |
| 1149 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C); |
| 1150 | DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D); |
| 1151 | DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL); |
| 1152 | DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST); |
| 1153 | DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST); |
| 1154 | DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST); |
| 1155 | DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST); |
| 1156 | DUMP_REG(DC_DISP_DAC_CRT_CTRL); |
| 1157 | DUMP_REG(DC_DISP_DISP_MISC_CONTROL); |
| 1158 | DUMP_REG(DC_DISP_SD_CONTROL); |
| 1159 | DUMP_REG(DC_DISP_SD_CSC_COEFF); |
| 1160 | DUMP_REG(DC_DISP_SD_LUT(0)); |
| 1161 | DUMP_REG(DC_DISP_SD_LUT(1)); |
| 1162 | DUMP_REG(DC_DISP_SD_LUT(2)); |
| 1163 | DUMP_REG(DC_DISP_SD_LUT(3)); |
| 1164 | DUMP_REG(DC_DISP_SD_LUT(4)); |
| 1165 | DUMP_REG(DC_DISP_SD_LUT(5)); |
| 1166 | DUMP_REG(DC_DISP_SD_LUT(6)); |
| 1167 | DUMP_REG(DC_DISP_SD_LUT(7)); |
| 1168 | DUMP_REG(DC_DISP_SD_LUT(8)); |
| 1169 | DUMP_REG(DC_DISP_SD_FLICKER_CONTROL); |
| 1170 | DUMP_REG(DC_DISP_DC_PIXEL_COUNT); |
| 1171 | DUMP_REG(DC_DISP_SD_HISTOGRAM(0)); |
| 1172 | DUMP_REG(DC_DISP_SD_HISTOGRAM(1)); |
| 1173 | DUMP_REG(DC_DISP_SD_HISTOGRAM(2)); |
| 1174 | DUMP_REG(DC_DISP_SD_HISTOGRAM(3)); |
| 1175 | DUMP_REG(DC_DISP_SD_HISTOGRAM(4)); |
| 1176 | DUMP_REG(DC_DISP_SD_HISTOGRAM(5)); |
| 1177 | DUMP_REG(DC_DISP_SD_HISTOGRAM(6)); |
| 1178 | DUMP_REG(DC_DISP_SD_HISTOGRAM(7)); |
| 1179 | DUMP_REG(DC_DISP_SD_BL_TF(0)); |
| 1180 | DUMP_REG(DC_DISP_SD_BL_TF(1)); |
| 1181 | DUMP_REG(DC_DISP_SD_BL_TF(2)); |
| 1182 | DUMP_REG(DC_DISP_SD_BL_TF(3)); |
| 1183 | DUMP_REG(DC_DISP_SD_BL_CONTROL); |
| 1184 | DUMP_REG(DC_DISP_SD_HW_K_VALUES); |
| 1185 | DUMP_REG(DC_DISP_SD_MAN_K_VALUES); |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1186 | DUMP_REG(DC_DISP_CURSOR_START_ADDR_HI); |
| 1187 | DUMP_REG(DC_DISP_BLEND_CURSOR_CONTROL); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1188 | DUMP_REG(DC_WIN_WIN_OPTIONS); |
| 1189 | DUMP_REG(DC_WIN_BYTE_SWAP); |
| 1190 | DUMP_REG(DC_WIN_BUFFER_CONTROL); |
| 1191 | DUMP_REG(DC_WIN_COLOR_DEPTH); |
| 1192 | DUMP_REG(DC_WIN_POSITION); |
| 1193 | DUMP_REG(DC_WIN_SIZE); |
| 1194 | DUMP_REG(DC_WIN_PRESCALED_SIZE); |
| 1195 | DUMP_REG(DC_WIN_H_INITIAL_DDA); |
| 1196 | DUMP_REG(DC_WIN_V_INITIAL_DDA); |
| 1197 | DUMP_REG(DC_WIN_DDA_INC); |
| 1198 | DUMP_REG(DC_WIN_LINE_STRIDE); |
| 1199 | DUMP_REG(DC_WIN_BUF_STRIDE); |
| 1200 | DUMP_REG(DC_WIN_UV_BUF_STRIDE); |
| 1201 | DUMP_REG(DC_WIN_BUFFER_ADDR_MODE); |
| 1202 | DUMP_REG(DC_WIN_DV_CONTROL); |
| 1203 | DUMP_REG(DC_WIN_BLEND_NOKEY); |
| 1204 | DUMP_REG(DC_WIN_BLEND_1WIN); |
| 1205 | DUMP_REG(DC_WIN_BLEND_2WIN_X); |
| 1206 | DUMP_REG(DC_WIN_BLEND_2WIN_Y); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1207 | DUMP_REG(DC_WIN_BLEND_3WIN_XY); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1208 | DUMP_REG(DC_WIN_HP_FETCH_CONTROL); |
| 1209 | DUMP_REG(DC_WINBUF_START_ADDR); |
| 1210 | DUMP_REG(DC_WINBUF_START_ADDR_NS); |
| 1211 | DUMP_REG(DC_WINBUF_START_ADDR_U); |
| 1212 | DUMP_REG(DC_WINBUF_START_ADDR_U_NS); |
| 1213 | DUMP_REG(DC_WINBUF_START_ADDR_V); |
| 1214 | DUMP_REG(DC_WINBUF_START_ADDR_V_NS); |
| 1215 | DUMP_REG(DC_WINBUF_ADDR_H_OFFSET); |
| 1216 | DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS); |
| 1217 | DUMP_REG(DC_WINBUF_ADDR_V_OFFSET); |
| 1218 | DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS); |
| 1219 | DUMP_REG(DC_WINBUF_UFLOW_STATUS); |
| 1220 | DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS); |
| 1221 | DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS); |
| 1222 | DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS); |
| 1223 | |
| 1224 | #undef DUMP_REG |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static struct drm_info_list debugfs_files[] = { |
| 1230 | { "regs", tegra_dc_show_regs, 0, NULL }, |
| 1231 | }; |
| 1232 | |
| 1233 | static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor) |
| 1234 | { |
| 1235 | unsigned int i; |
| 1236 | char *name; |
| 1237 | int err; |
| 1238 | |
| 1239 | name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe); |
| 1240 | dc->debugfs = debugfs_create_dir(name, minor->debugfs_root); |
| 1241 | kfree(name); |
| 1242 | |
| 1243 | if (!dc->debugfs) |
| 1244 | return -ENOMEM; |
| 1245 | |
| 1246 | dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), |
| 1247 | GFP_KERNEL); |
| 1248 | if (!dc->debugfs_files) { |
| 1249 | err = -ENOMEM; |
| 1250 | goto remove; |
| 1251 | } |
| 1252 | |
| 1253 | for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) |
| 1254 | dc->debugfs_files[i].data = dc; |
| 1255 | |
| 1256 | err = drm_debugfs_create_files(dc->debugfs_files, |
| 1257 | ARRAY_SIZE(debugfs_files), |
| 1258 | dc->debugfs, minor); |
| 1259 | if (err < 0) |
| 1260 | goto free; |
| 1261 | |
| 1262 | dc->minor = minor; |
| 1263 | |
| 1264 | return 0; |
| 1265 | |
| 1266 | free: |
| 1267 | kfree(dc->debugfs_files); |
| 1268 | dc->debugfs_files = NULL; |
| 1269 | remove: |
| 1270 | debugfs_remove(dc->debugfs); |
| 1271 | dc->debugfs = NULL; |
| 1272 | |
| 1273 | return err; |
| 1274 | } |
| 1275 | |
| 1276 | static int tegra_dc_debugfs_exit(struct tegra_dc *dc) |
| 1277 | { |
| 1278 | drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files), |
| 1279 | dc->minor); |
| 1280 | dc->minor = NULL; |
| 1281 | |
| 1282 | kfree(dc->debugfs_files); |
| 1283 | dc->debugfs_files = NULL; |
| 1284 | |
| 1285 | debugfs_remove(dc->debugfs); |
| 1286 | dc->debugfs = NULL; |
| 1287 | |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1291 | static int tegra_dc_init(struct host1x_client *client) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1292 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1293 | struct drm_device *drm = dev_get_drvdata(client->parent); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1294 | struct tegra_dc *dc = host1x_client_to_dc(client); |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1295 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1296 | int err; |
| 1297 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 1298 | if (tegra->domain) { |
| 1299 | err = iommu_attach_device(tegra->domain, dc->dev); |
| 1300 | if (err < 0) { |
| 1301 | dev_err(dc->dev, "failed to attach to domain: %d\n", |
| 1302 | err); |
| 1303 | return err; |
| 1304 | } |
| 1305 | |
| 1306 | dc->domain = tegra->domain; |
| 1307 | } |
| 1308 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1309 | drm_crtc_init(drm, &dc->base, &tegra_crtc_funcs); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1310 | drm_mode_crtc_set_gamma_size(&dc->base, 256); |
| 1311 | drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs); |
| 1312 | |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1313 | /* |
| 1314 | * Keep track of the minimum pitch alignment across all display |
| 1315 | * controllers. |
| 1316 | */ |
| 1317 | if (dc->soc->pitch_align > tegra->pitch_align) |
| 1318 | tegra->pitch_align = dc->soc->pitch_align; |
| 1319 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1320 | err = tegra_dc_rgb_init(drm, dc); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1321 | if (err < 0 && err != -ENODEV) { |
| 1322 | dev_err(dc->dev, "failed to initialize RGB output: %d\n", err); |
| 1323 | return err; |
| 1324 | } |
| 1325 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1326 | err = tegra_dc_add_planes(drm, dc); |
Thierry Reding | f34bc78 | 2012-11-04 21:47:13 +0100 | [diff] [blame] | 1327 | if (err < 0) |
| 1328 | return err; |
| 1329 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1330 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1331 | err = tegra_dc_debugfs_init(dc, drm->primary); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1332 | if (err < 0) |
| 1333 | dev_err(dc->dev, "debugfs setup failed: %d\n", err); |
| 1334 | } |
| 1335 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1336 | err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1337 | dev_name(dc->dev), dc); |
| 1338 | if (err < 0) { |
| 1339 | dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq, |
| 1340 | err); |
| 1341 | return err; |
| 1342 | } |
| 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1347 | static int tegra_dc_exit(struct host1x_client *client) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1348 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1349 | struct tegra_dc *dc = host1x_client_to_dc(client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1350 | int err; |
| 1351 | |
| 1352 | devm_free_irq(dc->dev, dc->irq, dc); |
| 1353 | |
| 1354 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
| 1355 | err = tegra_dc_debugfs_exit(dc); |
| 1356 | if (err < 0) |
| 1357 | dev_err(dc->dev, "debugfs cleanup failed: %d\n", err); |
| 1358 | } |
| 1359 | |
| 1360 | err = tegra_dc_rgb_exit(dc); |
| 1361 | if (err) { |
| 1362 | dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err); |
| 1363 | return err; |
| 1364 | } |
| 1365 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 1366 | if (dc->domain) { |
| 1367 | iommu_detach_device(dc->domain, dc->dev); |
| 1368 | dc->domain = NULL; |
| 1369 | } |
| 1370 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | static const struct host1x_client_ops dc_client_ops = { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1375 | .init = tegra_dc_init, |
| 1376 | .exit = tegra_dc_exit, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1377 | }; |
| 1378 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1379 | static const struct tegra_dc_soc_info tegra20_dc_soc_info = { |
| 1380 | .supports_interlacing = false, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1381 | .supports_cursor = false, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1382 | .supports_block_linear = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1383 | .pitch_align = 8, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1384 | .has_powergate = false, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1385 | }; |
| 1386 | |
| 1387 | static const struct tegra_dc_soc_info tegra30_dc_soc_info = { |
| 1388 | .supports_interlacing = false, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1389 | .supports_cursor = false, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1390 | .supports_block_linear = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1391 | .pitch_align = 8, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1392 | .has_powergate = false, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1393 | }; |
| 1394 | |
| 1395 | static const struct tegra_dc_soc_info tegra114_dc_soc_info = { |
| 1396 | .supports_interlacing = false, |
| 1397 | .supports_cursor = false, |
| 1398 | .supports_block_linear = false, |
| 1399 | .pitch_align = 64, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1400 | .has_powergate = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1401 | }; |
| 1402 | |
| 1403 | static const struct tegra_dc_soc_info tegra124_dc_soc_info = { |
| 1404 | .supports_interlacing = true, |
Thierry Reding | e687651 | 2013-12-20 13:58:33 +0100 | [diff] [blame] | 1405 | .supports_cursor = true, |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 1406 | .supports_block_linear = true, |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 1407 | .pitch_align = 64, |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1408 | .has_powergate = true, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1409 | }; |
| 1410 | |
| 1411 | static const struct of_device_id tegra_dc_of_match[] = { |
| 1412 | { |
| 1413 | .compatible = "nvidia,tegra124-dc", |
| 1414 | .data = &tegra124_dc_soc_info, |
| 1415 | }, { |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1416 | .compatible = "nvidia,tegra114-dc", |
| 1417 | .data = &tegra114_dc_soc_info, |
| 1418 | }, { |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1419 | .compatible = "nvidia,tegra30-dc", |
| 1420 | .data = &tegra30_dc_soc_info, |
| 1421 | }, { |
| 1422 | .compatible = "nvidia,tegra20-dc", |
| 1423 | .data = &tegra20_dc_soc_info, |
| 1424 | }, { |
| 1425 | /* sentinel */ |
| 1426 | } |
| 1427 | }; |
Stephen Warren | ef70728 | 2014-06-18 16:21:55 -0600 | [diff] [blame] | 1428 | MODULE_DEVICE_TABLE(of, tegra_dc_of_match); |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1429 | |
Thierry Reding | 13411dd | 2014-01-09 17:08:36 +0100 | [diff] [blame] | 1430 | static int tegra_dc_parse_dt(struct tegra_dc *dc) |
| 1431 | { |
| 1432 | struct device_node *np; |
| 1433 | u32 value = 0; |
| 1434 | int err; |
| 1435 | |
| 1436 | err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value); |
| 1437 | if (err < 0) { |
| 1438 | dev_err(dc->dev, "missing \"nvidia,head\" property\n"); |
| 1439 | |
| 1440 | /* |
| 1441 | * If the nvidia,head property isn't present, try to find the |
| 1442 | * correct head number by looking up the position of this |
| 1443 | * display controller's node within the device tree. Assuming |
| 1444 | * that the nodes are ordered properly in the DTS file and |
| 1445 | * that the translation into a flattened device tree blob |
| 1446 | * preserves that ordering this will actually yield the right |
| 1447 | * head number. |
| 1448 | * |
| 1449 | * If those assumptions don't hold, this will still work for |
| 1450 | * cases where only a single display controller is used. |
| 1451 | */ |
| 1452 | for_each_matching_node(np, tegra_dc_of_match) { |
| 1453 | if (np == dc->dev->of_node) |
| 1454 | break; |
| 1455 | |
| 1456 | value++; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | dc->pipe = value; |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1465 | static int tegra_dc_probe(struct platform_device *pdev) |
| 1466 | { |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1467 | const struct of_device_id *id; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1468 | struct resource *regs; |
| 1469 | struct tegra_dc *dc; |
| 1470 | int err; |
| 1471 | |
| 1472 | dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL); |
| 1473 | if (!dc) |
| 1474 | return -ENOMEM; |
| 1475 | |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1476 | id = of_match_node(tegra_dc_of_match, pdev->dev.of_node); |
| 1477 | if (!id) |
| 1478 | return -ENODEV; |
| 1479 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1480 | spin_lock_init(&dc->lock); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1481 | INIT_LIST_HEAD(&dc->list); |
| 1482 | dc->dev = &pdev->dev; |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1483 | dc->soc = id->data; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1484 | |
Thierry Reding | 13411dd | 2014-01-09 17:08:36 +0100 | [diff] [blame] | 1485 | err = tegra_dc_parse_dt(dc); |
| 1486 | if (err < 0) |
| 1487 | return err; |
| 1488 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1489 | dc->clk = devm_clk_get(&pdev->dev, NULL); |
| 1490 | if (IS_ERR(dc->clk)) { |
| 1491 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 1492 | return PTR_ERR(dc->clk); |
| 1493 | } |
| 1494 | |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 1495 | dc->rst = devm_reset_control_get(&pdev->dev, "dc"); |
| 1496 | if (IS_ERR(dc->rst)) { |
| 1497 | dev_err(&pdev->dev, "failed to get reset\n"); |
| 1498 | return PTR_ERR(dc->rst); |
| 1499 | } |
| 1500 | |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1501 | if (dc->soc->has_powergate) { |
| 1502 | if (dc->pipe == 0) |
| 1503 | dc->powergate = TEGRA_POWERGATE_DIS; |
| 1504 | else |
| 1505 | dc->powergate = TEGRA_POWERGATE_DISB; |
| 1506 | |
| 1507 | err = tegra_powergate_sequence_power_up(dc->powergate, dc->clk, |
| 1508 | dc->rst); |
| 1509 | if (err < 0) { |
| 1510 | dev_err(&pdev->dev, "failed to power partition: %d\n", |
| 1511 | err); |
| 1512 | return err; |
| 1513 | } |
| 1514 | } else { |
| 1515 | err = clk_prepare_enable(dc->clk); |
| 1516 | if (err < 0) { |
| 1517 | dev_err(&pdev->dev, "failed to enable clock: %d\n", |
| 1518 | err); |
| 1519 | return err; |
| 1520 | } |
| 1521 | |
| 1522 | err = reset_control_deassert(dc->rst); |
| 1523 | if (err < 0) { |
| 1524 | dev_err(&pdev->dev, "failed to deassert reset: %d\n", |
| 1525 | err); |
| 1526 | return err; |
| 1527 | } |
| 1528 | } |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1529 | |
| 1530 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | d4ed602 | 2013-01-21 11:09:02 +0100 | [diff] [blame] | 1531 | dc->regs = devm_ioremap_resource(&pdev->dev, regs); |
| 1532 | if (IS_ERR(dc->regs)) |
| 1533 | return PTR_ERR(dc->regs); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1534 | |
| 1535 | dc->irq = platform_get_irq(pdev, 0); |
| 1536 | if (dc->irq < 0) { |
| 1537 | dev_err(&pdev->dev, "failed to get IRQ\n"); |
| 1538 | return -ENXIO; |
| 1539 | } |
| 1540 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1541 | INIT_LIST_HEAD(&dc->client.list); |
| 1542 | dc->client.ops = &dc_client_ops; |
| 1543 | dc->client.dev = &pdev->dev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1544 | |
| 1545 | err = tegra_dc_rgb_probe(dc); |
| 1546 | if (err < 0 && err != -ENODEV) { |
| 1547 | dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err); |
| 1548 | return err; |
| 1549 | } |
| 1550 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1551 | err = host1x_client_register(&dc->client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1552 | if (err < 0) { |
| 1553 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 1554 | err); |
| 1555 | return err; |
| 1556 | } |
| 1557 | |
| 1558 | platform_set_drvdata(pdev, dc); |
| 1559 | |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | static int tegra_dc_remove(struct platform_device *pdev) |
| 1564 | { |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1565 | struct tegra_dc *dc = platform_get_drvdata(pdev); |
| 1566 | int err; |
| 1567 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1568 | err = host1x_client_unregister(&dc->client); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1569 | if (err < 0) { |
| 1570 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 1571 | err); |
| 1572 | return err; |
| 1573 | } |
| 1574 | |
Thierry Reding | 59d29c0 | 2013-10-14 14:26:42 +0200 | [diff] [blame] | 1575 | err = tegra_dc_rgb_remove(dc); |
| 1576 | if (err < 0) { |
| 1577 | dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err); |
| 1578 | return err; |
| 1579 | } |
| 1580 | |
Thierry Reding | 5482d75 | 2014-07-11 08:39:03 +0200 | [diff] [blame] | 1581 | reset_control_assert(dc->rst); |
Thierry Reding | 9c01270 | 2014-07-07 15:32:53 +0200 | [diff] [blame] | 1582 | |
| 1583 | if (dc->soc->has_powergate) |
| 1584 | tegra_powergate_power_off(dc->powergate); |
| 1585 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1586 | clk_disable_unprepare(dc->clk); |
| 1587 | |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1591 | struct platform_driver tegra_dc_driver = { |
| 1592 | .driver = { |
| 1593 | .name = "tegra-dc", |
| 1594 | .owner = THIS_MODULE, |
| 1595 | .of_match_table = tegra_dc_of_match, |
| 1596 | }, |
| 1597 | .probe = tegra_dc_probe, |
| 1598 | .remove = tegra_dc_remove, |
| 1599 | }; |