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