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