Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * rcar_du_crtc.c -- R-Car Display Unit CRTCs |
| 3 | * |
Laurent Pinchart | 2427b30 | 2015-09-07 17:34:26 +0300 | [diff] [blame] | 4 | * Copyright (C) 2013-2015 Renesas Electronics Corporation |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 5 | * |
| 6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/mutex.h> |
| 16 | |
| 17 | #include <drm/drmP.h> |
Laurent Pinchart | 3e8da87 | 2015-02-20 11:30:59 +0200 | [diff] [blame] | 18 | #include <drm/drm_atomic.h> |
| 19 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 20 | #include <drm/drm_crtc.h> |
| 21 | #include <drm/drm_crtc_helper.h> |
| 22 | #include <drm/drm_fb_cma_helper.h> |
| 23 | #include <drm/drm_gem_cma_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 24 | #include <drm/drm_plane_helper.h> |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 25 | |
| 26 | #include "rcar_du_crtc.h" |
| 27 | #include "rcar_du_drv.h" |
| 28 | #include "rcar_du_kms.h" |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 29 | #include "rcar_du_plane.h" |
| 30 | #include "rcar_du_regs.h" |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 31 | #include "rcar_du_vsp.h" |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 32 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 33 | static u32 rcar_du_crtc_read(struct rcar_du_crtc *rcrtc, u32 reg) |
| 34 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 35 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 36 | |
| 37 | return rcar_du_read(rcdu, rcrtc->mmio_offset + reg); |
| 38 | } |
| 39 | |
| 40 | static void rcar_du_crtc_write(struct rcar_du_crtc *rcrtc, u32 reg, u32 data) |
| 41 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 42 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 43 | |
| 44 | rcar_du_write(rcdu, rcrtc->mmio_offset + reg, data); |
| 45 | } |
| 46 | |
| 47 | static void rcar_du_crtc_clr(struct rcar_du_crtc *rcrtc, u32 reg, u32 clr) |
| 48 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 49 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 50 | |
| 51 | rcar_du_write(rcdu, rcrtc->mmio_offset + reg, |
| 52 | rcar_du_read(rcdu, rcrtc->mmio_offset + reg) & ~clr); |
| 53 | } |
| 54 | |
| 55 | static void rcar_du_crtc_set(struct rcar_du_crtc *rcrtc, u32 reg, u32 set) |
| 56 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 57 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 58 | |
| 59 | rcar_du_write(rcdu, rcrtc->mmio_offset + reg, |
| 60 | rcar_du_read(rcdu, rcrtc->mmio_offset + reg) | set); |
| 61 | } |
| 62 | |
| 63 | static void rcar_du_crtc_clr_set(struct rcar_du_crtc *rcrtc, u32 reg, |
| 64 | u32 clr, u32 set) |
| 65 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 66 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 67 | u32 value = rcar_du_read(rcdu, rcrtc->mmio_offset + reg); |
| 68 | |
| 69 | rcar_du_write(rcdu, rcrtc->mmio_offset + reg, (value & ~clr) | set); |
| 70 | } |
| 71 | |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 72 | static int rcar_du_crtc_get(struct rcar_du_crtc *rcrtc) |
| 73 | { |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 74 | int ret; |
| 75 | |
| 76 | ret = clk_prepare_enable(rcrtc->clock); |
| 77 | if (ret < 0) |
| 78 | return ret; |
| 79 | |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 80 | ret = clk_prepare_enable(rcrtc->extclock); |
| 81 | if (ret < 0) |
| 82 | goto error_clock; |
| 83 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 84 | ret = rcar_du_group_get(rcrtc->group); |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 85 | if (ret < 0) |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 86 | goto error_group; |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 87 | |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | |
| 90 | error_group: |
| 91 | clk_disable_unprepare(rcrtc->extclock); |
| 92 | error_clock: |
| 93 | clk_disable_unprepare(rcrtc->clock); |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static void rcar_du_crtc_put(struct rcar_du_crtc *rcrtc) |
| 98 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 99 | rcar_du_group_put(rcrtc->group); |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 100 | |
| 101 | clk_disable_unprepare(rcrtc->extclock); |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 102 | clk_disable_unprepare(rcrtc->clock); |
| 103 | } |
| 104 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 105 | /* ----------------------------------------------------------------------------- |
| 106 | * Hardware Setup |
| 107 | */ |
| 108 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 109 | static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc) |
| 110 | { |
Laurent Pinchart | 845f463 | 2015-02-18 15:47:27 +0200 | [diff] [blame] | 111 | const struct drm_display_mode *mode = &rcrtc->crtc.state->adjusted_mode; |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 112 | unsigned long mode_clock = mode->clock * 1000; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 113 | unsigned long clk; |
| 114 | u32 value; |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 115 | u32 escr; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 116 | u32 div; |
| 117 | |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 118 | /* Compute the clock divisor and select the internal or external dot |
| 119 | * clock based on the requested frequency. |
| 120 | */ |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 121 | clk = clk_get_rate(rcrtc->clock); |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 122 | div = DIV_ROUND_CLOSEST(clk, mode_clock); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 123 | div = clamp(div, 1U, 64U) - 1; |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 124 | escr = div | ESCR_DCLKSEL_CLKS; |
| 125 | |
| 126 | if (rcrtc->extclock) { |
| 127 | unsigned long extclk; |
| 128 | unsigned long extrate; |
| 129 | unsigned long rate; |
| 130 | u32 extdiv; |
| 131 | |
| 132 | extclk = clk_get_rate(rcrtc->extclock); |
| 133 | extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock); |
| 134 | extdiv = clamp(extdiv, 1U, 64U) - 1; |
| 135 | |
| 136 | rate = clk / (div + 1); |
| 137 | extrate = extclk / (extdiv + 1); |
| 138 | |
| 139 | if (abs((long)extrate - (long)mode_clock) < |
| 140 | abs((long)rate - (long)mode_clock)) { |
| 141 | dev_dbg(rcrtc->group->dev->dev, |
| 142 | "crtc%u: using external clock\n", rcrtc->index); |
| 143 | escr = extdiv | ESCR_DCLKSEL_DCLKIN; |
| 144 | } |
| 145 | } |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 146 | |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 147 | rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR, |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 148 | escr); |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 149 | rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 150 | |
| 151 | /* Signal polarities */ |
| 152 | value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL) |
| 153 | | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL) |
Laurent Pinchart | d792bc7 | 2015-09-07 22:02:14 +0300 | [diff] [blame] | 154 | | DSMR_DIPM_DISP | DSMR_CSPM; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 155 | rcar_du_crtc_write(rcrtc, DSMR, value); |
| 156 | |
| 157 | /* Display timings */ |
| 158 | rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19); |
| 159 | rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start + |
| 160 | mode->hdisplay - 19); |
| 161 | rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end - |
| 162 | mode->hsync_start - 1); |
| 163 | rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1); |
| 164 | |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 165 | rcar_du_crtc_write(rcrtc, VDSR, mode->crtc_vtotal - |
| 166 | mode->crtc_vsync_end - 2); |
| 167 | rcar_du_crtc_write(rcrtc, VDER, mode->crtc_vtotal - |
| 168 | mode->crtc_vsync_end + |
| 169 | mode->crtc_vdisplay - 2); |
| 170 | rcar_du_crtc_write(rcrtc, VSPR, mode->crtc_vtotal - |
| 171 | mode->crtc_vsync_end + |
| 172 | mode->crtc_vsync_start - 1); |
| 173 | rcar_du_crtc_write(rcrtc, VCR, mode->crtc_vtotal - 1); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 174 | |
| 175 | rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start); |
| 176 | rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay); |
| 177 | } |
| 178 | |
Laurent Pinchart | ef67a90 | 2013-06-17 03:13:11 +0200 | [diff] [blame] | 179 | void rcar_du_crtc_route_output(struct drm_crtc *crtc, |
| 180 | enum rcar_du_output output) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 181 | { |
| 182 | struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); |
Laurent Pinchart | ef67a90 | 2013-06-17 03:13:11 +0200 | [diff] [blame] | 183 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 184 | |
| 185 | /* Store the route from the CRTC output to the DU output. The DU will be |
| 186 | * configured when starting the CRTC. |
| 187 | */ |
Laurent Pinchart | ef67a90 | 2013-06-17 03:13:11 +0200 | [diff] [blame] | 188 | rcrtc->outputs |= BIT(output); |
Laurent Pinchart | 7cbc05c | 2013-06-17 03:20:08 +0200 | [diff] [blame] | 189 | |
Laurent Pinchart | 0c1c877 | 2014-12-09 00:21:12 +0200 | [diff] [blame] | 190 | /* Store RGB routing to DPAD0, the hardware will be configured when |
| 191 | * starting the CRTC. |
| 192 | */ |
| 193 | if (output == RCAR_DU_OUTPUT_DPAD0) |
Laurent Pinchart | 7cbc05c | 2013-06-17 03:20:08 +0200 | [diff] [blame] | 194 | rcdu->dpad0_source = rcrtc->index; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 197 | static unsigned int plane_zpos(struct rcar_du_plane *plane) |
| 198 | { |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 199 | return to_rcar_plane_state(plane->plane.state)->zpos; |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 202 | static const struct rcar_du_format_info * |
| 203 | plane_format(struct rcar_du_plane *plane) |
| 204 | { |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 205 | return to_rcar_plane_state(plane->plane.state)->format; |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 208 | static void rcar_du_crtc_update_planes(struct rcar_du_crtc *rcrtc) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 209 | { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 210 | struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES]; |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 211 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 212 | unsigned int num_planes = 0; |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 213 | unsigned int dptsr_planes; |
| 214 | unsigned int hwplanes = 0; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 215 | unsigned int prio = 0; |
| 216 | unsigned int i; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 217 | u32 dspr = 0; |
| 218 | |
Laurent Pinchart | d6aed57 | 2015-05-25 16:32:45 +0300 | [diff] [blame] | 219 | for (i = 0; i < rcrtc->group->num_planes; ++i) { |
Laurent Pinchart | 99caede | 2015-04-29 00:05:56 +0300 | [diff] [blame] | 220 | struct rcar_du_plane *plane = &rcrtc->group->planes[i]; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 221 | unsigned int j; |
| 222 | |
Laurent Pinchart | 4709419 | 2015-02-22 19:24:59 +0200 | [diff] [blame] | 223 | if (plane->plane.state->crtc != &rcrtc->crtc) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 224 | continue; |
| 225 | |
| 226 | /* Insert the plane in the sorted planes array. */ |
| 227 | for (j = num_planes++; j > 0; --j) { |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 228 | if (plane_zpos(planes[j-1]) <= plane_zpos(plane)) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 229 | break; |
| 230 | planes[j] = planes[j-1]; |
| 231 | } |
| 232 | |
| 233 | planes[j] = plane; |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 234 | prio += plane_format(plane)->planes * 4; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | for (i = 0; i < num_planes; ++i) { |
| 238 | struct rcar_du_plane *plane = planes[i]; |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 239 | struct drm_plane_state *state = plane->plane.state; |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 240 | unsigned int index = to_rcar_plane_state(state)->hwindex; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 241 | |
| 242 | prio -= 4; |
| 243 | dspr |= (index + 1) << prio; |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 244 | hwplanes |= 1 << index; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 245 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 246 | if (plane_format(plane)->planes == 2) { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 247 | index = (index + 1) % 8; |
| 248 | |
| 249 | prio -= 4; |
| 250 | dspr |= (index + 1) << prio; |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 251 | hwplanes |= 1 << index; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 255 | /* If VSP+DU integration is enabled the plane assignment is fixed. */ |
| 256 | if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) { |
Laurent Pinchart | 2427b30 | 2015-09-07 17:34:26 +0300 | [diff] [blame] | 257 | if (rcdu->info->gen < 3) { |
| 258 | dspr = (rcrtc->index % 2) + 1; |
| 259 | hwplanes = 1 << (rcrtc->index % 2); |
| 260 | } else { |
| 261 | dspr = (rcrtc->index % 2) ? 3 : 1; |
| 262 | hwplanes = 1 << ((rcrtc->index % 2) ? 2 : 0); |
| 263 | } |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 264 | } |
| 265 | |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 266 | /* Update the planes to display timing and dot clock generator |
| 267 | * associations. |
| 268 | * |
| 269 | * Updating the DPTSR register requires restarting the CRTC group, |
| 270 | * resulting in visible flicker. To mitigate the issue only update the |
| 271 | * association if needed by enabled planes. Planes being disabled will |
| 272 | * keep their current association. |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 273 | */ |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 274 | mutex_lock(&rcrtc->group->lock); |
| 275 | |
| 276 | dptsr_planes = rcrtc->index % 2 ? rcrtc->group->dptsr_planes | hwplanes |
| 277 | : rcrtc->group->dptsr_planes & ~hwplanes; |
| 278 | |
| 279 | if (dptsr_planes != rcrtc->group->dptsr_planes) { |
| 280 | rcar_du_group_write(rcrtc->group, DPTSR, |
| 281 | (dptsr_planes << 16) | dptsr_planes); |
| 282 | rcrtc->group->dptsr_planes = dptsr_planes; |
| 283 | |
| 284 | if (rcrtc->group->used_crtcs) |
| 285 | rcar_du_group_restart(rcrtc->group); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Laurent Pinchart | 2af0394 | 2013-08-24 02:17:03 +0200 | [diff] [blame] | 288 | /* Restart the group if plane sources have changed. */ |
| 289 | if (rcrtc->group->need_restart) |
| 290 | rcar_du_group_restart(rcrtc->group); |
| 291 | |
Laurent Pinchart | 2a57e9b | 2015-04-28 18:01:45 +0300 | [diff] [blame] | 292 | mutex_unlock(&rcrtc->group->lock); |
| 293 | |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 294 | rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, |
| 295 | dspr); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 298 | /* ----------------------------------------------------------------------------- |
| 299 | * Page Flip |
| 300 | */ |
| 301 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 302 | static void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc) |
| 303 | { |
| 304 | struct drm_pending_vblank_event *event; |
| 305 | struct drm_device *dev = rcrtc->crtc.dev; |
| 306 | unsigned long flags; |
| 307 | |
| 308 | spin_lock_irqsave(&dev->event_lock, flags); |
| 309 | event = rcrtc->event; |
| 310 | rcrtc->event = NULL; |
| 311 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 312 | |
| 313 | if (event == NULL) |
| 314 | return; |
| 315 | |
| 316 | spin_lock_irqsave(&dev->event_lock, flags); |
Gustavo Padovan | 444435b | 2016-04-14 10:48:20 -0700 | [diff] [blame] | 317 | drm_crtc_send_vblank_event(&rcrtc->crtc, event); |
Laurent Pinchart | 36693f3 | 2015-02-18 13:21:56 +0200 | [diff] [blame] | 318 | wake_up(&rcrtc->flip_wait); |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 319 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 320 | |
Laurent Pinchart | 0cd90a5 | 2015-02-18 13:14:46 +0200 | [diff] [blame] | 321 | drm_crtc_vblank_put(&rcrtc->crtc); |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Laurent Pinchart | 36693f3 | 2015-02-18 13:21:56 +0200 | [diff] [blame] | 324 | static bool rcar_du_crtc_page_flip_pending(struct rcar_du_crtc *rcrtc) |
| 325 | { |
| 326 | struct drm_device *dev = rcrtc->crtc.dev; |
| 327 | unsigned long flags; |
| 328 | bool pending; |
| 329 | |
| 330 | spin_lock_irqsave(&dev->event_lock, flags); |
| 331 | pending = rcrtc->event != NULL; |
| 332 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 333 | |
| 334 | return pending; |
| 335 | } |
| 336 | |
| 337 | static void rcar_du_crtc_wait_page_flip(struct rcar_du_crtc *rcrtc) |
| 338 | { |
| 339 | struct rcar_du_device *rcdu = rcrtc->group->dev; |
| 340 | |
| 341 | if (wait_event_timeout(rcrtc->flip_wait, |
| 342 | !rcar_du_crtc_page_flip_pending(rcrtc), |
| 343 | msecs_to_jiffies(50))) |
| 344 | return; |
| 345 | |
| 346 | dev_warn(rcdu->dev, "page flip timeout\n"); |
| 347 | |
| 348 | rcar_du_crtc_finish_page_flip(rcrtc); |
| 349 | } |
| 350 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 351 | /* ----------------------------------------------------------------------------- |
| 352 | * Start/Stop and Suspend/Resume |
| 353 | */ |
| 354 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 355 | static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc) |
| 356 | { |
| 357 | struct drm_crtc *crtc = &rcrtc->crtc; |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 358 | bool interlaced; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 359 | |
| 360 | if (rcrtc->started) |
| 361 | return; |
| 362 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 363 | /* Set display off and background to black */ |
| 364 | rcar_du_crtc_write(rcrtc, DOOR, DOOR_RGB(0, 0, 0)); |
| 365 | rcar_du_crtc_write(rcrtc, BPOR, BPOR_RGB(0, 0, 0)); |
| 366 | |
| 367 | /* Configure display timings and output routing */ |
| 368 | rcar_du_crtc_set_display_timing(rcrtc); |
Laurent Pinchart | 2fd22db | 2013-06-17 00:11:05 +0200 | [diff] [blame] | 369 | rcar_du_group_set_routing(rcrtc->group); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 370 | |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 371 | /* Start with all planes disabled. */ |
| 372 | rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, 0); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 373 | |
| 374 | /* Select master sync mode. This enables display operation in master |
| 375 | * sync mode (with the HSYNC and VSYNC signals configured as outputs and |
| 376 | * actively driven). |
| 377 | */ |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 378 | interlaced = rcrtc->crtc.mode.flags & DRM_MODE_FLAG_INTERLACE; |
| 379 | rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK | DSYSR_SCM_MASK, |
| 380 | (interlaced ? DSYSR_SCM_INT_VIDEO : 0) | |
| 381 | DSYSR_TVM_MASTER); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 382 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 383 | rcar_du_group_start_stop(rcrtc->group, true); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 384 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 385 | /* Enable the VSP compositor. */ |
| 386 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 387 | rcar_du_vsp_enable(rcrtc); |
| 388 | |
Laurent Pinchart | 0cd90a5 | 2015-02-18 13:14:46 +0200 | [diff] [blame] | 389 | /* Turn vertical blanking interrupt reporting back on. */ |
| 390 | drm_crtc_vblank_on(crtc); |
| 391 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 392 | rcrtc->started = true; |
| 393 | } |
| 394 | |
| 395 | static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc) |
| 396 | { |
| 397 | struct drm_crtc *crtc = &rcrtc->crtc; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 398 | |
| 399 | if (!rcrtc->started) |
| 400 | return; |
| 401 | |
Laurent Pinchart | 911316f | 2015-05-14 15:01:47 +0300 | [diff] [blame] | 402 | /* Disable all planes and wait for the change to take effect. This is |
| 403 | * required as the DSnPR registers are updated on vblank, and no vblank |
| 404 | * will occur once the CRTC is stopped. Disabling planes when starting |
| 405 | * the CRTC thus wouldn't be enough as it would start scanning out |
| 406 | * immediately from old frame buffers until the next vblank. |
| 407 | * |
| 408 | * This increases the CRTC stop delay, especially when multiple CRTCs |
| 409 | * are stopped in one operation as we now wait for one vblank per CRTC. |
| 410 | * Whether this can be improved needs to be researched. |
| 411 | */ |
| 412 | rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, 0); |
| 413 | drm_crtc_wait_one_vblank(crtc); |
| 414 | |
Laurent Pinchart | 0cd90a5 | 2015-02-18 13:14:46 +0200 | [diff] [blame] | 415 | /* Disable vertical blanking interrupt reporting. We first need to wait |
| 416 | * for page flip completion before stopping the CRTC as userspace |
| 417 | * expects page flips to eventually complete. |
Laurent Pinchart | 36693f3 | 2015-02-18 13:21:56 +0200 | [diff] [blame] | 418 | */ |
| 419 | rcar_du_crtc_wait_page_flip(rcrtc); |
Laurent Pinchart | 0cd90a5 | 2015-02-18 13:14:46 +0200 | [diff] [blame] | 420 | drm_crtc_vblank_off(crtc); |
Laurent Pinchart | 36693f3 | 2015-02-18 13:21:56 +0200 | [diff] [blame] | 421 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 422 | /* Disable the VSP compositor. */ |
| 423 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 424 | rcar_du_vsp_disable(rcrtc); |
| 425 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 426 | /* Select switch sync mode. This stops display operation and configures |
| 427 | * the HSYNC and VSYNC signals as inputs. |
| 428 | */ |
| 429 | rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH); |
| 430 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 431 | rcar_du_group_start_stop(rcrtc->group, false); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 432 | |
| 433 | rcrtc->started = false; |
| 434 | } |
| 435 | |
| 436 | void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc) |
| 437 | { |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 438 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 439 | rcar_du_vsp_disable(rcrtc); |
| 440 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 441 | rcar_du_crtc_stop(rcrtc); |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 442 | rcar_du_crtc_put(rcrtc); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc) |
| 446 | { |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 447 | unsigned int i; |
| 448 | |
Laurent Pinchart | 6ea22ab | 2016-01-25 00:28:11 +0200 | [diff] [blame] | 449 | if (!rcrtc->crtc.state->active) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 450 | return; |
| 451 | |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 452 | rcar_du_crtc_get(rcrtc); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 453 | rcar_du_crtc_start(rcrtc); |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 454 | |
| 455 | /* Commit the planes state. */ |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 456 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) { |
| 457 | rcar_du_vsp_enable(rcrtc); |
| 458 | } else { |
| 459 | for (i = 0; i < rcrtc->group->num_planes; ++i) { |
| 460 | struct rcar_du_plane *plane = &rcrtc->group->planes[i]; |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 461 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 462 | if (plane->plane.state->crtc != &rcrtc->crtc) |
| 463 | continue; |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 464 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 465 | rcar_du_plane_setup(plane); |
| 466 | } |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 467 | } |
| 468 | |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 469 | rcar_du_crtc_update_planes(rcrtc); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 472 | /* ----------------------------------------------------------------------------- |
| 473 | * CRTC Functions |
| 474 | */ |
| 475 | |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 476 | static void rcar_du_crtc_enable(struct drm_crtc *crtc) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 477 | { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 478 | struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); |
| 479 | |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 480 | rcar_du_crtc_get(rcrtc); |
| 481 | rcar_du_crtc_start(rcrtc); |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void rcar_du_crtc_disable(struct drm_crtc *crtc) |
| 485 | { |
| 486 | struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); |
| 487 | |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 488 | rcar_du_crtc_stop(rcrtc); |
| 489 | rcar_du_crtc_put(rcrtc); |
| 490 | |
Laurent Pinchart | cf1cc6f | 2015-02-20 15:16:55 +0200 | [diff] [blame] | 491 | rcrtc->outputs = 0; |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 492 | } |
| 493 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 494 | static void rcar_du_crtc_atomic_begin(struct drm_crtc *crtc, |
| 495 | struct drm_crtc_state *old_crtc_state) |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 496 | { |
Laurent Pinchart | d574664 | 2015-02-23 01:04:21 +0200 | [diff] [blame] | 497 | struct drm_pending_vblank_event *event = crtc->state->event; |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 498 | struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); |
Laurent Pinchart | d574664 | 2015-02-23 01:04:21 +0200 | [diff] [blame] | 499 | struct drm_device *dev = rcrtc->crtc.dev; |
| 500 | unsigned long flags; |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 501 | |
Laurent Pinchart | d574664 | 2015-02-23 01:04:21 +0200 | [diff] [blame] | 502 | if (event) { |
Laurent Pinchart | d574664 | 2015-02-23 01:04:21 +0200 | [diff] [blame] | 503 | WARN_ON(drm_crtc_vblank_get(crtc) != 0); |
| 504 | |
| 505 | spin_lock_irqsave(&dev->event_lock, flags); |
| 506 | rcrtc->event = event; |
| 507 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 508 | } |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 509 | |
| 510 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 511 | rcar_du_vsp_atomic_begin(rcrtc); |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 512 | } |
| 513 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 514 | static void rcar_du_crtc_atomic_flush(struct drm_crtc *crtc, |
| 515 | struct drm_crtc_state *old_crtc_state) |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 516 | { |
| 517 | struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); |
| 518 | |
Laurent Pinchart | 52055ba | 2015-02-23 01:39:13 +0200 | [diff] [blame] | 519 | rcar_du_crtc_update_planes(rcrtc); |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 520 | |
| 521 | if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 522 | rcar_du_vsp_atomic_flush(rcrtc); |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 525 | static const struct drm_crtc_helper_funcs crtc_helper_funcs = { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 526 | .disable = rcar_du_crtc_disable, |
Laurent Pinchart | beff155 | 2015-02-20 14:05:21 +0200 | [diff] [blame] | 527 | .enable = rcar_du_crtc_enable, |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 528 | .atomic_begin = rcar_du_crtc_atomic_begin, |
| 529 | .atomic_flush = rcar_du_crtc_atomic_flush, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 530 | }; |
| 531 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 532 | static const struct drm_crtc_funcs crtc_funcs = { |
Laurent Pinchart | 3e8da87 | 2015-02-20 11:30:59 +0200 | [diff] [blame] | 533 | .reset = drm_atomic_helper_crtc_reset, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 534 | .destroy = drm_crtc_cleanup, |
Laurent Pinchart | cf1cc6f | 2015-02-20 15:16:55 +0200 | [diff] [blame] | 535 | .set_config = drm_atomic_helper_set_config, |
Laurent Pinchart | d574664 | 2015-02-23 01:04:21 +0200 | [diff] [blame] | 536 | .page_flip = drm_atomic_helper_page_flip, |
Laurent Pinchart | 3e8da87 | 2015-02-20 11:30:59 +0200 | [diff] [blame] | 537 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 538 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 539 | }; |
| 540 | |
Laurent Pinchart | 17f6b8a | 2015-02-18 13:42:40 +0200 | [diff] [blame] | 541 | /* ----------------------------------------------------------------------------- |
| 542 | * Interrupt Handling |
| 543 | */ |
| 544 | |
| 545 | static irqreturn_t rcar_du_crtc_irq(int irq, void *arg) |
| 546 | { |
| 547 | struct rcar_du_crtc *rcrtc = arg; |
| 548 | irqreturn_t ret = IRQ_NONE; |
| 549 | u32 status; |
| 550 | |
| 551 | status = rcar_du_crtc_read(rcrtc, DSSR); |
| 552 | rcar_du_crtc_write(rcrtc, DSRCR, status & DSRCR_MASK); |
| 553 | |
| 554 | if (status & DSSR_FRM) { |
| 555 | drm_handle_vblank(rcrtc->crtc.dev, rcrtc->index); |
| 556 | rcar_du_crtc_finish_page_flip(rcrtc); |
| 557 | ret = IRQ_HANDLED; |
| 558 | } |
| 559 | |
| 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | /* ----------------------------------------------------------------------------- |
| 564 | * Initialization |
| 565 | */ |
| 566 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 567 | int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 568 | { |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 569 | static const unsigned int mmio_offsets[] = { |
Koji Matsuoka | 6a8c49f | 2015-09-04 19:49:05 +0900 | [diff] [blame] | 570 | DU0_REG_OFFSET, DU1_REG_OFFSET, DU2_REG_OFFSET, DU3_REG_OFFSET |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 571 | }; |
| 572 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 573 | struct rcar_du_device *rcdu = rgrp->dev; |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 574 | struct platform_device *pdev = to_platform_device(rcdu->dev); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 575 | struct rcar_du_crtc *rcrtc = &rcdu->crtcs[index]; |
| 576 | struct drm_crtc *crtc = &rcrtc->crtc; |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 577 | struct drm_plane *primary; |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 578 | unsigned int irqflags; |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 579 | struct clk *clk; |
| 580 | char clk_name[9]; |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 581 | char *name; |
| 582 | int irq; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 583 | int ret; |
| 584 | |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 585 | /* Get the CRTC clock and the optional external clock. */ |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 586 | if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) { |
| 587 | sprintf(clk_name, "du.%u", index); |
| 588 | name = clk_name; |
| 589 | } else { |
| 590 | name = NULL; |
| 591 | } |
| 592 | |
| 593 | rcrtc->clock = devm_clk_get(rcdu->dev, name); |
| 594 | if (IS_ERR(rcrtc->clock)) { |
| 595 | dev_err(rcdu->dev, "no clock for CRTC %u\n", index); |
| 596 | return PTR_ERR(rcrtc->clock); |
| 597 | } |
| 598 | |
Laurent Pinchart | 1b30dbd | 2014-12-09 00:24:49 +0200 | [diff] [blame] | 599 | sprintf(clk_name, "dclkin.%u", index); |
| 600 | clk = devm_clk_get(rcdu->dev, clk_name); |
| 601 | if (!IS_ERR(clk)) { |
| 602 | rcrtc->extclock = clk; |
| 603 | } else if (PTR_ERR(rcrtc->clock) == -EPROBE_DEFER) { |
| 604 | dev_info(rcdu->dev, "can't get external clock %u\n", index); |
| 605 | return -EPROBE_DEFER; |
| 606 | } |
| 607 | |
Laurent Pinchart | 36693f3 | 2015-02-18 13:21:56 +0200 | [diff] [blame] | 608 | init_waitqueue_head(&rcrtc->flip_wait); |
| 609 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 610 | rcrtc->group = rgrp; |
Laurent Pinchart | a5f0ef5 | 2013-06-17 00:29:25 +0200 | [diff] [blame] | 611 | rcrtc->mmio_offset = mmio_offsets[index]; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 612 | rcrtc->index = index; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 613 | |
Laurent Pinchart | 6d62ef3 | 2015-09-07 17:14:58 +0300 | [diff] [blame] | 614 | if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) |
| 615 | primary = &rcrtc->vsp->planes[0].plane; |
| 616 | else |
| 617 | primary = &rgrp->planes[index % 2].plane; |
| 618 | |
| 619 | ret = drm_crtc_init_with_planes(rcdu->ddev, crtc, primary, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 620 | NULL, &crtc_funcs, NULL); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 621 | if (ret < 0) |
| 622 | return ret; |
| 623 | |
| 624 | drm_crtc_helper_add(crtc, &crtc_helper_funcs); |
| 625 | |
Laurent Pinchart | 0cd90a5 | 2015-02-18 13:14:46 +0200 | [diff] [blame] | 626 | /* Start with vertical blanking interrupt reporting disabled. */ |
| 627 | drm_crtc_vblank_off(crtc); |
| 628 | |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 629 | /* Register the interrupt handler. */ |
| 630 | if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) { |
| 631 | irq = platform_get_irq(pdev, index); |
| 632 | irqflags = 0; |
| 633 | } else { |
| 634 | irq = platform_get_irq(pdev, 0); |
| 635 | irqflags = IRQF_SHARED; |
| 636 | } |
| 637 | |
| 638 | if (irq < 0) { |
| 639 | dev_err(rcdu->dev, "no IRQ for CRTC %u\n", index); |
Julia Lawall | 6512f5f | 2014-11-23 14:11:17 +0100 | [diff] [blame] | 640 | return irq; |
Laurent Pinchart | f66ee30 | 2013-06-14 14:15:01 +0200 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | ret = devm_request_irq(rcdu->dev, irq, rcar_du_crtc_irq, irqflags, |
| 644 | dev_name(rcdu->dev), rcrtc); |
| 645 | if (ret < 0) { |
| 646 | dev_err(rcdu->dev, |
| 647 | "failed to register IRQ for CRTC %u\n", index); |
| 648 | return ret; |
| 649 | } |
| 650 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | void rcar_du_crtc_enable_vblank(struct rcar_du_crtc *rcrtc, bool enable) |
| 655 | { |
| 656 | if (enable) { |
| 657 | rcar_du_crtc_write(rcrtc, DSRCR, DSRCR_VBCL); |
| 658 | rcar_du_crtc_set(rcrtc, DIER, DIER_VBE); |
| 659 | } else { |
| 660 | rcar_du_crtc_clr(rcrtc, DIER, DIER_VBE); |
| 661 | } |
| 662 | } |