blob: 3efe1aa89416701223745cec1ec587fb3ef0e2db [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>
Inki Dae1c248b72011-10-04 19:19:01 +090017#include <linux/platform_device.h>
18#include <linux/clk.h>
Sachin Kamat3f1c7812013-08-14 16:38:01 +053019#include <linux/of.h>
Joonyoung Shimd636ead2012-12-14 15:48:25 +090020#include <linux/of_device.h>
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +090021#include <linux/pm_runtime.h>
Inki Daef37cd5e2014-05-09 14:25:20 +090022#include <linux/component.h>
YoungJun Cho3854fab2014-07-17 18:01:21 +090023#include <linux/mfd/syscon.h>
24#include <linux/regmap.h>
Inki Dae1c248b72011-10-04 19:19:01 +090025
Vikas Sajjan7f4596f2013-03-07 12:15:21 +053026#include <video/of_display_timing.h>
Andrzej Hajda111e6052013-08-21 16:22:01 +020027#include <video/of_videomode.h>
Leela Krishna Amudala5a213a52012-08-08 09:44:49 +090028#include <video/samsung_fimd.h>
Inki Dae1c248b72011-10-04 19:19:01 +090029#include <drm/exynos_drm.h>
Inki Dae1c248b72011-10-04 19:19:01 +090030
31#include "exynos_drm_drv.h"
Marek Szyprowski0488f502015-11-30 14:53:21 +010032#include "exynos_drm_fb.h"
Inki Dae1c248b72011-10-04 19:19:01 +090033#include "exynos_drm_fbdev.h"
34#include "exynos_drm_crtc.h"
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +090035#include "exynos_drm_plane.h"
Inki Daebcc5cd1c2012-10-19 17:16:36 +090036#include "exynos_drm_iommu.h"
Inki Dae1c248b72011-10-04 19:19:01 +090037
38/*
Sachin Kamatb8654b32013-09-19 10:39:44 +053039 * FIMD stands for Fully Interactive Mobile Display and
Inki Dae1c248b72011-10-04 19:19:01 +090040 * as a display controller, it transfers contents drawn on memory
41 * to a LCD Panel through Display Interfaces such as RGB or
42 * CPU Interface.
43 */
44
Rahul Sharma66367462014-05-07 16:55:22 +053045#define MIN_FB_WIDTH_FOR_16WORD_BURST 128
Andrzej Hajda111e6052013-08-21 16:22:01 +020046
Inki Dae1c248b72011-10-04 19:19:01 +090047/* position control register for hardware window 0, 2 ~ 4.*/
48#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
49#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050050/*
51 * size control register for hardware windows 0 and alpha control register
52 * for hardware windows 1 ~ 4
53 */
54#define VIDOSD_C(win) (VIDOSD_BASE + 0x08 + (win) * 16)
55/* size control register for hardware windows 1 ~ 2. */
Inki Dae1c248b72011-10-04 19:19:01 +090056#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
57
Gustavo Padovan453b44a2015-04-01 13:02:05 -030058#define VIDWnALPHA0(win) (VIDW_ALPHA + 0x00 + (win) * 8)
59#define VIDWnALPHA1(win) (VIDW_ALPHA + 0x04 + (win) * 8)
60
Inki Dae1c248b72011-10-04 19:19:01 +090061#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
Gustavo Padovancb11b3f2015-08-15 13:26:16 -030062#define VIDWx_BUF_START_S(win, buf) (VIDW_BUF_START_S(buf) + (win) * 8)
Inki Dae1c248b72011-10-04 19:19:01 +090063#define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8)
64#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
65
66/* color key control register for hardware window 1 ~ 4. */
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050067#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8))
Inki Dae1c248b72011-10-04 19:19:01 +090068/* color key value register for hardware window 1 ~ 4. */
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050069#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8))
Inki Dae1c248b72011-10-04 19:19:01 +090070
Inki Daeb5bf0f12016-04-12 09:59:11 +090071/* I80 trigger control register */
YoungJun Cho3854fab2014-07-17 18:01:21 +090072#define TRIGCON 0x1A4
Inki Daeb5bf0f12016-04-12 09:59:11 +090073#define TRGMODE_ENABLE (1 << 0)
74#define SWTRGCMD_ENABLE (1 << 1)
Inki Daea6f75aa2016-04-18 17:54:39 +090075/* Exynos3250, 3472, 4415, 5260 5410, 5420 and 5422 only supported. */
Inki Daeb5bf0f12016-04-12 09:59:11 +090076#define HWTRGEN_ENABLE (1 << 3)
77#define HWTRGMASK_ENABLE (1 << 4)
Inki Daea6f75aa2016-04-18 17:54:39 +090078/* Exynos3250, 3472, 4415, 5260, 5420 and 5422 only supported. */
Inki Daeb5bf0f12016-04-12 09:59:11 +090079#define HWTRIGEN_PER_ENABLE (1 << 31)
YoungJun Cho3854fab2014-07-17 18:01:21 +090080
81/* display mode change control register except exynos4 */
82#define VIDOUT_CON 0x000
83#define VIDOUT_CON_F_I80_LDI0 (0x2 << 8)
84
85/* I80 interface control for main LDI register */
86#define I80IFCONFAx(x) (0x1B0 + (x) * 4)
87#define I80IFCONFBx(x) (0x1B8 + (x) * 4)
88#define LCD_CS_SETUP(x) ((x) << 16)
89#define LCD_WR_SETUP(x) ((x) << 12)
90#define LCD_WR_ACTIVE(x) ((x) << 8)
91#define LCD_WR_HOLD(x) ((x) << 4)
92#define I80IFEN_ENABLE (1 << 0)
93
Inki Dae1c248b72011-10-04 19:19:01 +090094/* FIMD has totally five hardware windows. */
95#define WINDOWS_NR 5
96
Inki Daea6f75aa2016-04-18 17:54:39 +090097/* HW trigger flag on i80 panel. */
98#define I80_HW_TRG (1 << 1)
99
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530100struct fimd_driver_data {
101 unsigned int timing_base;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900102 unsigned int lcdblk_offset;
103 unsigned int lcdblk_vt_shift;
104 unsigned int lcdblk_bypass_shift;
Chanho Park1feafd32016-02-12 22:31:39 +0900105 unsigned int lcdblk_mic_bypass_shift;
Inki Daea6f75aa2016-04-18 17:54:39 +0900106 unsigned int trg_type;
Tomasz Figade7af102013-05-01 21:02:27 +0200107
108 unsigned int has_shadowcon:1;
Tomasz Figa411d9ed2013-05-01 21:02:28 +0200109 unsigned int has_clksel:1;
Inki Dae5cc46212013-08-20 14:28:56 +0900110 unsigned int has_limited_fmt:1;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900111 unsigned int has_vidoutcon:1;
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900112 unsigned int has_vtsel:1;
Chanho Park1feafd32016-02-12 22:31:39 +0900113 unsigned int has_mic_bypass:1;
Andrzej Hajda196e0592016-04-30 01:39:08 +0900114 unsigned int has_dp_clk:1;
Inki Daea6f75aa2016-04-18 17:54:39 +0900115 unsigned int has_hw_trigger:1;
116 unsigned int has_trigger_per_te:1;
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530117};
118
Tomasz Figa725ddea2013-05-01 21:02:29 +0200119static struct fimd_driver_data s3c64xx_fimd_driver_data = {
120 .timing_base = 0x0,
121 .has_clksel = 1,
Inki Dae5cc46212013-08-20 14:28:56 +0900122 .has_limited_fmt = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900123 .has_hw_trigger = 1,
Tomasz Figa725ddea2013-05-01 21:02:29 +0200124};
125
Inki Daed6ce7b52014-08-18 16:53:19 +0900126static struct fimd_driver_data exynos3_fimd_driver_data = {
127 .timing_base = 0x20000,
128 .lcdblk_offset = 0x210,
129 .lcdblk_bypass_shift = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900130 .trg_type = I80_HW_TRG,
Inki Daed6ce7b52014-08-18 16:53:19 +0900131 .has_shadowcon = 1,
132 .has_vidoutcon = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900133 .has_trigger_per_te = 1,
Inki Daed6ce7b52014-08-18 16:53:19 +0900134};
135
Sachin Kamat6ecf18f2012-11-19 15:22:54 +0530136static struct fimd_driver_data exynos4_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530137 .timing_base = 0x0,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900138 .lcdblk_offset = 0x210,
139 .lcdblk_vt_shift = 10,
140 .lcdblk_bypass_shift = 1,
Tomasz Figade7af102013-05-01 21:02:27 +0200141 .has_shadowcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900142 .has_vtsel = 1,
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530143};
144
YoungJun Chodcb622a2014-11-07 15:12:25 +0900145static struct fimd_driver_data exynos4415_fimd_driver_data = {
146 .timing_base = 0x20000,
147 .lcdblk_offset = 0x210,
148 .lcdblk_vt_shift = 10,
149 .lcdblk_bypass_shift = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900150 .trg_type = I80_HW_TRG,
YoungJun Chodcb622a2014-11-07 15:12:25 +0900151 .has_shadowcon = 1,
152 .has_vidoutcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900153 .has_vtsel = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900154 .has_trigger_per_te = 1,
YoungJun Chodcb622a2014-11-07 15:12:25 +0900155};
156
Sachin Kamat6ecf18f2012-11-19 15:22:54 +0530157static struct fimd_driver_data exynos5_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530158 .timing_base = 0x20000,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900159 .lcdblk_offset = 0x214,
160 .lcdblk_vt_shift = 24,
161 .lcdblk_bypass_shift = 15,
Tomasz Figade7af102013-05-01 21:02:27 +0200162 .has_shadowcon = 1,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900163 .has_vidoutcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900164 .has_vtsel = 1,
Andrzej Hajda196e0592016-04-30 01:39:08 +0900165 .has_dp_clk = 1,
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530166};
167
Chanho Park1feafd32016-02-12 22:31:39 +0900168static struct fimd_driver_data exynos5420_fimd_driver_data = {
169 .timing_base = 0x20000,
170 .lcdblk_offset = 0x214,
171 .lcdblk_vt_shift = 24,
172 .lcdblk_bypass_shift = 15,
173 .lcdblk_mic_bypass_shift = 11,
Inki Daea6f75aa2016-04-18 17:54:39 +0900174 .trg_type = I80_HW_TRG,
Chanho Park1feafd32016-02-12 22:31:39 +0900175 .has_shadowcon = 1,
176 .has_vidoutcon = 1,
177 .has_vtsel = 1,
178 .has_mic_bypass = 1,
Andrzej Hajda196e0592016-04-30 01:39:08 +0900179 .has_dp_clk = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900180 .has_hw_trigger = 1,
181 .has_trigger_per_te = 1,
Chanho Park1feafd32016-02-12 22:31:39 +0900182};
183
Inki Dae1c248b72011-10-04 19:19:01 +0900184struct fimd_context {
Sean Paulbb7704d2014-01-30 16:19:06 -0500185 struct device *dev;
Sean Paul40c8ab42014-01-30 16:19:04 -0500186 struct drm_device *drm_dev;
Gustavo Padovan93bca242015-01-18 18:16:23 +0900187 struct exynos_drm_crtc *crtc;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900188 struct exynos_drm_plane planes[WINDOWS_NR];
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100189 struct exynos_drm_plane_config configs[WINDOWS_NR];
Inki Dae1c248b72011-10-04 19:19:01 +0900190 struct clk *bus_clk;
191 struct clk *lcd_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900192 void __iomem *regs;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900193 struct regmap *sysreg;
Inki Dae1c248b72011-10-04 19:19:01 +0900194 unsigned long irq_flags;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900195 u32 vidcon0;
Inki Dae1c248b72011-10-04 19:19:01 +0900196 u32 vidcon1;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900197 u32 vidout_con;
198 u32 i80ifcon;
199 bool i80_if;
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900200 bool suspended;
Sean Paul080be03d2014-02-19 21:02:55 +0900201 int pipe;
Prathyush K01ce1132012-12-06 20:16:04 +0530202 wait_queue_head_t wait_vsync_queue;
203 atomic_t wait_vsync_event;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900204 atomic_t win_updated;
205 atomic_t triggering;
Inki Dae1c248b72011-10-04 19:19:01 +0900206
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900207 const struct fimd_driver_data *driver_data;
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300208 struct drm_encoder *encoder;
Andrzej Hajda196e0592016-04-30 01:39:08 +0900209 struct exynos_drm_clk dp_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900210};
211
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900212static const struct of_device_id fimd_driver_dt_match[] = {
Tomasz Figa725ddea2013-05-01 21:02:29 +0200213 { .compatible = "samsung,s3c6400-fimd",
214 .data = &s3c64xx_fimd_driver_data },
Inki Daed6ce7b52014-08-18 16:53:19 +0900215 { .compatible = "samsung,exynos3250-fimd",
216 .data = &exynos3_fimd_driver_data },
Vikas Sajjan5830daf2013-02-27 16:02:58 +0530217 { .compatible = "samsung,exynos4210-fimd",
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900218 .data = &exynos4_fimd_driver_data },
YoungJun Chodcb622a2014-11-07 15:12:25 +0900219 { .compatible = "samsung,exynos4415-fimd",
220 .data = &exynos4415_fimd_driver_data },
Vikas Sajjan5830daf2013-02-27 16:02:58 +0530221 { .compatible = "samsung,exynos5250-fimd",
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900222 .data = &exynos5_fimd_driver_data },
Chanho Park1feafd32016-02-12 22:31:39 +0900223 { .compatible = "samsung,exynos5420-fimd",
224 .data = &exynos5420_fimd_driver_data },
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900225 {},
226};
Sjoerd Simons0262cee2014-07-30 11:28:31 +0900227MODULE_DEVICE_TABLE(of, fimd_driver_dt_match);
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900228
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100229static const enum drm_plane_type fimd_win_types[WINDOWS_NR] = {
230 DRM_PLANE_TYPE_PRIMARY,
231 DRM_PLANE_TYPE_OVERLAY,
232 DRM_PLANE_TYPE_OVERLAY,
233 DRM_PLANE_TYPE_OVERLAY,
234 DRM_PLANE_TYPE_CURSOR,
235};
236
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +0900237static const uint32_t fimd_formats[] = {
238 DRM_FORMAT_C8,
239 DRM_FORMAT_XRGB1555,
240 DRM_FORMAT_RGB565,
241 DRM_FORMAT_XRGB8888,
242 DRM_FORMAT_ARGB8888,
243};
244
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200245static int fimd_enable_vblank(struct exynos_drm_crtc *crtc)
246{
247 struct fimd_context *ctx = crtc->ctx;
248 u32 val;
249
250 if (ctx->suspended)
251 return -EPERM;
252
253 if (!test_and_set_bit(0, &ctx->irq_flags)) {
254 val = readl(ctx->regs + VIDINTCON0);
255
256 val |= VIDINTCON0_INT_ENABLE;
257
258 if (ctx->i80_if) {
259 val |= VIDINTCON0_INT_I80IFDONE;
260 val |= VIDINTCON0_INT_SYSMAINCON;
261 val &= ~VIDINTCON0_INT_SYSSUBCON;
262 } else {
263 val |= VIDINTCON0_INT_FRAME;
264
265 val &= ~VIDINTCON0_FRAMESEL0_MASK;
266 val |= VIDINTCON0_FRAMESEL0_VSYNC;
267 val &= ~VIDINTCON0_FRAMESEL1_MASK;
268 val |= VIDINTCON0_FRAMESEL1_NONE;
269 }
270
271 writel(val, ctx->regs + VIDINTCON0);
272 }
273
274 return 0;
275}
276
277static void fimd_disable_vblank(struct exynos_drm_crtc *crtc)
278{
279 struct fimd_context *ctx = crtc->ctx;
280 u32 val;
281
282 if (ctx->suspended)
283 return;
284
285 if (test_and_clear_bit(0, &ctx->irq_flags)) {
286 val = readl(ctx->regs + VIDINTCON0);
287
288 val &= ~VIDINTCON0_INT_ENABLE;
289
290 if (ctx->i80_if) {
291 val &= ~VIDINTCON0_INT_I80IFDONE;
292 val &= ~VIDINTCON0_INT_SYSMAINCON;
293 val &= ~VIDINTCON0_INT_SYSSUBCON;
294 } else
295 val &= ~VIDINTCON0_INT_FRAME;
296
297 writel(val, ctx->regs + VIDINTCON0);
298 }
299}
300
Gustavo Padovan93bca242015-01-18 18:16:23 +0900301static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc)
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900302{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900303 struct fimd_context *ctx = crtc->ctx;
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900304
305 if (ctx->suspended)
306 return;
307
308 atomic_set(&ctx->wait_vsync_event, 1);
309
310 /*
311 * wait for FIMD to signal VSYNC interrupt or return after
312 * timeout which is set to 50ms (refresh rate of 20).
313 */
314 if (!wait_event_timeout(ctx->wait_vsync_queue,
315 !atomic_read(&ctx->wait_vsync_event),
316 HZ/20))
317 DRM_DEBUG_KMS("vblank wait timed out.\n");
318}
319
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200320static void fimd_enable_video_output(struct fimd_context *ctx, unsigned int win,
YoungJun Chof181a542014-11-17 22:00:10 +0900321 bool enable)
322{
323 u32 val = readl(ctx->regs + WINCON(win));
324
325 if (enable)
326 val |= WINCONx_ENWIN;
327 else
328 val &= ~WINCONx_ENWIN;
329
330 writel(val, ctx->regs + WINCON(win));
331}
332
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200333static void fimd_enable_shadow_channel_path(struct fimd_context *ctx,
334 unsigned int win,
YoungJun Cho999d8b32014-11-17 22:00:11 +0900335 bool enable)
336{
337 u32 val = readl(ctx->regs + SHADOWCON);
338
339 if (enable)
340 val |= SHADOWCON_CHx_ENABLE(win);
341 else
342 val &= ~SHADOWCON_CHx_ENABLE(win);
343
344 writel(val, ctx->regs + SHADOWCON);
345}
346
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900347static void fimd_clear_channels(struct exynos_drm_crtc *crtc)
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900348{
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900349 struct fimd_context *ctx = crtc->ctx;
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200350 unsigned int win, ch_enabled = 0;
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900351
352 DRM_DEBUG_KMS("%s\n", __FILE__);
353
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200354 /* Hardware is in unknown state, so ensure it gets enabled properly */
355 pm_runtime_get_sync(ctx->dev);
356
357 clk_prepare_enable(ctx->bus_clk);
358 clk_prepare_enable(ctx->lcd_clk);
359
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900360 /* Check if any channel is enabled. */
361 for (win = 0; win < WINDOWS_NR; win++) {
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900362 u32 val = readl(ctx->regs + WINCON(win));
363
364 if (val & WINCONx_ENWIN) {
YoungJun Chof181a542014-11-17 22:00:10 +0900365 fimd_enable_video_output(ctx, win, false);
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900366
YoungJun Cho999d8b32014-11-17 22:00:11 +0900367 if (ctx->driver_data->has_shadowcon)
368 fimd_enable_shadow_channel_path(ctx, win,
369 false);
370
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900371 ch_enabled = 1;
372 }
373 }
374
375 /* Wait for vsync, as disable channel takes effect at next vsync */
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900376 if (ch_enabled) {
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200377 int pipe = ctx->pipe;
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900378
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200379 /* ensure that vblank interrupt won't be reported to core */
380 ctx->suspended = false;
381 ctx->pipe = -1;
382
383 fimd_enable_vblank(ctx->crtc);
Joonyoung Shim92dc7a02015-01-30 16:43:02 +0900384 fimd_wait_for_vblank(ctx->crtc);
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200385 fimd_disable_vblank(ctx->crtc);
386
387 ctx->suspended = true;
388 ctx->pipe = pipe;
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900389 }
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200390
391 clk_disable_unprepare(ctx->lcd_clk);
392 clk_disable_unprepare(ctx->bus_clk);
393
394 pm_runtime_put(ctx->dev);
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900395}
396
Sean Paula968e722014-01-30 16:19:20 -0500397static u32 fimd_calc_clkdiv(struct fimd_context *ctx,
398 const struct drm_display_mode *mode)
399{
Tobias Jakobifa9971d2016-05-05 18:23:38 +0200400 unsigned long ideal_clk;
Sean Paula968e722014-01-30 16:19:20 -0500401 u32 clkdiv;
402
Tobias Jakobifa9971d2016-05-05 18:23:38 +0200403 if (mode->clock == 0) {
404 DRM_ERROR("Mode has zero clock value.\n");
405 return 0xff;
406 }
407
408 ideal_clk = mode->clock * 1000;
409
YoungJun Cho3854fab2014-07-17 18:01:21 +0900410 if (ctx->i80_if) {
411 /*
412 * The frame done interrupt should be occurred prior to the
413 * next TE signal.
414 */
415 ideal_clk *= 2;
416 }
417
Sean Paula968e722014-01-30 16:19:20 -0500418 /* Find the clock divider value that gets us closest to ideal_clk */
Chanho Park217fb002016-02-11 23:11:20 +0900419 clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(ctx->lcd_clk), ideal_clk);
Sean Paula968e722014-01-30 16:19:20 -0500420
421 return (clkdiv < 0x100) ? clkdiv : 0xff;
422}
423
Inki Daea6f75aa2016-04-18 17:54:39 +0900424static void fimd_setup_trigger(struct fimd_context *ctx)
425{
426 void __iomem *timing_base = ctx->regs + ctx->driver_data->timing_base;
427 u32 trg_type = ctx->driver_data->trg_type;
428 u32 val = readl(timing_base + TRIGCON);
429
Inki Daeb5bf0f12016-04-12 09:59:11 +0900430 val &= ~(TRGMODE_ENABLE);
Inki Daea6f75aa2016-04-18 17:54:39 +0900431
432 if (trg_type == I80_HW_TRG) {
433 if (ctx->driver_data->has_hw_trigger)
Inki Daeb5bf0f12016-04-12 09:59:11 +0900434 val |= HWTRGEN_ENABLE | HWTRGMASK_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900435 if (ctx->driver_data->has_trigger_per_te)
Inki Daeb5bf0f12016-04-12 09:59:11 +0900436 val |= HWTRIGEN_PER_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900437 } else {
Inki Daeb5bf0f12016-04-12 09:59:11 +0900438 val |= TRGMODE_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900439 }
440
441 writel(val, timing_base + TRIGCON);
442}
443
Gustavo Padovan93bca242015-01-18 18:16:23 +0900444static void fimd_commit(struct exynos_drm_crtc *crtc)
Inki Dae1c248b72011-10-04 19:19:01 +0900445{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900446 struct fimd_context *ctx = crtc->ctx;
Joonyoung Shim020e79d2015-06-02 21:04:42 +0900447 struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900448 const struct fimd_driver_data *driver_data = ctx->driver_data;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900449 void *timing_base = ctx->regs + driver_data->timing_base;
450 u32 val, clkdiv;
Inki Dae1c248b72011-10-04 19:19:01 +0900451
Inki Daee30d4bc2011-12-12 16:35:20 +0900452 if (ctx->suspended)
453 return;
454
Sean Paula968e722014-01-30 16:19:20 -0500455 /* nothing to do if we haven't set the mode yet */
456 if (mode->htotal == 0 || mode->vtotal == 0)
457 return;
458
YoungJun Cho3854fab2014-07-17 18:01:21 +0900459 if (ctx->i80_if) {
460 val = ctx->i80ifcon | I80IFEN_ENABLE;
461 writel(val, timing_base + I80IFCONFAx(0));
Inki Dae1c248b72011-10-04 19:19:01 +0900462
YoungJun Cho3854fab2014-07-17 18:01:21 +0900463 /* disable auto frame rate */
464 writel(0, timing_base + I80IFCONFBx(0));
Sean Paula968e722014-01-30 16:19:20 -0500465
YoungJun Cho3854fab2014-07-17 18:01:21 +0900466 /* set video type selection to I80 interface */
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900467 if (driver_data->has_vtsel && ctx->sysreg &&
468 regmap_update_bits(ctx->sysreg,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900469 driver_data->lcdblk_offset,
470 0x3 << driver_data->lcdblk_vt_shift,
471 0x1 << driver_data->lcdblk_vt_shift)) {
472 DRM_ERROR("Failed to update sysreg for I80 i/f.\n");
473 return;
474 }
475 } else {
476 int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
477 u32 vidcon1;
Inki Dae1c248b72011-10-04 19:19:01 +0900478
YoungJun Cho3854fab2014-07-17 18:01:21 +0900479 /* setup polarity values */
480 vidcon1 = ctx->vidcon1;
481 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
482 vidcon1 |= VIDCON1_INV_VSYNC;
483 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
484 vidcon1 |= VIDCON1_INV_HSYNC;
485 writel(vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
Sean Paula968e722014-01-30 16:19:20 -0500486
YoungJun Cho3854fab2014-07-17 18:01:21 +0900487 /* setup vertical timing values. */
488 vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
489 vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
490 vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
491
492 val = VIDTCON0_VBPD(vbpd - 1) |
493 VIDTCON0_VFPD(vfpd - 1) |
494 VIDTCON0_VSPW(vsync_len - 1);
495 writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
496
497 /* setup horizontal timing values. */
498 hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
499 hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
500 hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
501
502 val = VIDTCON1_HBPD(hbpd - 1) |
503 VIDTCON1_HFPD(hfpd - 1) |
504 VIDTCON1_HSPW(hsync_len - 1);
505 writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
506 }
507
508 if (driver_data->has_vidoutcon)
509 writel(ctx->vidout_con, timing_base + VIDOUT_CON);
510
511 /* set bypass selection */
512 if (ctx->sysreg && regmap_update_bits(ctx->sysreg,
513 driver_data->lcdblk_offset,
514 0x1 << driver_data->lcdblk_bypass_shift,
515 0x1 << driver_data->lcdblk_bypass_shift)) {
516 DRM_ERROR("Failed to update sysreg for bypass setting.\n");
517 return;
518 }
Inki Dae1c248b72011-10-04 19:19:01 +0900519
Chanho Park1feafd32016-02-12 22:31:39 +0900520 /* TODO: When MIC is enabled for display path, the lcdblk_mic_bypass
521 * bit should be cleared.
522 */
523 if (driver_data->has_mic_bypass && ctx->sysreg &&
524 regmap_update_bits(ctx->sysreg,
525 driver_data->lcdblk_offset,
526 0x1 << driver_data->lcdblk_mic_bypass_shift,
527 0x1 << driver_data->lcdblk_mic_bypass_shift)) {
528 DRM_ERROR("Failed to update sysreg for bypass mic.\n");
529 return;
530 }
531
Inki Dae1c248b72011-10-04 19:19:01 +0900532 /* setup horizontal and vertical display size. */
Sean Paula968e722014-01-30 16:19:20 -0500533 val = VIDTCON2_LINEVAL(mode->vdisplay - 1) |
534 VIDTCON2_HOZVAL(mode->hdisplay - 1) |
535 VIDTCON2_LINEVAL_E(mode->vdisplay - 1) |
536 VIDTCON2_HOZVAL_E(mode->hdisplay - 1);
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530537 writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
Inki Dae1c248b72011-10-04 19:19:01 +0900538
Inki Daea6f75aa2016-04-18 17:54:39 +0900539 fimd_setup_trigger(ctx);
540
Inki Dae1c248b72011-10-04 19:19:01 +0900541 /*
542 * fields of register with prefix '_F' would be updated
543 * at vsync(same as dma start)
544 */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900545 val = ctx->vidcon0;
546 val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
Andrzej Hajda1d531062014-03-20 17:09:00 +0900547
548 if (ctx->driver_data->has_clksel)
549 val |= VIDCON0_CLKSEL_LCD;
550
551 clkdiv = fimd_calc_clkdiv(ctx, mode);
552 if (clkdiv > 1)
553 val |= VIDCON0_CLKVAL_F(clkdiv - 1) | VIDCON0_CLKDIR;
554
Inki Dae1c248b72011-10-04 19:19:01 +0900555 writel(val, ctx->regs + VIDCON0);
556}
557
Inki Dae1c248b72011-10-04 19:19:01 +0900558
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900559static void fimd_win_set_pixfmt(struct fimd_context *ctx, unsigned int win,
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100560 uint32_t pixel_format, int width)
Inki Dae1c248b72011-10-04 19:19:01 +0900561{
Inki Dae1c248b72011-10-04 19:19:01 +0900562 unsigned long val;
563
Inki Dae1c248b72011-10-04 19:19:01 +0900564 val = WINCONx_ENWIN;
565
Inki Dae5cc46212013-08-20 14:28:56 +0900566 /*
567 * In case of s3c64xx, window 0 doesn't support alpha channel.
568 * So the request format is ARGB8888 then change it to XRGB8888.
569 */
570 if (ctx->driver_data->has_limited_fmt && !win) {
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100571 if (pixel_format == DRM_FORMAT_ARGB8888)
572 pixel_format = DRM_FORMAT_XRGB8888;
Inki Dae5cc46212013-08-20 14:28:56 +0900573 }
574
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100575 switch (pixel_format) {
Inki Daea4f38a82013-08-20 13:51:02 +0900576 case DRM_FORMAT_C8:
Inki Dae1c248b72011-10-04 19:19:01 +0900577 val |= WINCON0_BPPMODE_8BPP_PALETTE;
578 val |= WINCONx_BURSTLEN_8WORD;
579 val |= WINCONx_BYTSWP;
580 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900581 case DRM_FORMAT_XRGB1555:
582 val |= WINCON0_BPPMODE_16BPP_1555;
583 val |= WINCONx_HAWSWP;
584 val |= WINCONx_BURSTLEN_16WORD;
585 break;
586 case DRM_FORMAT_RGB565:
Inki Dae1c248b72011-10-04 19:19:01 +0900587 val |= WINCON0_BPPMODE_16BPP_565;
588 val |= WINCONx_HAWSWP;
589 val |= WINCONx_BURSTLEN_16WORD;
590 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900591 case DRM_FORMAT_XRGB8888:
Inki Dae1c248b72011-10-04 19:19:01 +0900592 val |= WINCON0_BPPMODE_24BPP_888;
593 val |= WINCONx_WSWP;
594 val |= WINCONx_BURSTLEN_16WORD;
595 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900596 case DRM_FORMAT_ARGB8888:
597 val |= WINCON1_BPPMODE_25BPP_A1888
Inki Dae1c248b72011-10-04 19:19:01 +0900598 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
599 val |= WINCONx_WSWP;
600 val |= WINCONx_BURSTLEN_16WORD;
601 break;
602 default:
603 DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n");
604
605 val |= WINCON0_BPPMODE_24BPP_888;
606 val |= WINCONx_WSWP;
607 val |= WINCONx_BURSTLEN_16WORD;
608 break;
609 }
610
Rahul Sharma66367462014-05-07 16:55:22 +0530611 /*
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100612 * Setting dma-burst to 16Word causes permanent tearing for very small
613 * buffers, e.g. cursor buffer. Burst Mode switching which based on
614 * plane size is not recommended as plane size varies alot towards the
615 * end of the screen and rapid movement causes unstable DMA, but it is
616 * still better to change dma-burst than displaying garbage.
Rahul Sharma66367462014-05-07 16:55:22 +0530617 */
618
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100619 if (width < MIN_FB_WIDTH_FOR_16WORD_BURST) {
Rahul Sharma66367462014-05-07 16:55:22 +0530620 val &= ~WINCONx_BURSTLEN_MASK;
621 val |= WINCONx_BURSTLEN_4WORD;
622 }
623
Inki Dae1c248b72011-10-04 19:19:01 +0900624 writel(val, ctx->regs + WINCON(win));
Gustavo Padovan453b44a2015-04-01 13:02:05 -0300625
626 /* hardware window 0 doesn't support alpha channel. */
627 if (win != 0) {
628 /* OSD alpha */
629 val = VIDISD14C_ALPHA0_R(0xf) |
630 VIDISD14C_ALPHA0_G(0xf) |
631 VIDISD14C_ALPHA0_B(0xf) |
632 VIDISD14C_ALPHA1_R(0xf) |
633 VIDISD14C_ALPHA1_G(0xf) |
634 VIDISD14C_ALPHA1_B(0xf);
635
636 writel(val, ctx->regs + VIDOSD_C(win));
637
638 val = VIDW_ALPHA_R(0xf) | VIDW_ALPHA_G(0xf) |
639 VIDW_ALPHA_G(0xf);
640 writel(val, ctx->regs + VIDWnALPHA0(win));
641 writel(val, ctx->regs + VIDWnALPHA1(win));
642 }
Inki Dae1c248b72011-10-04 19:19:01 +0900643}
644
Sean Paulbb7704d2014-01-30 16:19:06 -0500645static void fimd_win_set_colkey(struct fimd_context *ctx, unsigned int win)
Inki Dae1c248b72011-10-04 19:19:01 +0900646{
Inki Dae1c248b72011-10-04 19:19:01 +0900647 unsigned int keycon0 = 0, keycon1 = 0;
648
Inki Dae1c248b72011-10-04 19:19:01 +0900649 keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
650 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
651
652 keycon1 = WxKEYCON1_COLVAL(0xffffffff);
653
654 writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
655 writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
656}
657
Tomasz Figade7af102013-05-01 21:02:27 +0200658/**
659 * shadow_protect_win() - disable updating values from shadow registers at vsync
660 *
661 * @win: window to protect registers for
662 * @protect: 1 to protect (disable updates)
663 */
664static void fimd_shadow_protect_win(struct fimd_context *ctx,
Gustavo Padovan6e2a3b62015-04-03 21:05:52 +0900665 unsigned int win, bool protect)
Tomasz Figade7af102013-05-01 21:02:27 +0200666{
667 u32 reg, bits, val;
668
Gustavo Padovance3ff362015-08-15 13:26:13 -0300669 /*
670 * SHADOWCON/PRTCON register is used for enabling timing.
671 *
672 * for example, once only width value of a register is set,
673 * if the dma is started then fimd hardware could malfunction so
674 * with protect window setting, the register fields with prefix '_F'
675 * wouldn't be updated at vsync also but updated once unprotect window
676 * is set.
677 */
678
Tomasz Figade7af102013-05-01 21:02:27 +0200679 if (ctx->driver_data->has_shadowcon) {
680 reg = SHADOWCON;
681 bits = SHADOWCON_WINx_PROTECT(win);
682 } else {
683 reg = PRTCON;
684 bits = PRTCON_PROTECT;
685 }
686
687 val = readl(ctx->regs + reg);
688 if (protect)
689 val |= bits;
690 else
691 val &= ~bits;
692 writel(val, ctx->regs + reg);
693}
694
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100695static void fimd_atomic_begin(struct exynos_drm_crtc *crtc)
Gustavo Padovance3ff362015-08-15 13:26:13 -0300696{
697 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100698 int i;
Gustavo Padovance3ff362015-08-15 13:26:13 -0300699
700 if (ctx->suspended)
701 return;
702
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100703 for (i = 0; i < WINDOWS_NR; i++)
704 fimd_shadow_protect_win(ctx, i, true);
Gustavo Padovance3ff362015-08-15 13:26:13 -0300705}
706
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100707static void fimd_atomic_flush(struct exynos_drm_crtc *crtc)
Gustavo Padovance3ff362015-08-15 13:26:13 -0300708{
709 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100710 int i;
Gustavo Padovance3ff362015-08-15 13:26:13 -0300711
712 if (ctx->suspended)
713 return;
714
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100715 for (i = 0; i < WINDOWS_NR; i++)
716 fimd_shadow_protect_win(ctx, i, false);
Gustavo Padovance3ff362015-08-15 13:26:13 -0300717}
718
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900719static void fimd_update_plane(struct exynos_drm_crtc *crtc,
720 struct exynos_drm_plane *plane)
Inki Dae1c248b72011-10-04 19:19:01 +0900721{
Marek Szyprowski0114f402015-11-30 14:53:22 +0100722 struct exynos_drm_plane_state *state =
723 to_exynos_plane_state(plane->base.state);
Gustavo Padovan93bca242015-01-18 18:16:23 +0900724 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100725 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900726 dma_addr_t dma_addr;
727 unsigned long val, size, offset;
728 unsigned int last_x, last_y, buf_offsize, line_size;
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100729 unsigned int win = plane->index;
Marek Szyprowski0488f502015-11-30 14:53:21 +0100730 unsigned int bpp = fb->bits_per_pixel >> 3;
731 unsigned int pitch = fb->pitches[0];
Inki Dae1c248b72011-10-04 19:19:01 +0900732
Inki Daee30d4bc2011-12-12 16:35:20 +0900733 if (ctx->suspended)
734 return;
735
Marek Szyprowski0114f402015-11-30 14:53:22 +0100736 offset = state->src.x * bpp;
737 offset += state->src.y * pitch;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900738
Inki Dae1c248b72011-10-04 19:19:01 +0900739 /* buffer start address */
Marek Szyprowski0488f502015-11-30 14:53:21 +0100740 dma_addr = exynos_drm_fb_dma_addr(fb, 0) + offset;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900741 val = (unsigned long)dma_addr;
Inki Dae1c248b72011-10-04 19:19:01 +0900742 writel(val, ctx->regs + VIDWx_BUF_START(win, 0));
743
744 /* buffer end address */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100745 size = pitch * state->crtc.h;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900746 val = (unsigned long)(dma_addr + size);
Inki Dae1c248b72011-10-04 19:19:01 +0900747 writel(val, ctx->regs + VIDWx_BUF_END(win, 0));
748
749 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900750 (unsigned long)dma_addr, val, size);
Inki Dae19c8b832011-10-14 13:29:46 +0900751 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
Marek Szyprowski0114f402015-11-30 14:53:22 +0100752 state->crtc.w, state->crtc.h);
Inki Dae1c248b72011-10-04 19:19:01 +0900753
754 /* buffer size */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100755 buf_offsize = pitch - (state->crtc.w * bpp);
756 line_size = state->crtc.w * bpp;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900757 val = VIDW_BUF_SIZE_OFFSET(buf_offsize) |
758 VIDW_BUF_SIZE_PAGEWIDTH(line_size) |
759 VIDW_BUF_SIZE_OFFSET_E(buf_offsize) |
760 VIDW_BUF_SIZE_PAGEWIDTH_E(line_size);
Inki Dae1c248b72011-10-04 19:19:01 +0900761 writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0));
762
763 /* OSD position */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100764 val = VIDOSDxA_TOPLEFT_X(state->crtc.x) |
765 VIDOSDxA_TOPLEFT_Y(state->crtc.y) |
766 VIDOSDxA_TOPLEFT_X_E(state->crtc.x) |
767 VIDOSDxA_TOPLEFT_Y_E(state->crtc.y);
Inki Dae1c248b72011-10-04 19:19:01 +0900768 writel(val, ctx->regs + VIDOSD_A(win));
769
Marek Szyprowski0114f402015-11-30 14:53:22 +0100770 last_x = state->crtc.x + state->crtc.w;
Joonyoung Shimf56aad32012-12-14 15:48:23 +0900771 if (last_x)
772 last_x--;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100773 last_y = state->crtc.y + state->crtc.h;
Joonyoung Shimf56aad32012-12-14 15:48:23 +0900774 if (last_y)
775 last_y--;
776
Joonyoung Shimca555e52012-12-14 15:48:24 +0900777 val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y) |
778 VIDOSDxB_BOTRIGHT_X_E(last_x) | VIDOSDxB_BOTRIGHT_Y_E(last_y);
779
Inki Dae1c248b72011-10-04 19:19:01 +0900780 writel(val, ctx->regs + VIDOSD_B(win));
781
Inki Dae19c8b832011-10-14 13:29:46 +0900782 DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
Marek Szyprowski0114f402015-11-30 14:53:22 +0100783 state->crtc.x, state->crtc.y, last_x, last_y);
Inki Dae1c248b72011-10-04 19:19:01 +0900784
Inki Dae1c248b72011-10-04 19:19:01 +0900785 /* OSD size */
786 if (win != 3 && win != 4) {
787 u32 offset = VIDOSD_D(win);
788 if (win == 0)
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -0500789 offset = VIDOSD_C(win);
Marek Szyprowski0114f402015-11-30 14:53:22 +0100790 val = state->crtc.w * state->crtc.h;
Inki Dae1c248b72011-10-04 19:19:01 +0900791 writel(val, ctx->regs + offset);
792
793 DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val);
794 }
795
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100796 fimd_win_set_pixfmt(ctx, win, fb->pixel_format, state->src.w);
Inki Dae1c248b72011-10-04 19:19:01 +0900797
798 /* hardware window 0 doesn't support color key. */
799 if (win != 0)
Sean Paulbb7704d2014-01-30 16:19:06 -0500800 fimd_win_set_colkey(ctx, win);
Inki Dae1c248b72011-10-04 19:19:01 +0900801
YoungJun Chof181a542014-11-17 22:00:10 +0900802 fimd_enable_video_output(ctx, win, true);
Inki Daeec05da92011-12-06 11:06:54 +0900803
YoungJun Cho999d8b32014-11-17 22:00:11 +0900804 if (ctx->driver_data->has_shadowcon)
805 fimd_enable_shadow_channel_path(ctx, win, true);
Inki Daeec05da92011-12-06 11:06:54 +0900806
YoungJun Cho3854fab2014-07-17 18:01:21 +0900807 if (ctx->i80_if)
808 atomic_set(&ctx->win_updated, 1);
Inki Dae1c248b72011-10-04 19:19:01 +0900809}
810
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900811static void fimd_disable_plane(struct exynos_drm_crtc *crtc,
812 struct exynos_drm_plane *plane)
Inki Dae1c248b72011-10-04 19:19:01 +0900813{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900814 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100815 unsigned int win = plane->index;
Inki Daeec05da92011-12-06 11:06:54 +0900816
Joonyoung Shimc329f662015-06-12 20:34:28 +0900817 if (ctx->suspended)
Prathyush Kdb7e55a2012-12-06 20:16:06 +0530818 return;
Prathyush Kdb7e55a2012-12-06 20:16:06 +0530819
YoungJun Chof181a542014-11-17 22:00:10 +0900820 fimd_enable_video_output(ctx, win, false);
Inki Dae1c248b72011-10-04 19:19:01 +0900821
YoungJun Cho999d8b32014-11-17 22:00:11 +0900822 if (ctx->driver_data->has_shadowcon)
823 fimd_enable_shadow_channel_path(ctx, win, false);
Sean Paula43b9332014-01-30 16:19:26 -0500824}
825
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300826static void fimd_enable(struct exynos_drm_crtc *crtc)
Sean Paula43b9332014-01-30 16:19:26 -0500827{
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300828 struct fimd_context *ctx = crtc->ctx;
Sean Paula43b9332014-01-30 16:19:26 -0500829
830 if (!ctx->suspended)
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300831 return;
Sean Paula43b9332014-01-30 16:19:26 -0500832
833 ctx->suspended = false;
834
Sean Paulaf65c802014-01-30 16:19:27 -0500835 pm_runtime_get_sync(ctx->dev);
836
Sean Paula43b9332014-01-30 16:19:26 -0500837 /* if vblank was enabled status, enable it again. */
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300838 if (test_and_clear_bit(0, &ctx->irq_flags))
839 fimd_enable_vblank(ctx->crtc);
Sean Paula43b9332014-01-30 16:19:26 -0500840
Joonyoung Shimc329f662015-06-12 20:34:28 +0900841 fimd_commit(ctx->crtc);
Sean Paula43b9332014-01-30 16:19:26 -0500842}
843
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300844static void fimd_disable(struct exynos_drm_crtc *crtc)
Sean Paula43b9332014-01-30 16:19:26 -0500845{
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300846 struct fimd_context *ctx = crtc->ctx;
Joonyoung Shimc329f662015-06-12 20:34:28 +0900847 int i;
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300848
Sean Paula43b9332014-01-30 16:19:26 -0500849 if (ctx->suspended)
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300850 return;
Sean Paula43b9332014-01-30 16:19:26 -0500851
852 /*
853 * We need to make sure that all windows are disabled before we
854 * suspend that connector. Otherwise we might try to scan from
855 * a destroyed buffer later.
856 */
Joonyoung Shimc329f662015-06-12 20:34:28 +0900857 for (i = 0; i < WINDOWS_NR; i++)
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900858 fimd_disable_plane(crtc, &ctx->planes[i]);
Sean Paula43b9332014-01-30 16:19:26 -0500859
Inki Dae94ab95a2015-06-12 22:19:22 +0900860 fimd_enable_vblank(crtc);
861 fimd_wait_for_vblank(crtc);
862 fimd_disable_vblank(crtc);
863
Joonyoung Shimb74f14f2015-06-12 17:27:16 +0900864 writel(0, ctx->regs + VIDCON0);
865
Sean Paulaf65c802014-01-30 16:19:27 -0500866 pm_runtime_put_sync(ctx->dev);
Sean Paula43b9332014-01-30 16:19:26 -0500867 ctx->suspended = true;
Sean Paul080be03d2014-02-19 21:02:55 +0900868}
869
YoungJun Cho3854fab2014-07-17 18:01:21 +0900870static void fimd_trigger(struct device *dev)
871{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +0100872 struct fimd_context *ctx = dev_get_drvdata(dev);
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900873 const struct fimd_driver_data *driver_data = ctx->driver_data;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900874 void *timing_base = ctx->regs + driver_data->timing_base;
875 u32 reg;
876
Joonyoung Shim9b67eb72014-11-17 22:00:08 +0900877 /*
YoungJun Cho1c905d92014-11-17 22:00:12 +0900878 * Skips triggering if in triggering state, because multiple triggering
879 * requests can cause panel reset.
880 */
Joonyoung Shim9b67eb72014-11-17 22:00:08 +0900881 if (atomic_read(&ctx->triggering))
882 return;
883
YoungJun Cho1c905d92014-11-17 22:00:12 +0900884 /* Enters triggering mode */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900885 atomic_set(&ctx->triggering, 1);
886
YoungJun Cho3854fab2014-07-17 18:01:21 +0900887 reg = readl(timing_base + TRIGCON);
Inki Daeb5bf0f12016-04-12 09:59:11 +0900888 reg |= (TRGMODE_ENABLE | SWTRGCMD_ENABLE);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900889 writel(reg, timing_base + TRIGCON);
YoungJun Cho87ab85b2014-11-17 22:00:13 +0900890
891 /*
892 * Exits triggering mode if vblank is not enabled yet, because when the
893 * VIDINTCON0 register is not set, it can not exit from triggering mode.
894 */
895 if (!test_bit(0, &ctx->irq_flags))
896 atomic_set(&ctx->triggering, 0);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900897}
898
Gustavo Padovan93bca242015-01-18 18:16:23 +0900899static void fimd_te_handler(struct exynos_drm_crtc *crtc)
YoungJun Cho3854fab2014-07-17 18:01:21 +0900900{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900901 struct fimd_context *ctx = crtc->ctx;
Inki Daea6f75aa2016-04-18 17:54:39 +0900902 u32 trg_type = ctx->driver_data->trg_type;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900903
904 /* Checks the crtc is detached already from encoder */
905 if (ctx->pipe < 0 || !ctx->drm_dev)
906 return;
907
Inki Daea6f75aa2016-04-18 17:54:39 +0900908 if (trg_type == I80_HW_TRG)
909 goto out;
910
YoungJun Cho3854fab2014-07-17 18:01:21 +0900911 /*
912 * If there is a page flip request, triggers and handles the page flip
913 * event so that current fb can be updated into panel GRAM.
914 */
915 if (atomic_add_unless(&ctx->win_updated, -1, 0))
916 fimd_trigger(ctx->dev);
917
Inki Daea6f75aa2016-04-18 17:54:39 +0900918out:
YoungJun Cho3854fab2014-07-17 18:01:21 +0900919 /* Wakes up vsync event queue */
920 if (atomic_read(&ctx->wait_vsync_event)) {
921 atomic_set(&ctx->wait_vsync_event, 0);
922 wake_up(&ctx->wait_vsync_queue);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900923 }
YoungJun Chob301ae22014-10-01 15:19:10 +0900924
Joonyoung Shimadf67ab2014-11-17 22:00:14 +0900925 if (test_bit(0, &ctx->irq_flags))
Gustavo Padovaneafd5402015-07-16 12:23:32 -0300926 drm_crtc_handle_vblank(&ctx->crtc->base);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900927}
928
Andrzej Hajda196e0592016-04-30 01:39:08 +0900929static void fimd_dp_clock_enable(struct exynos_drm_clk *clk, bool enable)
Krzysztof Kozlowski48107d72015-05-07 09:04:44 +0900930{
Andrzej Hajda196e0592016-04-30 01:39:08 +0900931 struct fimd_context *ctx = container_of(clk, struct fimd_context,
932 dp_clk);
933 u32 val = enable ? DP_MIE_CLK_DP_ENABLE : DP_MIE_CLK_DISABLE;
Gustavo Padovan3c79fb82015-09-30 18:40:54 -0300934 writel(val, ctx->regs + DP_MIE_CLKCON);
Krzysztof Kozlowski48107d72015-05-07 09:04:44 +0900935}
936
Krzysztof Kozlowskif3aaf762015-05-07 09:04:45 +0900937static const struct exynos_drm_crtc_ops fimd_crtc_ops = {
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300938 .enable = fimd_enable,
939 .disable = fimd_disable,
Sean Paul1c6244c2014-01-30 16:19:02 -0500940 .commit = fimd_commit,
941 .enable_vblank = fimd_enable_vblank,
942 .disable_vblank = fimd_disable_vblank,
Gustavo Padovance3ff362015-08-15 13:26:13 -0300943 .atomic_begin = fimd_atomic_begin,
Gustavo Padovan9cc76102015-08-03 14:38:05 +0900944 .update_plane = fimd_update_plane,
945 .disable_plane = fimd_disable_plane,
Gustavo Padovance3ff362015-08-15 13:26:13 -0300946 .atomic_flush = fimd_atomic_flush,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900947 .te_handler = fimd_te_handler,
Inki Dae1c248b72011-10-04 19:19:01 +0900948};
949
Inki Dae1c248b72011-10-04 19:19:01 +0900950static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
951{
952 struct fimd_context *ctx = (struct fimd_context *)dev_id;
Gustavo Padovancb11b3f2015-08-15 13:26:16 -0300953 u32 val, clear_bit, start, start_s;
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300954 int win;
Inki Dae1c248b72011-10-04 19:19:01 +0900955
956 val = readl(ctx->regs + VIDINTCON1);
957
YoungJun Cho3854fab2014-07-17 18:01:21 +0900958 clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME;
959 if (val & clear_bit)
960 writel(clear_bit, ctx->regs + VIDINTCON1);
Inki Dae1c248b72011-10-04 19:19:01 +0900961
Inki Daeec05da92011-12-06 11:06:54 +0900962 /* check the crtc is detached already from encoder */
Sean Paul080be03d2014-02-19 21:02:55 +0900963 if (ctx->pipe < 0 || !ctx->drm_dev)
Inki Daeec05da92011-12-06 11:06:54 +0900964 goto out;
Inki Dae483b88f2011-11-11 21:28:00 +0900965
Gustavo Padovanfc75f712015-08-15 13:26:11 -0300966 if (!ctx->i80_if)
967 drm_crtc_handle_vblank(&ctx->crtc->base);
Joonyoung Shimadf67ab2014-11-17 22:00:14 +0900968
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300969 for (win = 0 ; win < WINDOWS_NR ; win++) {
970 struct exynos_drm_plane *plane = &ctx->planes[win];
971
972 if (!plane->pending_fb)
973 continue;
974
Gustavo Padovancb11b3f2015-08-15 13:26:16 -0300975 start = readl(ctx->regs + VIDWx_BUF_START(win, 0));
976 start_s = readl(ctx->regs + VIDWx_BUF_START_S(win, 0));
977 if (start == start_s)
978 exynos_drm_crtc_finish_update(ctx->crtc, plane);
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300979 }
Gustavo Padovanfc75f712015-08-15 13:26:11 -0300980
981 if (ctx->i80_if) {
YoungJun Cho1c905d92014-11-17 22:00:12 +0900982 /* Exits triggering mode */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900983 atomic_set(&ctx->triggering, 0);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900984 } else {
YoungJun Cho3854fab2014-07-17 18:01:21 +0900985 /* set wait vsync event to zero and wake up queue. */
986 if (atomic_read(&ctx->wait_vsync_event)) {
987 atomic_set(&ctx->wait_vsync_event, 0);
988 wake_up(&ctx->wait_vsync_queue);
989 }
Prathyush K01ce1132012-12-06 20:16:04 +0530990 }
YoungJun Cho3854fab2014-07-17 18:01:21 +0900991
Inki Daeec05da92011-12-06 11:06:54 +0900992out:
Inki Dae1c248b72011-10-04 19:19:01 +0900993 return IRQ_HANDLED;
994}
995
Inki Daef37cd5e2014-05-09 14:25:20 +0900996static int fimd_bind(struct device *dev, struct device *master, void *data)
Andrzej Hajda562ad9f2013-08-21 16:22:03 +0200997{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +0100998 struct fimd_context *ctx = dev_get_drvdata(dev);
Inki Daef37cd5e2014-05-09 14:25:20 +0900999 struct drm_device *drm_dev = data;
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +09001000 struct exynos_drm_private *priv = drm_dev->dev_private;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001001 struct exynos_drm_plane *exynos_plane;
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001002 unsigned int i;
Gustavo Padovan6e2a3b62015-04-03 21:05:52 +09001003 int ret;
Andrzej Hajda000cc922014-04-03 16:26:00 +02001004
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +09001005 ctx->drm_dev = drm_dev;
1006 ctx->pipe = priv->pipe++;
Ajay Kumarefa75bc2015-01-12 01:57:07 +09001007
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001008 for (i = 0; i < WINDOWS_NR; i++) {
1009 ctx->configs[i].pixel_formats = fimd_formats;
1010 ctx->configs[i].num_pixel_formats = ARRAY_SIZE(fimd_formats);
1011 ctx->configs[i].zpos = i;
1012 ctx->configs[i].type = fimd_win_types[i];
Marek Szyprowski40bdfb02015-12-16 13:21:42 +01001013 ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001014 1 << ctx->pipe, &ctx->configs[i]);
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001015 if (ret)
1016 return ret;
1017 }
1018
Gustavo Padovan5d3d0992015-10-12 22:07:48 +09001019 exynos_plane = &ctx->planes[DEFAULT_WIN];
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001020 ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1021 ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD,
Joonyoung Shim0f04cf82015-01-30 16:43:01 +09001022 &fimd_crtc_ops, ctx);
Hyungwon Hwangd1222842015-04-07 22:19:43 +09001023 if (IS_ERR(ctx->crtc))
1024 return PTR_ERR(ctx->crtc);
Gustavo Padovan93bca242015-01-18 18:16:23 +09001025
Andrzej Hajda196e0592016-04-30 01:39:08 +09001026 if (ctx->driver_data->has_dp_clk) {
1027 ctx->dp_clk.enable = fimd_dp_clock_enable;
1028 ctx->crtc->pipe_clk = &ctx->dp_clk;
1029 }
1030
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001031 if (ctx->encoder)
Gustavo Padovana2986e82015-08-05 20:24:20 -03001032 exynos_dpi_bind(drm_dev, ctx->encoder);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001033
Joonyoung Shim43a3b862015-07-28 17:51:02 +09001034 if (is_drm_iommu_supported(drm_dev))
1035 fimd_clear_channels(ctx->crtc);
Joonyoung Shimeb7a3fc2015-07-02 21:49:39 +09001036
1037 ret = drm_iommu_attach_device(drm_dev, dev);
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +09001038 if (ret)
1039 priv->pipe--;
1040
1041 return ret;
Andrzej Hajda000cc922014-04-03 16:26:00 +02001042}
1043
1044static void fimd_unbind(struct device *dev, struct device *master,
1045 void *data)
1046{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001047 struct fimd_context *ctx = dev_get_drvdata(dev);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001048
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001049 fimd_disable(ctx->crtc);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001050
Joonyoung Shimbf566082015-07-02 21:49:38 +09001051 drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +09001052
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001053 if (ctx->encoder)
1054 exynos_dpi_remove(ctx->encoder);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001055}
1056
1057static const struct component_ops fimd_component_ops = {
1058 .bind = fimd_bind,
1059 .unbind = fimd_unbind,
1060};
1061
1062static int fimd_probe(struct platform_device *pdev)
1063{
1064 struct device *dev = &pdev->dev;
1065 struct fimd_context *ctx;
YoungJun Cho3854fab2014-07-17 18:01:21 +09001066 struct device_node *i80_if_timings;
Andrzej Hajda000cc922014-04-03 16:26:00 +02001067 struct resource *res;
Gustavo Padovanfe42cfb2014-11-03 18:56:57 -02001068 int ret;
Inki Dae1c248b72011-10-04 19:19:01 +09001069
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001070 if (!dev->of_node)
1071 return -ENODEV;
Sachin Kamat2d3f1732013-08-28 10:47:58 +05301072
Seung-Woo Kimd873ab92013-05-22 21:14:14 +09001073 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001074 if (!ctx)
1075 return -ENOMEM;
1076
Sean Paulbb7704d2014-01-30 16:19:06 -05001077 ctx->dev = dev;
Sean Paula43b9332014-01-30 16:19:26 -05001078 ctx->suspended = true;
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +09001079 ctx->driver_data = of_device_get_match_data(dev);
Sean Paulbb7704d2014-01-30 16:19:06 -05001080
Sean Paul1417f102014-01-30 16:19:23 -05001081 if (of_property_read_bool(dev->of_node, "samsung,invert-vden"))
1082 ctx->vidcon1 |= VIDCON1_INV_VDEN;
1083 if (of_property_read_bool(dev->of_node, "samsung,invert-vclk"))
1084 ctx->vidcon1 |= VIDCON1_INV_VCLK;
Andrzej Hajda562ad9f2013-08-21 16:22:03 +02001085
YoungJun Cho3854fab2014-07-17 18:01:21 +09001086 i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings");
1087 if (i80_if_timings) {
1088 u32 val;
1089
1090 ctx->i80_if = true;
1091
1092 if (ctx->driver_data->has_vidoutcon)
1093 ctx->vidout_con |= VIDOUT_CON_F_I80_LDI0;
1094 else
1095 ctx->vidcon0 |= VIDCON0_VIDOUT_I80_LDI0;
1096 /*
1097 * The user manual describes that this "DSI_EN" bit is required
1098 * to enable I80 24-bit data interface.
1099 */
1100 ctx->vidcon0 |= VIDCON0_DSI_EN;
1101
1102 if (of_property_read_u32(i80_if_timings, "cs-setup", &val))
1103 val = 0;
1104 ctx->i80ifcon = LCD_CS_SETUP(val);
1105 if (of_property_read_u32(i80_if_timings, "wr-setup", &val))
1106 val = 0;
1107 ctx->i80ifcon |= LCD_WR_SETUP(val);
1108 if (of_property_read_u32(i80_if_timings, "wr-active", &val))
1109 val = 1;
1110 ctx->i80ifcon |= LCD_WR_ACTIVE(val);
1111 if (of_property_read_u32(i80_if_timings, "wr-hold", &val))
1112 val = 0;
1113 ctx->i80ifcon |= LCD_WR_HOLD(val);
1114 }
1115 of_node_put(i80_if_timings);
1116
1117 ctx->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
1118 "samsung,sysreg");
1119 if (IS_ERR(ctx->sysreg)) {
1120 dev_warn(dev, "failed to get system register.\n");
1121 ctx->sysreg = NULL;
1122 }
1123
Sean Paula968e722014-01-30 16:19:20 -05001124 ctx->bus_clk = devm_clk_get(dev, "fimd");
1125 if (IS_ERR(ctx->bus_clk)) {
1126 dev_err(dev, "failed to get bus clock\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001127 return PTR_ERR(ctx->bus_clk);
Sean Paula968e722014-01-30 16:19:20 -05001128 }
1129
1130 ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
1131 if (IS_ERR(ctx->lcd_clk)) {
1132 dev_err(dev, "failed to get lcd clock\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001133 return PTR_ERR(ctx->lcd_clk);
Sean Paula968e722014-01-30 16:19:20 -05001134 }
Inki Dae1c248b72011-10-04 19:19:01 +09001135
Inki Dae1c248b72011-10-04 19:19:01 +09001136 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Inki Dae1c248b72011-10-04 19:19:01 +09001137
Seung-Woo Kimd873ab92013-05-22 21:14:14 +09001138 ctx->regs = devm_ioremap_resource(dev, res);
Andrzej Hajda86650402015-06-11 23:23:37 +09001139 if (IS_ERR(ctx->regs))
1140 return PTR_ERR(ctx->regs);
Inki Dae1c248b72011-10-04 19:19:01 +09001141
YoungJun Cho3854fab2014-07-17 18:01:21 +09001142 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1143 ctx->i80_if ? "lcd_sys" : "vsync");
Inki Dae1c248b72011-10-04 19:19:01 +09001144 if (!res) {
1145 dev_err(dev, "irq request failed.\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001146 return -ENXIO;
Inki Dae1c248b72011-10-04 19:19:01 +09001147 }
1148
Sean Paul055e0c02014-01-30 16:19:21 -05001149 ret = devm_request_irq(dev, res->start, fimd_irq_handler,
Sachin Kamatedc57262012-06-19 11:47:39 +05301150 0, "drm_fimd", ctx);
1151 if (ret) {
Inki Dae1c248b72011-10-04 19:19:01 +09001152 dev_err(dev, "irq request failed.\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001153 return ret;
Inki Dae1c248b72011-10-04 19:19:01 +09001154 }
1155
Daniel Vetter57ed0f72013-12-11 11:34:43 +01001156 init_waitqueue_head(&ctx->wait_vsync_queue);
Prathyush K01ce1132012-12-06 20:16:04 +05301157 atomic_set(&ctx->wait_vsync_event, 0);
Inki Dae1c248b72011-10-04 19:19:01 +09001158
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001159 platform_set_drvdata(pdev, ctx);
Sean Paul080be03d2014-02-19 21:02:55 +09001160
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001161 ctx->encoder = exynos_dpi_probe(dev);
1162 if (IS_ERR(ctx->encoder))
1163 return PTR_ERR(ctx->encoder);
Inki Daef37cd5e2014-05-09 14:25:20 +09001164
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001165 pm_runtime_enable(dev);
Inki Daef37cd5e2014-05-09 14:25:20 +09001166
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001167 ret = component_add(dev, &fimd_component_ops);
Inki Daedf5225b2014-05-29 18:28:02 +09001168 if (ret)
1169 goto err_disable_pm_runtime;
1170
1171 return ret;
1172
1173err_disable_pm_runtime:
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001174 pm_runtime_disable(dev);
Inki Daedf5225b2014-05-29 18:28:02 +09001175
Inki Daedf5225b2014-05-29 18:28:02 +09001176 return ret;
Inki Daef37cd5e2014-05-09 14:25:20 +09001177}
1178
1179static int fimd_remove(struct platform_device *pdev)
1180{
Sean Paulaf65c802014-01-30 16:19:27 -05001181 pm_runtime_disable(&pdev->dev);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001182
Inki Daedf5225b2014-05-29 18:28:02 +09001183 component_del(&pdev->dev, &fimd_component_ops);
Inki Daedf5225b2014-05-29 18:28:02 +09001184
Inki Dae1c248b72011-10-04 19:19:01 +09001185 return 0;
1186}
1187
Gustavo Padovan41571972015-09-04 17:15:49 -03001188#ifdef CONFIG_PM
1189static int exynos_fimd_suspend(struct device *dev)
1190{
1191 struct fimd_context *ctx = dev_get_drvdata(dev);
1192
1193 clk_disable_unprepare(ctx->lcd_clk);
1194 clk_disable_unprepare(ctx->bus_clk);
1195
1196 return 0;
1197}
1198
1199static int exynos_fimd_resume(struct device *dev)
1200{
1201 struct fimd_context *ctx = dev_get_drvdata(dev);
1202 int ret;
1203
1204 ret = clk_prepare_enable(ctx->bus_clk);
1205 if (ret < 0) {
1206 DRM_ERROR("Failed to prepare_enable the bus clk [%d]\n", ret);
1207 return ret;
1208 }
1209
1210 ret = clk_prepare_enable(ctx->lcd_clk);
1211 if (ret < 0) {
1212 DRM_ERROR("Failed to prepare_enable the lcd clk [%d]\n", ret);
1213 return ret;
1214 }
1215
1216 return 0;
1217}
1218#endif
1219
1220static const struct dev_pm_ops exynos_fimd_pm_ops = {
1221 SET_RUNTIME_PM_OPS(exynos_fimd_suspend, exynos_fimd_resume, NULL)
1222};
1223
Joonyoung Shim132a5b92012-03-16 18:47:08 +09001224struct platform_driver fimd_driver = {
Inki Dae1c248b72011-10-04 19:19:01 +09001225 .probe = fimd_probe,
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -08001226 .remove = fimd_remove,
Inki Dae1c248b72011-10-04 19:19:01 +09001227 .driver = {
1228 .name = "exynos4-fb",
1229 .owner = THIS_MODULE,
Gustavo Padovan41571972015-09-04 17:15:49 -03001230 .pm = &exynos_fimd_pm_ops,
Sachin Kamat2d3f1732013-08-28 10:47:58 +05301231 .of_match_table = fimd_driver_dt_match,
Inki Dae1c248b72011-10-04 19:19:01 +09001232 },
1233};