3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "drm_crtc_helper.h"
32 #include "exynos_drm_crtc.h"
33 #include "exynos_drm_drv.h"
34 #include "exynos_drm_fb.h"
35 #include "exynos_drm_encoder.h"
36 #include "exynos_drm_gem.h"
37 #include "exynos_drm_buf.h"
39 #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\
43 * Exynos specific crtc structure.
45 * @drm_crtc: crtc object.
46 * @overlay: contain information common to display controller and hdmi and
47 * contents of this overlay object would be copied to sub driver size.
48 * @pipe: a crtc index created at load() with a new crtc object creation
49 * and the crtc object would be set to private->crtc array
50 * to get a crtc object corresponding to this pipe from private->crtc
51 * array when irq interrupt occured. the reason of using this pipe is that
52 * drm framework doesn't support multiple irq yet.
53 * we can refer to the crtc to current hardware interrupt occured through
56 struct exynos_drm_crtc
{
57 struct drm_crtc drm_crtc
;
58 struct exynos_drm_overlay overlay
;
62 static void exynos_drm_crtc_apply(struct drm_crtc
*crtc
)
64 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
65 struct exynos_drm_overlay
*overlay
= &exynos_crtc
->overlay
;
67 exynos_drm_fn_encoder(crtc
, overlay
,
68 exynos_drm_encoder_crtc_mode_set
);
69 exynos_drm_fn_encoder(crtc
, &exynos_crtc
->pipe
,
70 exynos_drm_encoder_crtc_commit
);
73 int exynos_drm_overlay_update(struct exynos_drm_overlay
*overlay
,
74 struct drm_framebuffer
*fb
,
75 struct drm_display_mode
*mode
,
76 struct exynos_drm_crtc_pos
*pos
)
78 struct exynos_drm_gem_buf
*buffer
;
79 unsigned int actual_w
;
80 unsigned int actual_h
;
82 buffer
= exynos_drm_fb_get_buf(fb
);
84 DRM_LOG_KMS("buffer is null.\n");
88 overlay
->dma_addr
= buffer
->dma_addr
;
89 overlay
->vaddr
= buffer
->kvaddr
;
91 DRM_DEBUG_KMS("vaddr = 0x%lx, dma_addr = 0x%lx\n",
92 (unsigned long)overlay
->vaddr
,
93 (unsigned long)overlay
->dma_addr
);
95 actual_w
= min((mode
->hdisplay
- pos
->crtc_x
), pos
->crtc_w
);
96 actual_h
= min((mode
->vdisplay
- pos
->crtc_y
), pos
->crtc_h
);
98 /* set drm framebuffer data. */
99 overlay
->fb_x
= pos
->fb_x
;
100 overlay
->fb_y
= pos
->fb_y
;
101 overlay
->fb_width
= fb
->width
;
102 overlay
->fb_height
= fb
->height
;
103 overlay
->bpp
= fb
->bits_per_pixel
;
104 overlay
->pitch
= fb
->pitches
[0];
106 /* set overlay range to be displayed. */
107 overlay
->crtc_x
= pos
->crtc_x
;
108 overlay
->crtc_y
= pos
->crtc_y
;
109 overlay
->crtc_width
= actual_w
;
110 overlay
->crtc_height
= actual_h
;
112 /* set drm mode data. */
113 overlay
->mode_width
= mode
->hdisplay
;
114 overlay
->mode_height
= mode
->vdisplay
;
115 overlay
->refresh
= mode
->vrefresh
;
116 overlay
->scan_flag
= mode
->flags
;
118 DRM_DEBUG_KMS("overlay : offset_x/y(%d,%d), width/height(%d,%d)",
119 overlay
->crtc_x
, overlay
->crtc_y
,
120 overlay
->crtc_width
, overlay
->crtc_height
);
125 static int exynos_drm_crtc_update(struct drm_crtc
*crtc
)
127 struct exynos_drm_crtc
*exynos_crtc
;
128 struct exynos_drm_overlay
*overlay
;
129 struct exynos_drm_crtc_pos pos
;
130 struct drm_display_mode
*mode
= &crtc
->mode
;
131 struct drm_framebuffer
*fb
= crtc
->fb
;
136 exynos_crtc
= to_exynos_crtc(crtc
);
137 overlay
= &exynos_crtc
->overlay
;
139 memset(&pos
, 0, sizeof(struct exynos_drm_crtc_pos
));
141 /* it means the offset of framebuffer to be displayed. */
145 /* OSD position to be displayed. */
148 pos
.crtc_w
= fb
->width
- crtc
->x
;
149 pos
.crtc_h
= fb
->height
- crtc
->y
;
151 return exynos_drm_overlay_update(overlay
, crtc
->fb
, mode
, &pos
);
154 static void exynos_drm_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
156 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
158 DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc
->base
.id
, mode
);
161 case DRM_MODE_DPMS_ON
:
162 exynos_drm_fn_encoder(crtc
, &exynos_crtc
->pipe
,
163 exynos_drm_encoder_crtc_commit
);
165 case DRM_MODE_DPMS_STANDBY
:
166 case DRM_MODE_DPMS_SUSPEND
:
167 case DRM_MODE_DPMS_OFF
:
169 exynos_drm_fn_encoder(crtc
, NULL
,
170 exynos_drm_encoder_crtc_disable
);
173 DRM_DEBUG_KMS("unspecified mode %d\n", mode
);
178 static void exynos_drm_crtc_prepare(struct drm_crtc
*crtc
)
180 DRM_DEBUG_KMS("%s\n", __FILE__
);
182 /* drm framework doesn't check NULL. */
185 static void exynos_drm_crtc_commit(struct drm_crtc
*crtc
)
187 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
189 DRM_DEBUG_KMS("%s\n", __FILE__
);
191 exynos_drm_fn_encoder(crtc
, &exynos_crtc
->pipe
,
192 exynos_drm_encoder_crtc_commit
);
196 exynos_drm_crtc_mode_fixup(struct drm_crtc
*crtc
,
197 struct drm_display_mode
*mode
,
198 struct drm_display_mode
*adjusted_mode
)
200 DRM_DEBUG_KMS("%s\n", __FILE__
);
202 /* drm framework doesn't check NULL */
207 exynos_drm_crtc_mode_set(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
208 struct drm_display_mode
*adjusted_mode
, int x
, int y
,
209 struct drm_framebuffer
*old_fb
)
211 DRM_DEBUG_KMS("%s\n", __FILE__
);
213 mode
= adjusted_mode
;
215 return exynos_drm_crtc_update(crtc
);
218 static int exynos_drm_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
219 struct drm_framebuffer
*old_fb
)
223 DRM_DEBUG_KMS("%s\n", __FILE__
);
225 ret
= exynos_drm_crtc_update(crtc
);
229 exynos_drm_crtc_apply(crtc
);
234 static void exynos_drm_crtc_load_lut(struct drm_crtc
*crtc
)
236 DRM_DEBUG_KMS("%s\n", __FILE__
);
237 /* drm framework doesn't check NULL */
240 static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs
= {
241 .dpms
= exynos_drm_crtc_dpms
,
242 .prepare
= exynos_drm_crtc_prepare
,
243 .commit
= exynos_drm_crtc_commit
,
244 .mode_fixup
= exynos_drm_crtc_mode_fixup
,
245 .mode_set
= exynos_drm_crtc_mode_set
,
246 .mode_set_base
= exynos_drm_crtc_mode_set_base
,
247 .load_lut
= exynos_drm_crtc_load_lut
,
250 static int exynos_drm_crtc_page_flip(struct drm_crtc
*crtc
,
251 struct drm_framebuffer
*fb
,
252 struct drm_pending_vblank_event
*event
)
254 struct drm_device
*dev
= crtc
->dev
;
255 struct exynos_drm_private
*dev_priv
= dev
->dev_private
;
256 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
257 struct drm_framebuffer
*old_fb
= crtc
->fb
;
260 DRM_DEBUG_KMS("%s\n", __FILE__
);
262 mutex_lock(&dev
->struct_mutex
);
266 * the pipe from user always is 0 so we can set pipe number
267 * of current owner to event.
269 event
->pipe
= exynos_crtc
->pipe
;
271 list_add_tail(&event
->base
.link
,
272 &dev_priv
->pageflip_event_list
);
274 ret
= drm_vblank_get(dev
, exynos_crtc
->pipe
);
276 DRM_DEBUG("failed to acquire vblank counter\n");
277 list_del(&event
->base
.link
);
283 ret
= exynos_drm_crtc_update(crtc
);
286 drm_vblank_put(dev
, exynos_crtc
->pipe
);
287 list_del(&event
->base
.link
);
293 * the values related to a buffer of the drm framebuffer
294 * to be applied should be set at here. because these values
295 * first, are set to shadow registers and then to
296 * real registers at vsync front porch period.
298 exynos_drm_crtc_apply(crtc
);
301 mutex_unlock(&dev
->struct_mutex
);
305 static void exynos_drm_crtc_destroy(struct drm_crtc
*crtc
)
307 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
308 struct exynos_drm_private
*private = crtc
->dev
->dev_private
;
310 DRM_DEBUG_KMS("%s\n", __FILE__
);
312 private->crtc
[exynos_crtc
->pipe
] = NULL
;
314 drm_crtc_cleanup(crtc
);
318 static struct drm_crtc_funcs exynos_crtc_funcs
= {
319 .set_config
= drm_crtc_helper_set_config
,
320 .page_flip
= exynos_drm_crtc_page_flip
,
321 .destroy
= exynos_drm_crtc_destroy
,
324 struct exynos_drm_overlay
*get_exynos_drm_overlay(struct drm_device
*dev
,
325 struct drm_crtc
*crtc
)
327 struct exynos_drm_crtc
*exynos_crtc
= to_exynos_crtc(crtc
);
329 return &exynos_crtc
->overlay
;
332 int exynos_drm_crtc_create(struct drm_device
*dev
, unsigned int nr
)
334 struct exynos_drm_crtc
*exynos_crtc
;
335 struct exynos_drm_private
*private = dev
->dev_private
;
336 struct drm_crtc
*crtc
;
338 DRM_DEBUG_KMS("%s\n", __FILE__
);
340 exynos_crtc
= kzalloc(sizeof(*exynos_crtc
), GFP_KERNEL
);
342 DRM_ERROR("failed to allocate exynos crtc\n");
346 exynos_crtc
->pipe
= nr
;
347 crtc
= &exynos_crtc
->drm_crtc
;
349 private->crtc
[nr
] = crtc
;
351 drm_crtc_init(dev
, crtc
, &exynos_crtc_funcs
);
352 drm_crtc_helper_add(crtc
, &exynos_crtc_helper_funcs
);
357 int exynos_drm_crtc_enable_vblank(struct drm_device
*dev
, int crtc
)
359 struct exynos_drm_private
*private = dev
->dev_private
;
361 DRM_DEBUG_KMS("%s\n", __FILE__
);
363 exynos_drm_fn_encoder(private->crtc
[crtc
], &crtc
,
364 exynos_drm_enable_vblank
);
369 void exynos_drm_crtc_disable_vblank(struct drm_device
*dev
, int crtc
)
371 struct exynos_drm_private
*private = dev
->dev_private
;
373 DRM_DEBUG_KMS("%s\n", __FILE__
);
375 exynos_drm_fn_encoder(private->crtc
[crtc
], &crtc
,
376 exynos_drm_disable_vblank
);
379 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
380 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
381 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
382 MODULE_DESCRIPTION("Samsung SoC DRM CRTC Driver");
383 MODULE_LICENSE("GPL");