Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* 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 Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 14 | #include <drm/drmP.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 15 | |
| 16 | #include <linux/kernel.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/clk.h> |
Sachin Kamat | 3f1c781 | 2013-08-14 16:38:01 +0530 | [diff] [blame] | 19 | #include <linux/of.h> |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 22 | #include <linux/component.h> |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 23 | #include <linux/mfd/syscon.h> |
| 24 | #include <linux/regmap.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 25 | |
Vikas Sajjan | 7f4596f | 2013-03-07 12:15:21 +0530 | [diff] [blame] | 26 | #include <video/of_display_timing.h> |
Andrzej Hajda | 111e605 | 2013-08-21 16:22:01 +0200 | [diff] [blame] | 27 | #include <video/of_videomode.h> |
Leela Krishna Amudala | 5a213a5 | 2012-08-08 09:44:49 +0900 | [diff] [blame] | 28 | #include <video/samsung_fimd.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 29 | #include <drm/exynos_drm.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 30 | |
| 31 | #include "exynos_drm_drv.h" |
| 32 | #include "exynos_drm_fbdev.h" |
| 33 | #include "exynos_drm_crtc.h" |
Inki Dae | bcc5cd1c | 2012-10-19 17:16:36 +0900 | [diff] [blame] | 34 | #include "exynos_drm_iommu.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 35 | |
| 36 | /* |
Sachin Kamat | b8654b3 | 2013-09-19 10:39:44 +0530 | [diff] [blame] | 37 | * FIMD stands for Fully Interactive Mobile Display and |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 38 | * as a display controller, it transfers contents drawn on memory |
| 39 | * to a LCD Panel through Display Interfaces such as RGB or |
| 40 | * CPU Interface. |
| 41 | */ |
| 42 | |
Andrzej Hajda | 111e605 | 2013-08-21 16:22:01 +0200 | [diff] [blame] | 43 | #define FIMD_DEFAULT_FRAMERATE 60 |
Rahul Sharma | 6636746 | 2014-05-07 16:55:22 +0530 | [diff] [blame] | 44 | #define MIN_FB_WIDTH_FOR_16WORD_BURST 128 |
Andrzej Hajda | 111e605 | 2013-08-21 16:22:01 +0200 | [diff] [blame] | 45 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 46 | /* 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 Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 49 | /* |
| 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 55 | #define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16) |
| 56 | |
| 57 | #define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8) |
| 58 | #define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8) |
| 59 | #define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4) |
| 60 | |
| 61 | /* color key control register for hardware window 1 ~ 4. */ |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 62 | #define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 63 | /* color key value register for hardware window 1 ~ 4. */ |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 64 | #define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 65 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 66 | /* I80 / RGB trigger control register */ |
| 67 | #define TRIGCON 0x1A4 |
| 68 | #define TRGMODE_I80_RGB_ENABLE_I80 (1 << 0) |
| 69 | #define SWTRGCMD_I80_RGB_ENABLE (1 << 1) |
| 70 | |
| 71 | /* display mode change control register except exynos4 */ |
| 72 | #define VIDOUT_CON 0x000 |
| 73 | #define VIDOUT_CON_F_I80_LDI0 (0x2 << 8) |
| 74 | |
| 75 | /* I80 interface control for main LDI register */ |
| 76 | #define I80IFCONFAx(x) (0x1B0 + (x) * 4) |
| 77 | #define I80IFCONFBx(x) (0x1B8 + (x) * 4) |
| 78 | #define LCD_CS_SETUP(x) ((x) << 16) |
| 79 | #define LCD_WR_SETUP(x) ((x) << 12) |
| 80 | #define LCD_WR_ACTIVE(x) ((x) << 8) |
| 81 | #define LCD_WR_HOLD(x) ((x) << 4) |
| 82 | #define I80IFEN_ENABLE (1 << 0) |
| 83 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 84 | /* FIMD has totally five hardware windows. */ |
| 85 | #define WINDOWS_NR 5 |
| 86 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 87 | #define get_fimd_manager(mgr) platform_get_drvdata(to_platform_device(dev)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 88 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 89 | struct fimd_driver_data { |
| 90 | unsigned int timing_base; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 91 | unsigned int lcdblk_offset; |
| 92 | unsigned int lcdblk_vt_shift; |
| 93 | unsigned int lcdblk_bypass_shift; |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 94 | |
| 95 | unsigned int has_shadowcon:1; |
Tomasz Figa | 411d9ed | 2013-05-01 21:02:28 +0200 | [diff] [blame] | 96 | unsigned int has_clksel:1; |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 97 | unsigned int has_limited_fmt:1; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 98 | unsigned int has_vidoutcon:1; |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 101 | static struct fimd_driver_data s3c64xx_fimd_driver_data = { |
| 102 | .timing_base = 0x0, |
| 103 | .has_clksel = 1, |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 104 | .has_limited_fmt = 1, |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame^] | 107 | static struct fimd_driver_data exynos3_fimd_driver_data = { |
| 108 | .timing_base = 0x20000, |
| 109 | .lcdblk_offset = 0x210, |
| 110 | .lcdblk_bypass_shift = 1, |
| 111 | .has_shadowcon = 1, |
| 112 | .has_vidoutcon = 1, |
| 113 | }; |
| 114 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 115 | static struct fimd_driver_data exynos4_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 116 | .timing_base = 0x0, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 117 | .lcdblk_offset = 0x210, |
| 118 | .lcdblk_vt_shift = 10, |
| 119 | .lcdblk_bypass_shift = 1, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 120 | .has_shadowcon = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 121 | }; |
| 122 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 123 | static struct fimd_driver_data exynos5_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 124 | .timing_base = 0x20000, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 125 | .lcdblk_offset = 0x214, |
| 126 | .lcdblk_vt_shift = 24, |
| 127 | .lcdblk_bypass_shift = 15, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 128 | .has_shadowcon = 1, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 129 | .has_vidoutcon = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 130 | }; |
| 131 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 132 | struct fimd_win_data { |
| 133 | unsigned int offset_x; |
| 134 | unsigned int offset_y; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 135 | unsigned int ovl_width; |
| 136 | unsigned int ovl_height; |
| 137 | unsigned int fb_width; |
| 138 | unsigned int fb_height; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 139 | unsigned int bpp; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 140 | unsigned int pixel_format; |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 141 | dma_addr_t dma_addr; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 142 | unsigned int buf_offsize; |
| 143 | unsigned int line_size; /* bytes */ |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 144 | bool enabled; |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 145 | bool resume; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | struct fimd_context { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 149 | struct device *dev; |
Sean Paul | 40c8ab4 | 2014-01-30 16:19:04 -0500 | [diff] [blame] | 150 | struct drm_device *drm_dev; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 151 | struct clk *bus_clk; |
| 152 | struct clk *lcd_clk; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 153 | void __iomem *regs; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 154 | struct regmap *sysreg; |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 155 | struct drm_display_mode mode; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 156 | struct fimd_win_data win_data[WINDOWS_NR]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 157 | unsigned int default_win; |
| 158 | unsigned long irq_flags; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 159 | u32 vidcon0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 160 | u32 vidcon1; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 161 | u32 vidout_con; |
| 162 | u32 i80ifcon; |
| 163 | bool i80_if; |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 164 | bool suspended; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 165 | int pipe; |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 166 | wait_queue_head_t wait_vsync_queue; |
| 167 | atomic_t wait_vsync_event; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 168 | atomic_t win_updated; |
| 169 | atomic_t triggering; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 170 | |
Andrzej Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 171 | struct exynos_drm_panel_info panel; |
Tomasz Figa | 1887346 | 2013-05-01 21:02:26 +0200 | [diff] [blame] | 172 | struct fimd_driver_data *driver_data; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 173 | struct exynos_drm_display *display; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 174 | }; |
| 175 | |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 176 | static const struct of_device_id fimd_driver_dt_match[] = { |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 177 | { .compatible = "samsung,s3c6400-fimd", |
| 178 | .data = &s3c64xx_fimd_driver_data }, |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame^] | 179 | { .compatible = "samsung,exynos3250-fimd", |
| 180 | .data = &exynos3_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 181 | { .compatible = "samsung,exynos4210-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 182 | .data = &exynos4_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 183 | { .compatible = "samsung,exynos5250-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 184 | .data = &exynos5_fimd_driver_data }, |
| 185 | {}, |
| 186 | }; |
Sjoerd Simons | 0262cee | 2014-07-30 11:28:31 +0900 | [diff] [blame] | 187 | MODULE_DEVICE_TABLE(of, fimd_driver_dt_match); |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 188 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 189 | static inline struct fimd_driver_data *drm_fimd_get_driver_data( |
| 190 | struct platform_device *pdev) |
| 191 | { |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 192 | const struct of_device_id *of_id = |
| 193 | of_match_device(fimd_driver_dt_match, &pdev->dev); |
| 194 | |
Sachin Kamat | 2d3f173 | 2013-08-28 10:47:58 +0530 | [diff] [blame] | 195 | return (struct fimd_driver_data *)of_id->data; |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 196 | } |
| 197 | |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 198 | static void fimd_wait_for_vblank(struct exynos_drm_manager *mgr) |
| 199 | { |
| 200 | struct fimd_context *ctx = mgr->ctx; |
| 201 | |
| 202 | if (ctx->suspended) |
| 203 | return; |
| 204 | |
| 205 | atomic_set(&ctx->wait_vsync_event, 1); |
| 206 | |
| 207 | /* |
| 208 | * wait for FIMD to signal VSYNC interrupt or return after |
| 209 | * timeout which is set to 50ms (refresh rate of 20). |
| 210 | */ |
| 211 | if (!wait_event_timeout(ctx->wait_vsync_queue, |
| 212 | !atomic_read(&ctx->wait_vsync_event), |
| 213 | HZ/20)) |
| 214 | DRM_DEBUG_KMS("vblank wait timed out.\n"); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | static void fimd_clear_channel(struct exynos_drm_manager *mgr) |
| 219 | { |
| 220 | struct fimd_context *ctx = mgr->ctx; |
| 221 | int win, ch_enabled = 0; |
| 222 | |
| 223 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 224 | |
| 225 | /* Check if any channel is enabled. */ |
| 226 | for (win = 0; win < WINDOWS_NR; win++) { |
| 227 | u32 val = readl(ctx->regs + SHADOWCON); |
| 228 | if (val & SHADOWCON_CHx_ENABLE(win)) { |
| 229 | val &= ~SHADOWCON_CHx_ENABLE(win); |
| 230 | writel(val, ctx->regs + SHADOWCON); |
| 231 | ch_enabled = 1; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* Wait for vsync, as disable channel takes effect at next vsync */ |
| 236 | if (ch_enabled) |
| 237 | fimd_wait_for_vblank(mgr); |
| 238 | } |
| 239 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 240 | static int fimd_mgr_initialize(struct exynos_drm_manager *mgr, |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 241 | struct drm_device *drm_dev) |
Sean Paul | 40c8ab4 | 2014-01-30 16:19:04 -0500 | [diff] [blame] | 242 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 243 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 244 | struct exynos_drm_private *priv; |
| 245 | priv = drm_dev->dev_private; |
Sean Paul | 40c8ab4 | 2014-01-30 16:19:04 -0500 | [diff] [blame] | 246 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 247 | mgr->drm_dev = ctx->drm_dev = drm_dev; |
| 248 | mgr->pipe = ctx->pipe = priv->pipe++; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * enable drm irq mode. |
| 252 | * - with irq_enabled = true, we can use the vblank feature. |
| 253 | * |
| 254 | * P.S. note that we wouldn't use drm irq handler but |
| 255 | * just specific driver own one instead because |
| 256 | * drm framework supports only one irq handler. |
| 257 | */ |
| 258 | drm_dev->irq_enabled = true; |
| 259 | |
| 260 | /* |
| 261 | * with vblank_disable_allowed = true, vblank interrupt will be disabled |
| 262 | * by drm timer once a current process gives up ownership of |
| 263 | * vblank event.(after drm_vblank_put function is called) |
| 264 | */ |
| 265 | drm_dev->vblank_disable_allowed = true; |
| 266 | |
| 267 | /* attach this sub driver to iommu mapping if supported. */ |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 268 | if (is_drm_iommu_supported(ctx->drm_dev)) { |
| 269 | /* |
| 270 | * If any channel is already active, iommu will throw |
| 271 | * a PAGE FAULT when enabled. So clear any channel if enabled. |
| 272 | */ |
| 273 | fimd_clear_channel(mgr); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 274 | drm_iommu_attach_device(ctx->drm_dev, ctx->dev); |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 275 | } |
Sean Paul | 40c8ab4 | 2014-01-30 16:19:04 -0500 | [diff] [blame] | 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 280 | static void fimd_mgr_remove(struct exynos_drm_manager *mgr) |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 281 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 282 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 283 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 284 | /* detach this sub driver from iommu mapping if supported. */ |
| 285 | if (is_drm_iommu_supported(ctx->drm_dev)) |
| 286 | drm_iommu_detach_device(ctx->drm_dev, ctx->dev); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 287 | } |
| 288 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 289 | static u32 fimd_calc_clkdiv(struct fimd_context *ctx, |
| 290 | const struct drm_display_mode *mode) |
| 291 | { |
| 292 | unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh; |
| 293 | u32 clkdiv; |
| 294 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 295 | if (ctx->i80_if) { |
| 296 | /* |
| 297 | * The frame done interrupt should be occurred prior to the |
| 298 | * next TE signal. |
| 299 | */ |
| 300 | ideal_clk *= 2; |
| 301 | } |
| 302 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 303 | /* Find the clock divider value that gets us closest to ideal_clk */ |
| 304 | clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->lcd_clk), ideal_clk); |
| 305 | |
| 306 | return (clkdiv < 0x100) ? clkdiv : 0xff; |
| 307 | } |
| 308 | |
| 309 | static bool fimd_mode_fixup(struct exynos_drm_manager *mgr, |
| 310 | const struct drm_display_mode *mode, |
| 311 | struct drm_display_mode *adjusted_mode) |
| 312 | { |
| 313 | if (adjusted_mode->vrefresh == 0) |
| 314 | adjusted_mode->vrefresh = FIMD_DEFAULT_FRAMERATE; |
| 315 | |
| 316 | return true; |
| 317 | } |
| 318 | |
| 319 | static void fimd_mode_set(struct exynos_drm_manager *mgr, |
| 320 | const struct drm_display_mode *in_mode) |
| 321 | { |
| 322 | struct fimd_context *ctx = mgr->ctx; |
| 323 | |
| 324 | drm_mode_copy(&ctx->mode, in_mode); |
| 325 | } |
| 326 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 327 | static void fimd_commit(struct exynos_drm_manager *mgr) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 328 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 329 | struct fimd_context *ctx = mgr->ctx; |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 330 | struct drm_display_mode *mode = &ctx->mode; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 331 | struct fimd_driver_data *driver_data = ctx->driver_data; |
| 332 | void *timing_base = ctx->regs + driver_data->timing_base; |
| 333 | u32 val, clkdiv; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 334 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 335 | if (ctx->suspended) |
| 336 | return; |
| 337 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 338 | /* nothing to do if we haven't set the mode yet */ |
| 339 | if (mode->htotal == 0 || mode->vtotal == 0) |
| 340 | return; |
| 341 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 342 | if (ctx->i80_if) { |
| 343 | val = ctx->i80ifcon | I80IFEN_ENABLE; |
| 344 | writel(val, timing_base + I80IFCONFAx(0)); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 345 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 346 | /* disable auto frame rate */ |
| 347 | writel(0, timing_base + I80IFCONFBx(0)); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 348 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 349 | /* set video type selection to I80 interface */ |
| 350 | if (ctx->sysreg && regmap_update_bits(ctx->sysreg, |
| 351 | driver_data->lcdblk_offset, |
| 352 | 0x3 << driver_data->lcdblk_vt_shift, |
| 353 | 0x1 << driver_data->lcdblk_vt_shift)) { |
| 354 | DRM_ERROR("Failed to update sysreg for I80 i/f.\n"); |
| 355 | return; |
| 356 | } |
| 357 | } else { |
| 358 | int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd; |
| 359 | u32 vidcon1; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 360 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 361 | /* setup polarity values */ |
| 362 | vidcon1 = ctx->vidcon1; |
| 363 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 364 | vidcon1 |= VIDCON1_INV_VSYNC; |
| 365 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 366 | vidcon1 |= VIDCON1_INV_HSYNC; |
| 367 | writel(vidcon1, ctx->regs + driver_data->timing_base + VIDCON1); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 368 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 369 | /* setup vertical timing values. */ |
| 370 | vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 371 | vbpd = mode->crtc_vtotal - mode->crtc_vsync_end; |
| 372 | vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay; |
| 373 | |
| 374 | val = VIDTCON0_VBPD(vbpd - 1) | |
| 375 | VIDTCON0_VFPD(vfpd - 1) | |
| 376 | VIDTCON0_VSPW(vsync_len - 1); |
| 377 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON0); |
| 378 | |
| 379 | /* setup horizontal timing values. */ |
| 380 | hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 381 | hbpd = mode->crtc_htotal - mode->crtc_hsync_end; |
| 382 | hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay; |
| 383 | |
| 384 | val = VIDTCON1_HBPD(hbpd - 1) | |
| 385 | VIDTCON1_HFPD(hfpd - 1) | |
| 386 | VIDTCON1_HSPW(hsync_len - 1); |
| 387 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON1); |
| 388 | } |
| 389 | |
| 390 | if (driver_data->has_vidoutcon) |
| 391 | writel(ctx->vidout_con, timing_base + VIDOUT_CON); |
| 392 | |
| 393 | /* set bypass selection */ |
| 394 | if (ctx->sysreg && regmap_update_bits(ctx->sysreg, |
| 395 | driver_data->lcdblk_offset, |
| 396 | 0x1 << driver_data->lcdblk_bypass_shift, |
| 397 | 0x1 << driver_data->lcdblk_bypass_shift)) { |
| 398 | DRM_ERROR("Failed to update sysreg for bypass setting.\n"); |
| 399 | return; |
| 400 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 401 | |
| 402 | /* setup horizontal and vertical display size. */ |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 403 | val = VIDTCON2_LINEVAL(mode->vdisplay - 1) | |
| 404 | VIDTCON2_HOZVAL(mode->hdisplay - 1) | |
| 405 | VIDTCON2_LINEVAL_E(mode->vdisplay - 1) | |
| 406 | VIDTCON2_HOZVAL_E(mode->hdisplay - 1); |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 407 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON2); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 408 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 409 | /* |
| 410 | * fields of register with prefix '_F' would be updated |
| 411 | * at vsync(same as dma start) |
| 412 | */ |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 413 | val = ctx->vidcon0; |
| 414 | val |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
Andrzej Hajda | 1d53106 | 2014-03-20 17:09:00 +0900 | [diff] [blame] | 415 | |
| 416 | if (ctx->driver_data->has_clksel) |
| 417 | val |= VIDCON0_CLKSEL_LCD; |
| 418 | |
| 419 | clkdiv = fimd_calc_clkdiv(ctx, mode); |
| 420 | if (clkdiv > 1) |
| 421 | val |= VIDCON0_CLKVAL_F(clkdiv - 1) | VIDCON0_CLKDIR; |
| 422 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 423 | writel(val, ctx->regs + VIDCON0); |
| 424 | } |
| 425 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 426 | static int fimd_enable_vblank(struct exynos_drm_manager *mgr) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 427 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 428 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 429 | u32 val; |
| 430 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 431 | if (ctx->suspended) |
| 432 | return -EPERM; |
| 433 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 434 | if (!test_and_set_bit(0, &ctx->irq_flags)) { |
| 435 | val = readl(ctx->regs + VIDINTCON0); |
| 436 | |
| 437 | val |= VIDINTCON0_INT_ENABLE; |
| 438 | val |= VIDINTCON0_INT_FRAME; |
| 439 | |
| 440 | val &= ~VIDINTCON0_FRAMESEL0_MASK; |
| 441 | val |= VIDINTCON0_FRAMESEL0_VSYNC; |
| 442 | val &= ~VIDINTCON0_FRAMESEL1_MASK; |
| 443 | val |= VIDINTCON0_FRAMESEL1_NONE; |
| 444 | |
| 445 | writel(val, ctx->regs + VIDINTCON0); |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 451 | static void fimd_disable_vblank(struct exynos_drm_manager *mgr) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 452 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 453 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 454 | u32 val; |
| 455 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 456 | if (ctx->suspended) |
| 457 | return; |
| 458 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 459 | if (test_and_clear_bit(0, &ctx->irq_flags)) { |
| 460 | val = readl(ctx->regs + VIDINTCON0); |
| 461 | |
| 462 | val &= ~VIDINTCON0_INT_FRAME; |
| 463 | val &= ~VIDINTCON0_INT_ENABLE; |
| 464 | |
| 465 | writel(val, ctx->regs + VIDINTCON0); |
| 466 | } |
| 467 | } |
| 468 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 469 | static void fimd_win_mode_set(struct exynos_drm_manager *mgr, |
| 470 | struct exynos_drm_overlay *overlay) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 471 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 472 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 473 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 474 | int win; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 475 | unsigned long offset; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 476 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 477 | if (!overlay) { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 478 | DRM_ERROR("overlay is NULL\n"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 479 | return; |
| 480 | } |
| 481 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 482 | win = overlay->zpos; |
| 483 | if (win == DEFAULT_ZPOS) |
| 484 | win = ctx->default_win; |
| 485 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 486 | if (win < 0 || win >= WINDOWS_NR) |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 487 | return; |
| 488 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 489 | offset = overlay->fb_x * (overlay->bpp >> 3); |
| 490 | offset += overlay->fb_y * overlay->pitch; |
| 491 | |
| 492 | DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, overlay->pitch); |
| 493 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 494 | win_data = &ctx->win_data[win]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 495 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 496 | win_data->offset_x = overlay->crtc_x; |
| 497 | win_data->offset_y = overlay->crtc_y; |
| 498 | win_data->ovl_width = overlay->crtc_width; |
| 499 | win_data->ovl_height = overlay->crtc_height; |
| 500 | win_data->fb_width = overlay->fb_width; |
| 501 | win_data->fb_height = overlay->fb_height; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame] | 502 | win_data->dma_addr = overlay->dma_addr[0] + offset; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 503 | win_data->bpp = overlay->bpp; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 504 | win_data->pixel_format = overlay->pixel_format; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 505 | win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) * |
| 506 | (overlay->bpp >> 3); |
| 507 | win_data->line_size = overlay->crtc_width * (overlay->bpp >> 3); |
| 508 | |
| 509 | DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n", |
| 510 | win_data->offset_x, win_data->offset_y); |
| 511 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
| 512 | win_data->ovl_width, win_data->ovl_height); |
YoungJun Cho | ddd8e95 | 2012-12-10 15:44:58 +0900 | [diff] [blame] | 513 | DRM_DEBUG_KMS("paddr = 0x%lx\n", (unsigned long)win_data->dma_addr); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 514 | DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n", |
| 515 | overlay->fb_width, overlay->crtc_width); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 516 | } |
| 517 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 518 | static void fimd_win_set_pixfmt(struct fimd_context *ctx, unsigned int win) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 519 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 520 | struct fimd_win_data *win_data = &ctx->win_data[win]; |
| 521 | unsigned long val; |
| 522 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 523 | val = WINCONx_ENWIN; |
| 524 | |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 525 | /* |
| 526 | * In case of s3c64xx, window 0 doesn't support alpha channel. |
| 527 | * So the request format is ARGB8888 then change it to XRGB8888. |
| 528 | */ |
| 529 | if (ctx->driver_data->has_limited_fmt && !win) { |
| 530 | if (win_data->pixel_format == DRM_FORMAT_ARGB8888) |
| 531 | win_data->pixel_format = DRM_FORMAT_XRGB8888; |
| 532 | } |
| 533 | |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 534 | switch (win_data->pixel_format) { |
| 535 | case DRM_FORMAT_C8: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 536 | val |= WINCON0_BPPMODE_8BPP_PALETTE; |
| 537 | val |= WINCONx_BURSTLEN_8WORD; |
| 538 | val |= WINCONx_BYTSWP; |
| 539 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 540 | case DRM_FORMAT_XRGB1555: |
| 541 | val |= WINCON0_BPPMODE_16BPP_1555; |
| 542 | val |= WINCONx_HAWSWP; |
| 543 | val |= WINCONx_BURSTLEN_16WORD; |
| 544 | break; |
| 545 | case DRM_FORMAT_RGB565: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 546 | val |= WINCON0_BPPMODE_16BPP_565; |
| 547 | val |= WINCONx_HAWSWP; |
| 548 | val |= WINCONx_BURSTLEN_16WORD; |
| 549 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 550 | case DRM_FORMAT_XRGB8888: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 551 | val |= WINCON0_BPPMODE_24BPP_888; |
| 552 | val |= WINCONx_WSWP; |
| 553 | val |= WINCONx_BURSTLEN_16WORD; |
| 554 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 555 | case DRM_FORMAT_ARGB8888: |
| 556 | val |= WINCON1_BPPMODE_25BPP_A1888 |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 557 | | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL; |
| 558 | val |= WINCONx_WSWP; |
| 559 | val |= WINCONx_BURSTLEN_16WORD; |
| 560 | break; |
| 561 | default: |
| 562 | DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n"); |
| 563 | |
| 564 | val |= WINCON0_BPPMODE_24BPP_888; |
| 565 | val |= WINCONx_WSWP; |
| 566 | val |= WINCONx_BURSTLEN_16WORD; |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | DRM_DEBUG_KMS("bpp = %d\n", win_data->bpp); |
| 571 | |
Rahul Sharma | 6636746 | 2014-05-07 16:55:22 +0530 | [diff] [blame] | 572 | /* |
| 573 | * In case of exynos, setting dma-burst to 16Word causes permanent |
| 574 | * tearing for very small buffers, e.g. cursor buffer. Burst Mode |
| 575 | * switching which is based on overlay size is not recommended as |
| 576 | * overlay size varies alot towards the end of the screen and rapid |
| 577 | * movement causes unstable DMA which results into iommu crash/tear. |
| 578 | */ |
| 579 | |
| 580 | if (win_data->fb_width < MIN_FB_WIDTH_FOR_16WORD_BURST) { |
| 581 | val &= ~WINCONx_BURSTLEN_MASK; |
| 582 | val |= WINCONx_BURSTLEN_4WORD; |
| 583 | } |
| 584 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 585 | writel(val, ctx->regs + WINCON(win)); |
| 586 | } |
| 587 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 588 | static void fimd_win_set_colkey(struct fimd_context *ctx, unsigned int win) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 589 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 590 | unsigned int keycon0 = 0, keycon1 = 0; |
| 591 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 592 | keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F | |
| 593 | WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); |
| 594 | |
| 595 | keycon1 = WxKEYCON1_COLVAL(0xffffffff); |
| 596 | |
| 597 | writel(keycon0, ctx->regs + WKEYCON0_BASE(win)); |
| 598 | writel(keycon1, ctx->regs + WKEYCON1_BASE(win)); |
| 599 | } |
| 600 | |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 601 | /** |
| 602 | * shadow_protect_win() - disable updating values from shadow registers at vsync |
| 603 | * |
| 604 | * @win: window to protect registers for |
| 605 | * @protect: 1 to protect (disable updates) |
| 606 | */ |
| 607 | static void fimd_shadow_protect_win(struct fimd_context *ctx, |
| 608 | int win, bool protect) |
| 609 | { |
| 610 | u32 reg, bits, val; |
| 611 | |
| 612 | if (ctx->driver_data->has_shadowcon) { |
| 613 | reg = SHADOWCON; |
| 614 | bits = SHADOWCON_WINx_PROTECT(win); |
| 615 | } else { |
| 616 | reg = PRTCON; |
| 617 | bits = PRTCON_PROTECT; |
| 618 | } |
| 619 | |
| 620 | val = readl(ctx->regs + reg); |
| 621 | if (protect) |
| 622 | val |= bits; |
| 623 | else |
| 624 | val &= ~bits; |
| 625 | writel(val, ctx->regs + reg); |
| 626 | } |
| 627 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 628 | static void fimd_win_commit(struct exynos_drm_manager *mgr, int zpos) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 629 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 630 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 631 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 632 | int win = zpos; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 633 | unsigned long val, alpha, size; |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 634 | unsigned int last_x; |
| 635 | unsigned int last_y; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 636 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 637 | if (ctx->suspended) |
| 638 | return; |
| 639 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 640 | if (win == DEFAULT_ZPOS) |
| 641 | win = ctx->default_win; |
| 642 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 643 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 644 | return; |
| 645 | |
| 646 | win_data = &ctx->win_data[win]; |
| 647 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 648 | /* If suspended, enable this on resume */ |
| 649 | if (ctx->suspended) { |
| 650 | win_data->resume = true; |
| 651 | return; |
| 652 | } |
| 653 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 654 | /* |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 655 | * SHADOWCON/PRTCON register is used for enabling timing. |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 656 | * |
| 657 | * for example, once only width value of a register is set, |
| 658 | * if the dma is started then fimd hardware could malfunction so |
| 659 | * with protect window setting, the register fields with prefix '_F' |
| 660 | * wouldn't be updated at vsync also but updated once unprotect window |
| 661 | * is set. |
| 662 | */ |
| 663 | |
| 664 | /* protect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 665 | fimd_shadow_protect_win(ctx, win, true); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 666 | |
| 667 | /* buffer start address */ |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 668 | val = (unsigned long)win_data->dma_addr; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 669 | writel(val, ctx->regs + VIDWx_BUF_START(win, 0)); |
| 670 | |
| 671 | /* buffer end address */ |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 672 | size = win_data->fb_width * win_data->ovl_height * (win_data->bpp >> 3); |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 673 | val = (unsigned long)(win_data->dma_addr + size); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 674 | writel(val, ctx->regs + VIDWx_BUF_END(win, 0)); |
| 675 | |
| 676 | DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n", |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 677 | (unsigned long)win_data->dma_addr, val, size); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 678 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
| 679 | win_data->ovl_width, win_data->ovl_height); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 680 | |
| 681 | /* buffer size */ |
| 682 | val = VIDW_BUF_SIZE_OFFSET(win_data->buf_offsize) | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 683 | VIDW_BUF_SIZE_PAGEWIDTH(win_data->line_size) | |
| 684 | VIDW_BUF_SIZE_OFFSET_E(win_data->buf_offsize) | |
| 685 | VIDW_BUF_SIZE_PAGEWIDTH_E(win_data->line_size); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 686 | writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0)); |
| 687 | |
| 688 | /* OSD position */ |
| 689 | val = VIDOSDxA_TOPLEFT_X(win_data->offset_x) | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 690 | VIDOSDxA_TOPLEFT_Y(win_data->offset_y) | |
| 691 | VIDOSDxA_TOPLEFT_X_E(win_data->offset_x) | |
| 692 | VIDOSDxA_TOPLEFT_Y_E(win_data->offset_y); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 693 | writel(val, ctx->regs + VIDOSD_A(win)); |
| 694 | |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 695 | last_x = win_data->offset_x + win_data->ovl_width; |
| 696 | if (last_x) |
| 697 | last_x--; |
| 698 | last_y = win_data->offset_y + win_data->ovl_height; |
| 699 | if (last_y) |
| 700 | last_y--; |
| 701 | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 702 | val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y) | |
| 703 | VIDOSDxB_BOTRIGHT_X_E(last_x) | VIDOSDxB_BOTRIGHT_Y_E(last_y); |
| 704 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 705 | writel(val, ctx->regs + VIDOSD_B(win)); |
| 706 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 707 | DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 708 | win_data->offset_x, win_data->offset_y, last_x, last_y); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 709 | |
| 710 | /* hardware window 0 doesn't support alpha channel. */ |
| 711 | if (win != 0) { |
| 712 | /* OSD alpha */ |
| 713 | alpha = VIDISD14C_ALPHA1_R(0xf) | |
| 714 | VIDISD14C_ALPHA1_G(0xf) | |
| 715 | VIDISD14C_ALPHA1_B(0xf); |
| 716 | |
| 717 | writel(alpha, ctx->regs + VIDOSD_C(win)); |
| 718 | } |
| 719 | |
| 720 | /* OSD size */ |
| 721 | if (win != 3 && win != 4) { |
| 722 | u32 offset = VIDOSD_D(win); |
| 723 | if (win == 0) |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 724 | offset = VIDOSD_C(win); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 725 | val = win_data->ovl_width * win_data->ovl_height; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 726 | writel(val, ctx->regs + offset); |
| 727 | |
| 728 | DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val); |
| 729 | } |
| 730 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 731 | fimd_win_set_pixfmt(ctx, win); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 732 | |
| 733 | /* hardware window 0 doesn't support color key. */ |
| 734 | if (win != 0) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 735 | fimd_win_set_colkey(ctx, win); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 736 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 737 | /* wincon */ |
| 738 | val = readl(ctx->regs + WINCON(win)); |
| 739 | val |= WINCONx_ENWIN; |
| 740 | writel(val, ctx->regs + WINCON(win)); |
| 741 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 742 | /* Enable DMA channel and unprotect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 743 | fimd_shadow_protect_win(ctx, win, false); |
| 744 | |
| 745 | if (ctx->driver_data->has_shadowcon) { |
| 746 | val = readl(ctx->regs + SHADOWCON); |
| 747 | val |= SHADOWCON_CHx_ENABLE(win); |
| 748 | writel(val, ctx->regs + SHADOWCON); |
| 749 | } |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 750 | |
| 751 | win_data->enabled = true; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 752 | |
| 753 | if (ctx->i80_if) |
| 754 | atomic_set(&ctx->win_updated, 1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 755 | } |
| 756 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 757 | static void fimd_win_disable(struct exynos_drm_manager *mgr, int zpos) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 758 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 759 | struct fimd_context *ctx = mgr->ctx; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 760 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 761 | int win = zpos; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 762 | u32 val; |
| 763 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 764 | if (win == DEFAULT_ZPOS) |
| 765 | win = ctx->default_win; |
| 766 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 767 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 768 | return; |
| 769 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 770 | win_data = &ctx->win_data[win]; |
| 771 | |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 772 | if (ctx->suspended) { |
| 773 | /* do not resume this window*/ |
| 774 | win_data->resume = false; |
| 775 | return; |
| 776 | } |
| 777 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 778 | /* protect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 779 | fimd_shadow_protect_win(ctx, win, true); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 780 | |
| 781 | /* wincon */ |
| 782 | val = readl(ctx->regs + WINCON(win)); |
| 783 | val &= ~WINCONx_ENWIN; |
| 784 | writel(val, ctx->regs + WINCON(win)); |
| 785 | |
| 786 | /* unprotect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 787 | if (ctx->driver_data->has_shadowcon) { |
| 788 | val = readl(ctx->regs + SHADOWCON); |
| 789 | val &= ~SHADOWCON_CHx_ENABLE(win); |
| 790 | writel(val, ctx->regs + SHADOWCON); |
| 791 | } |
| 792 | |
| 793 | fimd_shadow_protect_win(ctx, win, false); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 794 | |
| 795 | win_data->enabled = false; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 796 | } |
| 797 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 798 | static void fimd_window_suspend(struct exynos_drm_manager *mgr) |
| 799 | { |
| 800 | struct fimd_context *ctx = mgr->ctx; |
| 801 | struct fimd_win_data *win_data; |
| 802 | int i; |
| 803 | |
| 804 | for (i = 0; i < WINDOWS_NR; i++) { |
| 805 | win_data = &ctx->win_data[i]; |
| 806 | win_data->resume = win_data->enabled; |
| 807 | if (win_data->enabled) |
| 808 | fimd_win_disable(mgr, i); |
| 809 | } |
| 810 | fimd_wait_for_vblank(mgr); |
| 811 | } |
| 812 | |
| 813 | static void fimd_window_resume(struct exynos_drm_manager *mgr) |
| 814 | { |
| 815 | struct fimd_context *ctx = mgr->ctx; |
| 816 | struct fimd_win_data *win_data; |
| 817 | int i; |
| 818 | |
| 819 | for (i = 0; i < WINDOWS_NR; i++) { |
| 820 | win_data = &ctx->win_data[i]; |
| 821 | win_data->enabled = win_data->resume; |
| 822 | win_data->resume = false; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | static void fimd_apply(struct exynos_drm_manager *mgr) |
| 827 | { |
| 828 | struct fimd_context *ctx = mgr->ctx; |
| 829 | struct fimd_win_data *win_data; |
| 830 | int i; |
| 831 | |
| 832 | for (i = 0; i < WINDOWS_NR; i++) { |
| 833 | win_data = &ctx->win_data[i]; |
| 834 | if (win_data->enabled) |
| 835 | fimd_win_commit(mgr, i); |
Andrzej Hajda | d9b68d8 | 2014-06-09 16:10:59 +0200 | [diff] [blame] | 836 | else |
| 837 | fimd_win_disable(mgr, i); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | fimd_commit(mgr); |
| 841 | } |
| 842 | |
| 843 | static int fimd_poweron(struct exynos_drm_manager *mgr) |
| 844 | { |
| 845 | struct fimd_context *ctx = mgr->ctx; |
| 846 | int ret; |
| 847 | |
| 848 | if (!ctx->suspended) |
| 849 | return 0; |
| 850 | |
| 851 | ctx->suspended = false; |
| 852 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 853 | pm_runtime_get_sync(ctx->dev); |
| 854 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 855 | ret = clk_prepare_enable(ctx->bus_clk); |
| 856 | if (ret < 0) { |
| 857 | DRM_ERROR("Failed to prepare_enable the bus clk [%d]\n", ret); |
| 858 | goto bus_clk_err; |
| 859 | } |
| 860 | |
| 861 | ret = clk_prepare_enable(ctx->lcd_clk); |
| 862 | if (ret < 0) { |
| 863 | DRM_ERROR("Failed to prepare_enable the lcd clk [%d]\n", ret); |
| 864 | goto lcd_clk_err; |
| 865 | } |
| 866 | |
| 867 | /* if vblank was enabled status, enable it again. */ |
| 868 | if (test_and_clear_bit(0, &ctx->irq_flags)) { |
| 869 | ret = fimd_enable_vblank(mgr); |
| 870 | if (ret) { |
| 871 | DRM_ERROR("Failed to re-enable vblank [%d]\n", ret); |
| 872 | goto enable_vblank_err; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | fimd_window_resume(mgr); |
| 877 | |
| 878 | fimd_apply(mgr); |
| 879 | |
| 880 | return 0; |
| 881 | |
| 882 | enable_vblank_err: |
| 883 | clk_disable_unprepare(ctx->lcd_clk); |
| 884 | lcd_clk_err: |
| 885 | clk_disable_unprepare(ctx->bus_clk); |
| 886 | bus_clk_err: |
| 887 | ctx->suspended = true; |
| 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | static int fimd_poweroff(struct exynos_drm_manager *mgr) |
| 892 | { |
| 893 | struct fimd_context *ctx = mgr->ctx; |
| 894 | |
| 895 | if (ctx->suspended) |
| 896 | return 0; |
| 897 | |
| 898 | /* |
| 899 | * We need to make sure that all windows are disabled before we |
| 900 | * suspend that connector. Otherwise we might try to scan from |
| 901 | * a destroyed buffer later. |
| 902 | */ |
| 903 | fimd_window_suspend(mgr); |
| 904 | |
| 905 | clk_disable_unprepare(ctx->lcd_clk); |
| 906 | clk_disable_unprepare(ctx->bus_clk); |
| 907 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 908 | pm_runtime_put_sync(ctx->dev); |
| 909 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 910 | ctx->suspended = true; |
| 911 | return 0; |
| 912 | } |
| 913 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 914 | static void fimd_dpms(struct exynos_drm_manager *mgr, int mode) |
| 915 | { |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 916 | DRM_DEBUG_KMS("%s, %d\n", __FILE__, mode); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 917 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 918 | switch (mode) { |
| 919 | case DRM_MODE_DPMS_ON: |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 920 | fimd_poweron(mgr); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 921 | break; |
| 922 | case DRM_MODE_DPMS_STANDBY: |
| 923 | case DRM_MODE_DPMS_SUSPEND: |
| 924 | case DRM_MODE_DPMS_OFF: |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 925 | fimd_poweroff(mgr); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 926 | break; |
| 927 | default: |
| 928 | DRM_DEBUG_KMS("unspecified mode %d\n", mode); |
| 929 | break; |
| 930 | } |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 931 | } |
| 932 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 933 | static void fimd_trigger(struct device *dev) |
| 934 | { |
| 935 | struct exynos_drm_manager *mgr = get_fimd_manager(dev); |
| 936 | struct fimd_context *ctx = mgr->ctx; |
| 937 | struct fimd_driver_data *driver_data = ctx->driver_data; |
| 938 | void *timing_base = ctx->regs + driver_data->timing_base; |
| 939 | u32 reg; |
| 940 | |
| 941 | atomic_set(&ctx->triggering, 1); |
| 942 | |
| 943 | reg = readl(ctx->regs + VIDINTCON0); |
| 944 | reg |= (VIDINTCON0_INT_ENABLE | VIDINTCON0_INT_I80IFDONE | |
| 945 | VIDINTCON0_INT_SYSMAINCON); |
| 946 | writel(reg, ctx->regs + VIDINTCON0); |
| 947 | |
| 948 | reg = readl(timing_base + TRIGCON); |
| 949 | reg |= (TRGMODE_I80_RGB_ENABLE_I80 | SWTRGCMD_I80_RGB_ENABLE); |
| 950 | writel(reg, timing_base + TRIGCON); |
| 951 | } |
| 952 | |
| 953 | static void fimd_te_handler(struct exynos_drm_manager *mgr) |
| 954 | { |
| 955 | struct fimd_context *ctx = mgr->ctx; |
| 956 | |
| 957 | /* Checks the crtc is detached already from encoder */ |
| 958 | if (ctx->pipe < 0 || !ctx->drm_dev) |
| 959 | return; |
| 960 | |
| 961 | /* |
| 962 | * Skips to trigger if in triggering state, because multiple triggering |
| 963 | * requests can cause panel reset. |
| 964 | */ |
| 965 | if (atomic_read(&ctx->triggering)) |
| 966 | return; |
| 967 | |
| 968 | /* |
| 969 | * If there is a page flip request, triggers and handles the page flip |
| 970 | * event so that current fb can be updated into panel GRAM. |
| 971 | */ |
| 972 | if (atomic_add_unless(&ctx->win_updated, -1, 0)) |
| 973 | fimd_trigger(ctx->dev); |
| 974 | |
| 975 | /* Wakes up vsync event queue */ |
| 976 | if (atomic_read(&ctx->wait_vsync_event)) { |
| 977 | atomic_set(&ctx->wait_vsync_event, 0); |
| 978 | wake_up(&ctx->wait_vsync_queue); |
| 979 | |
| 980 | if (!atomic_read(&ctx->triggering)) |
| 981 | drm_handle_vblank(ctx->drm_dev, ctx->pipe); |
| 982 | } |
| 983 | } |
| 984 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 985 | static struct exynos_drm_manager_ops fimd_manager_ops = { |
| 986 | .dpms = fimd_dpms, |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 987 | .mode_fixup = fimd_mode_fixup, |
| 988 | .mode_set = fimd_mode_set, |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 989 | .commit = fimd_commit, |
| 990 | .enable_vblank = fimd_enable_vblank, |
| 991 | .disable_vblank = fimd_disable_vblank, |
| 992 | .wait_for_vblank = fimd_wait_for_vblank, |
| 993 | .win_mode_set = fimd_win_mode_set, |
| 994 | .win_commit = fimd_win_commit, |
| 995 | .win_disable = fimd_win_disable, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 996 | .te_handler = fimd_te_handler, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 997 | }; |
| 998 | |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 999 | static struct exynos_drm_manager fimd_manager = { |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 1000 | .type = EXYNOS_DISPLAY_TYPE_LCD, |
| 1001 | .ops = &fimd_manager_ops, |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 1002 | }; |
| 1003 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1004 | static irqreturn_t fimd_irq_handler(int irq, void *dev_id) |
| 1005 | { |
| 1006 | struct fimd_context *ctx = (struct fimd_context *)dev_id; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1007 | u32 val, clear_bit; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1008 | |
| 1009 | val = readl(ctx->regs + VIDINTCON1); |
| 1010 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1011 | clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; |
| 1012 | if (val & clear_bit) |
| 1013 | writel(clear_bit, ctx->regs + VIDINTCON1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1014 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 1015 | /* check the crtc is detached already from encoder */ |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 1016 | if (ctx->pipe < 0 || !ctx->drm_dev) |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 1017 | goto out; |
Inki Dae | 483b88f | 2011-11-11 21:28:00 +0900 | [diff] [blame] | 1018 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1019 | if (ctx->i80_if) { |
| 1020 | /* unset I80 frame done interrupt */ |
| 1021 | val = readl(ctx->regs + VIDINTCON0); |
| 1022 | val &= ~(VIDINTCON0_INT_I80IFDONE | VIDINTCON0_INT_SYSMAINCON); |
| 1023 | writel(val, ctx->regs + VIDINTCON0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1024 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1025 | /* exit triggering mode */ |
| 1026 | atomic_set(&ctx->triggering, 0); |
| 1027 | |
| 1028 | drm_handle_vblank(ctx->drm_dev, ctx->pipe); |
| 1029 | exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); |
| 1030 | } else { |
| 1031 | drm_handle_vblank(ctx->drm_dev, ctx->pipe); |
| 1032 | exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); |
| 1033 | |
| 1034 | /* set wait vsync event to zero and wake up queue. */ |
| 1035 | if (atomic_read(&ctx->wait_vsync_event)) { |
| 1036 | atomic_set(&ctx->wait_vsync_event, 0); |
| 1037 | wake_up(&ctx->wait_vsync_queue); |
| 1038 | } |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 1039 | } |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1040 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 1041 | out: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1042 | return IRQ_HANDLED; |
| 1043 | } |
| 1044 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1045 | static int fimd_bind(struct device *dev, struct device *master, void *data) |
Andrzej Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 1046 | { |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1047 | struct fimd_context *ctx = fimd_manager.ctx; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1048 | struct drm_device *drm_dev = data; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1049 | |
| 1050 | fimd_mgr_initialize(&fimd_manager, drm_dev); |
| 1051 | exynos_drm_crtc_create(&fimd_manager); |
| 1052 | if (ctx->display) |
| 1053 | exynos_drm_create_enc_conn(drm_dev, ctx->display); |
| 1054 | |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1055 | return 0; |
| 1056 | |
| 1057 | } |
| 1058 | |
| 1059 | static void fimd_unbind(struct device *dev, struct device *master, |
| 1060 | void *data) |
| 1061 | { |
| 1062 | struct exynos_drm_manager *mgr = dev_get_drvdata(dev); |
| 1063 | struct fimd_context *ctx = fimd_manager.ctx; |
| 1064 | struct drm_crtc *crtc = mgr->crtc; |
| 1065 | |
| 1066 | fimd_dpms(mgr, DRM_MODE_DPMS_OFF); |
| 1067 | |
| 1068 | if (ctx->display) |
| 1069 | exynos_dpi_remove(dev); |
| 1070 | |
| 1071 | fimd_mgr_remove(mgr); |
| 1072 | |
| 1073 | crtc->funcs->destroy(crtc); |
| 1074 | } |
| 1075 | |
| 1076 | static const struct component_ops fimd_component_ops = { |
| 1077 | .bind = fimd_bind, |
| 1078 | .unbind = fimd_unbind, |
| 1079 | }; |
| 1080 | |
| 1081 | static int fimd_probe(struct platform_device *pdev) |
| 1082 | { |
| 1083 | struct device *dev = &pdev->dev; |
| 1084 | struct fimd_context *ctx; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1085 | struct device_node *i80_if_timings; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1086 | struct resource *res; |
Andrzej Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 1087 | int ret = -EINVAL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1088 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1089 | ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC, |
| 1090 | fimd_manager.type); |
| 1091 | if (ret) |
| 1092 | return ret; |
| 1093 | |
| 1094 | if (!dev->of_node) { |
| 1095 | ret = -ENODEV; |
| 1096 | goto err_del_component; |
| 1097 | } |
Sachin Kamat | 2d3f173 | 2013-08-28 10:47:58 +0530 | [diff] [blame] | 1098 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1099 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1100 | if (!ctx) { |
| 1101 | ret = -ENOMEM; |
| 1102 | goto err_del_component; |
| 1103 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1104 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 1105 | ctx->dev = dev; |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 1106 | ctx->suspended = true; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1107 | ctx->driver_data = drm_fimd_get_driver_data(pdev); |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 1108 | |
Sean Paul | 1417f10 | 2014-01-30 16:19:23 -0500 | [diff] [blame] | 1109 | if (of_property_read_bool(dev->of_node, "samsung,invert-vden")) |
| 1110 | ctx->vidcon1 |= VIDCON1_INV_VDEN; |
| 1111 | if (of_property_read_bool(dev->of_node, "samsung,invert-vclk")) |
| 1112 | ctx->vidcon1 |= VIDCON1_INV_VCLK; |
Andrzej Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 1113 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1114 | i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings"); |
| 1115 | if (i80_if_timings) { |
| 1116 | u32 val; |
| 1117 | |
| 1118 | ctx->i80_if = true; |
| 1119 | |
| 1120 | if (ctx->driver_data->has_vidoutcon) |
| 1121 | ctx->vidout_con |= VIDOUT_CON_F_I80_LDI0; |
| 1122 | else |
| 1123 | ctx->vidcon0 |= VIDCON0_VIDOUT_I80_LDI0; |
| 1124 | /* |
| 1125 | * The user manual describes that this "DSI_EN" bit is required |
| 1126 | * to enable I80 24-bit data interface. |
| 1127 | */ |
| 1128 | ctx->vidcon0 |= VIDCON0_DSI_EN; |
| 1129 | |
| 1130 | if (of_property_read_u32(i80_if_timings, "cs-setup", &val)) |
| 1131 | val = 0; |
| 1132 | ctx->i80ifcon = LCD_CS_SETUP(val); |
| 1133 | if (of_property_read_u32(i80_if_timings, "wr-setup", &val)) |
| 1134 | val = 0; |
| 1135 | ctx->i80ifcon |= LCD_WR_SETUP(val); |
| 1136 | if (of_property_read_u32(i80_if_timings, "wr-active", &val)) |
| 1137 | val = 1; |
| 1138 | ctx->i80ifcon |= LCD_WR_ACTIVE(val); |
| 1139 | if (of_property_read_u32(i80_if_timings, "wr-hold", &val)) |
| 1140 | val = 0; |
| 1141 | ctx->i80ifcon |= LCD_WR_HOLD(val); |
| 1142 | } |
| 1143 | of_node_put(i80_if_timings); |
| 1144 | |
| 1145 | ctx->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, |
| 1146 | "samsung,sysreg"); |
| 1147 | if (IS_ERR(ctx->sysreg)) { |
| 1148 | dev_warn(dev, "failed to get system register.\n"); |
| 1149 | ctx->sysreg = NULL; |
| 1150 | } |
| 1151 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1152 | ctx->bus_clk = devm_clk_get(dev, "fimd"); |
| 1153 | if (IS_ERR(ctx->bus_clk)) { |
| 1154 | dev_err(dev, "failed to get bus clock\n"); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1155 | ret = PTR_ERR(ctx->bus_clk); |
| 1156 | goto err_del_component; |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd"); |
| 1160 | if (IS_ERR(ctx->lcd_clk)) { |
| 1161 | dev_err(dev, "failed to get lcd clock\n"); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1162 | ret = PTR_ERR(ctx->lcd_clk); |
| 1163 | goto err_del_component; |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1164 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1165 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1166 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1167 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1168 | ctx->regs = devm_ioremap_resource(dev, res); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1169 | if (IS_ERR(ctx->regs)) { |
| 1170 | ret = PTR_ERR(ctx->regs); |
| 1171 | goto err_del_component; |
| 1172 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1173 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1174 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1175 | ctx->i80_if ? "lcd_sys" : "vsync"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1176 | if (!res) { |
| 1177 | dev_err(dev, "irq request failed.\n"); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1178 | ret = -ENXIO; |
| 1179 | goto err_del_component; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1180 | } |
| 1181 | |
Sean Paul | 055e0c0 | 2014-01-30 16:19:21 -0500 | [diff] [blame] | 1182 | ret = devm_request_irq(dev, res->start, fimd_irq_handler, |
Sachin Kamat | edc5726 | 2012-06-19 11:47:39 +0530 | [diff] [blame] | 1183 | 0, "drm_fimd", ctx); |
| 1184 | if (ret) { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1185 | dev_err(dev, "irq request failed.\n"); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1186 | goto err_del_component; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1187 | } |
| 1188 | |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 1189 | init_waitqueue_head(&ctx->wait_vsync_queue); |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 1190 | atomic_set(&ctx->wait_vsync_event, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1191 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 1192 | platform_set_drvdata(pdev, &fimd_manager); |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 1193 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 1194 | fimd_manager.ctx = ctx; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 1195 | |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1196 | ctx->display = exynos_dpi_probe(dev); |
| 1197 | if (IS_ERR(ctx->display)) |
| 1198 | return PTR_ERR(ctx->display); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1199 | |
| 1200 | pm_runtime_enable(&pdev->dev); |
| 1201 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1202 | ret = component_add(&pdev->dev, &fimd_component_ops); |
| 1203 | if (ret) |
| 1204 | goto err_disable_pm_runtime; |
| 1205 | |
| 1206 | return ret; |
| 1207 | |
| 1208 | err_disable_pm_runtime: |
| 1209 | pm_runtime_disable(&pdev->dev); |
| 1210 | |
| 1211 | err_del_component: |
| 1212 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); |
| 1213 | return ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | static int fimd_remove(struct platform_device *pdev) |
| 1217 | { |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 1218 | pm_runtime_disable(&pdev->dev); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1219 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1220 | component_del(&pdev->dev, &fimd_component_ops); |
| 1221 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); |
| 1222 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 1226 | struct platform_driver fimd_driver = { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1227 | .probe = fimd_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1228 | .remove = fimd_remove, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1229 | .driver = { |
| 1230 | .name = "exynos4-fb", |
| 1231 | .owner = THIS_MODULE, |
Sachin Kamat | 2d3f173 | 2013-08-28 10:47:58 +0530 | [diff] [blame] | 1232 | .of_match_table = fimd_driver_dt_match, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1233 | }, |
| 1234 | }; |