blob: 2f9af13905da00089ea32022e31ffc4685dad724 [file] [log] [blame]
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001/*
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 Reding9eb9b222013-09-24 16:32:47 +020011#include <linux/debugfs.h>
Thierry Redingdf06b752014-06-26 21:41:53 +020012#include <linux/iommu.h>
Stephen Warrenca480802013-11-06 16:20:54 -070013#include <linux/reset.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000014
Thierry Reding9c012702014-07-07 15:32:53 +020015#include <soc/tegra/pmc.h>
16
Arto Merilainende2ba662013-03-22 16:34:08 +020017#include "dc.h"
18#include "drm.h"
19#include "gem.h"
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000020
Thierry Reding9d441892014-11-24 17:02:53 +010021#include <drm/drm_atomic.h>
Thierry Reding4aa3df72014-11-24 16:27:13 +010022#include <drm/drm_atomic_helper.h>
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010023#include <drm/drm_plane_helper.h>
24
Thierry Reding8620fc62013-12-12 11:03:59 +010025struct tegra_dc_soc_info {
Thierry Reding42d06592014-12-08 15:45:39 +010026 bool supports_border_color;
Thierry Reding8620fc62013-12-12 11:03:59 +010027 bool supports_interlacing;
Thierry Redinge6876512013-12-20 13:58:33 +010028 bool supports_cursor;
Thierry Redingc134f012014-06-03 14:48:12 +020029 bool supports_block_linear;
Thierry Redingd1f3e1e2014-07-11 08:29:14 +020030 unsigned int pitch_align;
Thierry Reding9c012702014-07-07 15:32:53 +020031 bool has_powergate;
Thierry Reding8620fc62013-12-12 11:03:59 +010032};
33
Thierry Redingf34bc782012-11-04 21:47:13 +010034struct tegra_plane {
35 struct drm_plane base;
36 unsigned int index;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000037};
38
Thierry Redingf34bc782012-11-04 21:47:13 +010039static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane)
40{
41 return container_of(plane, struct tegra_plane, base);
42}
43
Thierry Redingca915b12014-12-08 16:14:45 +010044struct tegra_dc_state {
45 struct drm_crtc_state base;
46
47 struct clk *clk;
48 unsigned long pclk;
49 unsigned int div;
50};
51
52static inline struct tegra_dc_state *to_dc_state(struct drm_crtc_state *state)
53{
54 if (state)
55 return container_of(state, struct tegra_dc_state, base);
56
57 return NULL;
58}
59
Thierry Reding205d48e2014-10-21 13:41:46 +020060static void tegra_dc_window_commit(struct tegra_dc *dc, unsigned int index)
61{
62 u32 value = WIN_A_ACT_REQ << index;
63
64 tegra_dc_writel(dc, value << 8, DC_CMD_STATE_CONTROL);
65 tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
66}
67
68static void tegra_dc_cursor_commit(struct tegra_dc *dc)
69{
70 tegra_dc_writel(dc, CURSOR_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
71 tegra_dc_writel(dc, CURSOR_ACT_REQ, DC_CMD_STATE_CONTROL);
72}
73
Thierry Redingd700ba72014-12-08 15:50:04 +010074/*
Thierry Reding86df2562014-12-08 16:03:53 +010075 * Reads the active copy of a register. This takes the dc->lock spinlock to
76 * prevent races with the VBLANK processing which also needs access to the
77 * active copy of some registers.
78 */
79static u32 tegra_dc_readl_active(struct tegra_dc *dc, unsigned long offset)
80{
81 unsigned long flags;
82 u32 value;
83
84 spin_lock_irqsave(&dc->lock, flags);
85
86 tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
87 value = tegra_dc_readl(dc, offset);
88 tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
89
90 spin_unlock_irqrestore(&dc->lock, flags);
91 return value;
92}
93
94/*
Thierry Redingd700ba72014-12-08 15:50:04 +010095 * Double-buffered registers have two copies: ASSEMBLY and ACTIVE. When the
96 * *_ACT_REQ bits are set the ASSEMBLY copy is latched into the ACTIVE copy.
97 * Latching happens mmediately if the display controller is in STOP mode or
98 * on the next frame boundary otherwise.
99 *
100 * Triple-buffered registers have three copies: ASSEMBLY, ARM and ACTIVE. The
101 * ASSEMBLY copy is latched into the ARM copy immediately after *_UPDATE bits
102 * are written. When the *_ACT_REQ bits are written, the ARM copy is latched
103 * into the ACTIVE copy, either immediately if the display controller is in
104 * STOP mode, or at the next frame boundary otherwise.
105 */
Thierry Reding62b9e062014-11-21 17:33:33 +0100106void tegra_dc_commit(struct tegra_dc *dc)
Thierry Reding205d48e2014-10-21 13:41:46 +0200107{
108 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
109 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
110}
111
Thierry Reding10288ee2014-03-14 09:54:58 +0100112static unsigned int tegra_dc_format(uint32_t format, uint32_t *swap)
113{
114 /* assume no swapping of fetched data */
115 if (swap)
116 *swap = BYTE_SWAP_NOSWAP;
117
118 switch (format) {
119 case DRM_FORMAT_XBGR8888:
120 return WIN_COLOR_DEPTH_R8G8B8A8;
121
122 case DRM_FORMAT_XRGB8888:
123 return WIN_COLOR_DEPTH_B8G8R8A8;
124
125 case DRM_FORMAT_RGB565:
126 return WIN_COLOR_DEPTH_B5G6R5;
127
128 case DRM_FORMAT_UYVY:
129 return WIN_COLOR_DEPTH_YCbCr422;
130
131 case DRM_FORMAT_YUYV:
132 if (swap)
133 *swap = BYTE_SWAP_SWAP2;
134
135 return WIN_COLOR_DEPTH_YCbCr422;
136
137 case DRM_FORMAT_YUV420:
138 return WIN_COLOR_DEPTH_YCbCr420P;
139
140 case DRM_FORMAT_YUV422:
141 return WIN_COLOR_DEPTH_YCbCr422P;
142
143 default:
144 break;
145 }
146
147 WARN(1, "unsupported pixel format %u, using default\n", format);
148 return WIN_COLOR_DEPTH_B8G8R8A8;
149}
150
151static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar)
152{
153 switch (format) {
154 case WIN_COLOR_DEPTH_YCbCr422:
155 case WIN_COLOR_DEPTH_YUV422:
156 if (planar)
157 *planar = false;
158
159 return true;
160
161 case WIN_COLOR_DEPTH_YCbCr420P:
162 case WIN_COLOR_DEPTH_YUV420P:
163 case WIN_COLOR_DEPTH_YCbCr422P:
164 case WIN_COLOR_DEPTH_YUV422P:
165 case WIN_COLOR_DEPTH_YCbCr422R:
166 case WIN_COLOR_DEPTH_YUV422R:
167 case WIN_COLOR_DEPTH_YCbCr422RA:
168 case WIN_COLOR_DEPTH_YUV422RA:
169 if (planar)
170 *planar = true;
171
172 return true;
173 }
174
Thierry Redingfb35c6b2014-12-08 15:55:28 +0100175 if (planar)
176 *planar = false;
177
Thierry Reding10288ee2014-03-14 09:54:58 +0100178 return false;
179}
180
181static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v,
182 unsigned int bpp)
183{
184 fixed20_12 outf = dfixed_init(out);
185 fixed20_12 inf = dfixed_init(in);
186 u32 dda_inc;
187 int max;
188
189 if (v)
190 max = 15;
191 else {
192 switch (bpp) {
193 case 2:
194 max = 8;
195 break;
196
197 default:
198 WARN_ON_ONCE(1);
199 /* fallthrough */
200 case 4:
201 max = 4;
202 break;
203 }
204 }
205
206 outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1));
207 inf.full -= dfixed_const(1);
208
209 dda_inc = dfixed_div(inf, outf);
210 dda_inc = min_t(u32, dda_inc, dfixed_const(max));
211
212 return dda_inc;
213}
214
215static inline u32 compute_initial_dda(unsigned int in)
216{
217 fixed20_12 inf = dfixed_init(in);
218 return dfixed_frac(inf);
219}
220
Thierry Reding4aa3df72014-11-24 16:27:13 +0100221static void tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
222 const struct tegra_dc_window *window)
Thierry Reding10288ee2014-03-14 09:54:58 +0100223{
224 unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp;
Sean Paul93396d02014-11-19 13:04:49 -0500225 unsigned long value, flags;
Thierry Reding10288ee2014-03-14 09:54:58 +0100226 bool yuv, planar;
227
228 /*
229 * For YUV planar modes, the number of bytes per pixel takes into
230 * account only the luma component and therefore is 1.
231 */
232 yuv = tegra_dc_format_is_yuv(window->format, &planar);
233 if (!yuv)
234 bpp = window->bits_per_pixel / 8;
235 else
236 bpp = planar ? 1 : 2;
237
Sean Paul93396d02014-11-19 13:04:49 -0500238 spin_lock_irqsave(&dc->lock, flags);
239
Thierry Reding10288ee2014-03-14 09:54:58 +0100240 value = WINDOW_A_SELECT << index;
241 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
242
243 tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH);
244 tegra_dc_writel(dc, window->swap, DC_WIN_BYTE_SWAP);
245
246 value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x);
247 tegra_dc_writel(dc, value, DC_WIN_POSITION);
248
249 value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w);
250 tegra_dc_writel(dc, value, DC_WIN_SIZE);
251
252 h_offset = window->src.x * bpp;
253 v_offset = window->src.y;
254 h_size = window->src.w * bpp;
255 v_size = window->src.h;
256
257 value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size);
258 tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE);
259
260 /*
261 * For DDA computations the number of bytes per pixel for YUV planar
262 * modes needs to take into account all Y, U and V components.
263 */
264 if (yuv && planar)
265 bpp = 2;
266
267 h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp);
268 v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp);
269
270 value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda);
271 tegra_dc_writel(dc, value, DC_WIN_DDA_INC);
272
273 h_dda = compute_initial_dda(window->src.x);
274 v_dda = compute_initial_dda(window->src.y);
275
276 tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA);
277 tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA);
278
279 tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE);
280 tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE);
281
282 tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR);
283
284 if (yuv && planar) {
285 tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U);
286 tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V);
287 value = window->stride[1] << 16 | window->stride[0];
288 tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE);
289 } else {
290 tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE);
291 }
292
293 if (window->bottom_up)
294 v_offset += window->src.h - 1;
295
296 tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET);
297 tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET);
298
Thierry Redingc134f012014-06-03 14:48:12 +0200299 if (dc->soc->supports_block_linear) {
300 unsigned long height = window->tiling.value;
Thierry Reding10288ee2014-03-14 09:54:58 +0100301
Thierry Redingc134f012014-06-03 14:48:12 +0200302 switch (window->tiling.mode) {
303 case TEGRA_BO_TILING_MODE_PITCH:
304 value = DC_WINBUF_SURFACE_KIND_PITCH;
305 break;
306
307 case TEGRA_BO_TILING_MODE_TILED:
308 value = DC_WINBUF_SURFACE_KIND_TILED;
309 break;
310
311 case TEGRA_BO_TILING_MODE_BLOCK:
312 value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) |
313 DC_WINBUF_SURFACE_KIND_BLOCK;
314 break;
315 }
316
317 tegra_dc_writel(dc, value, DC_WINBUF_SURFACE_KIND);
318 } else {
319 switch (window->tiling.mode) {
320 case TEGRA_BO_TILING_MODE_PITCH:
321 value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV |
322 DC_WIN_BUFFER_ADDR_MODE_LINEAR;
323 break;
324
325 case TEGRA_BO_TILING_MODE_TILED:
326 value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV |
327 DC_WIN_BUFFER_ADDR_MODE_TILE;
328 break;
329
330 case TEGRA_BO_TILING_MODE_BLOCK:
Thierry Reding4aa3df72014-11-24 16:27:13 +0100331 /*
332 * No need to handle this here because ->atomic_check
333 * will already have filtered it out.
334 */
335 break;
Thierry Redingc134f012014-06-03 14:48:12 +0200336 }
337
338 tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE);
339 }
Thierry Reding10288ee2014-03-14 09:54:58 +0100340
341 value = WIN_ENABLE;
342
343 if (yuv) {
344 /* setup default colorspace conversion coefficients */
345 tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF);
346 tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB);
347 tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR);
348 tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR);
349 tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG);
350 tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG);
351 tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB);
352 tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB);
353
354 value |= CSC_ENABLE;
355 } else if (window->bits_per_pixel < 24) {
356 value |= COLOR_EXPAND;
357 }
358
359 if (window->bottom_up)
360 value |= V_DIRECTION;
361
362 tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
363
364 /*
365 * Disable blending and assume Window A is the bottom-most window,
366 * Window C is the top-most window and Window B is in the middle.
367 */
368 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY);
369 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN);
370
371 switch (index) {
372 case 0:
373 tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X);
374 tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
375 tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
376 break;
377
378 case 1:
379 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
380 tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
381 tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
382 break;
383
384 case 2:
385 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
386 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y);
387 tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY);
388 break;
389 }
390
Thierry Reding205d48e2014-10-21 13:41:46 +0200391 tegra_dc_window_commit(dc, index);
Thierry Reding10288ee2014-03-14 09:54:58 +0100392
Sean Paul93396d02014-11-19 13:04:49 -0500393 spin_unlock_irqrestore(&dc->lock, flags);
Thierry Redingc7679302014-10-21 13:51:53 +0200394}
395
396static void tegra_plane_destroy(struct drm_plane *plane)
397{
398 struct tegra_plane *p = to_tegra_plane(plane);
399
400 drm_plane_cleanup(plane);
401 kfree(p);
402}
403
404static const u32 tegra_primary_plane_formats[] = {
405 DRM_FORMAT_XBGR8888,
406 DRM_FORMAT_XRGB8888,
407 DRM_FORMAT_RGB565,
408};
409
Thierry Reding4aa3df72014-11-24 16:27:13 +0100410static void tegra_primary_plane_destroy(struct drm_plane *plane)
Thierry Redingc7679302014-10-21 13:51:53 +0200411{
Thierry Reding4aa3df72014-11-24 16:27:13 +0100412 tegra_plane_destroy(plane);
413}
414
415static const struct drm_plane_funcs tegra_primary_plane_funcs = {
Thierry Reding07866962014-11-24 17:08:06 +0100416 .update_plane = drm_atomic_helper_update_plane,
417 .disable_plane = drm_atomic_helper_disable_plane,
Thierry Reding4aa3df72014-11-24 16:27:13 +0100418 .destroy = tegra_primary_plane_destroy,
Thierry Reding9d441892014-11-24 17:02:53 +0100419 .reset = drm_atomic_helper_plane_reset,
420 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
Thierry Reding4aa3df72014-11-24 16:27:13 +0100421 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
422};
423
424static int tegra_plane_prepare_fb(struct drm_plane *plane,
425 struct drm_framebuffer *fb)
426{
427 return 0;
428}
429
430static void tegra_plane_cleanup_fb(struct drm_plane *plane,
431 struct drm_framebuffer *fb)
432{
433}
434
435static int tegra_plane_atomic_check(struct drm_plane *plane,
436 struct drm_plane_state *state)
437{
438 struct tegra_dc *dc = to_tegra_dc(state->crtc);
439 struct tegra_bo_tiling tiling;
Thierry Redingc7679302014-10-21 13:51:53 +0200440 int err;
441
Thierry Reding4aa3df72014-11-24 16:27:13 +0100442 /* no need for further checks if the plane is being disabled */
443 if (!state->crtc)
444 return 0;
445
446 err = tegra_fb_get_tiling(state->fb, &tiling);
447 if (err < 0)
448 return err;
449
450 if (tiling.mode == TEGRA_BO_TILING_MODE_BLOCK &&
451 !dc->soc->supports_block_linear) {
452 DRM_ERROR("hardware doesn't support block linear mode\n");
453 return -EINVAL;
454 }
455
456 /*
457 * Tegra doesn't support different strides for U and V planes so we
458 * error out if the user tries to display a framebuffer with such a
459 * configuration.
460 */
461 if (drm_format_num_planes(state->fb->pixel_format) > 2) {
462 if (state->fb->pitches[2] != state->fb->pitches[1]) {
463 DRM_ERROR("unsupported UV-plane configuration\n");
464 return -EINVAL;
465 }
466 }
467
468 return 0;
469}
470
471static void tegra_plane_atomic_update(struct drm_plane *plane,
472 struct drm_plane_state *old_state)
473{
474 struct tegra_dc *dc = to_tegra_dc(plane->state->crtc);
475 struct drm_framebuffer *fb = plane->state->fb;
476 struct tegra_plane *p = to_tegra_plane(plane);
477 struct tegra_dc_window window;
478 unsigned int i;
479 int err;
480
481 /* rien ne va plus */
482 if (!plane->state->crtc || !plane->state->fb)
483 return;
484
Thierry Redingc7679302014-10-21 13:51:53 +0200485 memset(&window, 0, sizeof(window));
Thierry Reding4aa3df72014-11-24 16:27:13 +0100486 window.src.x = plane->state->src_x >> 16;
487 window.src.y = plane->state->src_y >> 16;
488 window.src.w = plane->state->src_w >> 16;
489 window.src.h = plane->state->src_h >> 16;
490 window.dst.x = plane->state->crtc_x;
491 window.dst.y = plane->state->crtc_y;
492 window.dst.w = plane->state->crtc_w;
493 window.dst.h = plane->state->crtc_h;
Thierry Redingc7679302014-10-21 13:51:53 +0200494 window.format = tegra_dc_format(fb->pixel_format, &window.swap);
495 window.bits_per_pixel = fb->bits_per_pixel;
496 window.bottom_up = tegra_fb_is_bottom_up(fb);
497
498 err = tegra_fb_get_tiling(fb, &window.tiling);
Thierry Reding4aa3df72014-11-24 16:27:13 +0100499 WARN_ON(err < 0);
Thierry Redingc7679302014-10-21 13:51:53 +0200500
Thierry Reding4aa3df72014-11-24 16:27:13 +0100501 for (i = 0; i < drm_format_num_planes(fb->pixel_format); i++) {
502 struct tegra_bo *bo = tegra_fb_get_plane(fb, i);
Thierry Redingc7679302014-10-21 13:51:53 +0200503
Thierry Reding4aa3df72014-11-24 16:27:13 +0100504 window.base[i] = bo->paddr + fb->offsets[i];
505 window.stride[i] = fb->pitches[i];
506 }
Thierry Redingc7679302014-10-21 13:51:53 +0200507
Thierry Reding4aa3df72014-11-24 16:27:13 +0100508 tegra_dc_setup_window(dc, p->index, &window);
Thierry Redingc7679302014-10-21 13:51:53 +0200509}
510
Thierry Reding4aa3df72014-11-24 16:27:13 +0100511static void tegra_plane_atomic_disable(struct drm_plane *plane,
512 struct drm_plane_state *old_state)
Thierry Redingc7679302014-10-21 13:51:53 +0200513{
Thierry Reding4aa3df72014-11-24 16:27:13 +0100514 struct tegra_plane *p = to_tegra_plane(plane);
515 struct tegra_dc *dc;
516 unsigned long flags;
517 u32 value;
518
519 /* rien ne va plus */
520 if (!old_state || !old_state->crtc)
521 return;
522
523 dc = to_tegra_dc(old_state->crtc);
524
525 spin_lock_irqsave(&dc->lock, flags);
526
527 value = WINDOW_A_SELECT << p->index;
528 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
529
530 value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS);
531 value &= ~WIN_ENABLE;
532 tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
533
534 tegra_dc_window_commit(dc, p->index);
535
536 spin_unlock_irqrestore(&dc->lock, flags);
Thierry Redingc7679302014-10-21 13:51:53 +0200537}
538
Thierry Reding4aa3df72014-11-24 16:27:13 +0100539static const struct drm_plane_helper_funcs tegra_primary_plane_helper_funcs = {
540 .prepare_fb = tegra_plane_prepare_fb,
541 .cleanup_fb = tegra_plane_cleanup_fb,
542 .atomic_check = tegra_plane_atomic_check,
543 .atomic_update = tegra_plane_atomic_update,
544 .atomic_disable = tegra_plane_atomic_disable,
Thierry Redingc7679302014-10-21 13:51:53 +0200545};
546
547static struct drm_plane *tegra_dc_primary_plane_create(struct drm_device *drm,
548 struct tegra_dc *dc)
549{
Thierry Reding518e6222014-12-16 18:04:08 +0100550 /*
551 * Ideally this would use drm_crtc_mask(), but that would require the
552 * CRTC to already be in the mode_config's list of CRTCs. However, it
553 * will only be added to that list in the drm_crtc_init_with_planes()
554 * (in tegra_dc_init()), which in turn requires registration of these
555 * planes. So we have ourselves a nice little chicken and egg problem
556 * here.
557 *
558 * We work around this by manually creating the mask from the number
559 * of CRTCs that have been registered, and should therefore always be
560 * the same as drm_crtc_index() after registration.
561 */
562 unsigned long possible_crtcs = 1 << drm->mode_config.num_crtc;
Thierry Redingc7679302014-10-21 13:51:53 +0200563 struct tegra_plane *plane;
564 unsigned int num_formats;
565 const u32 *formats;
566 int err;
567
568 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
569 if (!plane)
570 return ERR_PTR(-ENOMEM);
571
572 num_formats = ARRAY_SIZE(tegra_primary_plane_formats);
573 formats = tegra_primary_plane_formats;
574
Thierry Reding518e6222014-12-16 18:04:08 +0100575 err = drm_universal_plane_init(drm, &plane->base, possible_crtcs,
Thierry Redingc7679302014-10-21 13:51:53 +0200576 &tegra_primary_plane_funcs, formats,
577 num_formats, DRM_PLANE_TYPE_PRIMARY);
578 if (err < 0) {
579 kfree(plane);
580 return ERR_PTR(err);
581 }
582
Thierry Reding4aa3df72014-11-24 16:27:13 +0100583 drm_plane_helper_add(&plane->base, &tegra_primary_plane_helper_funcs);
584
Thierry Redingc7679302014-10-21 13:51:53 +0200585 return &plane->base;
586}
587
588static const u32 tegra_cursor_plane_formats[] = {
589 DRM_FORMAT_RGBA8888,
590};
591
Thierry Reding4aa3df72014-11-24 16:27:13 +0100592static int tegra_cursor_atomic_check(struct drm_plane *plane,
593 struct drm_plane_state *state)
Thierry Redingc7679302014-10-21 13:51:53 +0200594{
Thierry Reding4aa3df72014-11-24 16:27:13 +0100595 /* no need for further checks if the plane is being disabled */
596 if (!state->crtc)
597 return 0;
Thierry Redingc7679302014-10-21 13:51:53 +0200598
599 /* scaling not supported for cursor */
Thierry Reding4aa3df72014-11-24 16:27:13 +0100600 if ((state->src_w >> 16 != state->crtc_w) ||
601 (state->src_h >> 16 != state->crtc_h))
Thierry Redingc7679302014-10-21 13:51:53 +0200602 return -EINVAL;
603
604 /* only square cursors supported */
Thierry Reding4aa3df72014-11-24 16:27:13 +0100605 if (state->src_w != state->src_h)
Thierry Redingc7679302014-10-21 13:51:53 +0200606 return -EINVAL;
607
Thierry Reding4aa3df72014-11-24 16:27:13 +0100608 if (state->crtc_w != 32 && state->crtc_w != 64 &&
609 state->crtc_w != 128 && state->crtc_w != 256)
610 return -EINVAL;
611
612 return 0;
613}
614
615static void tegra_cursor_atomic_update(struct drm_plane *plane,
616 struct drm_plane_state *old_state)
617{
618 struct tegra_bo *bo = tegra_fb_get_plane(plane->state->fb, 0);
619 struct tegra_dc *dc = to_tegra_dc(plane->state->crtc);
620 struct drm_plane_state *state = plane->state;
621 u32 value = CURSOR_CLIP_DISPLAY;
622
623 /* rien ne va plus */
624 if (!plane->state->crtc || !plane->state->fb)
625 return;
626
627 switch (state->crtc_w) {
Thierry Redingc7679302014-10-21 13:51:53 +0200628 case 32:
629 value |= CURSOR_SIZE_32x32;
630 break;
631
632 case 64:
633 value |= CURSOR_SIZE_64x64;
634 break;
635
636 case 128:
637 value |= CURSOR_SIZE_128x128;
638 break;
639
640 case 256:
641 value |= CURSOR_SIZE_256x256;
642 break;
643
644 default:
Thierry Reding4aa3df72014-11-24 16:27:13 +0100645 WARN(1, "cursor size %ux%u not supported\n", state->crtc_w,
646 state->crtc_h);
647 return;
Thierry Redingc7679302014-10-21 13:51:53 +0200648 }
649
650 value |= (bo->paddr >> 10) & 0x3fffff;
651 tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR);
652
653#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
654 value = (bo->paddr >> 32) & 0x3;
655 tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR_HI);
656#endif
657
658 /* enable cursor and set blend mode */
659 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
660 value |= CURSOR_ENABLE;
661 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
662
663 value = tegra_dc_readl(dc, DC_DISP_BLEND_CURSOR_CONTROL);
664 value &= ~CURSOR_DST_BLEND_MASK;
665 value &= ~CURSOR_SRC_BLEND_MASK;
666 value |= CURSOR_MODE_NORMAL;
667 value |= CURSOR_DST_BLEND_NEG_K1_TIMES_SRC;
668 value |= CURSOR_SRC_BLEND_K1_TIMES_SRC;
669 value |= CURSOR_ALPHA;
670 tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL);
671
672 /* position the cursor */
Thierry Reding4aa3df72014-11-24 16:27:13 +0100673 value = (state->crtc_y & 0x3fff) << 16 | (state->crtc_x & 0x3fff);
Thierry Redingc7679302014-10-21 13:51:53 +0200674 tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION);
675
676 /* apply changes */
677 tegra_dc_cursor_commit(dc);
678 tegra_dc_commit(dc);
Thierry Redingc7679302014-10-21 13:51:53 +0200679}
680
Thierry Reding4aa3df72014-11-24 16:27:13 +0100681static void tegra_cursor_atomic_disable(struct drm_plane *plane,
682 struct drm_plane_state *old_state)
Thierry Redingc7679302014-10-21 13:51:53 +0200683{
Thierry Reding4aa3df72014-11-24 16:27:13 +0100684 struct tegra_dc *dc;
Thierry Redingc7679302014-10-21 13:51:53 +0200685 u32 value;
686
Thierry Reding4aa3df72014-11-24 16:27:13 +0100687 /* rien ne va plus */
688 if (!old_state || !old_state->crtc)
689 return;
690
691 dc = to_tegra_dc(old_state->crtc);
Thierry Redingc7679302014-10-21 13:51:53 +0200692
693 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
694 value &= ~CURSOR_ENABLE;
695 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
696
697 tegra_dc_cursor_commit(dc);
698 tegra_dc_commit(dc);
Thierry Redingc7679302014-10-21 13:51:53 +0200699}
700
701static const struct drm_plane_funcs tegra_cursor_plane_funcs = {
Thierry Reding07866962014-11-24 17:08:06 +0100702 .update_plane = drm_atomic_helper_update_plane,
703 .disable_plane = drm_atomic_helper_disable_plane,
Thierry Redingc7679302014-10-21 13:51:53 +0200704 .destroy = tegra_plane_destroy,
Thierry Reding9d441892014-11-24 17:02:53 +0100705 .reset = drm_atomic_helper_plane_reset,
706 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
Thierry Reding4aa3df72014-11-24 16:27:13 +0100707 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
708};
709
710static const struct drm_plane_helper_funcs tegra_cursor_plane_helper_funcs = {
711 .prepare_fb = tegra_plane_prepare_fb,
712 .cleanup_fb = tegra_plane_cleanup_fb,
713 .atomic_check = tegra_cursor_atomic_check,
714 .atomic_update = tegra_cursor_atomic_update,
715 .atomic_disable = tegra_cursor_atomic_disable,
Thierry Redingc7679302014-10-21 13:51:53 +0200716};
717
718static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm,
719 struct tegra_dc *dc)
720{
721 struct tegra_plane *plane;
722 unsigned int num_formats;
723 const u32 *formats;
724 int err;
725
726 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
727 if (!plane)
728 return ERR_PTR(-ENOMEM);
729
730 num_formats = ARRAY_SIZE(tegra_cursor_plane_formats);
731 formats = tegra_cursor_plane_formats;
732
733 err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe,
734 &tegra_cursor_plane_funcs, formats,
735 num_formats, DRM_PLANE_TYPE_CURSOR);
736 if (err < 0) {
737 kfree(plane);
738 return ERR_PTR(err);
739 }
740
Thierry Reding4aa3df72014-11-24 16:27:13 +0100741 drm_plane_helper_add(&plane->base, &tegra_cursor_plane_helper_funcs);
742
Thierry Redingc7679302014-10-21 13:51:53 +0200743 return &plane->base;
744}
745
Thierry Redingc7679302014-10-21 13:51:53 +0200746static void tegra_overlay_plane_destroy(struct drm_plane *plane)
Thierry Redingf34bc782012-11-04 21:47:13 +0100747{
Thierry Redingc7679302014-10-21 13:51:53 +0200748 tegra_plane_destroy(plane);
Thierry Redingf34bc782012-11-04 21:47:13 +0100749}
750
Thierry Redingc7679302014-10-21 13:51:53 +0200751static const struct drm_plane_funcs tegra_overlay_plane_funcs = {
Thierry Reding07866962014-11-24 17:08:06 +0100752 .update_plane = drm_atomic_helper_update_plane,
753 .disable_plane = drm_atomic_helper_disable_plane,
Thierry Redingc7679302014-10-21 13:51:53 +0200754 .destroy = tegra_overlay_plane_destroy,
Thierry Reding9d441892014-11-24 17:02:53 +0100755 .reset = drm_atomic_helper_plane_reset,
756 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
Thierry Reding4aa3df72014-11-24 16:27:13 +0100757 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
Thierry Redingf34bc782012-11-04 21:47:13 +0100758};
759
Thierry Redingc7679302014-10-21 13:51:53 +0200760static const uint32_t tegra_overlay_plane_formats[] = {
Thierry Redingdbe4d9a2013-03-22 15:37:30 +0100761 DRM_FORMAT_XBGR8888,
Thierry Redingf34bc782012-11-04 21:47:13 +0100762 DRM_FORMAT_XRGB8888,
Thierry Redingdbe4d9a2013-03-22 15:37:30 +0100763 DRM_FORMAT_RGB565,
Thierry Redingf34bc782012-11-04 21:47:13 +0100764 DRM_FORMAT_UYVY,
Thierry Redingf9253902014-01-29 20:31:17 +0100765 DRM_FORMAT_YUYV,
Thierry Redingf34bc782012-11-04 21:47:13 +0100766 DRM_FORMAT_YUV420,
767 DRM_FORMAT_YUV422,
768};
769
Thierry Reding4aa3df72014-11-24 16:27:13 +0100770static const struct drm_plane_helper_funcs tegra_overlay_plane_helper_funcs = {
771 .prepare_fb = tegra_plane_prepare_fb,
772 .cleanup_fb = tegra_plane_cleanup_fb,
773 .atomic_check = tegra_plane_atomic_check,
774 .atomic_update = tegra_plane_atomic_update,
775 .atomic_disable = tegra_plane_atomic_disable,
776};
777
Thierry Redingc7679302014-10-21 13:51:53 +0200778static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm,
779 struct tegra_dc *dc,
780 unsigned int index)
781{
782 struct tegra_plane *plane;
783 unsigned int num_formats;
784 const u32 *formats;
785 int err;
786
787 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
788 if (!plane)
789 return ERR_PTR(-ENOMEM);
790
791 plane->index = index;
792
793 num_formats = ARRAY_SIZE(tegra_overlay_plane_formats);
794 formats = tegra_overlay_plane_formats;
795
796 err = drm_universal_plane_init(drm, &plane->base, 1 << dc->pipe,
797 &tegra_overlay_plane_funcs, formats,
798 num_formats, DRM_PLANE_TYPE_OVERLAY);
799 if (err < 0) {
800 kfree(plane);
801 return ERR_PTR(err);
802 }
803
Thierry Reding4aa3df72014-11-24 16:27:13 +0100804 drm_plane_helper_add(&plane->base, &tegra_overlay_plane_helper_funcs);
805
Thierry Redingc7679302014-10-21 13:51:53 +0200806 return &plane->base;
807}
808
Thierry Redingf34bc782012-11-04 21:47:13 +0100809static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc)
810{
Thierry Redingc7679302014-10-21 13:51:53 +0200811 struct drm_plane *plane;
Thierry Redingf34bc782012-11-04 21:47:13 +0100812 unsigned int i;
Thierry Redingf34bc782012-11-04 21:47:13 +0100813
814 for (i = 0; i < 2; i++) {
Thierry Redingc7679302014-10-21 13:51:53 +0200815 plane = tegra_dc_overlay_plane_create(drm, dc, 1 + i);
816 if (IS_ERR(plane))
817 return PTR_ERR(plane);
Thierry Redingf34bc782012-11-04 21:47:13 +0100818 }
819
820 return 0;
821}
822
Thierry Reding6e5ff992012-11-28 11:45:47 +0100823void tegra_dc_enable_vblank(struct tegra_dc *dc)
824{
825 unsigned long value, flags;
826
827 spin_lock_irqsave(&dc->lock, flags);
828
829 value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
830 value |= VBLANK_INT;
831 tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
832
833 spin_unlock_irqrestore(&dc->lock, flags);
834}
835
836void tegra_dc_disable_vblank(struct tegra_dc *dc)
837{
838 unsigned long value, flags;
839
840 spin_lock_irqsave(&dc->lock, flags);
841
842 value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
843 value &= ~VBLANK_INT;
844 tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
845
846 spin_unlock_irqrestore(&dc->lock, flags);
847}
848
Thierry Reding3c03c462012-11-28 12:00:18 +0100849static void tegra_dc_finish_page_flip(struct tegra_dc *dc)
850{
851 struct drm_device *drm = dc->base.dev;
852 struct drm_crtc *crtc = &dc->base;
Thierry Reding3c03c462012-11-28 12:00:18 +0100853 unsigned long flags, base;
Arto Merilainende2ba662013-03-22 16:34:08 +0200854 struct tegra_bo *bo;
Thierry Reding3c03c462012-11-28 12:00:18 +0100855
Thierry Reding6b59cc12014-12-16 16:33:27 +0100856 spin_lock_irqsave(&drm->event_lock, flags);
857
858 if (!dc->event) {
859 spin_unlock_irqrestore(&drm->event_lock, flags);
Thierry Reding3c03c462012-11-28 12:00:18 +0100860 return;
Thierry Reding6b59cc12014-12-16 16:33:27 +0100861 }
Thierry Reding3c03c462012-11-28 12:00:18 +0100862
Matt Roperf4510a22014-04-01 15:22:40 -0700863 bo = tegra_fb_get_plane(crtc->primary->fb, 0);
Thierry Reding3c03c462012-11-28 12:00:18 +0100864
Dan Carpenter8643bc62015-01-07 14:01:26 +0300865 spin_lock(&dc->lock);
Sean Paul93396d02014-11-19 13:04:49 -0500866
Thierry Reding3c03c462012-11-28 12:00:18 +0100867 /* check if new start address has been latched */
Sean Paul93396d02014-11-19 13:04:49 -0500868 tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER);
Thierry Reding3c03c462012-11-28 12:00:18 +0100869 tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
870 base = tegra_dc_readl(dc, DC_WINBUF_START_ADDR);
871 tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
872
Dan Carpenter8643bc62015-01-07 14:01:26 +0300873 spin_unlock(&dc->lock);
Sean Paul93396d02014-11-19 13:04:49 -0500874
Matt Roperf4510a22014-04-01 15:22:40 -0700875 if (base == bo->paddr + crtc->primary->fb->offsets[0]) {
Thierry Redinged7dae52014-12-16 16:03:13 +0100876 drm_crtc_send_vblank_event(crtc, dc->event);
877 drm_crtc_vblank_put(crtc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100878 dc->event = NULL;
Thierry Reding3c03c462012-11-28 12:00:18 +0100879 }
Thierry Reding6b59cc12014-12-16 16:33:27 +0100880
881 spin_unlock_irqrestore(&drm->event_lock, flags);
Thierry Reding3c03c462012-11-28 12:00:18 +0100882}
883
884void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
885{
886 struct tegra_dc *dc = to_tegra_dc(crtc);
887 struct drm_device *drm = crtc->dev;
888 unsigned long flags;
889
890 spin_lock_irqsave(&drm->event_lock, flags);
891
892 if (dc->event && dc->event->base.file_priv == file) {
893 dc->event->base.destroy(&dc->event->base);
Thierry Redinged7dae52014-12-16 16:03:13 +0100894 drm_crtc_vblank_put(crtc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100895 dc->event = NULL;
896 }
897
898 spin_unlock_irqrestore(&drm->event_lock, flags);
899}
900
Thierry Redingf002abc2013-10-14 14:06:02 +0200901static void tegra_dc_destroy(struct drm_crtc *crtc)
902{
903 drm_crtc_cleanup(crtc);
Thierry Redingf002abc2013-10-14 14:06:02 +0200904}
905
Thierry Redingca915b12014-12-08 16:14:45 +0100906static void tegra_crtc_reset(struct drm_crtc *crtc)
907{
908 struct tegra_dc_state *state;
909
910 kfree(crtc->state);
911 crtc->state = NULL;
912
913 state = kzalloc(sizeof(*state), GFP_KERNEL);
914 if (state)
915 crtc->state = &state->base;
916}
917
918static struct drm_crtc_state *
919tegra_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
920{
921 struct tegra_dc_state *state = to_dc_state(crtc->state);
922 struct tegra_dc_state *copy;
923
924 copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
925 if (!copy)
926 return NULL;
927
928 copy->base.mode_changed = false;
929 copy->base.planes_changed = false;
930 copy->base.event = NULL;
931
932 return &copy->base;
933}
934
935static void tegra_crtc_atomic_destroy_state(struct drm_crtc *crtc,
936 struct drm_crtc_state *state)
937{
938 kfree(state);
939}
940
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000941static const struct drm_crtc_funcs tegra_crtc_funcs = {
Thierry Reding1503ca42014-11-24 17:41:23 +0100942 .page_flip = drm_atomic_helper_page_flip,
Thierry Reding74f48792014-11-24 17:08:20 +0100943 .set_config = drm_atomic_helper_set_config,
Thierry Redingf002abc2013-10-14 14:06:02 +0200944 .destroy = tegra_dc_destroy,
Thierry Redingca915b12014-12-08 16:14:45 +0100945 .reset = tegra_crtc_reset,
946 .atomic_duplicate_state = tegra_crtc_atomic_duplicate_state,
947 .atomic_destroy_state = tegra_crtc_atomic_destroy_state,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000948};
949
Thierry Reding86df2562014-12-08 16:03:53 +0100950static void tegra_dc_stop(struct tegra_dc *dc)
951{
952 u32 value;
953
954 /* stop the display controller */
955 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
956 value &= ~DISP_CTRL_MODE_MASK;
957 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
958
959 tegra_dc_commit(dc);
960}
961
962static bool tegra_dc_idle(struct tegra_dc *dc)
963{
964 u32 value;
965
966 value = tegra_dc_readl_active(dc, DC_CMD_DISPLAY_COMMAND);
967
968 return (value & DISP_CTRL_MODE_MASK) == 0;
969}
970
971static int tegra_dc_wait_idle(struct tegra_dc *dc, unsigned long timeout)
972{
973 timeout = jiffies + msecs_to_jiffies(timeout);
974
975 while (time_before(jiffies, timeout)) {
976 if (tegra_dc_idle(dc))
977 return 0;
978
979 usleep_range(1000, 2000);
980 }
981
982 dev_dbg(dc->dev, "timeout waiting for DC to become idle\n");
983 return -ETIMEDOUT;
984}
985
Thierry Redingf34bc782012-11-04 21:47:13 +0100986static void tegra_crtc_disable(struct drm_crtc *crtc)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000987{
Thierry Redingf002abc2013-10-14 14:06:02 +0200988 struct tegra_dc *dc = to_tegra_dc(crtc);
Thierry Reding3b0e5852014-12-16 18:30:16 +0100989 u32 value;
Thierry Redingf002abc2013-10-14 14:06:02 +0200990
Thierry Reding86df2562014-12-08 16:03:53 +0100991 if (!tegra_dc_idle(dc)) {
992 tegra_dc_stop(dc);
993
994 /*
995 * Ignore the return value, there isn't anything useful to do
996 * in case this fails.
997 */
998 tegra_dc_wait_idle(dc, 100);
999 }
Thierry Reding36904ad2014-11-21 17:35:54 +01001000
Thierry Reding3b0e5852014-12-16 18:30:16 +01001001 /*
1002 * This should really be part of the RGB encoder driver, but clearing
1003 * these bits has the side-effect of stopping the display controller.
1004 * When that happens no VBLANK interrupts will be raised. At the same
1005 * time the encoder is disabled before the display controller, so the
1006 * above code is always going to timeout waiting for the controller
1007 * to go idle.
1008 *
1009 * Given the close coupling between the RGB encoder and the display
1010 * controller doing it here is still kind of okay. None of the other
1011 * encoder drivers require these bits to be cleared.
1012 *
1013 * XXX: Perhaps given that the display controller is switched off at
1014 * this point anyway maybe clearing these bits isn't even useful for
1015 * the RGB encoder?
1016 */
1017 if (dc->rgb) {
1018 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
1019 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1020 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
1021 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
1022 }
1023
Thierry Reding8ff64c12014-10-08 14:48:51 +02001024 drm_crtc_vblank_off(crtc);
Thierry Redingc7679302014-10-21 13:51:53 +02001025 tegra_dc_commit(dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001026}
1027
1028static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc,
1029 const struct drm_display_mode *mode,
1030 struct drm_display_mode *adjusted)
1031{
1032 return true;
1033}
1034
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001035static int tegra_dc_set_timings(struct tegra_dc *dc,
1036 struct drm_display_mode *mode)
1037{
Thierry Reding0444c0f2014-04-16 09:22:38 +02001038 unsigned int h_ref_to_sync = 1;
1039 unsigned int v_ref_to_sync = 1;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001040 unsigned long value;
1041
1042 tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS);
1043
1044 value = (v_ref_to_sync << 16) | h_ref_to_sync;
1045 tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC);
1046
1047 value = ((mode->vsync_end - mode->vsync_start) << 16) |
1048 ((mode->hsync_end - mode->hsync_start) << 0);
1049 tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH);
1050
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001051 value = ((mode->vtotal - mode->vsync_end) << 16) |
1052 ((mode->htotal - mode->hsync_end) << 0);
Lucas Stach40495082012-12-19 21:38:52 +00001053 tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH);
1054
1055 value = ((mode->vsync_start - mode->vdisplay) << 16) |
1056 ((mode->hsync_start - mode->hdisplay) << 0);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001057 tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH);
1058
1059 value = (mode->vdisplay << 16) | mode->hdisplay;
1060 tegra_dc_writel(dc, value, DC_DISP_ACTIVE);
1061
1062 return 0;
1063}
1064
Thierry Redingc5a107d2014-12-02 15:15:06 +01001065int tegra_dc_setup_clock(struct tegra_dc *dc, struct clk *parent,
1066 unsigned long pclk, unsigned int div)
1067{
1068 u32 value;
1069 int err;
1070
1071 err = clk_set_parent(dc->clk, parent);
1072 if (err < 0) {
1073 dev_err(dc->dev, "failed to set parent clock: %d\n", err);
1074 return err;
1075 }
1076
1077 DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk), div);
1078
1079 value = SHIFT_CLK_DIVIDER(div) | PIXEL_CLK_DIVIDER_PCD1;
1080 tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL);
1081
1082 return 0;
1083}
1084
Thierry Redingca915b12014-12-08 16:14:45 +01001085int tegra_dc_state_setup_clock(struct tegra_dc *dc,
1086 struct drm_crtc_state *crtc_state,
1087 struct clk *clk, unsigned long pclk,
1088 unsigned int div)
1089{
1090 struct tegra_dc_state *state = to_dc_state(crtc_state);
1091
1092 state->clk = clk;
1093 state->pclk = pclk;
1094 state->div = div;
1095
1096 return 0;
1097}
1098
Thierry Reding76d59ed2014-12-19 15:09:16 +01001099static void tegra_dc_commit_state(struct tegra_dc *dc,
1100 struct tegra_dc_state *state)
1101{
1102 u32 value;
1103 int err;
1104
1105 err = clk_set_parent(dc->clk, state->clk);
1106 if (err < 0)
1107 dev_err(dc->dev, "failed to set parent clock: %d\n", err);
1108
1109 /*
1110 * Outputs may not want to change the parent clock rate. This is only
1111 * relevant to Tegra20 where only a single display PLL is available.
1112 * Since that PLL would typically be used for HDMI, an internal LVDS
1113 * panel would need to be driven by some other clock such as PLL_P
1114 * which is shared with other peripherals. Changing the clock rate
1115 * should therefore be avoided.
1116 */
1117 if (state->pclk > 0) {
1118 err = clk_set_rate(state->clk, state->pclk);
1119 if (err < 0)
1120 dev_err(dc->dev,
1121 "failed to set clock rate to %lu Hz\n",
1122 state->pclk);
1123 }
1124
1125 DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk),
1126 state->div);
1127 DRM_DEBUG_KMS("pclk: %lu\n", state->pclk);
1128
1129 value = SHIFT_CLK_DIVIDER(state->div) | PIXEL_CLK_DIVIDER_PCD1;
1130 tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL);
1131}
1132
Thierry Reding4aa3df72014-11-24 16:27:13 +01001133static void tegra_crtc_mode_set_nofb(struct drm_crtc *crtc)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001134{
Thierry Reding4aa3df72014-11-24 16:27:13 +01001135 struct drm_display_mode *mode = &crtc->state->adjusted_mode;
Thierry Reding76d59ed2014-12-19 15:09:16 +01001136 struct tegra_dc_state *state = to_dc_state(crtc->state);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001137 struct tegra_dc *dc = to_tegra_dc(crtc);
Thierry Redingdbb3f2f2014-03-26 12:32:14 +01001138 u32 value;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001139
Thierry Reding76d59ed2014-12-19 15:09:16 +01001140 tegra_dc_commit_state(dc, state);
1141
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001142 /* program display mode */
1143 tegra_dc_set_timings(dc, mode);
1144
Thierry Reding42d06592014-12-08 15:45:39 +01001145 if (dc->soc->supports_border_color)
1146 tegra_dc_writel(dc, 0, DC_DISP_BORDER_COLOR);
1147
Thierry Reding8620fc62013-12-12 11:03:59 +01001148 /* interlacing isn't supported yet, so disable it */
1149 if (dc->soc->supports_interlacing) {
1150 value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL);
1151 value &= ~INTERLACE_ENABLE;
1152 tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL);
1153 }
Thierry Reding23fb4742012-11-28 11:38:24 +01001154}
1155
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001156static void tegra_crtc_prepare(struct drm_crtc *crtc)
1157{
1158 struct tegra_dc *dc = to_tegra_dc(crtc);
1159 unsigned int syncpt;
1160 unsigned long value;
1161
Thierry Reding8ff64c12014-10-08 14:48:51 +02001162 drm_crtc_vblank_off(crtc);
1163
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001164 if (dc->pipe)
1165 syncpt = SYNCPT_VBLANK1;
1166 else
1167 syncpt = SYNCPT_VBLANK0;
1168
1169 /* initialize display controller */
1170 tegra_dc_writel(dc, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
1171 tegra_dc_writel(dc, 0x100 | syncpt, DC_CMD_CONT_SYNCPT_VSYNC);
1172
1173 value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | WIN_A_OF_INT;
1174 tegra_dc_writel(dc, value, DC_CMD_INT_TYPE);
1175
1176 value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
1177 WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
1178 tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY);
1179
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001180 /* initialize timer */
1181 value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) |
1182 WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20);
1183 tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY);
1184
1185 value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) |
1186 WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1);
1187 tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
1188
1189 value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001190 tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
Thierry Reding6e5ff992012-11-28 11:45:47 +01001191
1192 value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
1193 tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001194}
1195
1196static void tegra_crtc_commit(struct drm_crtc *crtc)
1197{
1198 struct tegra_dc *dc = to_tegra_dc(crtc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001199
Thierry Reding8ff64c12014-10-08 14:48:51 +02001200 drm_crtc_vblank_on(crtc);
Thierry Reding205d48e2014-10-21 13:41:46 +02001201 tegra_dc_commit(dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001202}
1203
Thierry Reding4aa3df72014-11-24 16:27:13 +01001204static int tegra_crtc_atomic_check(struct drm_crtc *crtc,
1205 struct drm_crtc_state *state)
1206{
1207 return 0;
1208}
1209
1210static void tegra_crtc_atomic_begin(struct drm_crtc *crtc)
1211{
Thierry Reding1503ca42014-11-24 17:41:23 +01001212 struct tegra_dc *dc = to_tegra_dc(crtc);
1213
1214 if (crtc->state->event) {
1215 crtc->state->event->pipe = drm_crtc_index(crtc);
1216
1217 WARN_ON(drm_crtc_vblank_get(crtc) != 0);
1218
1219 dc->event = crtc->state->event;
1220 crtc->state->event = NULL;
1221 }
Thierry Reding4aa3df72014-11-24 16:27:13 +01001222}
1223
1224static void tegra_crtc_atomic_flush(struct drm_crtc *crtc)
1225{
1226}
1227
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001228static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = {
Thierry Redingf34bc782012-11-04 21:47:13 +01001229 .disable = tegra_crtc_disable,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001230 .mode_fixup = tegra_crtc_mode_fixup,
Thierry Reding4aa3df72014-11-24 16:27:13 +01001231 .mode_set = drm_helper_crtc_mode_set,
1232 .mode_set_nofb = tegra_crtc_mode_set_nofb,
1233 .mode_set_base = drm_helper_crtc_mode_set_base,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001234 .prepare = tegra_crtc_prepare,
1235 .commit = tegra_crtc_commit,
Thierry Reding4aa3df72014-11-24 16:27:13 +01001236 .atomic_check = tegra_crtc_atomic_check,
1237 .atomic_begin = tegra_crtc_atomic_begin,
1238 .atomic_flush = tegra_crtc_atomic_flush,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001239};
1240
Thierry Reding6e5ff992012-11-28 11:45:47 +01001241static irqreturn_t tegra_dc_irq(int irq, void *data)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001242{
1243 struct tegra_dc *dc = data;
1244 unsigned long status;
1245
1246 status = tegra_dc_readl(dc, DC_CMD_INT_STATUS);
1247 tegra_dc_writel(dc, status, DC_CMD_INT_STATUS);
1248
1249 if (status & FRAME_END_INT) {
1250 /*
1251 dev_dbg(dc->dev, "%s(): frame end\n", __func__);
1252 */
1253 }
1254
1255 if (status & VBLANK_INT) {
1256 /*
1257 dev_dbg(dc->dev, "%s(): vertical blank\n", __func__);
1258 */
Thierry Redinged7dae52014-12-16 16:03:13 +01001259 drm_crtc_handle_vblank(&dc->base);
Thierry Reding3c03c462012-11-28 12:00:18 +01001260 tegra_dc_finish_page_flip(dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001261 }
1262
1263 if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) {
1264 /*
1265 dev_dbg(dc->dev, "%s(): underflow\n", __func__);
1266 */
1267 }
1268
1269 return IRQ_HANDLED;
1270}
1271
1272static int tegra_dc_show_regs(struct seq_file *s, void *data)
1273{
1274 struct drm_info_node *node = s->private;
1275 struct tegra_dc *dc = node->info_ent->data;
1276
1277#define DUMP_REG(name) \
Thierry Reding03a60562014-10-21 13:48:48 +02001278 seq_printf(s, "%-40s %#05x %08x\n", #name, name, \
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001279 tegra_dc_readl(dc, name))
1280
1281 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT);
1282 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
1283 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR);
1284 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT);
1285 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL);
1286 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR);
1287 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT);
1288 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL);
1289 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR);
1290 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT);
1291 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL);
1292 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR);
1293 DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC);
1294 DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0);
1295 DUMP_REG(DC_CMD_DISPLAY_COMMAND);
1296 DUMP_REG(DC_CMD_SIGNAL_RAISE);
1297 DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL);
1298 DUMP_REG(DC_CMD_INT_STATUS);
1299 DUMP_REG(DC_CMD_INT_MASK);
1300 DUMP_REG(DC_CMD_INT_ENABLE);
1301 DUMP_REG(DC_CMD_INT_TYPE);
1302 DUMP_REG(DC_CMD_INT_POLARITY);
1303 DUMP_REG(DC_CMD_SIGNAL_RAISE1);
1304 DUMP_REG(DC_CMD_SIGNAL_RAISE2);
1305 DUMP_REG(DC_CMD_SIGNAL_RAISE3);
1306 DUMP_REG(DC_CMD_STATE_ACCESS);
1307 DUMP_REG(DC_CMD_STATE_CONTROL);
1308 DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER);
1309 DUMP_REG(DC_CMD_REG_ACT_CONTROL);
1310 DUMP_REG(DC_COM_CRC_CONTROL);
1311 DUMP_REG(DC_COM_CRC_CHECKSUM);
1312 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0));
1313 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1));
1314 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2));
1315 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3));
1316 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0));
1317 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1));
1318 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2));
1319 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3));
1320 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0));
1321 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1));
1322 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2));
1323 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3));
1324 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0));
1325 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1));
1326 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2));
1327 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3));
1328 DUMP_REG(DC_COM_PIN_INPUT_DATA(0));
1329 DUMP_REG(DC_COM_PIN_INPUT_DATA(1));
1330 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0));
1331 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1));
1332 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2));
1333 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3));
1334 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4));
1335 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5));
1336 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6));
1337 DUMP_REG(DC_COM_PIN_MISC_CONTROL);
1338 DUMP_REG(DC_COM_PIN_PM0_CONTROL);
1339 DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE);
1340 DUMP_REG(DC_COM_PIN_PM1_CONTROL);
1341 DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE);
1342 DUMP_REG(DC_COM_SPI_CONTROL);
1343 DUMP_REG(DC_COM_SPI_START_BYTE);
1344 DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB);
1345 DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD);
1346 DUMP_REG(DC_COM_HSPI_CS_DC);
1347 DUMP_REG(DC_COM_SCRATCH_REGISTER_A);
1348 DUMP_REG(DC_COM_SCRATCH_REGISTER_B);
1349 DUMP_REG(DC_COM_GPIO_CTRL);
1350 DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER);
1351 DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED);
1352 DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0);
1353 DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1);
1354 DUMP_REG(DC_DISP_DISP_WIN_OPTIONS);
1355 DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY);
1356 DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
1357 DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS);
1358 DUMP_REG(DC_DISP_REF_TO_SYNC);
1359 DUMP_REG(DC_DISP_SYNC_WIDTH);
1360 DUMP_REG(DC_DISP_BACK_PORCH);
1361 DUMP_REG(DC_DISP_ACTIVE);
1362 DUMP_REG(DC_DISP_FRONT_PORCH);
1363 DUMP_REG(DC_DISP_H_PULSE0_CONTROL);
1364 DUMP_REG(DC_DISP_H_PULSE0_POSITION_A);
1365 DUMP_REG(DC_DISP_H_PULSE0_POSITION_B);
1366 DUMP_REG(DC_DISP_H_PULSE0_POSITION_C);
1367 DUMP_REG(DC_DISP_H_PULSE0_POSITION_D);
1368 DUMP_REG(DC_DISP_H_PULSE1_CONTROL);
1369 DUMP_REG(DC_DISP_H_PULSE1_POSITION_A);
1370 DUMP_REG(DC_DISP_H_PULSE1_POSITION_B);
1371 DUMP_REG(DC_DISP_H_PULSE1_POSITION_C);
1372 DUMP_REG(DC_DISP_H_PULSE1_POSITION_D);
1373 DUMP_REG(DC_DISP_H_PULSE2_CONTROL);
1374 DUMP_REG(DC_DISP_H_PULSE2_POSITION_A);
1375 DUMP_REG(DC_DISP_H_PULSE2_POSITION_B);
1376 DUMP_REG(DC_DISP_H_PULSE2_POSITION_C);
1377 DUMP_REG(DC_DISP_H_PULSE2_POSITION_D);
1378 DUMP_REG(DC_DISP_V_PULSE0_CONTROL);
1379 DUMP_REG(DC_DISP_V_PULSE0_POSITION_A);
1380 DUMP_REG(DC_DISP_V_PULSE0_POSITION_B);
1381 DUMP_REG(DC_DISP_V_PULSE0_POSITION_C);
1382 DUMP_REG(DC_DISP_V_PULSE1_CONTROL);
1383 DUMP_REG(DC_DISP_V_PULSE1_POSITION_A);
1384 DUMP_REG(DC_DISP_V_PULSE1_POSITION_B);
1385 DUMP_REG(DC_DISP_V_PULSE1_POSITION_C);
1386 DUMP_REG(DC_DISP_V_PULSE2_CONTROL);
1387 DUMP_REG(DC_DISP_V_PULSE2_POSITION_A);
1388 DUMP_REG(DC_DISP_V_PULSE3_CONTROL);
1389 DUMP_REG(DC_DISP_V_PULSE3_POSITION_A);
1390 DUMP_REG(DC_DISP_M0_CONTROL);
1391 DUMP_REG(DC_DISP_M1_CONTROL);
1392 DUMP_REG(DC_DISP_DI_CONTROL);
1393 DUMP_REG(DC_DISP_PP_CONTROL);
1394 DUMP_REG(DC_DISP_PP_SELECT_A);
1395 DUMP_REG(DC_DISP_PP_SELECT_B);
1396 DUMP_REG(DC_DISP_PP_SELECT_C);
1397 DUMP_REG(DC_DISP_PP_SELECT_D);
1398 DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL);
1399 DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL);
1400 DUMP_REG(DC_DISP_DISP_COLOR_CONTROL);
1401 DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS);
1402 DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS);
1403 DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS);
1404 DUMP_REG(DC_DISP_LCD_SPI_OPTIONS);
1405 DUMP_REG(DC_DISP_BORDER_COLOR);
1406 DUMP_REG(DC_DISP_COLOR_KEY0_LOWER);
1407 DUMP_REG(DC_DISP_COLOR_KEY0_UPPER);
1408 DUMP_REG(DC_DISP_COLOR_KEY1_LOWER);
1409 DUMP_REG(DC_DISP_COLOR_KEY1_UPPER);
1410 DUMP_REG(DC_DISP_CURSOR_FOREGROUND);
1411 DUMP_REG(DC_DISP_CURSOR_BACKGROUND);
1412 DUMP_REG(DC_DISP_CURSOR_START_ADDR);
1413 DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS);
1414 DUMP_REG(DC_DISP_CURSOR_POSITION);
1415 DUMP_REG(DC_DISP_CURSOR_POSITION_NS);
1416 DUMP_REG(DC_DISP_INIT_SEQ_CONTROL);
1417 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A);
1418 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B);
1419 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C);
1420 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D);
1421 DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL);
1422 DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST);
1423 DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST);
1424 DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST);
1425 DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST);
1426 DUMP_REG(DC_DISP_DAC_CRT_CTRL);
1427 DUMP_REG(DC_DISP_DISP_MISC_CONTROL);
1428 DUMP_REG(DC_DISP_SD_CONTROL);
1429 DUMP_REG(DC_DISP_SD_CSC_COEFF);
1430 DUMP_REG(DC_DISP_SD_LUT(0));
1431 DUMP_REG(DC_DISP_SD_LUT(1));
1432 DUMP_REG(DC_DISP_SD_LUT(2));
1433 DUMP_REG(DC_DISP_SD_LUT(3));
1434 DUMP_REG(DC_DISP_SD_LUT(4));
1435 DUMP_REG(DC_DISP_SD_LUT(5));
1436 DUMP_REG(DC_DISP_SD_LUT(6));
1437 DUMP_REG(DC_DISP_SD_LUT(7));
1438 DUMP_REG(DC_DISP_SD_LUT(8));
1439 DUMP_REG(DC_DISP_SD_FLICKER_CONTROL);
1440 DUMP_REG(DC_DISP_DC_PIXEL_COUNT);
1441 DUMP_REG(DC_DISP_SD_HISTOGRAM(0));
1442 DUMP_REG(DC_DISP_SD_HISTOGRAM(1));
1443 DUMP_REG(DC_DISP_SD_HISTOGRAM(2));
1444 DUMP_REG(DC_DISP_SD_HISTOGRAM(3));
1445 DUMP_REG(DC_DISP_SD_HISTOGRAM(4));
1446 DUMP_REG(DC_DISP_SD_HISTOGRAM(5));
1447 DUMP_REG(DC_DISP_SD_HISTOGRAM(6));
1448 DUMP_REG(DC_DISP_SD_HISTOGRAM(7));
1449 DUMP_REG(DC_DISP_SD_BL_TF(0));
1450 DUMP_REG(DC_DISP_SD_BL_TF(1));
1451 DUMP_REG(DC_DISP_SD_BL_TF(2));
1452 DUMP_REG(DC_DISP_SD_BL_TF(3));
1453 DUMP_REG(DC_DISP_SD_BL_CONTROL);
1454 DUMP_REG(DC_DISP_SD_HW_K_VALUES);
1455 DUMP_REG(DC_DISP_SD_MAN_K_VALUES);
Thierry Redinge6876512013-12-20 13:58:33 +01001456 DUMP_REG(DC_DISP_CURSOR_START_ADDR_HI);
1457 DUMP_REG(DC_DISP_BLEND_CURSOR_CONTROL);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001458 DUMP_REG(DC_WIN_WIN_OPTIONS);
1459 DUMP_REG(DC_WIN_BYTE_SWAP);
1460 DUMP_REG(DC_WIN_BUFFER_CONTROL);
1461 DUMP_REG(DC_WIN_COLOR_DEPTH);
1462 DUMP_REG(DC_WIN_POSITION);
1463 DUMP_REG(DC_WIN_SIZE);
1464 DUMP_REG(DC_WIN_PRESCALED_SIZE);
1465 DUMP_REG(DC_WIN_H_INITIAL_DDA);
1466 DUMP_REG(DC_WIN_V_INITIAL_DDA);
1467 DUMP_REG(DC_WIN_DDA_INC);
1468 DUMP_REG(DC_WIN_LINE_STRIDE);
1469 DUMP_REG(DC_WIN_BUF_STRIDE);
1470 DUMP_REG(DC_WIN_UV_BUF_STRIDE);
1471 DUMP_REG(DC_WIN_BUFFER_ADDR_MODE);
1472 DUMP_REG(DC_WIN_DV_CONTROL);
1473 DUMP_REG(DC_WIN_BLEND_NOKEY);
1474 DUMP_REG(DC_WIN_BLEND_1WIN);
1475 DUMP_REG(DC_WIN_BLEND_2WIN_X);
1476 DUMP_REG(DC_WIN_BLEND_2WIN_Y);
Thierry Redingf34bc782012-11-04 21:47:13 +01001477 DUMP_REG(DC_WIN_BLEND_3WIN_XY);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001478 DUMP_REG(DC_WIN_HP_FETCH_CONTROL);
1479 DUMP_REG(DC_WINBUF_START_ADDR);
1480 DUMP_REG(DC_WINBUF_START_ADDR_NS);
1481 DUMP_REG(DC_WINBUF_START_ADDR_U);
1482 DUMP_REG(DC_WINBUF_START_ADDR_U_NS);
1483 DUMP_REG(DC_WINBUF_START_ADDR_V);
1484 DUMP_REG(DC_WINBUF_START_ADDR_V_NS);
1485 DUMP_REG(DC_WINBUF_ADDR_H_OFFSET);
1486 DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS);
1487 DUMP_REG(DC_WINBUF_ADDR_V_OFFSET);
1488 DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS);
1489 DUMP_REG(DC_WINBUF_UFLOW_STATUS);
1490 DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS);
1491 DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS);
1492 DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS);
1493
1494#undef DUMP_REG
1495
1496 return 0;
1497}
1498
1499static struct drm_info_list debugfs_files[] = {
1500 { "regs", tegra_dc_show_regs, 0, NULL },
1501};
1502
1503static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
1504{
1505 unsigned int i;
1506 char *name;
1507 int err;
1508
1509 name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe);
1510 dc->debugfs = debugfs_create_dir(name, minor->debugfs_root);
1511 kfree(name);
1512
1513 if (!dc->debugfs)
1514 return -ENOMEM;
1515
1516 dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1517 GFP_KERNEL);
1518 if (!dc->debugfs_files) {
1519 err = -ENOMEM;
1520 goto remove;
1521 }
1522
1523 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1524 dc->debugfs_files[i].data = dc;
1525
1526 err = drm_debugfs_create_files(dc->debugfs_files,
1527 ARRAY_SIZE(debugfs_files),
1528 dc->debugfs, minor);
1529 if (err < 0)
1530 goto free;
1531
1532 dc->minor = minor;
1533
1534 return 0;
1535
1536free:
1537 kfree(dc->debugfs_files);
1538 dc->debugfs_files = NULL;
1539remove:
1540 debugfs_remove(dc->debugfs);
1541 dc->debugfs = NULL;
1542
1543 return err;
1544}
1545
1546static int tegra_dc_debugfs_exit(struct tegra_dc *dc)
1547{
1548 drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files),
1549 dc->minor);
1550 dc->minor = NULL;
1551
1552 kfree(dc->debugfs_files);
1553 dc->debugfs_files = NULL;
1554
1555 debugfs_remove(dc->debugfs);
1556 dc->debugfs = NULL;
1557
1558 return 0;
1559}
1560
Thierry Reding53fa7f72013-09-24 15:35:40 +02001561static int tegra_dc_init(struct host1x_client *client)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001562{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001563 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Reding776dc382013-10-14 14:43:22 +02001564 struct tegra_dc *dc = host1x_client_to_dc(client);
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001565 struct tegra_drm *tegra = drm->dev_private;
Thierry Redingc7679302014-10-21 13:51:53 +02001566 struct drm_plane *primary = NULL;
1567 struct drm_plane *cursor = NULL;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001568 int err;
1569
Thierry Redingdf06b752014-06-26 21:41:53 +02001570 if (tegra->domain) {
1571 err = iommu_attach_device(tegra->domain, dc->dev);
1572 if (err < 0) {
1573 dev_err(dc->dev, "failed to attach to domain: %d\n",
1574 err);
1575 return err;
1576 }
1577
1578 dc->domain = tegra->domain;
1579 }
1580
Thierry Redingc7679302014-10-21 13:51:53 +02001581 primary = tegra_dc_primary_plane_create(drm, dc);
1582 if (IS_ERR(primary)) {
1583 err = PTR_ERR(primary);
1584 goto cleanup;
1585 }
1586
1587 if (dc->soc->supports_cursor) {
1588 cursor = tegra_dc_cursor_plane_create(drm, dc);
1589 if (IS_ERR(cursor)) {
1590 err = PTR_ERR(cursor);
1591 goto cleanup;
1592 }
1593 }
1594
1595 err = drm_crtc_init_with_planes(drm, &dc->base, primary, cursor,
1596 &tegra_crtc_funcs);
1597 if (err < 0)
1598 goto cleanup;
1599
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001600 drm_mode_crtc_set_gamma_size(&dc->base, 256);
1601 drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs);
1602
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001603 /*
1604 * Keep track of the minimum pitch alignment across all display
1605 * controllers.
1606 */
1607 if (dc->soc->pitch_align > tegra->pitch_align)
1608 tegra->pitch_align = dc->soc->pitch_align;
1609
Thierry Reding9910f5c2014-05-22 09:57:15 +02001610 err = tegra_dc_rgb_init(drm, dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001611 if (err < 0 && err != -ENODEV) {
1612 dev_err(dc->dev, "failed to initialize RGB output: %d\n", err);
Thierry Redingc7679302014-10-21 13:51:53 +02001613 goto cleanup;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001614 }
1615
Thierry Reding9910f5c2014-05-22 09:57:15 +02001616 err = tegra_dc_add_planes(drm, dc);
Thierry Redingf34bc782012-11-04 21:47:13 +01001617 if (err < 0)
Thierry Redingc7679302014-10-21 13:51:53 +02001618 goto cleanup;
Thierry Redingf34bc782012-11-04 21:47:13 +01001619
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001620 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +02001621 err = tegra_dc_debugfs_init(dc, drm->primary);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001622 if (err < 0)
1623 dev_err(dc->dev, "debugfs setup failed: %d\n", err);
1624 }
1625
Thierry Reding6e5ff992012-11-28 11:45:47 +01001626 err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001627 dev_name(dc->dev), dc);
1628 if (err < 0) {
1629 dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq,
1630 err);
Thierry Redingc7679302014-10-21 13:51:53 +02001631 goto cleanup;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001632 }
1633
1634 return 0;
Thierry Redingc7679302014-10-21 13:51:53 +02001635
1636cleanup:
1637 if (cursor)
1638 drm_plane_cleanup(cursor);
1639
1640 if (primary)
1641 drm_plane_cleanup(primary);
1642
1643 if (tegra->domain) {
1644 iommu_detach_device(tegra->domain, dc->dev);
1645 dc->domain = NULL;
1646 }
1647
1648 return err;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001649}
1650
Thierry Reding53fa7f72013-09-24 15:35:40 +02001651static int tegra_dc_exit(struct host1x_client *client)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001652{
Thierry Reding776dc382013-10-14 14:43:22 +02001653 struct tegra_dc *dc = host1x_client_to_dc(client);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001654 int err;
1655
1656 devm_free_irq(dc->dev, dc->irq, dc);
1657
1658 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1659 err = tegra_dc_debugfs_exit(dc);
1660 if (err < 0)
1661 dev_err(dc->dev, "debugfs cleanup failed: %d\n", err);
1662 }
1663
1664 err = tegra_dc_rgb_exit(dc);
1665 if (err) {
1666 dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err);
1667 return err;
1668 }
1669
Thierry Redingdf06b752014-06-26 21:41:53 +02001670 if (dc->domain) {
1671 iommu_detach_device(dc->domain, dc->dev);
1672 dc->domain = NULL;
1673 }
1674
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001675 return 0;
1676}
1677
1678static const struct host1x_client_ops dc_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001679 .init = tegra_dc_init,
1680 .exit = tegra_dc_exit,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001681};
1682
Thierry Reding8620fc62013-12-12 11:03:59 +01001683static const struct tegra_dc_soc_info tegra20_dc_soc_info = {
Thierry Reding42d06592014-12-08 15:45:39 +01001684 .supports_border_color = true,
Thierry Reding8620fc62013-12-12 11:03:59 +01001685 .supports_interlacing = false,
Thierry Redinge6876512013-12-20 13:58:33 +01001686 .supports_cursor = false,
Thierry Redingc134f012014-06-03 14:48:12 +02001687 .supports_block_linear = false,
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001688 .pitch_align = 8,
Thierry Reding9c012702014-07-07 15:32:53 +02001689 .has_powergate = false,
Thierry Reding8620fc62013-12-12 11:03:59 +01001690};
1691
1692static const struct tegra_dc_soc_info tegra30_dc_soc_info = {
Thierry Reding42d06592014-12-08 15:45:39 +01001693 .supports_border_color = true,
Thierry Reding8620fc62013-12-12 11:03:59 +01001694 .supports_interlacing = false,
Thierry Redinge6876512013-12-20 13:58:33 +01001695 .supports_cursor = false,
Thierry Redingc134f012014-06-03 14:48:12 +02001696 .supports_block_linear = false,
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001697 .pitch_align = 8,
Thierry Reding9c012702014-07-07 15:32:53 +02001698 .has_powergate = false,
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001699};
1700
1701static const struct tegra_dc_soc_info tegra114_dc_soc_info = {
Thierry Reding42d06592014-12-08 15:45:39 +01001702 .supports_border_color = true,
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001703 .supports_interlacing = false,
1704 .supports_cursor = false,
1705 .supports_block_linear = false,
1706 .pitch_align = 64,
Thierry Reding9c012702014-07-07 15:32:53 +02001707 .has_powergate = true,
Thierry Reding8620fc62013-12-12 11:03:59 +01001708};
1709
1710static const struct tegra_dc_soc_info tegra124_dc_soc_info = {
Thierry Reding42d06592014-12-08 15:45:39 +01001711 .supports_border_color = false,
Thierry Reding8620fc62013-12-12 11:03:59 +01001712 .supports_interlacing = true,
Thierry Redinge6876512013-12-20 13:58:33 +01001713 .supports_cursor = true,
Thierry Redingc134f012014-06-03 14:48:12 +02001714 .supports_block_linear = true,
Thierry Redingd1f3e1e2014-07-11 08:29:14 +02001715 .pitch_align = 64,
Thierry Reding9c012702014-07-07 15:32:53 +02001716 .has_powergate = true,
Thierry Reding8620fc62013-12-12 11:03:59 +01001717};
1718
1719static const struct of_device_id tegra_dc_of_match[] = {
1720 {
1721 .compatible = "nvidia,tegra124-dc",
1722 .data = &tegra124_dc_soc_info,
1723 }, {
Thierry Reding9c012702014-07-07 15:32:53 +02001724 .compatible = "nvidia,tegra114-dc",
1725 .data = &tegra114_dc_soc_info,
1726 }, {
Thierry Reding8620fc62013-12-12 11:03:59 +01001727 .compatible = "nvidia,tegra30-dc",
1728 .data = &tegra30_dc_soc_info,
1729 }, {
1730 .compatible = "nvidia,tegra20-dc",
1731 .data = &tegra20_dc_soc_info,
1732 }, {
1733 /* sentinel */
1734 }
1735};
Stephen Warrenef707282014-06-18 16:21:55 -06001736MODULE_DEVICE_TABLE(of, tegra_dc_of_match);
Thierry Reding8620fc62013-12-12 11:03:59 +01001737
Thierry Reding13411dd2014-01-09 17:08:36 +01001738static int tegra_dc_parse_dt(struct tegra_dc *dc)
1739{
1740 struct device_node *np;
1741 u32 value = 0;
1742 int err;
1743
1744 err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value);
1745 if (err < 0) {
1746 dev_err(dc->dev, "missing \"nvidia,head\" property\n");
1747
1748 /*
1749 * If the nvidia,head property isn't present, try to find the
1750 * correct head number by looking up the position of this
1751 * display controller's node within the device tree. Assuming
1752 * that the nodes are ordered properly in the DTS file and
1753 * that the translation into a flattened device tree blob
1754 * preserves that ordering this will actually yield the right
1755 * head number.
1756 *
1757 * If those assumptions don't hold, this will still work for
1758 * cases where only a single display controller is used.
1759 */
1760 for_each_matching_node(np, tegra_dc_of_match) {
1761 if (np == dc->dev->of_node)
1762 break;
1763
1764 value++;
1765 }
1766 }
1767
1768 dc->pipe = value;
1769
1770 return 0;
1771}
1772
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001773static int tegra_dc_probe(struct platform_device *pdev)
1774{
Thierry Reding8620fc62013-12-12 11:03:59 +01001775 const struct of_device_id *id;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001776 struct resource *regs;
1777 struct tegra_dc *dc;
1778 int err;
1779
1780 dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
1781 if (!dc)
1782 return -ENOMEM;
1783
Thierry Reding8620fc62013-12-12 11:03:59 +01001784 id = of_match_node(tegra_dc_of_match, pdev->dev.of_node);
1785 if (!id)
1786 return -ENODEV;
1787
Thierry Reding6e5ff992012-11-28 11:45:47 +01001788 spin_lock_init(&dc->lock);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001789 INIT_LIST_HEAD(&dc->list);
1790 dc->dev = &pdev->dev;
Thierry Reding8620fc62013-12-12 11:03:59 +01001791 dc->soc = id->data;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001792
Thierry Reding13411dd2014-01-09 17:08:36 +01001793 err = tegra_dc_parse_dt(dc);
1794 if (err < 0)
1795 return err;
1796
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001797 dc->clk = devm_clk_get(&pdev->dev, NULL);
1798 if (IS_ERR(dc->clk)) {
1799 dev_err(&pdev->dev, "failed to get clock\n");
1800 return PTR_ERR(dc->clk);
1801 }
1802
Stephen Warrenca480802013-11-06 16:20:54 -07001803 dc->rst = devm_reset_control_get(&pdev->dev, "dc");
1804 if (IS_ERR(dc->rst)) {
1805 dev_err(&pdev->dev, "failed to get reset\n");
1806 return PTR_ERR(dc->rst);
1807 }
1808
Thierry Reding9c012702014-07-07 15:32:53 +02001809 if (dc->soc->has_powergate) {
1810 if (dc->pipe == 0)
1811 dc->powergate = TEGRA_POWERGATE_DIS;
1812 else
1813 dc->powergate = TEGRA_POWERGATE_DISB;
1814
1815 err = tegra_powergate_sequence_power_up(dc->powergate, dc->clk,
1816 dc->rst);
1817 if (err < 0) {
1818 dev_err(&pdev->dev, "failed to power partition: %d\n",
1819 err);
1820 return err;
1821 }
1822 } else {
1823 err = clk_prepare_enable(dc->clk);
1824 if (err < 0) {
1825 dev_err(&pdev->dev, "failed to enable clock: %d\n",
1826 err);
1827 return err;
1828 }
1829
1830 err = reset_control_deassert(dc->rst);
1831 if (err < 0) {
1832 dev_err(&pdev->dev, "failed to deassert reset: %d\n",
1833 err);
1834 return err;
1835 }
1836 }
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001837
1838 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingd4ed6022013-01-21 11:09:02 +01001839 dc->regs = devm_ioremap_resource(&pdev->dev, regs);
1840 if (IS_ERR(dc->regs))
1841 return PTR_ERR(dc->regs);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001842
1843 dc->irq = platform_get_irq(pdev, 0);
1844 if (dc->irq < 0) {
1845 dev_err(&pdev->dev, "failed to get IRQ\n");
1846 return -ENXIO;
1847 }
1848
Thierry Reding776dc382013-10-14 14:43:22 +02001849 INIT_LIST_HEAD(&dc->client.list);
1850 dc->client.ops = &dc_client_ops;
1851 dc->client.dev = &pdev->dev;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001852
1853 err = tegra_dc_rgb_probe(dc);
1854 if (err < 0 && err != -ENODEV) {
1855 dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err);
1856 return err;
1857 }
1858
Thierry Reding776dc382013-10-14 14:43:22 +02001859 err = host1x_client_register(&dc->client);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001860 if (err < 0) {
1861 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1862 err);
1863 return err;
1864 }
1865
1866 platform_set_drvdata(pdev, dc);
1867
1868 return 0;
1869}
1870
1871static int tegra_dc_remove(struct platform_device *pdev)
1872{
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001873 struct tegra_dc *dc = platform_get_drvdata(pdev);
1874 int err;
1875
Thierry Reding776dc382013-10-14 14:43:22 +02001876 err = host1x_client_unregister(&dc->client);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001877 if (err < 0) {
1878 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1879 err);
1880 return err;
1881 }
1882
Thierry Reding59d29c02013-10-14 14:26:42 +02001883 err = tegra_dc_rgb_remove(dc);
1884 if (err < 0) {
1885 dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err);
1886 return err;
1887 }
1888
Thierry Reding5482d752014-07-11 08:39:03 +02001889 reset_control_assert(dc->rst);
Thierry Reding9c012702014-07-07 15:32:53 +02001890
1891 if (dc->soc->has_powergate)
1892 tegra_powergate_power_off(dc->powergate);
1893
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001894 clk_disable_unprepare(dc->clk);
1895
1896 return 0;
1897}
1898
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001899struct platform_driver tegra_dc_driver = {
1900 .driver = {
1901 .name = "tegra-dc",
1902 .owner = THIS_MODULE,
1903 .of_match_table = tegra_dc_of_match,
1904 },
1905 .probe = tegra_dc_probe,
1906 .remove = tegra_dc_remove,
1907};