Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd |
| 3 | * Author:Mark Yao <mark.yao@rock-chips.com> |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <drm/drm.h> |
| 16 | #include <drm/drmP.h> |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 17 | #include <drm/drm_atomic.h> |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 18 | #include <drm/drm_crtc.h> |
| 19 | #include <drm/drm_crtc_helper.h> |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 20 | #include <drm/drm_flip_work.h> |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 21 | #include <drm/drm_plane_helper.h> |
Sean Paul | 6cca386 | 2017-03-06 15:02:26 -0500 | [diff] [blame] | 22 | #ifdef CONFIG_DRM_ANALOGIX_DP |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 23 | #include <drm/bridge/analogix_dp.h> |
Sean Paul | 6cca386 | 2017-03-06 15:02:26 -0500 | [diff] [blame] | 24 | #endif |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 25 | |
| 26 | #include <linux/kernel.h> |
Paul Gortmaker | 00fe614 | 2015-05-01 20:02:30 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/clk.h> |
Tomasz Figa | 7caecdb | 2016-09-14 21:54:56 +0900 | [diff] [blame] | 30 | #include <linux/iopoll.h> |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 31 | #include <linux/of.h> |
| 32 | #include <linux/of_device.h> |
| 33 | #include <linux/pm_runtime.h> |
| 34 | #include <linux/component.h> |
| 35 | |
| 36 | #include <linux/reset.h> |
| 37 | #include <linux/delay.h> |
| 38 | |
| 39 | #include "rockchip_drm_drv.h" |
| 40 | #include "rockchip_drm_gem.h" |
| 41 | #include "rockchip_drm_fb.h" |
Yakir Yang | 5182c1a | 2016-07-24 14:57:44 +0800 | [diff] [blame] | 42 | #include "rockchip_drm_psr.h" |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 43 | #include "rockchip_drm_vop.h" |
| 44 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 45 | #define VOP_WIN_SET(x, win, name, v) \ |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 46 | vop_reg_set(vop, &win->phy->name, win->base, ~0, v, #name) |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 47 | #define VOP_SCL_SET(x, win, name, v) \ |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 48 | vop_reg_set(vop, &win->phy->scl->name, win->base, ~0, v, #name) |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 49 | #define VOP_SCL_SET_EXT(x, win, name, v) \ |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 50 | vop_reg_set(vop, &win->phy->scl->ext->name, \ |
| 51 | win->base, ~0, v, #name) |
Mark yao | ac6560d | 2017-07-26 14:19:19 +0800 | [diff] [blame] | 52 | |
| 53 | #define VOP_INTR_SET_MASK(vop, name, mask, v) \ |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 54 | vop_reg_set(vop, &vop->data->intr->name, 0, mask, v, #name) |
| 55 | |
| 56 | #define VOP_REG_SET(vop, group, name, v) \ |
| 57 | vop_reg_set(vop, &vop->data->group->name, 0, ~0, v, #name) |
Mark yao | ac6560d | 2017-07-26 14:19:19 +0800 | [diff] [blame] | 58 | |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 59 | #define VOP_INTR_SET_TYPE(vop, name, type, v) \ |
| 60 | do { \ |
John Keeping | c7647f8 | 2016-01-12 18:05:18 +0000 | [diff] [blame] | 61 | int i, reg = 0, mask = 0; \ |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 62 | for (i = 0; i < vop->data->intr->nintrs; i++) { \ |
John Keeping | c7647f8 | 2016-01-12 18:05:18 +0000 | [diff] [blame] | 63 | if (vop->data->intr->intrs[i] & type) { \ |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 64 | reg |= (v) << i; \ |
John Keeping | c7647f8 | 2016-01-12 18:05:18 +0000 | [diff] [blame] | 65 | mask |= 1 << i; \ |
| 66 | } \ |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 67 | } \ |
Mark yao | ac6560d | 2017-07-26 14:19:19 +0800 | [diff] [blame] | 68 | VOP_INTR_SET_MASK(vop, name, mask, reg); \ |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 69 | } while (0) |
| 70 | #define VOP_INTR_GET_TYPE(vop, name, type) \ |
| 71 | vop_get_intr_type(vop, &vop->data->intr->name, type) |
| 72 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 73 | #define VOP_WIN_GET(x, win, name) \ |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 74 | vop_read_reg(x, win->offset, win->phy->name) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 75 | |
| 76 | #define VOP_WIN_GET_YRGBADDR(vop, win) \ |
| 77 | vop_readl(vop, win->base + win->phy->yrgb_mst.offset) |
| 78 | |
| 79 | #define to_vop(x) container_of(x, struct vop, crtc) |
| 80 | #define to_vop_win(x) container_of(x, struct vop_win, base) |
| 81 | |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 82 | enum vop_pending { |
| 83 | VOP_PENDING_FB_UNREF, |
| 84 | }; |
| 85 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 86 | struct vop_win { |
| 87 | struct drm_plane base; |
| 88 | const struct vop_win_data *data; |
| 89 | struct vop *vop; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct vop { |
| 93 | struct drm_crtc crtc; |
| 94 | struct device *dev; |
| 95 | struct drm_device *drm_dev; |
Mark Yao | 31e980c | 2015-01-22 14:37:56 +0800 | [diff] [blame] | 96 | bool is_enabled; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 97 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 98 | /* mutex vsync_ work */ |
| 99 | struct mutex vsync_mutex; |
| 100 | bool vsync_work_pending; |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 101 | struct completion dsp_hold_completion; |
Daniel Vetter | 4f9d39a | 2016-06-08 14:19:11 +0200 | [diff] [blame] | 102 | |
| 103 | /* protected by dev->event_lock */ |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 104 | struct drm_pending_vblank_event *event; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 105 | |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 106 | struct drm_flip_work fb_unref_work; |
| 107 | unsigned long pending; |
| 108 | |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 109 | struct completion line_flag_completion; |
| 110 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 111 | const struct vop_data *data; |
| 112 | |
| 113 | uint32_t *regsbak; |
| 114 | void __iomem *regs; |
| 115 | |
| 116 | /* physical map length of vop register */ |
| 117 | uint32_t len; |
| 118 | |
| 119 | /* one time only one process allowed to config the register */ |
| 120 | spinlock_t reg_lock; |
| 121 | /* lock vop irq reg */ |
| 122 | spinlock_t irq_lock; |
| 123 | |
| 124 | unsigned int irq; |
| 125 | |
| 126 | /* vop AHP clk */ |
| 127 | struct clk *hclk; |
| 128 | /* vop dclk */ |
| 129 | struct clk *dclk; |
| 130 | /* vop share memory frequency */ |
| 131 | struct clk *aclk; |
| 132 | |
| 133 | /* vop dclk reset */ |
| 134 | struct reset_control *dclk_rst; |
| 135 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 136 | struct vop_win win[]; |
| 137 | }; |
| 138 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 139 | static inline void vop_writel(struct vop *vop, uint32_t offset, uint32_t v) |
| 140 | { |
| 141 | writel(v, vop->regs + offset); |
| 142 | vop->regsbak[offset >> 2] = v; |
| 143 | } |
| 144 | |
| 145 | static inline uint32_t vop_readl(struct vop *vop, uint32_t offset) |
| 146 | { |
| 147 | return readl(vop->regs + offset); |
| 148 | } |
| 149 | |
| 150 | static inline uint32_t vop_read_reg(struct vop *vop, uint32_t base, |
| 151 | const struct vop_reg *reg) |
| 152 | { |
| 153 | return (vop_readl(vop, base + reg->offset) >> reg->shift) & reg->mask; |
| 154 | } |
| 155 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 156 | static void vop_reg_set(struct vop *vop, const struct vop_reg *reg, |
| 157 | uint32_t _offset, uint32_t _mask, uint32_t v, |
| 158 | const char *reg_name) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 159 | { |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 160 | int offset, mask, shift; |
Mark Yao | d49463e | 2016-04-20 14:18:15 +0800 | [diff] [blame] | 161 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 162 | if (!reg || !reg->mask) { |
| 163 | dev_dbg(vop->dev, "Warning: not support %s\n", reg_name); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | offset = reg->offset + _offset; |
| 168 | mask = reg->mask & _mask; |
| 169 | shift = reg->shift; |
| 170 | |
| 171 | if (reg->write_mask) { |
Mark Yao | d49463e | 2016-04-20 14:18:15 +0800 | [diff] [blame] | 172 | v = ((v << shift) & 0xffff) | (mask << (shift + 16)); |
| 173 | } else { |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 174 | uint32_t cached_val = vop->regsbak[offset >> 2]; |
| 175 | |
Mark Yao | d49463e | 2016-04-20 14:18:15 +0800 | [diff] [blame] | 176 | v = (cached_val & ~(mask << shift)) | ((v & mask) << shift); |
| 177 | vop->regsbak[offset >> 2] = v; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 178 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 179 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 180 | if (reg->relaxed) |
Mark Yao | d49463e | 2016-04-20 14:18:15 +0800 | [diff] [blame] | 181 | writel_relaxed(v, vop->regs + offset); |
| 182 | else |
| 183 | writel(v, vop->regs + offset); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 186 | static inline uint32_t vop_get_intr_type(struct vop *vop, |
| 187 | const struct vop_reg *reg, int type) |
| 188 | { |
| 189 | uint32_t i, ret = 0; |
| 190 | uint32_t regs = vop_read_reg(vop, 0, reg); |
| 191 | |
| 192 | for (i = 0; i < vop->data->intr->nintrs; i++) { |
| 193 | if ((type & vop->data->intr->intrs[i]) && (regs & 1 << i)) |
| 194 | ret |= vop->data->intr->intrs[i]; |
| 195 | } |
| 196 | |
| 197 | return ret; |
| 198 | } |
| 199 | |
Mark Yao | 0cf33fe | 2015-12-14 18:14:36 +0800 | [diff] [blame] | 200 | static inline void vop_cfg_done(struct vop *vop) |
| 201 | { |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 202 | VOP_REG_SET(vop, common, cfg_done, 1); |
Mark Yao | 0cf33fe | 2015-12-14 18:14:36 +0800 | [diff] [blame] | 203 | } |
| 204 | |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 205 | static bool has_rb_swapped(uint32_t format) |
| 206 | { |
| 207 | switch (format) { |
| 208 | case DRM_FORMAT_XBGR8888: |
| 209 | case DRM_FORMAT_ABGR8888: |
| 210 | case DRM_FORMAT_BGR888: |
| 211 | case DRM_FORMAT_BGR565: |
| 212 | return true; |
| 213 | default: |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 218 | static enum vop_data_format vop_convert_format(uint32_t format) |
| 219 | { |
| 220 | switch (format) { |
| 221 | case DRM_FORMAT_XRGB8888: |
| 222 | case DRM_FORMAT_ARGB8888: |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 223 | case DRM_FORMAT_XBGR8888: |
| 224 | case DRM_FORMAT_ABGR8888: |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 225 | return VOP_FMT_ARGB8888; |
| 226 | case DRM_FORMAT_RGB888: |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 227 | case DRM_FORMAT_BGR888: |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 228 | return VOP_FMT_RGB888; |
| 229 | case DRM_FORMAT_RGB565: |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 230 | case DRM_FORMAT_BGR565: |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 231 | return VOP_FMT_RGB565; |
| 232 | case DRM_FORMAT_NV12: |
| 233 | return VOP_FMT_YUV420SP; |
| 234 | case DRM_FORMAT_NV16: |
| 235 | return VOP_FMT_YUV422SP; |
| 236 | case DRM_FORMAT_NV24: |
| 237 | return VOP_FMT_YUV444SP; |
| 238 | default: |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 239 | DRM_ERROR("unsupported format[%08x]\n", format); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 240 | return -EINVAL; |
| 241 | } |
| 242 | } |
| 243 | |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 244 | static bool is_yuv_support(uint32_t format) |
| 245 | { |
| 246 | switch (format) { |
| 247 | case DRM_FORMAT_NV12: |
| 248 | case DRM_FORMAT_NV16: |
| 249 | case DRM_FORMAT_NV24: |
| 250 | return true; |
| 251 | default: |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 256 | static bool is_alpha_support(uint32_t format) |
| 257 | { |
| 258 | switch (format) { |
| 259 | case DRM_FORMAT_ARGB8888: |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 260 | case DRM_FORMAT_ABGR8888: |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 261 | return true; |
| 262 | default: |
| 263 | return false; |
| 264 | } |
| 265 | } |
| 266 | |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 267 | static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src, |
| 268 | uint32_t dst, bool is_horizontal, |
| 269 | int vsu_mode, int *vskiplines) |
| 270 | { |
| 271 | uint16_t val = 1 << SCL_FT_DEFAULT_FIXPOINT_SHIFT; |
| 272 | |
| 273 | if (is_horizontal) { |
| 274 | if (mode == SCALE_UP) |
| 275 | val = GET_SCL_FT_BIC(src, dst); |
| 276 | else if (mode == SCALE_DOWN) |
| 277 | val = GET_SCL_FT_BILI_DN(src, dst); |
| 278 | } else { |
| 279 | if (mode == SCALE_UP) { |
| 280 | if (vsu_mode == SCALE_UP_BIL) |
| 281 | val = GET_SCL_FT_BILI_UP(src, dst); |
| 282 | else |
| 283 | val = GET_SCL_FT_BIC(src, dst); |
| 284 | } else if (mode == SCALE_DOWN) { |
| 285 | if (vskiplines) { |
| 286 | *vskiplines = scl_get_vskiplines(src, dst); |
| 287 | val = scl_get_bili_dn_vskip(src, dst, |
| 288 | *vskiplines); |
| 289 | } else { |
| 290 | val = GET_SCL_FT_BILI_DN(src, dst); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return val; |
| 296 | } |
| 297 | |
| 298 | static void scl_vop_cal_scl_fac(struct vop *vop, const struct vop_win_data *win, |
| 299 | uint32_t src_w, uint32_t src_h, uint32_t dst_w, |
| 300 | uint32_t dst_h, uint32_t pixel_format) |
| 301 | { |
| 302 | uint16_t yrgb_hor_scl_mode, yrgb_ver_scl_mode; |
| 303 | uint16_t cbcr_hor_scl_mode = SCALE_NONE; |
| 304 | uint16_t cbcr_ver_scl_mode = SCALE_NONE; |
| 305 | int hsub = drm_format_horz_chroma_subsampling(pixel_format); |
| 306 | int vsub = drm_format_vert_chroma_subsampling(pixel_format); |
| 307 | bool is_yuv = is_yuv_support(pixel_format); |
| 308 | uint16_t cbcr_src_w = src_w / hsub; |
| 309 | uint16_t cbcr_src_h = src_h / vsub; |
| 310 | uint16_t vsu_mode; |
| 311 | uint16_t lb_mode; |
| 312 | uint32_t val; |
Mark Yao | 2db00cf | 2016-04-29 15:39:53 +0800 | [diff] [blame] | 313 | int vskiplines = 0; |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 314 | |
| 315 | if (dst_w > 3840) { |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 316 | DRM_DEV_ERROR(vop->dev, "Maximum dst width (3840) exceeded\n"); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 320 | if (!win->phy->scl->ext) { |
| 321 | VOP_SCL_SET(vop, win, scale_yrgb_x, |
| 322 | scl_cal_scale2(src_w, dst_w)); |
| 323 | VOP_SCL_SET(vop, win, scale_yrgb_y, |
| 324 | scl_cal_scale2(src_h, dst_h)); |
| 325 | if (is_yuv) { |
| 326 | VOP_SCL_SET(vop, win, scale_cbcr_x, |
Mark Yao | ee8662f | 2016-06-06 15:58:46 +0800 | [diff] [blame] | 327 | scl_cal_scale2(cbcr_src_w, dst_w)); |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 328 | VOP_SCL_SET(vop, win, scale_cbcr_y, |
Mark Yao | ee8662f | 2016-06-06 15:58:46 +0800 | [diff] [blame] | 329 | scl_cal_scale2(cbcr_src_h, dst_h)); |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 330 | } |
| 331 | return; |
| 332 | } |
| 333 | |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 334 | yrgb_hor_scl_mode = scl_get_scl_mode(src_w, dst_w); |
| 335 | yrgb_ver_scl_mode = scl_get_scl_mode(src_h, dst_h); |
| 336 | |
| 337 | if (is_yuv) { |
| 338 | cbcr_hor_scl_mode = scl_get_scl_mode(cbcr_src_w, dst_w); |
| 339 | cbcr_ver_scl_mode = scl_get_scl_mode(cbcr_src_h, dst_h); |
| 340 | if (cbcr_hor_scl_mode == SCALE_DOWN) |
| 341 | lb_mode = scl_vop_cal_lb_mode(dst_w, true); |
| 342 | else |
| 343 | lb_mode = scl_vop_cal_lb_mode(cbcr_src_w, true); |
| 344 | } else { |
| 345 | if (yrgb_hor_scl_mode == SCALE_DOWN) |
| 346 | lb_mode = scl_vop_cal_lb_mode(dst_w, false); |
| 347 | else |
| 348 | lb_mode = scl_vop_cal_lb_mode(src_w, false); |
| 349 | } |
| 350 | |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 351 | VOP_SCL_SET_EXT(vop, win, lb_mode, lb_mode); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 352 | if (lb_mode == LB_RGB_3840X2) { |
| 353 | if (yrgb_ver_scl_mode != SCALE_NONE) { |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 354 | DRM_DEV_ERROR(vop->dev, "not allow yrgb ver scale\n"); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | if (cbcr_ver_scl_mode != SCALE_NONE) { |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 358 | DRM_DEV_ERROR(vop->dev, "not allow cbcr ver scale\n"); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | vsu_mode = SCALE_UP_BIL; |
| 362 | } else if (lb_mode == LB_RGB_2560X4) { |
| 363 | vsu_mode = SCALE_UP_BIL; |
| 364 | } else { |
| 365 | vsu_mode = SCALE_UP_BIC; |
| 366 | } |
| 367 | |
| 368 | val = scl_vop_cal_scale(yrgb_hor_scl_mode, src_w, dst_w, |
| 369 | true, 0, NULL); |
| 370 | VOP_SCL_SET(vop, win, scale_yrgb_x, val); |
| 371 | val = scl_vop_cal_scale(yrgb_ver_scl_mode, src_h, dst_h, |
| 372 | false, vsu_mode, &vskiplines); |
| 373 | VOP_SCL_SET(vop, win, scale_yrgb_y, val); |
| 374 | |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 375 | VOP_SCL_SET_EXT(vop, win, vsd_yrgb_gt4, vskiplines == 4); |
| 376 | VOP_SCL_SET_EXT(vop, win, vsd_yrgb_gt2, vskiplines == 2); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 377 | |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 378 | VOP_SCL_SET_EXT(vop, win, yrgb_hor_scl_mode, yrgb_hor_scl_mode); |
| 379 | VOP_SCL_SET_EXT(vop, win, yrgb_ver_scl_mode, yrgb_ver_scl_mode); |
| 380 | VOP_SCL_SET_EXT(vop, win, yrgb_hsd_mode, SCALE_DOWN_BIL); |
| 381 | VOP_SCL_SET_EXT(vop, win, yrgb_vsd_mode, SCALE_DOWN_BIL); |
| 382 | VOP_SCL_SET_EXT(vop, win, yrgb_vsu_mode, vsu_mode); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 383 | if (is_yuv) { |
| 384 | val = scl_vop_cal_scale(cbcr_hor_scl_mode, cbcr_src_w, |
| 385 | dst_w, true, 0, NULL); |
| 386 | VOP_SCL_SET(vop, win, scale_cbcr_x, val); |
| 387 | val = scl_vop_cal_scale(cbcr_ver_scl_mode, cbcr_src_h, |
| 388 | dst_h, false, vsu_mode, &vskiplines); |
| 389 | VOP_SCL_SET(vop, win, scale_cbcr_y, val); |
| 390 | |
Mark Yao | 1194fff | 2015-12-15 09:08:43 +0800 | [diff] [blame] | 391 | VOP_SCL_SET_EXT(vop, win, vsd_cbcr_gt4, vskiplines == 4); |
| 392 | VOP_SCL_SET_EXT(vop, win, vsd_cbcr_gt2, vskiplines == 2); |
| 393 | VOP_SCL_SET_EXT(vop, win, cbcr_hor_scl_mode, cbcr_hor_scl_mode); |
| 394 | VOP_SCL_SET_EXT(vop, win, cbcr_ver_scl_mode, cbcr_ver_scl_mode); |
| 395 | VOP_SCL_SET_EXT(vop, win, cbcr_hsd_mode, SCALE_DOWN_BIL); |
| 396 | VOP_SCL_SET_EXT(vop, win, cbcr_vsd_mode, SCALE_DOWN_BIL); |
| 397 | VOP_SCL_SET_EXT(vop, win, cbcr_vsu_mode, vsu_mode); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 401 | static void vop_dsp_hold_valid_irq_enable(struct vop *vop) |
| 402 | { |
| 403 | unsigned long flags; |
| 404 | |
| 405 | if (WARN_ON(!vop->is_enabled)) |
| 406 | return; |
| 407 | |
| 408 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 409 | |
Tomasz Figa | fa37410 | 2016-09-14 21:54:54 +0900 | [diff] [blame] | 410 | VOP_INTR_SET_TYPE(vop, clear, DSP_HOLD_VALID_INTR, 1); |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 411 | VOP_INTR_SET_TYPE(vop, enable, DSP_HOLD_VALID_INTR, 1); |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 412 | |
| 413 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 414 | } |
| 415 | |
| 416 | static void vop_dsp_hold_valid_irq_disable(struct vop *vop) |
| 417 | { |
| 418 | unsigned long flags; |
| 419 | |
| 420 | if (WARN_ON(!vop->is_enabled)) |
| 421 | return; |
| 422 | |
| 423 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 424 | |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 425 | VOP_INTR_SET_TYPE(vop, enable, DSP_HOLD_VALID_INTR, 0); |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 426 | |
| 427 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 428 | } |
| 429 | |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 430 | /* |
| 431 | * (1) each frame starts at the start of the Vsync pulse which is signaled by |
| 432 | * the "FRAME_SYNC" interrupt. |
| 433 | * (2) the active data region of each frame ends at dsp_vact_end |
| 434 | * (3) we should program this same number (dsp_vact_end) into dsp_line_frag_num, |
| 435 | * to get "LINE_FLAG" interrupt at the end of the active on screen data. |
| 436 | * |
| 437 | * VOP_INTR_CTRL0.dsp_line_frag_num = VOP_DSP_VACT_ST_END.dsp_vact_end |
| 438 | * Interrupts |
| 439 | * LINE_FLAG -------------------------------+ |
| 440 | * FRAME_SYNC ----+ | |
| 441 | * | | |
| 442 | * v v |
| 443 | * | Vsync | Vbp | Vactive | Vfp | |
| 444 | * ^ ^ ^ ^ |
| 445 | * | | | | |
| 446 | * | | | | |
| 447 | * dsp_vs_end ------------+ | | | VOP_DSP_VTOTAL_VS_END |
| 448 | * dsp_vact_start --------------+ | | VOP_DSP_VACT_ST_END |
| 449 | * dsp_vact_end ----------------------------+ | VOP_DSP_VACT_ST_END |
| 450 | * dsp_total -------------------------------------+ VOP_DSP_VTOTAL_VS_END |
| 451 | */ |
| 452 | static bool vop_line_flag_irq_is_enabled(struct vop *vop) |
| 453 | { |
| 454 | uint32_t line_flag_irq; |
| 455 | unsigned long flags; |
| 456 | |
| 457 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 458 | |
| 459 | line_flag_irq = VOP_INTR_GET_TYPE(vop, enable, LINE_FLAG_INTR); |
| 460 | |
| 461 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 462 | |
| 463 | return !!line_flag_irq; |
| 464 | } |
| 465 | |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 466 | static void vop_line_flag_irq_enable(struct vop *vop) |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 467 | { |
| 468 | unsigned long flags; |
| 469 | |
| 470 | if (WARN_ON(!vop->is_enabled)) |
| 471 | return; |
| 472 | |
| 473 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 474 | |
Tomasz Figa | fa37410 | 2016-09-14 21:54:54 +0900 | [diff] [blame] | 475 | VOP_INTR_SET_TYPE(vop, clear, LINE_FLAG_INTR, 1); |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 476 | VOP_INTR_SET_TYPE(vop, enable, LINE_FLAG_INTR, 1); |
| 477 | |
| 478 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 479 | } |
| 480 | |
| 481 | static void vop_line_flag_irq_disable(struct vop *vop) |
| 482 | { |
| 483 | unsigned long flags; |
| 484 | |
| 485 | if (WARN_ON(!vop->is_enabled)) |
| 486 | return; |
| 487 | |
| 488 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 489 | |
| 490 | VOP_INTR_SET_TYPE(vop, enable, LINE_FLAG_INTR, 0); |
| 491 | |
| 492 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 493 | } |
| 494 | |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 495 | static int vop_enable(struct drm_crtc *crtc) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 496 | { |
| 497 | struct vop *vop = to_vop(crtc); |
| 498 | int ret; |
| 499 | |
Mark Yao | 5d82d1a | 2015-04-01 13:48:53 +0800 | [diff] [blame] | 500 | ret = pm_runtime_get_sync(vop->dev); |
| 501 | if (ret < 0) { |
| 502 | dev_err(vop->dev, "failed to get pm runtime: %d\n", ret); |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 503 | return ret; |
Mark Yao | 5d82d1a | 2015-04-01 13:48:53 +0800 | [diff] [blame] | 504 | } |
| 505 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 506 | ret = clk_enable(vop->hclk); |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 507 | if (WARN_ON(ret < 0)) |
| 508 | goto err_put_pm_runtime; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 509 | |
| 510 | ret = clk_enable(vop->dclk); |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 511 | if (WARN_ON(ret < 0)) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 512 | goto err_disable_hclk; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 513 | |
| 514 | ret = clk_enable(vop->aclk); |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 515 | if (WARN_ON(ret < 0)) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 516 | goto err_disable_dclk; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * Slave iommu shares power, irq and clock with vop. It was associated |
| 520 | * automatically with this master device via common driver code. |
| 521 | * Now that we have enabled the clock we attach it to the shared drm |
| 522 | * mapping. |
| 523 | */ |
| 524 | ret = rockchip_drm_dma_attach_device(vop->drm_dev, vop->dev); |
| 525 | if (ret) { |
| 526 | dev_err(vop->dev, "failed to attach dma mapping, %d\n", ret); |
| 527 | goto err_disable_aclk; |
| 528 | } |
| 529 | |
Mark Yao | 77faa16 | 2015-07-20 16:25:20 +0800 | [diff] [blame] | 530 | memcpy(vop->regs, vop->regsbak, vop->len); |
Chris Zhong | 17a794d | 2016-08-26 20:39:38 -0700 | [diff] [blame] | 531 | vop_cfg_done(vop); |
| 532 | |
Mark Yao | 52ab789 | 2015-01-22 18:29:57 +0800 | [diff] [blame] | 533 | /* |
| 534 | * At here, vop clock & iommu is enable, R/W vop regs would be safe. |
| 535 | */ |
| 536 | vop->is_enabled = true; |
| 537 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 538 | spin_lock(&vop->reg_lock); |
| 539 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 540 | VOP_REG_SET(vop, common, standby, 1); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 541 | |
| 542 | spin_unlock(&vop->reg_lock); |
| 543 | |
| 544 | enable_irq(vop->irq); |
| 545 | |
Mark Yao | b5f7b75 | 2015-11-23 15:21:08 +0800 | [diff] [blame] | 546 | drm_crtc_vblank_on(crtc); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 547 | |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 548 | return 0; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 549 | |
| 550 | err_disable_aclk: |
| 551 | clk_disable(vop->aclk); |
| 552 | err_disable_dclk: |
| 553 | clk_disable(vop->dclk); |
| 554 | err_disable_hclk: |
| 555 | clk_disable(vop->hclk); |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 556 | err_put_pm_runtime: |
| 557 | pm_runtime_put_sync(vop->dev); |
| 558 | return ret; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 559 | } |
| 560 | |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 561 | static void vop_crtc_atomic_disable(struct drm_crtc *crtc, |
| 562 | struct drm_crtc_state *old_state) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 563 | { |
| 564 | struct vop *vop = to_vop(crtc); |
Tomeu Vizoso | 3ed6c64 | 2016-03-22 16:08:04 +0100 | [diff] [blame] | 565 | int i; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 566 | |
Daniel Vetter | 893b6ca | 2016-06-08 14:19:12 +0200 | [diff] [blame] | 567 | WARN_ON(vop->event); |
| 568 | |
Sean Paul | b883c9b | 2016-08-18 12:01:46 -0700 | [diff] [blame] | 569 | rockchip_drm_psr_deactivate(&vop->crtc); |
| 570 | |
Tomeu Vizoso | 3ed6c64 | 2016-03-22 16:08:04 +0100 | [diff] [blame] | 571 | /* |
| 572 | * We need to make sure that all windows are disabled before we |
| 573 | * disable that crtc. Otherwise we might try to scan from a destroyed |
| 574 | * buffer later. |
| 575 | */ |
| 576 | for (i = 0; i < vop->data->win_size; i++) { |
| 577 | struct vop_win *vop_win = &vop->win[i]; |
| 578 | const struct vop_win_data *win = vop_win->data; |
| 579 | |
| 580 | spin_lock(&vop->reg_lock); |
| 581 | VOP_WIN_SET(vop, win, enable, 0); |
| 582 | spin_unlock(&vop->reg_lock); |
| 583 | } |
| 584 | |
Chris Zhong | 17a794d | 2016-08-26 20:39:38 -0700 | [diff] [blame] | 585 | vop_cfg_done(vop); |
| 586 | |
Mark Yao | b5f7b75 | 2015-11-23 15:21:08 +0800 | [diff] [blame] | 587 | drm_crtc_vblank_off(crtc); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 588 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 589 | /* |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 590 | * Vop standby will take effect at end of current frame, |
| 591 | * if dsp hold valid irq happen, it means standby complete. |
| 592 | * |
| 593 | * we must wait standby complete when we want to disable aclk, |
| 594 | * if not, memory bus maybe dead. |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 595 | */ |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 596 | reinit_completion(&vop->dsp_hold_completion); |
| 597 | vop_dsp_hold_valid_irq_enable(vop); |
| 598 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 599 | spin_lock(&vop->reg_lock); |
| 600 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 601 | VOP_REG_SET(vop, common, standby, 1); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 602 | |
| 603 | spin_unlock(&vop->reg_lock); |
Mark Yao | 52ab789 | 2015-01-22 18:29:57 +0800 | [diff] [blame] | 604 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 605 | wait_for_completion(&vop->dsp_hold_completion); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 606 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 607 | vop_dsp_hold_valid_irq_disable(vop); |
| 608 | |
| 609 | disable_irq(vop->irq); |
| 610 | |
| 611 | vop->is_enabled = false; |
| 612 | |
| 613 | /* |
| 614 | * vop standby complete, so iommu detach is safe. |
| 615 | */ |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 616 | rockchip_drm_dma_detach_device(vop->drm_dev, vop->dev); |
| 617 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 618 | clk_disable(vop->dclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 619 | clk_disable(vop->aclk); |
| 620 | clk_disable(vop->hclk); |
Mark Yao | 5d82d1a | 2015-04-01 13:48:53 +0800 | [diff] [blame] | 621 | pm_runtime_put(vop->dev); |
Daniel Vetter | 893b6ca | 2016-06-08 14:19:12 +0200 | [diff] [blame] | 622 | |
| 623 | if (crtc->state->event && !crtc->state->active) { |
| 624 | spin_lock_irq(&crtc->dev->event_lock); |
| 625 | drm_crtc_send_vblank_event(crtc, crtc->state->event); |
| 626 | spin_unlock_irq(&crtc->dev->event_lock); |
| 627 | |
| 628 | crtc->state->event = NULL; |
| 629 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 630 | } |
| 631 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 632 | static void vop_plane_destroy(struct drm_plane *plane) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 633 | { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 634 | drm_plane_cleanup(plane); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 635 | } |
| 636 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 637 | static int vop_plane_atomic_check(struct drm_plane *plane, |
| 638 | struct drm_plane_state *state) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 639 | { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 640 | struct drm_crtc *crtc = state->crtc; |
John Keeping | 92915da | 2016-03-04 11:04:03 +0000 | [diff] [blame] | 641 | struct drm_crtc_state *crtc_state; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 642 | struct drm_framebuffer *fb = state->fb; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 643 | struct vop_win *vop_win = to_vop_win(plane); |
| 644 | const struct vop_win_data *win = vop_win->data; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 645 | int ret; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 646 | struct drm_rect clip; |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 647 | int min_scale = win->phy->scl ? FRAC_16_16(1, 8) : |
| 648 | DRM_PLANE_HELPER_NO_SCALING; |
| 649 | int max_scale = win->phy->scl ? FRAC_16_16(8, 1) : |
| 650 | DRM_PLANE_HELPER_NO_SCALING; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 651 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 652 | if (!crtc || !fb) |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 653 | return 0; |
John Keeping | 92915da | 2016-03-04 11:04:03 +0000 | [diff] [blame] | 654 | |
| 655 | crtc_state = drm_atomic_get_existing_crtc_state(state->state, crtc); |
| 656 | if (WARN_ON(!crtc_state)) |
| 657 | return -EINVAL; |
| 658 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 659 | clip.x1 = 0; |
| 660 | clip.y1 = 0; |
John Keeping | 92915da | 2016-03-04 11:04:03 +0000 | [diff] [blame] | 661 | clip.x2 = crtc_state->adjusted_mode.hdisplay; |
| 662 | clip.y2 = crtc_state->adjusted_mode.vdisplay; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 663 | |
Ville Syrjälä | f9b96be | 2016-07-26 19:07:02 +0300 | [diff] [blame] | 664 | ret = drm_plane_helper_check_state(state, &clip, |
| 665 | min_scale, max_scale, |
| 666 | true, true); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 667 | if (ret) |
| 668 | return ret; |
| 669 | |
Ville Syrjälä | f9b96be | 2016-07-26 19:07:02 +0300 | [diff] [blame] | 670 | if (!state->visible) |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 671 | return 0; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 672 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 673 | ret = vop_convert_format(fb->format->format); |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 674 | if (ret < 0) |
| 675 | return ret; |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 676 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 677 | /* |
| 678 | * Src.x1 can be odd when do clip, but yuv plane start point |
| 679 | * need align with 2 pixel. |
| 680 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 681 | if (is_yuv_support(fb->format->format) && ((state->src.x1 >> 16) % 2)) |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 682 | return -EINVAL; |
| 683 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static void vop_plane_atomic_disable(struct drm_plane *plane, |
| 688 | struct drm_plane_state *old_state) |
| 689 | { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 690 | struct vop_win *vop_win = to_vop_win(plane); |
| 691 | const struct vop_win_data *win = vop_win->data; |
| 692 | struct vop *vop = to_vop(old_state->crtc); |
| 693 | |
| 694 | if (!old_state->crtc) |
| 695 | return; |
| 696 | |
| 697 | spin_lock(&vop->reg_lock); |
| 698 | |
| 699 | VOP_WIN_SET(vop, win, enable, 0); |
| 700 | |
| 701 | spin_unlock(&vop->reg_lock); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static void vop_plane_atomic_update(struct drm_plane *plane, |
| 705 | struct drm_plane_state *old_state) |
| 706 | { |
| 707 | struct drm_plane_state *state = plane->state; |
| 708 | struct drm_crtc *crtc = state->crtc; |
| 709 | struct vop_win *vop_win = to_vop_win(plane); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 710 | const struct vop_win_data *win = vop_win->data; |
| 711 | struct vop *vop = to_vop(state->crtc); |
| 712 | struct drm_framebuffer *fb = state->fb; |
| 713 | unsigned int actual_w, actual_h; |
| 714 | unsigned int dsp_stx, dsp_sty; |
| 715 | uint32_t act_info, dsp_info, dsp_st; |
Ville Syrjälä | ac92028 | 2016-07-26 19:07:01 +0300 | [diff] [blame] | 716 | struct drm_rect *src = &state->src; |
| 717 | struct drm_rect *dest = &state->dst; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 718 | struct drm_gem_object *obj, *uv_obj; |
| 719 | struct rockchip_gem_object *rk_obj, *rk_uv_obj; |
| 720 | unsigned long offset; |
| 721 | dma_addr_t dma_addr; |
| 722 | uint32_t val; |
| 723 | bool rb_swap; |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 724 | int format; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * can't update plane when vop is disabled. |
| 728 | */ |
Daniel Vetter | 4f9d39a | 2016-06-08 14:19:11 +0200 | [diff] [blame] | 729 | if (WARN_ON(!crtc)) |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 730 | return; |
| 731 | |
| 732 | if (WARN_ON(!vop->is_enabled)) |
| 733 | return; |
| 734 | |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 735 | if (!state->visible) { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 736 | vop_plane_atomic_disable(plane, old_state); |
| 737 | return; |
| 738 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 739 | |
| 740 | obj = rockchip_fb_get_gem_obj(fb, 0); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 741 | rk_obj = to_rockchip_obj(obj); |
| 742 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 743 | actual_w = drm_rect_width(src) >> 16; |
| 744 | actual_h = drm_rect_height(src) >> 16; |
| 745 | act_info = (actual_h - 1) << 16 | ((actual_w - 1) & 0xffff); |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 746 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 747 | dsp_info = (drm_rect_height(dest) - 1) << 16; |
| 748 | dsp_info |= (drm_rect_width(dest) - 1) & 0xffff; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 749 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 750 | dsp_stx = dest->x1 + crtc->mode.htotal - crtc->mode.hsync_start; |
| 751 | dsp_sty = dest->y1 + crtc->mode.vtotal - crtc->mode.vsync_start; |
| 752 | dsp_st = dsp_sty << 16 | (dsp_stx & 0xffff); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 753 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 754 | offset = (src->x1 >> 16) * fb->format->cpp[0]; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 755 | offset += (src->y1 >> 16) * fb->pitches[0]; |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 756 | dma_addr = rk_obj->dma_addr + offset + fb->offsets[0]; |
| 757 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 758 | format = vop_convert_format(fb->format->format); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 759 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 760 | spin_lock(&vop->reg_lock); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 761 | |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 762 | VOP_WIN_SET(vop, win, format, format); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 763 | VOP_WIN_SET(vop, win, yrgb_vir, fb->pitches[0] >> 2); |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 764 | VOP_WIN_SET(vop, win, yrgb_mst, dma_addr); |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 765 | if (is_yuv_support(fb->format->format)) { |
| 766 | int hsub = drm_format_horz_chroma_subsampling(fb->format->format); |
| 767 | int vsub = drm_format_vert_chroma_subsampling(fb->format->format); |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 768 | int bpp = fb->format->cpp[1]; |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 769 | |
| 770 | uv_obj = rockchip_fb_get_gem_obj(fb, 1); |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 771 | rk_uv_obj = to_rockchip_obj(uv_obj); |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 772 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 773 | offset = (src->x1 >> 16) * bpp / hsub; |
| 774 | offset += (src->y1 >> 16) * fb->pitches[1] / vsub; |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 775 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 776 | dma_addr = rk_uv_obj->dma_addr + offset + fb->offsets[1]; |
| 777 | VOP_WIN_SET(vop, win, uv_vir, fb->pitches[1] >> 2); |
| 778 | VOP_WIN_SET(vop, win, uv_mst, dma_addr); |
Mark Yao | 84c7f8c | 2015-07-20 16:16:49 +0800 | [diff] [blame] | 779 | } |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 780 | |
| 781 | if (win->phy->scl) |
| 782 | scl_vop_cal_scl_fac(vop, win, actual_w, actual_h, |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 783 | drm_rect_width(dest), drm_rect_height(dest), |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 784 | fb->format->format); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 785 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 786 | VOP_WIN_SET(vop, win, act_info, act_info); |
| 787 | VOP_WIN_SET(vop, win, dsp_info, dsp_info); |
| 788 | VOP_WIN_SET(vop, win, dsp_st, dsp_st); |
Mark Yao | 4c156c2 | 2015-06-26 17:14:46 +0800 | [diff] [blame] | 789 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 790 | rb_swap = has_rb_swapped(fb->format->format); |
Tomasz Figa | 85a359f | 2015-05-11 19:55:39 +0900 | [diff] [blame] | 791 | VOP_WIN_SET(vop, win, rb_swap, rb_swap); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 792 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 793 | if (is_alpha_support(fb->format->format)) { |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 794 | VOP_WIN_SET(vop, win, dst_alpha_ctl, |
| 795 | DST_FACTOR_M0(ALPHA_SRC_INVERSE)); |
| 796 | val = SRC_ALPHA_EN(1) | SRC_COLOR_M0(ALPHA_SRC_PRE_MUL) | |
| 797 | SRC_ALPHA_M0(ALPHA_STRAIGHT) | |
| 798 | SRC_BLEND_M0(ALPHA_PER_PIX) | |
| 799 | SRC_ALPHA_CAL_M0(ALPHA_NO_SATURATION) | |
| 800 | SRC_FACTOR_M0(ALPHA_ONE); |
| 801 | VOP_WIN_SET(vop, win, src_alpha_ctl, val); |
| 802 | } else { |
| 803 | VOP_WIN_SET(vop, win, src_alpha_ctl, SRC_ALPHA_EN(0)); |
| 804 | } |
| 805 | |
| 806 | VOP_WIN_SET(vop, win, enable, 1); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 807 | spin_unlock(&vop->reg_lock); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 810 | static const struct drm_plane_helper_funcs plane_helper_funcs = { |
| 811 | .atomic_check = vop_plane_atomic_check, |
| 812 | .atomic_update = vop_plane_atomic_update, |
| 813 | .atomic_disable = vop_plane_atomic_disable, |
| 814 | }; |
| 815 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 816 | static const struct drm_plane_funcs vop_plane_funcs = { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 817 | .update_plane = drm_atomic_helper_update_plane, |
| 818 | .disable_plane = drm_atomic_helper_disable_plane, |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 819 | .destroy = vop_plane_destroy, |
Tomasz Figa | d47a724 | 2016-09-14 21:55:01 +0900 | [diff] [blame] | 820 | .reset = drm_atomic_helper_plane_reset, |
| 821 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
| 822 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 823 | }; |
| 824 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 825 | static int vop_crtc_enable_vblank(struct drm_crtc *crtc) |
| 826 | { |
| 827 | struct vop *vop = to_vop(crtc); |
| 828 | unsigned long flags; |
| 829 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 830 | if (WARN_ON(!vop->is_enabled)) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 831 | return -EPERM; |
| 832 | |
| 833 | spin_lock_irqsave(&vop->irq_lock, flags); |
| 834 | |
Tomasz Figa | fa37410 | 2016-09-14 21:54:54 +0900 | [diff] [blame] | 835 | VOP_INTR_SET_TYPE(vop, clear, FS_INTR, 1); |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 836 | VOP_INTR_SET_TYPE(vop, enable, FS_INTR, 1); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 837 | |
| 838 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static void vop_crtc_disable_vblank(struct drm_crtc *crtc) |
| 844 | { |
| 845 | struct vop *vop = to_vop(crtc); |
| 846 | unsigned long flags; |
| 847 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 848 | if (WARN_ON(!vop->is_enabled)) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 849 | return; |
Mark Yao | 31e980c | 2015-01-22 14:37:56 +0800 | [diff] [blame] | 850 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 851 | spin_lock_irqsave(&vop->irq_lock, flags); |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 852 | |
| 853 | VOP_INTR_SET_TYPE(vop, enable, FS_INTR, 0); |
| 854 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 855 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 856 | } |
| 857 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 858 | static bool vop_crtc_mode_fixup(struct drm_crtc *crtc, |
| 859 | const struct drm_display_mode *mode, |
| 860 | struct drm_display_mode *adjusted_mode) |
| 861 | { |
Chris Zhong | b59b8de | 2016-01-06 12:03:53 +0800 | [diff] [blame] | 862 | struct vop *vop = to_vop(crtc); |
| 863 | |
Chris Zhong | b59b8de | 2016-01-06 12:03:53 +0800 | [diff] [blame] | 864 | adjusted_mode->clock = |
| 865 | clk_round_rate(vop->dclk, mode->clock * 1000) / 1000; |
| 866 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 867 | return true; |
| 868 | } |
| 869 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 870 | static void vop_crtc_atomic_enable(struct drm_crtc *crtc, |
| 871 | struct drm_crtc_state *old_state) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 872 | { |
| 873 | struct vop *vop = to_vop(crtc); |
Mark yao | efd11cc | 2017-05-27 19:43:36 +0800 | [diff] [blame] | 874 | const struct vop_data *vop_data = vop->data; |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 875 | struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc->state); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 876 | struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 877 | u16 hsync_len = adjusted_mode->hsync_end - adjusted_mode->hsync_start; |
| 878 | u16 hdisplay = adjusted_mode->hdisplay; |
| 879 | u16 htotal = adjusted_mode->htotal; |
| 880 | u16 hact_st = adjusted_mode->htotal - adjusted_mode->hsync_start; |
| 881 | u16 hact_end = hact_st + hdisplay; |
| 882 | u16 vdisplay = adjusted_mode->vdisplay; |
| 883 | u16 vtotal = adjusted_mode->vtotal; |
| 884 | u16 vsync_len = adjusted_mode->vsync_end - adjusted_mode->vsync_start; |
| 885 | u16 vact_st = adjusted_mode->vtotal - adjusted_mode->vsync_start; |
| 886 | u16 vact_end = vact_st + vdisplay; |
Mark Yao | 0a63bfd | 2016-04-20 14:18:16 +0800 | [diff] [blame] | 887 | uint32_t pin_pol, val; |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 888 | int ret; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 889 | |
Daniel Vetter | 893b6ca | 2016-06-08 14:19:12 +0200 | [diff] [blame] | 890 | WARN_ON(vop->event); |
| 891 | |
Sean Paul | 39a9ad8 | 2016-08-15 16:12:29 -0700 | [diff] [blame] | 892 | ret = vop_enable(crtc); |
| 893 | if (ret) { |
| 894 | DRM_DEV_ERROR(vop->dev, "Failed to enable vop (%d)\n", ret); |
| 895 | return; |
| 896 | } |
| 897 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 898 | /* |
Mark Yao | ce3887e | 2015-12-16 18:08:17 +0800 | [diff] [blame] | 899 | * If dclk rate is zero, mean that scanout is stop, |
| 900 | * we don't need wait any more. |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 901 | */ |
Mark Yao | ce3887e | 2015-12-16 18:08:17 +0800 | [diff] [blame] | 902 | if (clk_get_rate(vop->dclk)) { |
| 903 | /* |
| 904 | * Rk3288 vop timing register is immediately, when configure |
| 905 | * display timing on display time, may cause tearing. |
| 906 | * |
| 907 | * Vop standby will take effect at end of current frame, |
| 908 | * if dsp hold valid irq happen, it means standby complete. |
| 909 | * |
| 910 | * mode set: |
| 911 | * standby and wait complete --> |---- |
| 912 | * | display time |
| 913 | * |---- |
| 914 | * |---> dsp hold irq |
| 915 | * configure display timing --> | |
| 916 | * standby exit | |
| 917 | * | new frame start. |
| 918 | */ |
| 919 | |
| 920 | reinit_completion(&vop->dsp_hold_completion); |
| 921 | vop_dsp_hold_valid_irq_enable(vop); |
| 922 | |
| 923 | spin_lock(&vop->reg_lock); |
| 924 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 925 | VOP_REG_SET(vop, common, standby, 1); |
Mark Yao | ce3887e | 2015-12-16 18:08:17 +0800 | [diff] [blame] | 926 | |
| 927 | spin_unlock(&vop->reg_lock); |
| 928 | |
| 929 | wait_for_completion(&vop->dsp_hold_completion); |
| 930 | |
| 931 | vop_dsp_hold_valid_irq_disable(vop); |
| 932 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 933 | |
Chris Zhong | 1a0f7ed | 2017-02-05 15:54:56 +0800 | [diff] [blame] | 934 | pin_pol = BIT(DCLK_INVERT); |
John Keeping | d790ad0 | 2017-02-24 12:55:03 +0000 | [diff] [blame] | 935 | pin_pol |= (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) ? |
| 936 | BIT(HSYNC_POSITIVE) : 0; |
| 937 | pin_pol |= (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) ? |
| 938 | BIT(VSYNC_POSITIVE) : 0; |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 939 | VOP_REG_SET(vop, output, pin_pol, pin_pol); |
Mark Yao | 0a63bfd | 2016-04-20 14:18:16 +0800 | [diff] [blame] | 940 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 941 | switch (s->output_type) { |
| 942 | case DRM_MODE_CONNECTOR_LVDS: |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 943 | VOP_REG_SET(vop, output, rgb_en, 1); |
| 944 | VOP_REG_SET(vop, output, rgb_pin_pol, pin_pol); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 945 | break; |
| 946 | case DRM_MODE_CONNECTOR_eDP: |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 947 | VOP_REG_SET(vop, output, edp_pin_pol, pin_pol); |
| 948 | VOP_REG_SET(vop, output, edp_en, 1); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 949 | break; |
| 950 | case DRM_MODE_CONNECTOR_HDMIA: |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 951 | VOP_REG_SET(vop, output, hdmi_pin_pol, pin_pol); |
| 952 | VOP_REG_SET(vop, output, hdmi_en, 1); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 953 | break; |
| 954 | case DRM_MODE_CONNECTOR_DSI: |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 955 | VOP_REG_SET(vop, output, mipi_pin_pol, pin_pol); |
| 956 | VOP_REG_SET(vop, output, mipi_en, 1); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 957 | break; |
Chris Zhong | 1a0f7ed | 2017-02-05 15:54:56 +0800 | [diff] [blame] | 958 | case DRM_MODE_CONNECTOR_DisplayPort: |
| 959 | pin_pol &= ~BIT(DCLK_INVERT); |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 960 | VOP_REG_SET(vop, output, dp_pin_pol, pin_pol); |
| 961 | VOP_REG_SET(vop, output, dp_en, 1); |
Chris Zhong | 1a0f7ed | 2017-02-05 15:54:56 +0800 | [diff] [blame] | 962 | break; |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 963 | default: |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 964 | DRM_DEV_ERROR(vop->dev, "unsupported connector_type [%d]\n", |
| 965 | s->output_type); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 966 | } |
Mark yao | efd11cc | 2017-05-27 19:43:36 +0800 | [diff] [blame] | 967 | |
| 968 | /* |
| 969 | * if vop is not support RGB10 output, need force RGB10 to RGB888. |
| 970 | */ |
| 971 | if (s->output_mode == ROCKCHIP_OUT_MODE_AAAA && |
| 972 | !(vop_data->feature & VOP_FEATURE_OUTPUT_RGB10)) |
| 973 | s->output_mode = ROCKCHIP_OUT_MODE_P888; |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 974 | VOP_REG_SET(vop, common, out_mode, s->output_mode); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 975 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 976 | VOP_REG_SET(vop, modeset, htotal_pw, (htotal << 16) | hsync_len); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 977 | val = hact_st << 16; |
| 978 | val |= hact_end; |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 979 | VOP_REG_SET(vop, modeset, hact_st_end, val); |
| 980 | VOP_REG_SET(vop, modeset, hpost_st_end, val); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 981 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 982 | VOP_REG_SET(vop, modeset, vtotal_pw, (vtotal << 16) | vsync_len); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 983 | val = vact_st << 16; |
| 984 | val |= vact_end; |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 985 | VOP_REG_SET(vop, modeset, vact_st_end, val); |
| 986 | VOP_REG_SET(vop, modeset, vpost_st_end, val); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 987 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 988 | VOP_REG_SET(vop, intr, line_flag_num[0], vact_end); |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 989 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 990 | clk_set_rate(vop->dclk, adjusted_mode->clock * 1000); |
Mark Yao | ce3887e | 2015-12-16 18:08:17 +0800 | [diff] [blame] | 991 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 992 | VOP_REG_SET(vop, common, standby, 0); |
Sean Paul | b883c9b | 2016-08-18 12:01:46 -0700 | [diff] [blame] | 993 | |
| 994 | rockchip_drm_psr_activate(&vop->crtc); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 995 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 996 | |
Tomasz Figa | 7caecdb | 2016-09-14 21:54:56 +0900 | [diff] [blame] | 997 | static bool vop_fs_irq_is_pending(struct vop *vop) |
| 998 | { |
| 999 | return VOP_INTR_GET_TYPE(vop, status, FS_INTR); |
| 1000 | } |
| 1001 | |
| 1002 | static void vop_wait_for_irq_handler(struct vop *vop) |
| 1003 | { |
| 1004 | bool pending; |
| 1005 | int ret; |
| 1006 | |
| 1007 | /* |
| 1008 | * Spin until frame start interrupt status bit goes low, which means |
| 1009 | * that interrupt handler was invoked and cleared it. The timeout of |
| 1010 | * 10 msecs is really too long, but it is just a safety measure if |
| 1011 | * something goes really wrong. The wait will only happen in the very |
| 1012 | * unlikely case of a vblank happening exactly at the same time and |
| 1013 | * shouldn't exceed microseconds range. |
| 1014 | */ |
| 1015 | ret = readx_poll_timeout_atomic(vop_fs_irq_is_pending, vop, pending, |
| 1016 | !pending, 0, 10 * 1000); |
| 1017 | if (ret) |
| 1018 | DRM_DEV_ERROR(vop->dev, "VOP vblank IRQ stuck for 10 ms\n"); |
| 1019 | |
| 1020 | synchronize_irq(vop->irq); |
| 1021 | } |
| 1022 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1023 | static void vop_crtc_atomic_flush(struct drm_crtc *crtc, |
| 1024 | struct drm_crtc_state *old_crtc_state) |
| 1025 | { |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1026 | struct drm_atomic_state *old_state = old_crtc_state->state; |
Maarten Lankhorst | e741f2b | 2017-07-12 10:13:37 +0200 | [diff] [blame] | 1027 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1028 | struct vop *vop = to_vop(crtc); |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1029 | struct drm_plane *plane; |
| 1030 | int i; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1031 | |
| 1032 | if (WARN_ON(!vop->is_enabled)) |
| 1033 | return; |
| 1034 | |
| 1035 | spin_lock(&vop->reg_lock); |
| 1036 | |
| 1037 | vop_cfg_done(vop); |
| 1038 | |
| 1039 | spin_unlock(&vop->reg_lock); |
Tomasz Figa | 7caecdb | 2016-09-14 21:54:56 +0900 | [diff] [blame] | 1040 | |
| 1041 | /* |
| 1042 | * There is a (rather unlikely) possiblity that a vblank interrupt |
| 1043 | * fired before we set the cfg_done bit. To avoid spuriously |
| 1044 | * signalling flip completion we need to wait for it to finish. |
| 1045 | */ |
| 1046 | vop_wait_for_irq_handler(vop); |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1047 | |
Tomasz Figa | 41ee436 | 2016-09-14 21:55:00 +0900 | [diff] [blame] | 1048 | spin_lock_irq(&crtc->dev->event_lock); |
| 1049 | if (crtc->state->event) { |
| 1050 | WARN_ON(drm_crtc_vblank_get(crtc) != 0); |
| 1051 | WARN_ON(vop->event); |
| 1052 | |
| 1053 | vop->event = crtc->state->event; |
| 1054 | crtc->state->event = NULL; |
| 1055 | } |
| 1056 | spin_unlock_irq(&crtc->dev->event_lock); |
| 1057 | |
Maarten Lankhorst | e741f2b | 2017-07-12 10:13:37 +0200 | [diff] [blame] | 1058 | for_each_oldnew_plane_in_state(old_state, plane, old_plane_state, |
| 1059 | new_plane_state, i) { |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1060 | if (!old_plane_state->fb) |
| 1061 | continue; |
| 1062 | |
Maarten Lankhorst | e741f2b | 2017-07-12 10:13:37 +0200 | [diff] [blame] | 1063 | if (old_plane_state->fb == new_plane_state->fb) |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1064 | continue; |
| 1065 | |
| 1066 | drm_framebuffer_reference(old_plane_state->fb); |
| 1067 | drm_flip_work_queue(&vop->fb_unref_work, old_plane_state->fb); |
| 1068 | set_bit(VOP_PENDING_FB_UNREF, &vop->pending); |
| 1069 | WARN_ON(drm_crtc_vblank_get(crtc) != 0); |
| 1070 | } |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static void vop_crtc_atomic_begin(struct drm_crtc *crtc, |
| 1074 | struct drm_crtc_state *old_crtc_state) |
| 1075 | { |
Sean Paul | b883c9b | 2016-08-18 12:01:46 -0700 | [diff] [blame] | 1076 | rockchip_drm_psr_flush(crtc); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1079 | static const struct drm_crtc_helper_funcs vop_crtc_helper_funcs = { |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1080 | .mode_fixup = vop_crtc_mode_fixup, |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1081 | .atomic_flush = vop_crtc_atomic_flush, |
| 1082 | .atomic_begin = vop_crtc_atomic_begin, |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 1083 | .atomic_enable = vop_crtc_atomic_enable, |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 1084 | .atomic_disable = vop_crtc_atomic_disable, |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1085 | }; |
| 1086 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1087 | static void vop_crtc_destroy(struct drm_crtc *crtc) |
| 1088 | { |
| 1089 | drm_crtc_cleanup(crtc); |
| 1090 | } |
| 1091 | |
John Keeping | dc0b408 | 2016-07-14 16:29:15 +0100 | [diff] [blame] | 1092 | static void vop_crtc_reset(struct drm_crtc *crtc) |
| 1093 | { |
| 1094 | if (crtc->state) |
| 1095 | __drm_atomic_helper_crtc_destroy_state(crtc->state); |
| 1096 | kfree(crtc->state); |
| 1097 | |
| 1098 | crtc->state = kzalloc(sizeof(struct rockchip_crtc_state), GFP_KERNEL); |
| 1099 | if (crtc->state) |
| 1100 | crtc->state->crtc = crtc; |
| 1101 | } |
| 1102 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 1103 | static struct drm_crtc_state *vop_crtc_duplicate_state(struct drm_crtc *crtc) |
| 1104 | { |
| 1105 | struct rockchip_crtc_state *rockchip_state; |
| 1106 | |
| 1107 | rockchip_state = kzalloc(sizeof(*rockchip_state), GFP_KERNEL); |
| 1108 | if (!rockchip_state) |
| 1109 | return NULL; |
| 1110 | |
| 1111 | __drm_atomic_helper_crtc_duplicate_state(crtc, &rockchip_state->base); |
| 1112 | return &rockchip_state->base; |
| 1113 | } |
| 1114 | |
| 1115 | static void vop_crtc_destroy_state(struct drm_crtc *crtc, |
| 1116 | struct drm_crtc_state *state) |
| 1117 | { |
| 1118 | struct rockchip_crtc_state *s = to_rockchip_crtc_state(state); |
| 1119 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 1120 | __drm_atomic_helper_crtc_destroy_state(&s->base); |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 1121 | kfree(s); |
| 1122 | } |
| 1123 | |
Sean Paul | 6cca386 | 2017-03-06 15:02:26 -0500 | [diff] [blame] | 1124 | #ifdef CONFIG_DRM_ANALOGIX_DP |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1125 | static struct drm_connector *vop_get_edp_connector(struct vop *vop) |
| 1126 | { |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1127 | struct drm_connector *connector; |
Gustavo Padovan | 2cbeb64 | 2017-05-15 10:43:30 -0300 | [diff] [blame] | 1128 | struct drm_connector_list_iter conn_iter; |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1129 | |
Gustavo Padovan | 2cbeb64 | 2017-05-15 10:43:30 -0300 | [diff] [blame] | 1130 | drm_connector_list_iter_begin(vop->drm_dev, &conn_iter); |
| 1131 | drm_for_each_connector_iter(connector, &conn_iter) { |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1132 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { |
Gustavo Padovan | 2cbeb64 | 2017-05-15 10:43:30 -0300 | [diff] [blame] | 1133 | drm_connector_list_iter_end(&conn_iter); |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1134 | return connector; |
| 1135 | } |
Gustavo Padovan | 2cbeb64 | 2017-05-15 10:43:30 -0300 | [diff] [blame] | 1136 | } |
| 1137 | drm_connector_list_iter_end(&conn_iter); |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1138 | |
| 1139 | return NULL; |
| 1140 | } |
| 1141 | |
| 1142 | static int vop_crtc_set_crc_source(struct drm_crtc *crtc, |
| 1143 | const char *source_name, size_t *values_cnt) |
| 1144 | { |
| 1145 | struct vop *vop = to_vop(crtc); |
| 1146 | struct drm_connector *connector; |
| 1147 | int ret; |
| 1148 | |
| 1149 | connector = vop_get_edp_connector(vop); |
| 1150 | if (!connector) |
| 1151 | return -EINVAL; |
| 1152 | |
| 1153 | *values_cnt = 3; |
| 1154 | |
| 1155 | if (source_name && strcmp(source_name, "auto") == 0) |
| 1156 | ret = analogix_dp_start_crc(connector); |
| 1157 | else if (!source_name) |
| 1158 | ret = analogix_dp_stop_crc(connector); |
| 1159 | else |
| 1160 | ret = -EINVAL; |
| 1161 | |
| 1162 | return ret; |
| 1163 | } |
Sean Paul | 6cca386 | 2017-03-06 15:02:26 -0500 | [diff] [blame] | 1164 | #else |
| 1165 | static int vop_crtc_set_crc_source(struct drm_crtc *crtc, |
| 1166 | const char *source_name, size_t *values_cnt) |
| 1167 | { |
| 1168 | return -ENODEV; |
| 1169 | } |
| 1170 | #endif |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1171 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1172 | static const struct drm_crtc_funcs vop_crtc_funcs = { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1173 | .set_config = drm_atomic_helper_set_config, |
| 1174 | .page_flip = drm_atomic_helper_page_flip, |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1175 | .destroy = vop_crtc_destroy, |
John Keeping | dc0b408 | 2016-07-14 16:29:15 +0100 | [diff] [blame] | 1176 | .reset = vop_crtc_reset, |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 1177 | .atomic_duplicate_state = vop_crtc_duplicate_state, |
| 1178 | .atomic_destroy_state = vop_crtc_destroy_state, |
Shawn Guo | c3605df | 2017-02-07 17:16:29 +0800 | [diff] [blame] | 1179 | .enable_vblank = vop_crtc_enable_vblank, |
| 1180 | .disable_vblank = vop_crtc_disable_vblank, |
Tomeu Vizoso | 3190e58 | 2017-03-03 14:39:36 +0100 | [diff] [blame] | 1181 | .set_crc_source = vop_crtc_set_crc_source, |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1182 | }; |
| 1183 | |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1184 | static void vop_fb_unref_worker(struct drm_flip_work *work, void *val) |
| 1185 | { |
| 1186 | struct vop *vop = container_of(work, struct vop, fb_unref_work); |
| 1187 | struct drm_framebuffer *fb = val; |
| 1188 | |
| 1189 | drm_crtc_vblank_put(&vop->crtc); |
| 1190 | drm_framebuffer_unreference(fb); |
| 1191 | } |
| 1192 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1193 | static void vop_handle_vblank(struct vop *vop) |
| 1194 | { |
| 1195 | struct drm_device *drm = vop->drm_dev; |
| 1196 | struct drm_crtc *crtc = &vop->crtc; |
| 1197 | unsigned long flags; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1198 | |
Daniel Vetter | 893b6ca | 2016-06-08 14:19:12 +0200 | [diff] [blame] | 1199 | spin_lock_irqsave(&drm->event_lock, flags); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1200 | if (vop->event) { |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1201 | drm_crtc_send_vblank_event(crtc, vop->event); |
Sean Paul | 5b68040 | 2016-08-10 16:24:39 -0400 | [diff] [blame] | 1202 | drm_crtc_vblank_put(crtc); |
Tomasz Figa | 646ec68 | 2016-09-14 21:54:59 +0900 | [diff] [blame] | 1203 | vop->event = NULL; |
Sean Paul | 5b68040 | 2016-08-10 16:24:39 -0400 | [diff] [blame] | 1204 | } |
Daniel Vetter | 893b6ca | 2016-06-08 14:19:12 +0200 | [diff] [blame] | 1205 | spin_unlock_irqrestore(&drm->event_lock, flags); |
| 1206 | |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1207 | if (test_and_clear_bit(VOP_PENDING_FB_UNREF, &vop->pending)) |
| 1208 | drm_flip_work_commit(&vop->fb_unref_work, system_unbound_wq); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | static irqreturn_t vop_isr(int irq, void *data) |
| 1212 | { |
| 1213 | struct vop *vop = data; |
Mark Yao | b5f7b75 | 2015-11-23 15:21:08 +0800 | [diff] [blame] | 1214 | struct drm_crtc *crtc = &vop->crtc; |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 1215 | uint32_t active_irqs; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1216 | unsigned long flags; |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1217 | int ret = IRQ_NONE; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1218 | |
| 1219 | /* |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 1220 | * interrupt register has interrupt status, enable and clear bits, we |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1221 | * must hold irq_lock to avoid a race with enable/disable_vblank(). |
| 1222 | */ |
| 1223 | spin_lock_irqsave(&vop->irq_lock, flags); |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 1224 | |
| 1225 | active_irqs = VOP_INTR_GET_TYPE(vop, status, INTR_MASK); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1226 | /* Clear all active interrupt sources */ |
| 1227 | if (active_irqs) |
Mark Yao | dbb3d94 | 2015-12-15 08:36:55 +0800 | [diff] [blame] | 1228 | VOP_INTR_SET_TYPE(vop, clear, active_irqs, 1); |
| 1229 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1230 | spin_unlock_irqrestore(&vop->irq_lock, flags); |
| 1231 | |
| 1232 | /* This is expected for vop iommu irqs, since the irq is shared */ |
| 1233 | if (!active_irqs) |
| 1234 | return IRQ_NONE; |
| 1235 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1236 | if (active_irqs & DSP_HOLD_VALID_INTR) { |
| 1237 | complete(&vop->dsp_hold_completion); |
| 1238 | active_irqs &= ~DSP_HOLD_VALID_INTR; |
| 1239 | ret = IRQ_HANDLED; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1242 | if (active_irqs & LINE_FLAG_INTR) { |
| 1243 | complete(&vop->line_flag_completion); |
| 1244 | active_irqs &= ~LINE_FLAG_INTR; |
| 1245 | ret = IRQ_HANDLED; |
| 1246 | } |
| 1247 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1248 | if (active_irqs & FS_INTR) { |
Mark Yao | b5f7b75 | 2015-11-23 15:21:08 +0800 | [diff] [blame] | 1249 | drm_crtc_handle_vblank(crtc); |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1250 | vop_handle_vblank(vop); |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1251 | active_irqs &= ~FS_INTR; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1252 | ret = IRQ_HANDLED; |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1253 | } |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1254 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1255 | /* Unhandled irqs are spurious. */ |
| 1256 | if (active_irqs) |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 1257 | DRM_DEV_ERROR(vop->dev, "Unknown VOP IRQs: %#02x\n", |
| 1258 | active_irqs); |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1259 | |
| 1260 | return ret; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static int vop_create_crtc(struct vop *vop) |
| 1264 | { |
| 1265 | const struct vop_data *vop_data = vop->data; |
| 1266 | struct device *dev = vop->dev; |
| 1267 | struct drm_device *drm_dev = vop->drm_dev; |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1268 | struct drm_plane *primary = NULL, *cursor = NULL, *plane, *tmp; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1269 | struct drm_crtc *crtc = &vop->crtc; |
| 1270 | struct device_node *port; |
| 1271 | int ret; |
| 1272 | int i; |
| 1273 | |
| 1274 | /* |
| 1275 | * Create drm_plane for primary and cursor planes first, since we need |
| 1276 | * to pass them to drm_crtc_init_with_planes, which sets the |
| 1277 | * "possible_crtcs" to the newly initialized crtc. |
| 1278 | */ |
| 1279 | for (i = 0; i < vop_data->win_size; i++) { |
| 1280 | struct vop_win *vop_win = &vop->win[i]; |
| 1281 | const struct vop_win_data *win_data = vop_win->data; |
| 1282 | |
| 1283 | if (win_data->type != DRM_PLANE_TYPE_PRIMARY && |
| 1284 | win_data->type != DRM_PLANE_TYPE_CURSOR) |
| 1285 | continue; |
| 1286 | |
| 1287 | ret = drm_universal_plane_init(vop->drm_dev, &vop_win->base, |
| 1288 | 0, &vop_plane_funcs, |
| 1289 | win_data->phy->data_formats, |
| 1290 | win_data->phy->nformats, |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame^] | 1291 | NULL, win_data->type, NULL); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1292 | if (ret) { |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 1293 | DRM_DEV_ERROR(vop->dev, "failed to init plane %d\n", |
| 1294 | ret); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1295 | goto err_cleanup_planes; |
| 1296 | } |
| 1297 | |
| 1298 | plane = &vop_win->base; |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1299 | drm_plane_helper_add(plane, &plane_helper_funcs); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1300 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
| 1301 | primary = plane; |
| 1302 | else if (plane->type == DRM_PLANE_TYPE_CURSOR) |
| 1303 | cursor = plane; |
| 1304 | } |
| 1305 | |
| 1306 | ret = drm_crtc_init_with_planes(drm_dev, crtc, primary, cursor, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 1307 | &vop_crtc_funcs, NULL); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1308 | if (ret) |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1309 | goto err_cleanup_planes; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1310 | |
| 1311 | drm_crtc_helper_add(crtc, &vop_crtc_helper_funcs); |
| 1312 | |
| 1313 | /* |
| 1314 | * Create drm_planes for overlay windows with possible_crtcs restricted |
| 1315 | * to the newly created crtc. |
| 1316 | */ |
| 1317 | for (i = 0; i < vop_data->win_size; i++) { |
| 1318 | struct vop_win *vop_win = &vop->win[i]; |
| 1319 | const struct vop_win_data *win_data = vop_win->data; |
| 1320 | unsigned long possible_crtcs = 1 << drm_crtc_index(crtc); |
| 1321 | |
| 1322 | if (win_data->type != DRM_PLANE_TYPE_OVERLAY) |
| 1323 | continue; |
| 1324 | |
| 1325 | ret = drm_universal_plane_init(vop->drm_dev, &vop_win->base, |
| 1326 | possible_crtcs, |
| 1327 | &vop_plane_funcs, |
| 1328 | win_data->phy->data_formats, |
| 1329 | win_data->phy->nformats, |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame^] | 1330 | NULL, win_data->type, NULL); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1331 | if (ret) { |
Sean Paul | ee4d789 | 2016-08-12 13:00:54 -0400 | [diff] [blame] | 1332 | DRM_DEV_ERROR(vop->dev, "failed to init overlay %d\n", |
| 1333 | ret); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1334 | goto err_cleanup_crtc; |
| 1335 | } |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1336 | drm_plane_helper_add(&vop_win->base, &plane_helper_funcs); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | port = of_get_child_by_name(dev->of_node, "port"); |
| 1340 | if (!port) { |
Rob Herring | 4bf9914 | 2017-07-18 16:43:04 -0500 | [diff] [blame] | 1341 | DRM_DEV_ERROR(vop->dev, "no port node found in %pOF\n", |
| 1342 | dev->of_node); |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1343 | ret = -ENOENT; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1344 | goto err_cleanup_crtc; |
| 1345 | } |
| 1346 | |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1347 | drm_flip_work_init(&vop->fb_unref_work, "fb_unref", |
| 1348 | vop_fb_unref_worker); |
| 1349 | |
Mark Yao | 1067219 | 2015-02-04 13:10:31 +0800 | [diff] [blame] | 1350 | init_completion(&vop->dsp_hold_completion); |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1351 | init_completion(&vop->line_flag_completion); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1352 | crtc->port = port; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1353 | |
| 1354 | return 0; |
| 1355 | |
| 1356 | err_cleanup_crtc: |
| 1357 | drm_crtc_cleanup(crtc); |
| 1358 | err_cleanup_planes: |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1359 | list_for_each_entry_safe(plane, tmp, &drm_dev->mode_config.plane_list, |
| 1360 | head) |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1361 | drm_plane_cleanup(plane); |
| 1362 | return ret; |
| 1363 | } |
| 1364 | |
| 1365 | static void vop_destroy_crtc(struct vop *vop) |
| 1366 | { |
| 1367 | struct drm_crtc *crtc = &vop->crtc; |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1368 | struct drm_device *drm_dev = vop->drm_dev; |
| 1369 | struct drm_plane *plane, *tmp; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1370 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1371 | of_node_put(crtc->port); |
Douglas Anderson | 328b51c | 2016-03-07 14:00:52 -0800 | [diff] [blame] | 1372 | |
| 1373 | /* |
| 1374 | * We need to cleanup the planes now. Why? |
| 1375 | * |
| 1376 | * The planes are "&vop->win[i].base". That means the memory is |
| 1377 | * all part of the big "struct vop" chunk of memory. That memory |
| 1378 | * was devm allocated and associated with this component. We need to |
| 1379 | * free it ourselves before vop_unbind() finishes. |
| 1380 | */ |
| 1381 | list_for_each_entry_safe(plane, tmp, &drm_dev->mode_config.plane_list, |
| 1382 | head) |
| 1383 | vop_plane_destroy(plane); |
| 1384 | |
| 1385 | /* |
| 1386 | * Destroy CRTC after vop_plane_destroy() since vop_disable_plane() |
| 1387 | * references the CRTC. |
| 1388 | */ |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1389 | drm_crtc_cleanup(crtc); |
Tomasz Figa | 47a7eb4 | 2016-09-14 21:54:57 +0900 | [diff] [blame] | 1390 | drm_flip_work_cleanup(&vop->fb_unref_work); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static int vop_initial(struct vop *vop) |
| 1394 | { |
| 1395 | const struct vop_data *vop_data = vop->data; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1396 | struct reset_control *ahb_rst; |
| 1397 | int i, ret; |
| 1398 | |
| 1399 | vop->hclk = devm_clk_get(vop->dev, "hclk_vop"); |
| 1400 | if (IS_ERR(vop->hclk)) { |
| 1401 | dev_err(vop->dev, "failed to get hclk source\n"); |
| 1402 | return PTR_ERR(vop->hclk); |
| 1403 | } |
| 1404 | vop->aclk = devm_clk_get(vop->dev, "aclk_vop"); |
| 1405 | if (IS_ERR(vop->aclk)) { |
| 1406 | dev_err(vop->dev, "failed to get aclk source\n"); |
| 1407 | return PTR_ERR(vop->aclk); |
| 1408 | } |
| 1409 | vop->dclk = devm_clk_get(vop->dev, "dclk_vop"); |
| 1410 | if (IS_ERR(vop->dclk)) { |
| 1411 | dev_err(vop->dev, "failed to get dclk source\n"); |
| 1412 | return PTR_ERR(vop->dclk); |
| 1413 | } |
| 1414 | |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1415 | ret = pm_runtime_get_sync(vop->dev); |
| 1416 | if (ret < 0) { |
| 1417 | dev_err(vop->dev, "failed to get pm runtime: %d\n", ret); |
| 1418 | return ret; |
| 1419 | } |
| 1420 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1421 | ret = clk_prepare(vop->dclk); |
| 1422 | if (ret < 0) { |
| 1423 | dev_err(vop->dev, "failed to prepare dclk\n"); |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1424 | goto err_put_pm_runtime; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1427 | /* Enable both the hclk and aclk to setup the vop */ |
| 1428 | ret = clk_prepare_enable(vop->hclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1429 | if (ret < 0) { |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1430 | dev_err(vop->dev, "failed to prepare/enable hclk\n"); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1431 | goto err_unprepare_dclk; |
| 1432 | } |
| 1433 | |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1434 | ret = clk_prepare_enable(vop->aclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1435 | if (ret < 0) { |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1436 | dev_err(vop->dev, "failed to prepare/enable aclk\n"); |
| 1437 | goto err_disable_hclk; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1438 | } |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1439 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1440 | /* |
| 1441 | * do hclk_reset, reset all vop registers. |
| 1442 | */ |
| 1443 | ahb_rst = devm_reset_control_get(vop->dev, "ahb"); |
| 1444 | if (IS_ERR(ahb_rst)) { |
| 1445 | dev_err(vop->dev, "failed to get ahb reset\n"); |
| 1446 | ret = PTR_ERR(ahb_rst); |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1447 | goto err_disable_aclk; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1448 | } |
| 1449 | reset_control_assert(ahb_rst); |
| 1450 | usleep_range(10, 20); |
| 1451 | reset_control_deassert(ahb_rst); |
| 1452 | |
| 1453 | memcpy(vop->regsbak, vop->regs, vop->len); |
| 1454 | |
Mark yao | 9a61c54 | 2017-07-28 14:06:25 +0800 | [diff] [blame] | 1455 | VOP_REG_SET(vop, misc, global_regdone_en, 1); |
| 1456 | VOP_REG_SET(vop, common, dsp_blank, 0); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1457 | |
| 1458 | for (i = 0; i < vop_data->win_size; i++) { |
| 1459 | const struct vop_win_data *win = &vop_data->win[i]; |
Mark yao | 9dd2aca | 2017-07-26 14:19:39 +0800 | [diff] [blame] | 1460 | int channel = i * 2 + 1; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1461 | |
Mark yao | 9dd2aca | 2017-07-26 14:19:39 +0800 | [diff] [blame] | 1462 | VOP_WIN_SET(vop, win, channel, (channel + 1) << 4 | channel); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1463 | VOP_WIN_SET(vop, win, enable, 0); |
Mark yao | 60b7ae7 | 2017-07-26 14:19:05 +0800 | [diff] [blame] | 1464 | VOP_WIN_SET(vop, win, gate, 1); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | vop_cfg_done(vop); |
| 1468 | |
| 1469 | /* |
| 1470 | * do dclk_reset, let all config take affect. |
| 1471 | */ |
| 1472 | vop->dclk_rst = devm_reset_control_get(vop->dev, "dclk"); |
| 1473 | if (IS_ERR(vop->dclk_rst)) { |
| 1474 | dev_err(vop->dev, "failed to get dclk reset\n"); |
| 1475 | ret = PTR_ERR(vop->dclk_rst); |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1476 | goto err_disable_aclk; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1477 | } |
| 1478 | reset_control_assert(vop->dclk_rst); |
| 1479 | usleep_range(10, 20); |
| 1480 | reset_control_deassert(vop->dclk_rst); |
| 1481 | |
| 1482 | clk_disable(vop->hclk); |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1483 | clk_disable(vop->aclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1484 | |
Mark Yao | 31e980c | 2015-01-22 14:37:56 +0800 | [diff] [blame] | 1485 | vop->is_enabled = false; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1486 | |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1487 | pm_runtime_put_sync(vop->dev); |
| 1488 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1489 | return 0; |
| 1490 | |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1491 | err_disable_aclk: |
| 1492 | clk_disable_unprepare(vop->aclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1493 | err_disable_hclk: |
Sjoerd Simons | d7b53fd | 2015-11-06 13:22:24 +0100 | [diff] [blame] | 1494 | clk_disable_unprepare(vop->hclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1495 | err_unprepare_dclk: |
| 1496 | clk_unprepare(vop->dclk); |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1497 | err_put_pm_runtime: |
| 1498 | pm_runtime_put_sync(vop->dev); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1499 | return ret; |
| 1500 | } |
| 1501 | |
| 1502 | /* |
| 1503 | * Initialize the vop->win array elements. |
| 1504 | */ |
| 1505 | static void vop_win_init(struct vop *vop) |
| 1506 | { |
| 1507 | const struct vop_data *vop_data = vop->data; |
| 1508 | unsigned int i; |
| 1509 | |
| 1510 | for (i = 0; i < vop_data->win_size; i++) { |
| 1511 | struct vop_win *vop_win = &vop->win[i]; |
| 1512 | const struct vop_win_data *win_data = &vop_data->win[i]; |
| 1513 | |
| 1514 | vop_win->data = win_data; |
| 1515 | vop_win->vop = vop; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1516 | } |
| 1517 | } |
| 1518 | |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1519 | /** |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1520 | * rockchip_drm_wait_vact_end |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1521 | * @crtc: CRTC to enable line flag |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1522 | * @mstimeout: millisecond for timeout |
| 1523 | * |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1524 | * Wait for vact_end line flag irq or timeout. |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1525 | * |
| 1526 | * Returns: |
| 1527 | * Zero on success, negative errno on failure. |
| 1528 | */ |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1529 | int rockchip_drm_wait_vact_end(struct drm_crtc *crtc, unsigned int mstimeout) |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1530 | { |
| 1531 | struct vop *vop = to_vop(crtc); |
| 1532 | unsigned long jiffies_left; |
| 1533 | |
| 1534 | if (!crtc || !vop->is_enabled) |
| 1535 | return -ENODEV; |
| 1536 | |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1537 | if (mstimeout <= 0) |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1538 | return -EINVAL; |
| 1539 | |
| 1540 | if (vop_line_flag_irq_is_enabled(vop)) |
| 1541 | return -EBUSY; |
| 1542 | |
| 1543 | reinit_completion(&vop->line_flag_completion); |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1544 | vop_line_flag_irq_enable(vop); |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1545 | |
| 1546 | jiffies_left = wait_for_completion_timeout(&vop->line_flag_completion, |
| 1547 | msecs_to_jiffies(mstimeout)); |
| 1548 | vop_line_flag_irq_disable(vop); |
| 1549 | |
| 1550 | if (jiffies_left == 0) { |
| 1551 | dev_err(vop->dev, "Timeout waiting for IRQ\n"); |
| 1552 | return -ETIMEDOUT; |
| 1553 | } |
| 1554 | |
| 1555 | return 0; |
| 1556 | } |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 1557 | EXPORT_SYMBOL(rockchip_drm_wait_vact_end); |
Yakir Yang | 69c34e4 | 2016-07-24 14:57:40 +0800 | [diff] [blame] | 1558 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1559 | static int vop_bind(struct device *dev, struct device *master, void *data) |
| 1560 | { |
| 1561 | struct platform_device *pdev = to_platform_device(dev); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1562 | const struct vop_data *vop_data; |
| 1563 | struct drm_device *drm_dev = data; |
| 1564 | struct vop *vop; |
| 1565 | struct resource *res; |
| 1566 | size_t alloc_size; |
Heiko Stuebner | 3ea6892 | 2015-04-20 01:00:53 +0200 | [diff] [blame] | 1567 | int ret, irq; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1568 | |
Mark Yao | a67719d | 2015-12-15 08:58:26 +0800 | [diff] [blame] | 1569 | vop_data = of_device_get_match_data(dev); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1570 | if (!vop_data) |
| 1571 | return -ENODEV; |
| 1572 | |
| 1573 | /* Allocate vop struct and its vop_win array */ |
| 1574 | alloc_size = sizeof(*vop) + sizeof(*vop->win) * vop_data->win_size; |
| 1575 | vop = devm_kzalloc(dev, alloc_size, GFP_KERNEL); |
| 1576 | if (!vop) |
| 1577 | return -ENOMEM; |
| 1578 | |
| 1579 | vop->dev = dev; |
| 1580 | vop->data = vop_data; |
| 1581 | vop->drm_dev = drm_dev; |
| 1582 | dev_set_drvdata(dev, vop); |
| 1583 | |
| 1584 | vop_win_init(vop); |
| 1585 | |
| 1586 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1587 | vop->len = resource_size(res); |
| 1588 | vop->regs = devm_ioremap_resource(dev, res); |
| 1589 | if (IS_ERR(vop->regs)) |
| 1590 | return PTR_ERR(vop->regs); |
| 1591 | |
| 1592 | vop->regsbak = devm_kzalloc(dev, vop->len, GFP_KERNEL); |
| 1593 | if (!vop->regsbak) |
| 1594 | return -ENOMEM; |
| 1595 | |
Heiko Stuebner | 3ea6892 | 2015-04-20 01:00:53 +0200 | [diff] [blame] | 1596 | irq = platform_get_irq(pdev, 0); |
| 1597 | if (irq < 0) { |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1598 | dev_err(dev, "cannot find irq for vop\n"); |
Heiko Stuebner | 3ea6892 | 2015-04-20 01:00:53 +0200 | [diff] [blame] | 1599 | return irq; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1600 | } |
Heiko Stuebner | 3ea6892 | 2015-04-20 01:00:53 +0200 | [diff] [blame] | 1601 | vop->irq = (unsigned int)irq; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1602 | |
| 1603 | spin_lock_init(&vop->reg_lock); |
| 1604 | spin_lock_init(&vop->irq_lock); |
| 1605 | |
| 1606 | mutex_init(&vop->vsync_mutex); |
| 1607 | |
Mark Yao | 63ebb9f | 2015-11-30 18:22:42 +0800 | [diff] [blame] | 1608 | ret = devm_request_irq(dev, vop->irq, vop_isr, |
| 1609 | IRQF_SHARED, dev_name(dev), vop); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1610 | if (ret) |
| 1611 | return ret; |
| 1612 | |
| 1613 | /* IRQ is initially disabled; it gets enabled in power_on */ |
| 1614 | disable_irq(vop->irq); |
| 1615 | |
| 1616 | ret = vop_create_crtc(vop); |
| 1617 | if (ret) |
Sean Paul | 8c763c9 | 2016-09-16 14:22:03 -0400 | [diff] [blame] | 1618 | goto err_enable_irq; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1619 | |
| 1620 | pm_runtime_enable(&pdev->dev); |
Yakir Yang | 5182c1a | 2016-07-24 14:57:44 +0800 | [diff] [blame] | 1621 | |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1622 | ret = vop_initial(vop); |
| 1623 | if (ret < 0) { |
| 1624 | dev_err(&pdev->dev, "cannot initial vop dev - err %d\n", ret); |
| 1625 | goto err_disable_pm_runtime; |
| 1626 | } |
| 1627 | |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1628 | return 0; |
Sean Paul | 8c763c9 | 2016-09-16 14:22:03 -0400 | [diff] [blame] | 1629 | |
Jeffy Chen | 5e57037 | 2017-04-06 20:31:20 +0800 | [diff] [blame] | 1630 | err_disable_pm_runtime: |
| 1631 | pm_runtime_disable(&pdev->dev); |
| 1632 | vop_destroy_crtc(vop); |
Sean Paul | 8c763c9 | 2016-09-16 14:22:03 -0400 | [diff] [blame] | 1633 | err_enable_irq: |
| 1634 | enable_irq(vop->irq); /* To balance out the disable_irq above */ |
| 1635 | return ret; |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static void vop_unbind(struct device *dev, struct device *master, void *data) |
| 1639 | { |
| 1640 | struct vop *vop = dev_get_drvdata(dev); |
| 1641 | |
| 1642 | pm_runtime_disable(dev); |
| 1643 | vop_destroy_crtc(vop); |
Jeffy Chen | ec6e776 | 2017-04-06 20:31:21 +0800 | [diff] [blame] | 1644 | |
| 1645 | clk_unprepare(vop->aclk); |
| 1646 | clk_unprepare(vop->hclk); |
| 1647 | clk_unprepare(vop->dclk); |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Mark Yao | a67719d | 2015-12-15 08:58:26 +0800 | [diff] [blame] | 1650 | const struct component_ops vop_component_ops = { |
Mark Yao | 2048e32 | 2014-08-22 18:36:26 +0800 | [diff] [blame] | 1651 | .bind = vop_bind, |
| 1652 | .unbind = vop_unbind, |
| 1653 | }; |
Stephen Rothwell | 54255e8 | 2015-12-31 13:40:11 +1100 | [diff] [blame] | 1654 | EXPORT_SYMBOL_GPL(vop_component_ops); |