blob: 23a57f4da478057230a39066331251f331920c00 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* exynos_drm_fimd.c
2 *
3 * Copyright (C) 2011 Samsung Electronics Co.Ltd
4 * Authors:
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Inki Dae <inki.dae@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
David Howells760285e2012-10-02 18:01:07 +010014#include <drm/drmP.h>
Inki Dae1c248b72011-10-04 19:19:01 +090015
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/clk.h>
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +090020#include <linux/pm_runtime.h>
Inki Dae1c248b72011-10-04 19:19:01 +090021
Leela Krishna Amudala5a213a52012-08-08 09:44:49 +090022#include <video/samsung_fimd.h>
Inki Dae1c248b72011-10-04 19:19:01 +090023#include <drm/exynos_drm.h>
Inki Dae1c248b72011-10-04 19:19:01 +090024
25#include "exynos_drm_drv.h"
26#include "exynos_drm_fbdev.h"
27#include "exynos_drm_crtc.h"
28
29/*
30 * FIMD is stand for Fully Interactive Mobile Display and
31 * as a display controller, it transfers contents drawn on memory
32 * to a LCD Panel through Display Interfaces such as RGB or
33 * CPU Interface.
34 */
35
36/* position control register for hardware window 0, 2 ~ 4.*/
37#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
38#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
39/* size control register for hardware window 0. */
40#define VIDOSD_C_SIZE_W0 (VIDOSD_BASE + 0x08)
41/* alpha control register for hardware window 1 ~ 4. */
42#define VIDOSD_C(win) (VIDOSD_BASE + 0x18 + (win) * 16)
43/* size control register for hardware window 1 ~ 4. */
44#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
45
46#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
47#define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8)
48#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
49
50/* color key control register for hardware window 1 ~ 4. */
51#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + (x * 8))
52/* color key value register for hardware window 1 ~ 4. */
53#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + (x * 8))
54
55/* FIMD has totally five hardware windows. */
56#define WINDOWS_NR 5
57
58#define get_fimd_context(dev) platform_get_drvdata(to_platform_device(dev))
59
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +053060struct fimd_driver_data {
61 unsigned int timing_base;
62};
63
Sachin Kamat6ecf18f2012-11-19 15:22:54 +053064static struct fimd_driver_data exynos4_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +053065 .timing_base = 0x0,
66};
67
Sachin Kamat6ecf18f2012-11-19 15:22:54 +053068static struct fimd_driver_data exynos5_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +053069 .timing_base = 0x20000,
70};
71
Inki Dae1c248b72011-10-04 19:19:01 +090072struct fimd_win_data {
73 unsigned int offset_x;
74 unsigned int offset_y;
Inki Dae19c8b832011-10-14 13:29:46 +090075 unsigned int ovl_width;
76 unsigned int ovl_height;
77 unsigned int fb_width;
78 unsigned int fb_height;
Inki Dae1c248b72011-10-04 19:19:01 +090079 unsigned int bpp;
Inki Dae2c871122011-11-12 15:23:32 +090080 dma_addr_t dma_addr;
Inki Dae1c248b72011-10-04 19:19:01 +090081 void __iomem *vaddr;
82 unsigned int buf_offsize;
83 unsigned int line_size; /* bytes */
Inki Daeec05da92011-12-06 11:06:54 +090084 bool enabled;
Inki Dae1c248b72011-10-04 19:19:01 +090085};
86
87struct fimd_context {
88 struct exynos_drm_subdrv subdrv;
89 int irq;
90 struct drm_crtc *crtc;
91 struct clk *bus_clk;
92 struct clk *lcd_clk;
Inki Dae1c248b72011-10-04 19:19:01 +090093 void __iomem *regs;
94 struct fimd_win_data win_data[WINDOWS_NR];
95 unsigned int clkdiv;
96 unsigned int default_win;
97 unsigned long irq_flags;
98 u32 vidcon0;
99 u32 vidcon1;
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900100 bool suspended;
Inki Daec32b06e2011-12-16 21:49:03 +0900101 struct mutex lock;
Inki Dae1c248b72011-10-04 19:19:01 +0900102
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900103 struct exynos_drm_panel_info *panel;
Inki Dae1c248b72011-10-04 19:19:01 +0900104};
105
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530106static inline struct fimd_driver_data *drm_fimd_get_driver_data(
107 struct platform_device *pdev)
108{
109 return (struct fimd_driver_data *)
110 platform_get_device_id(pdev)->driver_data;
111}
112
Inki Dae1c248b72011-10-04 19:19:01 +0900113static bool fimd_display_is_connected(struct device *dev)
114{
Inki Dae1c248b72011-10-04 19:19:01 +0900115 DRM_DEBUG_KMS("%s\n", __FILE__);
116
117 /* TODO. */
118
119 return true;
120}
121
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900122static void *fimd_get_panel(struct device *dev)
Inki Dae1c248b72011-10-04 19:19:01 +0900123{
124 struct fimd_context *ctx = get_fimd_context(dev);
125
126 DRM_DEBUG_KMS("%s\n", __FILE__);
127
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900128 return ctx->panel;
Inki Dae1c248b72011-10-04 19:19:01 +0900129}
130
131static int fimd_check_timing(struct device *dev, void *timing)
132{
Inki Dae1c248b72011-10-04 19:19:01 +0900133 DRM_DEBUG_KMS("%s\n", __FILE__);
134
135 /* TODO. */
136
137 return 0;
138}
139
140static int fimd_display_power_on(struct device *dev, int mode)
141{
Inki Dae1c248b72011-10-04 19:19:01 +0900142 DRM_DEBUG_KMS("%s\n", __FILE__);
143
Inki Daeec05da92011-12-06 11:06:54 +0900144 /* TODO */
Inki Dae1c248b72011-10-04 19:19:01 +0900145
146 return 0;
147}
148
Inki Dae74ccc532011-10-19 17:23:07 +0900149static struct exynos_drm_display_ops fimd_display_ops = {
Inki Dae1c248b72011-10-04 19:19:01 +0900150 .type = EXYNOS_DISPLAY_TYPE_LCD,
151 .is_connected = fimd_display_is_connected,
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900152 .get_panel = fimd_get_panel,
Inki Dae1c248b72011-10-04 19:19:01 +0900153 .check_timing = fimd_check_timing,
154 .power_on = fimd_display_power_on,
155};
156
Inki Daeec05da92011-12-06 11:06:54 +0900157static void fimd_dpms(struct device *subdrv_dev, int mode)
158{
Inki Daec32b06e2011-12-16 21:49:03 +0900159 struct fimd_context *ctx = get_fimd_context(subdrv_dev);
160
Inki Daeec05da92011-12-06 11:06:54 +0900161 DRM_DEBUG_KMS("%s, %d\n", __FILE__, mode);
162
Inki Daec32b06e2011-12-16 21:49:03 +0900163 mutex_lock(&ctx->lock);
164
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900165 switch (mode) {
166 case DRM_MODE_DPMS_ON:
Inki Daec32b06e2011-12-16 21:49:03 +0900167 /*
168 * enable fimd hardware only if suspended status.
169 *
170 * P.S. fimd_dpms function would be called at booting time so
171 * clk_enable could be called double time.
172 */
173 if (ctx->suspended)
174 pm_runtime_get_sync(subdrv_dev);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900175 break;
176 case DRM_MODE_DPMS_STANDBY:
177 case DRM_MODE_DPMS_SUSPEND:
178 case DRM_MODE_DPMS_OFF:
Inki Dae373af0c2012-01-27 11:54:58 +0900179 if (!ctx->suspended)
180 pm_runtime_put_sync(subdrv_dev);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900181 break;
182 default:
183 DRM_DEBUG_KMS("unspecified mode %d\n", mode);
184 break;
185 }
Inki Daec32b06e2011-12-16 21:49:03 +0900186
187 mutex_unlock(&ctx->lock);
Inki Daeec05da92011-12-06 11:06:54 +0900188}
189
190static void fimd_apply(struct device *subdrv_dev)
191{
192 struct fimd_context *ctx = get_fimd_context(subdrv_dev);
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900193 struct exynos_drm_manager *mgr = ctx->subdrv.manager;
Inki Daeec05da92011-12-06 11:06:54 +0900194 struct exynos_drm_manager_ops *mgr_ops = mgr->ops;
195 struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops;
196 struct fimd_win_data *win_data;
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900197 int i;
Inki Daeec05da92011-12-06 11:06:54 +0900198
199 DRM_DEBUG_KMS("%s\n", __FILE__);
200
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900201 for (i = 0; i < WINDOWS_NR; i++) {
202 win_data = &ctx->win_data[i];
203 if (win_data->enabled && (ovl_ops && ovl_ops->commit))
204 ovl_ops->commit(subdrv_dev, i);
205 }
Inki Daeec05da92011-12-06 11:06:54 +0900206
207 if (mgr_ops && mgr_ops->commit)
208 mgr_ops->commit(subdrv_dev);
209}
210
Inki Dae1c248b72011-10-04 19:19:01 +0900211static void fimd_commit(struct device *dev)
212{
213 struct fimd_context *ctx = get_fimd_context(dev);
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900214 struct exynos_drm_panel_info *panel = ctx->panel;
215 struct fb_videomode *timing = &panel->timing;
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530216 struct fimd_driver_data *driver_data;
217 struct platform_device *pdev = to_platform_device(dev);
Inki Dae1c248b72011-10-04 19:19:01 +0900218 u32 val;
219
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530220 driver_data = drm_fimd_get_driver_data(pdev);
Inki Daee30d4bc2011-12-12 16:35:20 +0900221 if (ctx->suspended)
222 return;
223
Inki Dae1c248b72011-10-04 19:19:01 +0900224 DRM_DEBUG_KMS("%s\n", __FILE__);
225
226 /* setup polarity values from machine code. */
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530227 writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
Inki Dae1c248b72011-10-04 19:19:01 +0900228
229 /* setup vertical timing values. */
230 val = VIDTCON0_VBPD(timing->upper_margin - 1) |
231 VIDTCON0_VFPD(timing->lower_margin - 1) |
232 VIDTCON0_VSPW(timing->vsync_len - 1);
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530233 writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
Inki Dae1c248b72011-10-04 19:19:01 +0900234
235 /* setup horizontal timing values. */
236 val = VIDTCON1_HBPD(timing->left_margin - 1) |
237 VIDTCON1_HFPD(timing->right_margin - 1) |
238 VIDTCON1_HSPW(timing->hsync_len - 1);
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530239 writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
Inki Dae1c248b72011-10-04 19:19:01 +0900240
241 /* setup horizontal and vertical display size. */
242 val = VIDTCON2_LINEVAL(timing->yres - 1) |
243 VIDTCON2_HOZVAL(timing->xres - 1);
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530244 writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
Inki Dae1c248b72011-10-04 19:19:01 +0900245
246 /* setup clock source, clock divider, enable dma. */
247 val = ctx->vidcon0;
248 val &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
249
250 if (ctx->clkdiv > 1)
251 val |= VIDCON0_CLKVAL_F(ctx->clkdiv - 1) | VIDCON0_CLKDIR;
252 else
253 val &= ~VIDCON0_CLKDIR; /* 1:1 clock */
254
255 /*
256 * fields of register with prefix '_F' would be updated
257 * at vsync(same as dma start)
258 */
259 val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
260 writel(val, ctx->regs + VIDCON0);
261}
262
263static int fimd_enable_vblank(struct device *dev)
264{
265 struct fimd_context *ctx = get_fimd_context(dev);
266 u32 val;
267
268 DRM_DEBUG_KMS("%s\n", __FILE__);
269
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900270 if (ctx->suspended)
271 return -EPERM;
272
Inki Dae1c248b72011-10-04 19:19:01 +0900273 if (!test_and_set_bit(0, &ctx->irq_flags)) {
274 val = readl(ctx->regs + VIDINTCON0);
275
276 val |= VIDINTCON0_INT_ENABLE;
277 val |= VIDINTCON0_INT_FRAME;
278
279 val &= ~VIDINTCON0_FRAMESEL0_MASK;
280 val |= VIDINTCON0_FRAMESEL0_VSYNC;
281 val &= ~VIDINTCON0_FRAMESEL1_MASK;
282 val |= VIDINTCON0_FRAMESEL1_NONE;
283
284 writel(val, ctx->regs + VIDINTCON0);
285 }
286
287 return 0;
288}
289
290static void fimd_disable_vblank(struct device *dev)
291{
292 struct fimd_context *ctx = get_fimd_context(dev);
293 u32 val;
294
295 DRM_DEBUG_KMS("%s\n", __FILE__);
296
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900297 if (ctx->suspended)
298 return;
299
Inki Dae1c248b72011-10-04 19:19:01 +0900300 if (test_and_clear_bit(0, &ctx->irq_flags)) {
301 val = readl(ctx->regs + VIDINTCON0);
302
303 val &= ~VIDINTCON0_INT_FRAME;
304 val &= ~VIDINTCON0_INT_ENABLE;
305
306 writel(val, ctx->regs + VIDINTCON0);
307 }
308}
309
310static struct exynos_drm_manager_ops fimd_manager_ops = {
Inki Daeec05da92011-12-06 11:06:54 +0900311 .dpms = fimd_dpms,
312 .apply = fimd_apply,
Inki Dae1c248b72011-10-04 19:19:01 +0900313 .commit = fimd_commit,
314 .enable_vblank = fimd_enable_vblank,
315 .disable_vblank = fimd_disable_vblank,
316};
317
318static void fimd_win_mode_set(struct device *dev,
319 struct exynos_drm_overlay *overlay)
320{
321 struct fimd_context *ctx = get_fimd_context(dev);
322 struct fimd_win_data *win_data;
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900323 int win;
Inki Dae19c8b832011-10-14 13:29:46 +0900324 unsigned long offset;
Inki Dae1c248b72011-10-04 19:19:01 +0900325
326 DRM_DEBUG_KMS("%s\n", __FILE__);
327
328 if (!overlay) {
329 dev_err(dev, "overlay is NULL\n");
330 return;
331 }
332
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900333 win = overlay->zpos;
334 if (win == DEFAULT_ZPOS)
335 win = ctx->default_win;
336
337 if (win < 0 || win > WINDOWS_NR)
338 return;
339
Inki Dae19c8b832011-10-14 13:29:46 +0900340 offset = overlay->fb_x * (overlay->bpp >> 3);
341 offset += overlay->fb_y * overlay->pitch;
342
343 DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, overlay->pitch);
344
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900345 win_data = &ctx->win_data[win];
Inki Dae1c248b72011-10-04 19:19:01 +0900346
Inki Dae19c8b832011-10-14 13:29:46 +0900347 win_data->offset_x = overlay->crtc_x;
348 win_data->offset_y = overlay->crtc_y;
349 win_data->ovl_width = overlay->crtc_width;
350 win_data->ovl_height = overlay->crtc_height;
351 win_data->fb_width = overlay->fb_width;
352 win_data->fb_height = overlay->fb_height;
Seung-Woo Kim229d3532011-12-15 14:36:22 +0900353 win_data->dma_addr = overlay->dma_addr[0] + offset;
354 win_data->vaddr = overlay->vaddr[0] + offset;
Inki Dae1c248b72011-10-04 19:19:01 +0900355 win_data->bpp = overlay->bpp;
Inki Dae19c8b832011-10-14 13:29:46 +0900356 win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) *
357 (overlay->bpp >> 3);
358 win_data->line_size = overlay->crtc_width * (overlay->bpp >> 3);
359
360 DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n",
361 win_data->offset_x, win_data->offset_y);
362 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
363 win_data->ovl_width, win_data->ovl_height);
364 DRM_DEBUG_KMS("paddr = 0x%lx, vaddr = 0x%lx\n",
Inki Dae2c871122011-11-12 15:23:32 +0900365 (unsigned long)win_data->dma_addr,
Inki Dae19c8b832011-10-14 13:29:46 +0900366 (unsigned long)win_data->vaddr);
367 DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n",
368 overlay->fb_width, overlay->crtc_width);
Inki Dae1c248b72011-10-04 19:19:01 +0900369}
370
371static void fimd_win_set_pixfmt(struct device *dev, unsigned int win)
372{
373 struct fimd_context *ctx = get_fimd_context(dev);
374 struct fimd_win_data *win_data = &ctx->win_data[win];
375 unsigned long val;
376
377 DRM_DEBUG_KMS("%s\n", __FILE__);
378
379 val = WINCONx_ENWIN;
380
381 switch (win_data->bpp) {
382 case 1:
383 val |= WINCON0_BPPMODE_1BPP;
384 val |= WINCONx_BITSWP;
385 val |= WINCONx_BURSTLEN_4WORD;
386 break;
387 case 2:
388 val |= WINCON0_BPPMODE_2BPP;
389 val |= WINCONx_BITSWP;
390 val |= WINCONx_BURSTLEN_8WORD;
391 break;
392 case 4:
393 val |= WINCON0_BPPMODE_4BPP;
394 val |= WINCONx_BITSWP;
395 val |= WINCONx_BURSTLEN_8WORD;
396 break;
397 case 8:
398 val |= WINCON0_BPPMODE_8BPP_PALETTE;
399 val |= WINCONx_BURSTLEN_8WORD;
400 val |= WINCONx_BYTSWP;
401 break;
402 case 16:
403 val |= WINCON0_BPPMODE_16BPP_565;
404 val |= WINCONx_HAWSWP;
405 val |= WINCONx_BURSTLEN_16WORD;
406 break;
407 case 24:
408 val |= WINCON0_BPPMODE_24BPP_888;
409 val |= WINCONx_WSWP;
410 val |= WINCONx_BURSTLEN_16WORD;
411 break;
412 case 32:
413 val |= WINCON1_BPPMODE_28BPP_A4888
414 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
415 val |= WINCONx_WSWP;
416 val |= WINCONx_BURSTLEN_16WORD;
417 break;
418 default:
419 DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n");
420
421 val |= WINCON0_BPPMODE_24BPP_888;
422 val |= WINCONx_WSWP;
423 val |= WINCONx_BURSTLEN_16WORD;
424 break;
425 }
426
427 DRM_DEBUG_KMS("bpp = %d\n", win_data->bpp);
428
429 writel(val, ctx->regs + WINCON(win));
430}
431
432static void fimd_win_set_colkey(struct device *dev, unsigned int win)
433{
434 struct fimd_context *ctx = get_fimd_context(dev);
435 unsigned int keycon0 = 0, keycon1 = 0;
436
437 DRM_DEBUG_KMS("%s\n", __FILE__);
438
439 keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
440 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
441
442 keycon1 = WxKEYCON1_COLVAL(0xffffffff);
443
444 writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
445 writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
446}
447
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900448static void fimd_win_commit(struct device *dev, int zpos)
Inki Dae1c248b72011-10-04 19:19:01 +0900449{
450 struct fimd_context *ctx = get_fimd_context(dev);
451 struct fimd_win_data *win_data;
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900452 int win = zpos;
Inki Dae1c248b72011-10-04 19:19:01 +0900453 unsigned long val, alpha, size;
454
455 DRM_DEBUG_KMS("%s\n", __FILE__);
456
Inki Daee30d4bc2011-12-12 16:35:20 +0900457 if (ctx->suspended)
458 return;
459
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900460 if (win == DEFAULT_ZPOS)
461 win = ctx->default_win;
462
Inki Dae1c248b72011-10-04 19:19:01 +0900463 if (win < 0 || win > WINDOWS_NR)
464 return;
465
466 win_data = &ctx->win_data[win];
467
468 /*
469 * SHADOWCON register is used for enabling timing.
470 *
471 * for example, once only width value of a register is set,
472 * if the dma is started then fimd hardware could malfunction so
473 * with protect window setting, the register fields with prefix '_F'
474 * wouldn't be updated at vsync also but updated once unprotect window
475 * is set.
476 */
477
478 /* protect windows */
479 val = readl(ctx->regs + SHADOWCON);
480 val |= SHADOWCON_WINx_PROTECT(win);
481 writel(val, ctx->regs + SHADOWCON);
482
483 /* buffer start address */
Inki Dae2c871122011-11-12 15:23:32 +0900484 val = (unsigned long)win_data->dma_addr;
Inki Dae1c248b72011-10-04 19:19:01 +0900485 writel(val, ctx->regs + VIDWx_BUF_START(win, 0));
486
487 /* buffer end address */
Inki Dae19c8b832011-10-14 13:29:46 +0900488 size = win_data->fb_width * win_data->ovl_height * (win_data->bpp >> 3);
Inki Dae2c871122011-11-12 15:23:32 +0900489 val = (unsigned long)(win_data->dma_addr + size);
Inki Dae1c248b72011-10-04 19:19:01 +0900490 writel(val, ctx->regs + VIDWx_BUF_END(win, 0));
491
492 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
Inki Dae2c871122011-11-12 15:23:32 +0900493 (unsigned long)win_data->dma_addr, val, size);
Inki Dae19c8b832011-10-14 13:29:46 +0900494 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
495 win_data->ovl_width, win_data->ovl_height);
Inki Dae1c248b72011-10-04 19:19:01 +0900496
497 /* buffer size */
498 val = VIDW_BUF_SIZE_OFFSET(win_data->buf_offsize) |
499 VIDW_BUF_SIZE_PAGEWIDTH(win_data->line_size);
500 writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0));
501
502 /* OSD position */
503 val = VIDOSDxA_TOPLEFT_X(win_data->offset_x) |
504 VIDOSDxA_TOPLEFT_Y(win_data->offset_y);
505 writel(val, ctx->regs + VIDOSD_A(win));
506
Inki Dae19c8b832011-10-14 13:29:46 +0900507 val = VIDOSDxB_BOTRIGHT_X(win_data->offset_x +
508 win_data->ovl_width - 1) |
509 VIDOSDxB_BOTRIGHT_Y(win_data->offset_y +
510 win_data->ovl_height - 1);
Inki Dae1c248b72011-10-04 19:19:01 +0900511 writel(val, ctx->regs + VIDOSD_B(win));
512
Inki Dae19c8b832011-10-14 13:29:46 +0900513 DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
Inki Dae1c248b72011-10-04 19:19:01 +0900514 win_data->offset_x, win_data->offset_y,
Inki Dae19c8b832011-10-14 13:29:46 +0900515 win_data->offset_x + win_data->ovl_width - 1,
516 win_data->offset_y + win_data->ovl_height - 1);
Inki Dae1c248b72011-10-04 19:19:01 +0900517
518 /* hardware window 0 doesn't support alpha channel. */
519 if (win != 0) {
520 /* OSD alpha */
521 alpha = VIDISD14C_ALPHA1_R(0xf) |
522 VIDISD14C_ALPHA1_G(0xf) |
523 VIDISD14C_ALPHA1_B(0xf);
524
525 writel(alpha, ctx->regs + VIDOSD_C(win));
526 }
527
528 /* OSD size */
529 if (win != 3 && win != 4) {
530 u32 offset = VIDOSD_D(win);
531 if (win == 0)
532 offset = VIDOSD_C_SIZE_W0;
Inki Dae19c8b832011-10-14 13:29:46 +0900533 val = win_data->ovl_width * win_data->ovl_height;
Inki Dae1c248b72011-10-04 19:19:01 +0900534 writel(val, ctx->regs + offset);
535
536 DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val);
537 }
538
539 fimd_win_set_pixfmt(dev, win);
540
541 /* hardware window 0 doesn't support color key. */
542 if (win != 0)
543 fimd_win_set_colkey(dev, win);
544
Inki Daeec05da92011-12-06 11:06:54 +0900545 /* wincon */
546 val = readl(ctx->regs + WINCON(win));
547 val |= WINCONx_ENWIN;
548 writel(val, ctx->regs + WINCON(win));
549
Inki Dae1c248b72011-10-04 19:19:01 +0900550 /* Enable DMA channel and unprotect windows */
551 val = readl(ctx->regs + SHADOWCON);
552 val |= SHADOWCON_CHx_ENABLE(win);
553 val &= ~SHADOWCON_WINx_PROTECT(win);
554 writel(val, ctx->regs + SHADOWCON);
Inki Daeec05da92011-12-06 11:06:54 +0900555
556 win_data->enabled = true;
Inki Dae1c248b72011-10-04 19:19:01 +0900557}
558
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900559static void fimd_win_disable(struct device *dev, int zpos)
Inki Dae1c248b72011-10-04 19:19:01 +0900560{
561 struct fimd_context *ctx = get_fimd_context(dev);
Inki Daeec05da92011-12-06 11:06:54 +0900562 struct fimd_win_data *win_data;
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900563 int win = zpos;
Inki Dae1c248b72011-10-04 19:19:01 +0900564 u32 val;
565
566 DRM_DEBUG_KMS("%s\n", __FILE__);
567
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900568 if (win == DEFAULT_ZPOS)
569 win = ctx->default_win;
570
Inki Dae1c248b72011-10-04 19:19:01 +0900571 if (win < 0 || win > WINDOWS_NR)
572 return;
573
Inki Daeec05da92011-12-06 11:06:54 +0900574 win_data = &ctx->win_data[win];
575
Inki Dae1c248b72011-10-04 19:19:01 +0900576 /* protect windows */
577 val = readl(ctx->regs + SHADOWCON);
578 val |= SHADOWCON_WINx_PROTECT(win);
579 writel(val, ctx->regs + SHADOWCON);
580
581 /* wincon */
582 val = readl(ctx->regs + WINCON(win));
583 val &= ~WINCONx_ENWIN;
584 writel(val, ctx->regs + WINCON(win));
585
586 /* unprotect windows */
587 val = readl(ctx->regs + SHADOWCON);
588 val &= ~SHADOWCON_CHx_ENABLE(win);
589 val &= ~SHADOWCON_WINx_PROTECT(win);
590 writel(val, ctx->regs + SHADOWCON);
Inki Daeec05da92011-12-06 11:06:54 +0900591
592 win_data->enabled = false;
Inki Dae1c248b72011-10-04 19:19:01 +0900593}
594
Inki Dae479cbc32012-08-20 19:58:05 +0900595static void fimd_wait_for_vblank(struct device *dev)
596{
597 struct fimd_context *ctx = get_fimd_context(dev);
598 int ret;
599
600 ret = wait_for((__raw_readl(ctx->regs + VIDCON1) &
601 VIDCON1_VSTATUS_VSYNC), 50);
602 if (ret < 0)
603 DRM_DEBUG_KMS("vblank wait timed out.\n");
604}
605
Inki Dae1c248b72011-10-04 19:19:01 +0900606static struct exynos_drm_overlay_ops fimd_overlay_ops = {
607 .mode_set = fimd_win_mode_set,
608 .commit = fimd_win_commit,
609 .disable = fimd_win_disable,
Inki Dae479cbc32012-08-20 19:58:05 +0900610 .wait_for_vblank = fimd_wait_for_vblank,
Inki Dae1c248b72011-10-04 19:19:01 +0900611};
612
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900613static struct exynos_drm_manager fimd_manager = {
614 .pipe = -1,
615 .ops = &fimd_manager_ops,
616 .overlay_ops = &fimd_overlay_ops,
617 .display_ops = &fimd_display_ops,
618};
619
Inki Dae1c248b72011-10-04 19:19:01 +0900620static void fimd_finish_pageflip(struct drm_device *drm_dev, int crtc)
621{
622 struct exynos_drm_private *dev_priv = drm_dev->dev_private;
623 struct drm_pending_vblank_event *e, *t;
624 struct timeval now;
625 unsigned long flags;
Inki Daeccf4d882011-10-14 13:29:51 +0900626 bool is_checked = false;
Inki Dae1c248b72011-10-04 19:19:01 +0900627
628 spin_lock_irqsave(&drm_dev->event_lock, flags);
629
Inki Dae1c248b72011-10-04 19:19:01 +0900630 list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
631 base.link) {
Inki Daea88cab22011-10-14 13:29:52 +0900632 /* if event's pipe isn't same as crtc then ignore it. */
Inki Daeccf4d882011-10-14 13:29:51 +0900633 if (crtc != e->pipe)
634 continue;
635
636 is_checked = true;
637
Inki Dae1c248b72011-10-04 19:19:01 +0900638 do_gettimeofday(&now);
639 e->event.sequence = 0;
640 e->event.tv_sec = now.tv_sec;
641 e->event.tv_usec = now.tv_usec;
642
643 list_move_tail(&e->base.link, &e->base.file_priv->event_list);
644 wake_up_interruptible(&e->base.file_priv->event_wait);
Imre Deake1f48ee2012-11-02 13:30:48 +0200645 drm_vblank_put(drm_dev, crtc);
Inki Dae1c248b72011-10-04 19:19:01 +0900646 }
647
Inki Daeec05da92011-12-06 11:06:54 +0900648 if (is_checked) {
Inki Dae039129b2012-02-14 11:15:09 +0900649 /*
Inki Daeec05da92011-12-06 11:06:54 +0900650 * don't off vblank if vblank_disable_allowed is 1,
651 * because vblank would be off by timer handler.
652 */
653 if (!drm_dev->vblank_disable_allowed)
654 drm_vblank_off(drm_dev, crtc);
655 }
656
Inki Dae1c248b72011-10-04 19:19:01 +0900657 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
658}
659
660static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
661{
662 struct fimd_context *ctx = (struct fimd_context *)dev_id;
663 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
664 struct drm_device *drm_dev = subdrv->drm_dev;
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900665 struct exynos_drm_manager *manager = subdrv->manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900666 u32 val;
667
668 val = readl(ctx->regs + VIDINTCON1);
669
670 if (val & VIDINTCON1_INT_FRAME)
671 /* VSYNC interrupt */
672 writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1);
673
Inki Daeec05da92011-12-06 11:06:54 +0900674 /* check the crtc is detached already from encoder */
675 if (manager->pipe < 0)
676 goto out;
Inki Dae483b88f2011-11-11 21:28:00 +0900677
Inki Dae1c248b72011-10-04 19:19:01 +0900678 drm_handle_vblank(drm_dev, manager->pipe);
679 fimd_finish_pageflip(drm_dev, manager->pipe);
680
Inki Daeec05da92011-12-06 11:06:54 +0900681out:
Inki Dae1c248b72011-10-04 19:19:01 +0900682 return IRQ_HANDLED;
683}
684
Inki Dae41c24342011-10-14 13:29:48 +0900685static int fimd_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
Inki Dae1c248b72011-10-04 19:19:01 +0900686{
Inki Dae1c248b72011-10-04 19:19:01 +0900687 DRM_DEBUG_KMS("%s\n", __FILE__);
688
689 /*
690 * enable drm irq mode.
691 * - with irq_enabled = 1, we can use the vblank feature.
692 *
693 * P.S. note that we wouldn't use drm irq handler but
694 * just specific driver own one instead because
695 * drm framework supports only one irq handler.
696 */
697 drm_dev->irq_enabled = 1;
698
Inki Daeec05da92011-12-06 11:06:54 +0900699 /*
700 * with vblank_disable_allowed = 1, vblank interrupt will be disabled
701 * by drm timer once a current process gives up ownership of
702 * vblank event.(after drm_vblank_put function is called)
703 */
704 drm_dev->vblank_disable_allowed = 1;
705
Inki Dae1c248b72011-10-04 19:19:01 +0900706 return 0;
707}
708
Inki Dae29cb6022012-09-05 14:12:06 +0900709static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
Inki Dae1c248b72011-10-04 19:19:01 +0900710{
Inki Dae1c248b72011-10-04 19:19:01 +0900711 DRM_DEBUG_KMS("%s\n", __FILE__);
712
713 /* TODO. */
714}
715
716static int fimd_calc_clkdiv(struct fimd_context *ctx,
717 struct fb_videomode *timing)
718{
719 unsigned long clk = clk_get_rate(ctx->lcd_clk);
720 u32 retrace;
721 u32 clkdiv;
722 u32 best_framerate = 0;
723 u32 framerate;
724
725 DRM_DEBUG_KMS("%s\n", __FILE__);
726
727 retrace = timing->left_margin + timing->hsync_len +
728 timing->right_margin + timing->xres;
729 retrace *= timing->upper_margin + timing->vsync_len +
730 timing->lower_margin + timing->yres;
731
732 /* default framerate is 60Hz */
733 if (!timing->refresh)
734 timing->refresh = 60;
735
736 clk /= retrace;
737
738 for (clkdiv = 1; clkdiv < 0x100; clkdiv++) {
739 int tmp;
740
741 /* get best framerate */
742 framerate = clk / clkdiv;
743 tmp = timing->refresh - framerate;
744 if (tmp < 0) {
745 best_framerate = framerate;
746 continue;
747 } else {
748 if (!best_framerate)
749 best_framerate = framerate;
750 else if (tmp < (best_framerate - framerate))
751 best_framerate = framerate;
752 break;
753 }
754 }
755
756 return clkdiv;
757}
758
759static void fimd_clear_win(struct fimd_context *ctx, int win)
760{
761 u32 val;
762
763 DRM_DEBUG_KMS("%s\n", __FILE__);
764
765 writel(0, ctx->regs + WINCON(win));
766 writel(0, ctx->regs + VIDOSD_A(win));
767 writel(0, ctx->regs + VIDOSD_B(win));
768 writel(0, ctx->regs + VIDOSD_C(win));
769
770 if (win == 1 || win == 2)
771 writel(0, ctx->regs + VIDOSD_D(win));
772
773 val = readl(ctx->regs + SHADOWCON);
774 val &= ~SHADOWCON_WINx_PROTECT(win);
775 writel(val, ctx->regs + SHADOWCON);
776}
777
Inki Dae5d553932012-08-17 17:08:04 +0900778static int fimd_clock(struct fimd_context *ctx, bool enable)
Inki Dae373af0c2012-01-27 11:54:58 +0900779{
Inki Dae373af0c2012-01-27 11:54:58 +0900780 DRM_DEBUG_KMS("%s\n", __FILE__);
781
Inki Dae373af0c2012-01-27 11:54:58 +0900782 if (enable) {
783 int ret;
784
785 ret = clk_enable(ctx->bus_clk);
786 if (ret < 0)
787 return ret;
788
789 ret = clk_enable(ctx->lcd_clk);
790 if (ret < 0) {
791 clk_disable(ctx->bus_clk);
792 return ret;
793 }
Inki Dae5d553932012-08-17 17:08:04 +0900794 } else {
795 clk_disable(ctx->lcd_clk);
796 clk_disable(ctx->bus_clk);
797 }
798
799 return 0;
800}
801
802static int fimd_activate(struct fimd_context *ctx, bool enable)
803{
804 if (enable) {
805 int ret;
806 struct device *dev = ctx->subdrv.dev;
807
808 ret = fimd_clock(ctx, true);
809 if (ret < 0)
810 return ret;
Inki Dae373af0c2012-01-27 11:54:58 +0900811
812 ctx->suspended = false;
813
814 /* if vblank was enabled status, enable it again. */
815 if (test_and_clear_bit(0, &ctx->irq_flags))
816 fimd_enable_vblank(dev);
Inki Dae373af0c2012-01-27 11:54:58 +0900817 } else {
Inki Dae5d553932012-08-17 17:08:04 +0900818 fimd_clock(ctx, false);
Inki Dae373af0c2012-01-27 11:54:58 +0900819 ctx->suspended = true;
820 }
821
822 return 0;
823}
824
Inki Dae1c248b72011-10-04 19:19:01 +0900825static int __devinit fimd_probe(struct platform_device *pdev)
826{
827 struct device *dev = &pdev->dev;
828 struct fimd_context *ctx;
829 struct exynos_drm_subdrv *subdrv;
830 struct exynos_drm_fimd_pdata *pdata;
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900831 struct exynos_drm_panel_info *panel;
Inki Dae1c248b72011-10-04 19:19:01 +0900832 struct resource *res;
833 int win;
834 int ret = -EINVAL;
835
836 DRM_DEBUG_KMS("%s\n", __FILE__);
837
838 pdata = pdev->dev.platform_data;
839 if (!pdata) {
840 dev_err(dev, "no platform data specified\n");
841 return -EINVAL;
842 }
843
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900844 panel = &pdata->panel;
845 if (!panel) {
846 dev_err(dev, "panel is null.\n");
Inki Dae1c248b72011-10-04 19:19:01 +0900847 return -EINVAL;
848 }
849
Sachin Kamatedc57262012-06-19 11:47:39 +0530850 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
Inki Dae1c248b72011-10-04 19:19:01 +0900851 if (!ctx)
852 return -ENOMEM;
853
854 ctx->bus_clk = clk_get(dev, "fimd");
855 if (IS_ERR(ctx->bus_clk)) {
856 dev_err(dev, "failed to get bus clock\n");
857 ret = PTR_ERR(ctx->bus_clk);
858 goto err_clk_get;
859 }
860
Inki Dae1c248b72011-10-04 19:19:01 +0900861 ctx->lcd_clk = clk_get(dev, "sclk_fimd");
862 if (IS_ERR(ctx->lcd_clk)) {
863 dev_err(dev, "failed to get lcd clock\n");
864 ret = PTR_ERR(ctx->lcd_clk);
865 goto err_bus_clk;
866 }
867
Inki Dae1c248b72011-10-04 19:19:01 +0900868 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Inki Dae1c248b72011-10-04 19:19:01 +0900869
Sachin Kamatedc57262012-06-19 11:47:39 +0530870 ctx->regs = devm_request_and_ioremap(&pdev->dev, res);
Inki Dae1c248b72011-10-04 19:19:01 +0900871 if (!ctx->regs) {
872 dev_err(dev, "failed to map registers\n");
873 ret = -ENXIO;
Sachin Kamatedc57262012-06-19 11:47:39 +0530874 goto err_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900875 }
876
877 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
878 if (!res) {
879 dev_err(dev, "irq request failed.\n");
Sachin Kamatedc57262012-06-19 11:47:39 +0530880 goto err_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900881 }
882
883 ctx->irq = res->start;
884
Sachin Kamatedc57262012-06-19 11:47:39 +0530885 ret = devm_request_irq(&pdev->dev, ctx->irq, fimd_irq_handler,
886 0, "drm_fimd", ctx);
887 if (ret) {
Inki Dae1c248b72011-10-04 19:19:01 +0900888 dev_err(dev, "irq request failed.\n");
Sachin Kamatedc57262012-06-19 11:47:39 +0530889 goto err_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900890 }
891
Inki Dae1c248b72011-10-04 19:19:01 +0900892 ctx->vidcon0 = pdata->vidcon0;
893 ctx->vidcon1 = pdata->vidcon1;
894 ctx->default_win = pdata->default_win;
Eun-Chul Kim607c50d2012-02-14 15:59:46 +0900895 ctx->panel = panel;
Inki Dae1c248b72011-10-04 19:19:01 +0900896
Inki Dae1c248b72011-10-04 19:19:01 +0900897 subdrv = &ctx->subdrv;
898
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900899 subdrv->dev = dev;
900 subdrv->manager = &fimd_manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900901 subdrv->probe = fimd_subdrv_probe;
902 subdrv->remove = fimd_subdrv_remove;
Inki Dae1c248b72011-10-04 19:19:01 +0900903
Inki Daec32b06e2011-12-16 21:49:03 +0900904 mutex_init(&ctx->lock);
905
Inki Dae1c248b72011-10-04 19:19:01 +0900906 platform_set_drvdata(pdev, ctx);
Inki Daec32b06e2011-12-16 21:49:03 +0900907
Inki Daec32b06e2011-12-16 21:49:03 +0900908 pm_runtime_enable(dev);
909 pm_runtime_get_sync(dev);
910
Marek Szyprowski0d8ce3a2012-03-08 10:28:56 +0900911 ctx->clkdiv = fimd_calc_clkdiv(ctx, &panel->timing);
912 panel->timing.pixclock = clk_get_rate(ctx->lcd_clk) / ctx->clkdiv;
913
914 DRM_DEBUG_KMS("pixel clock = %d, clkdiv = %d\n",
915 panel->timing.pixclock, ctx->clkdiv);
916
Inki Daec32b06e2011-12-16 21:49:03 +0900917 for (win = 0; win < WINDOWS_NR; win++)
918 fimd_clear_win(ctx, win);
919
Inki Dae1c248b72011-10-04 19:19:01 +0900920 exynos_drm_subdrv_register(subdrv);
921
922 return 0;
923
Inki Dae1c248b72011-10-04 19:19:01 +0900924err_clk:
925 clk_disable(ctx->lcd_clk);
926 clk_put(ctx->lcd_clk);
927
928err_bus_clk:
929 clk_disable(ctx->bus_clk);
930 clk_put(ctx->bus_clk);
931
932err_clk_get:
Inki Dae1c248b72011-10-04 19:19:01 +0900933 return ret;
934}
935
936static int __devexit fimd_remove(struct platform_device *pdev)
937{
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900938 struct device *dev = &pdev->dev;
Inki Dae1c248b72011-10-04 19:19:01 +0900939 struct fimd_context *ctx = platform_get_drvdata(pdev);
940
941 DRM_DEBUG_KMS("%s\n", __FILE__);
942
943 exynos_drm_subdrv_unregister(&ctx->subdrv);
944
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900945 if (ctx->suspended)
946 goto out;
947
Inki Dae1c248b72011-10-04 19:19:01 +0900948 clk_disable(ctx->lcd_clk);
949 clk_disable(ctx->bus_clk);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900950
951 pm_runtime_set_suspended(dev);
952 pm_runtime_put_sync(dev);
953
954out:
955 pm_runtime_disable(dev);
956
Inki Dae1c248b72011-10-04 19:19:01 +0900957 clk_put(ctx->lcd_clk);
958 clk_put(ctx->bus_clk);
959
Inki Dae1c248b72011-10-04 19:19:01 +0900960 return 0;
961}
962
Inki Daee30d4bc2011-12-12 16:35:20 +0900963#ifdef CONFIG_PM_SLEEP
964static int fimd_suspend(struct device *dev)
965{
Inki Dae373af0c2012-01-27 11:54:58 +0900966 struct fimd_context *ctx = get_fimd_context(dev);
Inki Daee30d4bc2011-12-12 16:35:20 +0900967
Inki Dae373af0c2012-01-27 11:54:58 +0900968 /*
969 * do not use pm_runtime_suspend(). if pm_runtime_suspend() is
970 * called here, an error would be returned by that interface
971 * because the usage_count of pm runtime is more than 1.
972 */
Inki Dae5d553932012-08-17 17:08:04 +0900973 if (!pm_runtime_suspended(dev))
974 return fimd_activate(ctx, false);
975
976 return 0;
Inki Daee30d4bc2011-12-12 16:35:20 +0900977}
978
979static int fimd_resume(struct device *dev)
980{
Inki Dae373af0c2012-01-27 11:54:58 +0900981 struct fimd_context *ctx = get_fimd_context(dev);
Inki Daee30d4bc2011-12-12 16:35:20 +0900982
Inki Dae373af0c2012-01-27 11:54:58 +0900983 /*
984 * if entered to sleep when lcd panel was on, the usage_count
985 * of pm runtime would still be 1 so in this case, fimd driver
986 * should be on directly not drawing on pm runtime interface.
987 */
Inki Dae5d553932012-08-17 17:08:04 +0900988 if (pm_runtime_suspended(dev)) {
989 int ret;
990
991 ret = fimd_activate(ctx, true);
992 if (ret < 0)
993 return ret;
994
995 /*
996 * in case of dpms on(standby), fimd_apply function will
997 * be called by encoder's dpms callback to update fimd's
998 * registers but in case of sleep wakeup, it's not.
999 * so fimd_apply function should be called at here.
1000 */
1001 fimd_apply(dev);
1002 }
Inki Daee30d4bc2011-12-12 16:35:20 +09001003
Inki Daee30d4bc2011-12-12 16:35:20 +09001004 return 0;
1005}
1006#endif
1007
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001008#ifdef CONFIG_PM_RUNTIME
1009static int fimd_runtime_suspend(struct device *dev)
1010{
1011 struct fimd_context *ctx = get_fimd_context(dev);
1012
1013 DRM_DEBUG_KMS("%s\n", __FILE__);
1014
Inki Dae5d553932012-08-17 17:08:04 +09001015 return fimd_activate(ctx, false);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001016}
1017
1018static int fimd_runtime_resume(struct device *dev)
1019{
1020 struct fimd_context *ctx = get_fimd_context(dev);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001021
1022 DRM_DEBUG_KMS("%s\n", __FILE__);
1023
Inki Dae5d553932012-08-17 17:08:04 +09001024 return fimd_activate(ctx, true);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001025}
1026#endif
1027
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +05301028static struct platform_device_id fimd_driver_ids[] = {
1029 {
1030 .name = "exynos4-fb",
1031 .driver_data = (unsigned long)&exynos4_fimd_driver_data,
1032 }, {
1033 .name = "exynos5-fb",
1034 .driver_data = (unsigned long)&exynos5_fimd_driver_data,
1035 },
1036 {},
1037};
1038MODULE_DEVICE_TABLE(platform, fimd_driver_ids);
1039
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001040static const struct dev_pm_ops fimd_pm_ops = {
Inki Daee30d4bc2011-12-12 16:35:20 +09001041 SET_SYSTEM_SLEEP_PM_OPS(fimd_suspend, fimd_resume)
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001042 SET_RUNTIME_PM_OPS(fimd_runtime_suspend, fimd_runtime_resume, NULL)
1043};
1044
Joonyoung Shim132a5b92012-03-16 18:47:08 +09001045struct platform_driver fimd_driver = {
Inki Dae1c248b72011-10-04 19:19:01 +09001046 .probe = fimd_probe,
1047 .remove = __devexit_p(fimd_remove),
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +05301048 .id_table = fimd_driver_ids,
Inki Dae1c248b72011-10-04 19:19:01 +09001049 .driver = {
1050 .name = "exynos4-fb",
1051 .owner = THIS_MODULE,
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001052 .pm = &fimd_pm_ops,
Inki Dae1c248b72011-10-04 19:19:01 +09001053 },
1054};