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