blob: d4721648898524e9dc76ee6476dd9a068c52520a [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_crtc.h"
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +090034#include "exynos_drm_plane.h"
Inki Daebcc5cd1c2012-10-19 17:16:36 +090035#include "exynos_drm_iommu.h"
Inki Dae1c248b72011-10-04 19:19:01 +090036
37/*
Sachin Kamatb8654b32013-09-19 10:39:44 +053038 * FIMD stands for Fully Interactive Mobile Display and
Inki Dae1c248b72011-10-04 19:19:01 +090039 * as a display controller, it transfers contents drawn on memory
40 * to a LCD Panel through Display Interfaces such as RGB or
41 * CPU Interface.
42 */
43
Rahul Sharma66367462014-05-07 16:55:22 +053044#define MIN_FB_WIDTH_FOR_16WORD_BURST 128
Andrzej Hajda111e6052013-08-21 16:22:01 +020045
Inki Dae1c248b72011-10-04 19:19:01 +090046/* position control register for hardware window 0, 2 ~ 4.*/
47#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
48#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050049/*
50 * size control register for hardware windows 0 and alpha control register
51 * for hardware windows 1 ~ 4
52 */
53#define VIDOSD_C(win) (VIDOSD_BASE + 0x08 + (win) * 16)
54/* size control register for hardware windows 1 ~ 2. */
Inki Dae1c248b72011-10-04 19:19:01 +090055#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
56
Gustavo Padovan453b44a2015-04-01 13:02:05 -030057#define VIDWnALPHA0(win) (VIDW_ALPHA + 0x00 + (win) * 8)
58#define VIDWnALPHA1(win) (VIDW_ALPHA + 0x04 + (win) * 8)
59
Inki Dae1c248b72011-10-04 19:19:01 +090060#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
Gustavo Padovancb11b3f2015-08-15 13:26:16 -030061#define VIDWx_BUF_START_S(win, buf) (VIDW_BUF_START_S(buf) + (win) * 8)
Inki Dae1c248b72011-10-04 19:19:01 +090062#define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8)
63#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
64
65/* color key control register for hardware window 1 ~ 4. */
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050066#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8))
Inki Dae1c248b72011-10-04 19:19:01 +090067/* color key value register for hardware window 1 ~ 4. */
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -050068#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8))
Inki Dae1c248b72011-10-04 19:19:01 +090069
Inki Daeb5bf0f12016-04-12 09:59:11 +090070/* I80 trigger control register */
YoungJun Cho3854fab2014-07-17 18:01:21 +090071#define TRIGCON 0x1A4
Inki Daeb5bf0f12016-04-12 09:59:11 +090072#define TRGMODE_ENABLE (1 << 0)
73#define SWTRGCMD_ENABLE (1 << 1)
Inki Daea6f75aa2016-04-18 17:54:39 +090074/* Exynos3250, 3472, 4415, 5260 5410, 5420 and 5422 only supported. */
Inki Daeb5bf0f12016-04-12 09:59:11 +090075#define HWTRGEN_ENABLE (1 << 3)
76#define HWTRGMASK_ENABLE (1 << 4)
Inki Daea6f75aa2016-04-18 17:54:39 +090077/* Exynos3250, 3472, 4415, 5260, 5420 and 5422 only supported. */
Inki Daeb5bf0f12016-04-12 09:59:11 +090078#define HWTRIGEN_PER_ENABLE (1 << 31)
YoungJun Cho3854fab2014-07-17 18:01:21 +090079
80/* display mode change control register except exynos4 */
81#define VIDOUT_CON 0x000
82#define VIDOUT_CON_F_I80_LDI0 (0x2 << 8)
83
84/* I80 interface control for main LDI register */
85#define I80IFCONFAx(x) (0x1B0 + (x) * 4)
86#define I80IFCONFBx(x) (0x1B8 + (x) * 4)
87#define LCD_CS_SETUP(x) ((x) << 16)
88#define LCD_WR_SETUP(x) ((x) << 12)
89#define LCD_WR_ACTIVE(x) ((x) << 8)
90#define LCD_WR_HOLD(x) ((x) << 4)
91#define I80IFEN_ENABLE (1 << 0)
92
Inki Dae1c248b72011-10-04 19:19:01 +090093/* FIMD has totally five hardware windows. */
94#define WINDOWS_NR 5
95
Inki Daea6f75aa2016-04-18 17:54:39 +090096/* HW trigger flag on i80 panel. */
97#define I80_HW_TRG (1 << 1)
98
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +053099struct fimd_driver_data {
100 unsigned int timing_base;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900101 unsigned int lcdblk_offset;
102 unsigned int lcdblk_vt_shift;
103 unsigned int lcdblk_bypass_shift;
Chanho Park1feafd32016-02-12 22:31:39 +0900104 unsigned int lcdblk_mic_bypass_shift;
Inki Daea6f75aa2016-04-18 17:54:39 +0900105 unsigned int trg_type;
Tomasz Figade7af102013-05-01 21:02:27 +0200106
107 unsigned int has_shadowcon:1;
Tomasz Figa411d9ed2013-05-01 21:02:28 +0200108 unsigned int has_clksel:1;
Inki Dae5cc46212013-08-20 14:28:56 +0900109 unsigned int has_limited_fmt:1;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900110 unsigned int has_vidoutcon:1;
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900111 unsigned int has_vtsel:1;
Chanho Park1feafd32016-02-12 22:31:39 +0900112 unsigned int has_mic_bypass:1;
Andrzej Hajda196e0592016-04-30 01:39:08 +0900113 unsigned int has_dp_clk:1;
Inki Daea6f75aa2016-04-18 17:54:39 +0900114 unsigned int has_hw_trigger:1;
115 unsigned int has_trigger_per_te:1;
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530116};
117
Tomasz Figa725ddea2013-05-01 21:02:29 +0200118static struct fimd_driver_data s3c64xx_fimd_driver_data = {
119 .timing_base = 0x0,
120 .has_clksel = 1,
Inki Dae5cc46212013-08-20 14:28:56 +0900121 .has_limited_fmt = 1,
Tomasz Figa725ddea2013-05-01 21:02:29 +0200122};
123
Inki Daed6ce7b52014-08-18 16:53:19 +0900124static struct fimd_driver_data exynos3_fimd_driver_data = {
125 .timing_base = 0x20000,
126 .lcdblk_offset = 0x210,
127 .lcdblk_bypass_shift = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900128 .trg_type = I80_HW_TRG,
Inki Daed6ce7b52014-08-18 16:53:19 +0900129 .has_shadowcon = 1,
130 .has_vidoutcon = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900131 .has_trigger_per_te = 1,
Inki Daed6ce7b52014-08-18 16:53:19 +0900132};
133
Sachin Kamat6ecf18f2012-11-19 15:22:54 +0530134static struct fimd_driver_data exynos4_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530135 .timing_base = 0x0,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900136 .lcdblk_offset = 0x210,
137 .lcdblk_vt_shift = 10,
138 .lcdblk_bypass_shift = 1,
Tomasz Figade7af102013-05-01 21:02:27 +0200139 .has_shadowcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900140 .has_vtsel = 1,
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530141};
142
YoungJun Chodcb622a2014-11-07 15:12:25 +0900143static struct fimd_driver_data exynos4415_fimd_driver_data = {
144 .timing_base = 0x20000,
145 .lcdblk_offset = 0x210,
146 .lcdblk_vt_shift = 10,
147 .lcdblk_bypass_shift = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900148 .trg_type = I80_HW_TRG,
YoungJun Chodcb622a2014-11-07 15:12:25 +0900149 .has_shadowcon = 1,
150 .has_vidoutcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900151 .has_vtsel = 1,
Inki Daea6f75aa2016-04-18 17:54:39 +0900152 .has_trigger_per_te = 1,
YoungJun Chodcb622a2014-11-07 15:12:25 +0900153};
154
Sachin Kamat6ecf18f2012-11-19 15:22:54 +0530155static struct fimd_driver_data exynos5_fimd_driver_data = {
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530156 .timing_base = 0x20000,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900157 .lcdblk_offset = 0x214,
158 .lcdblk_vt_shift = 24,
159 .lcdblk_bypass_shift = 15,
Tomasz Figade7af102013-05-01 21:02:27 +0200160 .has_shadowcon = 1,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900161 .has_vidoutcon = 1,
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900162 .has_vtsel = 1,
Andrzej Hajda196e0592016-04-30 01:39:08 +0900163 .has_dp_clk = 1,
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530164};
165
Chanho Park1feafd32016-02-12 22:31:39 +0900166static struct fimd_driver_data exynos5420_fimd_driver_data = {
167 .timing_base = 0x20000,
168 .lcdblk_offset = 0x214,
169 .lcdblk_vt_shift = 24,
170 .lcdblk_bypass_shift = 15,
171 .lcdblk_mic_bypass_shift = 11,
172 .has_shadowcon = 1,
173 .has_vidoutcon = 1,
174 .has_vtsel = 1,
175 .has_mic_bypass = 1,
Andrzej Hajda196e0592016-04-30 01:39:08 +0900176 .has_dp_clk = 1,
Chanho Park1feafd32016-02-12 22:31:39 +0900177};
178
Inki Dae1c248b72011-10-04 19:19:01 +0900179struct fimd_context {
Sean Paulbb7704d2014-01-30 16:19:06 -0500180 struct device *dev;
Sean Paul40c8ab42014-01-30 16:19:04 -0500181 struct drm_device *drm_dev;
Gustavo Padovan93bca242015-01-18 18:16:23 +0900182 struct exynos_drm_crtc *crtc;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900183 struct exynos_drm_plane planes[WINDOWS_NR];
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100184 struct exynos_drm_plane_config configs[WINDOWS_NR];
Inki Dae1c248b72011-10-04 19:19:01 +0900185 struct clk *bus_clk;
186 struct clk *lcd_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900187 void __iomem *regs;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900188 struct regmap *sysreg;
Inki Dae1c248b72011-10-04 19:19:01 +0900189 unsigned long irq_flags;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900190 u32 vidcon0;
Inki Dae1c248b72011-10-04 19:19:01 +0900191 u32 vidcon1;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900192 u32 vidout_con;
193 u32 i80ifcon;
194 bool i80_if;
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +0900195 bool suspended;
Sean Paul080be03d2014-02-19 21:02:55 +0900196 int pipe;
Prathyush K01ce1132012-12-06 20:16:04 +0530197 wait_queue_head_t wait_vsync_queue;
198 atomic_t wait_vsync_event;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900199 atomic_t win_updated;
200 atomic_t triggering;
Inki Dae1c248b72011-10-04 19:19:01 +0900201
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900202 const struct fimd_driver_data *driver_data;
Gustavo Padovan2b8376c2015-08-15 12:14:08 -0300203 struct drm_encoder *encoder;
Andrzej Hajda196e0592016-04-30 01:39:08 +0900204 struct exynos_drm_clk dp_clk;
Inki Dae1c248b72011-10-04 19:19:01 +0900205};
206
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900207static const struct of_device_id fimd_driver_dt_match[] = {
Tomasz Figa725ddea2013-05-01 21:02:29 +0200208 { .compatible = "samsung,s3c6400-fimd",
209 .data = &s3c64xx_fimd_driver_data },
Inki Daed6ce7b52014-08-18 16:53:19 +0900210 { .compatible = "samsung,exynos3250-fimd",
211 .data = &exynos3_fimd_driver_data },
Vikas Sajjan5830daf2013-02-27 16:02:58 +0530212 { .compatible = "samsung,exynos4210-fimd",
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900213 .data = &exynos4_fimd_driver_data },
YoungJun Chodcb622a2014-11-07 15:12:25 +0900214 { .compatible = "samsung,exynos4415-fimd",
215 .data = &exynos4415_fimd_driver_data },
Vikas Sajjan5830daf2013-02-27 16:02:58 +0530216 { .compatible = "samsung,exynos5250-fimd",
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900217 .data = &exynos5_fimd_driver_data },
Chanho Park1feafd32016-02-12 22:31:39 +0900218 { .compatible = "samsung,exynos5420-fimd",
219 .data = &exynos5420_fimd_driver_data },
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900220 {},
221};
Sjoerd Simons0262cee2014-07-30 11:28:31 +0900222MODULE_DEVICE_TABLE(of, fimd_driver_dt_match);
Joonyoung Shimd636ead2012-12-14 15:48:25 +0900223
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100224static const enum drm_plane_type fimd_win_types[WINDOWS_NR] = {
225 DRM_PLANE_TYPE_PRIMARY,
226 DRM_PLANE_TYPE_OVERLAY,
227 DRM_PLANE_TYPE_OVERLAY,
228 DRM_PLANE_TYPE_OVERLAY,
229 DRM_PLANE_TYPE_CURSOR,
230};
231
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +0900232static const uint32_t fimd_formats[] = {
233 DRM_FORMAT_C8,
234 DRM_FORMAT_XRGB1555,
235 DRM_FORMAT_RGB565,
236 DRM_FORMAT_XRGB8888,
237 DRM_FORMAT_ARGB8888,
238};
239
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200240static int fimd_enable_vblank(struct exynos_drm_crtc *crtc)
241{
242 struct fimd_context *ctx = crtc->ctx;
243 u32 val;
244
245 if (ctx->suspended)
246 return -EPERM;
247
248 if (!test_and_set_bit(0, &ctx->irq_flags)) {
249 val = readl(ctx->regs + VIDINTCON0);
250
251 val |= VIDINTCON0_INT_ENABLE;
252
253 if (ctx->i80_if) {
254 val |= VIDINTCON0_INT_I80IFDONE;
255 val |= VIDINTCON0_INT_SYSMAINCON;
256 val &= ~VIDINTCON0_INT_SYSSUBCON;
257 } else {
258 val |= VIDINTCON0_INT_FRAME;
259
260 val &= ~VIDINTCON0_FRAMESEL0_MASK;
261 val |= VIDINTCON0_FRAMESEL0_VSYNC;
262 val &= ~VIDINTCON0_FRAMESEL1_MASK;
263 val |= VIDINTCON0_FRAMESEL1_NONE;
264 }
265
266 writel(val, ctx->regs + VIDINTCON0);
267 }
268
269 return 0;
270}
271
272static void fimd_disable_vblank(struct exynos_drm_crtc *crtc)
273{
274 struct fimd_context *ctx = crtc->ctx;
275 u32 val;
276
277 if (ctx->suspended)
278 return;
279
280 if (test_and_clear_bit(0, &ctx->irq_flags)) {
281 val = readl(ctx->regs + VIDINTCON0);
282
283 val &= ~VIDINTCON0_INT_ENABLE;
284
285 if (ctx->i80_if) {
286 val &= ~VIDINTCON0_INT_I80IFDONE;
287 val &= ~VIDINTCON0_INT_SYSMAINCON;
288 val &= ~VIDINTCON0_INT_SYSSUBCON;
289 } else
290 val &= ~VIDINTCON0_INT_FRAME;
291
292 writel(val, ctx->regs + VIDINTCON0);
293 }
294}
295
Gustavo Padovan93bca242015-01-18 18:16:23 +0900296static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc)
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900297{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900298 struct fimd_context *ctx = crtc->ctx;
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900299
300 if (ctx->suspended)
301 return;
302
303 atomic_set(&ctx->wait_vsync_event, 1);
304
305 /*
306 * wait for FIMD to signal VSYNC interrupt or return after
307 * timeout which is set to 50ms (refresh rate of 20).
308 */
309 if (!wait_event_timeout(ctx->wait_vsync_queue,
310 !atomic_read(&ctx->wait_vsync_event),
311 HZ/20))
312 DRM_DEBUG_KMS("vblank wait timed out.\n");
313}
314
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200315static void fimd_enable_video_output(struct fimd_context *ctx, unsigned int win,
YoungJun Chof181a542014-11-17 22:00:10 +0900316 bool enable)
317{
318 u32 val = readl(ctx->regs + WINCON(win));
319
320 if (enable)
321 val |= WINCONx_ENWIN;
322 else
323 val &= ~WINCONx_ENWIN;
324
325 writel(val, ctx->regs + WINCON(win));
326}
327
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200328static void fimd_enable_shadow_channel_path(struct fimd_context *ctx,
329 unsigned int win,
YoungJun Cho999d8b32014-11-17 22:00:11 +0900330 bool enable)
331{
332 u32 val = readl(ctx->regs + SHADOWCON);
333
334 if (enable)
335 val |= SHADOWCON_CHx_ENABLE(win);
336 else
337 val &= ~SHADOWCON_CHx_ENABLE(win);
338
339 writel(val, ctx->regs + SHADOWCON);
340}
341
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900342static void fimd_clear_channels(struct exynos_drm_crtc *crtc)
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900343{
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900344 struct fimd_context *ctx = crtc->ctx;
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200345 unsigned int win, ch_enabled = 0;
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900346
347 DRM_DEBUG_KMS("%s\n", __FILE__);
348
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200349 /* Hardware is in unknown state, so ensure it gets enabled properly */
350 pm_runtime_get_sync(ctx->dev);
351
352 clk_prepare_enable(ctx->bus_clk);
353 clk_prepare_enable(ctx->lcd_clk);
354
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900355 /* Check if any channel is enabled. */
356 for (win = 0; win < WINDOWS_NR; win++) {
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900357 u32 val = readl(ctx->regs + WINCON(win));
358
359 if (val & WINCONx_ENWIN) {
YoungJun Chof181a542014-11-17 22:00:10 +0900360 fimd_enable_video_output(ctx, win, false);
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900361
YoungJun Cho999d8b32014-11-17 22:00:11 +0900362 if (ctx->driver_data->has_shadowcon)
363 fimd_enable_shadow_channel_path(ctx, win,
364 false);
365
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900366 ch_enabled = 1;
367 }
368 }
369
370 /* Wait for vsync, as disable channel takes effect at next vsync */
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900371 if (ch_enabled) {
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200372 int pipe = ctx->pipe;
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900373
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200374 /* ensure that vblank interrupt won't be reported to core */
375 ctx->suspended = false;
376 ctx->pipe = -1;
377
378 fimd_enable_vblank(ctx->crtc);
Joonyoung Shim92dc7a02015-01-30 16:43:02 +0900379 fimd_wait_for_vblank(ctx->crtc);
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200380 fimd_disable_vblank(ctx->crtc);
381
382 ctx->suspended = true;
383 ctx->pipe = pipe;
Marek Szyprowskieb8a3bf2014-09-01 22:27:10 +0900384 }
Marek Szyprowskifb88e212015-06-12 11:07:17 +0200385
386 clk_disable_unprepare(ctx->lcd_clk);
387 clk_disable_unprepare(ctx->bus_clk);
388
389 pm_runtime_put(ctx->dev);
Akshu Agrawalf13bdbd2014-04-28 21:26:39 +0900390}
391
Sean Paula968e722014-01-30 16:19:20 -0500392static u32 fimd_calc_clkdiv(struct fimd_context *ctx,
393 const struct drm_display_mode *mode)
394{
Tobias Jakobifa9971d2016-05-05 18:23:38 +0200395 unsigned long ideal_clk;
Sean Paula968e722014-01-30 16:19:20 -0500396 u32 clkdiv;
397
Tobias Jakobifa9971d2016-05-05 18:23:38 +0200398 if (mode->clock == 0) {
399 DRM_ERROR("Mode has zero clock value.\n");
400 return 0xff;
401 }
402
403 ideal_clk = mode->clock * 1000;
404
YoungJun Cho3854fab2014-07-17 18:01:21 +0900405 if (ctx->i80_if) {
406 /*
407 * The frame done interrupt should be occurred prior to the
408 * next TE signal.
409 */
410 ideal_clk *= 2;
411 }
412
Sean Paula968e722014-01-30 16:19:20 -0500413 /* Find the clock divider value that gets us closest to ideal_clk */
Chanho Park217fb002016-02-11 23:11:20 +0900414 clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(ctx->lcd_clk), ideal_clk);
Sean Paula968e722014-01-30 16:19:20 -0500415
416 return (clkdiv < 0x100) ? clkdiv : 0xff;
417}
418
Inki Daea6f75aa2016-04-18 17:54:39 +0900419static void fimd_setup_trigger(struct fimd_context *ctx)
420{
421 void __iomem *timing_base = ctx->regs + ctx->driver_data->timing_base;
422 u32 trg_type = ctx->driver_data->trg_type;
423 u32 val = readl(timing_base + TRIGCON);
424
Inki Daeb5bf0f12016-04-12 09:59:11 +0900425 val &= ~(TRGMODE_ENABLE);
Inki Daea6f75aa2016-04-18 17:54:39 +0900426
427 if (trg_type == I80_HW_TRG) {
428 if (ctx->driver_data->has_hw_trigger)
Inki Daeb5bf0f12016-04-12 09:59:11 +0900429 val |= HWTRGEN_ENABLE | HWTRGMASK_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900430 if (ctx->driver_data->has_trigger_per_te)
Inki Daeb5bf0f12016-04-12 09:59:11 +0900431 val |= HWTRIGEN_PER_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900432 } else {
Inki Daeb5bf0f12016-04-12 09:59:11 +0900433 val |= TRGMODE_ENABLE;
Inki Daea6f75aa2016-04-18 17:54:39 +0900434 }
435
436 writel(val, timing_base + TRIGCON);
437}
438
Gustavo Padovan93bca242015-01-18 18:16:23 +0900439static void fimd_commit(struct exynos_drm_crtc *crtc)
Inki Dae1c248b72011-10-04 19:19:01 +0900440{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900441 struct fimd_context *ctx = crtc->ctx;
Joonyoung Shim020e79d2015-06-02 21:04:42 +0900442 struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900443 const struct fimd_driver_data *driver_data = ctx->driver_data;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900444 void *timing_base = ctx->regs + driver_data->timing_base;
445 u32 val, clkdiv;
Inki Dae1c248b72011-10-04 19:19:01 +0900446
Inki Daee30d4bc2011-12-12 16:35:20 +0900447 if (ctx->suspended)
448 return;
449
Sean Paula968e722014-01-30 16:19:20 -0500450 /* nothing to do if we haven't set the mode yet */
451 if (mode->htotal == 0 || mode->vtotal == 0)
452 return;
453
YoungJun Cho3854fab2014-07-17 18:01:21 +0900454 if (ctx->i80_if) {
455 val = ctx->i80ifcon | I80IFEN_ENABLE;
456 writel(val, timing_base + I80IFCONFAx(0));
Inki Dae1c248b72011-10-04 19:19:01 +0900457
YoungJun Cho3854fab2014-07-17 18:01:21 +0900458 /* disable auto frame rate */
459 writel(0, timing_base + I80IFCONFBx(0));
Sean Paula968e722014-01-30 16:19:20 -0500460
YoungJun Cho3854fab2014-07-17 18:01:21 +0900461 /* set video type selection to I80 interface */
Joonyoung Shim3c3c9c12014-11-14 11:36:02 +0900462 if (driver_data->has_vtsel && ctx->sysreg &&
463 regmap_update_bits(ctx->sysreg,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900464 driver_data->lcdblk_offset,
465 0x3 << driver_data->lcdblk_vt_shift,
466 0x1 << driver_data->lcdblk_vt_shift)) {
467 DRM_ERROR("Failed to update sysreg for I80 i/f.\n");
468 return;
469 }
470 } else {
471 int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
472 u32 vidcon1;
Inki Dae1c248b72011-10-04 19:19:01 +0900473
YoungJun Cho3854fab2014-07-17 18:01:21 +0900474 /* setup polarity values */
475 vidcon1 = ctx->vidcon1;
476 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
477 vidcon1 |= VIDCON1_INV_VSYNC;
478 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
479 vidcon1 |= VIDCON1_INV_HSYNC;
480 writel(vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
Sean Paula968e722014-01-30 16:19:20 -0500481
YoungJun Cho3854fab2014-07-17 18:01:21 +0900482 /* setup vertical timing values. */
483 vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
484 vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
485 vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
486
487 val = VIDTCON0_VBPD(vbpd - 1) |
488 VIDTCON0_VFPD(vfpd - 1) |
489 VIDTCON0_VSPW(vsync_len - 1);
490 writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
491
492 /* setup horizontal timing values. */
493 hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
494 hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
495 hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
496
497 val = VIDTCON1_HBPD(hbpd - 1) |
498 VIDTCON1_HFPD(hfpd - 1) |
499 VIDTCON1_HSPW(hsync_len - 1);
500 writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
501 }
502
503 if (driver_data->has_vidoutcon)
504 writel(ctx->vidout_con, timing_base + VIDOUT_CON);
505
506 /* set bypass selection */
507 if (ctx->sysreg && regmap_update_bits(ctx->sysreg,
508 driver_data->lcdblk_offset,
509 0x1 << driver_data->lcdblk_bypass_shift,
510 0x1 << driver_data->lcdblk_bypass_shift)) {
511 DRM_ERROR("Failed to update sysreg for bypass setting.\n");
512 return;
513 }
Inki Dae1c248b72011-10-04 19:19:01 +0900514
Chanho Park1feafd32016-02-12 22:31:39 +0900515 /* TODO: When MIC is enabled for display path, the lcdblk_mic_bypass
516 * bit should be cleared.
517 */
518 if (driver_data->has_mic_bypass && ctx->sysreg &&
519 regmap_update_bits(ctx->sysreg,
520 driver_data->lcdblk_offset,
521 0x1 << driver_data->lcdblk_mic_bypass_shift,
522 0x1 << driver_data->lcdblk_mic_bypass_shift)) {
523 DRM_ERROR("Failed to update sysreg for bypass mic.\n");
524 return;
525 }
526
Inki Dae1c248b72011-10-04 19:19:01 +0900527 /* setup horizontal and vertical display size. */
Sean Paula968e722014-01-30 16:19:20 -0500528 val = VIDTCON2_LINEVAL(mode->vdisplay - 1) |
529 VIDTCON2_HOZVAL(mode->hdisplay - 1) |
530 VIDTCON2_LINEVAL_E(mode->vdisplay - 1) |
531 VIDTCON2_HOZVAL_E(mode->hdisplay - 1);
Leela Krishna Amudalae2e13382012-09-21 16:52:15 +0530532 writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
Inki Dae1c248b72011-10-04 19:19:01 +0900533
Inki Daea6f75aa2016-04-18 17:54:39 +0900534 fimd_setup_trigger(ctx);
535
Inki Dae1c248b72011-10-04 19:19:01 +0900536 /*
537 * fields of register with prefix '_F' would be updated
538 * at vsync(same as dma start)
539 */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900540 val = ctx->vidcon0;
541 val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
Andrzej Hajda1d531062014-03-20 17:09:00 +0900542
543 if (ctx->driver_data->has_clksel)
544 val |= VIDCON0_CLKSEL_LCD;
545
546 clkdiv = fimd_calc_clkdiv(ctx, mode);
547 if (clkdiv > 1)
548 val |= VIDCON0_CLKVAL_F(clkdiv - 1) | VIDCON0_CLKDIR;
549
Inki Dae1c248b72011-10-04 19:19:01 +0900550 writel(val, ctx->regs + VIDCON0);
551}
552
Inki Dae1c248b72011-10-04 19:19:01 +0900553
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900554static void fimd_win_set_pixfmt(struct fimd_context *ctx, unsigned int win,
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100555 uint32_t pixel_format, int width)
Inki Dae1c248b72011-10-04 19:19:01 +0900556{
Inki Dae1c248b72011-10-04 19:19:01 +0900557 unsigned long val;
558
Inki Dae1c248b72011-10-04 19:19:01 +0900559 val = WINCONx_ENWIN;
560
Inki Dae5cc46212013-08-20 14:28:56 +0900561 /*
562 * In case of s3c64xx, window 0 doesn't support alpha channel.
563 * So the request format is ARGB8888 then change it to XRGB8888.
564 */
565 if (ctx->driver_data->has_limited_fmt && !win) {
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100566 if (pixel_format == DRM_FORMAT_ARGB8888)
567 pixel_format = DRM_FORMAT_XRGB8888;
Inki Dae5cc46212013-08-20 14:28:56 +0900568 }
569
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100570 switch (pixel_format) {
Inki Daea4f38a82013-08-20 13:51:02 +0900571 case DRM_FORMAT_C8:
Inki Dae1c248b72011-10-04 19:19:01 +0900572 val |= WINCON0_BPPMODE_8BPP_PALETTE;
573 val |= WINCONx_BURSTLEN_8WORD;
574 val |= WINCONx_BYTSWP;
575 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900576 case DRM_FORMAT_XRGB1555:
577 val |= WINCON0_BPPMODE_16BPP_1555;
578 val |= WINCONx_HAWSWP;
579 val |= WINCONx_BURSTLEN_16WORD;
580 break;
581 case DRM_FORMAT_RGB565:
Inki Dae1c248b72011-10-04 19:19:01 +0900582 val |= WINCON0_BPPMODE_16BPP_565;
583 val |= WINCONx_HAWSWP;
584 val |= WINCONx_BURSTLEN_16WORD;
585 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900586 case DRM_FORMAT_XRGB8888:
Inki Dae1c248b72011-10-04 19:19:01 +0900587 val |= WINCON0_BPPMODE_24BPP_888;
588 val |= WINCONx_WSWP;
589 val |= WINCONx_BURSTLEN_16WORD;
590 break;
Inki Daea4f38a82013-08-20 13:51:02 +0900591 case DRM_FORMAT_ARGB8888:
592 val |= WINCON1_BPPMODE_25BPP_A1888
Inki Dae1c248b72011-10-04 19:19:01 +0900593 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
594 val |= WINCONx_WSWP;
595 val |= WINCONx_BURSTLEN_16WORD;
596 break;
597 default:
598 DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n");
599
600 val |= WINCON0_BPPMODE_24BPP_888;
601 val |= WINCONx_WSWP;
602 val |= WINCONx_BURSTLEN_16WORD;
603 break;
604 }
605
Rahul Sharma66367462014-05-07 16:55:22 +0530606 /*
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100607 * Setting dma-burst to 16Word causes permanent tearing for very small
608 * buffers, e.g. cursor buffer. Burst Mode switching which based on
609 * plane size is not recommended as plane size varies alot towards the
610 * end of the screen and rapid movement causes unstable DMA, but it is
611 * still better to change dma-burst than displaying garbage.
Rahul Sharma66367462014-05-07 16:55:22 +0530612 */
613
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100614 if (width < MIN_FB_WIDTH_FOR_16WORD_BURST) {
Rahul Sharma66367462014-05-07 16:55:22 +0530615 val &= ~WINCONx_BURSTLEN_MASK;
616 val |= WINCONx_BURSTLEN_4WORD;
617 }
618
Inki Dae1c248b72011-10-04 19:19:01 +0900619 writel(val, ctx->regs + WINCON(win));
Gustavo Padovan453b44a2015-04-01 13:02:05 -0300620
621 /* hardware window 0 doesn't support alpha channel. */
622 if (win != 0) {
623 /* OSD alpha */
624 val = VIDISD14C_ALPHA0_R(0xf) |
625 VIDISD14C_ALPHA0_G(0xf) |
626 VIDISD14C_ALPHA0_B(0xf) |
627 VIDISD14C_ALPHA1_R(0xf) |
628 VIDISD14C_ALPHA1_G(0xf) |
629 VIDISD14C_ALPHA1_B(0xf);
630
631 writel(val, ctx->regs + VIDOSD_C(win));
632
633 val = VIDW_ALPHA_R(0xf) | VIDW_ALPHA_G(0xf) |
634 VIDW_ALPHA_G(0xf);
635 writel(val, ctx->regs + VIDWnALPHA0(win));
636 writel(val, ctx->regs + VIDWnALPHA1(win));
637 }
Inki Dae1c248b72011-10-04 19:19:01 +0900638}
639
Sean Paulbb7704d2014-01-30 16:19:06 -0500640static void fimd_win_set_colkey(struct fimd_context *ctx, unsigned int win)
Inki Dae1c248b72011-10-04 19:19:01 +0900641{
Inki Dae1c248b72011-10-04 19:19:01 +0900642 unsigned int keycon0 = 0, keycon1 = 0;
643
Inki Dae1c248b72011-10-04 19:19:01 +0900644 keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
645 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
646
647 keycon1 = WxKEYCON1_COLVAL(0xffffffff);
648
649 writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
650 writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
651}
652
Tomasz Figade7af102013-05-01 21:02:27 +0200653/**
654 * shadow_protect_win() - disable updating values from shadow registers at vsync
655 *
656 * @win: window to protect registers for
657 * @protect: 1 to protect (disable updates)
658 */
659static void fimd_shadow_protect_win(struct fimd_context *ctx,
Gustavo Padovan6e2a3b62015-04-03 21:05:52 +0900660 unsigned int win, bool protect)
Tomasz Figade7af102013-05-01 21:02:27 +0200661{
662 u32 reg, bits, val;
663
Gustavo Padovance3ff362015-08-15 13:26:13 -0300664 /*
665 * SHADOWCON/PRTCON register is used for enabling timing.
666 *
667 * for example, once only width value of a register is set,
668 * if the dma is started then fimd hardware could malfunction so
669 * with protect window setting, the register fields with prefix '_F'
670 * wouldn't be updated at vsync also but updated once unprotect window
671 * is set.
672 */
673
Tomasz Figade7af102013-05-01 21:02:27 +0200674 if (ctx->driver_data->has_shadowcon) {
675 reg = SHADOWCON;
676 bits = SHADOWCON_WINx_PROTECT(win);
677 } else {
678 reg = PRTCON;
679 bits = PRTCON_PROTECT;
680 }
681
682 val = readl(ctx->regs + reg);
683 if (protect)
684 val |= bits;
685 else
686 val &= ~bits;
687 writel(val, ctx->regs + reg);
688}
689
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100690static void fimd_atomic_begin(struct exynos_drm_crtc *crtc)
Gustavo Padovance3ff362015-08-15 13:26:13 -0300691{
692 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100693 int i;
Gustavo Padovance3ff362015-08-15 13:26:13 -0300694
695 if (ctx->suspended)
696 return;
697
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100698 for (i = 0; i < WINDOWS_NR; i++)
699 fimd_shadow_protect_win(ctx, i, true);
Gustavo Padovance3ff362015-08-15 13:26:13 -0300700}
701
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100702static void fimd_atomic_flush(struct exynos_drm_crtc *crtc)
Gustavo Padovance3ff362015-08-15 13:26:13 -0300703{
704 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100705 int i;
Gustavo Padovance3ff362015-08-15 13:26:13 -0300706
707 if (ctx->suspended)
708 return;
709
Marek Szyprowskid29c2c12016-01-05 13:52:51 +0100710 for (i = 0; i < WINDOWS_NR; i++)
711 fimd_shadow_protect_win(ctx, i, false);
Gustavo Padovance3ff362015-08-15 13:26:13 -0300712}
713
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900714static void fimd_update_plane(struct exynos_drm_crtc *crtc,
715 struct exynos_drm_plane *plane)
Inki Dae1c248b72011-10-04 19:19:01 +0900716{
Marek Szyprowski0114f402015-11-30 14:53:22 +0100717 struct exynos_drm_plane_state *state =
718 to_exynos_plane_state(plane->base.state);
Gustavo Padovan93bca242015-01-18 18:16:23 +0900719 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100720 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900721 dma_addr_t dma_addr;
722 unsigned long val, size, offset;
723 unsigned int last_x, last_y, buf_offsize, line_size;
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100724 unsigned int win = plane->index;
Marek Szyprowski0488f502015-11-30 14:53:21 +0100725 unsigned int bpp = fb->bits_per_pixel >> 3;
726 unsigned int pitch = fb->pitches[0];
Inki Dae1c248b72011-10-04 19:19:01 +0900727
Inki Daee30d4bc2011-12-12 16:35:20 +0900728 if (ctx->suspended)
729 return;
730
Marek Szyprowski0114f402015-11-30 14:53:22 +0100731 offset = state->src.x * bpp;
732 offset += state->src.y * pitch;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900733
Inki Dae1c248b72011-10-04 19:19:01 +0900734 /* buffer start address */
Marek Szyprowski0488f502015-11-30 14:53:21 +0100735 dma_addr = exynos_drm_fb_dma_addr(fb, 0) + offset;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900736 val = (unsigned long)dma_addr;
Inki Dae1c248b72011-10-04 19:19:01 +0900737 writel(val, ctx->regs + VIDWx_BUF_START(win, 0));
738
739 /* buffer end address */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100740 size = pitch * state->crtc.h;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900741 val = (unsigned long)(dma_addr + size);
Inki Dae1c248b72011-10-04 19:19:01 +0900742 writel(val, ctx->regs + VIDWx_BUF_END(win, 0));
743
744 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900745 (unsigned long)dma_addr, val, size);
Inki Dae19c8b832011-10-14 13:29:46 +0900746 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
Marek Szyprowski0114f402015-11-30 14:53:22 +0100747 state->crtc.w, state->crtc.h);
Inki Dae1c248b72011-10-04 19:19:01 +0900748
749 /* buffer size */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100750 buf_offsize = pitch - (state->crtc.w * bpp);
751 line_size = state->crtc.w * bpp;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900752 val = VIDW_BUF_SIZE_OFFSET(buf_offsize) |
753 VIDW_BUF_SIZE_PAGEWIDTH(line_size) |
754 VIDW_BUF_SIZE_OFFSET_E(buf_offsize) |
755 VIDW_BUF_SIZE_PAGEWIDTH_E(line_size);
Inki Dae1c248b72011-10-04 19:19:01 +0900756 writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0));
757
758 /* OSD position */
Marek Szyprowski0114f402015-11-30 14:53:22 +0100759 val = VIDOSDxA_TOPLEFT_X(state->crtc.x) |
760 VIDOSDxA_TOPLEFT_Y(state->crtc.y) |
761 VIDOSDxA_TOPLEFT_X_E(state->crtc.x) |
762 VIDOSDxA_TOPLEFT_Y_E(state->crtc.y);
Inki Dae1c248b72011-10-04 19:19:01 +0900763 writel(val, ctx->regs + VIDOSD_A(win));
764
Marek Szyprowski0114f402015-11-30 14:53:22 +0100765 last_x = state->crtc.x + state->crtc.w;
Joonyoung Shimf56aad32012-12-14 15:48:23 +0900766 if (last_x)
767 last_x--;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100768 last_y = state->crtc.y + state->crtc.h;
Joonyoung Shimf56aad32012-12-14 15:48:23 +0900769 if (last_y)
770 last_y--;
771
Joonyoung Shimca555e52012-12-14 15:48:24 +0900772 val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y) |
773 VIDOSDxB_BOTRIGHT_X_E(last_x) | VIDOSDxB_BOTRIGHT_Y_E(last_y);
774
Inki Dae1c248b72011-10-04 19:19:01 +0900775 writel(val, ctx->regs + VIDOSD_B(win));
776
Inki Dae19c8b832011-10-14 13:29:46 +0900777 DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
Marek Szyprowski0114f402015-11-30 14:53:22 +0100778 state->crtc.x, state->crtc.y, last_x, last_y);
Inki Dae1c248b72011-10-04 19:19:01 +0900779
Inki Dae1c248b72011-10-04 19:19:01 +0900780 /* OSD size */
781 if (win != 3 && win != 4) {
782 u32 offset = VIDOSD_D(win);
783 if (win == 0)
Leela Krishna Amudala0f10cf12013-03-07 23:28:52 -0500784 offset = VIDOSD_C(win);
Marek Szyprowski0114f402015-11-30 14:53:22 +0100785 val = state->crtc.w * state->crtc.h;
Inki Dae1c248b72011-10-04 19:19:01 +0900786 writel(val, ctx->regs + offset);
787
788 DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val);
789 }
790
Marek Szyprowski8b704d82015-11-30 14:53:29 +0100791 fimd_win_set_pixfmt(ctx, win, fb->pixel_format, state->src.w);
Inki Dae1c248b72011-10-04 19:19:01 +0900792
793 /* hardware window 0 doesn't support color key. */
794 if (win != 0)
Sean Paulbb7704d2014-01-30 16:19:06 -0500795 fimd_win_set_colkey(ctx, win);
Inki Dae1c248b72011-10-04 19:19:01 +0900796
YoungJun Chof181a542014-11-17 22:00:10 +0900797 fimd_enable_video_output(ctx, win, true);
Inki Daeec05da92011-12-06 11:06:54 +0900798
YoungJun Cho999d8b32014-11-17 22:00:11 +0900799 if (ctx->driver_data->has_shadowcon)
800 fimd_enable_shadow_channel_path(ctx, win, true);
Inki Daeec05da92011-12-06 11:06:54 +0900801
YoungJun Cho3854fab2014-07-17 18:01:21 +0900802 if (ctx->i80_if)
803 atomic_set(&ctx->win_updated, 1);
Inki Dae1c248b72011-10-04 19:19:01 +0900804}
805
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900806static void fimd_disable_plane(struct exynos_drm_crtc *crtc,
807 struct exynos_drm_plane *plane)
Inki Dae1c248b72011-10-04 19:19:01 +0900808{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900809 struct fimd_context *ctx = crtc->ctx;
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100810 unsigned int win = plane->index;
Inki Daeec05da92011-12-06 11:06:54 +0900811
Joonyoung Shimc329f662015-06-12 20:34:28 +0900812 if (ctx->suspended)
Prathyush Kdb7e55a2012-12-06 20:16:06 +0530813 return;
Prathyush Kdb7e55a2012-12-06 20:16:06 +0530814
YoungJun Chof181a542014-11-17 22:00:10 +0900815 fimd_enable_video_output(ctx, win, false);
Inki Dae1c248b72011-10-04 19:19:01 +0900816
YoungJun Cho999d8b32014-11-17 22:00:11 +0900817 if (ctx->driver_data->has_shadowcon)
818 fimd_enable_shadow_channel_path(ctx, win, false);
Sean Paula43b9332014-01-30 16:19:26 -0500819}
820
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300821static void fimd_enable(struct exynos_drm_crtc *crtc)
Sean Paula43b9332014-01-30 16:19:26 -0500822{
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300823 struct fimd_context *ctx = crtc->ctx;
Sean Paula43b9332014-01-30 16:19:26 -0500824
825 if (!ctx->suspended)
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300826 return;
Sean Paula43b9332014-01-30 16:19:26 -0500827
828 ctx->suspended = false;
829
Sean Paulaf65c802014-01-30 16:19:27 -0500830 pm_runtime_get_sync(ctx->dev);
831
Sean Paula43b9332014-01-30 16:19:26 -0500832 /* if vblank was enabled status, enable it again. */
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300833 if (test_and_clear_bit(0, &ctx->irq_flags))
834 fimd_enable_vblank(ctx->crtc);
Sean Paula43b9332014-01-30 16:19:26 -0500835
Joonyoung Shimc329f662015-06-12 20:34:28 +0900836 fimd_commit(ctx->crtc);
Sean Paula43b9332014-01-30 16:19:26 -0500837}
838
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300839static void fimd_disable(struct exynos_drm_crtc *crtc)
Sean Paula43b9332014-01-30 16:19:26 -0500840{
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300841 struct fimd_context *ctx = crtc->ctx;
Joonyoung Shimc329f662015-06-12 20:34:28 +0900842 int i;
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300843
Sean Paula43b9332014-01-30 16:19:26 -0500844 if (ctx->suspended)
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300845 return;
Sean Paula43b9332014-01-30 16:19:26 -0500846
847 /*
848 * We need to make sure that all windows are disabled before we
849 * suspend that connector. Otherwise we might try to scan from
850 * a destroyed buffer later.
851 */
Joonyoung Shimc329f662015-06-12 20:34:28 +0900852 for (i = 0; i < WINDOWS_NR; i++)
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900853 fimd_disable_plane(crtc, &ctx->planes[i]);
Sean Paula43b9332014-01-30 16:19:26 -0500854
Inki Dae94ab95a2015-06-12 22:19:22 +0900855 fimd_enable_vblank(crtc);
856 fimd_wait_for_vblank(crtc);
857 fimd_disable_vblank(crtc);
858
Joonyoung Shimb74f14f2015-06-12 17:27:16 +0900859 writel(0, ctx->regs + VIDCON0);
860
Sean Paulaf65c802014-01-30 16:19:27 -0500861 pm_runtime_put_sync(ctx->dev);
Sean Paula43b9332014-01-30 16:19:26 -0500862 ctx->suspended = true;
Sean Paul080be03d2014-02-19 21:02:55 +0900863}
864
YoungJun Cho3854fab2014-07-17 18:01:21 +0900865static void fimd_trigger(struct device *dev)
866{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +0100867 struct fimd_context *ctx = dev_get_drvdata(dev);
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +0900868 const struct fimd_driver_data *driver_data = ctx->driver_data;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900869 void *timing_base = ctx->regs + driver_data->timing_base;
870 u32 reg;
871
Joonyoung Shim9b67eb72014-11-17 22:00:08 +0900872 /*
YoungJun Cho1c905d92014-11-17 22:00:12 +0900873 * Skips triggering if in triggering state, because multiple triggering
874 * requests can cause panel reset.
875 */
Joonyoung Shim9b67eb72014-11-17 22:00:08 +0900876 if (atomic_read(&ctx->triggering))
877 return;
878
YoungJun Cho1c905d92014-11-17 22:00:12 +0900879 /* Enters triggering mode */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900880 atomic_set(&ctx->triggering, 1);
881
YoungJun Cho3854fab2014-07-17 18:01:21 +0900882 reg = readl(timing_base + TRIGCON);
Inki Daeb5bf0f12016-04-12 09:59:11 +0900883 reg |= (TRGMODE_ENABLE | SWTRGCMD_ENABLE);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900884 writel(reg, timing_base + TRIGCON);
YoungJun Cho87ab85b2014-11-17 22:00:13 +0900885
886 /*
887 * Exits triggering mode if vblank is not enabled yet, because when the
888 * VIDINTCON0 register is not set, it can not exit from triggering mode.
889 */
890 if (!test_bit(0, &ctx->irq_flags))
891 atomic_set(&ctx->triggering, 0);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900892}
893
Gustavo Padovan93bca242015-01-18 18:16:23 +0900894static void fimd_te_handler(struct exynos_drm_crtc *crtc)
YoungJun Cho3854fab2014-07-17 18:01:21 +0900895{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900896 struct fimd_context *ctx = crtc->ctx;
Inki Daea6f75aa2016-04-18 17:54:39 +0900897 u32 trg_type = ctx->driver_data->trg_type;
YoungJun Cho3854fab2014-07-17 18:01:21 +0900898
899 /* Checks the crtc is detached already from encoder */
900 if (ctx->pipe < 0 || !ctx->drm_dev)
901 return;
902
Inki Daea6f75aa2016-04-18 17:54:39 +0900903 if (trg_type == I80_HW_TRG)
904 goto out;
905
YoungJun Cho3854fab2014-07-17 18:01:21 +0900906 /*
907 * If there is a page flip request, triggers and handles the page flip
908 * event so that current fb can be updated into panel GRAM.
909 */
910 if (atomic_add_unless(&ctx->win_updated, -1, 0))
911 fimd_trigger(ctx->dev);
912
Inki Daea6f75aa2016-04-18 17:54:39 +0900913out:
YoungJun Cho3854fab2014-07-17 18:01:21 +0900914 /* Wakes up vsync event queue */
915 if (atomic_read(&ctx->wait_vsync_event)) {
916 atomic_set(&ctx->wait_vsync_event, 0);
917 wake_up(&ctx->wait_vsync_queue);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900918 }
YoungJun Chob301ae22014-10-01 15:19:10 +0900919
Joonyoung Shimadf67ab2014-11-17 22:00:14 +0900920 if (test_bit(0, &ctx->irq_flags))
Gustavo Padovaneafd5402015-07-16 12:23:32 -0300921 drm_crtc_handle_vblank(&ctx->crtc->base);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900922}
923
Andrzej Hajda196e0592016-04-30 01:39:08 +0900924static void fimd_dp_clock_enable(struct exynos_drm_clk *clk, bool enable)
Krzysztof Kozlowski48107d72015-05-07 09:04:44 +0900925{
Andrzej Hajda196e0592016-04-30 01:39:08 +0900926 struct fimd_context *ctx = container_of(clk, struct fimd_context,
927 dp_clk);
928 u32 val = enable ? DP_MIE_CLK_DP_ENABLE : DP_MIE_CLK_DISABLE;
Gustavo Padovan3c79fb82015-09-30 18:40:54 -0300929 writel(val, ctx->regs + DP_MIE_CLKCON);
Krzysztof Kozlowski48107d72015-05-07 09:04:44 +0900930}
931
Krzysztof Kozlowskif3aaf762015-05-07 09:04:45 +0900932static const struct exynos_drm_crtc_ops fimd_crtc_ops = {
Gustavo Padovan3cecda02015-06-01 12:04:55 -0300933 .enable = fimd_enable,
934 .disable = fimd_disable,
Sean Paul1c6244c2014-01-30 16:19:02 -0500935 .commit = fimd_commit,
936 .enable_vblank = fimd_enable_vblank,
937 .disable_vblank = fimd_disable_vblank,
Gustavo Padovance3ff362015-08-15 13:26:13 -0300938 .atomic_begin = fimd_atomic_begin,
Gustavo Padovan9cc76102015-08-03 14:38:05 +0900939 .update_plane = fimd_update_plane,
940 .disable_plane = fimd_disable_plane,
Gustavo Padovance3ff362015-08-15 13:26:13 -0300941 .atomic_flush = fimd_atomic_flush,
YoungJun Cho3854fab2014-07-17 18:01:21 +0900942 .te_handler = fimd_te_handler,
Inki Dae1c248b72011-10-04 19:19:01 +0900943};
944
Inki Dae1c248b72011-10-04 19:19:01 +0900945static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
946{
947 struct fimd_context *ctx = (struct fimd_context *)dev_id;
Gustavo Padovancb11b3f2015-08-15 13:26:16 -0300948 u32 val, clear_bit, start, start_s;
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300949 int win;
Inki Dae1c248b72011-10-04 19:19:01 +0900950
951 val = readl(ctx->regs + VIDINTCON1);
952
YoungJun Cho3854fab2014-07-17 18:01:21 +0900953 clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME;
954 if (val & clear_bit)
955 writel(clear_bit, ctx->regs + VIDINTCON1);
Inki Dae1c248b72011-10-04 19:19:01 +0900956
Inki Daeec05da92011-12-06 11:06:54 +0900957 /* check the crtc is detached already from encoder */
Sean Paul080be03d2014-02-19 21:02:55 +0900958 if (ctx->pipe < 0 || !ctx->drm_dev)
Inki Daeec05da92011-12-06 11:06:54 +0900959 goto out;
Inki Dae483b88f2011-11-11 21:28:00 +0900960
Gustavo Padovanfc75f712015-08-15 13:26:11 -0300961 if (!ctx->i80_if)
962 drm_crtc_handle_vblank(&ctx->crtc->base);
Joonyoung Shimadf67ab2014-11-17 22:00:14 +0900963
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300964 for (win = 0 ; win < WINDOWS_NR ; win++) {
965 struct exynos_drm_plane *plane = &ctx->planes[win];
966
967 if (!plane->pending_fb)
968 continue;
969
Gustavo Padovancb11b3f2015-08-15 13:26:16 -0300970 start = readl(ctx->regs + VIDWx_BUF_START(win, 0));
971 start_s = readl(ctx->regs + VIDWx_BUF_START_S(win, 0));
972 if (start == start_s)
973 exynos_drm_crtc_finish_update(ctx->crtc, plane);
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300974 }
Gustavo Padovanfc75f712015-08-15 13:26:11 -0300975
976 if (ctx->i80_if) {
YoungJun Cho1c905d92014-11-17 22:00:12 +0900977 /* Exits triggering mode */
YoungJun Cho3854fab2014-07-17 18:01:21 +0900978 atomic_set(&ctx->triggering, 0);
YoungJun Cho3854fab2014-07-17 18:01:21 +0900979 } else {
YoungJun Cho3854fab2014-07-17 18:01:21 +0900980 /* set wait vsync event to zero and wake up queue. */
981 if (atomic_read(&ctx->wait_vsync_event)) {
982 atomic_set(&ctx->wait_vsync_event, 0);
983 wake_up(&ctx->wait_vsync_queue);
984 }
Prathyush K01ce1132012-12-06 20:16:04 +0530985 }
YoungJun Cho3854fab2014-07-17 18:01:21 +0900986
Inki Daeec05da92011-12-06 11:06:54 +0900987out:
Inki Dae1c248b72011-10-04 19:19:01 +0900988 return IRQ_HANDLED;
989}
990
Inki Daef37cd5e2014-05-09 14:25:20 +0900991static int fimd_bind(struct device *dev, struct device *master, void *data)
Andrzej Hajda562ad9f2013-08-21 16:22:03 +0200992{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +0100993 struct fimd_context *ctx = dev_get_drvdata(dev);
Inki Daef37cd5e2014-05-09 14:25:20 +0900994 struct drm_device *drm_dev = data;
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +0900995 struct exynos_drm_private *priv = drm_dev->dev_private;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +0900996 struct exynos_drm_plane *exynos_plane;
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100997 unsigned int i;
Gustavo Padovan6e2a3b62015-04-03 21:05:52 +0900998 int ret;
Andrzej Hajda000cc922014-04-03 16:26:00 +0200999
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +09001000 ctx->drm_dev = drm_dev;
1001 ctx->pipe = priv->pipe++;
Ajay Kumarefa75bc2015-01-12 01:57:07 +09001002
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001003 for (i = 0; i < WINDOWS_NR; i++) {
1004 ctx->configs[i].pixel_formats = fimd_formats;
1005 ctx->configs[i].num_pixel_formats = ARRAY_SIZE(fimd_formats);
1006 ctx->configs[i].zpos = i;
1007 ctx->configs[i].type = fimd_win_types[i];
Marek Szyprowski40bdfb02015-12-16 13:21:42 +01001008 ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001009 1 << ctx->pipe, &ctx->configs[i]);
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001010 if (ret)
1011 return ret;
1012 }
1013
Gustavo Padovan5d3d0992015-10-12 22:07:48 +09001014 exynos_plane = &ctx->planes[DEFAULT_WIN];
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001015 ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1016 ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD,
Joonyoung Shim0f04cf82015-01-30 16:43:01 +09001017 &fimd_crtc_ops, ctx);
Hyungwon Hwangd1222842015-04-07 22:19:43 +09001018 if (IS_ERR(ctx->crtc))
1019 return PTR_ERR(ctx->crtc);
Gustavo Padovan93bca242015-01-18 18:16:23 +09001020
Andrzej Hajda196e0592016-04-30 01:39:08 +09001021 if (ctx->driver_data->has_dp_clk) {
1022 ctx->dp_clk.enable = fimd_dp_clock_enable;
1023 ctx->crtc->pipe_clk = &ctx->dp_clk;
1024 }
1025
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001026 if (ctx->encoder)
Gustavo Padovana2986e82015-08-05 20:24:20 -03001027 exynos_dpi_bind(drm_dev, ctx->encoder);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001028
Joonyoung Shim43a3b862015-07-28 17:51:02 +09001029 if (is_drm_iommu_supported(drm_dev))
1030 fimd_clear_channels(ctx->crtc);
Joonyoung Shimeb7a3fc2015-07-02 21:49:39 +09001031
1032 ret = drm_iommu_attach_device(drm_dev, dev);
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +09001033 if (ret)
1034 priv->pipe--;
1035
1036 return ret;
Andrzej Hajda000cc922014-04-03 16:26:00 +02001037}
1038
1039static void fimd_unbind(struct device *dev, struct device *master,
1040 void *data)
1041{
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001042 struct fimd_context *ctx = dev_get_drvdata(dev);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001043
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001044 fimd_disable(ctx->crtc);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001045
Joonyoung Shimbf566082015-07-02 21:49:38 +09001046 drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
Hyungwon Hwangcdbfca82015-03-12 13:36:02 +09001047
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001048 if (ctx->encoder)
1049 exynos_dpi_remove(ctx->encoder);
Andrzej Hajda000cc922014-04-03 16:26:00 +02001050}
1051
1052static const struct component_ops fimd_component_ops = {
1053 .bind = fimd_bind,
1054 .unbind = fimd_unbind,
1055};
1056
1057static int fimd_probe(struct platform_device *pdev)
1058{
1059 struct device *dev = &pdev->dev;
1060 struct fimd_context *ctx;
YoungJun Cho3854fab2014-07-17 18:01:21 +09001061 struct device_node *i80_if_timings;
Andrzej Hajda000cc922014-04-03 16:26:00 +02001062 struct resource *res;
Gustavo Padovanfe42cfb2014-11-03 18:56:57 -02001063 int ret;
Inki Dae1c248b72011-10-04 19:19:01 +09001064
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001065 if (!dev->of_node)
1066 return -ENODEV;
Sachin Kamat2d3f1732013-08-28 10:47:58 +05301067
Seung-Woo Kimd873ab92013-05-22 21:14:14 +09001068 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001069 if (!ctx)
1070 return -ENOMEM;
1071
Sean Paulbb7704d2014-01-30 16:19:06 -05001072 ctx->dev = dev;
Sean Paula43b9332014-01-30 16:19:26 -05001073 ctx->suspended = true;
Marek Szyprowskie1a7b9b2016-04-18 17:38:27 +09001074 ctx->driver_data = of_device_get_match_data(dev);
Sean Paulbb7704d2014-01-30 16:19:06 -05001075
Sean Paul1417f102014-01-30 16:19:23 -05001076 if (of_property_read_bool(dev->of_node, "samsung,invert-vden"))
1077 ctx->vidcon1 |= VIDCON1_INV_VDEN;
1078 if (of_property_read_bool(dev->of_node, "samsung,invert-vclk"))
1079 ctx->vidcon1 |= VIDCON1_INV_VCLK;
Andrzej Hajda562ad9f2013-08-21 16:22:03 +02001080
YoungJun Cho3854fab2014-07-17 18:01:21 +09001081 i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings");
1082 if (i80_if_timings) {
1083 u32 val;
1084
1085 ctx->i80_if = true;
1086
1087 if (ctx->driver_data->has_vidoutcon)
1088 ctx->vidout_con |= VIDOUT_CON_F_I80_LDI0;
1089 else
1090 ctx->vidcon0 |= VIDCON0_VIDOUT_I80_LDI0;
1091 /*
1092 * The user manual describes that this "DSI_EN" bit is required
1093 * to enable I80 24-bit data interface.
1094 */
1095 ctx->vidcon0 |= VIDCON0_DSI_EN;
1096
1097 if (of_property_read_u32(i80_if_timings, "cs-setup", &val))
1098 val = 0;
1099 ctx->i80ifcon = LCD_CS_SETUP(val);
1100 if (of_property_read_u32(i80_if_timings, "wr-setup", &val))
1101 val = 0;
1102 ctx->i80ifcon |= LCD_WR_SETUP(val);
1103 if (of_property_read_u32(i80_if_timings, "wr-active", &val))
1104 val = 1;
1105 ctx->i80ifcon |= LCD_WR_ACTIVE(val);
1106 if (of_property_read_u32(i80_if_timings, "wr-hold", &val))
1107 val = 0;
1108 ctx->i80ifcon |= LCD_WR_HOLD(val);
1109 }
1110 of_node_put(i80_if_timings);
1111
1112 ctx->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
1113 "samsung,sysreg");
1114 if (IS_ERR(ctx->sysreg)) {
1115 dev_warn(dev, "failed to get system register.\n");
1116 ctx->sysreg = NULL;
1117 }
1118
Sean Paula968e722014-01-30 16:19:20 -05001119 ctx->bus_clk = devm_clk_get(dev, "fimd");
1120 if (IS_ERR(ctx->bus_clk)) {
1121 dev_err(dev, "failed to get bus clock\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001122 return PTR_ERR(ctx->bus_clk);
Sean Paula968e722014-01-30 16:19:20 -05001123 }
1124
1125 ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
1126 if (IS_ERR(ctx->lcd_clk)) {
1127 dev_err(dev, "failed to get lcd clock\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001128 return PTR_ERR(ctx->lcd_clk);
Sean Paula968e722014-01-30 16:19:20 -05001129 }
Inki Dae1c248b72011-10-04 19:19:01 +09001130
Inki Dae1c248b72011-10-04 19:19:01 +09001131 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Inki Dae1c248b72011-10-04 19:19:01 +09001132
Seung-Woo Kimd873ab92013-05-22 21:14:14 +09001133 ctx->regs = devm_ioremap_resource(dev, res);
Andrzej Hajda86650402015-06-11 23:23:37 +09001134 if (IS_ERR(ctx->regs))
1135 return PTR_ERR(ctx->regs);
Inki Dae1c248b72011-10-04 19:19:01 +09001136
YoungJun Cho3854fab2014-07-17 18:01:21 +09001137 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1138 ctx->i80_if ? "lcd_sys" : "vsync");
Inki Dae1c248b72011-10-04 19:19:01 +09001139 if (!res) {
1140 dev_err(dev, "irq request failed.\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001141 return -ENXIO;
Inki Dae1c248b72011-10-04 19:19:01 +09001142 }
1143
Sean Paul055e0c02014-01-30 16:19:21 -05001144 ret = devm_request_irq(dev, res->start, fimd_irq_handler,
Sachin Kamatedc57262012-06-19 11:47:39 +05301145 0, "drm_fimd", ctx);
1146 if (ret) {
Inki Dae1c248b72011-10-04 19:19:01 +09001147 dev_err(dev, "irq request failed.\n");
Andrzej Hajda86650402015-06-11 23:23:37 +09001148 return ret;
Inki Dae1c248b72011-10-04 19:19:01 +09001149 }
1150
Daniel Vetter57ed0f72013-12-11 11:34:43 +01001151 init_waitqueue_head(&ctx->wait_vsync_queue);
Prathyush K01ce1132012-12-06 20:16:04 +05301152 atomic_set(&ctx->wait_vsync_event, 0);
Inki Dae1c248b72011-10-04 19:19:01 +09001153
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001154 platform_set_drvdata(pdev, ctx);
Sean Paul080be03d2014-02-19 21:02:55 +09001155
Gustavo Padovancf67cc92015-08-11 17:38:06 +09001156 ctx->encoder = exynos_dpi_probe(dev);
1157 if (IS_ERR(ctx->encoder))
1158 return PTR_ERR(ctx->encoder);
Inki Daef37cd5e2014-05-09 14:25:20 +09001159
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001160 pm_runtime_enable(dev);
Inki Daef37cd5e2014-05-09 14:25:20 +09001161
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001162 ret = component_add(dev, &fimd_component_ops);
Inki Daedf5225b2014-05-29 18:28:02 +09001163 if (ret)
1164 goto err_disable_pm_runtime;
1165
1166 return ret;
1167
1168err_disable_pm_runtime:
Andrzej Hajdae152dbd2014-11-17 09:54:18 +01001169 pm_runtime_disable(dev);
Inki Daedf5225b2014-05-29 18:28:02 +09001170
Inki Daedf5225b2014-05-29 18:28:02 +09001171 return ret;
Inki Daef37cd5e2014-05-09 14:25:20 +09001172}
1173
1174static int fimd_remove(struct platform_device *pdev)
1175{
Sean Paulaf65c802014-01-30 16:19:27 -05001176 pm_runtime_disable(&pdev->dev);
Joonyoung Shimcb91f6a2011-12-09 16:52:11 +09001177
Inki Daedf5225b2014-05-29 18:28:02 +09001178 component_del(&pdev->dev, &fimd_component_ops);
Inki Daedf5225b2014-05-29 18:28:02 +09001179
Inki Dae1c248b72011-10-04 19:19:01 +09001180 return 0;
1181}
1182
Gustavo Padovan41571972015-09-04 17:15:49 -03001183#ifdef CONFIG_PM
1184static int exynos_fimd_suspend(struct device *dev)
1185{
1186 struct fimd_context *ctx = dev_get_drvdata(dev);
1187
1188 clk_disable_unprepare(ctx->lcd_clk);
1189 clk_disable_unprepare(ctx->bus_clk);
1190
1191 return 0;
1192}
1193
1194static int exynos_fimd_resume(struct device *dev)
1195{
1196 struct fimd_context *ctx = dev_get_drvdata(dev);
1197 int ret;
1198
1199 ret = clk_prepare_enable(ctx->bus_clk);
1200 if (ret < 0) {
1201 DRM_ERROR("Failed to prepare_enable the bus clk [%d]\n", ret);
1202 return ret;
1203 }
1204
1205 ret = clk_prepare_enable(ctx->lcd_clk);
1206 if (ret < 0) {
1207 DRM_ERROR("Failed to prepare_enable the lcd clk [%d]\n", ret);
1208 return ret;
1209 }
1210
1211 return 0;
1212}
1213#endif
1214
1215static const struct dev_pm_ops exynos_fimd_pm_ops = {
1216 SET_RUNTIME_PM_OPS(exynos_fimd_suspend, exynos_fimd_resume, NULL)
1217};
1218
Joonyoung Shim132a5b92012-03-16 18:47:08 +09001219struct platform_driver fimd_driver = {
Inki Dae1c248b72011-10-04 19:19:01 +09001220 .probe = fimd_probe,
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -08001221 .remove = fimd_remove,
Inki Dae1c248b72011-10-04 19:19:01 +09001222 .driver = {
1223 .name = "exynos4-fb",
1224 .owner = THIS_MODULE,
Gustavo Padovan41571972015-09-04 17:15:49 -03001225 .pm = &exynos_fimd_pm_ops,
Sachin Kamat2d3f1732013-08-28 10:47:58 +05301226 .of_match_table = fimd_driver_dt_match,
Inki Dae1c248b72011-10-04 19:19:01 +09001227 },
1228};