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