xref: /openbmc/linux/drivers/gpu/drm/tegra/dc.c (revision 89f6501825b5bae3d4aaa2447636f9d3a4287a75)
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>
12df06b759SThierry Reding #include <linux/iommu.h>
13b9ff7aeaSThierry Reding #include <linux/of_device.h>
1433a8eb8dSThierry Reding #include <linux/pm_runtime.h>
15ca48080aSStephen Warren #include <linux/reset.h>
16dee8268fSThierry Reding 
179c012700SThierry Reding #include <soc/tegra/pmc.h>
189c012700SThierry Reding 
19dee8268fSThierry Reding #include "dc.h"
20dee8268fSThierry Reding #include "drm.h"
21dee8268fSThierry Reding #include "gem.h"
2247307954SThierry Reding #include "hub.h"
235acd3514SThierry Reding #include "plane.h"
24dee8268fSThierry Reding 
259d44189fSThierry Reding #include <drm/drm_atomic.h>
264aa3df71SThierry Reding #include <drm/drm_atomic_helper.h>
273cb9ae4fSDaniel Vetter #include <drm/drm_plane_helper.h>
283cb9ae4fSDaniel Vetter 
29791ddb1eSThierry Reding static void tegra_dc_stats_reset(struct tegra_dc_stats *stats)
30791ddb1eSThierry Reding {
31791ddb1eSThierry Reding 	stats->frames = 0;
32791ddb1eSThierry Reding 	stats->vblank = 0;
33791ddb1eSThierry Reding 	stats->underflow = 0;
34791ddb1eSThierry Reding 	stats->overflow = 0;
35791ddb1eSThierry Reding }
36791ddb1eSThierry Reding 
371087fac1SThierry Reding /* Reads the active copy of a register. */
3886df256fSThierry Reding static u32 tegra_dc_readl_active(struct tegra_dc *dc, unsigned long offset)
3986df256fSThierry Reding {
4086df256fSThierry Reding 	u32 value;
4186df256fSThierry Reding 
4286df256fSThierry Reding 	tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
4386df256fSThierry Reding 	value = tegra_dc_readl(dc, offset);
4486df256fSThierry Reding 	tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS);
4586df256fSThierry Reding 
4686df256fSThierry Reding 	return value;
4786df256fSThierry Reding }
4886df256fSThierry Reding 
491087fac1SThierry Reding static inline unsigned int tegra_plane_offset(struct tegra_plane *plane,
501087fac1SThierry Reding 					      unsigned int offset)
511087fac1SThierry Reding {
521087fac1SThierry Reding 	if (offset >= 0x500 && offset <= 0x638) {
531087fac1SThierry Reding 		offset = 0x000 + (offset - 0x500);
541087fac1SThierry Reding 		return plane->offset + offset;
551087fac1SThierry Reding 	}
561087fac1SThierry Reding 
571087fac1SThierry Reding 	if (offset >= 0x700 && offset <= 0x719) {
581087fac1SThierry Reding 		offset = 0x180 + (offset - 0x700);
591087fac1SThierry Reding 		return plane->offset + offset;
601087fac1SThierry Reding 	}
611087fac1SThierry Reding 
621087fac1SThierry Reding 	if (offset >= 0x800 && offset <= 0x839) {
631087fac1SThierry Reding 		offset = 0x1c0 + (offset - 0x800);
641087fac1SThierry Reding 		return plane->offset + offset;
651087fac1SThierry Reding 	}
661087fac1SThierry Reding 
671087fac1SThierry Reding 	dev_WARN(plane->dc->dev, "invalid offset: %x\n", offset);
681087fac1SThierry Reding 
691087fac1SThierry Reding 	return plane->offset + offset;
701087fac1SThierry Reding }
711087fac1SThierry Reding 
721087fac1SThierry Reding static inline u32 tegra_plane_readl(struct tegra_plane *plane,
731087fac1SThierry Reding 				    unsigned int offset)
741087fac1SThierry Reding {
751087fac1SThierry Reding 	return tegra_dc_readl(plane->dc, tegra_plane_offset(plane, offset));
761087fac1SThierry Reding }
771087fac1SThierry Reding 
781087fac1SThierry Reding static inline void tegra_plane_writel(struct tegra_plane *plane, u32 value,
791087fac1SThierry Reding 				      unsigned int offset)
801087fac1SThierry Reding {
811087fac1SThierry Reding 	tegra_dc_writel(plane->dc, value, tegra_plane_offset(plane, offset));
821087fac1SThierry Reding }
831087fac1SThierry Reding 
84c57997bcSThierry Reding bool tegra_dc_has_output(struct tegra_dc *dc, struct device *dev)
85c57997bcSThierry Reding {
86c57997bcSThierry Reding 	struct device_node *np = dc->dev->of_node;
87c57997bcSThierry Reding 	struct of_phandle_iterator it;
88c57997bcSThierry Reding 	int err;
89c57997bcSThierry Reding 
90c57997bcSThierry Reding 	of_for_each_phandle(&it, err, np, "nvidia,outputs", NULL, 0)
91c57997bcSThierry Reding 		if (it.node == dev->of_node)
92c57997bcSThierry Reding 			return true;
93c57997bcSThierry Reding 
94c57997bcSThierry Reding 	return false;
95c57997bcSThierry Reding }
96c57997bcSThierry Reding 
9786df256fSThierry Reding /*
98d700ba7aSThierry Reding  * Double-buffered registers have two copies: ASSEMBLY and ACTIVE. When the
99d700ba7aSThierry Reding  * *_ACT_REQ bits are set the ASSEMBLY copy is latched into the ACTIVE copy.
100d700ba7aSThierry Reding  * Latching happens mmediately if the display controller is in STOP mode or
101d700ba7aSThierry Reding  * on the next frame boundary otherwise.
102d700ba7aSThierry Reding  *
103d700ba7aSThierry Reding  * Triple-buffered registers have three copies: ASSEMBLY, ARM and ACTIVE. The
104d700ba7aSThierry Reding  * ASSEMBLY copy is latched into the ARM copy immediately after *_UPDATE bits
105d700ba7aSThierry Reding  * are written. When the *_ACT_REQ bits are written, the ARM copy is latched
106d700ba7aSThierry Reding  * into the ACTIVE copy, either immediately if the display controller is in
107d700ba7aSThierry Reding  * STOP mode, or at the next frame boundary otherwise.
108d700ba7aSThierry Reding  */
10962b9e063SThierry Reding void tegra_dc_commit(struct tegra_dc *dc)
110205d48edSThierry Reding {
111205d48edSThierry Reding 	tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
112205d48edSThierry Reding 	tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
113205d48edSThierry Reding }
114205d48edSThierry Reding 
11510288eeaSThierry Reding static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v,
11610288eeaSThierry Reding 				  unsigned int bpp)
11710288eeaSThierry Reding {
11810288eeaSThierry Reding 	fixed20_12 outf = dfixed_init(out);
11910288eeaSThierry Reding 	fixed20_12 inf = dfixed_init(in);
12010288eeaSThierry Reding 	u32 dda_inc;
12110288eeaSThierry Reding 	int max;
12210288eeaSThierry Reding 
12310288eeaSThierry Reding 	if (v)
12410288eeaSThierry Reding 		max = 15;
12510288eeaSThierry Reding 	else {
12610288eeaSThierry Reding 		switch (bpp) {
12710288eeaSThierry Reding 		case 2:
12810288eeaSThierry Reding 			max = 8;
12910288eeaSThierry Reding 			break;
13010288eeaSThierry Reding 
13110288eeaSThierry Reding 		default:
13210288eeaSThierry Reding 			WARN_ON_ONCE(1);
13310288eeaSThierry Reding 			/* fallthrough */
13410288eeaSThierry Reding 		case 4:
13510288eeaSThierry Reding 			max = 4;
13610288eeaSThierry Reding 			break;
13710288eeaSThierry Reding 		}
13810288eeaSThierry Reding 	}
13910288eeaSThierry Reding 
14010288eeaSThierry Reding 	outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1));
14110288eeaSThierry Reding 	inf.full -= dfixed_const(1);
14210288eeaSThierry Reding 
14310288eeaSThierry Reding 	dda_inc = dfixed_div(inf, outf);
14410288eeaSThierry Reding 	dda_inc = min_t(u32, dda_inc, dfixed_const(max));
14510288eeaSThierry Reding 
14610288eeaSThierry Reding 	return dda_inc;
14710288eeaSThierry Reding }
14810288eeaSThierry Reding 
14910288eeaSThierry Reding static inline u32 compute_initial_dda(unsigned int in)
15010288eeaSThierry Reding {
15110288eeaSThierry Reding 	fixed20_12 inf = dfixed_init(in);
15210288eeaSThierry Reding 	return dfixed_frac(inf);
15310288eeaSThierry Reding }
15410288eeaSThierry Reding 
155ab7d3f58SThierry Reding static void tegra_plane_setup_blending_legacy(struct tegra_plane *plane)
156ab7d3f58SThierry Reding {
157ebae8d07SThierry Reding 	u32 background[3] = {
158ebae8d07SThierry Reding 		BLEND_WEIGHT1(0) | BLEND_WEIGHT0(0) | BLEND_COLOR_KEY_NONE,
159ebae8d07SThierry Reding 		BLEND_WEIGHT1(0) | BLEND_WEIGHT0(0) | BLEND_COLOR_KEY_NONE,
160ebae8d07SThierry Reding 		BLEND_WEIGHT1(0) | BLEND_WEIGHT0(0) | BLEND_COLOR_KEY_NONE,
161ebae8d07SThierry Reding 	};
162ebae8d07SThierry Reding 	u32 foreground = BLEND_WEIGHT1(255) | BLEND_WEIGHT0(255) |
163ebae8d07SThierry Reding 			 BLEND_COLOR_KEY_NONE;
164ebae8d07SThierry Reding 	u32 blendnokey = BLEND_WEIGHT1(255) | BLEND_WEIGHT0(255);
165ebae8d07SThierry Reding 	struct tegra_plane_state *state;
166ebae8d07SThierry Reding 	unsigned int i;
167ebae8d07SThierry Reding 
168ebae8d07SThierry Reding 	state = to_tegra_plane_state(plane->base.state);
169ebae8d07SThierry Reding 
170ebae8d07SThierry Reding 	/* alpha contribution is 1 minus sum of overlapping windows */
171ebae8d07SThierry Reding 	for (i = 0; i < 3; i++) {
172ebae8d07SThierry Reding 		if (state->dependent[i])
173ebae8d07SThierry Reding 			background[i] |= BLEND_CONTROL_DEPENDENT;
174ebae8d07SThierry Reding 	}
175ebae8d07SThierry Reding 
176ebae8d07SThierry Reding 	/* enable alpha blending if pixel format has an alpha component */
177ebae8d07SThierry Reding 	if (!state->opaque)
178ebae8d07SThierry Reding 		foreground |= BLEND_CONTROL_ALPHA;
179ebae8d07SThierry Reding 
180ab7d3f58SThierry Reding 	/*
181ab7d3f58SThierry Reding 	 * Disable blending and assume Window A is the bottom-most window,
182ab7d3f58SThierry Reding 	 * Window C is the top-most window and Window B is in the middle.
183ab7d3f58SThierry Reding 	 */
184ebae8d07SThierry Reding 	tegra_plane_writel(plane, blendnokey, DC_WIN_BLEND_NOKEY);
185ebae8d07SThierry Reding 	tegra_plane_writel(plane, foreground, DC_WIN_BLEND_1WIN);
186ab7d3f58SThierry Reding 
187ab7d3f58SThierry Reding 	switch (plane->index) {
188ab7d3f58SThierry Reding 	case 0:
189ebae8d07SThierry Reding 		tegra_plane_writel(plane, background[0], DC_WIN_BLEND_2WIN_X);
190ebae8d07SThierry Reding 		tegra_plane_writel(plane, background[1], DC_WIN_BLEND_2WIN_Y);
191ebae8d07SThierry Reding 		tegra_plane_writel(plane, background[2], DC_WIN_BLEND_3WIN_XY);
192ab7d3f58SThierry Reding 		break;
193ab7d3f58SThierry Reding 
194ab7d3f58SThierry Reding 	case 1:
195ebae8d07SThierry Reding 		tegra_plane_writel(plane, foreground, DC_WIN_BLEND_2WIN_X);
196ebae8d07SThierry Reding 		tegra_plane_writel(plane, background[1], DC_WIN_BLEND_2WIN_Y);
197ebae8d07SThierry Reding 		tegra_plane_writel(plane, background[2], DC_WIN_BLEND_3WIN_XY);
198ab7d3f58SThierry Reding 		break;
199ab7d3f58SThierry Reding 
200ab7d3f58SThierry Reding 	case 2:
201ebae8d07SThierry Reding 		tegra_plane_writel(plane, foreground, DC_WIN_BLEND_2WIN_X);
202ebae8d07SThierry Reding 		tegra_plane_writel(plane, foreground, DC_WIN_BLEND_2WIN_Y);
203ebae8d07SThierry Reding 		tegra_plane_writel(plane, foreground, DC_WIN_BLEND_3WIN_XY);
204ab7d3f58SThierry Reding 		break;
205ab7d3f58SThierry Reding 	}
206ab7d3f58SThierry Reding }
207ab7d3f58SThierry Reding 
208ab7d3f58SThierry Reding static void tegra_plane_setup_blending(struct tegra_plane *plane,
209ab7d3f58SThierry Reding 				       const struct tegra_dc_window *window)
210ab7d3f58SThierry Reding {
211ab7d3f58SThierry Reding 	u32 value;
212ab7d3f58SThierry Reding 
213ab7d3f58SThierry Reding 	value = BLEND_FACTOR_DST_ALPHA_ZERO | BLEND_FACTOR_SRC_ALPHA_K2 |
214ab7d3f58SThierry Reding 		BLEND_FACTOR_DST_COLOR_NEG_K1_TIMES_SRC |
215ab7d3f58SThierry Reding 		BLEND_FACTOR_SRC_COLOR_K1_TIMES_SRC;
216ab7d3f58SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_BLEND_MATCH_SELECT);
217ab7d3f58SThierry Reding 
218ab7d3f58SThierry Reding 	value = BLEND_FACTOR_DST_ALPHA_ZERO | BLEND_FACTOR_SRC_ALPHA_K2 |
219ab7d3f58SThierry Reding 		BLEND_FACTOR_DST_COLOR_NEG_K1_TIMES_SRC |
220ab7d3f58SThierry Reding 		BLEND_FACTOR_SRC_COLOR_K1_TIMES_SRC;
221ab7d3f58SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_BLEND_NOMATCH_SELECT);
222ab7d3f58SThierry Reding 
223ab7d3f58SThierry Reding 	value = K2(255) | K1(255) | WINDOW_LAYER_DEPTH(255 - window->zpos);
224ab7d3f58SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_BLEND_LAYER_CONTROL);
225ab7d3f58SThierry Reding }
226ab7d3f58SThierry Reding 
2271087fac1SThierry Reding static void tegra_dc_setup_window(struct tegra_plane *plane,
22810288eeaSThierry Reding 				  const struct tegra_dc_window *window)
22910288eeaSThierry Reding {
23010288eeaSThierry Reding 	unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp;
2311087fac1SThierry Reding 	struct tegra_dc *dc = plane->dc;
23210288eeaSThierry Reding 	bool yuv, planar;
2331087fac1SThierry Reding 	u32 value;
23410288eeaSThierry Reding 
23510288eeaSThierry Reding 	/*
23610288eeaSThierry Reding 	 * For YUV planar modes, the number of bytes per pixel takes into
23710288eeaSThierry Reding 	 * account only the luma component and therefore is 1.
23810288eeaSThierry Reding 	 */
2395acd3514SThierry Reding 	yuv = tegra_plane_format_is_yuv(window->format, &planar);
24010288eeaSThierry Reding 	if (!yuv)
24110288eeaSThierry Reding 		bpp = window->bits_per_pixel / 8;
24210288eeaSThierry Reding 	else
24310288eeaSThierry Reding 		bpp = planar ? 1 : 2;
24410288eeaSThierry Reding 
2451087fac1SThierry Reding 	tegra_plane_writel(plane, window->format, DC_WIN_COLOR_DEPTH);
2461087fac1SThierry Reding 	tegra_plane_writel(plane, window->swap, DC_WIN_BYTE_SWAP);
24710288eeaSThierry Reding 
24810288eeaSThierry Reding 	value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x);
2491087fac1SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_POSITION);
25010288eeaSThierry Reding 
25110288eeaSThierry Reding 	value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w);
2521087fac1SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_SIZE);
25310288eeaSThierry Reding 
25410288eeaSThierry Reding 	h_offset = window->src.x * bpp;
25510288eeaSThierry Reding 	v_offset = window->src.y;
25610288eeaSThierry Reding 	h_size = window->src.w * bpp;
25710288eeaSThierry Reding 	v_size = window->src.h;
25810288eeaSThierry Reding 
25910288eeaSThierry Reding 	value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size);
2601087fac1SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_PRESCALED_SIZE);
26110288eeaSThierry Reding 
26210288eeaSThierry Reding 	/*
26310288eeaSThierry Reding 	 * For DDA computations the number of bytes per pixel for YUV planar
26410288eeaSThierry Reding 	 * modes needs to take into account all Y, U and V components.
26510288eeaSThierry Reding 	 */
26610288eeaSThierry Reding 	if (yuv && planar)
26710288eeaSThierry Reding 		bpp = 2;
26810288eeaSThierry Reding 
26910288eeaSThierry Reding 	h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp);
27010288eeaSThierry Reding 	v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp);
27110288eeaSThierry Reding 
27210288eeaSThierry Reding 	value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda);
2731087fac1SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_DDA_INC);
27410288eeaSThierry Reding 
27510288eeaSThierry Reding 	h_dda = compute_initial_dda(window->src.x);
27610288eeaSThierry Reding 	v_dda = compute_initial_dda(window->src.y);
27710288eeaSThierry Reding 
2781087fac1SThierry Reding 	tegra_plane_writel(plane, h_dda, DC_WIN_H_INITIAL_DDA);
2791087fac1SThierry Reding 	tegra_plane_writel(plane, v_dda, DC_WIN_V_INITIAL_DDA);
28010288eeaSThierry Reding 
2811087fac1SThierry Reding 	tegra_plane_writel(plane, 0, DC_WIN_UV_BUF_STRIDE);
2821087fac1SThierry Reding 	tegra_plane_writel(plane, 0, DC_WIN_BUF_STRIDE);
28310288eeaSThierry Reding 
2841087fac1SThierry Reding 	tegra_plane_writel(plane, window->base[0], DC_WINBUF_START_ADDR);
28510288eeaSThierry Reding 
28610288eeaSThierry Reding 	if (yuv && planar) {
2871087fac1SThierry Reding 		tegra_plane_writel(plane, window->base[1], DC_WINBUF_START_ADDR_U);
2881087fac1SThierry Reding 		tegra_plane_writel(plane, window->base[2], DC_WINBUF_START_ADDR_V);
28910288eeaSThierry Reding 		value = window->stride[1] << 16 | window->stride[0];
2901087fac1SThierry Reding 		tegra_plane_writel(plane, value, DC_WIN_LINE_STRIDE);
29110288eeaSThierry Reding 	} else {
2921087fac1SThierry Reding 		tegra_plane_writel(plane, window->stride[0], DC_WIN_LINE_STRIDE);
29310288eeaSThierry Reding 	}
29410288eeaSThierry Reding 
29510288eeaSThierry Reding 	if (window->bottom_up)
29610288eeaSThierry Reding 		v_offset += window->src.h - 1;
29710288eeaSThierry Reding 
2981087fac1SThierry Reding 	tegra_plane_writel(plane, h_offset, DC_WINBUF_ADDR_H_OFFSET);
2991087fac1SThierry Reding 	tegra_plane_writel(plane, v_offset, DC_WINBUF_ADDR_V_OFFSET);
30010288eeaSThierry Reding 
301c134f019SThierry Reding 	if (dc->soc->supports_block_linear) {
302c134f019SThierry Reding 		unsigned long height = window->tiling.value;
303c134f019SThierry Reding 
304c134f019SThierry Reding 		switch (window->tiling.mode) {
305c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_PITCH:
306c134f019SThierry Reding 			value = DC_WINBUF_SURFACE_KIND_PITCH;
307c134f019SThierry Reding 			break;
308c134f019SThierry Reding 
309c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_TILED:
310c134f019SThierry Reding 			value = DC_WINBUF_SURFACE_KIND_TILED;
311c134f019SThierry Reding 			break;
312c134f019SThierry Reding 
313c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_BLOCK:
314c134f019SThierry Reding 			value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) |
315c134f019SThierry Reding 				DC_WINBUF_SURFACE_KIND_BLOCK;
316c134f019SThierry Reding 			break;
317c134f019SThierry Reding 		}
318c134f019SThierry Reding 
3191087fac1SThierry Reding 		tegra_plane_writel(plane, value, DC_WINBUF_SURFACE_KIND);
32010288eeaSThierry Reding 	} else {
321c134f019SThierry Reding 		switch (window->tiling.mode) {
322c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_PITCH:
32310288eeaSThierry Reding 			value = DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV |
32410288eeaSThierry Reding 				DC_WIN_BUFFER_ADDR_MODE_LINEAR;
325c134f019SThierry Reding 			break;
326c134f019SThierry Reding 
327c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_TILED:
328c134f019SThierry Reding 			value = DC_WIN_BUFFER_ADDR_MODE_TILE_UV |
329c134f019SThierry Reding 				DC_WIN_BUFFER_ADDR_MODE_TILE;
330c134f019SThierry Reding 			break;
331c134f019SThierry Reding 
332c134f019SThierry Reding 		case TEGRA_BO_TILING_MODE_BLOCK:
3334aa3df71SThierry Reding 			/*
3344aa3df71SThierry Reding 			 * No need to handle this here because ->atomic_check
3354aa3df71SThierry Reding 			 * will already have filtered it out.
3364aa3df71SThierry Reding 			 */
3374aa3df71SThierry Reding 			break;
33810288eeaSThierry Reding 		}
33910288eeaSThierry Reding 
3401087fac1SThierry Reding 		tegra_plane_writel(plane, value, DC_WIN_BUFFER_ADDR_MODE);
341c134f019SThierry Reding 	}
34210288eeaSThierry Reding 
34310288eeaSThierry Reding 	value = WIN_ENABLE;
34410288eeaSThierry Reding 
34510288eeaSThierry Reding 	if (yuv) {
34610288eeaSThierry Reding 		/* setup default colorspace conversion coefficients */
3471087fac1SThierry Reding 		tegra_plane_writel(plane, 0x00f0, DC_WIN_CSC_YOF);
3481087fac1SThierry Reding 		tegra_plane_writel(plane, 0x012a, DC_WIN_CSC_KYRGB);
3491087fac1SThierry Reding 		tegra_plane_writel(plane, 0x0000, DC_WIN_CSC_KUR);
3501087fac1SThierry Reding 		tegra_plane_writel(plane, 0x0198, DC_WIN_CSC_KVR);
3511087fac1SThierry Reding 		tegra_plane_writel(plane, 0x039b, DC_WIN_CSC_KUG);
3521087fac1SThierry Reding 		tegra_plane_writel(plane, 0x032f, DC_WIN_CSC_KVG);
3531087fac1SThierry Reding 		tegra_plane_writel(plane, 0x0204, DC_WIN_CSC_KUB);
3541087fac1SThierry Reding 		tegra_plane_writel(plane, 0x0000, DC_WIN_CSC_KVB);
35510288eeaSThierry Reding 
35610288eeaSThierry Reding 		value |= CSC_ENABLE;
35710288eeaSThierry Reding 	} else if (window->bits_per_pixel < 24) {
35810288eeaSThierry Reding 		value |= COLOR_EXPAND;
35910288eeaSThierry Reding 	}
36010288eeaSThierry Reding 
36110288eeaSThierry Reding 	if (window->bottom_up)
36210288eeaSThierry Reding 		value |= V_DIRECTION;
36310288eeaSThierry Reding 
3641087fac1SThierry Reding 	tegra_plane_writel(plane, value, DC_WIN_WIN_OPTIONS);
36510288eeaSThierry Reding 
366ab7d3f58SThierry Reding 	if (dc->soc->supports_blending)
367ab7d3f58SThierry Reding 		tegra_plane_setup_blending(plane, window);
368ab7d3f58SThierry Reding 	else
369ab7d3f58SThierry Reding 		tegra_plane_setup_blending_legacy(plane);
370c7679306SThierry Reding }
371c7679306SThierry Reding 
372511c7023SThierry Reding static const u32 tegra20_primary_formats[] = {
373511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
374511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
375c7679306SThierry Reding 	DRM_FORMAT_RGB565,
376511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
377511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
378511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
379ebae8d07SThierry Reding 	/* non-native formats */
380ebae8d07SThierry Reding 	DRM_FORMAT_XRGB1555,
381ebae8d07SThierry Reding 	DRM_FORMAT_RGBX5551,
382ebae8d07SThierry Reding 	DRM_FORMAT_XBGR8888,
383ebae8d07SThierry Reding 	DRM_FORMAT_XRGB8888,
384511c7023SThierry Reding };
385511c7023SThierry Reding 
386511c7023SThierry Reding static const u32 tegra114_primary_formats[] = {
387511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
388511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
389511c7023SThierry Reding 	DRM_FORMAT_RGB565,
390511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
391511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
392511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
393511c7023SThierry Reding 	/* new on Tegra114 */
394511c7023SThierry Reding 	DRM_FORMAT_ABGR4444,
395511c7023SThierry Reding 	DRM_FORMAT_ABGR1555,
396511c7023SThierry Reding 	DRM_FORMAT_BGRA5551,
397511c7023SThierry Reding 	DRM_FORMAT_XRGB1555,
398511c7023SThierry Reding 	DRM_FORMAT_RGBX5551,
399511c7023SThierry Reding 	DRM_FORMAT_XBGR1555,
400511c7023SThierry Reding 	DRM_FORMAT_BGRX5551,
401511c7023SThierry Reding 	DRM_FORMAT_BGR565,
402511c7023SThierry Reding 	DRM_FORMAT_BGRA8888,
403511c7023SThierry Reding 	DRM_FORMAT_RGBA8888,
404511c7023SThierry Reding 	DRM_FORMAT_XRGB8888,
405511c7023SThierry Reding 	DRM_FORMAT_XBGR8888,
406511c7023SThierry Reding };
407511c7023SThierry Reding 
408511c7023SThierry Reding static const u32 tegra124_primary_formats[] = {
409511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
410511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
411511c7023SThierry Reding 	DRM_FORMAT_RGB565,
412511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
413511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
414511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
415511c7023SThierry Reding 	/* new on Tegra114 */
416511c7023SThierry Reding 	DRM_FORMAT_ABGR4444,
417511c7023SThierry Reding 	DRM_FORMAT_ABGR1555,
418511c7023SThierry Reding 	DRM_FORMAT_BGRA5551,
419511c7023SThierry Reding 	DRM_FORMAT_XRGB1555,
420511c7023SThierry Reding 	DRM_FORMAT_RGBX5551,
421511c7023SThierry Reding 	DRM_FORMAT_XBGR1555,
422511c7023SThierry Reding 	DRM_FORMAT_BGRX5551,
423511c7023SThierry Reding 	DRM_FORMAT_BGR565,
424511c7023SThierry Reding 	DRM_FORMAT_BGRA8888,
425511c7023SThierry Reding 	DRM_FORMAT_RGBA8888,
426511c7023SThierry Reding 	DRM_FORMAT_XRGB8888,
427511c7023SThierry Reding 	DRM_FORMAT_XBGR8888,
428511c7023SThierry Reding 	/* new on Tegra124 */
429511c7023SThierry Reding 	DRM_FORMAT_RGBX8888,
430511c7023SThierry Reding 	DRM_FORMAT_BGRX8888,
431c7679306SThierry Reding };
432c7679306SThierry Reding 
4334aa3df71SThierry Reding static int tegra_plane_atomic_check(struct drm_plane *plane,
4344aa3df71SThierry Reding 				    struct drm_plane_state *state)
4354aa3df71SThierry Reding {
4368f604f8cSThierry Reding 	struct tegra_plane_state *plane_state = to_tegra_plane_state(state);
4378f604f8cSThierry Reding 	struct tegra_bo_tiling *tiling = &plane_state->tiling;
43847802b09SThierry Reding 	struct tegra_plane *tegra = to_tegra_plane(plane);
4394aa3df71SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(state->crtc);
440ebae8d07SThierry Reding 	unsigned int format;
441c7679306SThierry Reding 	int err;
442c7679306SThierry Reding 
4434aa3df71SThierry Reding 	/* no need for further checks if the plane is being disabled */
4444aa3df71SThierry Reding 	if (!state->crtc)
4454aa3df71SThierry Reding 		return 0;
4464aa3df71SThierry Reding 
447ebae8d07SThierry Reding 	err = tegra_plane_format(state->fb->format->format, &format,
4488f604f8cSThierry Reding 				 &plane_state->swap);
4494aa3df71SThierry Reding 	if (err < 0)
4504aa3df71SThierry Reding 		return err;
4514aa3df71SThierry Reding 
452ebae8d07SThierry Reding 	/*
453ebae8d07SThierry Reding 	 * Tegra20 and Tegra30 are special cases here because they support
454ebae8d07SThierry Reding 	 * only variants of specific formats with an alpha component, but not
455ebae8d07SThierry Reding 	 * the corresponding opaque formats. However, the opaque formats can
456ebae8d07SThierry Reding 	 * be emulated by disabling alpha blending for the plane.
457ebae8d07SThierry Reding 	 */
458ebae8d07SThierry Reding 	if (!dc->soc->supports_blending) {
459ebae8d07SThierry Reding 		if (!tegra_plane_format_has_alpha(format)) {
460ebae8d07SThierry Reding 			err = tegra_plane_format_get_alpha(format, &format);
461ebae8d07SThierry Reding 			if (err < 0)
462ebae8d07SThierry Reding 				return err;
463ebae8d07SThierry Reding 
464ebae8d07SThierry Reding 			plane_state->opaque = true;
465ebae8d07SThierry Reding 		} else {
466ebae8d07SThierry Reding 			plane_state->opaque = false;
467ebae8d07SThierry Reding 		}
468ebae8d07SThierry Reding 
469ebae8d07SThierry Reding 		tegra_plane_check_dependent(tegra, plane_state);
470ebae8d07SThierry Reding 	}
471ebae8d07SThierry Reding 
472ebae8d07SThierry Reding 	plane_state->format = format;
473ebae8d07SThierry Reding 
4748f604f8cSThierry Reding 	err = tegra_fb_get_tiling(state->fb, tiling);
4758f604f8cSThierry Reding 	if (err < 0)
4768f604f8cSThierry Reding 		return err;
4778f604f8cSThierry Reding 
4788f604f8cSThierry Reding 	if (tiling->mode == TEGRA_BO_TILING_MODE_BLOCK &&
4794aa3df71SThierry Reding 	    !dc->soc->supports_block_linear) {
4804aa3df71SThierry Reding 		DRM_ERROR("hardware doesn't support block linear mode\n");
4814aa3df71SThierry Reding 		return -EINVAL;
4824aa3df71SThierry Reding 	}
4834aa3df71SThierry Reding 
4844aa3df71SThierry Reding 	/*
4854aa3df71SThierry Reding 	 * Tegra doesn't support different strides for U and V planes so we
4864aa3df71SThierry Reding 	 * error out if the user tries to display a framebuffer with such a
4874aa3df71SThierry Reding 	 * configuration.
4884aa3df71SThierry Reding 	 */
489bcb0b461SVille Syrjälä 	if (state->fb->format->num_planes > 2) {
4904aa3df71SThierry Reding 		if (state->fb->pitches[2] != state->fb->pitches[1]) {
4914aa3df71SThierry Reding 			DRM_ERROR("unsupported UV-plane configuration\n");
4924aa3df71SThierry Reding 			return -EINVAL;
4934aa3df71SThierry Reding 		}
4944aa3df71SThierry Reding 	}
4954aa3df71SThierry Reding 
49647802b09SThierry Reding 	err = tegra_plane_state_add(tegra, state);
49747802b09SThierry Reding 	if (err < 0)
49847802b09SThierry Reding 		return err;
49947802b09SThierry Reding 
5004aa3df71SThierry Reding 	return 0;
5014aa3df71SThierry Reding }
5024aa3df71SThierry Reding 
503a4bfa096SThierry Reding static void tegra_plane_atomic_disable(struct drm_plane *plane,
504a4bfa096SThierry Reding 				       struct drm_plane_state *old_state)
50580d3eef1SDmitry Osipenko {
506a4bfa096SThierry Reding 	struct tegra_plane *p = to_tegra_plane(plane);
50780d3eef1SDmitry Osipenko 	u32 value;
50880d3eef1SDmitry Osipenko 
509a4bfa096SThierry Reding 	/* rien ne va plus */
510a4bfa096SThierry Reding 	if (!old_state || !old_state->crtc)
511a4bfa096SThierry Reding 		return;
512a4bfa096SThierry Reding 
5131087fac1SThierry Reding 	value = tegra_plane_readl(p, DC_WIN_WIN_OPTIONS);
51480d3eef1SDmitry Osipenko 	value &= ~WIN_ENABLE;
5151087fac1SThierry Reding 	tegra_plane_writel(p, value, DC_WIN_WIN_OPTIONS);
51680d3eef1SDmitry Osipenko }
51780d3eef1SDmitry Osipenko 
5184aa3df71SThierry Reding static void tegra_plane_atomic_update(struct drm_plane *plane,
5194aa3df71SThierry Reding 				      struct drm_plane_state *old_state)
5204aa3df71SThierry Reding {
5218f604f8cSThierry Reding 	struct tegra_plane_state *state = to_tegra_plane_state(plane->state);
5224aa3df71SThierry Reding 	struct drm_framebuffer *fb = plane->state->fb;
5234aa3df71SThierry Reding 	struct tegra_plane *p = to_tegra_plane(plane);
5244aa3df71SThierry Reding 	struct tegra_dc_window window;
5254aa3df71SThierry Reding 	unsigned int i;
5264aa3df71SThierry Reding 
5274aa3df71SThierry Reding 	/* rien ne va plus */
5284aa3df71SThierry Reding 	if (!plane->state->crtc || !plane->state->fb)
5294aa3df71SThierry Reding 		return;
5304aa3df71SThierry Reding 
53180d3eef1SDmitry Osipenko 	if (!plane->state->visible)
532a4bfa096SThierry Reding 		return tegra_plane_atomic_disable(plane, old_state);
53380d3eef1SDmitry Osipenko 
534c7679306SThierry Reding 	memset(&window, 0, sizeof(window));
5357d205857SDmitry Osipenko 	window.src.x = plane->state->src.x1 >> 16;
5367d205857SDmitry Osipenko 	window.src.y = plane->state->src.y1 >> 16;
5377d205857SDmitry Osipenko 	window.src.w = drm_rect_width(&plane->state->src) >> 16;
5387d205857SDmitry Osipenko 	window.src.h = drm_rect_height(&plane->state->src) >> 16;
5397d205857SDmitry Osipenko 	window.dst.x = plane->state->dst.x1;
5407d205857SDmitry Osipenko 	window.dst.y = plane->state->dst.y1;
5417d205857SDmitry Osipenko 	window.dst.w = drm_rect_width(&plane->state->dst);
5427d205857SDmitry Osipenko 	window.dst.h = drm_rect_height(&plane->state->dst);
543272725c7SVille Syrjälä 	window.bits_per_pixel = fb->format->cpp[0] * 8;
544c7679306SThierry Reding 	window.bottom_up = tegra_fb_is_bottom_up(fb);
545c7679306SThierry Reding 
5468f604f8cSThierry Reding 	/* copy from state */
547ab7d3f58SThierry Reding 	window.zpos = plane->state->normalized_zpos;
5488f604f8cSThierry Reding 	window.tiling = state->tiling;
5498f604f8cSThierry Reding 	window.format = state->format;
5508f604f8cSThierry Reding 	window.swap = state->swap;
551c7679306SThierry Reding 
552bcb0b461SVille Syrjälä 	for (i = 0; i < fb->format->num_planes; i++) {
5534aa3df71SThierry Reding 		struct tegra_bo *bo = tegra_fb_get_plane(fb, i);
554c7679306SThierry Reding 
5554aa3df71SThierry Reding 		window.base[i] = bo->paddr + fb->offsets[i];
55608ee0178SDmitry Osipenko 
55708ee0178SDmitry Osipenko 		/*
55808ee0178SDmitry Osipenko 		 * Tegra uses a shared stride for UV planes. Framebuffers are
55908ee0178SDmitry Osipenko 		 * already checked for this in the tegra_plane_atomic_check()
56008ee0178SDmitry Osipenko 		 * function, so it's safe to ignore the V-plane pitch here.
56108ee0178SDmitry Osipenko 		 */
56208ee0178SDmitry Osipenko 		if (i < 2)
5634aa3df71SThierry Reding 			window.stride[i] = fb->pitches[i];
564c7679306SThierry Reding 	}
565c7679306SThierry Reding 
5661087fac1SThierry Reding 	tegra_dc_setup_window(p, &window);
5674aa3df71SThierry Reding }
5684aa3df71SThierry Reding 
569a4bfa096SThierry Reding static const struct drm_plane_helper_funcs tegra_plane_helper_funcs = {
5704aa3df71SThierry Reding 	.atomic_check = tegra_plane_atomic_check,
5714aa3df71SThierry Reding 	.atomic_disable = tegra_plane_atomic_disable,
572a4bfa096SThierry Reding 	.atomic_update = tegra_plane_atomic_update,
573c7679306SThierry Reding };
574c7679306SThierry Reding 
575*89f65018SThierry Reding static unsigned long tegra_plane_get_possible_crtcs(struct drm_device *drm)
576c7679306SThierry Reding {
577518e6227SThierry Reding 	/*
578518e6227SThierry Reding 	 * Ideally this would use drm_crtc_mask(), but that would require the
579518e6227SThierry Reding 	 * CRTC to already be in the mode_config's list of CRTCs. However, it
580518e6227SThierry Reding 	 * will only be added to that list in the drm_crtc_init_with_planes()
581518e6227SThierry Reding 	 * (in tegra_dc_init()), which in turn requires registration of these
582518e6227SThierry Reding 	 * planes. So we have ourselves a nice little chicken and egg problem
583518e6227SThierry Reding 	 * here.
584518e6227SThierry Reding 	 *
585518e6227SThierry Reding 	 * We work around this by manually creating the mask from the number
586518e6227SThierry Reding 	 * of CRTCs that have been registered, and should therefore always be
587518e6227SThierry Reding 	 * the same as drm_crtc_index() after registration.
588518e6227SThierry Reding 	 */
589*89f65018SThierry Reding 	return 1 << drm->mode_config.num_crtc;
590*89f65018SThierry Reding }
591*89f65018SThierry Reding 
592*89f65018SThierry Reding static struct drm_plane *tegra_primary_plane_create(struct drm_device *drm,
593*89f65018SThierry Reding 						    struct tegra_dc *dc)
594*89f65018SThierry Reding {
595*89f65018SThierry Reding 	unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
59647307954SThierry Reding 	enum drm_plane_type type = DRM_PLANE_TYPE_PRIMARY;
597c7679306SThierry Reding 	struct tegra_plane *plane;
598c7679306SThierry Reding 	unsigned int num_formats;
599c7679306SThierry Reding 	const u32 *formats;
600c7679306SThierry Reding 	int err;
601c7679306SThierry Reding 
602c7679306SThierry Reding 	plane = kzalloc(sizeof(*plane), GFP_KERNEL);
603c7679306SThierry Reding 	if (!plane)
604c7679306SThierry Reding 		return ERR_PTR(-ENOMEM);
605c7679306SThierry Reding 
6061087fac1SThierry Reding 	/* Always use window A as primary window */
6071087fac1SThierry Reding 	plane->offset = 0xa00;
608c4755fb9SThierry Reding 	plane->index = 0;
6091087fac1SThierry Reding 	plane->dc = dc;
6101087fac1SThierry Reding 
6111087fac1SThierry Reding 	num_formats = dc->soc->num_primary_formats;
6121087fac1SThierry Reding 	formats = dc->soc->primary_formats;
613c4755fb9SThierry Reding 
614518e6227SThierry Reding 	err = drm_universal_plane_init(drm, &plane->base, possible_crtcs,
615c1cb4b61SThierry Reding 				       &tegra_plane_funcs, formats,
61647307954SThierry Reding 				       num_formats, NULL, type, NULL);
617c7679306SThierry Reding 	if (err < 0) {
618c7679306SThierry Reding 		kfree(plane);
619c7679306SThierry Reding 		return ERR_PTR(err);
620c7679306SThierry Reding 	}
621c7679306SThierry Reding 
622a4bfa096SThierry Reding 	drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs);
6234aa3df71SThierry Reding 
624ab7d3f58SThierry Reding 	if (dc->soc->supports_blending)
625ab7d3f58SThierry Reding 		drm_plane_create_zpos_property(&plane->base, 0, 0, 255);
626ab7d3f58SThierry Reding 
627c7679306SThierry Reding 	return &plane->base;
628c7679306SThierry Reding }
629c7679306SThierry Reding 
630c7679306SThierry Reding static const u32 tegra_cursor_plane_formats[] = {
631c7679306SThierry Reding 	DRM_FORMAT_RGBA8888,
632c7679306SThierry Reding };
633c7679306SThierry Reding 
6344aa3df71SThierry Reding static int tegra_cursor_atomic_check(struct drm_plane *plane,
6354aa3df71SThierry Reding 				     struct drm_plane_state *state)
636c7679306SThierry Reding {
63747802b09SThierry Reding 	struct tegra_plane *tegra = to_tegra_plane(plane);
63847802b09SThierry Reding 	int err;
63947802b09SThierry Reding 
6404aa3df71SThierry Reding 	/* no need for further checks if the plane is being disabled */
6414aa3df71SThierry Reding 	if (!state->crtc)
6424aa3df71SThierry Reding 		return 0;
643c7679306SThierry Reding 
644c7679306SThierry Reding 	/* scaling not supported for cursor */
6454aa3df71SThierry Reding 	if ((state->src_w >> 16 != state->crtc_w) ||
6464aa3df71SThierry Reding 	    (state->src_h >> 16 != state->crtc_h))
647c7679306SThierry Reding 		return -EINVAL;
648c7679306SThierry Reding 
649c7679306SThierry Reding 	/* only square cursors supported */
6504aa3df71SThierry Reding 	if (state->src_w != state->src_h)
651c7679306SThierry Reding 		return -EINVAL;
652c7679306SThierry Reding 
6534aa3df71SThierry Reding 	if (state->crtc_w != 32 && state->crtc_w != 64 &&
6544aa3df71SThierry Reding 	    state->crtc_w != 128 && state->crtc_w != 256)
6554aa3df71SThierry Reding 		return -EINVAL;
6564aa3df71SThierry Reding 
65747802b09SThierry Reding 	err = tegra_plane_state_add(tegra, state);
65847802b09SThierry Reding 	if (err < 0)
65947802b09SThierry Reding 		return err;
66047802b09SThierry Reding 
6614aa3df71SThierry Reding 	return 0;
6624aa3df71SThierry Reding }
6634aa3df71SThierry Reding 
6644aa3df71SThierry Reding static void tegra_cursor_atomic_update(struct drm_plane *plane,
6654aa3df71SThierry Reding 				       struct drm_plane_state *old_state)
6664aa3df71SThierry Reding {
6674aa3df71SThierry Reding 	struct tegra_bo *bo = tegra_fb_get_plane(plane->state->fb, 0);
6684aa3df71SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(plane->state->crtc);
6694aa3df71SThierry Reding 	struct drm_plane_state *state = plane->state;
6704aa3df71SThierry Reding 	u32 value = CURSOR_CLIP_DISPLAY;
6714aa3df71SThierry Reding 
6724aa3df71SThierry Reding 	/* rien ne va plus */
6734aa3df71SThierry Reding 	if (!plane->state->crtc || !plane->state->fb)
6744aa3df71SThierry Reding 		return;
6754aa3df71SThierry Reding 
6764aa3df71SThierry Reding 	switch (state->crtc_w) {
677c7679306SThierry Reding 	case 32:
678c7679306SThierry Reding 		value |= CURSOR_SIZE_32x32;
679c7679306SThierry Reding 		break;
680c7679306SThierry Reding 
681c7679306SThierry Reding 	case 64:
682c7679306SThierry Reding 		value |= CURSOR_SIZE_64x64;
683c7679306SThierry Reding 		break;
684c7679306SThierry Reding 
685c7679306SThierry Reding 	case 128:
686c7679306SThierry Reding 		value |= CURSOR_SIZE_128x128;
687c7679306SThierry Reding 		break;
688c7679306SThierry Reding 
689c7679306SThierry Reding 	case 256:
690c7679306SThierry Reding 		value |= CURSOR_SIZE_256x256;
691c7679306SThierry Reding 		break;
692c7679306SThierry Reding 
693c7679306SThierry Reding 	default:
6944aa3df71SThierry Reding 		WARN(1, "cursor size %ux%u not supported\n", state->crtc_w,
6954aa3df71SThierry Reding 		     state->crtc_h);
6964aa3df71SThierry Reding 		return;
697c7679306SThierry Reding 	}
698c7679306SThierry Reding 
699c7679306SThierry Reding 	value |= (bo->paddr >> 10) & 0x3fffff;
700c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR);
701c7679306SThierry Reding 
702c7679306SThierry Reding #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
703c7679306SThierry Reding 	value = (bo->paddr >> 32) & 0x3;
704c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR_HI);
705c7679306SThierry Reding #endif
706c7679306SThierry Reding 
707c7679306SThierry Reding 	/* enable cursor and set blend mode */
708c7679306SThierry Reding 	value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
709c7679306SThierry Reding 	value |= CURSOR_ENABLE;
710c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
711c7679306SThierry Reding 
712c7679306SThierry Reding 	value = tegra_dc_readl(dc, DC_DISP_BLEND_CURSOR_CONTROL);
713c7679306SThierry Reding 	value &= ~CURSOR_DST_BLEND_MASK;
714c7679306SThierry Reding 	value &= ~CURSOR_SRC_BLEND_MASK;
715c7679306SThierry Reding 	value |= CURSOR_MODE_NORMAL;
716c7679306SThierry Reding 	value |= CURSOR_DST_BLEND_NEG_K1_TIMES_SRC;
717c7679306SThierry Reding 	value |= CURSOR_SRC_BLEND_K1_TIMES_SRC;
718c7679306SThierry Reding 	value |= CURSOR_ALPHA;
719c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL);
720c7679306SThierry Reding 
721c7679306SThierry Reding 	/* position the cursor */
7224aa3df71SThierry Reding 	value = (state->crtc_y & 0x3fff) << 16 | (state->crtc_x & 0x3fff);
723c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION);
724c7679306SThierry Reding }
725c7679306SThierry Reding 
7264aa3df71SThierry Reding static void tegra_cursor_atomic_disable(struct drm_plane *plane,
7274aa3df71SThierry Reding 					struct drm_plane_state *old_state)
728c7679306SThierry Reding {
7294aa3df71SThierry Reding 	struct tegra_dc *dc;
730c7679306SThierry Reding 	u32 value;
731c7679306SThierry Reding 
7324aa3df71SThierry Reding 	/* rien ne va plus */
7334aa3df71SThierry Reding 	if (!old_state || !old_state->crtc)
7344aa3df71SThierry Reding 		return;
7354aa3df71SThierry Reding 
7364aa3df71SThierry Reding 	dc = to_tegra_dc(old_state->crtc);
737c7679306SThierry Reding 
738c7679306SThierry Reding 	value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
739c7679306SThierry Reding 	value &= ~CURSOR_ENABLE;
740c7679306SThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
741c7679306SThierry Reding }
742c7679306SThierry Reding 
7434aa3df71SThierry Reding static const struct drm_plane_helper_funcs tegra_cursor_plane_helper_funcs = {
7444aa3df71SThierry Reding 	.atomic_check = tegra_cursor_atomic_check,
7454aa3df71SThierry Reding 	.atomic_update = tegra_cursor_atomic_update,
7464aa3df71SThierry Reding 	.atomic_disable = tegra_cursor_atomic_disable,
747c7679306SThierry Reding };
748c7679306SThierry Reding 
749c7679306SThierry Reding static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm,
750c7679306SThierry Reding 						      struct tegra_dc *dc)
751c7679306SThierry Reding {
752*89f65018SThierry Reding 	unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
753c7679306SThierry Reding 	struct tegra_plane *plane;
754c7679306SThierry Reding 	unsigned int num_formats;
755c7679306SThierry Reding 	const u32 *formats;
756c7679306SThierry Reding 	int err;
757c7679306SThierry Reding 
758c7679306SThierry Reding 	plane = kzalloc(sizeof(*plane), GFP_KERNEL);
759c7679306SThierry Reding 	if (!plane)
760c7679306SThierry Reding 		return ERR_PTR(-ENOMEM);
761c7679306SThierry Reding 
76247802b09SThierry Reding 	/*
763a1df3b24SThierry Reding 	 * This index is kind of fake. The cursor isn't a regular plane, but
764a1df3b24SThierry Reding 	 * its update and activation request bits in DC_CMD_STATE_CONTROL do
765a1df3b24SThierry Reding 	 * use the same programming. Setting this fake index here allows the
766a1df3b24SThierry Reding 	 * code in tegra_add_plane_state() to do the right thing without the
767a1df3b24SThierry Reding 	 * need to special-casing the cursor plane.
76847802b09SThierry Reding 	 */
76947802b09SThierry Reding 	plane->index = 6;
7701087fac1SThierry Reding 	plane->dc = dc;
77147802b09SThierry Reding 
772c7679306SThierry Reding 	num_formats = ARRAY_SIZE(tegra_cursor_plane_formats);
773c7679306SThierry Reding 	formats = tegra_cursor_plane_formats;
774c7679306SThierry Reding 
775*89f65018SThierry Reding 	err = drm_universal_plane_init(drm, &plane->base, possible_crtcs,
776c1cb4b61SThierry Reding 				       &tegra_plane_funcs, formats,
777e6fc3b68SBen Widawsky 				       num_formats, NULL,
778e6fc3b68SBen Widawsky 				       DRM_PLANE_TYPE_CURSOR, NULL);
779c7679306SThierry Reding 	if (err < 0) {
780c7679306SThierry Reding 		kfree(plane);
781c7679306SThierry Reding 		return ERR_PTR(err);
782c7679306SThierry Reding 	}
783c7679306SThierry Reding 
7844aa3df71SThierry Reding 	drm_plane_helper_add(&plane->base, &tegra_cursor_plane_helper_funcs);
7854aa3df71SThierry Reding 
786c7679306SThierry Reding 	return &plane->base;
787c7679306SThierry Reding }
788c7679306SThierry Reding 
789511c7023SThierry Reding static const u32 tegra20_overlay_formats[] = {
790511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
791511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
792dee8268fSThierry Reding 	DRM_FORMAT_RGB565,
793511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
794511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
795511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
796ebae8d07SThierry Reding 	/* non-native formats */
797ebae8d07SThierry Reding 	DRM_FORMAT_XRGB1555,
798ebae8d07SThierry Reding 	DRM_FORMAT_RGBX5551,
799ebae8d07SThierry Reding 	DRM_FORMAT_XBGR8888,
800ebae8d07SThierry Reding 	DRM_FORMAT_XRGB8888,
801511c7023SThierry Reding 	/* planar formats */
802511c7023SThierry Reding 	DRM_FORMAT_UYVY,
803511c7023SThierry Reding 	DRM_FORMAT_YUYV,
804511c7023SThierry Reding 	DRM_FORMAT_YUV420,
805511c7023SThierry Reding 	DRM_FORMAT_YUV422,
806511c7023SThierry Reding };
807511c7023SThierry Reding 
808511c7023SThierry Reding static const u32 tegra114_overlay_formats[] = {
809511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
810511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
811511c7023SThierry Reding 	DRM_FORMAT_RGB565,
812511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
813511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
814511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
815511c7023SThierry Reding 	/* new on Tegra114 */
816511c7023SThierry Reding 	DRM_FORMAT_ABGR4444,
817511c7023SThierry Reding 	DRM_FORMAT_ABGR1555,
818511c7023SThierry Reding 	DRM_FORMAT_BGRA5551,
819511c7023SThierry Reding 	DRM_FORMAT_XRGB1555,
820511c7023SThierry Reding 	DRM_FORMAT_RGBX5551,
821511c7023SThierry Reding 	DRM_FORMAT_XBGR1555,
822511c7023SThierry Reding 	DRM_FORMAT_BGRX5551,
823511c7023SThierry Reding 	DRM_FORMAT_BGR565,
824511c7023SThierry Reding 	DRM_FORMAT_BGRA8888,
825511c7023SThierry Reding 	DRM_FORMAT_RGBA8888,
826511c7023SThierry Reding 	DRM_FORMAT_XRGB8888,
827511c7023SThierry Reding 	DRM_FORMAT_XBGR8888,
828511c7023SThierry Reding 	/* planar formats */
829511c7023SThierry Reding 	DRM_FORMAT_UYVY,
830511c7023SThierry Reding 	DRM_FORMAT_YUYV,
831511c7023SThierry Reding 	DRM_FORMAT_YUV420,
832511c7023SThierry Reding 	DRM_FORMAT_YUV422,
833511c7023SThierry Reding };
834511c7023SThierry Reding 
835511c7023SThierry Reding static const u32 tegra124_overlay_formats[] = {
836511c7023SThierry Reding 	DRM_FORMAT_ARGB4444,
837511c7023SThierry Reding 	DRM_FORMAT_ARGB1555,
838511c7023SThierry Reding 	DRM_FORMAT_RGB565,
839511c7023SThierry Reding 	DRM_FORMAT_RGBA5551,
840511c7023SThierry Reding 	DRM_FORMAT_ABGR8888,
841511c7023SThierry Reding 	DRM_FORMAT_ARGB8888,
842511c7023SThierry Reding 	/* new on Tegra114 */
843511c7023SThierry Reding 	DRM_FORMAT_ABGR4444,
844511c7023SThierry Reding 	DRM_FORMAT_ABGR1555,
845511c7023SThierry Reding 	DRM_FORMAT_BGRA5551,
846511c7023SThierry Reding 	DRM_FORMAT_XRGB1555,
847511c7023SThierry Reding 	DRM_FORMAT_RGBX5551,
848511c7023SThierry Reding 	DRM_FORMAT_XBGR1555,
849511c7023SThierry Reding 	DRM_FORMAT_BGRX5551,
850511c7023SThierry Reding 	DRM_FORMAT_BGR565,
851511c7023SThierry Reding 	DRM_FORMAT_BGRA8888,
852511c7023SThierry Reding 	DRM_FORMAT_RGBA8888,
853511c7023SThierry Reding 	DRM_FORMAT_XRGB8888,
854511c7023SThierry Reding 	DRM_FORMAT_XBGR8888,
855511c7023SThierry Reding 	/* new on Tegra124 */
856511c7023SThierry Reding 	DRM_FORMAT_RGBX8888,
857511c7023SThierry Reding 	DRM_FORMAT_BGRX8888,
858511c7023SThierry Reding 	/* planar formats */
859dee8268fSThierry Reding 	DRM_FORMAT_UYVY,
860f925390eSThierry Reding 	DRM_FORMAT_YUYV,
861dee8268fSThierry Reding 	DRM_FORMAT_YUV420,
862dee8268fSThierry Reding 	DRM_FORMAT_YUV422,
863dee8268fSThierry Reding };
864dee8268fSThierry Reding 
865c7679306SThierry Reding static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm,
866c7679306SThierry Reding 						       struct tegra_dc *dc,
867c7679306SThierry Reding 						       unsigned int index)
868dee8268fSThierry Reding {
869*89f65018SThierry Reding 	unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
870dee8268fSThierry Reding 	struct tegra_plane *plane;
871c7679306SThierry Reding 	unsigned int num_formats;
872c7679306SThierry Reding 	const u32 *formats;
873c7679306SThierry Reding 	int err;
874dee8268fSThierry Reding 
875f002abc1SThierry Reding 	plane = kzalloc(sizeof(*plane), GFP_KERNEL);
876dee8268fSThierry Reding 	if (!plane)
877c7679306SThierry Reding 		return ERR_PTR(-ENOMEM);
878dee8268fSThierry Reding 
8791087fac1SThierry Reding 	plane->offset = 0xa00 + 0x200 * index;
880c7679306SThierry Reding 	plane->index = index;
8811087fac1SThierry Reding 	plane->dc = dc;
882dee8268fSThierry Reding 
883511c7023SThierry Reding 	num_formats = dc->soc->num_overlay_formats;
884511c7023SThierry Reding 	formats = dc->soc->overlay_formats;
885c7679306SThierry Reding 
886*89f65018SThierry Reding 	err = drm_universal_plane_init(drm, &plane->base, possible_crtcs,
887301e0ddbSThierry Reding 				       &tegra_plane_funcs, formats,
888e6fc3b68SBen Widawsky 				       num_formats, NULL,
889e6fc3b68SBen Widawsky 				       DRM_PLANE_TYPE_OVERLAY, NULL);
890f002abc1SThierry Reding 	if (err < 0) {
891f002abc1SThierry Reding 		kfree(plane);
892c7679306SThierry Reding 		return ERR_PTR(err);
893dee8268fSThierry Reding 	}
894c7679306SThierry Reding 
895a4bfa096SThierry Reding 	drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs);
8964aa3df71SThierry Reding 
897ab7d3f58SThierry Reding 	if (dc->soc->supports_blending)
898ab7d3f58SThierry Reding 		drm_plane_create_zpos_property(&plane->base, 0, 0, 255);
899ab7d3f58SThierry Reding 
900c7679306SThierry Reding 	return &plane->base;
901c7679306SThierry Reding }
902c7679306SThierry Reding 
90347307954SThierry Reding static struct drm_plane *tegra_dc_add_shared_planes(struct drm_device *drm,
90447307954SThierry Reding 						    struct tegra_dc *dc)
905c7679306SThierry Reding {
90647307954SThierry Reding 	struct drm_plane *plane, *primary = NULL;
90747307954SThierry Reding 	unsigned int i, j;
90847307954SThierry Reding 
90947307954SThierry Reding 	for (i = 0; i < dc->soc->num_wgrps; i++) {
91047307954SThierry Reding 		const struct tegra_windowgroup_soc *wgrp = &dc->soc->wgrps[i];
91147307954SThierry Reding 
91247307954SThierry Reding 		if (wgrp->dc == dc->pipe) {
91347307954SThierry Reding 			for (j = 0; j < wgrp->num_windows; j++) {
91447307954SThierry Reding 				unsigned int index = wgrp->windows[j];
91547307954SThierry Reding 
91647307954SThierry Reding 				plane = tegra_shared_plane_create(drm, dc,
91747307954SThierry Reding 								  wgrp->index,
91847307954SThierry Reding 								  index);
91947307954SThierry Reding 				if (IS_ERR(plane))
92047307954SThierry Reding 					return plane;
92147307954SThierry Reding 
92247307954SThierry Reding 				/*
92347307954SThierry Reding 				 * Choose the first shared plane owned by this
92447307954SThierry Reding 				 * head as the primary plane.
92547307954SThierry Reding 				 */
92647307954SThierry Reding 				if (!primary) {
92747307954SThierry Reding 					plane->type = DRM_PLANE_TYPE_PRIMARY;
92847307954SThierry Reding 					primary = plane;
92947307954SThierry Reding 				}
93047307954SThierry Reding 			}
93147307954SThierry Reding 		}
93247307954SThierry Reding 	}
93347307954SThierry Reding 
93447307954SThierry Reding 	return primary;
93547307954SThierry Reding }
93647307954SThierry Reding 
93747307954SThierry Reding static struct drm_plane *tegra_dc_add_planes(struct drm_device *drm,
93847307954SThierry Reding 					     struct tegra_dc *dc)
93947307954SThierry Reding {
94047307954SThierry Reding 	struct drm_plane *plane, *primary;
941c7679306SThierry Reding 	unsigned int i;
942c7679306SThierry Reding 
94347307954SThierry Reding 	primary = tegra_primary_plane_create(drm, dc);
94447307954SThierry Reding 	if (IS_ERR(primary))
94547307954SThierry Reding 		return primary;
94647307954SThierry Reding 
947c7679306SThierry Reding 	for (i = 0; i < 2; i++) {
948c7679306SThierry Reding 		plane = tegra_dc_overlay_plane_create(drm, dc, 1 + i);
94947307954SThierry Reding 		if (IS_ERR(plane)) {
95047307954SThierry Reding 			/* XXX tegra_plane_destroy() */
95147307954SThierry Reding 			drm_plane_cleanup(primary);
95247307954SThierry Reding 			kfree(primary);
95347307954SThierry Reding 			return plane;
95447307954SThierry Reding 		}
955f002abc1SThierry Reding 	}
956dee8268fSThierry Reding 
95747307954SThierry Reding 	return primary;
958dee8268fSThierry Reding }
959dee8268fSThierry Reding 
960f002abc1SThierry Reding static void tegra_dc_destroy(struct drm_crtc *crtc)
961f002abc1SThierry Reding {
962f002abc1SThierry Reding 	drm_crtc_cleanup(crtc);
963f002abc1SThierry Reding }
964f002abc1SThierry Reding 
965ca915b10SThierry Reding static void tegra_crtc_reset(struct drm_crtc *crtc)
966ca915b10SThierry Reding {
967ca915b10SThierry Reding 	struct tegra_dc_state *state;
968ca915b10SThierry Reding 
9693b59b7acSThierry Reding 	if (crtc->state)
970ec2dc6a0SDaniel Vetter 		__drm_atomic_helper_crtc_destroy_state(crtc->state);
9713b59b7acSThierry Reding 
972ca915b10SThierry Reding 	kfree(crtc->state);
973ca915b10SThierry Reding 	crtc->state = NULL;
974ca915b10SThierry Reding 
975ca915b10SThierry Reding 	state = kzalloc(sizeof(*state), GFP_KERNEL);
976332bbe70SThierry Reding 	if (state) {
977ca915b10SThierry Reding 		crtc->state = &state->base;
978332bbe70SThierry Reding 		crtc->state->crtc = crtc;
979332bbe70SThierry Reding 	}
98031930d4dSThierry Reding 
98131930d4dSThierry Reding 	drm_crtc_vblank_reset(crtc);
982ca915b10SThierry Reding }
983ca915b10SThierry Reding 
984ca915b10SThierry Reding static struct drm_crtc_state *
985ca915b10SThierry Reding tegra_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
986ca915b10SThierry Reding {
987ca915b10SThierry Reding 	struct tegra_dc_state *state = to_dc_state(crtc->state);
988ca915b10SThierry Reding 	struct tegra_dc_state *copy;
989ca915b10SThierry Reding 
9903b59b7acSThierry Reding 	copy = kmalloc(sizeof(*copy), GFP_KERNEL);
991ca915b10SThierry Reding 	if (!copy)
992ca915b10SThierry Reding 		return NULL;
993ca915b10SThierry Reding 
9943b59b7acSThierry Reding 	__drm_atomic_helper_crtc_duplicate_state(crtc, &copy->base);
9953b59b7acSThierry Reding 	copy->clk = state->clk;
9963b59b7acSThierry Reding 	copy->pclk = state->pclk;
9973b59b7acSThierry Reding 	copy->div = state->div;
9983b59b7acSThierry Reding 	copy->planes = state->planes;
999ca915b10SThierry Reding 
1000ca915b10SThierry Reding 	return &copy->base;
1001ca915b10SThierry Reding }
1002ca915b10SThierry Reding 
1003ca915b10SThierry Reding static void tegra_crtc_atomic_destroy_state(struct drm_crtc *crtc,
1004ca915b10SThierry Reding 					    struct drm_crtc_state *state)
1005ca915b10SThierry Reding {
1006ec2dc6a0SDaniel Vetter 	__drm_atomic_helper_crtc_destroy_state(state);
1007ca915b10SThierry Reding 	kfree(state);
1008ca915b10SThierry Reding }
1009ca915b10SThierry Reding 
1010b95800eeSThierry Reding #define DEBUGFS_REG32(_name) { .name = #_name, .offset = _name }
1011b95800eeSThierry Reding 
1012b95800eeSThierry Reding static const struct debugfs_reg32 tegra_dc_regs[] = {
1013b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_GENERAL_INCR_SYNCPT),
1014b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL),
1015b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_GENERAL_INCR_SYNCPT_ERROR),
1016b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_A_INCR_SYNCPT),
1017b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL),
1018b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_A_INCR_SYNCPT_ERROR),
1019b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_B_INCR_SYNCPT),
1020b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL),
1021b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_B_INCR_SYNCPT_ERROR),
1022b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_C_INCR_SYNCPT),
1023b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL),
1024b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_WIN_C_INCR_SYNCPT_ERROR),
1025b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_CONT_SYNCPT_VSYNC),
1026b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_DISPLAY_COMMAND_OPTION0),
1027b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_DISPLAY_COMMAND),
1028b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_SIGNAL_RAISE),
1029b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_DISPLAY_POWER_CONTROL),
1030b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_INT_STATUS),
1031b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_INT_MASK),
1032b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_INT_ENABLE),
1033b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_INT_TYPE),
1034b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_INT_POLARITY),
1035b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_SIGNAL_RAISE1),
1036b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_SIGNAL_RAISE2),
1037b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_SIGNAL_RAISE3),
1038b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_STATE_ACCESS),
1039b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_STATE_CONTROL),
1040b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_DISPLAY_WINDOW_HEADER),
1041b95800eeSThierry Reding 	DEBUGFS_REG32(DC_CMD_REG_ACT_CONTROL),
1042b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_CRC_CONTROL),
1043b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_CRC_CHECKSUM),
1044b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_ENABLE(0)),
1045b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_ENABLE(1)),
1046b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_ENABLE(2)),
1047b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_ENABLE(3)),
1048b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_POLARITY(0)),
1049b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_POLARITY(1)),
1050b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_POLARITY(2)),
1051b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_POLARITY(3)),
1052b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_DATA(0)),
1053b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_DATA(1)),
1054b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_DATA(2)),
1055b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_DATA(3)),
1056b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_ENABLE(0)),
1057b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_ENABLE(1)),
1058b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_ENABLE(2)),
1059b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_ENABLE(3)),
1060b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_DATA(0)),
1061b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_INPUT_DATA(1)),
1062b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(0)),
1063b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(1)),
1064b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(2)),
1065b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(3)),
1066b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(4)),
1067b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(5)),
1068b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_OUTPUT_SELECT(6)),
1069b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_MISC_CONTROL),
1070b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_PM0_CONTROL),
1071b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_PM0_DUTY_CYCLE),
1072b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_PM1_CONTROL),
1073b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_PIN_PM1_DUTY_CYCLE),
1074b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_SPI_CONTROL),
1075b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_SPI_START_BYTE),
1076b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_HSPI_WRITE_DATA_AB),
1077b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_HSPI_WRITE_DATA_CD),
1078b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_HSPI_CS_DC),
1079b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_SCRATCH_REGISTER_A),
1080b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_SCRATCH_REGISTER_B),
1081b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_GPIO_CTRL),
1082b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_GPIO_DEBOUNCE_COUNTER),
1083b95800eeSThierry Reding 	DEBUGFS_REG32(DC_COM_CRC_CHECKSUM_LATCHED),
1084b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_SIGNAL_OPTIONS0),
1085b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_SIGNAL_OPTIONS1),
1086b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_WIN_OPTIONS),
1087b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_MEM_HIGH_PRIORITY),
1088b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER),
1089b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_TIMING_OPTIONS),
1090b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_REF_TO_SYNC),
1091b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SYNC_WIDTH),
1092b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_BACK_PORCH),
1093b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_ACTIVE),
1094b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_FRONT_PORCH),
1095b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE0_CONTROL),
1096b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE0_POSITION_A),
1097b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE0_POSITION_B),
1098b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE0_POSITION_C),
1099b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE0_POSITION_D),
1100b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE1_CONTROL),
1101b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE1_POSITION_A),
1102b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE1_POSITION_B),
1103b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE1_POSITION_C),
1104b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE1_POSITION_D),
1105b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE2_CONTROL),
1106b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE2_POSITION_A),
1107b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE2_POSITION_B),
1108b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE2_POSITION_C),
1109b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_H_PULSE2_POSITION_D),
1110b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE0_CONTROL),
1111b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE0_POSITION_A),
1112b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE0_POSITION_B),
1113b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE0_POSITION_C),
1114b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE1_CONTROL),
1115b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE1_POSITION_A),
1116b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE1_POSITION_B),
1117b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE1_POSITION_C),
1118b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE2_CONTROL),
1119b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE2_POSITION_A),
1120b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE3_CONTROL),
1121b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_V_PULSE3_POSITION_A),
1122b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_M0_CONTROL),
1123b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_M1_CONTROL),
1124b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DI_CONTROL),
1125b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_PP_CONTROL),
1126b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_PP_SELECT_A),
1127b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_PP_SELECT_B),
1128b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_PP_SELECT_C),
1129b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_PP_SELECT_D),
1130b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_CLOCK_CONTROL),
1131b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_INTERFACE_CONTROL),
1132b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_COLOR_CONTROL),
1133b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SHIFT_CLOCK_OPTIONS),
1134b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DATA_ENABLE_OPTIONS),
1135b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SERIAL_INTERFACE_OPTIONS),
1136b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_LCD_SPI_OPTIONS),
1137b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_BORDER_COLOR),
1138b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_COLOR_KEY0_LOWER),
1139b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_COLOR_KEY0_UPPER),
1140b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_COLOR_KEY1_LOWER),
1141b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_COLOR_KEY1_UPPER),
1142b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_FOREGROUND),
1143b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_BACKGROUND),
1144b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_START_ADDR),
1145b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_START_ADDR_NS),
1146b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_POSITION),
1147b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_POSITION_NS),
1148b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_INIT_SEQ_CONTROL),
1149b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SPI_INIT_SEQ_DATA_A),
1150b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SPI_INIT_SEQ_DATA_B),
1151b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SPI_INIT_SEQ_DATA_C),
1152b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SPI_INIT_SEQ_DATA_D),
1153b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DC_MCCIF_FIFOCTRL),
1154b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_MCCIF_DISPLAY0A_HYST),
1155b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_MCCIF_DISPLAY0B_HYST),
1156b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_MCCIF_DISPLAY1A_HYST),
1157b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_MCCIF_DISPLAY1B_HYST),
1158b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DAC_CRT_CTRL),
1159b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DISP_MISC_CONTROL),
1160b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_CONTROL),
1161b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_CSC_COEFF),
1162b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(0)),
1163b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(1)),
1164b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(2)),
1165b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(3)),
1166b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(4)),
1167b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(5)),
1168b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(6)),
1169b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(7)),
1170b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_LUT(8)),
1171b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_FLICKER_CONTROL),
1172b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_DC_PIXEL_COUNT),
1173b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(0)),
1174b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(1)),
1175b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(2)),
1176b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(3)),
1177b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(4)),
1178b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(5)),
1179b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(6)),
1180b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HISTOGRAM(7)),
1181b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_BL_TF(0)),
1182b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_BL_TF(1)),
1183b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_BL_TF(2)),
1184b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_BL_TF(3)),
1185b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_BL_CONTROL),
1186b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_HW_K_VALUES),
1187b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_SD_MAN_K_VALUES),
1188b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_CURSOR_START_ADDR_HI),
1189b95800eeSThierry Reding 	DEBUGFS_REG32(DC_DISP_BLEND_CURSOR_CONTROL),
1190b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_WIN_OPTIONS),
1191b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BYTE_SWAP),
1192b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BUFFER_CONTROL),
1193b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_COLOR_DEPTH),
1194b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_POSITION),
1195b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_SIZE),
1196b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_PRESCALED_SIZE),
1197b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_H_INITIAL_DDA),
1198b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_V_INITIAL_DDA),
1199b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_DDA_INC),
1200b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_LINE_STRIDE),
1201b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BUF_STRIDE),
1202b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_UV_BUF_STRIDE),
1203b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BUFFER_ADDR_MODE),
1204b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_DV_CONTROL),
1205b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BLEND_NOKEY),
1206b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BLEND_1WIN),
1207b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BLEND_2WIN_X),
1208b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BLEND_2WIN_Y),
1209b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_BLEND_3WIN_XY),
1210b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WIN_HP_FETCH_CONTROL),
1211b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR),
1212b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR_NS),
1213b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR_U),
1214b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR_U_NS),
1215b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR_V),
1216b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_START_ADDR_V_NS),
1217b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_ADDR_H_OFFSET),
1218b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_ADDR_H_OFFSET_NS),
1219b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_ADDR_V_OFFSET),
1220b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_ADDR_V_OFFSET_NS),
1221b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_UFLOW_STATUS),
1222b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_AD_UFLOW_STATUS),
1223b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_BD_UFLOW_STATUS),
1224b95800eeSThierry Reding 	DEBUGFS_REG32(DC_WINBUF_CD_UFLOW_STATUS),
1225b95800eeSThierry Reding };
1226b95800eeSThierry Reding 
1227b95800eeSThierry Reding static int tegra_dc_show_regs(struct seq_file *s, void *data)
1228b95800eeSThierry Reding {
1229b95800eeSThierry Reding 	struct drm_info_node *node = s->private;
1230b95800eeSThierry Reding 	struct tegra_dc *dc = node->info_ent->data;
1231b95800eeSThierry Reding 	unsigned int i;
1232b95800eeSThierry Reding 	int err = 0;
1233b95800eeSThierry Reding 
1234b95800eeSThierry Reding 	drm_modeset_lock(&dc->base.mutex, NULL);
1235b95800eeSThierry Reding 
1236b95800eeSThierry Reding 	if (!dc->base.state->active) {
1237b95800eeSThierry Reding 		err = -EBUSY;
1238b95800eeSThierry Reding 		goto unlock;
1239b95800eeSThierry Reding 	}
1240b95800eeSThierry Reding 
1241b95800eeSThierry Reding 	for (i = 0; i < ARRAY_SIZE(tegra_dc_regs); i++) {
1242b95800eeSThierry Reding 		unsigned int offset = tegra_dc_regs[i].offset;
1243b95800eeSThierry Reding 
1244b95800eeSThierry Reding 		seq_printf(s, "%-40s %#05x %08x\n", tegra_dc_regs[i].name,
1245b95800eeSThierry Reding 			   offset, tegra_dc_readl(dc, offset));
1246b95800eeSThierry Reding 	}
1247b95800eeSThierry Reding 
1248b95800eeSThierry Reding unlock:
1249b95800eeSThierry Reding 	drm_modeset_unlock(&dc->base.mutex);
1250b95800eeSThierry Reding 	return err;
1251b95800eeSThierry Reding }
1252b95800eeSThierry Reding 
1253b95800eeSThierry Reding static int tegra_dc_show_crc(struct seq_file *s, void *data)
1254b95800eeSThierry Reding {
1255b95800eeSThierry Reding 	struct drm_info_node *node = s->private;
1256b95800eeSThierry Reding 	struct tegra_dc *dc = node->info_ent->data;
1257b95800eeSThierry Reding 	int err = 0;
1258b95800eeSThierry Reding 	u32 value;
1259b95800eeSThierry Reding 
1260b95800eeSThierry Reding 	drm_modeset_lock(&dc->base.mutex, NULL);
1261b95800eeSThierry Reding 
1262b95800eeSThierry Reding 	if (!dc->base.state->active) {
1263b95800eeSThierry Reding 		err = -EBUSY;
1264b95800eeSThierry Reding 		goto unlock;
1265b95800eeSThierry Reding 	}
1266b95800eeSThierry Reding 
1267b95800eeSThierry Reding 	value = DC_COM_CRC_CONTROL_ACTIVE_DATA | DC_COM_CRC_CONTROL_ENABLE;
1268b95800eeSThierry Reding 	tegra_dc_writel(dc, value, DC_COM_CRC_CONTROL);
1269b95800eeSThierry Reding 	tegra_dc_commit(dc);
1270b95800eeSThierry Reding 
1271b95800eeSThierry Reding 	drm_crtc_wait_one_vblank(&dc->base);
1272b95800eeSThierry Reding 	drm_crtc_wait_one_vblank(&dc->base);
1273b95800eeSThierry Reding 
1274b95800eeSThierry Reding 	value = tegra_dc_readl(dc, DC_COM_CRC_CHECKSUM);
1275b95800eeSThierry Reding 	seq_printf(s, "%08x\n", value);
1276b95800eeSThierry Reding 
1277b95800eeSThierry Reding 	tegra_dc_writel(dc, 0, DC_COM_CRC_CONTROL);
1278b95800eeSThierry Reding 
1279b95800eeSThierry Reding unlock:
1280b95800eeSThierry Reding 	drm_modeset_unlock(&dc->base.mutex);
1281b95800eeSThierry Reding 	return err;
1282b95800eeSThierry Reding }
1283b95800eeSThierry Reding 
1284b95800eeSThierry Reding static int tegra_dc_show_stats(struct seq_file *s, void *data)
1285b95800eeSThierry Reding {
1286b95800eeSThierry Reding 	struct drm_info_node *node = s->private;
1287b95800eeSThierry Reding 	struct tegra_dc *dc = node->info_ent->data;
1288b95800eeSThierry Reding 
1289b95800eeSThierry Reding 	seq_printf(s, "frames: %lu\n", dc->stats.frames);
1290b95800eeSThierry Reding 	seq_printf(s, "vblank: %lu\n", dc->stats.vblank);
1291b95800eeSThierry Reding 	seq_printf(s, "underflow: %lu\n", dc->stats.underflow);
1292b95800eeSThierry Reding 	seq_printf(s, "overflow: %lu\n", dc->stats.overflow);
1293b95800eeSThierry Reding 
1294b95800eeSThierry Reding 	return 0;
1295b95800eeSThierry Reding }
1296b95800eeSThierry Reding 
1297b95800eeSThierry Reding static struct drm_info_list debugfs_files[] = {
1298b95800eeSThierry Reding 	{ "regs", tegra_dc_show_regs, 0, NULL },
1299b95800eeSThierry Reding 	{ "crc", tegra_dc_show_crc, 0, NULL },
1300b95800eeSThierry Reding 	{ "stats", tegra_dc_show_stats, 0, NULL },
1301b95800eeSThierry Reding };
1302b95800eeSThierry Reding 
1303b95800eeSThierry Reding static int tegra_dc_late_register(struct drm_crtc *crtc)
1304b95800eeSThierry Reding {
1305b95800eeSThierry Reding 	unsigned int i, count = ARRAY_SIZE(debugfs_files);
1306b95800eeSThierry Reding 	struct drm_minor *minor = crtc->dev->primary;
130739f55c61SArnd Bergmann 	struct dentry *root;
1308b95800eeSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1309b95800eeSThierry Reding 	int err;
1310b95800eeSThierry Reding 
131139f55c61SArnd Bergmann #ifdef CONFIG_DEBUG_FS
131239f55c61SArnd Bergmann 	root = crtc->debugfs_entry;
131339f55c61SArnd Bergmann #else
131439f55c61SArnd Bergmann 	root = NULL;
131539f55c61SArnd Bergmann #endif
131639f55c61SArnd Bergmann 
1317b95800eeSThierry Reding 	dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1318b95800eeSThierry Reding 				    GFP_KERNEL);
1319b95800eeSThierry Reding 	if (!dc->debugfs_files)
1320b95800eeSThierry Reding 		return -ENOMEM;
1321b95800eeSThierry Reding 
1322b95800eeSThierry Reding 	for (i = 0; i < count; i++)
1323b95800eeSThierry Reding 		dc->debugfs_files[i].data = dc;
1324b95800eeSThierry Reding 
1325b95800eeSThierry Reding 	err = drm_debugfs_create_files(dc->debugfs_files, count, root, minor);
1326b95800eeSThierry Reding 	if (err < 0)
1327b95800eeSThierry Reding 		goto free;
1328b95800eeSThierry Reding 
1329b95800eeSThierry Reding 	return 0;
1330b95800eeSThierry Reding 
1331b95800eeSThierry Reding free:
1332b95800eeSThierry Reding 	kfree(dc->debugfs_files);
1333b95800eeSThierry Reding 	dc->debugfs_files = NULL;
1334b95800eeSThierry Reding 
1335b95800eeSThierry Reding 	return err;
1336b95800eeSThierry Reding }
1337b95800eeSThierry Reding 
1338b95800eeSThierry Reding static void tegra_dc_early_unregister(struct drm_crtc *crtc)
1339b95800eeSThierry Reding {
1340b95800eeSThierry Reding 	unsigned int count = ARRAY_SIZE(debugfs_files);
1341b95800eeSThierry Reding 	struct drm_minor *minor = crtc->dev->primary;
1342b95800eeSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1343b95800eeSThierry Reding 
1344b95800eeSThierry Reding 	drm_debugfs_remove_files(dc->debugfs_files, count, minor);
1345b95800eeSThierry Reding 	kfree(dc->debugfs_files);
1346b95800eeSThierry Reding 	dc->debugfs_files = NULL;
1347b95800eeSThierry Reding }
1348b95800eeSThierry Reding 
1349c49c81e2SThierry Reding static u32 tegra_dc_get_vblank_counter(struct drm_crtc *crtc)
1350c49c81e2SThierry Reding {
1351c49c81e2SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1352c49c81e2SThierry Reding 
135347307954SThierry Reding 	/* XXX vblank syncpoints don't work with nvdisplay yet */
135447307954SThierry Reding 	if (dc->syncpt && !dc->soc->has_nvdisplay)
1355c49c81e2SThierry Reding 		return host1x_syncpt_read(dc->syncpt);
1356c49c81e2SThierry Reding 
1357c49c81e2SThierry Reding 	/* fallback to software emulated VBLANK counter */
1358c49c81e2SThierry Reding 	return drm_crtc_vblank_count(&dc->base);
1359c49c81e2SThierry Reding }
1360c49c81e2SThierry Reding 
1361c49c81e2SThierry Reding static int tegra_dc_enable_vblank(struct drm_crtc *crtc)
1362c49c81e2SThierry Reding {
1363c49c81e2SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1364363541e8SThierry Reding 	u32 value;
1365c49c81e2SThierry Reding 
1366c49c81e2SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
1367c49c81e2SThierry Reding 	value |= VBLANK_INT;
1368c49c81e2SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
1369c49c81e2SThierry Reding 
1370c49c81e2SThierry Reding 	return 0;
1371c49c81e2SThierry Reding }
1372c49c81e2SThierry Reding 
1373c49c81e2SThierry Reding static void tegra_dc_disable_vblank(struct drm_crtc *crtc)
1374c49c81e2SThierry Reding {
1375c49c81e2SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1376363541e8SThierry Reding 	u32 value;
1377c49c81e2SThierry Reding 
1378c49c81e2SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
1379c49c81e2SThierry Reding 	value &= ~VBLANK_INT;
1380c49c81e2SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
1381c49c81e2SThierry Reding }
1382c49c81e2SThierry Reding 
1383dee8268fSThierry Reding static const struct drm_crtc_funcs tegra_crtc_funcs = {
13841503ca47SThierry Reding 	.page_flip = drm_atomic_helper_page_flip,
138574f48791SThierry Reding 	.set_config = drm_atomic_helper_set_config,
1386f002abc1SThierry Reding 	.destroy = tegra_dc_destroy,
1387ca915b10SThierry Reding 	.reset = tegra_crtc_reset,
1388ca915b10SThierry Reding 	.atomic_duplicate_state = tegra_crtc_atomic_duplicate_state,
1389ca915b10SThierry Reding 	.atomic_destroy_state = tegra_crtc_atomic_destroy_state,
1390b95800eeSThierry Reding 	.late_register = tegra_dc_late_register,
1391b95800eeSThierry Reding 	.early_unregister = tegra_dc_early_unregister,
139210437d9bSShawn Guo 	.get_vblank_counter = tegra_dc_get_vblank_counter,
139310437d9bSShawn Guo 	.enable_vblank = tegra_dc_enable_vblank,
139410437d9bSShawn Guo 	.disable_vblank = tegra_dc_disable_vblank,
1395dee8268fSThierry Reding };
1396dee8268fSThierry Reding 
1397dee8268fSThierry Reding static int tegra_dc_set_timings(struct tegra_dc *dc,
1398dee8268fSThierry Reding 				struct drm_display_mode *mode)
1399dee8268fSThierry Reding {
14000444c0ffSThierry Reding 	unsigned int h_ref_to_sync = 1;
14010444c0ffSThierry Reding 	unsigned int v_ref_to_sync = 1;
1402dee8268fSThierry Reding 	unsigned long value;
1403dee8268fSThierry Reding 
140447307954SThierry Reding 	if (!dc->soc->has_nvdisplay) {
1405dee8268fSThierry Reding 		tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS);
1406dee8268fSThierry Reding 
1407dee8268fSThierry Reding 		value = (v_ref_to_sync << 16) | h_ref_to_sync;
1408dee8268fSThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC);
140947307954SThierry Reding 	}
1410dee8268fSThierry Reding 
1411dee8268fSThierry Reding 	value = ((mode->vsync_end - mode->vsync_start) << 16) |
1412dee8268fSThierry Reding 		((mode->hsync_end - mode->hsync_start) <<  0);
1413dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH);
1414dee8268fSThierry Reding 
1415dee8268fSThierry Reding 	value = ((mode->vtotal - mode->vsync_end) << 16) |
1416dee8268fSThierry Reding 		((mode->htotal - mode->hsync_end) <<  0);
1417dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH);
1418dee8268fSThierry Reding 
1419dee8268fSThierry Reding 	value = ((mode->vsync_start - mode->vdisplay) << 16) |
1420dee8268fSThierry Reding 		((mode->hsync_start - mode->hdisplay) <<  0);
1421dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH);
1422dee8268fSThierry Reding 
1423dee8268fSThierry Reding 	value = (mode->vdisplay << 16) | mode->hdisplay;
1424dee8268fSThierry Reding 	tegra_dc_writel(dc, value, DC_DISP_ACTIVE);
1425dee8268fSThierry Reding 
1426dee8268fSThierry Reding 	return 0;
1427dee8268fSThierry Reding }
1428dee8268fSThierry Reding 
14299d910b60SThierry Reding /**
14309d910b60SThierry Reding  * tegra_dc_state_setup_clock - check clock settings and store them in atomic
14319d910b60SThierry Reding  *     state
14329d910b60SThierry Reding  * @dc: display controller
14339d910b60SThierry Reding  * @crtc_state: CRTC atomic state
14349d910b60SThierry Reding  * @clk: parent clock for display controller
14359d910b60SThierry Reding  * @pclk: pixel clock
14369d910b60SThierry Reding  * @div: shift clock divider
14379d910b60SThierry Reding  *
14389d910b60SThierry Reding  * Returns:
14399d910b60SThierry Reding  * 0 on success or a negative error-code on failure.
14409d910b60SThierry Reding  */
1441ca915b10SThierry Reding int tegra_dc_state_setup_clock(struct tegra_dc *dc,
1442ca915b10SThierry Reding 			       struct drm_crtc_state *crtc_state,
1443ca915b10SThierry Reding 			       struct clk *clk, unsigned long pclk,
1444ca915b10SThierry Reding 			       unsigned int div)
1445ca915b10SThierry Reding {
1446ca915b10SThierry Reding 	struct tegra_dc_state *state = to_dc_state(crtc_state);
1447ca915b10SThierry Reding 
1448d2982748SThierry Reding 	if (!clk_has_parent(dc->clk, clk))
1449d2982748SThierry Reding 		return -EINVAL;
1450d2982748SThierry Reding 
1451ca915b10SThierry Reding 	state->clk = clk;
1452ca915b10SThierry Reding 	state->pclk = pclk;
1453ca915b10SThierry Reding 	state->div = div;
1454ca915b10SThierry Reding 
1455ca915b10SThierry Reding 	return 0;
1456ca915b10SThierry Reding }
1457ca915b10SThierry Reding 
145876d59ed0SThierry Reding static void tegra_dc_commit_state(struct tegra_dc *dc,
145976d59ed0SThierry Reding 				  struct tegra_dc_state *state)
146076d59ed0SThierry Reding {
146176d59ed0SThierry Reding 	u32 value;
146276d59ed0SThierry Reding 	int err;
146376d59ed0SThierry Reding 
146476d59ed0SThierry Reding 	err = clk_set_parent(dc->clk, state->clk);
146576d59ed0SThierry Reding 	if (err < 0)
146676d59ed0SThierry Reding 		dev_err(dc->dev, "failed to set parent clock: %d\n", err);
146776d59ed0SThierry Reding 
146876d59ed0SThierry Reding 	/*
146976d59ed0SThierry Reding 	 * Outputs may not want to change the parent clock rate. This is only
147076d59ed0SThierry Reding 	 * relevant to Tegra20 where only a single display PLL is available.
147176d59ed0SThierry Reding 	 * Since that PLL would typically be used for HDMI, an internal LVDS
147276d59ed0SThierry Reding 	 * panel would need to be driven by some other clock such as PLL_P
147376d59ed0SThierry Reding 	 * which is shared with other peripherals. Changing the clock rate
147476d59ed0SThierry Reding 	 * should therefore be avoided.
147576d59ed0SThierry Reding 	 */
147676d59ed0SThierry Reding 	if (state->pclk > 0) {
147776d59ed0SThierry Reding 		err = clk_set_rate(state->clk, state->pclk);
147876d59ed0SThierry Reding 		if (err < 0)
147976d59ed0SThierry Reding 			dev_err(dc->dev,
148076d59ed0SThierry Reding 				"failed to set clock rate to %lu Hz\n",
148176d59ed0SThierry Reding 				state->pclk);
148276d59ed0SThierry Reding 	}
148376d59ed0SThierry Reding 
148476d59ed0SThierry Reding 	DRM_DEBUG_KMS("rate: %lu, div: %u\n", clk_get_rate(dc->clk),
148576d59ed0SThierry Reding 		      state->div);
148676d59ed0SThierry Reding 	DRM_DEBUG_KMS("pclk: %lu\n", state->pclk);
148776d59ed0SThierry Reding 
148847307954SThierry Reding 	if (!dc->soc->has_nvdisplay) {
148976d59ed0SThierry Reding 		value = SHIFT_CLK_DIVIDER(state->div) | PIXEL_CLK_DIVIDER_PCD1;
149076d59ed0SThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL);
149147307954SThierry Reding 	}
149239e08affSThierry Reding 
149339e08affSThierry Reding 	err = clk_set_rate(dc->clk, state->pclk);
149439e08affSThierry Reding 	if (err < 0)
149539e08affSThierry Reding 		dev_err(dc->dev, "failed to set clock %pC to %lu Hz: %d\n",
149639e08affSThierry Reding 			dc->clk, state->pclk, err);
149776d59ed0SThierry Reding }
149876d59ed0SThierry Reding 
1499003fc848SThierry Reding static void tegra_dc_stop(struct tegra_dc *dc)
1500003fc848SThierry Reding {
1501003fc848SThierry Reding 	u32 value;
1502003fc848SThierry Reding 
1503003fc848SThierry Reding 	/* stop the display controller */
1504003fc848SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
1505003fc848SThierry Reding 	value &= ~DISP_CTRL_MODE_MASK;
1506003fc848SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
1507003fc848SThierry Reding 
1508003fc848SThierry Reding 	tegra_dc_commit(dc);
1509003fc848SThierry Reding }
1510003fc848SThierry Reding 
1511003fc848SThierry Reding static bool tegra_dc_idle(struct tegra_dc *dc)
1512003fc848SThierry Reding {
1513003fc848SThierry Reding 	u32 value;
1514003fc848SThierry Reding 
1515003fc848SThierry Reding 	value = tegra_dc_readl_active(dc, DC_CMD_DISPLAY_COMMAND);
1516003fc848SThierry Reding 
1517003fc848SThierry Reding 	return (value & DISP_CTRL_MODE_MASK) == 0;
1518003fc848SThierry Reding }
1519003fc848SThierry Reding 
1520003fc848SThierry Reding static int tegra_dc_wait_idle(struct tegra_dc *dc, unsigned long timeout)
1521003fc848SThierry Reding {
1522003fc848SThierry Reding 	timeout = jiffies + msecs_to_jiffies(timeout);
1523003fc848SThierry Reding 
1524003fc848SThierry Reding 	while (time_before(jiffies, timeout)) {
1525003fc848SThierry Reding 		if (tegra_dc_idle(dc))
1526003fc848SThierry Reding 			return 0;
1527003fc848SThierry Reding 
1528003fc848SThierry Reding 		usleep_range(1000, 2000);
1529003fc848SThierry Reding 	}
1530003fc848SThierry Reding 
1531003fc848SThierry Reding 	dev_dbg(dc->dev, "timeout waiting for DC to become idle\n");
1532003fc848SThierry Reding 	return -ETIMEDOUT;
1533003fc848SThierry Reding }
1534003fc848SThierry Reding 
153564581714SLaurent Pinchart static void tegra_crtc_atomic_disable(struct drm_crtc *crtc,
153664581714SLaurent Pinchart 				      struct drm_crtc_state *old_state)
1537003fc848SThierry Reding {
1538003fc848SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1539003fc848SThierry Reding 	u32 value;
1540003fc848SThierry Reding 
1541003fc848SThierry Reding 	if (!tegra_dc_idle(dc)) {
1542003fc848SThierry Reding 		tegra_dc_stop(dc);
1543003fc848SThierry Reding 
1544003fc848SThierry Reding 		/*
1545003fc848SThierry Reding 		 * Ignore the return value, there isn't anything useful to do
1546003fc848SThierry Reding 		 * in case this fails.
1547003fc848SThierry Reding 		 */
1548003fc848SThierry Reding 		tegra_dc_wait_idle(dc, 100);
1549003fc848SThierry Reding 	}
1550003fc848SThierry Reding 
1551003fc848SThierry Reding 	/*
1552003fc848SThierry Reding 	 * This should really be part of the RGB encoder driver, but clearing
1553003fc848SThierry Reding 	 * these bits has the side-effect of stopping the display controller.
1554003fc848SThierry Reding 	 * When that happens no VBLANK interrupts will be raised. At the same
1555003fc848SThierry Reding 	 * time the encoder is disabled before the display controller, so the
1556003fc848SThierry Reding 	 * above code is always going to timeout waiting for the controller
1557003fc848SThierry Reding 	 * to go idle.
1558003fc848SThierry Reding 	 *
1559003fc848SThierry Reding 	 * Given the close coupling between the RGB encoder and the display
1560003fc848SThierry Reding 	 * controller doing it here is still kind of okay. None of the other
1561003fc848SThierry Reding 	 * encoder drivers require these bits to be cleared.
1562003fc848SThierry Reding 	 *
1563003fc848SThierry Reding 	 * XXX: Perhaps given that the display controller is switched off at
1564003fc848SThierry Reding 	 * this point anyway maybe clearing these bits isn't even useful for
1565003fc848SThierry Reding 	 * the RGB encoder?
1566003fc848SThierry Reding 	 */
1567003fc848SThierry Reding 	if (dc->rgb) {
1568003fc848SThierry Reding 		value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
1569003fc848SThierry Reding 		value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1570003fc848SThierry Reding 			   PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
1571003fc848SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
1572003fc848SThierry Reding 	}
1573003fc848SThierry Reding 
1574003fc848SThierry Reding 	tegra_dc_stats_reset(&dc->stats);
1575003fc848SThierry Reding 	drm_crtc_vblank_off(crtc);
157633a8eb8dSThierry Reding 
15779d99ab6eSThierry Reding 	spin_lock_irq(&crtc->dev->event_lock);
15789d99ab6eSThierry Reding 
15799d99ab6eSThierry Reding 	if (crtc->state->event) {
15809d99ab6eSThierry Reding 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
15819d99ab6eSThierry Reding 		crtc->state->event = NULL;
15829d99ab6eSThierry Reding 	}
15839d99ab6eSThierry Reding 
15849d99ab6eSThierry Reding 	spin_unlock_irq(&crtc->dev->event_lock);
15859d99ab6eSThierry Reding 
158633a8eb8dSThierry Reding 	pm_runtime_put_sync(dc->dev);
1587003fc848SThierry Reding }
1588003fc848SThierry Reding 
15890b20a0f8SLaurent Pinchart static void tegra_crtc_atomic_enable(struct drm_crtc *crtc,
15900b20a0f8SLaurent Pinchart 				     struct drm_crtc_state *old_state)
1591dee8268fSThierry Reding {
15924aa3df71SThierry Reding 	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
159376d59ed0SThierry Reding 	struct tegra_dc_state *state = to_dc_state(crtc->state);
1594dee8268fSThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
1595dbb3f2f7SThierry Reding 	u32 value;
1596dee8268fSThierry Reding 
159733a8eb8dSThierry Reding 	pm_runtime_get_sync(dc->dev);
159833a8eb8dSThierry Reding 
159933a8eb8dSThierry Reding 	/* initialize display controller */
160033a8eb8dSThierry Reding 	if (dc->syncpt) {
160147307954SThierry Reding 		u32 syncpt = host1x_syncpt_id(dc->syncpt), enable;
160247307954SThierry Reding 
160347307954SThierry Reding 		if (dc->soc->has_nvdisplay)
160447307954SThierry Reding 			enable = 1 << 31;
160547307954SThierry Reding 		else
160647307954SThierry Reding 			enable = 1 << 8;
160733a8eb8dSThierry Reding 
160833a8eb8dSThierry Reding 		value = SYNCPT_CNTRL_NO_STALL;
160933a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
161033a8eb8dSThierry Reding 
161147307954SThierry Reding 		value = enable | syncpt;
161233a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_CONT_SYNCPT_VSYNC);
161333a8eb8dSThierry Reding 	}
161433a8eb8dSThierry Reding 
161547307954SThierry Reding 	if (dc->soc->has_nvdisplay) {
161647307954SThierry Reding 		value = DSC_TO_UF_INT | DSC_BBUF_UF_INT | DSC_RBUF_UF_INT |
161747307954SThierry Reding 			DSC_OBUF_UF_INT;
161847307954SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_TYPE);
161947307954SThierry Reding 
162047307954SThierry Reding 		value = DSC_TO_UF_INT | DSC_BBUF_UF_INT | DSC_RBUF_UF_INT |
162147307954SThierry Reding 			DSC_OBUF_UF_INT | SD3_BUCKET_WALK_DONE_INT |
162247307954SThierry Reding 			HEAD_UF_INT | MSF_INT | REG_TMOUT_INT |
162347307954SThierry Reding 			REGION_CRC_INT | V_PULSE2_INT | V_PULSE3_INT |
162447307954SThierry Reding 			VBLANK_INT | FRAME_END_INT;
162547307954SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY);
162647307954SThierry Reding 
162747307954SThierry Reding 		value = SD3_BUCKET_WALK_DONE_INT | HEAD_UF_INT | VBLANK_INT |
162847307954SThierry Reding 			FRAME_END_INT;
162947307954SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
163047307954SThierry Reding 
163147307954SThierry Reding 		value = HEAD_UF_INT | REG_TMOUT_INT | FRAME_END_INT;
163247307954SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
163347307954SThierry Reding 
163447307954SThierry Reding 		tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS);
163547307954SThierry Reding 	} else {
163633a8eb8dSThierry Reding 		value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
163733a8eb8dSThierry Reding 			WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
163833a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_TYPE);
163933a8eb8dSThierry Reding 
164033a8eb8dSThierry Reding 		value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
164133a8eb8dSThierry Reding 			WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
164233a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY);
164333a8eb8dSThierry Reding 
164433a8eb8dSThierry Reding 		/* initialize timer */
164533a8eb8dSThierry Reding 		value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) |
164633a8eb8dSThierry Reding 			WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20);
164733a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY);
164833a8eb8dSThierry Reding 
164933a8eb8dSThierry Reding 		value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) |
165033a8eb8dSThierry Reding 			WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1);
165133a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
165233a8eb8dSThierry Reding 
165333a8eb8dSThierry Reding 		value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
165433a8eb8dSThierry Reding 			WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
165533a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
165633a8eb8dSThierry Reding 
165733a8eb8dSThierry Reding 		value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
165833a8eb8dSThierry Reding 			WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
165933a8eb8dSThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
166047307954SThierry Reding 	}
166133a8eb8dSThierry Reding 
16627116e9a8SThierry Reding 	if (dc->soc->supports_background_color)
16637116e9a8SThierry Reding 		tegra_dc_writel(dc, 0, DC_DISP_BLEND_BACKGROUND_COLOR);
16647116e9a8SThierry Reding 	else
166533a8eb8dSThierry Reding 		tegra_dc_writel(dc, 0, DC_DISP_BORDER_COLOR);
166633a8eb8dSThierry Reding 
166733a8eb8dSThierry Reding 	/* apply PLL and pixel clock changes */
166876d59ed0SThierry Reding 	tegra_dc_commit_state(dc, state);
166976d59ed0SThierry Reding 
1670dee8268fSThierry Reding 	/* program display mode */
1671dee8268fSThierry Reding 	tegra_dc_set_timings(dc, mode);
1672dee8268fSThierry Reding 
16738620fc62SThierry Reding 	/* interlacing isn't supported yet, so disable it */
16748620fc62SThierry Reding 	if (dc->soc->supports_interlacing) {
16758620fc62SThierry Reding 		value = tegra_dc_readl(dc, DC_DISP_INTERLACE_CONTROL);
16768620fc62SThierry Reding 		value &= ~INTERLACE_ENABLE;
16778620fc62SThierry Reding 		tegra_dc_writel(dc, value, DC_DISP_INTERLACE_CONTROL);
16788620fc62SThierry Reding 	}
1679666cb873SThierry Reding 
1680666cb873SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
1681666cb873SThierry Reding 	value &= ~DISP_CTRL_MODE_MASK;
1682666cb873SThierry Reding 	value |= DISP_CTRL_MODE_C_DISPLAY;
1683666cb873SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
1684666cb873SThierry Reding 
168547307954SThierry Reding 	if (!dc->soc->has_nvdisplay) {
1686666cb873SThierry Reding 		value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
1687666cb873SThierry Reding 		value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1688666cb873SThierry Reding 			 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
1689666cb873SThierry Reding 		tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
169047307954SThierry Reding 	}
169147307954SThierry Reding 
169247307954SThierry Reding 	/* enable underflow reporting and display red for missing pixels */
169347307954SThierry Reding 	if (dc->soc->has_nvdisplay) {
169447307954SThierry Reding 		value = UNDERFLOW_MODE_RED | UNDERFLOW_REPORT_ENABLE;
169547307954SThierry Reding 		tegra_dc_writel(dc, value, DC_COM_RG_UNDERFLOW);
169647307954SThierry Reding 	}
1697666cb873SThierry Reding 
1698666cb873SThierry Reding 	tegra_dc_commit(dc);
1699dee8268fSThierry Reding 
17008ff64c17SThierry Reding 	drm_crtc_vblank_on(crtc);
1701dee8268fSThierry Reding }
1702dee8268fSThierry Reding 
17034aa3df71SThierry Reding static int tegra_crtc_atomic_check(struct drm_crtc *crtc,
17044aa3df71SThierry Reding 				   struct drm_crtc_state *state)
17054aa3df71SThierry Reding {
1706c4755fb9SThierry Reding 	struct tegra_atomic_state *s = to_tegra_atomic_state(state->state);
1707c4755fb9SThierry Reding 	struct tegra_dc_state *tegra = to_dc_state(state);
1708c4755fb9SThierry Reding 
1709c4755fb9SThierry Reding 	/*
1710c4755fb9SThierry Reding 	 * The display hub display clock needs to be fed by the display clock
1711c4755fb9SThierry Reding 	 * with the highest frequency to ensure proper functioning of all the
1712c4755fb9SThierry Reding 	 * displays.
1713c4755fb9SThierry Reding 	 *
1714c4755fb9SThierry Reding 	 * Note that this isn't used before Tegra186, but it doesn't hurt and
1715c4755fb9SThierry Reding 	 * conditionalizing it would make the code less clean.
1716c4755fb9SThierry Reding 	 */
1717c4755fb9SThierry Reding 	if (state->active) {
1718c4755fb9SThierry Reding 		if (!s->clk_disp || tegra->pclk > s->rate) {
1719c4755fb9SThierry Reding 			s->dc = to_tegra_dc(crtc);
1720c4755fb9SThierry Reding 			s->clk_disp = s->dc->clk;
1721c4755fb9SThierry Reding 			s->rate = tegra->pclk;
1722c4755fb9SThierry Reding 		}
1723c4755fb9SThierry Reding 	}
1724c4755fb9SThierry Reding 
17254aa3df71SThierry Reding 	return 0;
17264aa3df71SThierry Reding }
17274aa3df71SThierry Reding 
1728613d2b27SMaarten Lankhorst static void tegra_crtc_atomic_begin(struct drm_crtc *crtc,
1729613d2b27SMaarten Lankhorst 				    struct drm_crtc_state *old_crtc_state)
17304aa3df71SThierry Reding {
17319d99ab6eSThierry Reding 	unsigned long flags;
17321503ca47SThierry Reding 
17331503ca47SThierry Reding 	if (crtc->state->event) {
17349d99ab6eSThierry Reding 		spin_lock_irqsave(&crtc->dev->event_lock, flags);
17351503ca47SThierry Reding 
17369d99ab6eSThierry Reding 		if (drm_crtc_vblank_get(crtc) != 0)
17379d99ab6eSThierry Reding 			drm_crtc_send_vblank_event(crtc, crtc->state->event);
17389d99ab6eSThierry Reding 		else
17399d99ab6eSThierry Reding 			drm_crtc_arm_vblank_event(crtc, crtc->state->event);
17401503ca47SThierry Reding 
17419d99ab6eSThierry Reding 		spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
17429d99ab6eSThierry Reding 
17431503ca47SThierry Reding 		crtc->state->event = NULL;
17441503ca47SThierry Reding 	}
17454aa3df71SThierry Reding }
17464aa3df71SThierry Reding 
1747613d2b27SMaarten Lankhorst static void tegra_crtc_atomic_flush(struct drm_crtc *crtc,
1748613d2b27SMaarten Lankhorst 				    struct drm_crtc_state *old_crtc_state)
17494aa3df71SThierry Reding {
175047802b09SThierry Reding 	struct tegra_dc_state *state = to_dc_state(crtc->state);
175147802b09SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(crtc);
175247307954SThierry Reding 	u32 value;
175347802b09SThierry Reding 
175447307954SThierry Reding 	value = state->planes << 8 | GENERAL_UPDATE;
175547307954SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
175647307954SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
175747307954SThierry Reding 
175847307954SThierry Reding 	value = state->planes | GENERAL_ACT_REQ;
175947307954SThierry Reding 	tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
176047307954SThierry Reding 	value = tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
17614aa3df71SThierry Reding }
17624aa3df71SThierry Reding 
1763dee8268fSThierry Reding static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = {
17644aa3df71SThierry Reding 	.atomic_check = tegra_crtc_atomic_check,
17654aa3df71SThierry Reding 	.atomic_begin = tegra_crtc_atomic_begin,
17664aa3df71SThierry Reding 	.atomic_flush = tegra_crtc_atomic_flush,
17670b20a0f8SLaurent Pinchart 	.atomic_enable = tegra_crtc_atomic_enable,
176864581714SLaurent Pinchart 	.atomic_disable = tegra_crtc_atomic_disable,
1769dee8268fSThierry Reding };
1770dee8268fSThierry Reding 
1771dee8268fSThierry Reding static irqreturn_t tegra_dc_irq(int irq, void *data)
1772dee8268fSThierry Reding {
1773dee8268fSThierry Reding 	struct tegra_dc *dc = data;
1774dee8268fSThierry Reding 	unsigned long status;
1775dee8268fSThierry Reding 
1776dee8268fSThierry Reding 	status = tegra_dc_readl(dc, DC_CMD_INT_STATUS);
1777dee8268fSThierry Reding 	tegra_dc_writel(dc, status, DC_CMD_INT_STATUS);
1778dee8268fSThierry Reding 
1779dee8268fSThierry Reding 	if (status & FRAME_END_INT) {
1780dee8268fSThierry Reding 		/*
1781dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): frame end\n", __func__);
1782dee8268fSThierry Reding 		*/
1783791ddb1eSThierry Reding 		dc->stats.frames++;
1784dee8268fSThierry Reding 	}
1785dee8268fSThierry Reding 
1786dee8268fSThierry Reding 	if (status & VBLANK_INT) {
1787dee8268fSThierry Reding 		/*
1788dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): vertical blank\n", __func__);
1789dee8268fSThierry Reding 		*/
1790ed7dae58SThierry Reding 		drm_crtc_handle_vblank(&dc->base);
1791791ddb1eSThierry Reding 		dc->stats.vblank++;
1792dee8268fSThierry Reding 	}
1793dee8268fSThierry Reding 
1794dee8268fSThierry Reding 	if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) {
1795dee8268fSThierry Reding 		/*
1796dee8268fSThierry Reding 		dev_dbg(dc->dev, "%s(): underflow\n", __func__);
1797dee8268fSThierry Reding 		*/
1798791ddb1eSThierry Reding 		dc->stats.underflow++;
1799791ddb1eSThierry Reding 	}
1800791ddb1eSThierry Reding 
1801791ddb1eSThierry Reding 	if (status & (WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT)) {
1802791ddb1eSThierry Reding 		/*
1803791ddb1eSThierry Reding 		dev_dbg(dc->dev, "%s(): overflow\n", __func__);
1804791ddb1eSThierry Reding 		*/
1805791ddb1eSThierry Reding 		dc->stats.overflow++;
1806dee8268fSThierry Reding 	}
1807dee8268fSThierry Reding 
180847307954SThierry Reding 	if (status & HEAD_UF_INT) {
180947307954SThierry Reding 		dev_dbg_ratelimited(dc->dev, "%s(): head underflow\n", __func__);
181047307954SThierry Reding 		dc->stats.underflow++;
181147307954SThierry Reding 	}
181247307954SThierry Reding 
1813dee8268fSThierry Reding 	return IRQ_HANDLED;
1814dee8268fSThierry Reding }
1815dee8268fSThierry Reding 
1816dee8268fSThierry Reding static int tegra_dc_init(struct host1x_client *client)
1817dee8268fSThierry Reding {
18189910f5c4SThierry Reding 	struct drm_device *drm = dev_get_drvdata(client->parent);
1819bc8828bdSThierry Reding 	struct iommu_group *group = iommu_group_get(client->dev);
18202bcdcbfaSThierry Reding 	unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED;
1821dee8268fSThierry Reding 	struct tegra_dc *dc = host1x_client_to_dc(client);
1822d1f3e1e0SThierry Reding 	struct tegra_drm *tegra = drm->dev_private;
1823c7679306SThierry Reding 	struct drm_plane *primary = NULL;
1824c7679306SThierry Reding 	struct drm_plane *cursor = NULL;
1825dee8268fSThierry Reding 	int err;
1826dee8268fSThierry Reding 
1827617dd7ccSThierry Reding 	dc->syncpt = host1x_syncpt_request(client, flags);
18282bcdcbfaSThierry Reding 	if (!dc->syncpt)
18292bcdcbfaSThierry Reding 		dev_warn(dc->dev, "failed to allocate syncpoint\n");
18302bcdcbfaSThierry Reding 
1831bc8828bdSThierry Reding 	if (group && tegra->domain) {
1832bc8828bdSThierry Reding 		if (group != tegra->group) {
1833bc8828bdSThierry Reding 			err = iommu_attach_group(tegra->domain, group);
1834df06b759SThierry Reding 			if (err < 0) {
1835bc8828bdSThierry Reding 				dev_err(dc->dev,
1836bc8828bdSThierry Reding 					"failed to attach to domain: %d\n",
1837df06b759SThierry Reding 					err);
1838df06b759SThierry Reding 				return err;
1839df06b759SThierry Reding 			}
1840df06b759SThierry Reding 
1841bc8828bdSThierry Reding 			tegra->group = group;
1842bc8828bdSThierry Reding 		}
1843bc8828bdSThierry Reding 
1844df06b759SThierry Reding 		dc->domain = tegra->domain;
1845df06b759SThierry Reding 	}
1846df06b759SThierry Reding 
184747307954SThierry Reding 	if (dc->soc->wgrps)
184847307954SThierry Reding 		primary = tegra_dc_add_shared_planes(drm, dc);
184947307954SThierry Reding 	else
185047307954SThierry Reding 		primary = tegra_dc_add_planes(drm, dc);
185147307954SThierry Reding 
1852c7679306SThierry Reding 	if (IS_ERR(primary)) {
1853c7679306SThierry Reding 		err = PTR_ERR(primary);
1854c7679306SThierry Reding 		goto cleanup;
1855c7679306SThierry Reding 	}
1856c7679306SThierry Reding 
1857c7679306SThierry Reding 	if (dc->soc->supports_cursor) {
1858c7679306SThierry Reding 		cursor = tegra_dc_cursor_plane_create(drm, dc);
1859c7679306SThierry Reding 		if (IS_ERR(cursor)) {
1860c7679306SThierry Reding 			err = PTR_ERR(cursor);
1861c7679306SThierry Reding 			goto cleanup;
1862c7679306SThierry Reding 		}
1863c7679306SThierry Reding 	}
1864c7679306SThierry Reding 
1865c7679306SThierry Reding 	err = drm_crtc_init_with_planes(drm, &dc->base, primary, cursor,
1866f9882876SVille Syrjälä 					&tegra_crtc_funcs, NULL);
1867c7679306SThierry Reding 	if (err < 0)
1868c7679306SThierry Reding 		goto cleanup;
1869c7679306SThierry Reding 
1870dee8268fSThierry Reding 	drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs);
1871dee8268fSThierry Reding 
1872d1f3e1e0SThierry Reding 	/*
1873d1f3e1e0SThierry Reding 	 * Keep track of the minimum pitch alignment across all display
1874d1f3e1e0SThierry Reding 	 * controllers.
1875d1f3e1e0SThierry Reding 	 */
1876d1f3e1e0SThierry Reding 	if (dc->soc->pitch_align > tegra->pitch_align)
1877d1f3e1e0SThierry Reding 		tegra->pitch_align = dc->soc->pitch_align;
1878d1f3e1e0SThierry Reding 
18799910f5c4SThierry Reding 	err = tegra_dc_rgb_init(drm, dc);
1880dee8268fSThierry Reding 	if (err < 0 && err != -ENODEV) {
1881dee8268fSThierry Reding 		dev_err(dc->dev, "failed to initialize RGB output: %d\n", err);
1882c7679306SThierry Reding 		goto cleanup;
1883dee8268fSThierry Reding 	}
1884dee8268fSThierry Reding 
1885dee8268fSThierry Reding 	err = devm_request_irq(dc->dev, dc->irq, tegra_dc_irq, 0,
1886dee8268fSThierry Reding 			       dev_name(dc->dev), dc);
1887dee8268fSThierry Reding 	if (err < 0) {
1888dee8268fSThierry Reding 		dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq,
1889dee8268fSThierry Reding 			err);
1890c7679306SThierry Reding 		goto cleanup;
1891dee8268fSThierry Reding 	}
1892dee8268fSThierry Reding 
1893dee8268fSThierry Reding 	return 0;
1894c7679306SThierry Reding 
1895c7679306SThierry Reding cleanup:
189647307954SThierry Reding 	if (!IS_ERR_OR_NULL(cursor))
1897c7679306SThierry Reding 		drm_plane_cleanup(cursor);
1898c7679306SThierry Reding 
189947307954SThierry Reding 	if (!IS_ERR(primary))
1900c7679306SThierry Reding 		drm_plane_cleanup(primary);
1901c7679306SThierry Reding 
1902bc8828bdSThierry Reding 	if (group && tegra->domain) {
1903bc8828bdSThierry Reding 		iommu_detach_group(tegra->domain, group);
1904c7679306SThierry Reding 		dc->domain = NULL;
1905c7679306SThierry Reding 	}
1906c7679306SThierry Reding 
1907c7679306SThierry Reding 	return err;
1908dee8268fSThierry Reding }
1909dee8268fSThierry Reding 
1910dee8268fSThierry Reding static int tegra_dc_exit(struct host1x_client *client)
1911dee8268fSThierry Reding {
1912bc8828bdSThierry Reding 	struct iommu_group *group = iommu_group_get(client->dev);
1913dee8268fSThierry Reding 	struct tegra_dc *dc = host1x_client_to_dc(client);
1914dee8268fSThierry Reding 	int err;
1915dee8268fSThierry Reding 
1916dee8268fSThierry Reding 	devm_free_irq(dc->dev, dc->irq, dc);
1917dee8268fSThierry Reding 
1918dee8268fSThierry Reding 	err = tegra_dc_rgb_exit(dc);
1919dee8268fSThierry Reding 	if (err) {
1920dee8268fSThierry Reding 		dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err);
1921dee8268fSThierry Reding 		return err;
1922dee8268fSThierry Reding 	}
1923dee8268fSThierry Reding 
1924bc8828bdSThierry Reding 	if (group && dc->domain) {
1925bc8828bdSThierry Reding 		iommu_detach_group(dc->domain, group);
1926df06b759SThierry Reding 		dc->domain = NULL;
1927df06b759SThierry Reding 	}
1928df06b759SThierry Reding 
19292bcdcbfaSThierry Reding 	host1x_syncpt_free(dc->syncpt);
19302bcdcbfaSThierry Reding 
1931dee8268fSThierry Reding 	return 0;
1932dee8268fSThierry Reding }
1933dee8268fSThierry Reding 
1934dee8268fSThierry Reding static const struct host1x_client_ops dc_client_ops = {
1935dee8268fSThierry Reding 	.init = tegra_dc_init,
1936dee8268fSThierry Reding 	.exit = tegra_dc_exit,
1937dee8268fSThierry Reding };
1938dee8268fSThierry Reding 
19398620fc62SThierry Reding static const struct tegra_dc_soc_info tegra20_dc_soc_info = {
19407116e9a8SThierry Reding 	.supports_background_color = false,
19418620fc62SThierry Reding 	.supports_interlacing = false,
1942e687651bSThierry Reding 	.supports_cursor = false,
1943c134f019SThierry Reding 	.supports_block_linear = false,
1944ab7d3f58SThierry Reding 	.supports_blending = false,
1945d1f3e1e0SThierry Reding 	.pitch_align = 8,
19469c012700SThierry Reding 	.has_powergate = false,
1947f68ba691SDmitry Osipenko 	.coupled_pm = true,
194847307954SThierry Reding 	.has_nvdisplay = false,
1949511c7023SThierry Reding 	.num_primary_formats = ARRAY_SIZE(tegra20_primary_formats),
1950511c7023SThierry Reding 	.primary_formats = tegra20_primary_formats,
1951511c7023SThierry Reding 	.num_overlay_formats = ARRAY_SIZE(tegra20_overlay_formats),
1952511c7023SThierry Reding 	.overlay_formats = tegra20_overlay_formats,
19538620fc62SThierry Reding };
19548620fc62SThierry Reding 
19558620fc62SThierry Reding static const struct tegra_dc_soc_info tegra30_dc_soc_info = {
19567116e9a8SThierry Reding 	.supports_background_color = false,
19578620fc62SThierry Reding 	.supports_interlacing = false,
1958e687651bSThierry Reding 	.supports_cursor = false,
1959c134f019SThierry Reding 	.supports_block_linear = false,
1960ab7d3f58SThierry Reding 	.supports_blending = false,
1961d1f3e1e0SThierry Reding 	.pitch_align = 8,
19629c012700SThierry Reding 	.has_powergate = false,
1963f68ba691SDmitry Osipenko 	.coupled_pm = false,
196447307954SThierry Reding 	.has_nvdisplay = false,
1965511c7023SThierry Reding 	.num_primary_formats = ARRAY_SIZE(tegra20_primary_formats),
1966511c7023SThierry Reding 	.primary_formats = tegra20_primary_formats,
1967511c7023SThierry Reding 	.num_overlay_formats = ARRAY_SIZE(tegra20_overlay_formats),
1968511c7023SThierry Reding 	.overlay_formats = tegra20_overlay_formats,
1969d1f3e1e0SThierry Reding };
1970d1f3e1e0SThierry Reding 
1971d1f3e1e0SThierry Reding static const struct tegra_dc_soc_info tegra114_dc_soc_info = {
19727116e9a8SThierry Reding 	.supports_background_color = false,
1973d1f3e1e0SThierry Reding 	.supports_interlacing = false,
1974d1f3e1e0SThierry Reding 	.supports_cursor = false,
1975d1f3e1e0SThierry Reding 	.supports_block_linear = false,
1976ab7d3f58SThierry Reding 	.supports_blending = false,
1977d1f3e1e0SThierry Reding 	.pitch_align = 64,
19789c012700SThierry Reding 	.has_powergate = true,
1979f68ba691SDmitry Osipenko 	.coupled_pm = false,
198047307954SThierry Reding 	.has_nvdisplay = false,
1981511c7023SThierry Reding 	.num_primary_formats = ARRAY_SIZE(tegra114_primary_formats),
1982511c7023SThierry Reding 	.primary_formats = tegra114_primary_formats,
1983511c7023SThierry Reding 	.num_overlay_formats = ARRAY_SIZE(tegra114_overlay_formats),
1984511c7023SThierry Reding 	.overlay_formats = tegra114_overlay_formats,
19858620fc62SThierry Reding };
19868620fc62SThierry Reding 
19878620fc62SThierry Reding static const struct tegra_dc_soc_info tegra124_dc_soc_info = {
19887116e9a8SThierry Reding 	.supports_background_color = true,
19898620fc62SThierry Reding 	.supports_interlacing = true,
1990e687651bSThierry Reding 	.supports_cursor = true,
1991c134f019SThierry Reding 	.supports_block_linear = true,
1992ab7d3f58SThierry Reding 	.supports_blending = true,
1993d1f3e1e0SThierry Reding 	.pitch_align = 64,
19949c012700SThierry Reding 	.has_powergate = true,
1995f68ba691SDmitry Osipenko 	.coupled_pm = false,
199647307954SThierry Reding 	.has_nvdisplay = false,
1997511c7023SThierry Reding 	.num_primary_formats = ARRAY_SIZE(tegra124_primary_formats),
1998511c7023SThierry Reding 	.primary_formats = tegra114_primary_formats,
1999511c7023SThierry Reding 	.num_overlay_formats = ARRAY_SIZE(tegra124_overlay_formats),
2000511c7023SThierry Reding 	.overlay_formats = tegra114_overlay_formats,
20018620fc62SThierry Reding };
20028620fc62SThierry Reding 
20035b4f516fSThierry Reding static const struct tegra_dc_soc_info tegra210_dc_soc_info = {
20047116e9a8SThierry Reding 	.supports_background_color = true,
20055b4f516fSThierry Reding 	.supports_interlacing = true,
20065b4f516fSThierry Reding 	.supports_cursor = true,
20075b4f516fSThierry Reding 	.supports_block_linear = true,
2008ab7d3f58SThierry Reding 	.supports_blending = true,
20095b4f516fSThierry Reding 	.pitch_align = 64,
20105b4f516fSThierry Reding 	.has_powergate = true,
2011f68ba691SDmitry Osipenko 	.coupled_pm = false,
201247307954SThierry Reding 	.has_nvdisplay = false,
2013511c7023SThierry Reding 	.num_primary_formats = ARRAY_SIZE(tegra114_primary_formats),
2014511c7023SThierry Reding 	.primary_formats = tegra114_primary_formats,
2015511c7023SThierry Reding 	.num_overlay_formats = ARRAY_SIZE(tegra114_overlay_formats),
2016511c7023SThierry Reding 	.overlay_formats = tegra114_overlay_formats,
201747307954SThierry Reding };
201847307954SThierry Reding 
201947307954SThierry Reding static const struct tegra_windowgroup_soc tegra186_dc_wgrps[] = {
202047307954SThierry Reding 	{
202147307954SThierry Reding 		.index = 0,
202247307954SThierry Reding 		.dc = 0,
202347307954SThierry Reding 		.windows = (const unsigned int[]) { 0 },
202447307954SThierry Reding 		.num_windows = 1,
202547307954SThierry Reding 	}, {
202647307954SThierry Reding 		.index = 1,
202747307954SThierry Reding 		.dc = 1,
202847307954SThierry Reding 		.windows = (const unsigned int[]) { 1 },
202947307954SThierry Reding 		.num_windows = 1,
203047307954SThierry Reding 	}, {
203147307954SThierry Reding 		.index = 2,
203247307954SThierry Reding 		.dc = 1,
203347307954SThierry Reding 		.windows = (const unsigned int[]) { 2 },
203447307954SThierry Reding 		.num_windows = 1,
203547307954SThierry Reding 	}, {
203647307954SThierry Reding 		.index = 3,
203747307954SThierry Reding 		.dc = 2,
203847307954SThierry Reding 		.windows = (const unsigned int[]) { 3 },
203947307954SThierry Reding 		.num_windows = 1,
204047307954SThierry Reding 	}, {
204147307954SThierry Reding 		.index = 4,
204247307954SThierry Reding 		.dc = 2,
204347307954SThierry Reding 		.windows = (const unsigned int[]) { 4 },
204447307954SThierry Reding 		.num_windows = 1,
204547307954SThierry Reding 	}, {
204647307954SThierry Reding 		.index = 5,
204747307954SThierry Reding 		.dc = 2,
204847307954SThierry Reding 		.windows = (const unsigned int[]) { 5 },
204947307954SThierry Reding 		.num_windows = 1,
205047307954SThierry Reding 	},
205147307954SThierry Reding };
205247307954SThierry Reding 
205347307954SThierry Reding static const struct tegra_dc_soc_info tegra186_dc_soc_info = {
205447307954SThierry Reding 	.supports_background_color = true,
205547307954SThierry Reding 	.supports_interlacing = true,
205647307954SThierry Reding 	.supports_cursor = true,
205747307954SThierry Reding 	.supports_block_linear = true,
2058ab7d3f58SThierry Reding 	.supports_blending = true,
205947307954SThierry Reding 	.pitch_align = 64,
206047307954SThierry Reding 	.has_powergate = false,
2061f68ba691SDmitry Osipenko 	.coupled_pm = false,
206247307954SThierry Reding 	.has_nvdisplay = true,
206347307954SThierry Reding 	.wgrps = tegra186_dc_wgrps,
206447307954SThierry Reding 	.num_wgrps = ARRAY_SIZE(tegra186_dc_wgrps),
20655b4f516fSThierry Reding };
20665b4f516fSThierry Reding 
20678620fc62SThierry Reding static const struct of_device_id tegra_dc_of_match[] = {
20688620fc62SThierry Reding 	{
206947307954SThierry Reding 		.compatible = "nvidia,tegra186-dc",
207047307954SThierry Reding 		.data = &tegra186_dc_soc_info,
207147307954SThierry Reding 	}, {
20725b4f516fSThierry Reding 		.compatible = "nvidia,tegra210-dc",
20735b4f516fSThierry Reding 		.data = &tegra210_dc_soc_info,
20745b4f516fSThierry Reding 	}, {
20758620fc62SThierry Reding 		.compatible = "nvidia,tegra124-dc",
20768620fc62SThierry Reding 		.data = &tegra124_dc_soc_info,
20778620fc62SThierry Reding 	}, {
20789c012700SThierry Reding 		.compatible = "nvidia,tegra114-dc",
20799c012700SThierry Reding 		.data = &tegra114_dc_soc_info,
20809c012700SThierry Reding 	}, {
20818620fc62SThierry Reding 		.compatible = "nvidia,tegra30-dc",
20828620fc62SThierry Reding 		.data = &tegra30_dc_soc_info,
20838620fc62SThierry Reding 	}, {
20848620fc62SThierry Reding 		.compatible = "nvidia,tegra20-dc",
20858620fc62SThierry Reding 		.data = &tegra20_dc_soc_info,
20868620fc62SThierry Reding 	}, {
20878620fc62SThierry Reding 		/* sentinel */
20888620fc62SThierry Reding 	}
20898620fc62SThierry Reding };
2090ef70728cSStephen Warren MODULE_DEVICE_TABLE(of, tegra_dc_of_match);
20918620fc62SThierry Reding 
209213411dddSThierry Reding static int tegra_dc_parse_dt(struct tegra_dc *dc)
209313411dddSThierry Reding {
209413411dddSThierry Reding 	struct device_node *np;
209513411dddSThierry Reding 	u32 value = 0;
209613411dddSThierry Reding 	int err;
209713411dddSThierry Reding 
209813411dddSThierry Reding 	err = of_property_read_u32(dc->dev->of_node, "nvidia,head", &value);
209913411dddSThierry Reding 	if (err < 0) {
210013411dddSThierry Reding 		dev_err(dc->dev, "missing \"nvidia,head\" property\n");
210113411dddSThierry Reding 
210213411dddSThierry Reding 		/*
210313411dddSThierry Reding 		 * If the nvidia,head property isn't present, try to find the
210413411dddSThierry Reding 		 * correct head number by looking up the position of this
210513411dddSThierry Reding 		 * display controller's node within the device tree. Assuming
210613411dddSThierry Reding 		 * that the nodes are ordered properly in the DTS file and
210713411dddSThierry Reding 		 * that the translation into a flattened device tree blob
210813411dddSThierry Reding 		 * preserves that ordering this will actually yield the right
210913411dddSThierry Reding 		 * head number.
211013411dddSThierry Reding 		 *
211113411dddSThierry Reding 		 * If those assumptions don't hold, this will still work for
211213411dddSThierry Reding 		 * cases where only a single display controller is used.
211313411dddSThierry Reding 		 */
211413411dddSThierry Reding 		for_each_matching_node(np, tegra_dc_of_match) {
2115cf6b1744SJulia Lawall 			if (np == dc->dev->of_node) {
2116cf6b1744SJulia Lawall 				of_node_put(np);
211713411dddSThierry Reding 				break;
2118cf6b1744SJulia Lawall 			}
211913411dddSThierry Reding 
212013411dddSThierry Reding 			value++;
212113411dddSThierry Reding 		}
212213411dddSThierry Reding 	}
212313411dddSThierry Reding 
212413411dddSThierry Reding 	dc->pipe = value;
212513411dddSThierry Reding 
212613411dddSThierry Reding 	return 0;
212713411dddSThierry Reding }
212813411dddSThierry Reding 
2129f68ba691SDmitry Osipenko static int tegra_dc_match_by_pipe(struct device *dev, void *data)
2130f68ba691SDmitry Osipenko {
2131f68ba691SDmitry Osipenko 	struct tegra_dc *dc = dev_get_drvdata(dev);
2132f68ba691SDmitry Osipenko 	unsigned int pipe = (unsigned long)data;
2133f68ba691SDmitry Osipenko 
2134f68ba691SDmitry Osipenko 	return dc->pipe == pipe;
2135f68ba691SDmitry Osipenko }
2136f68ba691SDmitry Osipenko 
2137f68ba691SDmitry Osipenko static int tegra_dc_couple(struct tegra_dc *dc)
2138f68ba691SDmitry Osipenko {
2139f68ba691SDmitry Osipenko 	/*
2140f68ba691SDmitry Osipenko 	 * On Tegra20, DC1 requires DC0 to be taken out of reset in order to
2141f68ba691SDmitry Osipenko 	 * be enabled, otherwise CPU hangs on writing to CMD_DISPLAY_COMMAND /
2142f68ba691SDmitry Osipenko 	 * POWER_CONTROL registers during CRTC enabling.
2143f68ba691SDmitry Osipenko 	 */
2144f68ba691SDmitry Osipenko 	if (dc->soc->coupled_pm && dc->pipe == 1) {
2145f68ba691SDmitry Osipenko 		u32 flags = DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE;
2146f68ba691SDmitry Osipenko 		struct device_link *link;
2147f68ba691SDmitry Osipenko 		struct device *partner;
2148f68ba691SDmitry Osipenko 
2149f68ba691SDmitry Osipenko 		partner = driver_find_device(dc->dev->driver, NULL, 0,
2150f68ba691SDmitry Osipenko 					     tegra_dc_match_by_pipe);
2151f68ba691SDmitry Osipenko 		if (!partner)
2152f68ba691SDmitry Osipenko 			return -EPROBE_DEFER;
2153f68ba691SDmitry Osipenko 
2154f68ba691SDmitry Osipenko 		link = device_link_add(dc->dev, partner, flags);
2155f68ba691SDmitry Osipenko 		if (!link) {
2156f68ba691SDmitry Osipenko 			dev_err(dc->dev, "failed to link controllers\n");
2157f68ba691SDmitry Osipenko 			return -EINVAL;
2158f68ba691SDmitry Osipenko 		}
2159f68ba691SDmitry Osipenko 
2160f68ba691SDmitry Osipenko 		dev_dbg(dc->dev, "coupled to %s\n", dev_name(partner));
2161f68ba691SDmitry Osipenko 	}
2162f68ba691SDmitry Osipenko 
2163f68ba691SDmitry Osipenko 	return 0;
2164f68ba691SDmitry Osipenko }
2165f68ba691SDmitry Osipenko 
2166dee8268fSThierry Reding static int tegra_dc_probe(struct platform_device *pdev)
2167dee8268fSThierry Reding {
2168dee8268fSThierry Reding 	struct resource *regs;
2169dee8268fSThierry Reding 	struct tegra_dc *dc;
2170dee8268fSThierry Reding 	int err;
2171dee8268fSThierry Reding 
2172dee8268fSThierry Reding 	dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
2173dee8268fSThierry Reding 	if (!dc)
2174dee8268fSThierry Reding 		return -ENOMEM;
2175dee8268fSThierry Reding 
2176b9ff7aeaSThierry Reding 	dc->soc = of_device_get_match_data(&pdev->dev);
21778620fc62SThierry Reding 
2178dee8268fSThierry Reding 	INIT_LIST_HEAD(&dc->list);
2179dee8268fSThierry Reding 	dc->dev = &pdev->dev;
2180dee8268fSThierry Reding 
218113411dddSThierry Reding 	err = tegra_dc_parse_dt(dc);
218213411dddSThierry Reding 	if (err < 0)
218313411dddSThierry Reding 		return err;
218413411dddSThierry Reding 
2185f68ba691SDmitry Osipenko 	err = tegra_dc_couple(dc);
2186f68ba691SDmitry Osipenko 	if (err < 0)
2187f68ba691SDmitry Osipenko 		return err;
2188f68ba691SDmitry Osipenko 
2189dee8268fSThierry Reding 	dc->clk = devm_clk_get(&pdev->dev, NULL);
2190dee8268fSThierry Reding 	if (IS_ERR(dc->clk)) {
2191dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to get clock\n");
2192dee8268fSThierry Reding 		return PTR_ERR(dc->clk);
2193dee8268fSThierry Reding 	}
2194dee8268fSThierry Reding 
2195ca48080aSStephen Warren 	dc->rst = devm_reset_control_get(&pdev->dev, "dc");
2196ca48080aSStephen Warren 	if (IS_ERR(dc->rst)) {
2197ca48080aSStephen Warren 		dev_err(&pdev->dev, "failed to get reset\n");
2198ca48080aSStephen Warren 		return PTR_ERR(dc->rst);
2199ca48080aSStephen Warren 	}
2200ca48080aSStephen Warren 
2201a2f2f740SThierry Reding 	/* assert reset and disable clock */
2202a2f2f740SThierry Reding 	err = clk_prepare_enable(dc->clk);
2203a2f2f740SThierry Reding 	if (err < 0)
2204a2f2f740SThierry Reding 		return err;
2205a2f2f740SThierry Reding 
2206a2f2f740SThierry Reding 	usleep_range(2000, 4000);
2207a2f2f740SThierry Reding 
2208a2f2f740SThierry Reding 	err = reset_control_assert(dc->rst);
2209a2f2f740SThierry Reding 	if (err < 0)
2210a2f2f740SThierry Reding 		return err;
2211a2f2f740SThierry Reding 
2212a2f2f740SThierry Reding 	usleep_range(2000, 4000);
2213a2f2f740SThierry Reding 
2214a2f2f740SThierry Reding 	clk_disable_unprepare(dc->clk);
221533a8eb8dSThierry Reding 
22169c012700SThierry Reding 	if (dc->soc->has_powergate) {
22179c012700SThierry Reding 		if (dc->pipe == 0)
22189c012700SThierry Reding 			dc->powergate = TEGRA_POWERGATE_DIS;
22199c012700SThierry Reding 		else
22209c012700SThierry Reding 			dc->powergate = TEGRA_POWERGATE_DISB;
22219c012700SThierry Reding 
222233a8eb8dSThierry Reding 		tegra_powergate_power_off(dc->powergate);
22239c012700SThierry Reding 	}
2224dee8268fSThierry Reding 
2225dee8268fSThierry Reding 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2226dee8268fSThierry Reding 	dc->regs = devm_ioremap_resource(&pdev->dev, regs);
2227dee8268fSThierry Reding 	if (IS_ERR(dc->regs))
2228dee8268fSThierry Reding 		return PTR_ERR(dc->regs);
2229dee8268fSThierry Reding 
2230dee8268fSThierry Reding 	dc->irq = platform_get_irq(pdev, 0);
2231dee8268fSThierry Reding 	if (dc->irq < 0) {
2232dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to get IRQ\n");
2233dee8268fSThierry Reding 		return -ENXIO;
2234dee8268fSThierry Reding 	}
2235dee8268fSThierry Reding 
2236dee8268fSThierry Reding 	err = tegra_dc_rgb_probe(dc);
2237dee8268fSThierry Reding 	if (err < 0 && err != -ENODEV) {
2238dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err);
2239dee8268fSThierry Reding 		return err;
2240dee8268fSThierry Reding 	}
2241dee8268fSThierry Reding 
224233a8eb8dSThierry Reding 	platform_set_drvdata(pdev, dc);
224333a8eb8dSThierry Reding 	pm_runtime_enable(&pdev->dev);
224433a8eb8dSThierry Reding 
224533a8eb8dSThierry Reding 	INIT_LIST_HEAD(&dc->client.list);
224633a8eb8dSThierry Reding 	dc->client.ops = &dc_client_ops;
224733a8eb8dSThierry Reding 	dc->client.dev = &pdev->dev;
224833a8eb8dSThierry Reding 
2249dee8268fSThierry Reding 	err = host1x_client_register(&dc->client);
2250dee8268fSThierry Reding 	if (err < 0) {
2251dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to register host1x client: %d\n",
2252dee8268fSThierry Reding 			err);
2253dee8268fSThierry Reding 		return err;
2254dee8268fSThierry Reding 	}
2255dee8268fSThierry Reding 
2256dee8268fSThierry Reding 	return 0;
2257dee8268fSThierry Reding }
2258dee8268fSThierry Reding 
2259dee8268fSThierry Reding static int tegra_dc_remove(struct platform_device *pdev)
2260dee8268fSThierry Reding {
2261dee8268fSThierry Reding 	struct tegra_dc *dc = platform_get_drvdata(pdev);
2262dee8268fSThierry Reding 	int err;
2263dee8268fSThierry Reding 
2264dee8268fSThierry Reding 	err = host1x_client_unregister(&dc->client);
2265dee8268fSThierry Reding 	if (err < 0) {
2266dee8268fSThierry Reding 		dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
2267dee8268fSThierry Reding 			err);
2268dee8268fSThierry Reding 		return err;
2269dee8268fSThierry Reding 	}
2270dee8268fSThierry Reding 
227159d29c0eSThierry Reding 	err = tegra_dc_rgb_remove(dc);
227259d29c0eSThierry Reding 	if (err < 0) {
227359d29c0eSThierry Reding 		dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err);
227459d29c0eSThierry Reding 		return err;
227559d29c0eSThierry Reding 	}
227659d29c0eSThierry Reding 
227733a8eb8dSThierry Reding 	pm_runtime_disable(&pdev->dev);
227833a8eb8dSThierry Reding 
227933a8eb8dSThierry Reding 	return 0;
228033a8eb8dSThierry Reding }
228133a8eb8dSThierry Reding 
228233a8eb8dSThierry Reding #ifdef CONFIG_PM
228333a8eb8dSThierry Reding static int tegra_dc_suspend(struct device *dev)
228433a8eb8dSThierry Reding {
228533a8eb8dSThierry Reding 	struct tegra_dc *dc = dev_get_drvdata(dev);
228633a8eb8dSThierry Reding 	int err;
228733a8eb8dSThierry Reding 
228833a8eb8dSThierry Reding 	err = reset_control_assert(dc->rst);
228933a8eb8dSThierry Reding 	if (err < 0) {
229033a8eb8dSThierry Reding 		dev_err(dev, "failed to assert reset: %d\n", err);
229133a8eb8dSThierry Reding 		return err;
229233a8eb8dSThierry Reding 	}
22939c012700SThierry Reding 
22949c012700SThierry Reding 	if (dc->soc->has_powergate)
22959c012700SThierry Reding 		tegra_powergate_power_off(dc->powergate);
22969c012700SThierry Reding 
2297dee8268fSThierry Reding 	clk_disable_unprepare(dc->clk);
2298dee8268fSThierry Reding 
2299dee8268fSThierry Reding 	return 0;
2300dee8268fSThierry Reding }
2301dee8268fSThierry Reding 
230233a8eb8dSThierry Reding static int tegra_dc_resume(struct device *dev)
230333a8eb8dSThierry Reding {
230433a8eb8dSThierry Reding 	struct tegra_dc *dc = dev_get_drvdata(dev);
230533a8eb8dSThierry Reding 	int err;
230633a8eb8dSThierry Reding 
230733a8eb8dSThierry Reding 	if (dc->soc->has_powergate) {
230833a8eb8dSThierry Reding 		err = tegra_powergate_sequence_power_up(dc->powergate, dc->clk,
230933a8eb8dSThierry Reding 							dc->rst);
231033a8eb8dSThierry Reding 		if (err < 0) {
231133a8eb8dSThierry Reding 			dev_err(dev, "failed to power partition: %d\n", err);
231233a8eb8dSThierry Reding 			return err;
231333a8eb8dSThierry Reding 		}
231433a8eb8dSThierry Reding 	} else {
231533a8eb8dSThierry Reding 		err = clk_prepare_enable(dc->clk);
231633a8eb8dSThierry Reding 		if (err < 0) {
231733a8eb8dSThierry Reding 			dev_err(dev, "failed to enable clock: %d\n", err);
231833a8eb8dSThierry Reding 			return err;
231933a8eb8dSThierry Reding 		}
232033a8eb8dSThierry Reding 
232133a8eb8dSThierry Reding 		err = reset_control_deassert(dc->rst);
232233a8eb8dSThierry Reding 		if (err < 0) {
2323f68ba691SDmitry Osipenko 			dev_err(dev, "failed to deassert reset: %d\n", err);
232433a8eb8dSThierry Reding 			return err;
232533a8eb8dSThierry Reding 		}
232633a8eb8dSThierry Reding 	}
232733a8eb8dSThierry Reding 
232833a8eb8dSThierry Reding 	return 0;
232933a8eb8dSThierry Reding }
233033a8eb8dSThierry Reding #endif
233133a8eb8dSThierry Reding 
233233a8eb8dSThierry Reding static const struct dev_pm_ops tegra_dc_pm_ops = {
233333a8eb8dSThierry Reding 	SET_RUNTIME_PM_OPS(tegra_dc_suspend, tegra_dc_resume, NULL)
233433a8eb8dSThierry Reding };
233533a8eb8dSThierry Reding 
2336dee8268fSThierry Reding struct platform_driver tegra_dc_driver = {
2337dee8268fSThierry Reding 	.driver = {
2338dee8268fSThierry Reding 		.name = "tegra-dc",
2339dee8268fSThierry Reding 		.of_match_table = tegra_dc_of_match,
234033a8eb8dSThierry Reding 		.pm = &tegra_dc_pm_ops,
2341dee8268fSThierry Reding 	},
2342dee8268fSThierry Reding 	.probe = tegra_dc_probe,
2343dee8268fSThierry Reding 	.remove = tegra_dc_remove,
2344dee8268fSThierry Reding };
2345