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" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 32 | #include "exynos_drm_fb.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 33 | #include "exynos_drm_crtc.h" |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 34 | #include "exynos_drm_plane.h" |
Inki Dae | bcc5cd1c | 2012-10-19 17:16:36 +0900 | [diff] [blame] | 35 | #include "exynos_drm_iommu.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 36 | |
| 37 | /* |
Sachin Kamat | b8654b3 | 2013-09-19 10:39:44 +0530 | [diff] [blame] | 38 | * FIMD stands for Fully Interactive Mobile Display and |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 39 | * 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 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 | |
Gustavo Padovan | 453b44a | 2015-04-01 13:02:05 -0300 | [diff] [blame] | 57 | #define VIDWnALPHA0(win) (VIDW_ALPHA + 0x00 + (win) * 8) |
| 58 | #define VIDWnALPHA1(win) (VIDW_ALPHA + 0x04 + (win) * 8) |
| 59 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 60 | #define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8) |
Gustavo Padovan | cb11b3f | 2015-08-15 13:26:16 -0300 | [diff] [blame] | 61 | #define VIDWx_BUF_START_S(win, buf) (VIDW_BUF_START_S(buf) + (win) * 8) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 62 | #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 Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 66 | #define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 67 | /* color key value register for hardware window 1 ~ 4. */ |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 68 | #define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 69 | |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 70 | /* I80 trigger control register */ |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 71 | #define TRIGCON 0x1A4 |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 72 | #define TRGMODE_ENABLE (1 << 0) |
| 73 | #define SWTRGCMD_ENABLE (1 << 1) |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 74 | /* Exynos3250, 3472, 4415, 5260 5410, 5420 and 5422 only supported. */ |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 75 | #define HWTRGEN_ENABLE (1 << 3) |
| 76 | #define HWTRGMASK_ENABLE (1 << 4) |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 77 | /* Exynos3250, 3472, 4415, 5260, 5420 and 5422 only supported. */ |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 78 | #define HWTRIGEN_PER_ENABLE (1 << 31) |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 79 | |
| 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 93 | /* FIMD has totally five hardware windows. */ |
| 94 | #define WINDOWS_NR 5 |
| 95 | |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 96 | /* HW trigger flag on i80 panel. */ |
| 97 | #define I80_HW_TRG (1 << 1) |
| 98 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 99 | struct fimd_driver_data { |
| 100 | unsigned int timing_base; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 101 | unsigned int lcdblk_offset; |
| 102 | unsigned int lcdblk_vt_shift; |
| 103 | unsigned int lcdblk_bypass_shift; |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 104 | unsigned int lcdblk_mic_bypass_shift; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 105 | unsigned int trg_type; |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 106 | |
| 107 | unsigned int has_shadowcon:1; |
Tomasz Figa | 411d9ed | 2013-05-01 21:02:28 +0200 | [diff] [blame] | 108 | unsigned int has_clksel:1; |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 109 | unsigned int has_limited_fmt:1; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 110 | unsigned int has_vidoutcon:1; |
Joonyoung Shim | 3c3c9c1 | 2014-11-14 11:36:02 +0900 | [diff] [blame] | 111 | unsigned int has_vtsel:1; |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 112 | unsigned int has_mic_bypass:1; |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 113 | unsigned int has_dp_clk:1; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 114 | unsigned int has_hw_trigger:1; |
| 115 | unsigned int has_trigger_per_te:1; |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 116 | }; |
| 117 | |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 118 | static struct fimd_driver_data s3c64xx_fimd_driver_data = { |
| 119 | .timing_base = 0x0, |
| 120 | .has_clksel = 1, |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 121 | .has_limited_fmt = 1, |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame] | 124 | static struct fimd_driver_data exynos3_fimd_driver_data = { |
| 125 | .timing_base = 0x20000, |
| 126 | .lcdblk_offset = 0x210, |
| 127 | .lcdblk_bypass_shift = 1, |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 128 | .trg_type = I80_HW_TRG, |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame] | 129 | .has_shadowcon = 1, |
| 130 | .has_vidoutcon = 1, |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 131 | .has_trigger_per_te = 1, |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame] | 132 | }; |
| 133 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 134 | static struct fimd_driver_data exynos4_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 135 | .timing_base = 0x0, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 136 | .lcdblk_offset = 0x210, |
| 137 | .lcdblk_vt_shift = 10, |
| 138 | .lcdblk_bypass_shift = 1, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 139 | .has_shadowcon = 1, |
Joonyoung Shim | 3c3c9c1 | 2014-11-14 11:36:02 +0900 | [diff] [blame] | 140 | .has_vtsel = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 141 | }; |
| 142 | |
YoungJun Cho | dcb622a | 2014-11-07 15:12:25 +0900 | [diff] [blame] | 143 | static 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 Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 148 | .trg_type = I80_HW_TRG, |
YoungJun Cho | dcb622a | 2014-11-07 15:12:25 +0900 | [diff] [blame] | 149 | .has_shadowcon = 1, |
| 150 | .has_vidoutcon = 1, |
Joonyoung Shim | 3c3c9c1 | 2014-11-14 11:36:02 +0900 | [diff] [blame] | 151 | .has_vtsel = 1, |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 152 | .has_trigger_per_te = 1, |
YoungJun Cho | dcb622a | 2014-11-07 15:12:25 +0900 | [diff] [blame] | 153 | }; |
| 154 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 155 | static struct fimd_driver_data exynos5_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 156 | .timing_base = 0x20000, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 157 | .lcdblk_offset = 0x214, |
| 158 | .lcdblk_vt_shift = 24, |
| 159 | .lcdblk_bypass_shift = 15, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 160 | .has_shadowcon = 1, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 161 | .has_vidoutcon = 1, |
Joonyoung Shim | 3c3c9c1 | 2014-11-14 11:36:02 +0900 | [diff] [blame] | 162 | .has_vtsel = 1, |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 163 | .has_dp_clk = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 164 | }; |
| 165 | |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 166 | static 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 Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 176 | .has_dp_clk = 1, |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 177 | }; |
| 178 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 179 | struct fimd_context { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 180 | struct device *dev; |
Sean Paul | 40c8ab4 | 2014-01-30 16:19:04 -0500 | [diff] [blame] | 181 | struct drm_device *drm_dev; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 182 | struct exynos_drm_crtc *crtc; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 183 | struct exynos_drm_plane planes[WINDOWS_NR]; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 184 | struct exynos_drm_plane_config configs[WINDOWS_NR]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 185 | struct clk *bus_clk; |
| 186 | struct clk *lcd_clk; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 187 | void __iomem *regs; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 188 | struct regmap *sysreg; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 189 | unsigned long irq_flags; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 190 | u32 vidcon0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 191 | u32 vidcon1; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 192 | u32 vidout_con; |
| 193 | u32 i80ifcon; |
| 194 | bool i80_if; |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 195 | bool suspended; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 196 | int pipe; |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 197 | wait_queue_head_t wait_vsync_queue; |
| 198 | atomic_t wait_vsync_event; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 199 | atomic_t win_updated; |
| 200 | atomic_t triggering; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 201 | |
Marek Szyprowski | e1a7b9b | 2016-04-18 17:38:27 +0900 | [diff] [blame] | 202 | const struct fimd_driver_data *driver_data; |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 203 | struct drm_encoder *encoder; |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 204 | struct exynos_drm_clk dp_clk; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 205 | }; |
| 206 | |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 207 | static const struct of_device_id fimd_driver_dt_match[] = { |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 208 | { .compatible = "samsung,s3c6400-fimd", |
| 209 | .data = &s3c64xx_fimd_driver_data }, |
Inki Dae | d6ce7b5 | 2014-08-18 16:53:19 +0900 | [diff] [blame] | 210 | { .compatible = "samsung,exynos3250-fimd", |
| 211 | .data = &exynos3_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 212 | { .compatible = "samsung,exynos4210-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 213 | .data = &exynos4_fimd_driver_data }, |
YoungJun Cho | dcb622a | 2014-11-07 15:12:25 +0900 | [diff] [blame] | 214 | { .compatible = "samsung,exynos4415-fimd", |
| 215 | .data = &exynos4415_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 216 | { .compatible = "samsung,exynos5250-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 217 | .data = &exynos5_fimd_driver_data }, |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 218 | { .compatible = "samsung,exynos5420-fimd", |
| 219 | .data = &exynos5420_fimd_driver_data }, |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 220 | {}, |
| 221 | }; |
Sjoerd Simons | 0262cee | 2014-07-30 11:28:31 +0900 | [diff] [blame] | 222 | MODULE_DEVICE_TABLE(of, fimd_driver_dt_match); |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 223 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 224 | static 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 Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 232 | static 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 Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 240 | static 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 | |
| 272 | static 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 Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 296 | static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc) |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 297 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 298 | struct fimd_context *ctx = crtc->ctx; |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 299 | |
| 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 Jakobi | 5b1d5bc | 2015-05-06 14:10:22 +0200 | [diff] [blame] | 315 | static void fimd_enable_video_output(struct fimd_context *ctx, unsigned int win, |
YoungJun Cho | f181a54 | 2014-11-17 22:00:10 +0900 | [diff] [blame] | 316 | 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 Jakobi | 5b1d5bc | 2015-05-06 14:10:22 +0200 | [diff] [blame] | 328 | static void fimd_enable_shadow_channel_path(struct fimd_context *ctx, |
| 329 | unsigned int win, |
YoungJun Cho | 999d8b3 | 2014-11-17 22:00:11 +0900 | [diff] [blame] | 330 | 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 Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 342 | static void fimd_clear_channels(struct exynos_drm_crtc *crtc) |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 343 | { |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 344 | struct fimd_context *ctx = crtc->ctx; |
Tobias Jakobi | 5b1d5bc | 2015-05-06 14:10:22 +0200 | [diff] [blame] | 345 | unsigned int win, ch_enabled = 0; |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 346 | |
| 347 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 348 | |
Marek Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 349 | /* 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 Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 355 | /* Check if any channel is enabled. */ |
| 356 | for (win = 0; win < WINDOWS_NR; win++) { |
Marek Szyprowski | eb8a3bf | 2014-09-01 22:27:10 +0900 | [diff] [blame] | 357 | u32 val = readl(ctx->regs + WINCON(win)); |
| 358 | |
| 359 | if (val & WINCONx_ENWIN) { |
YoungJun Cho | f181a54 | 2014-11-17 22:00:10 +0900 | [diff] [blame] | 360 | fimd_enable_video_output(ctx, win, false); |
Marek Szyprowski | eb8a3bf | 2014-09-01 22:27:10 +0900 | [diff] [blame] | 361 | |
YoungJun Cho | 999d8b3 | 2014-11-17 22:00:11 +0900 | [diff] [blame] | 362 | if (ctx->driver_data->has_shadowcon) |
| 363 | fimd_enable_shadow_channel_path(ctx, win, |
| 364 | false); |
| 365 | |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 366 | ch_enabled = 1; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /* Wait for vsync, as disable channel takes effect at next vsync */ |
Marek Szyprowski | eb8a3bf | 2014-09-01 22:27:10 +0900 | [diff] [blame] | 371 | if (ch_enabled) { |
Marek Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 372 | int pipe = ctx->pipe; |
Marek Szyprowski | eb8a3bf | 2014-09-01 22:27:10 +0900 | [diff] [blame] | 373 | |
Marek Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 374 | /* 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 Shim | 92dc7a0 | 2015-01-30 16:43:02 +0900 | [diff] [blame] | 379 | fimd_wait_for_vblank(ctx->crtc); |
Marek Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 380 | fimd_disable_vblank(ctx->crtc); |
| 381 | |
| 382 | ctx->suspended = true; |
| 383 | ctx->pipe = pipe; |
Marek Szyprowski | eb8a3bf | 2014-09-01 22:27:10 +0900 | [diff] [blame] | 384 | } |
Marek Szyprowski | fb88e21 | 2015-06-12 11:07:17 +0200 | [diff] [blame] | 385 | |
| 386 | clk_disable_unprepare(ctx->lcd_clk); |
| 387 | clk_disable_unprepare(ctx->bus_clk); |
| 388 | |
| 389 | pm_runtime_put(ctx->dev); |
Akshu Agrawal | f13bdbd | 2014-04-28 21:26:39 +0900 | [diff] [blame] | 390 | } |
| 391 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 392 | static u32 fimd_calc_clkdiv(struct fimd_context *ctx, |
| 393 | const struct drm_display_mode *mode) |
| 394 | { |
Tobias Jakobi | fa9971d | 2016-05-05 18:23:38 +0200 | [diff] [blame] | 395 | unsigned long ideal_clk; |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 396 | u32 clkdiv; |
| 397 | |
Tobias Jakobi | fa9971d | 2016-05-05 18:23:38 +0200 | [diff] [blame] | 398 | 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 Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 405 | 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 Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 413 | /* Find the clock divider value that gets us closest to ideal_clk */ |
Chanho Park | 217fb00 | 2016-02-11 23:11:20 +0900 | [diff] [blame] | 414 | clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(ctx->lcd_clk), ideal_clk); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 415 | |
| 416 | return (clkdiv < 0x100) ? clkdiv : 0xff; |
| 417 | } |
| 418 | |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 419 | static 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 Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 425 | val &= ~(TRGMODE_ENABLE); |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 426 | |
| 427 | if (trg_type == I80_HW_TRG) { |
| 428 | if (ctx->driver_data->has_hw_trigger) |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 429 | val |= HWTRGEN_ENABLE | HWTRGMASK_ENABLE; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 430 | if (ctx->driver_data->has_trigger_per_te) |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 431 | val |= HWTRIGEN_PER_ENABLE; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 432 | } else { |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 433 | val |= TRGMODE_ENABLE; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | writel(val, timing_base + TRIGCON); |
| 437 | } |
| 438 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 439 | static void fimd_commit(struct exynos_drm_crtc *crtc) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 440 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 441 | struct fimd_context *ctx = crtc->ctx; |
Joonyoung Shim | 020e79d | 2015-06-02 21:04:42 +0900 | [diff] [blame] | 442 | struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; |
Marek Szyprowski | e1a7b9b | 2016-04-18 17:38:27 +0900 | [diff] [blame] | 443 | const struct fimd_driver_data *driver_data = ctx->driver_data; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 444 | void *timing_base = ctx->regs + driver_data->timing_base; |
| 445 | u32 val, clkdiv; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 446 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 447 | if (ctx->suspended) |
| 448 | return; |
| 449 | |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 450 | /* nothing to do if we haven't set the mode yet */ |
| 451 | if (mode->htotal == 0 || mode->vtotal == 0) |
| 452 | return; |
| 453 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 454 | if (ctx->i80_if) { |
| 455 | val = ctx->i80ifcon | I80IFEN_ENABLE; |
| 456 | writel(val, timing_base + I80IFCONFAx(0)); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 457 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 458 | /* disable auto frame rate */ |
| 459 | writel(0, timing_base + I80IFCONFBx(0)); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 460 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 461 | /* set video type selection to I80 interface */ |
Joonyoung Shim | 3c3c9c1 | 2014-11-14 11:36:02 +0900 | [diff] [blame] | 462 | if (driver_data->has_vtsel && ctx->sysreg && |
| 463 | regmap_update_bits(ctx->sysreg, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 464 | 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 473 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 474 | /* 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 Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 481 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 482 | /* 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 514 | |
Chanho Park | 1feafd3 | 2016-02-12 22:31:39 +0900 | [diff] [blame] | 515 | /* 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 527 | /* setup horizontal and vertical display size. */ |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 528 | 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 Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 532 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON2); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 533 | |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 534 | fimd_setup_trigger(ctx); |
| 535 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 536 | /* |
| 537 | * fields of register with prefix '_F' would be updated |
| 538 | * at vsync(same as dma start) |
| 539 | */ |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 540 | val = ctx->vidcon0; |
| 541 | val |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
Andrzej Hajda | 1d53106 | 2014-03-20 17:09:00 +0900 | [diff] [blame] | 542 | |
| 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 550 | writel(val, ctx->regs + VIDCON0); |
| 551 | } |
| 552 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 553 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 554 | static void fimd_win_set_pixfmt(struct fimd_context *ctx, unsigned int win, |
Marek Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 555 | uint32_t pixel_format, int width) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 556 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 557 | unsigned long val; |
| 558 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 559 | val = WINCONx_ENWIN; |
| 560 | |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 561 | /* |
| 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 Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 566 | if (pixel_format == DRM_FORMAT_ARGB8888) |
| 567 | pixel_format = DRM_FORMAT_XRGB8888; |
Inki Dae | 5cc4621 | 2013-08-20 14:28:56 +0900 | [diff] [blame] | 568 | } |
| 569 | |
Marek Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 570 | switch (pixel_format) { |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 571 | case DRM_FORMAT_C8: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 572 | val |= WINCON0_BPPMODE_8BPP_PALETTE; |
| 573 | val |= WINCONx_BURSTLEN_8WORD; |
| 574 | val |= WINCONx_BYTSWP; |
| 575 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 576 | 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 582 | val |= WINCON0_BPPMODE_16BPP_565; |
| 583 | val |= WINCONx_HAWSWP; |
| 584 | val |= WINCONx_BURSTLEN_16WORD; |
| 585 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 586 | case DRM_FORMAT_XRGB8888: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 587 | val |= WINCON0_BPPMODE_24BPP_888; |
| 588 | val |= WINCONx_WSWP; |
| 589 | val |= WINCONx_BURSTLEN_16WORD; |
| 590 | break; |
Inki Dae | a4f38a8 | 2013-08-20 13:51:02 +0900 | [diff] [blame] | 591 | case DRM_FORMAT_ARGB8888: |
| 592 | val |= WINCON1_BPPMODE_25BPP_A1888 |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 593 | | 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 Sharma | 6636746 | 2014-05-07 16:55:22 +0530 | [diff] [blame] | 606 | /* |
Marek Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 607 | * 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 Sharma | 6636746 | 2014-05-07 16:55:22 +0530 | [diff] [blame] | 612 | */ |
| 613 | |
Marek Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 614 | if (width < MIN_FB_WIDTH_FOR_16WORD_BURST) { |
Rahul Sharma | 6636746 | 2014-05-07 16:55:22 +0530 | [diff] [blame] | 615 | val &= ~WINCONx_BURSTLEN_MASK; |
| 616 | val |= WINCONx_BURSTLEN_4WORD; |
| 617 | } |
| 618 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 619 | writel(val, ctx->regs + WINCON(win)); |
Gustavo Padovan | 453b44a | 2015-04-01 13:02:05 -0300 | [diff] [blame] | 620 | |
| 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 638 | } |
| 639 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 640 | 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] | 641 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 642 | unsigned int keycon0 = 0, keycon1 = 0; |
| 643 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 644 | 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 Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 653 | /** |
| 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 | */ |
| 659 | static void fimd_shadow_protect_win(struct fimd_context *ctx, |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 660 | unsigned int win, bool protect) |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 661 | { |
| 662 | u32 reg, bits, val; |
| 663 | |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 664 | /* |
| 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 Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 674 | 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 Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 690 | static void fimd_atomic_begin(struct exynos_drm_crtc *crtc) |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 691 | { |
| 692 | struct fimd_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 693 | int i; |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 694 | |
| 695 | if (ctx->suspended) |
| 696 | return; |
| 697 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 698 | for (i = 0; i < WINDOWS_NR; i++) |
| 699 | fimd_shadow_protect_win(ctx, i, true); |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 700 | } |
| 701 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 702 | static void fimd_atomic_flush(struct exynos_drm_crtc *crtc) |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 703 | { |
| 704 | struct fimd_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 705 | int i; |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 706 | |
| 707 | if (ctx->suspended) |
| 708 | return; |
| 709 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 710 | for (i = 0; i < WINDOWS_NR; i++) |
| 711 | fimd_shadow_protect_win(ctx, i, false); |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 712 | } |
| 713 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 714 | static void fimd_update_plane(struct exynos_drm_crtc *crtc, |
| 715 | struct exynos_drm_plane *plane) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 716 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 717 | struct exynos_drm_plane_state *state = |
| 718 | to_exynos_plane_state(plane->base.state); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 719 | struct fimd_context *ctx = crtc->ctx; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 720 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 721 | dma_addr_t dma_addr; |
| 722 | unsigned long val, size, offset; |
| 723 | unsigned int last_x, last_y, buf_offsize, line_size; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 724 | unsigned int win = plane->index; |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 725 | unsigned int bpp = fb->bits_per_pixel >> 3; |
| 726 | unsigned int pitch = fb->pitches[0]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 727 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 728 | if (ctx->suspended) |
| 729 | return; |
| 730 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 731 | offset = state->src.x * bpp; |
| 732 | offset += state->src.y * pitch; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 733 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 734 | /* buffer start address */ |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 735 | dma_addr = exynos_drm_fb_dma_addr(fb, 0) + offset; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 736 | val = (unsigned long)dma_addr; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 737 | writel(val, ctx->regs + VIDWx_BUF_START(win, 0)); |
| 738 | |
| 739 | /* buffer end address */ |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 740 | size = pitch * state->crtc.h; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 741 | val = (unsigned long)(dma_addr + size); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 742 | 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 Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 745 | (unsigned long)dma_addr, val, size); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 746 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 747 | state->crtc.w, state->crtc.h); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 748 | |
| 749 | /* buffer size */ |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 750 | buf_offsize = pitch - (state->crtc.w * bpp); |
| 751 | line_size = state->crtc.w * bpp; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 752 | 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 756 | writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0)); |
| 757 | |
| 758 | /* OSD position */ |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 759 | 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 763 | writel(val, ctx->regs + VIDOSD_A(win)); |
| 764 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 765 | last_x = state->crtc.x + state->crtc.w; |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 766 | if (last_x) |
| 767 | last_x--; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 768 | last_y = state->crtc.y + state->crtc.h; |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 769 | if (last_y) |
| 770 | last_y--; |
| 771 | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 772 | 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 Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 775 | writel(val, ctx->regs + VIDOSD_B(win)); |
| 776 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 777 | DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 778 | state->crtc.x, state->crtc.y, last_x, last_y); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 779 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 780 | /* OSD size */ |
| 781 | if (win != 3 && win != 4) { |
| 782 | u32 offset = VIDOSD_D(win); |
| 783 | if (win == 0) |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 784 | offset = VIDOSD_C(win); |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 785 | val = state->crtc.w * state->crtc.h; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 786 | writel(val, ctx->regs + offset); |
| 787 | |
| 788 | DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val); |
| 789 | } |
| 790 | |
Marek Szyprowski | 8b704d8 | 2015-11-30 14:53:29 +0100 | [diff] [blame] | 791 | fimd_win_set_pixfmt(ctx, win, fb->pixel_format, state->src.w); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 792 | |
| 793 | /* hardware window 0 doesn't support color key. */ |
| 794 | if (win != 0) |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 795 | fimd_win_set_colkey(ctx, win); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 796 | |
YoungJun Cho | f181a54 | 2014-11-17 22:00:10 +0900 | [diff] [blame] | 797 | fimd_enable_video_output(ctx, win, true); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 798 | |
YoungJun Cho | 999d8b3 | 2014-11-17 22:00:11 +0900 | [diff] [blame] | 799 | if (ctx->driver_data->has_shadowcon) |
| 800 | fimd_enable_shadow_channel_path(ctx, win, true); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 801 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 802 | if (ctx->i80_if) |
| 803 | atomic_set(&ctx->win_updated, 1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 804 | } |
| 805 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 806 | static void fimd_disable_plane(struct exynos_drm_crtc *crtc, |
| 807 | struct exynos_drm_plane *plane) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 808 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 809 | struct fimd_context *ctx = crtc->ctx; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 810 | unsigned int win = plane->index; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 811 | |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 812 | if (ctx->suspended) |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 813 | return; |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 814 | |
YoungJun Cho | f181a54 | 2014-11-17 22:00:10 +0900 | [diff] [blame] | 815 | fimd_enable_video_output(ctx, win, false); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 816 | |
YoungJun Cho | 999d8b3 | 2014-11-17 22:00:11 +0900 | [diff] [blame] | 817 | if (ctx->driver_data->has_shadowcon) |
| 818 | fimd_enable_shadow_channel_path(ctx, win, false); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 819 | } |
| 820 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 821 | static void fimd_enable(struct exynos_drm_crtc *crtc) |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 822 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 823 | struct fimd_context *ctx = crtc->ctx; |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 824 | |
| 825 | if (!ctx->suspended) |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 826 | return; |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 827 | |
| 828 | ctx->suspended = false; |
| 829 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 830 | pm_runtime_get_sync(ctx->dev); |
| 831 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 832 | /* if vblank was enabled status, enable it again. */ |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 833 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
| 834 | fimd_enable_vblank(ctx->crtc); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 835 | |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 836 | fimd_commit(ctx->crtc); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 837 | } |
| 838 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 839 | static void fimd_disable(struct exynos_drm_crtc *crtc) |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 840 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 841 | struct fimd_context *ctx = crtc->ctx; |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 842 | int i; |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 843 | |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 844 | if (ctx->suspended) |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 845 | return; |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 846 | |
| 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 Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 852 | for (i = 0; i < WINDOWS_NR; i++) |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 853 | fimd_disable_plane(crtc, &ctx->planes[i]); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 854 | |
Inki Dae | 94ab95a | 2015-06-12 22:19:22 +0900 | [diff] [blame] | 855 | fimd_enable_vblank(crtc); |
| 856 | fimd_wait_for_vblank(crtc); |
| 857 | fimd_disable_vblank(crtc); |
| 858 | |
Joonyoung Shim | b74f14f | 2015-06-12 17:27:16 +0900 | [diff] [blame] | 859 | writel(0, ctx->regs + VIDCON0); |
| 860 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 861 | pm_runtime_put_sync(ctx->dev); |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 862 | ctx->suspended = true; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 863 | } |
| 864 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 865 | static void fimd_trigger(struct device *dev) |
| 866 | { |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 867 | struct fimd_context *ctx = dev_get_drvdata(dev); |
Marek Szyprowski | e1a7b9b | 2016-04-18 17:38:27 +0900 | [diff] [blame] | 868 | const struct fimd_driver_data *driver_data = ctx->driver_data; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 869 | void *timing_base = ctx->regs + driver_data->timing_base; |
| 870 | u32 reg; |
| 871 | |
Joonyoung Shim | 9b67eb7 | 2014-11-17 22:00:08 +0900 | [diff] [blame] | 872 | /* |
YoungJun Cho | 1c905d9 | 2014-11-17 22:00:12 +0900 | [diff] [blame] | 873 | * Skips triggering if in triggering state, because multiple triggering |
| 874 | * requests can cause panel reset. |
| 875 | */ |
Joonyoung Shim | 9b67eb7 | 2014-11-17 22:00:08 +0900 | [diff] [blame] | 876 | if (atomic_read(&ctx->triggering)) |
| 877 | return; |
| 878 | |
YoungJun Cho | 1c905d9 | 2014-11-17 22:00:12 +0900 | [diff] [blame] | 879 | /* Enters triggering mode */ |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 880 | atomic_set(&ctx->triggering, 1); |
| 881 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 882 | reg = readl(timing_base + TRIGCON); |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 883 | reg |= (TRGMODE_ENABLE | SWTRGCMD_ENABLE); |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 884 | writel(reg, timing_base + TRIGCON); |
YoungJun Cho | 87ab85b | 2014-11-17 22:00:13 +0900 | [diff] [blame] | 885 | |
| 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 Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 892 | } |
| 893 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 894 | static void fimd_te_handler(struct exynos_drm_crtc *crtc) |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 895 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 896 | struct fimd_context *ctx = crtc->ctx; |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 897 | u32 trg_type = ctx->driver_data->trg_type; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 898 | |
| 899 | /* Checks the crtc is detached already from encoder */ |
| 900 | if (ctx->pipe < 0 || !ctx->drm_dev) |
| 901 | return; |
| 902 | |
Inki Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 903 | if (trg_type == I80_HW_TRG) |
| 904 | goto out; |
| 905 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 906 | /* |
| 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 Dae | a6f75aa | 2016-04-18 17:54:39 +0900 | [diff] [blame] | 913 | out: |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 914 | /* 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 Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 918 | } |
YoungJun Cho | b301ae2 | 2014-10-01 15:19:10 +0900 | [diff] [blame] | 919 | |
Joonyoung Shim | adf67ab | 2014-11-17 22:00:14 +0900 | [diff] [blame] | 920 | if (test_bit(0, &ctx->irq_flags)) |
Gustavo Padovan | eafd540 | 2015-07-16 12:23:32 -0300 | [diff] [blame] | 921 | drm_crtc_handle_vblank(&ctx->crtc->base); |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 922 | } |
| 923 | |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 924 | static void fimd_dp_clock_enable(struct exynos_drm_clk *clk, bool enable) |
Krzysztof Kozlowski | 48107d7 | 2015-05-07 09:04:44 +0900 | [diff] [blame] | 925 | { |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 926 | 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 Padovan | 3c79fb8 | 2015-09-30 18:40:54 -0300 | [diff] [blame] | 929 | writel(val, ctx->regs + DP_MIE_CLKCON); |
Krzysztof Kozlowski | 48107d7 | 2015-05-07 09:04:44 +0900 | [diff] [blame] | 930 | } |
| 931 | |
Krzysztof Kozlowski | f3aaf76 | 2015-05-07 09:04:45 +0900 | [diff] [blame] | 932 | static const struct exynos_drm_crtc_ops fimd_crtc_ops = { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 933 | .enable = fimd_enable, |
| 934 | .disable = fimd_disable, |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 935 | .commit = fimd_commit, |
| 936 | .enable_vblank = fimd_enable_vblank, |
| 937 | .disable_vblank = fimd_disable_vblank, |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 938 | .atomic_begin = fimd_atomic_begin, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 939 | .update_plane = fimd_update_plane, |
| 940 | .disable_plane = fimd_disable_plane, |
Gustavo Padovan | ce3ff36 | 2015-08-15 13:26:13 -0300 | [diff] [blame] | 941 | .atomic_flush = fimd_atomic_flush, |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 942 | .te_handler = fimd_te_handler, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 943 | }; |
| 944 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 945 | static irqreturn_t fimd_irq_handler(int irq, void *dev_id) |
| 946 | { |
| 947 | struct fimd_context *ctx = (struct fimd_context *)dev_id; |
Gustavo Padovan | cb11b3f | 2015-08-15 13:26:16 -0300 | [diff] [blame] | 948 | u32 val, clear_bit, start, start_s; |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 949 | int win; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 950 | |
| 951 | val = readl(ctx->regs + VIDINTCON1); |
| 952 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 953 | clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; |
| 954 | if (val & clear_bit) |
| 955 | writel(clear_bit, ctx->regs + VIDINTCON1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 956 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 957 | /* check the crtc is detached already from encoder */ |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 958 | if (ctx->pipe < 0 || !ctx->drm_dev) |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 959 | goto out; |
Inki Dae | 483b88f | 2011-11-11 21:28:00 +0900 | [diff] [blame] | 960 | |
Gustavo Padovan | fc75f71 | 2015-08-15 13:26:11 -0300 | [diff] [blame] | 961 | if (!ctx->i80_if) |
| 962 | drm_crtc_handle_vblank(&ctx->crtc->base); |
Joonyoung Shim | adf67ab | 2014-11-17 22:00:14 +0900 | [diff] [blame] | 963 | |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 964 | 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 Padovan | cb11b3f | 2015-08-15 13:26:16 -0300 | [diff] [blame] | 970 | 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 Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 974 | } |
Gustavo Padovan | fc75f71 | 2015-08-15 13:26:11 -0300 | [diff] [blame] | 975 | |
| 976 | if (ctx->i80_if) { |
YoungJun Cho | 1c905d9 | 2014-11-17 22:00:12 +0900 | [diff] [blame] | 977 | /* Exits triggering mode */ |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 978 | atomic_set(&ctx->triggering, 0); |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 979 | } else { |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 980 | /* 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 K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 985 | } |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 986 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 987 | out: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 988 | return IRQ_HANDLED; |
| 989 | } |
| 990 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 991 | static int fimd_bind(struct device *dev, struct device *master, void *data) |
Andrzej Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 992 | { |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 993 | struct fimd_context *ctx = dev_get_drvdata(dev); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 994 | struct drm_device *drm_dev = data; |
Hyungwon Hwang | cdbfca8 | 2015-03-12 13:36:02 +0900 | [diff] [blame] | 995 | struct exynos_drm_private *priv = drm_dev->dev_private; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 996 | struct exynos_drm_plane *exynos_plane; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 997 | unsigned int i; |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 998 | int ret; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 999 | |
Hyungwon Hwang | cdbfca8 | 2015-03-12 13:36:02 +0900 | [diff] [blame] | 1000 | ctx->drm_dev = drm_dev; |
| 1001 | ctx->pipe = priv->pipe++; |
Ajay Kumar | efa75bc | 2015-01-12 01:57:07 +0900 | [diff] [blame] | 1002 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 1003 | 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 Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 1008 | ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 1009 | 1 << ctx->pipe, &ctx->configs[i]); |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 1010 | if (ret) |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
Gustavo Padovan | 5d3d099 | 2015-10-12 22:07:48 +0900 | [diff] [blame] | 1014 | exynos_plane = &ctx->planes[DEFAULT_WIN]; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 1015 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
| 1016 | ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, |
Joonyoung Shim | 0f04cf8 | 2015-01-30 16:43:01 +0900 | [diff] [blame] | 1017 | &fimd_crtc_ops, ctx); |
Hyungwon Hwang | d122284 | 2015-04-07 22:19:43 +0900 | [diff] [blame] | 1018 | if (IS_ERR(ctx->crtc)) |
| 1019 | return PTR_ERR(ctx->crtc); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1020 | |
Andrzej Hajda | 196e059 | 2016-04-30 01:39:08 +0900 | [diff] [blame] | 1021 | 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 Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 1026 | if (ctx->encoder) |
Gustavo Padovan | a2986e8 | 2015-08-05 20:24:20 -0300 | [diff] [blame] | 1027 | exynos_dpi_bind(drm_dev, ctx->encoder); |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1028 | |
Joonyoung Shim | 43a3b86 | 2015-07-28 17:51:02 +0900 | [diff] [blame] | 1029 | if (is_drm_iommu_supported(drm_dev)) |
| 1030 | fimd_clear_channels(ctx->crtc); |
Joonyoung Shim | eb7a3fc | 2015-07-02 21:49:39 +0900 | [diff] [blame] | 1031 | |
| 1032 | ret = drm_iommu_attach_device(drm_dev, dev); |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 1033 | if (ret) |
| 1034 | priv->pipe--; |
| 1035 | |
| 1036 | return ret; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static void fimd_unbind(struct device *dev, struct device *master, |
| 1040 | void *data) |
| 1041 | { |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1042 | struct fimd_context *ctx = dev_get_drvdata(dev); |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1043 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1044 | fimd_disable(ctx->crtc); |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1045 | |
Joonyoung Shim | bf56608 | 2015-07-02 21:49:38 +0900 | [diff] [blame] | 1046 | drm_iommu_detach_device(ctx->drm_dev, ctx->dev); |
Hyungwon Hwang | cdbfca8 | 2015-03-12 13:36:02 +0900 | [diff] [blame] | 1047 | |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 1048 | if (ctx->encoder) |
| 1049 | exynos_dpi_remove(ctx->encoder); |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static const struct component_ops fimd_component_ops = { |
| 1053 | .bind = fimd_bind, |
| 1054 | .unbind = fimd_unbind, |
| 1055 | }; |
| 1056 | |
| 1057 | static int fimd_probe(struct platform_device *pdev) |
| 1058 | { |
| 1059 | struct device *dev = &pdev->dev; |
| 1060 | struct fimd_context *ctx; |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1061 | struct device_node *i80_if_timings; |
Andrzej Hajda | 000cc92 | 2014-04-03 16:26:00 +0200 | [diff] [blame] | 1062 | struct resource *res; |
Gustavo Padovan | fe42cfb | 2014-11-03 18:56:57 -0200 | [diff] [blame] | 1063 | int ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1064 | |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1065 | if (!dev->of_node) |
| 1066 | return -ENODEV; |
Sachin Kamat | 2d3f173 | 2013-08-28 10:47:58 +0530 | [diff] [blame] | 1067 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1068 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1069 | if (!ctx) |
| 1070 | return -ENOMEM; |
| 1071 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 1072 | ctx->dev = dev; |
Sean Paul | a43b933 | 2014-01-30 16:19:26 -0500 | [diff] [blame] | 1073 | ctx->suspended = true; |
Marek Szyprowski | e1a7b9b | 2016-04-18 17:38:27 +0900 | [diff] [blame] | 1074 | ctx->driver_data = of_device_get_match_data(dev); |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame] | 1075 | |
Sean Paul | 1417f10 | 2014-01-30 16:19:23 -0500 | [diff] [blame] | 1076 | 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 Hajda | 562ad9f | 2013-08-21 16:22:03 +0200 | [diff] [blame] | 1080 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1081 | 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 Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1119 | 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 Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1122 | return PTR_ERR(ctx->bus_clk); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1123 | } |
| 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 Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1128 | return PTR_ERR(ctx->lcd_clk); |
Sean Paul | a968e72 | 2014-01-30 16:19:20 -0500 | [diff] [blame] | 1129 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1130 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1131 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1132 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1133 | ctx->regs = devm_ioremap_resource(dev, res); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1134 | if (IS_ERR(ctx->regs)) |
| 1135 | return PTR_ERR(ctx->regs); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1136 | |
YoungJun Cho | 3854fab | 2014-07-17 18:01:21 +0900 | [diff] [blame] | 1137 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 1138 | ctx->i80_if ? "lcd_sys" : "vsync"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1139 | if (!res) { |
| 1140 | dev_err(dev, "irq request failed.\n"); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1141 | return -ENXIO; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1142 | } |
| 1143 | |
Sean Paul | 055e0c0 | 2014-01-30 16:19:21 -0500 | [diff] [blame] | 1144 | ret = devm_request_irq(dev, res->start, fimd_irq_handler, |
Sachin Kamat | edc5726 | 2012-06-19 11:47:39 +0530 | [diff] [blame] | 1145 | 0, "drm_fimd", ctx); |
| 1146 | if (ret) { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1147 | dev_err(dev, "irq request failed.\n"); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1148 | return ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1149 | } |
| 1150 | |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 1151 | init_waitqueue_head(&ctx->wait_vsync_queue); |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 1152 | atomic_set(&ctx->wait_vsync_event, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1153 | |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1154 | platform_set_drvdata(pdev, ctx); |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 1155 | |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 1156 | ctx->encoder = exynos_dpi_probe(dev); |
| 1157 | if (IS_ERR(ctx->encoder)) |
| 1158 | return PTR_ERR(ctx->encoder); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1159 | |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1160 | pm_runtime_enable(dev); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1161 | |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1162 | ret = component_add(dev, &fimd_component_ops); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1163 | if (ret) |
| 1164 | goto err_disable_pm_runtime; |
| 1165 | |
| 1166 | return ret; |
| 1167 | |
| 1168 | err_disable_pm_runtime: |
Andrzej Hajda | e152dbd | 2014-11-17 09:54:18 +0100 | [diff] [blame] | 1169 | pm_runtime_disable(dev); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1170 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1171 | return ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | static int fimd_remove(struct platform_device *pdev) |
| 1175 | { |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 1176 | pm_runtime_disable(&pdev->dev); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1177 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1178 | component_del(&pdev->dev, &fimd_component_ops); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1179 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
| 1182 | |
Gustavo Padovan | 4157197 | 2015-09-04 17:15:49 -0300 | [diff] [blame] | 1183 | #ifdef CONFIG_PM |
| 1184 | static 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 | |
| 1194 | static 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 | |
| 1215 | static const struct dev_pm_ops exynos_fimd_pm_ops = { |
| 1216 | SET_RUNTIME_PM_OPS(exynos_fimd_suspend, exynos_fimd_resume, NULL) |
| 1217 | }; |
| 1218 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 1219 | struct platform_driver fimd_driver = { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1220 | .probe = fimd_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1221 | .remove = fimd_remove, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1222 | .driver = { |
| 1223 | .name = "exynos4-fb", |
| 1224 | .owner = THIS_MODULE, |
Gustavo Padovan | 4157197 | 2015-09-04 17:15:49 -0300 | [diff] [blame] | 1225 | .pm = &exynos_fimd_pm_ops, |
Sachin Kamat | 2d3f173 | 2013-08-28 10:47:58 +0530 | [diff] [blame] | 1226 | .of_match_table = fimd_driver_dt_match, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1227 | }, |
| 1228 | }; |