Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics Co.Ltd |
| 3 | * Authors: |
| 4 | * Seung-Woo Kim <sw0312.kim@samsung.com> |
| 5 | * Inki Dae <inki.dae@samsung.com> |
| 6 | * Joonyoung Shim <jy0922.shim@samsung.com> |
| 7 | * |
| 8 | * Based on drivers/media/video/s5p-tv/mixer_reg.c |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 17 | #include <drm/drmP.h> |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 18 | |
| 19 | #include "regs-mixer.h" |
| 20 | #include "regs-vp.h" |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/wait.h> |
| 25 | #include <linux/i2c.h> |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/irq.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/pm_runtime.h> |
| 31 | #include <linux/clk.h> |
| 32 | #include <linux/regulator/consumer.h> |
Sachin Kamat | 3f1c781 | 2013-08-14 16:38:01 +0530 | [diff] [blame] | 33 | #include <linux/of.h> |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 34 | #include <linux/component.h> |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 35 | |
| 36 | #include <drm/exynos_drm.h> |
| 37 | |
| 38 | #include "exynos_drm_drv.h" |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 39 | #include "exynos_drm_crtc.h" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 40 | #include "exynos_drm_fb.h" |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 41 | #include "exynos_drm_plane.h" |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 42 | #include "exynos_drm_iommu.h" |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 43 | |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 44 | #define MIXER_WIN_NR 3 |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 45 | #define VP_DEFAULT_WIN 2 |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 46 | |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 47 | /* The pixelformats that are natively supported by the mixer. */ |
| 48 | #define MXR_FORMAT_RGB565 4 |
| 49 | #define MXR_FORMAT_ARGB1555 5 |
| 50 | #define MXR_FORMAT_ARGB4444 6 |
| 51 | #define MXR_FORMAT_ARGB8888 7 |
| 52 | |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 53 | struct mixer_resources { |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 54 | int irq; |
| 55 | void __iomem *mixer_regs; |
| 56 | void __iomem *vp_regs; |
| 57 | spinlock_t reg_slock; |
| 58 | struct clk *mixer; |
| 59 | struct clk *vp; |
Marek Szyprowski | 04427ec | 2015-02-02 14:20:28 +0100 | [diff] [blame] | 60 | struct clk *hdmi; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 61 | struct clk *sclk_mixer; |
| 62 | struct clk *sclk_hdmi; |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 63 | struct clk *mout_mixer; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 64 | }; |
| 65 | |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 66 | enum mixer_version_id { |
| 67 | MXR_VER_0_0_0_16, |
| 68 | MXR_VER_16_0_33_0, |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 69 | MXR_VER_128_0_0_184, |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 70 | }; |
| 71 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 72 | enum mixer_flag_bits { |
| 73 | MXR_BIT_POWERED, |
Andrzej Hajda | 0df5e4a | 2015-07-09 08:25:43 +0200 | [diff] [blame] | 74 | MXR_BIT_VSYNC, |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 77 | static const uint32_t mixer_formats[] = { |
| 78 | DRM_FORMAT_XRGB4444, |
Tobias Jakobi | 26a7af3 | 2015-12-16 13:21:47 +0100 | [diff] [blame] | 79 | DRM_FORMAT_ARGB4444, |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 80 | DRM_FORMAT_XRGB1555, |
Tobias Jakobi | 26a7af3 | 2015-12-16 13:21:47 +0100 | [diff] [blame] | 81 | DRM_FORMAT_ARGB1555, |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 82 | DRM_FORMAT_RGB565, |
| 83 | DRM_FORMAT_XRGB8888, |
| 84 | DRM_FORMAT_ARGB8888, |
| 85 | }; |
| 86 | |
| 87 | static const uint32_t vp_formats[] = { |
| 88 | DRM_FORMAT_NV12, |
| 89 | DRM_FORMAT_NV21, |
| 90 | }; |
| 91 | |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 92 | struct mixer_context { |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 93 | struct platform_device *pdev; |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 94 | struct device *dev; |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 95 | struct drm_device *drm_dev; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 96 | struct exynos_drm_crtc *crtc; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 97 | struct exynos_drm_plane planes[MIXER_WIN_NR]; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 98 | int pipe; |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 99 | unsigned long flags; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 100 | bool interlace; |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 101 | bool vp_enabled; |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 102 | bool has_sclk; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 103 | |
| 104 | struct mixer_resources mixer_res; |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 105 | enum mixer_version_id mxr_ver; |
Prathyush K | 6e95d5e | 2012-12-06 20:16:03 +0530 | [diff] [blame] | 106 | wait_queue_head_t wait_vsync_queue; |
| 107 | atomic_t wait_vsync_event; |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct mixer_drv_data { |
| 111 | enum mixer_version_id version; |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 112 | bool is_vp_enabled; |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 113 | bool has_sclk; |
Joonyoung Shim | 22b21ae | 2012-03-15 17:19:04 +0900 | [diff] [blame] | 114 | }; |
| 115 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 116 | static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = { |
| 117 | { |
| 118 | .zpos = 0, |
| 119 | .type = DRM_PLANE_TYPE_PRIMARY, |
| 120 | .pixel_formats = mixer_formats, |
| 121 | .num_pixel_formats = ARRAY_SIZE(mixer_formats), |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 122 | .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE | |
| 123 | EXYNOS_DRM_PLANE_CAP_ZPOS, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 124 | }, { |
| 125 | .zpos = 1, |
| 126 | .type = DRM_PLANE_TYPE_CURSOR, |
| 127 | .pixel_formats = mixer_formats, |
| 128 | .num_pixel_formats = ARRAY_SIZE(mixer_formats), |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 129 | .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE | |
| 130 | EXYNOS_DRM_PLANE_CAP_ZPOS, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 131 | }, { |
| 132 | .zpos = 2, |
| 133 | .type = DRM_PLANE_TYPE_OVERLAY, |
| 134 | .pixel_formats = vp_formats, |
| 135 | .num_pixel_formats = ARRAY_SIZE(vp_formats), |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 136 | .capabilities = EXYNOS_DRM_PLANE_CAP_SCALE | |
| 137 | EXYNOS_DRM_PLANE_CAP_ZPOS, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 138 | }, |
| 139 | }; |
| 140 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 141 | static const u8 filter_y_horiz_tap8[] = { |
| 142 | 0, -1, -1, -1, -1, -1, -1, -1, |
| 143 | -1, -1, -1, -1, -1, 0, 0, 0, |
| 144 | 0, 2, 4, 5, 6, 6, 6, 6, |
| 145 | 6, 5, 5, 4, 3, 2, 1, 1, |
| 146 | 0, -6, -12, -16, -18, -20, -21, -20, |
| 147 | -20, -18, -16, -13, -10, -8, -5, -2, |
| 148 | 127, 126, 125, 121, 114, 107, 99, 89, |
| 149 | 79, 68, 57, 46, 35, 25, 16, 8, |
| 150 | }; |
| 151 | |
| 152 | static const u8 filter_y_vert_tap4[] = { |
| 153 | 0, -3, -6, -8, -8, -8, -8, -7, |
| 154 | -6, -5, -4, -3, -2, -1, -1, 0, |
| 155 | 127, 126, 124, 118, 111, 102, 92, 81, |
| 156 | 70, 59, 48, 37, 27, 19, 11, 5, |
| 157 | 0, 5, 11, 19, 27, 37, 48, 59, |
| 158 | 70, 81, 92, 102, 111, 118, 124, 126, |
| 159 | 0, 0, -1, -1, -2, -3, -4, -5, |
| 160 | -6, -7, -8, -8, -8, -8, -6, -3, |
| 161 | }; |
| 162 | |
| 163 | static const u8 filter_cr_horiz_tap4[] = { |
| 164 | 0, -3, -6, -8, -8, -8, -8, -7, |
| 165 | -6, -5, -4, -3, -2, -1, -1, 0, |
| 166 | 127, 126, 124, 118, 111, 102, 92, 81, |
| 167 | 70, 59, 48, 37, 27, 19, 11, 5, |
| 168 | }; |
| 169 | |
Marek Szyprowski | f657a99 | 2015-12-16 13:21:46 +0100 | [diff] [blame] | 170 | static inline bool is_alpha_format(unsigned int pixel_format) |
| 171 | { |
| 172 | switch (pixel_format) { |
| 173 | case DRM_FORMAT_ARGB8888: |
Tobias Jakobi | 26a7af3 | 2015-12-16 13:21:47 +0100 | [diff] [blame] | 174 | case DRM_FORMAT_ARGB1555: |
| 175 | case DRM_FORMAT_ARGB4444: |
Marek Szyprowski | f657a99 | 2015-12-16 13:21:46 +0100 | [diff] [blame] | 176 | return true; |
| 177 | default: |
| 178 | return false; |
| 179 | } |
| 180 | } |
| 181 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 182 | static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id) |
| 183 | { |
| 184 | return readl(res->vp_regs + reg_id); |
| 185 | } |
| 186 | |
| 187 | static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id, |
| 188 | u32 val) |
| 189 | { |
| 190 | writel(val, res->vp_regs + reg_id); |
| 191 | } |
| 192 | |
| 193 | static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id, |
| 194 | u32 val, u32 mask) |
| 195 | { |
| 196 | u32 old = vp_reg_read(res, reg_id); |
| 197 | |
| 198 | val = (val & mask) | (old & ~mask); |
| 199 | writel(val, res->vp_regs + reg_id); |
| 200 | } |
| 201 | |
| 202 | static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id) |
| 203 | { |
| 204 | return readl(res->mixer_regs + reg_id); |
| 205 | } |
| 206 | |
| 207 | static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id, |
| 208 | u32 val) |
| 209 | { |
| 210 | writel(val, res->mixer_regs + reg_id); |
| 211 | } |
| 212 | |
| 213 | static inline void mixer_reg_writemask(struct mixer_resources *res, |
| 214 | u32 reg_id, u32 val, u32 mask) |
| 215 | { |
| 216 | u32 old = mixer_reg_read(res, reg_id); |
| 217 | |
| 218 | val = (val & mask) | (old & ~mask); |
| 219 | writel(val, res->mixer_regs + reg_id); |
| 220 | } |
| 221 | |
| 222 | static void mixer_regs_dump(struct mixer_context *ctx) |
| 223 | { |
| 224 | #define DUMPREG(reg_id) \ |
| 225 | do { \ |
| 226 | DRM_DEBUG_KMS(#reg_id " = %08x\n", \ |
| 227 | (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \ |
| 228 | } while (0) |
| 229 | |
| 230 | DUMPREG(MXR_STATUS); |
| 231 | DUMPREG(MXR_CFG); |
| 232 | DUMPREG(MXR_INT_EN); |
| 233 | DUMPREG(MXR_INT_STATUS); |
| 234 | |
| 235 | DUMPREG(MXR_LAYER_CFG); |
| 236 | DUMPREG(MXR_VIDEO_CFG); |
| 237 | |
| 238 | DUMPREG(MXR_GRAPHIC0_CFG); |
| 239 | DUMPREG(MXR_GRAPHIC0_BASE); |
| 240 | DUMPREG(MXR_GRAPHIC0_SPAN); |
| 241 | DUMPREG(MXR_GRAPHIC0_WH); |
| 242 | DUMPREG(MXR_GRAPHIC0_SXY); |
| 243 | DUMPREG(MXR_GRAPHIC0_DXY); |
| 244 | |
| 245 | DUMPREG(MXR_GRAPHIC1_CFG); |
| 246 | DUMPREG(MXR_GRAPHIC1_BASE); |
| 247 | DUMPREG(MXR_GRAPHIC1_SPAN); |
| 248 | DUMPREG(MXR_GRAPHIC1_WH); |
| 249 | DUMPREG(MXR_GRAPHIC1_SXY); |
| 250 | DUMPREG(MXR_GRAPHIC1_DXY); |
| 251 | #undef DUMPREG |
| 252 | } |
| 253 | |
| 254 | static void vp_regs_dump(struct mixer_context *ctx) |
| 255 | { |
| 256 | #define DUMPREG(reg_id) \ |
| 257 | do { \ |
| 258 | DRM_DEBUG_KMS(#reg_id " = %08x\n", \ |
| 259 | (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \ |
| 260 | } while (0) |
| 261 | |
| 262 | DUMPREG(VP_ENABLE); |
| 263 | DUMPREG(VP_SRESET); |
| 264 | DUMPREG(VP_SHADOW_UPDATE); |
| 265 | DUMPREG(VP_FIELD_ID); |
| 266 | DUMPREG(VP_MODE); |
| 267 | DUMPREG(VP_IMG_SIZE_Y); |
| 268 | DUMPREG(VP_IMG_SIZE_C); |
| 269 | DUMPREG(VP_PER_RATE_CTRL); |
| 270 | DUMPREG(VP_TOP_Y_PTR); |
| 271 | DUMPREG(VP_BOT_Y_PTR); |
| 272 | DUMPREG(VP_TOP_C_PTR); |
| 273 | DUMPREG(VP_BOT_C_PTR); |
| 274 | DUMPREG(VP_ENDIAN_MODE); |
| 275 | DUMPREG(VP_SRC_H_POSITION); |
| 276 | DUMPREG(VP_SRC_V_POSITION); |
| 277 | DUMPREG(VP_SRC_WIDTH); |
| 278 | DUMPREG(VP_SRC_HEIGHT); |
| 279 | DUMPREG(VP_DST_H_POSITION); |
| 280 | DUMPREG(VP_DST_V_POSITION); |
| 281 | DUMPREG(VP_DST_WIDTH); |
| 282 | DUMPREG(VP_DST_HEIGHT); |
| 283 | DUMPREG(VP_H_RATIO); |
| 284 | DUMPREG(VP_V_RATIO); |
| 285 | |
| 286 | #undef DUMPREG |
| 287 | } |
| 288 | |
| 289 | static inline void vp_filter_set(struct mixer_resources *res, |
| 290 | int reg_id, const u8 *data, unsigned int size) |
| 291 | { |
| 292 | /* assure 4-byte align */ |
| 293 | BUG_ON(size & 3); |
| 294 | for (; size; size -= 4, reg_id += 4, data += 4) { |
| 295 | u32 val = (data[0] << 24) | (data[1] << 16) | |
| 296 | (data[2] << 8) | data[3]; |
| 297 | vp_reg_write(res, reg_id, val); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | static void vp_default_filter(struct mixer_resources *res) |
| 302 | { |
| 303 | vp_filter_set(res, VP_POLY8_Y0_LL, |
Sachin Kamat | e25e1b6 | 2012-08-31 15:50:48 +0530 | [diff] [blame] | 304 | filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 305 | vp_filter_set(res, VP_POLY4_Y0_LL, |
Sachin Kamat | e25e1b6 | 2012-08-31 15:50:48 +0530 | [diff] [blame] | 306 | filter_y_vert_tap4, sizeof(filter_y_vert_tap4)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 307 | vp_filter_set(res, VP_POLY4_C0_LL, |
Sachin Kamat | e25e1b6 | 2012-08-31 15:50:48 +0530 | [diff] [blame] | 308 | filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 309 | } |
| 310 | |
Marek Szyprowski | f657a99 | 2015-12-16 13:21:46 +0100 | [diff] [blame] | 311 | static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win, |
| 312 | bool alpha) |
| 313 | { |
| 314 | struct mixer_resources *res = &ctx->mixer_res; |
| 315 | u32 val; |
| 316 | |
| 317 | val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ |
| 318 | if (alpha) { |
| 319 | /* blending based on pixel alpha */ |
| 320 | val |= MXR_GRP_CFG_BLEND_PRE_MUL; |
| 321 | val |= MXR_GRP_CFG_PIXEL_BLEND_EN; |
| 322 | } |
| 323 | mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), |
| 324 | val, MXR_GRP_CFG_MISC_MASK); |
| 325 | } |
| 326 | |
| 327 | static void mixer_cfg_vp_blend(struct mixer_context *ctx) |
| 328 | { |
| 329 | struct mixer_resources *res = &ctx->mixer_res; |
| 330 | u32 val; |
| 331 | |
| 332 | /* |
| 333 | * No blending at the moment since the NV12/NV21 pixelformats don't |
| 334 | * have an alpha channel. However the mixer supports a global alpha |
| 335 | * value for a layer. Once this functionality is exposed, we can |
| 336 | * support blending of the video layer through this. |
| 337 | */ |
| 338 | val = 0; |
| 339 | mixer_reg_write(res, MXR_VIDEO_CFG, val); |
| 340 | } |
| 341 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 342 | static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) |
| 343 | { |
| 344 | struct mixer_resources *res = &ctx->mixer_res; |
| 345 | |
| 346 | /* block update on vsync */ |
| 347 | mixer_reg_writemask(res, MXR_STATUS, enable ? |
| 348 | MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); |
| 349 | |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 350 | if (ctx->vp_enabled) |
| 351 | vp_reg_write(res, VP_SHADOW_UPDATE, enable ? |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 352 | VP_SHADOW_UPDATE_ENABLE : 0); |
| 353 | } |
| 354 | |
| 355 | static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height) |
| 356 | { |
| 357 | struct mixer_resources *res = &ctx->mixer_res; |
| 358 | u32 val; |
| 359 | |
| 360 | /* choosing between interlace and progressive mode */ |
| 361 | val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE : |
Tobias Jakobi | 1e6d459 | 2015-04-07 01:14:50 +0200 | [diff] [blame] | 362 | MXR_CFG_SCAN_PROGRESSIVE); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 363 | |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 364 | if (ctx->mxr_ver != MXR_VER_128_0_0_184) { |
| 365 | /* choosing between proper HD and SD mode */ |
| 366 | if (height <= 480) |
| 367 | val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; |
| 368 | else if (height <= 576) |
| 369 | val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; |
| 370 | else if (height <= 720) |
| 371 | val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; |
| 372 | else if (height <= 1080) |
| 373 | val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; |
| 374 | else |
| 375 | val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; |
| 376 | } |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 377 | |
| 378 | mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK); |
| 379 | } |
| 380 | |
| 381 | static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) |
| 382 | { |
| 383 | struct mixer_resources *res = &ctx->mixer_res; |
| 384 | u32 val; |
| 385 | |
| 386 | if (height == 480) { |
| 387 | val = MXR_CFG_RGB601_0_255; |
| 388 | } else if (height == 576) { |
| 389 | val = MXR_CFG_RGB601_0_255; |
| 390 | } else if (height == 720) { |
| 391 | val = MXR_CFG_RGB709_16_235; |
| 392 | mixer_reg_write(res, MXR_CM_COEFF_Y, |
| 393 | (1 << 30) | (94 << 20) | (314 << 10) | |
| 394 | (32 << 0)); |
| 395 | mixer_reg_write(res, MXR_CM_COEFF_CB, |
| 396 | (972 << 20) | (851 << 10) | (225 << 0)); |
| 397 | mixer_reg_write(res, MXR_CM_COEFF_CR, |
| 398 | (225 << 20) | (820 << 10) | (1004 << 0)); |
| 399 | } else if (height == 1080) { |
| 400 | val = MXR_CFG_RGB709_16_235; |
| 401 | mixer_reg_write(res, MXR_CM_COEFF_Y, |
| 402 | (1 << 30) | (94 << 20) | (314 << 10) | |
| 403 | (32 << 0)); |
| 404 | mixer_reg_write(res, MXR_CM_COEFF_CB, |
| 405 | (972 << 20) | (851 << 10) | (225 << 0)); |
| 406 | mixer_reg_write(res, MXR_CM_COEFF_CR, |
| 407 | (225 << 20) | (820 << 10) | (1004 << 0)); |
| 408 | } else { |
| 409 | val = MXR_CFG_RGB709_16_235; |
| 410 | mixer_reg_write(res, MXR_CM_COEFF_Y, |
| 411 | (1 << 30) | (94 << 20) | (314 << 10) | |
| 412 | (32 << 0)); |
| 413 | mixer_reg_write(res, MXR_CM_COEFF_CB, |
| 414 | (972 << 20) | (851 << 10) | (225 << 0)); |
| 415 | mixer_reg_write(res, MXR_CM_COEFF_CR, |
| 416 | (225 << 20) | (820 << 10) | (1004 << 0)); |
| 417 | } |
| 418 | |
| 419 | mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); |
| 420 | } |
| 421 | |
Tobias Jakobi | 5b1d5bc | 2015-05-06 14:10:22 +0200 | [diff] [blame] | 422 | static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win, |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 423 | unsigned int priority, bool enable) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 424 | { |
| 425 | struct mixer_resources *res = &ctx->mixer_res; |
| 426 | u32 val = enable ? ~0 : 0; |
| 427 | |
| 428 | switch (win) { |
| 429 | case 0: |
| 430 | mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 431 | mixer_reg_writemask(res, MXR_LAYER_CFG, |
| 432 | MXR_LAYER_CFG_GRP0_VAL(priority), |
| 433 | MXR_LAYER_CFG_GRP0_MASK); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 434 | break; |
| 435 | case 1: |
| 436 | mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 437 | mixer_reg_writemask(res, MXR_LAYER_CFG, |
| 438 | MXR_LAYER_CFG_GRP1_VAL(priority), |
| 439 | MXR_LAYER_CFG_GRP1_MASK); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 440 | break; |
Marek Szyprowski | 5e68fef | 2015-12-16 13:21:48 +0100 | [diff] [blame] | 441 | case VP_DEFAULT_WIN: |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 442 | if (ctx->vp_enabled) { |
| 443 | vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON); |
| 444 | mixer_reg_writemask(res, MXR_CFG, val, |
| 445 | MXR_CFG_VP_ENABLE); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 446 | mixer_reg_writemask(res, MXR_LAYER_CFG, |
| 447 | MXR_LAYER_CFG_VP_VAL(priority), |
| 448 | MXR_LAYER_CFG_VP_MASK); |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 449 | } |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | static void mixer_run(struct mixer_context *ctx) |
| 455 | { |
| 456 | struct mixer_resources *res = &ctx->mixer_res; |
| 457 | |
| 458 | mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 459 | } |
| 460 | |
Rahul Sharma | 381be02 | 2014-06-23 11:02:22 +0530 | [diff] [blame] | 461 | static void mixer_stop(struct mixer_context *ctx) |
| 462 | { |
| 463 | struct mixer_resources *res = &ctx->mixer_res; |
| 464 | int timeout = 20; |
| 465 | |
| 466 | mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN); |
| 467 | |
| 468 | while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) && |
| 469 | --timeout) |
| 470 | usleep_range(10000, 12000); |
Rahul Sharma | 381be02 | 2014-06-23 11:02:22 +0530 | [diff] [blame] | 471 | } |
| 472 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 473 | static void vp_video_buffer(struct mixer_context *ctx, |
| 474 | struct exynos_drm_plane *plane) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 475 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 476 | struct exynos_drm_plane_state *state = |
| 477 | to_exynos_plane_state(plane->base.state); |
Marek Szyprowski | 2ee35d8 | 2015-11-30 14:53:23 +0100 | [diff] [blame] | 478 | struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 479 | struct mixer_resources *res = &ctx->mixer_res; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 480 | struct drm_framebuffer *fb = state->base.fb; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 481 | unsigned long flags; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 482 | dma_addr_t luma_addr[2], chroma_addr[2]; |
| 483 | bool tiled_mode = false; |
| 484 | bool crcb_mode = false; |
| 485 | u32 val; |
| 486 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 487 | switch (fb->pixel_format) { |
Ville Syrjälä | 363b06a | 2012-05-14 11:08:51 +0900 | [diff] [blame] | 488 | case DRM_FORMAT_NV12: |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 489 | crcb_mode = false; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 490 | break; |
Tobias Jakobi | 8f2590f | 2015-04-27 23:10:16 +0200 | [diff] [blame] | 491 | case DRM_FORMAT_NV21: |
| 492 | crcb_mode = true; |
| 493 | break; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 494 | default: |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 495 | DRM_ERROR("pixel format for vp is wrong [%d].\n", |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 496 | fb->pixel_format); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 500 | luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0); |
| 501 | chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 502 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 503 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 504 | ctx->interlace = true; |
| 505 | if (tiled_mode) { |
| 506 | luma_addr[1] = luma_addr[0] + 0x40; |
| 507 | chroma_addr[1] = chroma_addr[0] + 0x40; |
| 508 | } else { |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 509 | luma_addr[1] = luma_addr[0] + fb->pitches[0]; |
| 510 | chroma_addr[1] = chroma_addr[0] + fb->pitches[0]; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 511 | } |
| 512 | } else { |
| 513 | ctx->interlace = false; |
| 514 | luma_addr[1] = 0; |
| 515 | chroma_addr[1] = 0; |
| 516 | } |
| 517 | |
| 518 | spin_lock_irqsave(&res->reg_slock, flags); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 519 | |
| 520 | /* interlace or progressive scan mode */ |
| 521 | val = (ctx->interlace ? ~0 : 0); |
| 522 | vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP); |
| 523 | |
| 524 | /* setup format */ |
| 525 | val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12); |
| 526 | val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); |
| 527 | vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK); |
| 528 | |
| 529 | /* setting size of input image */ |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 530 | vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) | |
| 531 | VP_IMG_VSIZE(fb->height)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 532 | /* chroma height has to reduced by 2 to avoid chroma distorions */ |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 533 | vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) | |
| 534 | VP_IMG_VSIZE(fb->height / 2)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 535 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 536 | vp_reg_write(res, VP_SRC_WIDTH, state->src.w); |
| 537 | vp_reg_write(res, VP_SRC_HEIGHT, state->src.h); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 538 | vp_reg_write(res, VP_SRC_H_POSITION, |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 539 | VP_SRC_H_POSITION_VAL(state->src.x)); |
| 540 | vp_reg_write(res, VP_SRC_V_POSITION, state->src.y); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 541 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 542 | vp_reg_write(res, VP_DST_WIDTH, state->crtc.w); |
| 543 | vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 544 | if (ctx->interlace) { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 545 | vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2); |
| 546 | vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 547 | } else { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 548 | vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h); |
| 549 | vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 550 | } |
| 551 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 552 | vp_reg_write(res, VP_H_RATIO, state->h_ratio); |
| 553 | vp_reg_write(res, VP_V_RATIO, state->v_ratio); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 554 | |
| 555 | vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); |
| 556 | |
| 557 | /* set buffer address to vp */ |
| 558 | vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]); |
| 559 | vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]); |
| 560 | vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]); |
| 561 | vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]); |
| 562 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 563 | mixer_cfg_scan(ctx, mode->vdisplay); |
| 564 | mixer_cfg_rgb_fmt(ctx, mode->vdisplay); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 565 | mixer_cfg_layer(ctx, plane->index, state->zpos + 1, true); |
Marek Szyprowski | f657a99 | 2015-12-16 13:21:46 +0100 | [diff] [blame] | 566 | mixer_cfg_vp_blend(ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 567 | mixer_run(ctx); |
| 568 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 569 | spin_unlock_irqrestore(&res->reg_slock, flags); |
| 570 | |
Tobias Jakobi | c0734fb | 2015-05-06 14:10:21 +0200 | [diff] [blame] | 571 | mixer_regs_dump(ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 572 | vp_regs_dump(ctx); |
| 573 | } |
| 574 | |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 575 | static void mixer_layer_update(struct mixer_context *ctx) |
| 576 | { |
| 577 | struct mixer_resources *res = &ctx->mixer_res; |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 578 | |
Rahul Sharma | 5c0f482 | 2014-06-23 11:02:23 +0530 | [diff] [blame] | 579 | mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE); |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 580 | } |
| 581 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 582 | static void mixer_graph_buffer(struct mixer_context *ctx, |
| 583 | struct exynos_drm_plane *plane) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 584 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 585 | struct exynos_drm_plane_state *state = |
| 586 | to_exynos_plane_state(plane->base.state); |
Marek Szyprowski | 2ee35d8 | 2015-11-30 14:53:23 +0100 | [diff] [blame] | 587 | struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 588 | struct mixer_resources *res = &ctx->mixer_res; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 589 | struct drm_framebuffer *fb = state->base.fb; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 590 | unsigned long flags; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 591 | unsigned int win = plane->index; |
Tobias Jakobi | 2611015 | 2015-04-07 01:14:52 +0200 | [diff] [blame] | 592 | unsigned int x_ratio = 0, y_ratio = 0; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 593 | unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 594 | dma_addr_t dma_addr; |
| 595 | unsigned int fmt; |
| 596 | u32 val; |
| 597 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 598 | switch (fb->pixel_format) { |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 599 | case DRM_FORMAT_XRGB4444: |
Tobias Jakobi | 26a7af3 | 2015-12-16 13:21:47 +0100 | [diff] [blame] | 600 | case DRM_FORMAT_ARGB4444: |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 601 | fmt = MXR_FORMAT_ARGB4444; |
| 602 | break; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 603 | |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 604 | case DRM_FORMAT_XRGB1555: |
Tobias Jakobi | 26a7af3 | 2015-12-16 13:21:47 +0100 | [diff] [blame] | 605 | case DRM_FORMAT_ARGB1555: |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 606 | fmt = MXR_FORMAT_ARGB1555; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 607 | break; |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 608 | |
| 609 | case DRM_FORMAT_RGB565: |
| 610 | fmt = MXR_FORMAT_RGB565; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 611 | break; |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 612 | |
| 613 | case DRM_FORMAT_XRGB8888: |
| 614 | case DRM_FORMAT_ARGB8888: |
| 615 | fmt = MXR_FORMAT_ARGB8888; |
| 616 | break; |
| 617 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 618 | default: |
Tobias Jakobi | 7a57ca7 | 2015-04-27 23:11:59 +0200 | [diff] [blame] | 619 | DRM_DEBUG_KMS("pixelformat unsupported by mixer\n"); |
| 620 | return; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 621 | } |
| 622 | |
Marek Szyprowski | e463b06 | 2015-11-30 14:53:27 +0100 | [diff] [blame] | 623 | /* ratio is already checked by common plane code */ |
| 624 | x_ratio = state->h_ratio == (1 << 15); |
| 625 | y_ratio = state->v_ratio == (1 << 15); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 626 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 627 | dst_x_offset = state->crtc.x; |
| 628 | dst_y_offset = state->crtc.y; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 629 | |
| 630 | /* converting dma address base and source offset */ |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 631 | dma_addr = exynos_drm_fb_dma_addr(fb, 0) |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 632 | + (state->src.x * fb->bits_per_pixel >> 3) |
| 633 | + (state->src.y * fb->pitches[0]); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 634 | src_x_offset = 0; |
| 635 | src_y_offset = 0; |
| 636 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 637 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 638 | ctx->interlace = true; |
| 639 | else |
| 640 | ctx->interlace = false; |
| 641 | |
| 642 | spin_lock_irqsave(&res->reg_slock, flags); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 643 | |
| 644 | /* setup format */ |
| 645 | mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), |
| 646 | MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); |
| 647 | |
| 648 | /* setup geometry */ |
Daniel Stone | adacb22 | 2015-03-17 13:24:58 +0000 | [diff] [blame] | 649 | mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 650 | fb->pitches[0] / (fb->bits_per_pixel >> 3)); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 651 | |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 652 | /* setup display size */ |
| 653 | if (ctx->mxr_ver == MXR_VER_128_0_0_184 && |
Gustavo Padovan | 5d3d099 | 2015-10-12 22:07:48 +0900 | [diff] [blame] | 654 | win == DEFAULT_WIN) { |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 655 | val = MXR_MXR_RES_HEIGHT(mode->vdisplay); |
| 656 | val |= MXR_MXR_RES_WIDTH(mode->hdisplay); |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 657 | mixer_reg_write(res, MXR_RESOLUTION, val); |
| 658 | } |
| 659 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 660 | val = MXR_GRP_WH_WIDTH(state->src.w); |
| 661 | val |= MXR_GRP_WH_HEIGHT(state->src.h); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 662 | val |= MXR_GRP_WH_H_SCALE(x_ratio); |
| 663 | val |= MXR_GRP_WH_V_SCALE(y_ratio); |
| 664 | mixer_reg_write(res, MXR_GRAPHIC_WH(win), val); |
| 665 | |
| 666 | /* setup offsets in source image */ |
| 667 | val = MXR_GRP_SXY_SX(src_x_offset); |
| 668 | val |= MXR_GRP_SXY_SY(src_y_offset); |
| 669 | mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val); |
| 670 | |
| 671 | /* setup offsets in display image */ |
| 672 | val = MXR_GRP_DXY_DX(dst_x_offset); |
| 673 | val |= MXR_GRP_DXY_DY(dst_y_offset); |
| 674 | mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val); |
| 675 | |
| 676 | /* set buffer address to mixer */ |
| 677 | mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr); |
| 678 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 679 | mixer_cfg_scan(ctx, mode->vdisplay); |
| 680 | mixer_cfg_rgb_fmt(ctx, mode->vdisplay); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 681 | mixer_cfg_layer(ctx, win, state->zpos + 1, true); |
Marek Szyprowski | f657a99 | 2015-12-16 13:21:46 +0100 | [diff] [blame] | 682 | mixer_cfg_gfx_blend(ctx, win, is_alpha_format(fb->pixel_format)); |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 683 | |
| 684 | /* layer update mandatory for mixer 16.0.33.0 */ |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 685 | if (ctx->mxr_ver == MXR_VER_16_0_33_0 || |
| 686 | ctx->mxr_ver == MXR_VER_128_0_0_184) |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 687 | mixer_layer_update(ctx); |
| 688 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 689 | mixer_run(ctx); |
| 690 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 691 | spin_unlock_irqrestore(&res->reg_slock, flags); |
Tobias Jakobi | c0734fb | 2015-05-06 14:10:21 +0200 | [diff] [blame] | 692 | |
| 693 | mixer_regs_dump(ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | static void vp_win_reset(struct mixer_context *ctx) |
| 697 | { |
| 698 | struct mixer_resources *res = &ctx->mixer_res; |
| 699 | int tries = 100; |
| 700 | |
| 701 | vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING); |
| 702 | for (tries = 100; tries; --tries) { |
| 703 | /* waiting until VP_SRESET_PROCESSING is 0 */ |
| 704 | if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING) |
| 705 | break; |
Tomasz Stanislawski | 02b3de4 | 2015-09-25 14:48:29 +0200 | [diff] [blame] | 706 | mdelay(10); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 707 | } |
| 708 | WARN(tries == 0, "failed to reset Video Processor\n"); |
| 709 | } |
| 710 | |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 711 | static void mixer_win_reset(struct mixer_context *ctx) |
| 712 | { |
| 713 | struct mixer_resources *res = &ctx->mixer_res; |
| 714 | unsigned long flags; |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 715 | |
| 716 | spin_lock_irqsave(&res->reg_slock, flags); |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 717 | |
| 718 | mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); |
| 719 | |
| 720 | /* set output in RGB888 mode */ |
| 721 | mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); |
| 722 | |
| 723 | /* 16 beat burst in DMA */ |
| 724 | mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST, |
| 725 | MXR_STATUS_BURST_MASK); |
| 726 | |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 727 | /* reset default layer priority */ |
| 728 | mixer_reg_write(res, MXR_LAYER_CFG, 0); |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 729 | |
| 730 | /* setting background color */ |
| 731 | mixer_reg_write(res, MXR_BG_COLOR0, 0x008080); |
| 732 | mixer_reg_write(res, MXR_BG_COLOR1, 0x008080); |
| 733 | mixer_reg_write(res, MXR_BG_COLOR2, 0x008080); |
| 734 | |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 735 | if (ctx->vp_enabled) { |
| 736 | /* configuration of Video Processor Registers */ |
| 737 | vp_win_reset(ctx); |
| 738 | vp_default_filter(res); |
| 739 | } |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 740 | |
| 741 | /* disable all layers */ |
| 742 | mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); |
| 743 | mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 744 | if (ctx->vp_enabled) |
| 745 | mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE); |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 746 | |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 747 | spin_unlock_irqrestore(&res->reg_slock, flags); |
| 748 | } |
| 749 | |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 750 | static irqreturn_t mixer_irq_handler(int irq, void *arg) |
| 751 | { |
| 752 | struct mixer_context *ctx = arg; |
| 753 | struct mixer_resources *res = &ctx->mixer_res; |
| 754 | u32 val, base, shadow; |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 755 | int win; |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 756 | |
| 757 | spin_lock(&res->reg_slock); |
| 758 | |
| 759 | /* read interrupt status for handling and clearing flags for VSYNC */ |
| 760 | val = mixer_reg_read(res, MXR_INT_STATUS); |
| 761 | |
| 762 | /* handling VSYNC */ |
| 763 | if (val & MXR_INT_STATUS_VSYNC) { |
Andrzej Hajda | 81a464d | 2015-07-09 10:07:53 +0200 | [diff] [blame] | 764 | /* vsync interrupt use different bit for read and clear */ |
| 765 | val |= MXR_INT_CLEAR_VSYNC; |
| 766 | val &= ~MXR_INT_STATUS_VSYNC; |
| 767 | |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 768 | /* interlace scan need to check shadow register */ |
| 769 | if (ctx->interlace) { |
| 770 | base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0)); |
| 771 | shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0)); |
| 772 | if (base != shadow) |
| 773 | goto out; |
| 774 | |
| 775 | base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1)); |
| 776 | shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1)); |
| 777 | if (base != shadow) |
| 778 | goto out; |
| 779 | } |
| 780 | |
Gustavo Padovan | eafd540 | 2015-07-16 12:23:32 -0300 | [diff] [blame] | 781 | drm_crtc_handle_vblank(&ctx->crtc->base); |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 782 | for (win = 0 ; win < MIXER_WIN_NR ; win++) { |
| 783 | struct exynos_drm_plane *plane = &ctx->planes[win]; |
| 784 | |
| 785 | if (!plane->pending_fb) |
| 786 | continue; |
| 787 | |
| 788 | exynos_drm_crtc_finish_update(ctx->crtc, plane); |
| 789 | } |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 790 | |
| 791 | /* set wait vsync event to zero and wake up queue. */ |
| 792 | if (atomic_read(&ctx->wait_vsync_event)) { |
| 793 | atomic_set(&ctx->wait_vsync_event, 0); |
| 794 | wake_up(&ctx->wait_vsync_queue); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | out: |
| 799 | /* clear interrupts */ |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 800 | mixer_reg_write(res, MXR_INT_STATUS, val); |
| 801 | |
| 802 | spin_unlock(&res->reg_slock); |
| 803 | |
| 804 | return IRQ_HANDLED; |
| 805 | } |
| 806 | |
| 807 | static int mixer_resources_init(struct mixer_context *mixer_ctx) |
| 808 | { |
| 809 | struct device *dev = &mixer_ctx->pdev->dev; |
| 810 | struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; |
| 811 | struct resource *res; |
| 812 | int ret; |
| 813 | |
| 814 | spin_lock_init(&mixer_res->reg_slock); |
| 815 | |
| 816 | mixer_res->mixer = devm_clk_get(dev, "mixer"); |
| 817 | if (IS_ERR(mixer_res->mixer)) { |
| 818 | dev_err(dev, "failed to get clock 'mixer'\n"); |
| 819 | return -ENODEV; |
| 820 | } |
| 821 | |
Marek Szyprowski | 04427ec | 2015-02-02 14:20:28 +0100 | [diff] [blame] | 822 | mixer_res->hdmi = devm_clk_get(dev, "hdmi"); |
| 823 | if (IS_ERR(mixer_res->hdmi)) { |
| 824 | dev_err(dev, "failed to get clock 'hdmi'\n"); |
| 825 | return PTR_ERR(mixer_res->hdmi); |
| 826 | } |
| 827 | |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 828 | mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi"); |
| 829 | if (IS_ERR(mixer_res->sclk_hdmi)) { |
| 830 | dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); |
| 831 | return -ENODEV; |
| 832 | } |
| 833 | res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0); |
| 834 | if (res == NULL) { |
| 835 | dev_err(dev, "get memory resource failed.\n"); |
| 836 | return -ENXIO; |
| 837 | } |
| 838 | |
| 839 | mixer_res->mixer_regs = devm_ioremap(dev, res->start, |
| 840 | resource_size(res)); |
| 841 | if (mixer_res->mixer_regs == NULL) { |
| 842 | dev_err(dev, "register mapping failed.\n"); |
| 843 | return -ENXIO; |
| 844 | } |
| 845 | |
| 846 | res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0); |
| 847 | if (res == NULL) { |
| 848 | dev_err(dev, "get interrupt resource failed.\n"); |
| 849 | return -ENXIO; |
| 850 | } |
| 851 | |
| 852 | ret = devm_request_irq(dev, res->start, mixer_irq_handler, |
| 853 | 0, "drm_mixer", mixer_ctx); |
| 854 | if (ret) { |
| 855 | dev_err(dev, "request interrupt failed.\n"); |
| 856 | return ret; |
| 857 | } |
| 858 | mixer_res->irq = res->start; |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | static int vp_resources_init(struct mixer_context *mixer_ctx) |
| 864 | { |
| 865 | struct device *dev = &mixer_ctx->pdev->dev; |
| 866 | struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; |
| 867 | struct resource *res; |
| 868 | |
| 869 | mixer_res->vp = devm_clk_get(dev, "vp"); |
| 870 | if (IS_ERR(mixer_res->vp)) { |
| 871 | dev_err(dev, "failed to get clock 'vp'\n"); |
| 872 | return -ENODEV; |
| 873 | } |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 874 | |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 875 | if (mixer_ctx->has_sclk) { |
| 876 | mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer"); |
| 877 | if (IS_ERR(mixer_res->sclk_mixer)) { |
| 878 | dev_err(dev, "failed to get clock 'sclk_mixer'\n"); |
| 879 | return -ENODEV; |
| 880 | } |
| 881 | mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer"); |
| 882 | if (IS_ERR(mixer_res->mout_mixer)) { |
| 883 | dev_err(dev, "failed to get clock 'mout_mixer'\n"); |
| 884 | return -ENODEV; |
| 885 | } |
| 886 | |
| 887 | if (mixer_res->sclk_hdmi && mixer_res->mout_mixer) |
| 888 | clk_set_parent(mixer_res->mout_mixer, |
| 889 | mixer_res->sclk_hdmi); |
| 890 | } |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 891 | |
| 892 | res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1); |
| 893 | if (res == NULL) { |
| 894 | dev_err(dev, "get memory resource failed.\n"); |
| 895 | return -ENXIO; |
| 896 | } |
| 897 | |
| 898 | mixer_res->vp_regs = devm_ioremap(dev, res->start, |
| 899 | resource_size(res)); |
| 900 | if (mixer_res->vp_regs == NULL) { |
| 901 | dev_err(dev, "register mapping failed.\n"); |
| 902 | return -ENXIO; |
| 903 | } |
| 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 908 | static int mixer_initialize(struct mixer_context *mixer_ctx, |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 909 | struct drm_device *drm_dev) |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 910 | { |
| 911 | int ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 912 | struct exynos_drm_private *priv; |
| 913 | priv = drm_dev->dev_private; |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 914 | |
Gustavo Padovan | eb88e42 | 2014-11-26 16:43:27 -0200 | [diff] [blame] | 915 | mixer_ctx->drm_dev = drm_dev; |
Gustavo Padovan | 8a326ed | 2014-11-04 18:44:47 -0200 | [diff] [blame] | 916 | mixer_ctx->pipe = priv->pipe++; |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 917 | |
| 918 | /* acquire resources: regs, irqs, clocks */ |
| 919 | ret = mixer_resources_init(mixer_ctx); |
| 920 | if (ret) { |
| 921 | DRM_ERROR("mixer_resources_init failed ret=%d\n", ret); |
| 922 | return ret; |
| 923 | } |
| 924 | |
| 925 | if (mixer_ctx->vp_enabled) { |
| 926 | /* acquire vp resources: regs, irqs, clocks */ |
| 927 | ret = vp_resources_init(mixer_ctx); |
| 928 | if (ret) { |
| 929 | DRM_ERROR("vp_resources_init failed ret=%d\n", ret); |
| 930 | return ret; |
| 931 | } |
| 932 | } |
| 933 | |
Joonyoung Shim | eb7a3fc | 2015-07-02 21:49:39 +0900 | [diff] [blame] | 934 | ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev); |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 935 | if (ret) |
| 936 | priv->pipe--; |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 937 | |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 938 | return ret; |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 939 | } |
| 940 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 941 | static void mixer_ctx_remove(struct mixer_context *mixer_ctx) |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 942 | { |
Joonyoung Shim | bf56608 | 2015-07-02 21:49:38 +0900 | [diff] [blame] | 943 | drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev); |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 944 | } |
| 945 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 946 | static int mixer_enable_vblank(struct exynos_drm_crtc *crtc) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 947 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 948 | struct mixer_context *mixer_ctx = crtc->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 949 | struct mixer_resources *res = &mixer_ctx->mixer_res; |
| 950 | |
Andrzej Hajda | 0df5e4a | 2015-07-09 08:25:43 +0200 | [diff] [blame] | 951 | __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); |
| 952 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 953 | return 0; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 954 | |
| 955 | /* enable vsync interrupt */ |
Andrzej Hajda | fc073248 | 2015-07-09 08:25:40 +0200 | [diff] [blame] | 956 | mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); |
| 957 | mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 962 | static void mixer_disable_vblank(struct exynos_drm_crtc *crtc) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 963 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 964 | struct mixer_context *mixer_ctx = crtc->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 965 | struct mixer_resources *res = &mixer_ctx->mixer_res; |
| 966 | |
Andrzej Hajda | 0df5e4a | 2015-07-09 08:25:43 +0200 | [diff] [blame] | 967 | __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); |
| 968 | |
| 969 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
Andrzej Hajda | 947710c | 2015-07-09 08:25:41 +0200 | [diff] [blame] | 970 | return; |
Andrzej Hajda | 947710c | 2015-07-09 08:25:41 +0200 | [diff] [blame] | 971 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 972 | /* disable vsync interrupt */ |
Andrzej Hajda | fc073248 | 2015-07-09 08:25:40 +0200 | [diff] [blame] | 973 | mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 974 | mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); |
| 975 | } |
| 976 | |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 977 | static void mixer_atomic_begin(struct exynos_drm_crtc *crtc) |
| 978 | { |
| 979 | struct mixer_context *mixer_ctx = crtc->ctx; |
| 980 | |
| 981 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
| 982 | return; |
| 983 | |
| 984 | mixer_vsync_set_update(mixer_ctx, false); |
| 985 | } |
| 986 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 987 | static void mixer_update_plane(struct exynos_drm_crtc *crtc, |
| 988 | struct exynos_drm_plane *plane) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 989 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 990 | struct mixer_context *mixer_ctx = crtc->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 991 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 992 | DRM_DEBUG_KMS("win: %d\n", plane->index); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 993 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 994 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
Shirish S | dda9012 | 2013-01-23 22:03:18 -0500 | [diff] [blame] | 995 | return; |
Shirish S | dda9012 | 2013-01-23 22:03:18 -0500 | [diff] [blame] | 996 | |
Marek Szyprowski | 5e68fef | 2015-12-16 13:21:48 +0100 | [diff] [blame] | 997 | if (plane->index == VP_DEFAULT_WIN) |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 998 | vp_video_buffer(mixer_ctx, plane); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 999 | else |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 1000 | mixer_graph_buffer(mixer_ctx, plane); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1001 | } |
| 1002 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 1003 | static void mixer_disable_plane(struct exynos_drm_crtc *crtc, |
| 1004 | struct exynos_drm_plane *plane) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1005 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1006 | struct mixer_context *mixer_ctx = crtc->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1007 | struct mixer_resources *res = &mixer_ctx->mixer_res; |
| 1008 | unsigned long flags; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1009 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 1010 | DRM_DEBUG_KMS("win: %d\n", plane->index); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1011 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 1012 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1013 | return; |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1014 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1015 | spin_lock_irqsave(&res->reg_slock, flags); |
Marek Szyprowski | a2cb911 | 2015-12-16 13:21:44 +0100 | [diff] [blame] | 1016 | mixer_cfg_layer(mixer_ctx, plane->index, 0, false); |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 1017 | spin_unlock_irqrestore(&res->reg_slock, flags); |
| 1018 | } |
| 1019 | |
| 1020 | static void mixer_atomic_flush(struct exynos_drm_crtc *crtc) |
| 1021 | { |
| 1022 | struct mixer_context *mixer_ctx = crtc->ctx; |
| 1023 | |
| 1024 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
| 1025 | return; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1026 | |
| 1027 | mixer_vsync_set_update(mixer_ctx, true); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1028 | } |
| 1029 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1030 | static void mixer_wait_for_vblank(struct exynos_drm_crtc *crtc) |
Rahul Sharma | 0ea6822 | 2013-01-15 08:11:06 -0500 | [diff] [blame] | 1031 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1032 | struct mixer_context *mixer_ctx = crtc->ctx; |
Joonyoung Shim | 7c4c558 | 2015-01-18 17:48:29 +0900 | [diff] [blame] | 1033 | int err; |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 1034 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 1035 | if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) |
Prathyush K | 6e95d5e | 2012-12-06 20:16:03 +0530 | [diff] [blame] | 1036 | return; |
Prathyush K | 6e95d5e | 2012-12-06 20:16:03 +0530 | [diff] [blame] | 1037 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1038 | err = drm_vblank_get(mixer_ctx->drm_dev, mixer_ctx->pipe); |
Joonyoung Shim | 7c4c558 | 2015-01-18 17:48:29 +0900 | [diff] [blame] | 1039 | if (err < 0) { |
| 1040 | DRM_DEBUG_KMS("failed to acquire vblank counter\n"); |
| 1041 | return; |
| 1042 | } |
Rahul Sharma | 5d39b9e | 2014-06-23 11:02:25 +0530 | [diff] [blame] | 1043 | |
Prathyush K | 6e95d5e | 2012-12-06 20:16:03 +0530 | [diff] [blame] | 1044 | atomic_set(&mixer_ctx->wait_vsync_event, 1); |
| 1045 | |
| 1046 | /* |
| 1047 | * wait for MIXER to signal VSYNC interrupt or return after |
| 1048 | * timeout which is set to 50ms (refresh rate of 20). |
| 1049 | */ |
| 1050 | if (!wait_event_timeout(mixer_ctx->wait_vsync_queue, |
| 1051 | !atomic_read(&mixer_ctx->wait_vsync_event), |
Daniel Vetter | bfd8303 | 2013-12-11 11:34:41 +0100 | [diff] [blame] | 1052 | HZ/20)) |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 1053 | DRM_DEBUG_KMS("vblank wait timed out.\n"); |
Rahul Sharma | 5d39b9e | 2014-06-23 11:02:25 +0530 | [diff] [blame] | 1054 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1055 | drm_vblank_put(mixer_ctx->drm_dev, mixer_ctx->pipe); |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 1056 | } |
| 1057 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1058 | static void mixer_enable(struct exynos_drm_crtc *crtc) |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1059 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1060 | struct mixer_context *ctx = crtc->ctx; |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1061 | struct mixer_resources *res = &ctx->mixer_res; |
| 1062 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 1063 | if (test_bit(MXR_BIT_POWERED, &ctx->flags)) |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1064 | return; |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1065 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 1066 | pm_runtime_get_sync(ctx->dev); |
| 1067 | |
Andrzej Hajda | a121d17 | 2016-03-23 14:26:01 +0100 | [diff] [blame^] | 1068 | exynos_drm_pipe_clk_enable(crtc, true); |
| 1069 | |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 1070 | mixer_vsync_set_update(ctx, false); |
| 1071 | |
Rahul Sharma | d74ed93 | 2014-06-23 11:02:24 +0530 | [diff] [blame] | 1072 | mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET); |
| 1073 | |
Andrzej Hajda | 0df5e4a | 2015-07-09 08:25:43 +0200 | [diff] [blame] | 1074 | if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) { |
Andrzej Hajda | fc073248 | 2015-07-09 08:25:40 +0200 | [diff] [blame] | 1075 | mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); |
Andrzej Hajda | 0df5e4a | 2015-07-09 08:25:43 +0200 | [diff] [blame] | 1076 | mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); |
| 1077 | } |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1078 | mixer_win_reset(ctx); |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1079 | |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 1080 | mixer_vsync_set_update(ctx, true); |
| 1081 | |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1082 | set_bit(MXR_BIT_POWERED, &ctx->flags); |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1083 | } |
| 1084 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1085 | static void mixer_disable(struct exynos_drm_crtc *crtc) |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1086 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1087 | struct mixer_context *ctx = crtc->ctx; |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 1088 | int i; |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1089 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 1090 | if (!test_bit(MXR_BIT_POWERED, &ctx->flags)) |
Rahul Sharma | b4bfa3c | 2014-06-23 11:02:21 +0530 | [diff] [blame] | 1091 | return; |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1092 | |
Rahul Sharma | 381be02 | 2014-06-23 11:02:22 +0530 | [diff] [blame] | 1093 | mixer_stop(ctx); |
Tobias Jakobi | c0734fb | 2015-05-06 14:10:21 +0200 | [diff] [blame] | 1094 | mixer_regs_dump(ctx); |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 1095 | |
| 1096 | for (i = 0; i < MIXER_WIN_NR; i++) |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 1097 | mixer_disable_plane(crtc, &ctx->planes[i]); |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1098 | |
Andrzej Hajda | a121d17 | 2016-03-23 14:26:01 +0100 | [diff] [blame^] | 1099 | exynos_drm_pipe_clk_enable(crtc, false); |
| 1100 | |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1101 | pm_runtime_put(ctx->dev); |
| 1102 | |
Andrzej Hajda | a44652e | 2015-07-09 08:25:42 +0200 | [diff] [blame] | 1103 | clear_bit(MXR_BIT_POWERED, &ctx->flags); |
Prathyush K | db43fd1 | 2012-12-06 20:16:05 +0530 | [diff] [blame] | 1104 | } |
| 1105 | |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1106 | /* Only valid for Mixer version 16.0.33.0 */ |
Andrzej Hajda | 3ae2436 | 2015-10-26 13:03:40 +0100 | [diff] [blame] | 1107 | static int mixer_atomic_check(struct exynos_drm_crtc *crtc, |
| 1108 | struct drm_crtc_state *state) |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1109 | { |
Andrzej Hajda | 3ae2436 | 2015-10-26 13:03:40 +0100 | [diff] [blame] | 1110 | struct drm_display_mode *mode = &state->adjusted_mode; |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1111 | u32 w, h; |
| 1112 | |
| 1113 | w = mode->hdisplay; |
| 1114 | h = mode->vdisplay; |
| 1115 | |
| 1116 | DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", |
| 1117 | mode->hdisplay, mode->vdisplay, mode->vrefresh, |
| 1118 | (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0); |
| 1119 | |
| 1120 | if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) || |
| 1121 | (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) || |
| 1122 | (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080)) |
| 1123 | return 0; |
| 1124 | |
| 1125 | return -EINVAL; |
| 1126 | } |
| 1127 | |
Krzysztof Kozlowski | f3aaf76 | 2015-05-07 09:04:45 +0900 | [diff] [blame] | 1128 | static const struct exynos_drm_crtc_ops mixer_crtc_ops = { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 1129 | .enable = mixer_enable, |
| 1130 | .disable = mixer_disable, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1131 | .enable_vblank = mixer_enable_vblank, |
| 1132 | .disable_vblank = mixer_disable_vblank, |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 1133 | .wait_for_vblank = mixer_wait_for_vblank, |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 1134 | .atomic_begin = mixer_atomic_begin, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 1135 | .update_plane = mixer_update_plane, |
| 1136 | .disable_plane = mixer_disable_plane, |
Marek Szyprowski | 3dbaab1 | 2016-01-05 13:52:52 +0100 | [diff] [blame] | 1137 | .atomic_flush = mixer_atomic_flush, |
Andrzej Hajda | 3ae2436 | 2015-10-26 13:03:40 +0100 | [diff] [blame] | 1138 | .atomic_check = mixer_atomic_check, |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1139 | }; |
Rahul Sharma | 0ea6822 | 2013-01-15 08:11:06 -0500 | [diff] [blame] | 1140 | |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 1141 | static struct mixer_drv_data exynos5420_mxr_drv_data = { |
| 1142 | .version = MXR_VER_128_0_0_184, |
| 1143 | .is_vp_enabled = 0, |
| 1144 | }; |
| 1145 | |
Rahul Sharma | cc57caf | 2013-06-19 18:21:07 +0530 | [diff] [blame] | 1146 | static struct mixer_drv_data exynos5250_mxr_drv_data = { |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1147 | .version = MXR_VER_16_0_33_0, |
| 1148 | .is_vp_enabled = 0, |
| 1149 | }; |
| 1150 | |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 1151 | static struct mixer_drv_data exynos4212_mxr_drv_data = { |
| 1152 | .version = MXR_VER_0_0_0_16, |
| 1153 | .is_vp_enabled = 1, |
| 1154 | }; |
| 1155 | |
Rahul Sharma | cc57caf | 2013-06-19 18:21:07 +0530 | [diff] [blame] | 1156 | static struct mixer_drv_data exynos4210_mxr_drv_data = { |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1157 | .version = MXR_VER_0_0_0_16, |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 1158 | .is_vp_enabled = 1, |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 1159 | .has_sclk = 1, |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1160 | }; |
| 1161 | |
Krzysztof Kozlowski | d6b1630 | 2015-05-02 00:56:36 +0900 | [diff] [blame] | 1162 | static const struct platform_device_id mixer_driver_types[] = { |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1163 | { |
| 1164 | .name = "s5p-mixer", |
Rahul Sharma | cc57caf | 2013-06-19 18:21:07 +0530 | [diff] [blame] | 1165 | .driver_data = (unsigned long)&exynos4210_mxr_drv_data, |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1166 | }, { |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1167 | .name = "exynos5-mixer", |
Rahul Sharma | cc57caf | 2013-06-19 18:21:07 +0530 | [diff] [blame] | 1168 | .driver_data = (unsigned long)&exynos5250_mxr_drv_data, |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1169 | }, { |
| 1170 | /* end node */ |
| 1171 | } |
| 1172 | }; |
| 1173 | |
| 1174 | static struct of_device_id mixer_match_types[] = { |
| 1175 | { |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 1176 | .compatible = "samsung,exynos4210-mixer", |
| 1177 | .data = &exynos4210_mxr_drv_data, |
| 1178 | }, { |
| 1179 | .compatible = "samsung,exynos4212-mixer", |
| 1180 | .data = &exynos4212_mxr_drv_data, |
| 1181 | }, { |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1182 | .compatible = "samsung,exynos5-mixer", |
Rahul Sharma | cc57caf | 2013-06-19 18:21:07 +0530 | [diff] [blame] | 1183 | .data = &exynos5250_mxr_drv_data, |
| 1184 | }, { |
| 1185 | .compatible = "samsung,exynos5250-mixer", |
| 1186 | .data = &exynos5250_mxr_drv_data, |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1187 | }, { |
Rahul Sharma | def5e09 | 2013-06-19 18:21:08 +0530 | [diff] [blame] | 1188 | .compatible = "samsung,exynos5420-mixer", |
| 1189 | .data = &exynos5420_mxr_drv_data, |
| 1190 | }, { |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1191 | /* end node */ |
| 1192 | } |
| 1193 | }; |
Sjoerd Simons | 39b58a3 | 2014-07-18 22:36:41 +0200 | [diff] [blame] | 1194 | MODULE_DEVICE_TABLE(of, mixer_match_types); |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1195 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1196 | static int mixer_bind(struct device *dev, struct device *manager, void *data) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1197 | { |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1198 | struct mixer_context *ctx = dev_get_drvdata(dev); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1199 | struct drm_device *drm_dev = data; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 1200 | struct exynos_drm_plane *exynos_plane; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 1201 | unsigned int i; |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 1202 | int ret; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1203 | |
Alban Browaeys | e2dc3f7 | 2015-01-29 22:18:40 +0100 | [diff] [blame] | 1204 | ret = mixer_initialize(ctx, drm_dev); |
| 1205 | if (ret) |
| 1206 | return ret; |
| 1207 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 1208 | for (i = 0; i < MIXER_WIN_NR; i++) { |
| 1209 | if (i == VP_DEFAULT_WIN && !ctx->vp_enabled) |
Marek Szyprowski | ab14420 | 2015-11-30 14:53:24 +0100 | [diff] [blame] | 1210 | continue; |
| 1211 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 1212 | ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 1213 | 1 << ctx->pipe, &plane_configs[i]); |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 1214 | if (ret) |
| 1215 | return ret; |
| 1216 | } |
| 1217 | |
Gustavo Padovan | 5d3d099 | 2015-10-12 22:07:48 +0900 | [diff] [blame] | 1218 | exynos_plane = &ctx->planes[DEFAULT_WIN]; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 1219 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
| 1220 | ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI, |
| 1221 | &mixer_crtc_ops, ctx); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1222 | if (IS_ERR(ctx->crtc)) { |
Alban Browaeys | e2dc3f7 | 2015-01-29 22:18:40 +0100 | [diff] [blame] | 1223 | mixer_ctx_remove(ctx); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1224 | ret = PTR_ERR(ctx->crtc); |
| 1225 | goto free_ctx; |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1226 | } |
| 1227 | |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1228 | return 0; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1229 | |
| 1230 | free_ctx: |
| 1231 | devm_kfree(dev, ctx); |
| 1232 | return ret; |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | static void mixer_unbind(struct device *dev, struct device *master, void *data) |
| 1236 | { |
| 1237 | struct mixer_context *ctx = dev_get_drvdata(dev); |
| 1238 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 1239 | mixer_ctx_remove(ctx); |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static const struct component_ops mixer_component_ops = { |
| 1243 | .bind = mixer_bind, |
| 1244 | .unbind = mixer_unbind, |
| 1245 | }; |
| 1246 | |
| 1247 | static int mixer_probe(struct platform_device *pdev) |
| 1248 | { |
| 1249 | struct device *dev = &pdev->dev; |
| 1250 | struct mixer_drv_data *drv; |
| 1251 | struct mixer_context *ctx; |
| 1252 | int ret; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1253 | |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1254 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); |
| 1255 | if (!ctx) { |
| 1256 | DRM_ERROR("failed to alloc mixer context.\n"); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1257 | return -ENOMEM; |
Sean Paul | f041b25 | 2014-01-30 16:19:15 -0500 | [diff] [blame] | 1258 | } |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1259 | |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1260 | if (dev->of_node) { |
| 1261 | const struct of_device_id *match; |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1262 | |
Sachin Kamat | e436b09 | 2013-06-05 16:00:23 +0900 | [diff] [blame] | 1263 | match = of_match_node(mixer_match_types, dev->of_node); |
Rahul Sharma | 2cdc53b | 2012-10-31 09:36:26 +0530 | [diff] [blame] | 1264 | drv = (struct mixer_drv_data *)match->data; |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1265 | } else { |
| 1266 | drv = (struct mixer_drv_data *) |
| 1267 | platform_get_device_id(pdev)->driver_data; |
| 1268 | } |
| 1269 | |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 1270 | ctx->pdev = pdev; |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1271 | ctx->dev = dev; |
Rahul Sharma | 1b8e574 | 2012-10-04 20:48:52 +0530 | [diff] [blame] | 1272 | ctx->vp_enabled = drv->is_vp_enabled; |
Marek Szyprowski | ff830c9 | 2014-07-01 10:10:07 +0200 | [diff] [blame] | 1273 | ctx->has_sclk = drv->has_sclk; |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1274 | ctx->mxr_ver = drv->version; |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 1275 | init_waitqueue_head(&ctx->wait_vsync_queue); |
Prathyush K | 6e95d5e | 2012-12-06 20:16:03 +0530 | [diff] [blame] | 1276 | atomic_set(&ctx->wait_vsync_event, 0); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1277 | |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1278 | platform_set_drvdata(pdev, ctx); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1279 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1280 | ret = component_add(&pdev->dev, &mixer_component_ops); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 1281 | if (!ret) |
| 1282 | pm_runtime_enable(dev); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1283 | |
| 1284 | return ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 1285 | } |
| 1286 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1287 | static int mixer_remove(struct platform_device *pdev) |
| 1288 | { |
Andrzej Hajda | 8103ef1 | 2014-11-24 14:12:46 +0900 | [diff] [blame] | 1289 | pm_runtime_disable(&pdev->dev); |
| 1290 | |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1291 | component_del(&pdev->dev, &mixer_component_ops); |
Inki Dae | df5225b | 2014-05-29 18:28:02 +0900 | [diff] [blame] | 1292 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Arnd Bergmann | e0fea7e | 2015-11-17 16:08:36 +0100 | [diff] [blame] | 1296 | static int __maybe_unused exynos_mixer_suspend(struct device *dev) |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1297 | { |
| 1298 | struct mixer_context *ctx = dev_get_drvdata(dev); |
| 1299 | struct mixer_resources *res = &ctx->mixer_res; |
| 1300 | |
| 1301 | clk_disable_unprepare(res->hdmi); |
| 1302 | clk_disable_unprepare(res->mixer); |
| 1303 | if (ctx->vp_enabled) { |
| 1304 | clk_disable_unprepare(res->vp); |
| 1305 | if (ctx->has_sclk) |
| 1306 | clk_disable_unprepare(res->sclk_mixer); |
| 1307 | } |
| 1308 | |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Arnd Bergmann | e0fea7e | 2015-11-17 16:08:36 +0100 | [diff] [blame] | 1312 | static int __maybe_unused exynos_mixer_resume(struct device *dev) |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1313 | { |
| 1314 | struct mixer_context *ctx = dev_get_drvdata(dev); |
| 1315 | struct mixer_resources *res = &ctx->mixer_res; |
| 1316 | int ret; |
| 1317 | |
| 1318 | ret = clk_prepare_enable(res->mixer); |
| 1319 | if (ret < 0) { |
| 1320 | DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret); |
| 1321 | return ret; |
| 1322 | } |
| 1323 | ret = clk_prepare_enable(res->hdmi); |
| 1324 | if (ret < 0) { |
| 1325 | DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret); |
| 1326 | return ret; |
| 1327 | } |
| 1328 | if (ctx->vp_enabled) { |
| 1329 | ret = clk_prepare_enable(res->vp); |
| 1330 | if (ret < 0) { |
| 1331 | DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n", |
| 1332 | ret); |
| 1333 | return ret; |
| 1334 | } |
| 1335 | if (ctx->has_sclk) { |
| 1336 | ret = clk_prepare_enable(res->sclk_mixer); |
| 1337 | if (ret < 0) { |
| 1338 | DRM_ERROR("Failed to prepare_enable the " \ |
| 1339 | "sclk_mixer clk [%d]\n", |
| 1340 | ret); |
| 1341 | return ret; |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | return 0; |
| 1347 | } |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1348 | |
| 1349 | static const struct dev_pm_ops exynos_mixer_pm_ops = { |
| 1350 | SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL) |
| 1351 | }; |
| 1352 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1353 | struct platform_driver mixer_driver = { |
| 1354 | .driver = { |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1355 | .name = "exynos-mixer", |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1356 | .owner = THIS_MODULE, |
Gustavo Padovan | ccf034a | 2015-09-04 17:15:46 -0300 | [diff] [blame] | 1357 | .pm = &exynos_mixer_pm_ops, |
Rahul Sharma | aaf8b49 | 2012-10-04 20:48:53 +0530 | [diff] [blame] | 1358 | .of_match_table = mixer_match_types, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1359 | }, |
| 1360 | .probe = mixer_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1361 | .remove = mixer_remove, |
Rahul Sharma | 1e12344 | 2012-10-04 20:48:51 +0530 | [diff] [blame] | 1362 | .id_table = mixer_driver_types, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 1363 | }; |