xref: /openbmc/linux/drivers/gpu/drm/tegra/dc.c (revision dbb3f2f751069bc757fbdbe8911a7e784e850b24)
1dee8268fSThierry Reding /*
2dee8268fSThierry Reding  * Copyright (C) 2012 Avionic Design GmbH
3dee8268fSThierry Reding  * Copyright (C) 2012 NVIDIA CORPORATION.  All rights reserved.
4dee8268fSThierry Reding  *
5dee8268fSThierry Reding  * This program is free software; you can redistribute it and/or modify
6dee8268fSThierry Reding  * it under the terms of the GNU General Public License version 2 as
7dee8268fSThierry Reding  * published by the Free Software Foundation.
8dee8268fSThierry Reding  */
9dee8268fSThierry Reding 
10dee8268fSThierry Reding #include <linux/clk.h>
11dee8268fSThierry Reding #include <linux/debugfs.h>
12ca48080aSStephen Warren #include <linux/reset.h>
13dee8268fSThierry Reding 
14dee8268fSThierry Reding #include "dc.h"
15dee8268fSThierry Reding #include "drm.h"
16dee8268fSThierry Reding #include "gem.h"
17dee8268fSThierry Reding 
188620fc62SThierry Reding struct tegra_dc_soc_info {
198620fc62SThierry Reding 	bool supports_interlacing;
208620fc62SThierry Reding };
218620fc62SThierry Reding 
22dee8268fSThierry Reding struct tegra_plane {
23dee8268fSThierry Reding 	struct drm_plane base;
24dee8268fSThierry Reding 	unsigned int index;
25dee8268fSThierry Reding };
26dee8268fSThierry Reding 
27dee8268fSThierry Reding static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane)
28dee8268fSThierry Reding {
29dee8268fSThierry Reding 	return container_of(plane, struct tegra_plane, base);
30dee8268fSThierry Reding }
31dee8268fSThierry Reding 
3210288eeaSThierry Reding static unsigned int tegra_dc_format(uint32_t format, uint32_t *swap)
3310288eeaSThierry Reding {
3410288eeaSThierry Reding 	/* assume no swapping of fetched data */
3510288eeaSThierry Reding 	if (swap)
3610288eeaSThierry Reding 		*swap = BYTE_SWAP_NOSWAP;
3710288eeaSThierry Reding 
3810288eeaSThierry Reding 	switch (format) {
3910288eeaSThierry Reding 	case DRM_FORMAT_XBGR8888:
4010288eeaSThierry Reding 		return WIN_COLOR_DEPTH_R8G8B8A8;
4110288eeaSThierry Reding 
4210288eeaSThierry Reding 	case DRM_FORMAT_XRGB8888:
4310288eeaSThierry Reding 		return WIN_COLOR_DEPTH_B8G8R8A8;
4410288eeaSThierry Reding 
4510288eeaSThierry Reding 	case DRM_FORMAT_RGB565:
4610288eeaSThierry Reding 		return WIN_COLOR_DEPTH_B5G6R5;
4710288eeaSThierry Reding 
4810288eeaSThierry Reding 	case DRM_FORMAT_UYVY:
4910288eeaSThierry Reding 		return WIN_COLOR_DEPTH_YCbCr422;
5010288eeaSThierry Reding 
5110288eeaSThierry Reding 	case DRM_FORMAT_YUYV:
5210288eeaSThierry Reding 		if (swap)
5310288eeaSThierry Reding 			*swap = BYTE_SWAP_SWAP2;
5410288eeaSThierry Reding 
5510288eeaSThierry Reding 		return WIN_COLOR_DEPTH_YCbCr422;
5610288eeaSThierry Reding 
5710288eeaSThierry Reding 	case DRM_FORMAT_YUV420:
5810288eeaSThierry Reding 		return WIN_COLOR_DEPTH_YCbCr420P;
5910288eeaSThierry Reding 
6010288eeaSThierry Reding 	case DRM_FORMAT_YUV422:
6110288eeaSThierry Reding 		return WIN_COLOR_DEPTH_YCbCr422P;
6210288eeaSThierry Reding 
6310288eeaSThierry Reding 	default:
6410288eeaSThierry Reding 		break;
6510288eeaSThierry Reding 	}
6610288eeaSThierry Reding 
6710288eeaSThierry Reding 	WARN(1, "unsupported pixel format %u, using default\n", format);
6810288eeaSThierry Reding 	return WIN_COLOR_DEPTH_B8G8R8A8;
6910288eeaSThierry Reding }
7010288eeaSThierry Reding 
7110288eeaSThierry Reding static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar)
7210288eeaSThierry Reding {
7310288eeaSThierry Reding 	switch (format) {
7410288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YCbCr422:
7510288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YUV422:
7610288eeaSThierry Reding 		if (planar)
7710288eeaSThierry Reding 			*planar = false;
7810288eeaSThierry Reding 
7910288eeaSThierry Reding 		return true;
8010288eeaSThierry Reding 
8110288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YCbCr420P:
8210288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YUV420P:
8310288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YCbCr422P:
8410288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YUV422P:
8510288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YCbCr422R:
8610288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YUV422R:
8710288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YCbCr422RA:
8810288eeaSThierry Reding 	case WIN_COLOR_DEPTH_YUV422RA:
8910288eeaSThierry Reding 		if (planar)
9010288eeaSThierry Reding 			*planar = true;
9110288eeaSThierry Reding 
9210288eeaSThierry Reding 		return true;
9310288eeaSThierry Reding 	}
9410288eeaSThierry Reding 
9510288eeaSThierry Reding 	return false;
9610288eeaSThierry Reding }
9710288eeaSThierry Reding 
9810288eeaSThierry Reding static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v,
9910288eeaSThierry Reding 				  unsigned int bpp)
10010288eeaSThierry Reding {
10110288eeaSThierry Reding 	fixed20_12 outf = dfixed_init(out);
10210288eeaSThierry Reding 	fixed20_12 inf = dfixed_init(in);
10310288eeaSThierry Reding 	u32 dda_inc;
10410288eeaSThierry Reding 	int max;
10510288eeaSThierry Reding 
10610288eeaSThierry Reding 	if (v)
10710288eeaSThierry Reding 		max = 15;
10810288eeaSThierry Reding 	else {
10910288eeaSThierry Reding 		switch (bpp) {
11010288eeaSThierry Reding 		case 2:
11110288eeaSThierry Reding 			max = 8;
11210288eeaSThierry Reding 			break;
11310288eeaSThierry Reding 
11410288eeaSThierry Reding 		default:
11510288eeaSThierry Reding 			WARN_ON_ONCE(1);
11610288eeaSThierry Reding 			/* fallthrough */
11710288eeaSThierry Reding 		case 4:
11810288eeaSThierry Reding 			max = 4;
11910288eeaSThierry Reding 			break;
12010288eeaSThierry Reding 		}
12110288eeaSThierry Reding 	}
12210288eeaSThierry Reding 
12310288eeaSThierry Reding 	outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1));
12410288eeaSThierry Reding 	inf.full -= dfixed_const(1);
12510288eeaSThierry Reding 
12610288eeaSThierry Reding 	dda_inc = dfixed_div(inf, outf);
12710288eeaSThierry Reding 	dda_inc = min_t(u32, dda_inc, dfixed_const(max));
12810288eeaSThierry Reding 
12910288eeaSThierry Reding 	return dda_inc;
13010288eeaSThierry Reding }
13110288eeaSThierry Reding 
13210288eeaSThierry Reding static inline u32 compute_initial_dda(unsigned int in)
13310288eeaSThierry Reding {
13410288eeaSThierry Reding 	fixed20_12 inf = dfixed_init(in);
13510288eeaSThierry Reding 	return dfixed_frac(inf);
13610288eeaSThierry Reding }
13710288eeaSThierry Reding 
13810288eeaSThierry Reding static int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
13910288eeaSThierry Reding 				 const struct tegra_dc_window *window)
14010288eeaSThierry Reding {
14110288eeaSThierry Reding 	unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp;
14210288eeaSThierry Reding 	unsigned long value;
14310288eeaSThierry Reding 	bool yuv, planar;
14410288eeaSThierry Reding 
14510288eeaSThierry Reding 	/*
14610288eeaSThierry Reding 	 * For YUV planar modes, the number of bytes per pixel takes into
14710288eeaSThierry Reding 	 * account only the luma component and therefore is 1.
14810288eeaSThierry Reding 	 */
14910288eeaSThierry Reding 	yuv = tegra_dc_format_is_yuv(window->format, &planar);
15010288eeaSThierry Reding 	if (!yuv)
15110288eeaSThierry Reding 		bpp = window->bits_per_pixel / 8;
15210288eeaSThierry Reding 	else
15310288eeaSThierry Reding 		bpp = planar ? 1 : 2;
15410288eeaSThierry Reding 
15510288eeaSThierry Reding 	value = WINDOW_A_SELECT << index;
15610288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
15710288eeaSThierry Reding 
15810288eeaSThierry Reding 	tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH);
15910288eeaSThierry Reding 	tegra_dc_writel(dc, window->swap, DC_WIN_BYTE_SWAP);
16010288eeaSThierry Reding 
16110288eeaSThierry Reding 	value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x);
16210288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_POSITION);
16310288eeaSThierry Reding 
16410288eeaSThierry Reding 	value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w);
16510288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_SIZE);
16610288eeaSThierry Reding 
16710288eeaSThierry Reding 	h_offset = window->src.x * bpp;
16810288eeaSThierry Reding 	v_offset = window->src.y;
16910288eeaSThierry Reding 	h_size = window->src.w * bpp;
17010288eeaSThierry Reding 	v_size = window->src.h;
17110288eeaSThierry Reding 
17210288eeaSThierry Reding 	value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size);
17310288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE);
17410288eeaSThierry Reding 
17510288eeaSThierry Reding 	/*
17610288eeaSThierry Reding 	 * For DDA computations the number of bytes per pixel for YUV planar
17710288eeaSThierry Reding 	 * modes needs to take into account all Y, U and V components.
17810288eeaSThierry Reding 	 */
17910288eeaSThierry Reding 	if (yuv && planar)
18010288eeaSThierry Reding 		bpp = 2;
18110288eeaSThierry Reding 
18210288eeaSThierry Reding 	h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp);
18310288eeaSThierry Reding 	v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp);
18410288eeaSThierry Reding 
18510288eeaSThierry Reding 	value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda);
18610288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_DDA_INC);
18710288eeaSThierry Reding 
18810288eeaSThierry Reding 	h_dda = compute_initial_dda(window->src.x);
18910288eeaSThierry Reding 	v_dda = compute_initial_dda(window->src.y);
19010288eeaSThierry Reding 
19110288eeaSThierry Reding 	tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA);
19210288eeaSThierry Reding 	tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA);
19310288eeaSThierry Reding 
19410288eeaSThierry Reding 	tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE);
19510288eeaSThierry Reding 	tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE);
19610288eeaSThierry Reding 
19710288eeaSThierry Reding 	tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR);
19810288eeaSThierry Reding 
19910288eeaSThierry Reding 	if (yuv && planar) {
20010288eeaSThierry Reding 		tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U);
20110288eeaSThierry Reding 		tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V);
20210288eeaSThierry Reding 		value = window->stride[1] << 16 | window->stride[0];
20310288eeaSThierry Reding 		tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE);
20410288eeaSThierry Reding 	} else {
20510288eeaSThierry Reding 		tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE);
20610288eeaSThierry Reding 	}
20710288eeaSThierry Reding 
20810288eeaSThierry Reding 	if (window->bottom_up)
20910288eeaSThierry Reding 		v_offset += window->src.h - 1;
21010288eeaSThierry Reding 
21110288eeaSThierry Reding 	tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET);
21210288eeaSThierry Reding 	tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET);
21310288eeaSThierry Reding 
21410288eeaSThierry Reding 	if (window->tiled) {
21510288eeaSThierry Reding 		value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV |
21610288eeaSThierry Reding 			DC_WIN_BUFFER_ADDR_MODE_TILE;
21710288eeaSThierry Reding 	} else {
21810288eeaSThierry Reding 		value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV |
21910288eeaSThierry Reding 			DC_WIN_BUFFER_ADDR_MODE_LINEAR;
22010288eeaSThierry Reding 	}
22110288eeaSThierry Reding 
22210288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE);
22310288eeaSThierry Reding 
22410288eeaSThierry Reding 	value = WIN_ENABLE;
22510288eeaSThierry Reding 
22610288eeaSThierry Reding 	if (yuv) {
22710288eeaSThierry Reding 		/* setup default colorspace conversion coefficients */
22810288eeaSThierry Reding 		tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF);
22910288eeaSThierry Reding 		tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB);
23010288eeaSThierry Reding 		tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR);
23110288eeaSThierry Reding 		tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR);
23210288eeaSThierry Reding 		tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG);
23310288eeaSThierry Reding 		tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG);
23410288eeaSThierry Reding 		tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB);
23510288eeaSThierry Reding 		tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB);
23610288eeaSThierry Reding 
23710288eeaSThierry Reding 		value |= CSC_ENABLE;
23810288eeaSThierry Reding 	} else if (window->bits_per_pixel < 24) {
23910288eeaSThierry Reding 		value |= COLOR_EXPAND;
24010288eeaSThierry Reding 	}
24110288eeaSThierry Reding 
24210288eeaSThierry Reding 	if (window->bottom_up)
24310288eeaSThierry Reding 		value |= V_DIRECTION;
24410288eeaSThierry Reding 
24510288eeaSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
24610288eeaSThierry Reding 
24710288eeaSThierry Reding 	/*
24810288eeaSThierry Reding 	 * Disable blending and assume Window A is the bottom-most window,
24910288eeaSThierry Reding 	 * Window C is the top-most window and Window B is in the middle.
25010288eeaSThierry Reding 	 */
25110288eeaSThierry Reding 	tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY);
25210288eeaSThierry Reding 	tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN);
25310288eeaSThierry Reding 
25410288eeaSThierry Reding 	switch (index) {
25510288eeaSThierry Reding 	case 0:
25610288eeaSThierry Reding 		tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X);
25710288eeaSThierry Reding 		tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
25810288eeaSThierry Reding 		tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
25910288eeaSThierry Reding 		break;
26010288eeaSThierry Reding 
26110288eeaSThierry Reding 	case 1:
26210288eeaSThierry Reding 		tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
26310288eeaSThierry Reding 		tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
26410288eeaSThierry Reding 		tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
26510288eeaSThierry Reding 		break;
26610288eeaSThierry Reding 
26710288eeaSThierry Reding 	case 2:
26810288eeaSThierry Reding 		tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
26910288eeaSThierry Reding 		tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y);
27010288eeaSThierry Reding 		tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY);
27110288eeaSThierry Reding 		break;
27210288eeaSThierry Reding 	}
27310288eeaSThierry Reding 
27410288eeaSThierry Reding 	tegra_dc_writel(dc, WIN_A_UPDATE << index, DC_CMD_STATE_CONTROL);
27510288eeaSThierry Reding 	tegra_dc_writel(dc, WIN_A_ACT_REQ << index, DC_CMD_STATE_CONTROL);
27610288eeaSThierry Reding 
27710288eeaSThierry Reding 	return 0;
27810288eeaSThierry Reding }
27910288eeaSThierry Reding 
280dee8268fSThierry Reding static int tegra_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
281dee8268fSThierry Reding 			      struct drm_framebuffer *fb, int crtc_x,
282dee8268fSThierry Reding 			      int crtc_y, unsigned int crtc_w,
283dee8268fSThierry Reding 			      unsigned int crtc_h, uint32_t src_x,
284dee8268fSThierry Reding 			      uint32_t src_y, uint32_t src_w, uint32_t src_h)
285dee8268fSThierry Reding {
286dee8268fSThierry Reding 	struct tegra_plane *p = to_tegra_plane(plane);
287dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
288dee8268fSThierry Reding 	struct tegra_dc_window window;
289dee8268fSThierry Reding 	unsigned int i;
290dee8268fSThierry Reding 
291dee8268fSThierry Reding 	memset(&window, 0, sizeof(window));
292dee8268fSThierry Reding 	window.src.x = src_x >> 16;
293dee8268fSThierry Reding 	window.src.y = src_y >> 16;
294dee8268fSThierry Reding 	window.src.w = src_w >> 16;
295dee8268fSThierry Reding 	window.src.h = src_h >> 16;
296dee8268fSThierry Reding 	window.dst.x = crtc_x;
297dee8268fSThierry Reding 	window.dst.y = crtc_y;
298dee8268fSThierry Reding 	window.dst.w = crtc_w;
299dee8268fSThierry Reding 	window.dst.h = crtc_h;
300f925390eSThierry Reding 	window.format = tegra_dc_format(fb->pixel_format, &window.swap);
301dee8268fSThierry Reding 	window.bits_per_pixel = fb->bits_per_pixel;
302db7fbdfdSThierry Reding 	window.bottom_up = tegra_fb_is_bottom_up(fb);
303773af77fSThierry Reding 	window.tiled = tegra_fb_is_tiled(fb);
304dee8268fSThierry Reding 
305dee8268fSThierry Reding 	for (i = 0; i < drm_format_num_planes(fb->pixel_format); i++) {
306dee8268fSThierry Reding 		struct tegra_bo *bo = tegra_fb_get_plane(fb, i);
307dee8268fSThierry Reding 
308dee8268fSThierry Reding 		window.base[i] = bo->paddr + fb->offsets[i];
309dee8268fSThierry Reding 
310dee8268fSThierry Reding 		/*
311dee8268fSThierry Reding 		 * Tegra doesn't support different strides for U and V planes
312dee8268fSThierry Reding 		 * so we display a warning if the user tries to display a
313dee8268fSThierry Reding 		 * framebuffer with such a configuration.
314dee8268fSThierry Reding 		 */
315dee8268fSThierry Reding 		if (i >= 2) {
316dee8268fSThierry Reding 			if (fb->pitches[i] != window.stride[1])
317dee8268fSThierry Reding 				DRM_ERROR("unsupported UV-plane configuration\n");
318dee8268fSThierry Reding 		} else {
319dee8268fSThierry Reding 			window.stride[i] = fb->pitches[i];
320dee8268fSThierry Reding 		}
321dee8268fSThierry Reding 	}
322dee8268fSThierry Reding 
323dee8268fSThierry Reding 	return tegra_dc_setup_window(dc, p->index, &window);
324dee8268fSThierry Reding }
325dee8268fSThierry Reding 
326dee8268fSThierry Reding static int tegra_plane_disable(struct drm_plane *plane)
327dee8268fSThierry Reding {
328dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(plane->crtc);
329dee8268fSThierry Reding 	struct tegra_plane *p = to_tegra_plane(plane);
330dee8268fSThierry Reding 	unsigned long value;
331dee8268fSThierry Reding 
332dee8268fSThierry Reding 	if (!plane->crtc)
333dee8268fSThierry Reding 		return 0;
334dee8268fSThierry Reding 
335dee8268fSThierry Reding 	value = WINDOW_A_SELECT << p->index;
336dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
337dee8268fSThierry Reding 
338dee8268fSThierry Reding 	value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS);
339dee8268fSThierry Reding 	value &= ~WIN_ENABLE;
340dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
341dee8268fSThierry Reding 
342dee8268fSThierry Reding 	tegra_dc_writel(dc, WIN_A_UPDATE << p->index, DC_CMD_STATE_CONTROL);
343dee8268fSThierry Reding 	tegra_dc_writel(dc, WIN_A_ACT_REQ << p->index, DC_CMD_STATE_CONTROL);
344dee8268fSThierry Reding 
345dee8268fSThierry Reding 	return 0;
346dee8268fSThierry Reding }
347dee8268fSThierry Reding 
348dee8268fSThierry Reding static void tegra_plane_destroy(struct drm_plane *plane)
349dee8268fSThierry Reding {
350f002abc1SThierry Reding 	struct tegra_plane *p = to_tegra_plane(plane);
351f002abc1SThierry Reding 
352dee8268fSThierry Reding 	tegra_plane_disable(plane);
353dee8268fSThierry Reding 	drm_plane_cleanup(plane);
354f002abc1SThierry Reding 	kfree(p);
355dee8268fSThierry Reding }
356dee8268fSThierry Reding 
357dee8268fSThierry Reding static const struct drm_plane_funcs tegra_plane_funcs = {
358dee8268fSThierry Reding 	.update_plane = tegra_plane_update,
359dee8268fSThierry Reding 	.disable_plane = tegra_plane_disable,
360dee8268fSThierry Reding 	.destroy = tegra_plane_destroy,
361dee8268fSThierry Reding };
362dee8268fSThierry Reding 
363dee8268fSThierry Reding static const uint32_t plane_formats[] = {
364dee8268fSThierry Reding 	DRM_FORMAT_XBGR8888,
365dee8268fSThierry Reding 	DRM_FORMAT_XRGB8888,
366dee8268fSThierry Reding 	DRM_FORMAT_RGB565,
367dee8268fSThierry Reding 	DRM_FORMAT_UYVY,
368f925390eSThierry Reding 	DRM_FORMAT_YUYV,
369dee8268fSThierry Reding 	DRM_FORMAT_YUV420,
370dee8268fSThierry Reding 	DRM_FORMAT_YUV422,
371dee8268fSThierry Reding };
372dee8268fSThierry Reding 
373dee8268fSThierry Reding static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc)
374dee8268fSThierry Reding {
375dee8268fSThierry Reding 	unsigned int i;
376dee8268fSThierry Reding 	int err = 0;
377dee8268fSThierry Reding 
378dee8268fSThierry Reding 	for (i = 0; i < 2; i++) {
379dee8268fSThierry Reding 		struct tegra_plane *plane;
380dee8268fSThierry Reding 
381f002abc1SThierry Reding 		plane = kzalloc(sizeof(*plane), GFP_KERNEL);
382dee8268fSThierry Reding 		if (!plane)
383dee8268fSThierry Reding 			return -ENOMEM;
384dee8268fSThierry Reding 
385dee8268fSThierry Reding 		plane->index = 1 + i;
386dee8268fSThierry Reding 
387dee8268fSThierry Reding 		err = drm_plane_init(drm, &plane->base, 1 << dc->pipe,
388dee8268fSThierry Reding 				     &tegra_plane_funcs, plane_formats,
389dee8268fSThierry Reding 				     ARRAY_SIZE(plane_formats), false);
390f002abc1SThierry Reding 		if (err < 0) {
391f002abc1SThierry Reding 			kfree(plane);
392dee8268fSThierry Reding 			return err;
393dee8268fSThierry Reding 		}
394f002abc1SThierry Reding 	}
395dee8268fSThierry Reding 
396dee8268fSThierry Reding 	return 0;
397dee8268fSThierry Reding }
398dee8268fSThierry Reding 
399dee8268fSThierry Reding static int tegra_dc_set_base(struct tegra_dc *dc, int x, int y,
400dee8268fSThierry Reding 			     struct drm_framebuffer *fb)
401dee8268fSThierry Reding {
402dee8268fSThierry Reding 	struct tegra_bo *bo = tegra_fb_get_plane(fb, 0);
403db7fbdfdSThierry Reding 	unsigned int h_offset = 0, v_offset = 0;
404f925390eSThierry Reding 	unsigned int format, swap;
405dee8268fSThierry Reding 	unsigned long value;
406dee8268fSThierry Reding 
407dee8268fSThierry Reding 	tegra_dc_writel(dc, WINDOW_A_SELECT, DC_CMD_DISPLAY_WINDOW_HEADER);
408dee8268fSThierry Reding 
409dee8268fSThierry Reding 	value = fb->offsets[0] + y * fb->pitches[0] +
410dee8268fSThierry Reding 		x * fb->bits_per_pixel / 8;
411dee8268fSThierry Reding 
412dee8268fSThierry Reding 	tegra_dc_writel(dc, bo->paddr + value, DC_WINBUF_START_ADDR);
413dee8268fSThierry Reding 	tegra_dc_writel(dc, fb->pitches[0], DC_WIN_LINE_STRIDE);
414f925390eSThierry Reding 
415f925390eSThierry Reding 	format = tegra_dc_format(fb->pixel_format, &swap);
416dee8268fSThierry Reding 	tegra_dc_writel(dc, format, DC_WIN_COLOR_DEPTH);
417f925390eSThierry Reding 	tegra_dc_writel(dc, swap, DC_WIN_BYTE_SWAP);
418dee8268fSThierry Reding 
419773af77fSThierry Reding 	if (tegra_fb_is_tiled(fb)) {
420773af77fSThierry Reding 		value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV |
421773af77fSThierry Reding 			DC_WIN_BUFFER_ADDR_MODE_TILE;
422773af77fSThierry Reding 	} else {
423773af77fSThierry Reding 		value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV |
424773af77fSThierry Reding 			DC_WIN_BUFFER_ADDR_MODE_LINEAR;
425773af77fSThierry Reding 	}
426773af77fSThierry Reding 
427773af77fSThierry Reding 	tegra_dc_writel(dc, value, DC_WIN_BUFFER_ADDR_MODE);
428773af77fSThierry Reding 
429db7fbdfdSThierry Reding 	/* make sure bottom-up buffers are properly displayed */
430db7fbdfdSThierry Reding 	if (tegra_fb_is_bottom_up(fb)) {
431db7fbdfdSThierry Reding 		value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS);
432eba66501SThierry Reding 		value |= V_DIRECTION;
433db7fbdfdSThierry Reding 		tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
434db7fbdfdSThierry Reding 
435db7fbdfdSThierry Reding 		v_offset += fb->height - 1;
436db7fbdfdSThierry Reding 	} else {
437db7fbdfdSThierry Reding 		value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS);
438eba66501SThierry Reding 		value &= ~V_DIRECTION;
439db7fbdfdSThierry Reding 		tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
440db7fbdfdSThierry Reding 	}
441db7fbdfdSThierry Reding 
442db7fbdfdSThierry Reding 	tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET);
443db7fbdfdSThierry Reding 	tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET);
444db7fbdfdSThierry Reding 
445dee8268fSThierry Reding 	value = GENERAL_UPDATE | WIN_A_UPDATE;
446dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
447dee8268fSThierry Reding 
448dee8268fSThierry Reding 	value = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
449dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
450dee8268fSThierry Reding 
451dee8268fSThierry Reding 	return 0;
452dee8268fSThierry Reding }
453dee8268fSThierry Reding 
454dee8268fSThierry Reding void tegra_dc_enable_vblank(struct tegra_dc *dc)
455dee8268fSThierry Reding {
456dee8268fSThierry Reding 	unsigned long value, flags;
457dee8268fSThierry Reding 
458dee8268fSThierry Reding 	spin_lock_irqsave(&dc->lock, flags);
459dee8268fSThierry Reding 
460dee8268fSThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
461dee8268fSThierry Reding 	value |= VBLANK_INT;
462dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
463dee8268fSThierry Reding 
464dee8268fSThierry Reding 	spin_unlock_irqrestore(&dc->lock, flags);
465dee8268fSThierry Reding }
466dee8268fSThierry Reding 
467dee8268fSThierry Reding void tegra_dc_disable_vblank(struct tegra_dc *dc)
468dee8268fSThierry Reding {
469dee8268fSThierry Reding 	unsigned long value, flags;
470dee8268fSThierry Reding 
471dee8268fSThierry Reding 	spin_lock_irqsave(&dc->lock, flags);
472dee8268fSThierry Reding 
473dee8268fSThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
474dee8268fSThierry Reding 	value &= ~VBLANK_INT;
475dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
476dee8268fSThierry Reding 
477dee8268fSThierry Reding 	spin_unlock_irqrestore(&dc->lock, flags);
478dee8268fSThierry Reding }
479dee8268fSThierry Reding 
480dee8268fSThierry Reding static void tegra_dc_finish_page_flip(struct tegra_dc *dc)
481dee8268fSThierry Reding {
482dee8268fSThierry Reding 	struct drm_device *drm = dc->base.dev;
483dee8268fSThierry Reding 	struct drm_crtc *crtc = &dc->base;
484dee8268fSThierry Reding 	unsigned long flags, base;
485dee8268fSThierry Reding 	struct tegra_bo *bo;
486dee8268fSThierry Reding 
487dee8268fSThierry Reding 	if (!dc->event)
488dee8268fSThierry Reding 		return;
489dee8268fSThierry Reding 
490f4510a27SMatt Roper 	bo = tegra_fb_get_plane(crtc->primary->fb, 0);
491dee8268fSThierry Reding 
492dee8268fSThierry Reding 	/* check if new start address has been latched */
493dee8268fSThierry Reding 	tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
494dee8268fSThierry Reding 	base = tegra_dc_readl(dc, DC_WINBUF_START_ADDR);
495dee8268fSThierry Reding 	tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
496dee8268fSThierry Reding 
497f4510a27SMatt Roper 	if (base == bo->paddr + crtc->primary->fb->offsets[0]) {
498dee8268fSThierry Reding 		spin_lock_irqsave(&drm->event_lock, flags);
499dee8268fSThierry Reding 		drm_send_vblank_event(drm, dc->pipe, dc->event);
500dee8268fSThierry Reding 		drm_vblank_put(drm, dc->pipe);
501dee8268fSThierry Reding 		dc->event = NULL;
502dee8268fSThierry Reding 		spin_unlock_irqrestore(&drm->event_lock, flags);
503dee8268fSThierry Reding 	}
504dee8268fSThierry Reding }
505dee8268fSThierry Reding 
506dee8268fSThierry Reding void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
507dee8268fSThierry Reding {
508dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
509dee8268fSThierry Reding 	struct drm_device *drm = crtc->dev;
510dee8268fSThierry Reding 	unsigned long flags;
511dee8268fSThierry Reding 
512dee8268fSThierry Reding 	spin_lock_irqsave(&drm->event_lock, flags);
513dee8268fSThierry Reding 
514dee8268fSThierry Reding 	if (dc->event && dc->event->base.file_priv == file) {
515dee8268fSThierry Reding 		dc->event->base.destroy(&dc->event->base);
516dee8268fSThierry Reding 		drm_vblank_put(drm, dc->pipe);
517dee8268fSThierry Reding 		dc->event = NULL;
518dee8268fSThierry Reding 	}
519dee8268fSThierry Reding 
520dee8268fSThierry Reding 	spin_unlock_irqrestore(&drm->event_lock, flags);
521dee8268fSThierry Reding }
522dee8268fSThierry Reding 
523dee8268fSThierry Reding static int tegra_dc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
524dee8268fSThierry Reding 			      struct drm_pending_vblank_event *event, uint32_t page_flip_flags)
525dee8268fSThierry Reding {
526dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
527dee8268fSThierry Reding 	struct drm_device *drm = crtc->dev;
528dee8268fSThierry Reding 
529dee8268fSThierry Reding 	if (dc->event)
530dee8268fSThierry Reding 		return -EBUSY;
531dee8268fSThierry Reding 
532dee8268fSThierry Reding 	if (event) {
533dee8268fSThierry Reding 		event->pipe = dc->pipe;
534dee8268fSThierry Reding 		dc->event = event;
535dee8268fSThierry Reding 		drm_vblank_get(drm, dc->pipe);
536dee8268fSThierry Reding 	}
537dee8268fSThierry Reding 
538dee8268fSThierry Reding 	tegra_dc_set_base(dc, 0, 0, fb);
539f4510a27SMatt Roper 	crtc->primary->fb = fb;
540dee8268fSThierry Reding 
541dee8268fSThierry Reding 	return 0;
542dee8268fSThierry Reding }
543dee8268fSThierry Reding 
544f002abc1SThierry Reding static void drm_crtc_clear(struct drm_crtc *crtc)
545f002abc1SThierry Reding {
546f002abc1SThierry Reding 	memset(crtc, 0, sizeof(*crtc));
547f002abc1SThierry Reding }
548f002abc1SThierry Reding 
549f002abc1SThierry Reding static void tegra_dc_destroy(struct drm_crtc *crtc)
550f002abc1SThierry Reding {
551f002abc1SThierry Reding 	drm_crtc_cleanup(crtc);
552f002abc1SThierry Reding 	drm_crtc_clear(crtc);
553f002abc1SThierry Reding }
554f002abc1SThierry Reding 
555dee8268fSThierry Reding static const struct drm_crtc_funcs tegra_crtc_funcs = {
556dee8268fSThierry Reding 	.page_flip = tegra_dc_page_flip,
557dee8268fSThierry Reding 	.set_config = drm_crtc_helper_set_config,
558f002abc1SThierry Reding 	.destroy = tegra_dc_destroy,
559dee8268fSThierry Reding };
560dee8268fSThierry Reding 
561dee8268fSThierry Reding static void tegra_crtc_disable(struct drm_crtc *crtc)
562dee8268fSThierry Reding {
563f002abc1SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
564dee8268fSThierry Reding 	struct drm_device *drm = crtc->dev;
565dee8268fSThierry Reding 	struct drm_plane *plane;
566dee8268fSThierry Reding 
5672b4c3661SDaniel Vetter 	drm_for_each_legacy_plane(plane, &drm->mode_config.plane_list) {
568dee8268fSThierry Reding 		if (plane->crtc == crtc) {
569dee8268fSThierry Reding 			tegra_plane_disable(plane);
570dee8268fSThierry Reding 			plane->crtc = NULL;
571dee8268fSThierry Reding 
572dee8268fSThierry Reding 			if (plane->fb) {
573dee8268fSThierry Reding 				drm_framebuffer_unreference(plane->fb);
574dee8268fSThierry Reding 				plane->fb = NULL;
575dee8268fSThierry Reding 			}
576dee8268fSThierry Reding 		}
577dee8268fSThierry Reding 	}
578f002abc1SThierry Reding 
579f002abc1SThierry Reding 	drm_vblank_off(drm, dc->pipe);
580dee8268fSThierry Reding }
581dee8268fSThierry Reding 
582dee8268fSThierry Reding static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc,
583dee8268fSThierry Reding 				  const struct drm_display_mode *mode,
584dee8268fSThierry Reding 				  struct drm_display_mode *adjusted)
585dee8268fSThierry Reding {
586dee8268fSThierry Reding 	return true;
587dee8268fSThierry Reding }
588dee8268fSThierry Reding 
589dee8268fSThierry Reding static int tegra_dc_set_timings(struct tegra_dc *dc,
590dee8268fSThierry Reding 				struct drm_display_mode *mode)
591dee8268fSThierry Reding {
5920444c0ffSThierry Reding 	unsigned int h_ref_to_sync = 1;
5930444c0ffSThierry Reding 	unsigned int v_ref_to_sync = 1;
594dee8268fSThierry Reding 	unsigned long value;
595dee8268fSThierry Reding 
596dee8268fSThierry Reding 	tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS);
597dee8268fSThierry Reding 
598dee8268fSThierry Reding 	value = (v_ref_to_sync << 16) | h_ref_to_sync;
599dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC);
600dee8268fSThierry Reding 
601dee8268fSThierry Reding 	value = ((mode->vsync_end - mode->vsync_start) << 16) |
602dee8268fSThierry Reding 		((mode->hsync_end - mode->hsync_start) <<  0);
603dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH);
604dee8268fSThierry Reding 
605dee8268fSThierry Reding 	value = ((mode->vtotal - mode->vsync_end) << 16) |
606dee8268fSThierry Reding 		((mode->htotal - mode->hsync_end) <<  0);
607dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH);
608dee8268fSThierry Reding 
609dee8268fSThierry Reding 	value = ((mode->vsync_start - mode->vdisplay) << 16) |
610dee8268fSThierry Reding 		((mode->hsync_start - mode->hdisplay) <<  0);
611dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH);
612dee8268fSThierry Reding 
613dee8268fSThierry Reding 	value = (mode->vdisplay << 16) | mode->hdisplay;
614dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_ACTIVE);
615dee8268fSThierry Reding 
616dee8268fSThierry Reding 	return 0;
617dee8268fSThierry Reding }
618dee8268fSThierry Reding 
619dee8268fSThierry Reding static int tegra_crtc_setup_clk(struct drm_crtc *crtc,
620*dbb3f2f7SThierry Reding 				struct drm_display_mode *mode)
621dee8268fSThierry Reding {
622dee8268fSThierry Reding 	unsigned long pclk = mode->clock * 1000, rate;
623dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
624dee8268fSThierry Reding 	struct tegra_output *output = NULL;
625dee8268fSThierry Reding 	struct drm_encoder *encoder;
626*dbb3f2f7SThierry Reding 	unsigned int div;
627*dbb3f2f7SThierry Reding 	u32 value;
628dee8268fSThierry Reding 	long err;
629dee8268fSThierry Reding 
630dee8268fSThierry Reding 	list_for_each_entry(encoder, &crtc->dev->mode_config.encoder_list, head)
631dee8268fSThierry Reding 		if (encoder->crtc == crtc) {
632dee8268fSThierry Reding 			output = encoder_to_output(encoder);
633dee8268fSThierry Reding 			break;
634dee8268fSThierry Reding 		}
635dee8268fSThierry Reding 
636dee8268fSThierry Reding 	if (!output)
637dee8268fSThierry Reding 		return -ENODEV;
638dee8268fSThierry Reding 
639dee8268fSThierry Reding 	/*
640dee8268fSThierry Reding 	 * This assumes that the display controller will divide its parent
641dee8268fSThierry Reding 	 * clock by 2 to generate the pixel clock.
642dee8268fSThierry Reding 	 */
643dee8268fSThierry Reding 	err = tegra_output_setup_clock(output, dc->clk, pclk * 2);
644dee8268fSThierry Reding 	if (err < 0) {
645dee8268fSThierry Reding 		dev_err(dc->dev, "failed to setup clock: %ld\n", err);
646dee8268fSThierry Reding 		return err;
647dee8268fSThierry Reding 	}
648dee8268fSThierry Reding 
649dee8268fSThierry Reding 	rate = clk_get_rate(dc->clk);
650*dbb3f2f7SThierry Reding 	div = (rate * 2 / pclk) - 2;
651dee8268fSThierry Reding 
652*dbb3f2f7SThierry Reding 	DRM_DEBUG_KMS("rate: %lu, div: %u\n", rate, div);
653*dbb3f2f7SThierry Reding 
654*dbb3f2f7SThierry Reding 	value = SHIFT_CLK_DIVIDER(div) | PIXEL_CLK_DIVIDER_PCD1;
655*dbb3f2f7SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL);
656dee8268fSThierry Reding 
657dee8268fSThierry Reding 	return 0;
658dee8268fSThierry Reding }
659dee8268fSThierry Reding 
660dee8268fSThierry Reding static int tegra_crtc_mode_set(struct drm_crtc *crtc,
661dee8268fSThierry Reding 			       struct drm_display_mode *mode,
662dee8268fSThierry Reding 			       struct drm_display_mode *adjusted,
663dee8268fSThierry Reding 			       int x, int y, struct drm_framebuffer *old_fb)
664dee8268fSThierry Reding {
665f4510a27SMatt Roper 	struct tegra_bo *bo = tegra_fb_get_plane(crtc->primary->fb, 0);
666dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
667dee8268fSThierry Reding 	struct tegra_dc_window window;
668*dbb3f2f7SThierry Reding 	u32 value;
669dee8268fSThierry Reding 	int err;
670dee8268fSThierry Reding 
671dee8268fSThierry Reding 	drm_vblank_pre_modeset(crtc->dev, dc->pipe);
672dee8268fSThierry Reding 
673*dbb3f2f7SThierry Reding 	err = tegra_crtc_setup_clk(crtc, mode);
674dee8268fSThierry Reding 	if (err) {
675dee8268fSThierry Reding 		dev_err(dc->dev, "failed to setup clock for CRTC: %d\n", err);
676dee8268fSThierry Reding 		return err;
677dee8268fSThierry Reding 	}
678dee8268fSThierry Reding 
679dee8268fSThierry Reding 	/* program display mode */
680dee8268fSThierry Reding 	tegra_dc_set_timings(dc, mode);
681dee8268fSThierry Reding 
6828620fc62SThierry Reding 	/* interlacing isn't supported yet, so disable it */
6838620fc62SThierry Reding 	if (dc->soc->supports_interlacing) {
6848620fc62SThierry Reding 		value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL);
6858620fc62SThierry Reding 		value &= ~INTERLACE_ENABLE;
6868620fc62SThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL);
6878620fc62SThierry Reding 	}
6888620fc62SThierry Reding 
689dee8268fSThierry Reding 	/* setup window parameters */
690dee8268fSThierry Reding 	memset(&window, 0, sizeof(window));
691dee8268fSThierry Reding 	window.src.x = 0;
692dee8268fSThierry Reding 	window.src.y = 0;
693dee8268fSThierry Reding 	window.src.w = mode->hdisplay;
694dee8268fSThierry Reding 	window.src.h = mode->vdisplay;
695dee8268fSThierry Reding 	window.dst.x = 0;
696dee8268fSThierry Reding 	window.dst.y = 0;
697dee8268fSThierry Reding 	window.dst.w = mode->hdisplay;
698dee8268fSThierry Reding 	window.dst.h = mode->vdisplay;
699f925390eSThierry Reding 	window.format = tegra_dc_format(crtc->primary->fb->pixel_format,
700f925390eSThierry Reding 					&window.swap);
701f4510a27SMatt Roper 	window.bits_per_pixel = crtc->primary->fb->bits_per_pixel;
702f4510a27SMatt Roper 	window.stride[0] = crtc->primary->fb->pitches[0];
703dee8268fSThierry Reding 	window.base[0] = bo->paddr;
704dee8268fSThierry Reding 
705dee8268fSThierry Reding 	err = tegra_dc_setup_window(dc, 0, &window);
706dee8268fSThierry Reding 	if (err < 0)
707dee8268fSThierry Reding 		dev_err(dc->dev, "failed to enable root plane\n");
708dee8268fSThierry Reding 
709dee8268fSThierry Reding 	return 0;
710dee8268fSThierry Reding }
711dee8268fSThierry Reding 
712dee8268fSThierry Reding static int tegra_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
713dee8268fSThierry Reding 				    struct drm_framebuffer *old_fb)
714dee8268fSThierry Reding {
715dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
716dee8268fSThierry Reding 
717f4510a27SMatt Roper 	return tegra_dc_set_base(dc, x, y, crtc->primary->fb);
718dee8268fSThierry Reding }
719dee8268fSThierry Reding 
720dee8268fSThierry Reding static void tegra_crtc_prepare(struct drm_crtc *crtc)
721dee8268fSThierry Reding {
722dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
723dee8268fSThierry Reding 	unsigned int syncpt;
724dee8268fSThierry Reding 	unsigned long value;
725dee8268fSThierry Reding 
726dee8268fSThierry Reding 	/* hardware initialization */
727ca48080aSStephen Warren 	reset_control_deassert(dc->rst);
728dee8268fSThierry Reding 	usleep_range(10000, 20000);
729dee8268fSThierry Reding 
730dee8268fSThierry Reding 	if (dc->pipe)
731dee8268fSThierry Reding 		syncpt = SYNCPT_VBLANK1;
732dee8268fSThierry Reding 	else
733dee8268fSThierry Reding 		syncpt = SYNCPT_VBLANK0;
734dee8268fSThierry Reding 
735dee8268fSThierry Reding 	/* initialize display controller */
736dee8268fSThierry Reding 	tegra_dc_writel(dc, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
737dee8268fSThierry Reding 	tegra_dc_writel(dc, 0x100 | syncpt, DC_CMD_CONT_SYNCPT_VSYNC);
738dee8268fSThierry Reding 
739dee8268fSThierry Reding 	value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | WIN_A_OF_INT;
740dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_TYPE);
741dee8268fSThierry Reding 
742dee8268fSThierry Reding 	value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
743dee8268fSThierry Reding 		WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
744dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY);
745dee8268fSThierry Reding 
746dee8268fSThierry Reding 	/* initialize timer */
747dee8268fSThierry Reding 	value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) |
748dee8268fSThierry Reding 		WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20);
749dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY);
750dee8268fSThierry Reding 
751dee8268fSThierry Reding 	value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) |
752dee8268fSThierry Reding 		WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1);
753dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
754dee8268fSThierry Reding 
755dee8268fSThierry Reding 	value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
756dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
757dee8268fSThierry Reding 
758dee8268fSThierry Reding 	value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
759dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
760dee8268fSThierry Reding }
761dee8268fSThierry Reding 
762dee8268fSThierry Reding static void tegra_crtc_commit(struct drm_crtc *crtc)
763dee8268fSThierry Reding {
764dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
765dee8268fSThierry Reding 	unsigned long value;
766dee8268fSThierry Reding 
767dee8268fSThierry Reding 	value = GENERAL_UPDATE | WIN_A_UPDATE;
768dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
769dee8268fSThierry Reding 
770dee8268fSThierry Reding 	value = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
771dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
772dee8268fSThierry Reding 
773dee8268fSThierry Reding 	drm_vblank_post_modeset(crtc->dev, dc->pipe);
774dee8268fSThierry Reding }
775dee8268fSThierry Reding 
776dee8268fSThierry Reding static void tegra_crtc_load_lut(struct drm_crtc *crtc)
777dee8268fSThierry Reding {
778dee8268fSThierry Reding }
779dee8268fSThierry Reding 
780dee8268fSThierry Reding static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = {
781dee8268fSThierry Reding 	.disable = tegra_crtc_disable,
782dee8268fSThierry Reding 	.mode_fixup = tegra_crtc_mode_fixup,
783dee8268fSThierry Reding 	.mode_set = tegra_crtc_mode_set,
784dee8268fSThierry Reding 	.mode_set_base = tegra_crtc_mode_set_base,
785dee8268fSThierry Reding 	.prepare = tegra_crtc_prepare,
786dee8268fSThierry Reding 	.commit = tegra_crtc_commit,
787dee8268fSThierry Reding 	.load_lut = tegra_crtc_load_lut,
788dee8268fSThierry Reding };
789dee8268fSThierry Reding 
790dee8268fSThierry Reding static irqreturn_t tegra_dc_irq(int irq, void *data)
791dee8268fSThierry Reding {
792dee8268fSThierry Reding 	struct tegra_dc *dc = data;
793dee8268fSThierry Reding 	unsigned long status;
794dee8268fSThierry Reding 
795dee8268fSThierry Reding 	status = tegra_dc_readl(dc, DC_CMD_INT_STATUS);
796dee8268fSThierry Reding 	tegra_dc_writel(dc, status, DC_CMD_INT_STATUS);
797dee8268fSThierry Reding 
798dee8268fSThierry Reding 	if (status & FRAME_END_INT) {
799dee8268fSThierry Reding 		/*
800dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): frame end\n", __func__);
801dee8268fSThierry Reding 		*/
802dee8268fSThierry Reding 	}
803dee8268fSThierry Reding 
804dee8268fSThierry Reding 	if (status & VBLANK_INT) {
805dee8268fSThierry Reding 		/*
806dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): vertical blank\n", __func__);
807dee8268fSThierry Reding 		*/
808dee8268fSThierry Reding 		drm_handle_vblank(dc->base.dev, dc->pipe);
809dee8268fSThierry Reding 		tegra_dc_finish_page_flip(dc);
810dee8268fSThierry Reding 	}
811dee8268fSThierry Reding 
812dee8268fSThierry Reding 	if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) {
813dee8268fSThierry Reding 		/*
814dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): underflow\n", __func__);
815dee8268fSThierry Reding 		*/
816dee8268fSThierry Reding 	}
817dee8268fSThierry Reding 
818dee8268fSThierry Reding 	return IRQ_HANDLED;
819dee8268fSThierry Reding }
820dee8268fSThierry Reding 
821dee8268fSThierry Reding static int tegra_dc_show_regs(struct seq_file *s, void *data)
822dee8268fSThierry Reding {
823dee8268fSThierry Reding 	struct drm_info_node *node = s->private;
824dee8268fSThierry Reding 	struct tegra_dc *dc = node->info_ent->data;
825dee8268fSThierry Reding 
826dee8268fSThierry Reding #define DUMP_REG(name)						\
827dee8268fSThierry Reding 	seq_printf(s, "%-40s %#05x %08lx\n", #name, name,	\
828dee8268fSThierry Reding 		   tegra_dc_readl(dc, name))
829dee8268fSThierry Reding 
830dee8268fSThierry Reding 	DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT);
831dee8268fSThierry Reding 	DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
832dee8268fSThierry Reding 	DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR);
833dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT);
834dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL);
835dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR);
836dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT);
837dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL);
838dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR);
839dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT);
840dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL);
841dee8268fSThierry Reding 	DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR);
842dee8268fSThierry Reding 	DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC);
843dee8268fSThierry Reding 	DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0);
844dee8268fSThierry Reding 	DUMP_REG(DC_CMD_DISPLAY_COMMAND);
845dee8268fSThierry Reding 	DUMP_REG(DC_CMD_SIGNAL_RAISE);
846dee8268fSThierry Reding 	DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL);
847dee8268fSThierry Reding 	DUMP_REG(DC_CMD_INT_STATUS);
848dee8268fSThierry Reding 	DUMP_REG(DC_CMD_INT_MASK);
849dee8268fSThierry Reding 	DUMP_REG(DC_CMD_INT_ENABLE);
850dee8268fSThierry Reding 	DUMP_REG(DC_CMD_INT_TYPE);
851dee8268fSThierry Reding 	DUMP_REG(DC_CMD_INT_POLARITY);
852dee8268fSThierry Reding 	DUMP_REG(DC_CMD_SIGNAL_RAISE1);
853dee8268fSThierry Reding 	DUMP_REG(DC_CMD_SIGNAL_RAISE2);
854dee8268fSThierry Reding 	DUMP_REG(DC_CMD_SIGNAL_RAISE3);
855dee8268fSThierry Reding 	DUMP_REG(DC_CMD_STATE_ACCESS);
856dee8268fSThierry Reding 	DUMP_REG(DC_CMD_STATE_CONTROL);
857dee8268fSThierry Reding 	DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER);
858dee8268fSThierry Reding 	DUMP_REG(DC_CMD_REG_ACT_CONTROL);
859dee8268fSThierry Reding 	DUMP_REG(DC_COM_CRC_CONTROL);
860dee8268fSThierry Reding 	DUMP_REG(DC_COM_CRC_CHECKSUM);
861dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0));
862dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1));
863dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2));
864dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3));
865dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0));
866dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1));
867dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2));
868dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3));
869dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0));
870dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1));
871dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2));
872dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3));
873dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0));
874dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1));
875dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2));
876dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3));
877dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_DATA(0));
878dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_INPUT_DATA(1));
879dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0));
880dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1));
881dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2));
882dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3));
883dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4));
884dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5));
885dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6));
886dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_MISC_CONTROL);
887dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_PM0_CONTROL);
888dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE);
889dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_PM1_CONTROL);
890dee8268fSThierry Reding 	DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE);
891dee8268fSThierry Reding 	DUMP_REG(DC_COM_SPI_CONTROL);
892dee8268fSThierry Reding 	DUMP_REG(DC_COM_SPI_START_BYTE);
893dee8268fSThierry Reding 	DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB);
894dee8268fSThierry Reding 	DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD);
895dee8268fSThierry Reding 	DUMP_REG(DC_COM_HSPI_CS_DC);
896dee8268fSThierry Reding 	DUMP_REG(DC_COM_SCRATCH_REGISTER_A);
897dee8268fSThierry Reding 	DUMP_REG(DC_COM_SCRATCH_REGISTER_B);
898dee8268fSThierry Reding 	DUMP_REG(DC_COM_GPIO_CTRL);
899dee8268fSThierry Reding 	DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER);
900dee8268fSThierry Reding 	DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED);
901dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0);
902dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1);
903dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_WIN_OPTIONS);
904dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY);
905dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
906dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS);
907dee8268fSThierry Reding 	DUMP_REG(DC_DISP_REF_TO_SYNC);
908dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SYNC_WIDTH);
909dee8268fSThierry Reding 	DUMP_REG(DC_DISP_BACK_PORCH);
910dee8268fSThierry Reding 	DUMP_REG(DC_DISP_ACTIVE);
911dee8268fSThierry Reding 	DUMP_REG(DC_DISP_FRONT_PORCH);
912dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE0_CONTROL);
913dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE0_POSITION_A);
914dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE0_POSITION_B);
915dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE0_POSITION_C);
916dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE0_POSITION_D);
917dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE1_CONTROL);
918dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE1_POSITION_A);
919dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE1_POSITION_B);
920dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE1_POSITION_C);
921dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE1_POSITION_D);
922dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE2_CONTROL);
923dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE2_POSITION_A);
924dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE2_POSITION_B);
925dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE2_POSITION_C);
926dee8268fSThierry Reding 	DUMP_REG(DC_DISP_H_PULSE2_POSITION_D);
927dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE0_CONTROL);
928dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE0_POSITION_A);
929dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE0_POSITION_B);
930dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE0_POSITION_C);
931dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE1_CONTROL);
932dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE1_POSITION_A);
933dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE1_POSITION_B);
934dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE1_POSITION_C);
935dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE2_CONTROL);
936dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE2_POSITION_A);
937dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE3_CONTROL);
938dee8268fSThierry Reding 	DUMP_REG(DC_DISP_V_PULSE3_POSITION_A);
939dee8268fSThierry Reding 	DUMP_REG(DC_DISP_M0_CONTROL);
940dee8268fSThierry Reding 	DUMP_REG(DC_DISP_M1_CONTROL);
941dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DI_CONTROL);
942dee8268fSThierry Reding 	DUMP_REG(DC_DISP_PP_CONTROL);
943dee8268fSThierry Reding 	DUMP_REG(DC_DISP_PP_SELECT_A);
944dee8268fSThierry Reding 	DUMP_REG(DC_DISP_PP_SELECT_B);
945dee8268fSThierry Reding 	DUMP_REG(DC_DISP_PP_SELECT_C);
946dee8268fSThierry Reding 	DUMP_REG(DC_DISP_PP_SELECT_D);
947dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL);
948dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL);
949dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_COLOR_CONTROL);
950dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS);
951dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS);
952dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS);
953dee8268fSThierry Reding 	DUMP_REG(DC_DISP_LCD_SPI_OPTIONS);
954dee8268fSThierry Reding 	DUMP_REG(DC_DISP_BORDER_COLOR);
955dee8268fSThierry Reding 	DUMP_REG(DC_DISP_COLOR_KEY0_LOWER);
956dee8268fSThierry Reding 	DUMP_REG(DC_DISP_COLOR_KEY0_UPPER);
957dee8268fSThierry Reding 	DUMP_REG(DC_DISP_COLOR_KEY1_LOWER);
958dee8268fSThierry Reding 	DUMP_REG(DC_DISP_COLOR_KEY1_UPPER);
959dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_FOREGROUND);
960dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_BACKGROUND);
961dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_START_ADDR);
962dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS);
963dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_POSITION);
964dee8268fSThierry Reding 	DUMP_REG(DC_DISP_CURSOR_POSITION_NS);
965dee8268fSThierry Reding 	DUMP_REG(DC_DISP_INIT_SEQ_CONTROL);
966dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A);
967dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B);
968dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C);
969dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D);
970dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL);
971dee8268fSThierry Reding 	DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST);
972dee8268fSThierry Reding 	DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST);
973dee8268fSThierry Reding 	DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST);
974dee8268fSThierry Reding 	DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST);
975dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DAC_CRT_CTRL);
976dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DISP_MISC_CONTROL);
977dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_CONTROL);
978dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_CSC_COEFF);
979dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(0));
980dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(1));
981dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(2));
982dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(3));
983dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(4));
984dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(5));
985dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(6));
986dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(7));
987dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_LUT(8));
988dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_FLICKER_CONTROL);
989dee8268fSThierry Reding 	DUMP_REG(DC_DISP_DC_PIXEL_COUNT);
990dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(0));
991dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(1));
992dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(2));
993dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(3));
994dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(4));
995dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(5));
996dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(6));
997dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HISTOGRAM(7));
998dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_BL_TF(0));
999dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_BL_TF(1));
1000dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_BL_TF(2));
1001dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_BL_TF(3));
1002dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_BL_CONTROL);
1003dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_HW_K_VALUES);
1004dee8268fSThierry Reding 	DUMP_REG(DC_DISP_SD_MAN_K_VALUES);
1005dee8268fSThierry Reding 	DUMP_REG(DC_WIN_WIN_OPTIONS);
1006dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BYTE_SWAP);
1007dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BUFFER_CONTROL);
1008dee8268fSThierry Reding 	DUMP_REG(DC_WIN_COLOR_DEPTH);
1009dee8268fSThierry Reding 	DUMP_REG(DC_WIN_POSITION);
1010dee8268fSThierry Reding 	DUMP_REG(DC_WIN_SIZE);
1011dee8268fSThierry Reding 	DUMP_REG(DC_WIN_PRESCALED_SIZE);
1012dee8268fSThierry Reding 	DUMP_REG(DC_WIN_H_INITIAL_DDA);
1013dee8268fSThierry Reding 	DUMP_REG(DC_WIN_V_INITIAL_DDA);
1014dee8268fSThierry Reding 	DUMP_REG(DC_WIN_DDA_INC);
1015dee8268fSThierry Reding 	DUMP_REG(DC_WIN_LINE_STRIDE);
1016dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BUF_STRIDE);
1017dee8268fSThierry Reding 	DUMP_REG(DC_WIN_UV_BUF_STRIDE);
1018dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BUFFER_ADDR_MODE);
1019dee8268fSThierry Reding 	DUMP_REG(DC_WIN_DV_CONTROL);
1020dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BLEND_NOKEY);
1021dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BLEND_1WIN);
1022dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BLEND_2WIN_X);
1023dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BLEND_2WIN_Y);
1024dee8268fSThierry Reding 	DUMP_REG(DC_WIN_BLEND_3WIN_XY);
1025dee8268fSThierry Reding 	DUMP_REG(DC_WIN_HP_FETCH_CONTROL);
1026dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR);
1027dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR_NS);
1028dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR_U);
1029dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR_U_NS);
1030dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR_V);
1031dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_START_ADDR_V_NS);
1032dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_ADDR_H_OFFSET);
1033dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS);
1034dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_ADDR_V_OFFSET);
1035dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS);
1036dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_UFLOW_STATUS);
1037dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS);
1038dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS);
1039dee8268fSThierry Reding 	DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS);
1040dee8268fSThierry Reding 
1041dee8268fSThierry Reding #undef DUMP_REG
1042dee8268fSThierry Reding 
1043dee8268fSThierry Reding 	return 0;
1044dee8268fSThierry Reding }
1045dee8268fSThierry Reding 
1046dee8268fSThierry Reding static struct drm_info_list debugfs_files[] = {
1047dee8268fSThierry Reding 	{ "regs", tegra_dc_show_regs, 0, NULL },
1048dee8268fSThierry Reding };
1049dee8268fSThierry Reding 
1050dee8268fSThierry Reding static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
1051dee8268fSThierry Reding {
1052dee8268fSThierry Reding 	unsigned int i;
1053dee8268fSThierry Reding 	char *name;
1054dee8268fSThierry Reding 	int err;
1055dee8268fSThierry Reding 
1056dee8268fSThierry Reding 	name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe);
1057dee8268fSThierry Reding 	dc->debugfs = debugfs_create_dir(name, minor->debugfs_root);
1058dee8268fSThierry Reding 	kfree(name);
1059dee8268fSThierry Reding 
1060dee8268fSThierry Reding 	if (!dc->debugfs)
1061dee8268fSThierry Reding 		return -ENOMEM;
1062dee8268fSThierry Reding 
1063dee8268fSThierry Reding 	dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1064dee8268fSThierry Reding 				    GFP_KERNEL);
1065dee8268fSThierry Reding 	if (!dc->debugfs_files) {
1066dee8268fSThierry Reding 		err = -ENOMEM;
1067dee8268fSThierry Reding 		goto remove;
1068dee8268fSThierry Reding 	}
1069dee8268fSThierry Reding 
1070dee8268fSThierry Reding 	for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1071dee8268fSThierry Reding 		dc->debugfs_files[i].data = dc;
1072dee8268fSThierry Reding 
1073dee8268fSThierry Reding 	err = drm_debugfs_create_files(dc->debugfs_files,
1074dee8268fSThierry Reding 				       ARRAY_SIZE(debugfs_files),
1075dee8268fSThierry Reding 				       dc->debugfs, minor);
1076dee8268fSThierry Reding 	if (err < 0)
1077dee8268fSThierry Reding 		goto free;
1078dee8268fSThierry Reding 
1079dee8268fSThierry Reding 	dc->minor = minor;
1080dee8268fSThierry Reding 
1081dee8268fSThierry Reding 	return 0;
1082dee8268fSThierry Reding 
1083dee8268fSThierry Reding free:
1084dee8268fSThierry Reding 	kfree(dc->debugfs_files);
1085dee8268fSThierry Reding 	dc->debugfs_files = NULL;
1086dee8268fSThierry Reding remove:
1087dee8268fSThierry Reding 	debugfs_remove(dc->debugfs);
1088dee8268fSThierry Reding 	dc->debugfs = NULL;
1089dee8268fSThierry Reding 
1090dee8268fSThierry Reding 	return err;
1091dee8268fSThierry Reding }
1092dee8268fSThierry Reding 
1093dee8268fSThierry Reding static int tegra_dc_debugfs_exit(struct tegra_dc *dc)
1094dee8268fSThierry Reding {
1095dee8268fSThierry Reding 	drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files),
1096dee8268fSThierry Reding 				 dc->minor);
1097dee8268fSThierry Reding 	dc->minor = NULL;
1098dee8268fSThierry Reding 
1099dee8268fSThierry Reding 	kfree(dc->debugfs_files);
1100dee8268fSThierry Reding 	dc->debugfs_files = NULL;
1101dee8268fSThierry Reding 
1102dee8268fSThierry Reding 	debugfs_remove(dc->debugfs);
1103dee8268fSThierry Reding 	dc->debugfs = NULL;
1104dee8268fSThierry Reding 
1105dee8268fSThierry Reding 	return 0;
1106dee8268fSThierry Reding }
1107dee8268fSThierry Reding 
1108dee8268fSThierry Reding static int tegra_dc_init(struct host1x_client *client)
1109dee8268fSThierry Reding {
1110dee8268fSThierry Reding 	struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1111dee8268fSThierry Reding 	struct tegra_dc *dc = host1x_client_to_dc(client);
1112dee8268fSThierry Reding 	int err;
1113dee8268fSThierry Reding 
1114dee8268fSThierry Reding 	drm_crtc_init(tegra->drm, &dc->base, &tegra_crtc_funcs);
1115dee8268fSThierry Reding 	drm_mode_crtc_set_gamma_size(&dc->base, 256);
1116dee8268fSThierry Reding 	drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs);
1117dee8268fSThierry Reding 
1118dee8268fSThierry Reding 	err = tegra_dc_rgb_init(tegra->drm, dc);
1119dee8268fSThierry Reding 	if (err < 0 && err != -ENODEV) {
1120dee8268fSThierry Reding 		dev_err(dc->dev, "failed to initialize RGB output: %d\n", err);
1121dee8268fSThierry Reding 		return err;
1122dee8268fSThierry Reding 	}
1123dee8268fSThierry Reding 
1124dee8268fSThierry Reding 	err = tegra_dc_add_planes(tegra->drm, dc);
1125dee8268fSThierry Reding 	if (err < 0)
1126dee8268fSThierry Reding 		return err;
1127dee8268fSThierry Reding 
1128dee8268fSThierry Reding 	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1129dee8268fSThierry Reding 		err = tegra_dc_debugfs_init(dc, tegra->drm->primary);
1130dee8268fSThierry Reding 		if (err < 0)
1131dee8268fSThierry Reding 			dev_err(dc->dev, "debugfs setup failed: %d\n", err);
1132dee8268fSThierry Reding 	}
1133dee8268fSThierry Reding 
1134dee8268fSThierry Reding 	err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0,
1135dee8268fSThierry Reding 			       dev_name(dc->dev), dc);
1136dee8268fSThierry Reding 	if (err < 0) {
1137dee8268fSThierry Reding 		dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq,
1138dee8268fSThierry Reding 			err);
1139dee8268fSThierry Reding 		return err;
1140dee8268fSThierry Reding 	}
1141dee8268fSThierry Reding 
1142dee8268fSThierry Reding 	return 0;
1143dee8268fSThierry Reding }
1144dee8268fSThierry Reding 
1145dee8268fSThierry Reding static int tegra_dc_exit(struct host1x_client *client)
1146dee8268fSThierry Reding {
1147dee8268fSThierry Reding 	struct tegra_dc *dc = host1x_client_to_dc(client);
1148dee8268fSThierry Reding 	int err;
1149dee8268fSThierry Reding 
1150dee8268fSThierry Reding 	devm_free_irq(dc->dev, dc->irq, dc);
1151dee8268fSThierry Reding 
1152dee8268fSThierry Reding 	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1153dee8268fSThierry Reding 		err = tegra_dc_debugfs_exit(dc);
1154dee8268fSThierry Reding 		if (err < 0)
1155dee8268fSThierry Reding 			dev_err(dc->dev, "debugfs cleanup failed: %d\n", err);
1156dee8268fSThierry Reding 	}
1157dee8268fSThierry Reding 
1158dee8268fSThierry Reding 	err = tegra_dc_rgb_exit(dc);
1159dee8268fSThierry Reding 	if (err) {
1160dee8268fSThierry Reding 		dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err);
1161dee8268fSThierry Reding 		return err;
1162dee8268fSThierry Reding 	}
1163dee8268fSThierry Reding 
1164dee8268fSThierry Reding 	return 0;
1165dee8268fSThierry Reding }
1166dee8268fSThierry Reding 
1167dee8268fSThierry Reding static const struct host1x_client_ops dc_client_ops = {
1168dee8268fSThierry Reding 	.init = tegra_dc_init,
1169dee8268fSThierry Reding 	.exit = tegra_dc_exit,
1170dee8268fSThierry Reding };
1171dee8268fSThierry Reding 
11728620fc62SThierry Reding static const struct tegra_dc_soc_info tegra20_dc_soc_info = {
11738620fc62SThierry Reding 	.supports_interlacing = false,
11748620fc62SThierry Reding };
11758620fc62SThierry Reding 
11768620fc62SThierry Reding static const struct tegra_dc_soc_info tegra30_dc_soc_info = {
11778620fc62SThierry Reding 	.supports_interlacing = false,
11788620fc62SThierry Reding };
11798620fc62SThierry Reding 
11808620fc62SThierry Reding static const struct tegra_dc_soc_info tegra124_dc_soc_info = {
11818620fc62SThierry Reding 	.supports_interlacing = true,
11828620fc62SThierry Reding };
11838620fc62SThierry Reding 
11848620fc62SThierry Reding static const struct of_device_id tegra_dc_of_match[] = {
11858620fc62SThierry Reding 	{
11868620fc62SThierry Reding 		.compatible = "nvidia,tegra124-dc",
11878620fc62SThierry Reding 		.data = &tegra124_dc_soc_info,
11888620fc62SThierry Reding 	}, {
11898620fc62SThierry Reding 		.compatible = "nvidia,tegra30-dc",
11908620fc62SThierry Reding 		.data = &tegra30_dc_soc_info,
11918620fc62SThierry Reding 	}, {
11928620fc62SThierry Reding 		.compatible = "nvidia,tegra20-dc",
11938620fc62SThierry Reding 		.data = &tegra20_dc_soc_info,
11948620fc62SThierry Reding 	}, {
11958620fc62SThierry Reding 		/* sentinel */
11968620fc62SThierry Reding 	}
11978620fc62SThierry Reding };
11988620fc62SThierry Reding 
119913411dddSThierry Reding static int tegra_dc_parse_dt(struct tegra_dc *dc)
120013411dddSThierry Reding {
120113411dddSThierry Reding 	struct device_node *np;
120213411dddSThierry Reding 	u32 value = 0;
120313411dddSThierry Reding 	int err;
120413411dddSThierry Reding 
120513411dddSThierry Reding 	err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value);
120613411dddSThierry Reding 	if (err < 0) {
120713411dddSThierry Reding 		dev_err(dc->dev, "missing \"nvidia,head\" property\n");
120813411dddSThierry Reding 
120913411dddSThierry Reding 		/*
121013411dddSThierry Reding 		 * If the nvidia,head property isn't present, try to find the
121113411dddSThierry Reding 		 * correct head number by looking up the position of this
121213411dddSThierry Reding 		 * display controller's node within the device tree. Assuming
121313411dddSThierry Reding 		 * that the nodes are ordered properly in the DTS file and
121413411dddSThierry Reding 		 * that the translation into a flattened device tree blob
121513411dddSThierry Reding 		 * preserves that ordering this will actually yield the right
121613411dddSThierry Reding 		 * head number.
121713411dddSThierry Reding 		 *
121813411dddSThierry Reding 		 * If those assumptions don't hold, this will still work for
121913411dddSThierry Reding 		 * cases where only a single display controller is used.
122013411dddSThierry Reding 		 */
122113411dddSThierry Reding 		for_each_matching_node(np, tegra_dc_of_match) {
122213411dddSThierry Reding 			if (np == dc->dev->of_node)
122313411dddSThierry Reding 				break;
122413411dddSThierry Reding 
122513411dddSThierry Reding 			value++;
122613411dddSThierry Reding 		}
122713411dddSThierry Reding 	}
122813411dddSThierry Reding 
122913411dddSThierry Reding 	dc->pipe = value;
123013411dddSThierry Reding 
123113411dddSThierry Reding 	return 0;
123213411dddSThierry Reding }
123313411dddSThierry Reding 
1234dee8268fSThierry Reding static int tegra_dc_probe(struct platform_device *pdev)
1235dee8268fSThierry Reding {
12368620fc62SThierry Reding 	const struct of_device_id *id;
1237dee8268fSThierry Reding 	struct resource *regs;
1238dee8268fSThierry Reding 	struct tegra_dc *dc;
1239dee8268fSThierry Reding 	int err;
1240dee8268fSThierry Reding 
1241dee8268fSThierry Reding 	dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
1242dee8268fSThierry Reding 	if (!dc)
1243dee8268fSThierry Reding 		return -ENOMEM;
1244dee8268fSThierry Reding 
12458620fc62SThierry Reding 	id = of_match_node(tegra_dc_of_match, pdev->dev.of_node);
12468620fc62SThierry Reding 	if (!id)
12478620fc62SThierry Reding 		return -ENODEV;
12488620fc62SThierry Reding 
1249dee8268fSThierry Reding 	spin_lock_init(&dc->lock);
1250dee8268fSThierry Reding 	INIT_LIST_HEAD(&dc->list);
1251dee8268fSThierry Reding 	dc->dev = &pdev->dev;
12528620fc62SThierry Reding 	dc->soc = id->data;
1253dee8268fSThierry Reding 
125413411dddSThierry Reding 	err = tegra_dc_parse_dt(dc);
125513411dddSThierry Reding 	if (err < 0)
125613411dddSThierry Reding 		return err;
125713411dddSThierry Reding 
1258dee8268fSThierry Reding 	dc->clk = devm_clk_get(&pdev->dev, NULL);
1259dee8268fSThierry Reding 	if (IS_ERR(dc->clk)) {
1260dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to get clock\n");
1261dee8268fSThierry Reding 		return PTR_ERR(dc->clk);
1262dee8268fSThierry Reding 	}
1263dee8268fSThierry Reding 
1264ca48080aSStephen Warren 	dc->rst = devm_reset_control_get(&pdev->dev, "dc");
1265ca48080aSStephen Warren 	if (IS_ERR(dc->rst)) {
1266ca48080aSStephen Warren 		dev_err(&pdev->dev, "failed to get reset\n");
1267ca48080aSStephen Warren 		return PTR_ERR(dc->rst);
1268ca48080aSStephen Warren 	}
1269ca48080aSStephen Warren 
1270dee8268fSThierry Reding 	err = clk_prepare_enable(dc->clk);
1271dee8268fSThierry Reding 	if (err < 0)
1272dee8268fSThierry Reding 		return err;
1273dee8268fSThierry Reding 
1274dee8268fSThierry Reding 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1275dee8268fSThierry Reding 	dc->regs = devm_ioremap_resource(&pdev->dev, regs);
1276dee8268fSThierry Reding 	if (IS_ERR(dc->regs))
1277dee8268fSThierry Reding 		return PTR_ERR(dc->regs);
1278dee8268fSThierry Reding 
1279dee8268fSThierry Reding 	dc->irq = platform_get_irq(pdev, 0);
1280dee8268fSThierry Reding 	if (dc->irq < 0) {
1281dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to get IRQ\n");
1282dee8268fSThierry Reding 		return -ENXIO;
1283dee8268fSThierry Reding 	}
1284dee8268fSThierry Reding 
1285dee8268fSThierry Reding 	INIT_LIST_HEAD(&dc->client.list);
1286dee8268fSThierry Reding 	dc->client.ops = &dc_client_ops;
1287dee8268fSThierry Reding 	dc->client.dev = &pdev->dev;
1288dee8268fSThierry Reding 
1289dee8268fSThierry Reding 	err = tegra_dc_rgb_probe(dc);
1290dee8268fSThierry Reding 	if (err < 0 && err != -ENODEV) {
1291dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err);
1292dee8268fSThierry Reding 		return err;
1293dee8268fSThierry Reding 	}
1294dee8268fSThierry Reding 
1295dee8268fSThierry Reding 	err = host1x_client_register(&dc->client);
1296dee8268fSThierry Reding 	if (err < 0) {
1297dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1298dee8268fSThierry Reding 			err);
1299dee8268fSThierry Reding 		return err;
1300dee8268fSThierry Reding 	}
1301dee8268fSThierry Reding 
1302dee8268fSThierry Reding 	platform_set_drvdata(pdev, dc);
1303dee8268fSThierry Reding 
1304dee8268fSThierry Reding 	return 0;
1305dee8268fSThierry Reding }
1306dee8268fSThierry Reding 
1307dee8268fSThierry Reding static int tegra_dc_remove(struct platform_device *pdev)
1308dee8268fSThierry Reding {
1309dee8268fSThierry Reding 	struct tegra_dc *dc = platform_get_drvdata(pdev);
1310dee8268fSThierry Reding 	int err;
1311dee8268fSThierry Reding 
1312dee8268fSThierry Reding 	err = host1x_client_unregister(&dc->client);
1313dee8268fSThierry Reding 	if (err < 0) {
1314dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1315dee8268fSThierry Reding 			err);
1316dee8268fSThierry Reding 		return err;
1317dee8268fSThierry Reding 	}
1318dee8268fSThierry Reding 
131959d29c0eSThierry Reding 	err = tegra_dc_rgb_remove(dc);
132059d29c0eSThierry Reding 	if (err < 0) {
132159d29c0eSThierry Reding 		dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err);
132259d29c0eSThierry Reding 		return err;
132359d29c0eSThierry Reding 	}
132459d29c0eSThierry Reding 
1325dee8268fSThierry Reding 	clk_disable_unprepare(dc->clk);
1326dee8268fSThierry Reding 
1327dee8268fSThierry Reding 	return 0;
1328dee8268fSThierry Reding }
1329dee8268fSThierry Reding 
1330dee8268fSThierry Reding struct platform_driver tegra_dc_driver = {
1331dee8268fSThierry Reding 	.driver = {
1332dee8268fSThierry Reding 		.name = "tegra-dc",
1333dee8268fSThierry Reding 		.owner = THIS_MODULE,
1334dee8268fSThierry Reding 		.of_match_table = tegra_dc_of_match,
1335dee8268fSThierry Reding 	},
1336dee8268fSThierry Reding 	.probe = tegra_dc_probe,
1337dee8268fSThierry Reding 	.remove = tegra_dc_remove,
1338dee8268fSThierry Reding };
1339