11c248b7dSInki Dae /* exynos_drm_crtc.c
21c248b7dSInki Dae  *
31c248b7dSInki Dae  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
41c248b7dSInki Dae  * Authors:
51c248b7dSInki Dae  *	Inki Dae <inki.dae@samsung.com>
61c248b7dSInki Dae  *	Joonyoung Shim <jy0922.shim@samsung.com>
71c248b7dSInki Dae  *	Seung-Woo Kim <sw0312.kim@samsung.com>
81c248b7dSInki Dae  *
91c248b7dSInki Dae  * Permission is hereby granted, free of charge, to any person obtaining a
101c248b7dSInki Dae  * copy of this software and associated documentation files (the "Software"),
111c248b7dSInki Dae  * to deal in the Software without restriction, including without limitation
121c248b7dSInki Dae  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
131c248b7dSInki Dae  * and/or sell copies of the Software, and to permit persons to whom the
141c248b7dSInki Dae  * Software is furnished to do so, subject to the following conditions:
151c248b7dSInki Dae  *
161c248b7dSInki Dae  * The above copyright notice and this permission notice (including the next
171c248b7dSInki Dae  * paragraph) shall be included in all copies or substantial portions of the
181c248b7dSInki Dae  * Software.
191c248b7dSInki Dae  *
201c248b7dSInki Dae  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
211c248b7dSInki Dae  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
221c248b7dSInki Dae  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
231c248b7dSInki Dae  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
241c248b7dSInki Dae  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
251c248b7dSInki Dae  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
261c248b7dSInki Dae  * OTHER DEALINGS IN THE SOFTWARE.
271c248b7dSInki Dae  */
281c248b7dSInki Dae 
291c248b7dSInki Dae #include "drmP.h"
301c248b7dSInki Dae #include "drm_crtc_helper.h"
311c248b7dSInki Dae 
321c248b7dSInki Dae #include "exynos_drm_drv.h"
331c248b7dSInki Dae #include "exynos_drm_encoder.h"
34b5d2eb3bSJoonyoung Shim #include "exynos_drm_plane.h"
351c248b7dSInki Dae 
361c248b7dSInki Dae #define to_exynos_crtc(x)	container_of(x, struct exynos_drm_crtc,\
371c248b7dSInki Dae 				drm_crtc)
381c248b7dSInki Dae 
393b8d1cf8SJoonyoung Shim enum exynos_crtc_mode {
403b8d1cf8SJoonyoung Shim 	CRTC_MODE_NORMAL,	/* normal mode */
413b8d1cf8SJoonyoung Shim 	CRTC_MODE_BLANK,	/* The private plane of crtc is blank */
423b8d1cf8SJoonyoung Shim };
433b8d1cf8SJoonyoung Shim 
441c248b7dSInki Dae /*
451c248b7dSInki Dae  * Exynos specific crtc structure.
461c248b7dSInki Dae  *
471c248b7dSInki Dae  * @drm_crtc: crtc object.
48b5d2eb3bSJoonyoung Shim  * @drm_plane: pointer of private plane object for this crtc
491c248b7dSInki Dae  * @pipe: a crtc index created at load() with a new crtc object creation
501c248b7dSInki Dae  *	and the crtc object would be set to private->crtc array
511c248b7dSInki Dae  *	to get a crtc object corresponding to this pipe from private->crtc
521c248b7dSInki Dae  *	array when irq interrupt occured. the reason of using this pipe is that
531c248b7dSInki Dae  *	drm framework doesn't support multiple irq yet.
541c248b7dSInki Dae  *	we can refer to the crtc to current hardware interrupt occured through
551c248b7dSInki Dae  *	this pipe value.
56ec05da95SInki Dae  * @dpms: store the crtc dpms value
573b8d1cf8SJoonyoung Shim  * @mode: store the crtc mode value
581c248b7dSInki Dae  */
591c248b7dSInki Dae struct exynos_drm_crtc {
601c248b7dSInki Dae 	struct drm_crtc			drm_crtc;
61b5d2eb3bSJoonyoung Shim 	struct drm_plane		*plane;
621c248b7dSInki Dae 	unsigned int			pipe;
63ec05da95SInki Dae 	unsigned int			dpms;
643b8d1cf8SJoonyoung Shim 	enum exynos_crtc_mode		mode;
651c248b7dSInki Dae };
661c248b7dSInki Dae 
671c248b7dSInki Dae static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
681c248b7dSInki Dae {
69d2716c89SJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
701c248b7dSInki Dae 
71d2716c89SJoonyoung Shim 	DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode);
72d2716c89SJoonyoung Shim 
73ec05da95SInki Dae 	if (exynos_crtc->dpms == mode) {
74ec05da95SInki Dae 		DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n");
75ec05da95SInki Dae 		return;
76ec05da95SInki Dae 	}
77ec05da95SInki Dae 
78cf5188acSJoonyoung Shim 	exynos_drm_fn_encoder(crtc, &mode, exynos_drm_encoder_crtc_dpms);
79ec05da95SInki Dae 	exynos_crtc->dpms = mode;
801c248b7dSInki Dae }
811c248b7dSInki Dae 
821c248b7dSInki Dae static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
831c248b7dSInki Dae {
841c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
851c248b7dSInki Dae 
861c248b7dSInki Dae 	/* drm framework doesn't check NULL. */
871c248b7dSInki Dae }
881c248b7dSInki Dae 
891c248b7dSInki Dae static void exynos_drm_crtc_commit(struct drm_crtc *crtc)
901c248b7dSInki Dae {
91d2716c89SJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
92d2716c89SJoonyoung Shim 
931c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
941c248b7dSInki Dae 
9550caf25cSInki Dae 	exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
964070d212SJoonyoung Shim 	exynos_plane_commit(exynos_crtc->plane);
97cf5188acSJoonyoung Shim 	exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_ON);
981c248b7dSInki Dae }
991c248b7dSInki Dae 
1001c248b7dSInki Dae static bool
1011c248b7dSInki Dae exynos_drm_crtc_mode_fixup(struct drm_crtc *crtc,
102e811f5aeSLaurent Pinchart 			    const struct drm_display_mode *mode,
1031c248b7dSInki Dae 			    struct drm_display_mode *adjusted_mode)
1041c248b7dSInki Dae {
1051c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
1061c248b7dSInki Dae 
1071c248b7dSInki Dae 	/* drm framework doesn't check NULL */
1081c248b7dSInki Dae 	return true;
1091c248b7dSInki Dae }
1101c248b7dSInki Dae 
1111c248b7dSInki Dae static int
1121c248b7dSInki Dae exynos_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
1131c248b7dSInki Dae 			  struct drm_display_mode *adjusted_mode, int x, int y,
1141c248b7dSInki Dae 			  struct drm_framebuffer *old_fb)
1151c248b7dSInki Dae {
116aeb29224SJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
1174070d212SJoonyoung Shim 	struct drm_plane *plane = exynos_crtc->plane;
1184070d212SJoonyoung Shim 	unsigned int crtc_w;
1194070d212SJoonyoung Shim 	unsigned int crtc_h;
120d249ce02SJoonyoung Shim 	int pipe = exynos_crtc->pipe;
121aeb29224SJoonyoung Shim 	int ret;
122aeb29224SJoonyoung Shim 
1231c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
1241c248b7dSInki Dae 
1251de425b0SInki Dae 	/*
1261de425b0SInki Dae 	 * copy the mode data adjusted by mode_fixup() into crtc->mode
1271de425b0SInki Dae 	 * so that hardware can be seet to proper mode.
1281de425b0SInki Dae 	 */
1291de425b0SInki Dae 	memcpy(&crtc->mode, adjusted_mode, sizeof(*adjusted_mode));
1301c248b7dSInki Dae 
1314070d212SJoonyoung Shim 	crtc_w = crtc->fb->width - x;
1324070d212SJoonyoung Shim 	crtc_h = crtc->fb->height - y;
1334070d212SJoonyoung Shim 
1344070d212SJoonyoung Shim 	ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
1354070d212SJoonyoung Shim 				    x, y, crtc_w, crtc_h);
136aeb29224SJoonyoung Shim 	if (ret)
137aeb29224SJoonyoung Shim 		return ret;
138aeb29224SJoonyoung Shim 
1394070d212SJoonyoung Shim 	plane->crtc = crtc;
1404070d212SJoonyoung Shim 	plane->fb = crtc->fb;
1414070d212SJoonyoung Shim 
142d249ce02SJoonyoung Shim 	exynos_drm_fn_encoder(crtc, &pipe, exynos_drm_encoder_crtc_pipe);
143aeb29224SJoonyoung Shim 
144aeb29224SJoonyoung Shim 	return 0;
1451c248b7dSInki Dae }
1461c248b7dSInki Dae 
1471c248b7dSInki Dae static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
1481c248b7dSInki Dae 					  struct drm_framebuffer *old_fb)
1491c248b7dSInki Dae {
1504070d212SJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
1514070d212SJoonyoung Shim 	struct drm_plane *plane = exynos_crtc->plane;
1524070d212SJoonyoung Shim 	unsigned int crtc_w;
1534070d212SJoonyoung Shim 	unsigned int crtc_h;
1541c248b7dSInki Dae 	int ret;
1551c248b7dSInki Dae 
1561c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
1571c248b7dSInki Dae 
1584070d212SJoonyoung Shim 	crtc_w = crtc->fb->width - x;
1594070d212SJoonyoung Shim 	crtc_h = crtc->fb->height - y;
1604070d212SJoonyoung Shim 
1614070d212SJoonyoung Shim 	ret = exynos_plane_mode_set(plane, crtc, crtc->fb, 0, 0, crtc_w, crtc_h,
1624070d212SJoonyoung Shim 				    x, y, crtc_w, crtc_h);
1631c248b7dSInki Dae 	if (ret)
1641c248b7dSInki Dae 		return ret;
1651c248b7dSInki Dae 
166bebab8ffSJoonyoung Shim 	exynos_drm_crtc_commit(crtc);
1671c248b7dSInki Dae 
1684070d212SJoonyoung Shim 	return 0;
1691c248b7dSInki Dae }
1701c248b7dSInki Dae 
1711c248b7dSInki Dae static void exynos_drm_crtc_load_lut(struct drm_crtc *crtc)
1721c248b7dSInki Dae {
1731c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
1741c248b7dSInki Dae 	/* drm framework doesn't check NULL */
1751c248b7dSInki Dae }
1761c248b7dSInki Dae 
177a365d9ebSJoonyoung Shim static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
178a365d9ebSJoonyoung Shim {
179a365d9ebSJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
180a365d9ebSJoonyoung Shim 
181a365d9ebSJoonyoung Shim 	DRM_DEBUG_KMS("%s\n", __FILE__);
182a365d9ebSJoonyoung Shim 
183a365d9ebSJoonyoung Shim 	exynos_plane_dpms(exynos_crtc->plane, DRM_MODE_DPMS_OFF);
184a365d9ebSJoonyoung Shim 	exynos_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
185a365d9ebSJoonyoung Shim }
186a365d9ebSJoonyoung Shim 
1871c248b7dSInki Dae static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
1881c248b7dSInki Dae 	.dpms		= exynos_drm_crtc_dpms,
1891c248b7dSInki Dae 	.prepare	= exynos_drm_crtc_prepare,
1901c248b7dSInki Dae 	.commit		= exynos_drm_crtc_commit,
1911c248b7dSInki Dae 	.mode_fixup	= exynos_drm_crtc_mode_fixup,
1921c248b7dSInki Dae 	.mode_set	= exynos_drm_crtc_mode_set,
1931c248b7dSInki Dae 	.mode_set_base	= exynos_drm_crtc_mode_set_base,
1941c248b7dSInki Dae 	.load_lut	= exynos_drm_crtc_load_lut,
195a365d9ebSJoonyoung Shim 	.disable	= exynos_drm_crtc_disable,
1961c248b7dSInki Dae };
1971c248b7dSInki Dae 
1981c248b7dSInki Dae static int exynos_drm_crtc_page_flip(struct drm_crtc *crtc,
1991c248b7dSInki Dae 				      struct drm_framebuffer *fb,
2001c248b7dSInki Dae 				      struct drm_pending_vblank_event *event)
2011c248b7dSInki Dae {
2021c248b7dSInki Dae 	struct drm_device *dev = crtc->dev;
2031c248b7dSInki Dae 	struct exynos_drm_private *dev_priv = dev->dev_private;
2041c248b7dSInki Dae 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
2051c248b7dSInki Dae 	struct drm_framebuffer *old_fb = crtc->fb;
2061c248b7dSInki Dae 	int ret = -EINVAL;
2071c248b7dSInki Dae 
2081c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
2091c248b7dSInki Dae 
210ef6223dcSInki Dae 	/* when the page flip is requested, crtc's dpms should be on */
211ef6223dcSInki Dae 	if (exynos_crtc->dpms > DRM_MODE_DPMS_ON) {
212ef6223dcSInki Dae 		DRM_ERROR("failed page flip request.\n");
213ef6223dcSInki Dae 		return -EINVAL;
214ef6223dcSInki Dae 	}
215ef6223dcSInki Dae 
2161c248b7dSInki Dae 	mutex_lock(&dev->struct_mutex);
2171c248b7dSInki Dae 
218ccf4d883SInki Dae 	if (event) {
219ccf4d883SInki Dae 		/*
220ccf4d883SInki Dae 		 * the pipe from user always is 0 so we can set pipe number
221ccf4d883SInki Dae 		 * of current owner to event.
222ccf4d883SInki Dae 		 */
223ccf4d883SInki Dae 		event->pipe = exynos_crtc->pipe;
224ccf4d883SInki Dae 
2251c248b7dSInki Dae 		ret = drm_vblank_get(dev, exynos_crtc->pipe);
2261c248b7dSInki Dae 		if (ret) {
2271c248b7dSInki Dae 			DRM_DEBUG("failed to acquire vblank counter\n");
228ccf4d883SInki Dae 			list_del(&event->base.link);
229ccf4d883SInki Dae 
2301c248b7dSInki Dae 			goto out;
2311c248b7dSInki Dae 		}
2321c248b7dSInki Dae 
233c5614ae3SInki Dae 		list_add_tail(&event->base.link,
234c5614ae3SInki Dae 				&dev_priv->pageflip_event_list);
235c5614ae3SInki Dae 
2361c248b7dSInki Dae 		crtc->fb = fb;
2374070d212SJoonyoung Shim 		ret = exynos_drm_crtc_mode_set_base(crtc, crtc->x, crtc->y,
2384070d212SJoonyoung Shim 						    NULL);
2391c248b7dSInki Dae 		if (ret) {
2401c248b7dSInki Dae 			crtc->fb = old_fb;
2411c248b7dSInki Dae 			drm_vblank_put(dev, exynos_crtc->pipe);
242ccf4d883SInki Dae 			list_del(&event->base.link);
2431c248b7dSInki Dae 
2441c248b7dSInki Dae 			goto out;
2451c248b7dSInki Dae 		}
2461c248b7dSInki Dae 	}
2471c248b7dSInki Dae out:
2481c248b7dSInki Dae 	mutex_unlock(&dev->struct_mutex);
2491c248b7dSInki Dae 	return ret;
2501c248b7dSInki Dae }
2511c248b7dSInki Dae 
2521c248b7dSInki Dae static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
2531c248b7dSInki Dae {
2541c248b7dSInki Dae 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
2551c248b7dSInki Dae 	struct exynos_drm_private *private = crtc->dev->dev_private;
2561c248b7dSInki Dae 
2571c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
2581c248b7dSInki Dae 
2591c248b7dSInki Dae 	private->crtc[exynos_crtc->pipe] = NULL;
2601c248b7dSInki Dae 
2611c248b7dSInki Dae 	drm_crtc_cleanup(crtc);
2621c248b7dSInki Dae 	kfree(exynos_crtc);
2631c248b7dSInki Dae }
2641c248b7dSInki Dae 
2653b8d1cf8SJoonyoung Shim static int exynos_drm_crtc_set_property(struct drm_crtc *crtc,
2663b8d1cf8SJoonyoung Shim 					struct drm_property *property,
2673b8d1cf8SJoonyoung Shim 					uint64_t val)
2683b8d1cf8SJoonyoung Shim {
2693b8d1cf8SJoonyoung Shim 	struct drm_device *dev = crtc->dev;
2703b8d1cf8SJoonyoung Shim 	struct exynos_drm_private *dev_priv = dev->dev_private;
2713b8d1cf8SJoonyoung Shim 	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
2723b8d1cf8SJoonyoung Shim 
2733b8d1cf8SJoonyoung Shim 	DRM_DEBUG_KMS("%s\n", __func__);
2743b8d1cf8SJoonyoung Shim 
2753b8d1cf8SJoonyoung Shim 	if (property == dev_priv->crtc_mode_property) {
2763b8d1cf8SJoonyoung Shim 		enum exynos_crtc_mode mode = val;
2773b8d1cf8SJoonyoung Shim 
2783b8d1cf8SJoonyoung Shim 		if (mode == exynos_crtc->mode)
2793b8d1cf8SJoonyoung Shim 			return 0;
2803b8d1cf8SJoonyoung Shim 
2813b8d1cf8SJoonyoung Shim 		exynos_crtc->mode = mode;
2823b8d1cf8SJoonyoung Shim 
2833b8d1cf8SJoonyoung Shim 		switch (mode) {
2843b8d1cf8SJoonyoung Shim 		case CRTC_MODE_NORMAL:
2853b8d1cf8SJoonyoung Shim 			exynos_drm_crtc_commit(crtc);
2863b8d1cf8SJoonyoung Shim 			break;
2873b8d1cf8SJoonyoung Shim 		case CRTC_MODE_BLANK:
2883b8d1cf8SJoonyoung Shim 			exynos_plane_dpms(exynos_crtc->plane,
2893b8d1cf8SJoonyoung Shim 					  DRM_MODE_DPMS_OFF);
2903b8d1cf8SJoonyoung Shim 			break;
2913b8d1cf8SJoonyoung Shim 		default:
2923b8d1cf8SJoonyoung Shim 			break;
2933b8d1cf8SJoonyoung Shim 		}
2943b8d1cf8SJoonyoung Shim 
2953b8d1cf8SJoonyoung Shim 		return 0;
2963b8d1cf8SJoonyoung Shim 	}
2973b8d1cf8SJoonyoung Shim 
2983b8d1cf8SJoonyoung Shim 	return -EINVAL;
2993b8d1cf8SJoonyoung Shim }
3003b8d1cf8SJoonyoung Shim 
3011c248b7dSInki Dae static struct drm_crtc_funcs exynos_crtc_funcs = {
3021c248b7dSInki Dae 	.set_config	= drm_crtc_helper_set_config,
3031c248b7dSInki Dae 	.page_flip	= exynos_drm_crtc_page_flip,
3041c248b7dSInki Dae 	.destroy	= exynos_drm_crtc_destroy,
3053b8d1cf8SJoonyoung Shim 	.set_property	= exynos_drm_crtc_set_property,
3061c248b7dSInki Dae };
3071c248b7dSInki Dae 
3083b8d1cf8SJoonyoung Shim static const struct drm_prop_enum_list mode_names[] = {
3093b8d1cf8SJoonyoung Shim 	{ CRTC_MODE_NORMAL, "normal" },
3103b8d1cf8SJoonyoung Shim 	{ CRTC_MODE_BLANK, "blank" },
3113b8d1cf8SJoonyoung Shim };
3123b8d1cf8SJoonyoung Shim 
3133b8d1cf8SJoonyoung Shim static void exynos_drm_crtc_attach_mode_property(struct drm_crtc *crtc)
3143b8d1cf8SJoonyoung Shim {
3153b8d1cf8SJoonyoung Shim 	struct drm_device *dev = crtc->dev;
3163b8d1cf8SJoonyoung Shim 	struct exynos_drm_private *dev_priv = dev->dev_private;
3173b8d1cf8SJoonyoung Shim 	struct drm_property *prop;
3183b8d1cf8SJoonyoung Shim 
3193b8d1cf8SJoonyoung Shim 	DRM_DEBUG_KMS("%s\n", __func__);
3203b8d1cf8SJoonyoung Shim 
3213b8d1cf8SJoonyoung Shim 	prop = dev_priv->crtc_mode_property;
3223b8d1cf8SJoonyoung Shim 	if (!prop) {
3233b8d1cf8SJoonyoung Shim 		prop = drm_property_create_enum(dev, 0, "mode", mode_names,
3243b8d1cf8SJoonyoung Shim 						ARRAY_SIZE(mode_names));
3253b8d1cf8SJoonyoung Shim 		if (!prop)
3263b8d1cf8SJoonyoung Shim 			return;
3273b8d1cf8SJoonyoung Shim 
3283b8d1cf8SJoonyoung Shim 		dev_priv->crtc_mode_property = prop;
3293b8d1cf8SJoonyoung Shim 	}
3303b8d1cf8SJoonyoung Shim 
3313b8d1cf8SJoonyoung Shim 	drm_object_attach_property(&crtc->base, prop, 0);
3323b8d1cf8SJoonyoung Shim }
3333b8d1cf8SJoonyoung Shim 
3341c248b7dSInki Dae int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr)
3351c248b7dSInki Dae {
3361c248b7dSInki Dae 	struct exynos_drm_crtc *exynos_crtc;
3371c248b7dSInki Dae 	struct exynos_drm_private *private = dev->dev_private;
3381c248b7dSInki Dae 	struct drm_crtc *crtc;
3391c248b7dSInki Dae 
3401c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
3411c248b7dSInki Dae 
3421c248b7dSInki Dae 	exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
3431c248b7dSInki Dae 	if (!exynos_crtc) {
3441c248b7dSInki Dae 		DRM_ERROR("failed to allocate exynos crtc\n");
3451c248b7dSInki Dae 		return -ENOMEM;
3461c248b7dSInki Dae 	}
3471c248b7dSInki Dae 
3481c248b7dSInki Dae 	exynos_crtc->pipe = nr;
349ec05da95SInki Dae 	exynos_crtc->dpms = DRM_MODE_DPMS_OFF;
350b5d2eb3bSJoonyoung Shim 	exynos_crtc->plane = exynos_plane_init(dev, 1 << nr, true);
351b5d2eb3bSJoonyoung Shim 	if (!exynos_crtc->plane) {
352b5d2eb3bSJoonyoung Shim 		kfree(exynos_crtc);
353b5d2eb3bSJoonyoung Shim 		return -ENOMEM;
354b5d2eb3bSJoonyoung Shim 	}
355b5d2eb3bSJoonyoung Shim 
3561c248b7dSInki Dae 	crtc = &exynos_crtc->drm_crtc;
3571c248b7dSInki Dae 
3581c248b7dSInki Dae 	private->crtc[nr] = crtc;
3591c248b7dSInki Dae 
3601c248b7dSInki Dae 	drm_crtc_init(dev, crtc, &exynos_crtc_funcs);
3611c248b7dSInki Dae 	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
3621c248b7dSInki Dae 
3633b8d1cf8SJoonyoung Shim 	exynos_drm_crtc_attach_mode_property(crtc);
3643b8d1cf8SJoonyoung Shim 
3651c248b7dSInki Dae 	return 0;
3661c248b7dSInki Dae }
3671c248b7dSInki Dae 
3681c248b7dSInki Dae int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc)
3691c248b7dSInki Dae {
3701c248b7dSInki Dae 	struct exynos_drm_private *private = dev->dev_private;
371ec05da95SInki Dae 	struct exynos_drm_crtc *exynos_crtc =
372ec05da95SInki Dae 		to_exynos_crtc(private->crtc[crtc]);
3731c248b7dSInki Dae 
3741c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
3751c248b7dSInki Dae 
376ec05da95SInki Dae 	if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
377ec05da95SInki Dae 		return -EPERM;
378ec05da95SInki Dae 
3791c248b7dSInki Dae 	exynos_drm_fn_encoder(private->crtc[crtc], &crtc,
3801c248b7dSInki Dae 			exynos_drm_enable_vblank);
3811c248b7dSInki Dae 
3821c248b7dSInki Dae 	return 0;
3831c248b7dSInki Dae }
3841c248b7dSInki Dae 
3851c248b7dSInki Dae void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc)
3861c248b7dSInki Dae {
3871c248b7dSInki Dae 	struct exynos_drm_private *private = dev->dev_private;
388ec05da95SInki Dae 	struct exynos_drm_crtc *exynos_crtc =
389ec05da95SInki Dae 		to_exynos_crtc(private->crtc[crtc]);
3901c248b7dSInki Dae 
3911c248b7dSInki Dae 	DRM_DEBUG_KMS("%s\n", __FILE__);
3921c248b7dSInki Dae 
393ec05da95SInki Dae 	if (exynos_crtc->dpms != DRM_MODE_DPMS_ON)
394ec05da95SInki Dae 		return;
395ec05da95SInki Dae 
3961c248b7dSInki Dae 	exynos_drm_fn_encoder(private->crtc[crtc], &crtc,
3971c248b7dSInki Dae 			exynos_drm_disable_vblank);
3981c248b7dSInki Dae }
399