1 1.1 riastrad /* $NetBSD: vlv_dsi.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2013 Intel Corporation 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 1.1 riastrad * DEALINGS IN THE SOFTWARE. 24 1.1 riastrad * 25 1.1 riastrad * Author: Jani Nikula <jani.nikula (at) intel.com> 26 1.1 riastrad */ 27 1.1 riastrad 28 1.1 riastrad #include <sys/cdefs.h> 29 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: vlv_dsi.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $"); 30 1.1 riastrad 31 1.1 riastrad #include <linux/slab.h> 32 1.1 riastrad 33 1.1 riastrad #include <drm/drm_atomic_helper.h> 34 1.1 riastrad #include <drm/drm_crtc.h> 35 1.1 riastrad #include <drm/drm_edid.h> 36 1.1 riastrad #include <drm/drm_mipi_dsi.h> 37 1.1 riastrad 38 1.1 riastrad #include "i915_drv.h" 39 1.1 riastrad #include "intel_atomic.h" 40 1.1 riastrad #include "intel_connector.h" 41 1.1 riastrad #include "intel_display_types.h" 42 1.1 riastrad #include "intel_dsi.h" 43 1.1 riastrad #include "intel_fifo_underrun.h" 44 1.1 riastrad #include "intel_panel.h" 45 1.1 riastrad #include "intel_sideband.h" 46 1.1 riastrad 47 1.1 riastrad /* return pixels in terms of txbyteclkhs */ 48 1.1 riastrad static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count, 49 1.1 riastrad u16 burst_mode_ratio) 50 1.1 riastrad { 51 1.1 riastrad return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio, 52 1.1 riastrad 8 * 100), lane_count); 53 1.1 riastrad } 54 1.1 riastrad 55 1.1 riastrad /* return pixels equvalent to txbyteclkhs */ 56 1.1 riastrad static u16 pixels_from_txbyteclkhs(u16 clk_hs, int bpp, int lane_count, 57 1.1 riastrad u16 burst_mode_ratio) 58 1.1 riastrad { 59 1.1 riastrad return DIV_ROUND_UP((clk_hs * lane_count * 8 * 100), 60 1.1 riastrad (bpp * burst_mode_ratio)); 61 1.1 riastrad } 62 1.1 riastrad 63 1.1 riastrad enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt) 64 1.1 riastrad { 65 1.1 riastrad /* It just so happens the VBT matches register contents. */ 66 1.1 riastrad switch (fmt) { 67 1.1 riastrad case VID_MODE_FORMAT_RGB888: 68 1.1 riastrad return MIPI_DSI_FMT_RGB888; 69 1.1 riastrad case VID_MODE_FORMAT_RGB666: 70 1.1 riastrad return MIPI_DSI_FMT_RGB666; 71 1.1 riastrad case VID_MODE_FORMAT_RGB666_PACKED: 72 1.1 riastrad return MIPI_DSI_FMT_RGB666_PACKED; 73 1.1 riastrad case VID_MODE_FORMAT_RGB565: 74 1.1 riastrad return MIPI_DSI_FMT_RGB565; 75 1.1 riastrad default: 76 1.1 riastrad MISSING_CASE(fmt); 77 1.1 riastrad return MIPI_DSI_FMT_RGB666; 78 1.1 riastrad } 79 1.1 riastrad } 80 1.1 riastrad 81 1.1 riastrad void vlv_dsi_wait_for_fifo_empty(struct intel_dsi *intel_dsi, enum port port) 82 1.1 riastrad { 83 1.1 riastrad struct drm_encoder *encoder = &intel_dsi->base.base; 84 1.1 riastrad struct drm_device *dev = encoder->dev; 85 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 86 1.1 riastrad u32 mask; 87 1.1 riastrad 88 1.1 riastrad mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY | 89 1.1 riastrad LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY; 90 1.1 riastrad 91 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_GEN_FIFO_STAT(port), 92 1.1 riastrad mask, 100)) 93 1.1 riastrad DRM_ERROR("DPI FIFOs are not empty\n"); 94 1.1 riastrad } 95 1.1 riastrad 96 1.1 riastrad static void write_data(struct drm_i915_private *dev_priv, 97 1.1 riastrad i915_reg_t reg, 98 1.1 riastrad const u8 *data, u32 len) 99 1.1 riastrad { 100 1.1 riastrad u32 i, j; 101 1.1 riastrad 102 1.1 riastrad for (i = 0; i < len; i += 4) { 103 1.1 riastrad u32 val = 0; 104 1.1 riastrad 105 1.1 riastrad for (j = 0; j < min_t(u32, len - i, 4); j++) 106 1.1 riastrad val |= *data++ << 8 * j; 107 1.1 riastrad 108 1.1 riastrad I915_WRITE(reg, val); 109 1.1 riastrad } 110 1.1 riastrad } 111 1.1 riastrad 112 1.1 riastrad static void read_data(struct drm_i915_private *dev_priv, 113 1.1 riastrad i915_reg_t reg, 114 1.1 riastrad u8 *data, u32 len) 115 1.1 riastrad { 116 1.1 riastrad u32 i, j; 117 1.1 riastrad 118 1.1 riastrad for (i = 0; i < len; i += 4) { 119 1.1 riastrad u32 val = I915_READ(reg); 120 1.1 riastrad 121 1.1 riastrad for (j = 0; j < min_t(u32, len - i, 4); j++) 122 1.1 riastrad *data++ = val >> 8 * j; 123 1.1 riastrad } 124 1.1 riastrad } 125 1.1 riastrad 126 1.1 riastrad static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host, 127 1.1 riastrad const struct mipi_dsi_msg *msg) 128 1.1 riastrad { 129 1.1 riastrad struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); 130 1.1 riastrad struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev; 131 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 132 1.1 riastrad enum port port = intel_dsi_host->port; 133 1.1 riastrad struct mipi_dsi_packet packet; 134 1.1 riastrad ssize_t ret; 135 1.1 riastrad const u8 *header, *data; 136 1.1 riastrad i915_reg_t data_reg, ctrl_reg; 137 1.1 riastrad u32 data_mask, ctrl_mask; 138 1.1 riastrad 139 1.1 riastrad ret = mipi_dsi_create_packet(&packet, msg); 140 1.1 riastrad if (ret < 0) 141 1.1 riastrad return ret; 142 1.1 riastrad 143 1.1 riastrad header = packet.header; 144 1.1 riastrad data = packet.payload; 145 1.1 riastrad 146 1.1 riastrad if (msg->flags & MIPI_DSI_MSG_USE_LPM) { 147 1.1 riastrad data_reg = MIPI_LP_GEN_DATA(port); 148 1.1 riastrad data_mask = LP_DATA_FIFO_FULL; 149 1.1 riastrad ctrl_reg = MIPI_LP_GEN_CTRL(port); 150 1.1 riastrad ctrl_mask = LP_CTRL_FIFO_FULL; 151 1.1 riastrad } else { 152 1.1 riastrad data_reg = MIPI_HS_GEN_DATA(port); 153 1.1 riastrad data_mask = HS_DATA_FIFO_FULL; 154 1.1 riastrad ctrl_reg = MIPI_HS_GEN_CTRL(port); 155 1.1 riastrad ctrl_mask = HS_CTRL_FIFO_FULL; 156 1.1 riastrad } 157 1.1 riastrad 158 1.1 riastrad /* note: this is never true for reads */ 159 1.1 riastrad if (packet.payload_length) { 160 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port), 161 1.1 riastrad data_mask, 50)) 162 1.1 riastrad DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n"); 163 1.1 riastrad 164 1.1 riastrad write_data(dev_priv, data_reg, packet.payload, 165 1.1 riastrad packet.payload_length); 166 1.1 riastrad } 167 1.1 riastrad 168 1.1 riastrad if (msg->rx_len) { 169 1.1 riastrad I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL); 170 1.1 riastrad } 171 1.1 riastrad 172 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port), 173 1.1 riastrad ctrl_mask, 50)) { 174 1.1 riastrad DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n"); 175 1.1 riastrad } 176 1.1 riastrad 177 1.1 riastrad I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]); 178 1.1 riastrad 179 1.1 riastrad /* ->rx_len is set only for reads */ 180 1.1 riastrad if (msg->rx_len) { 181 1.1 riastrad data_mask = GEN_READ_DATA_AVAIL; 182 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port), 183 1.1 riastrad data_mask, 50)) 184 1.1 riastrad DRM_ERROR("Timeout waiting for read data.\n"); 185 1.1 riastrad 186 1.1 riastrad read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len); 187 1.1 riastrad } 188 1.1 riastrad 189 1.1 riastrad /* XXX: fix for reads and writes */ 190 1.1 riastrad return 4 + packet.payload_length; 191 1.1 riastrad } 192 1.1 riastrad 193 1.1 riastrad static int intel_dsi_host_attach(struct mipi_dsi_host *host, 194 1.1 riastrad struct mipi_dsi_device *dsi) 195 1.1 riastrad { 196 1.1 riastrad return 0; 197 1.1 riastrad } 198 1.1 riastrad 199 1.1 riastrad static int intel_dsi_host_detach(struct mipi_dsi_host *host, 200 1.1 riastrad struct mipi_dsi_device *dsi) 201 1.1 riastrad { 202 1.1 riastrad return 0; 203 1.1 riastrad } 204 1.1 riastrad 205 1.1 riastrad static const struct mipi_dsi_host_ops intel_dsi_host_ops = { 206 1.1 riastrad .attach = intel_dsi_host_attach, 207 1.1 riastrad .detach = intel_dsi_host_detach, 208 1.1 riastrad .transfer = intel_dsi_host_transfer, 209 1.1 riastrad }; 210 1.1 riastrad 211 1.1 riastrad /* 212 1.1 riastrad * send a video mode command 213 1.1 riastrad * 214 1.1 riastrad * XXX: commands with data in MIPI_DPI_DATA? 215 1.1 riastrad */ 216 1.1 riastrad static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs, 217 1.1 riastrad enum port port) 218 1.1 riastrad { 219 1.1 riastrad struct drm_encoder *encoder = &intel_dsi->base.base; 220 1.1 riastrad struct drm_device *dev = encoder->dev; 221 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 222 1.1 riastrad u32 mask; 223 1.1 riastrad 224 1.1 riastrad /* XXX: pipe, hs */ 225 1.1 riastrad if (hs) 226 1.1 riastrad cmd &= ~DPI_LP_MODE; 227 1.1 riastrad else 228 1.1 riastrad cmd |= DPI_LP_MODE; 229 1.1 riastrad 230 1.1 riastrad /* clear bit */ 231 1.1 riastrad I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT); 232 1.1 riastrad 233 1.1 riastrad /* XXX: old code skips write if control unchanged */ 234 1.1 riastrad if (cmd == I915_READ(MIPI_DPI_CONTROL(port))) 235 1.1 riastrad DRM_DEBUG_KMS("Same special packet %02x twice in a row.\n", cmd); 236 1.1 riastrad 237 1.1 riastrad I915_WRITE(MIPI_DPI_CONTROL(port), cmd); 238 1.1 riastrad 239 1.1 riastrad mask = SPL_PKT_SENT_INTERRUPT; 240 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port), mask, 100)) 241 1.1 riastrad DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd); 242 1.1 riastrad 243 1.1 riastrad return 0; 244 1.1 riastrad } 245 1.1 riastrad 246 1.1 riastrad static void band_gap_reset(struct drm_i915_private *dev_priv) 247 1.1 riastrad { 248 1.1 riastrad vlv_flisdsi_get(dev_priv); 249 1.1 riastrad 250 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x08, 0x0001); 251 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x0F, 0x0005); 252 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x0F, 0x0025); 253 1.1 riastrad udelay(150); 254 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x0F, 0x0000); 255 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x08, 0x0000); 256 1.1 riastrad 257 1.1 riastrad vlv_flisdsi_put(dev_priv); 258 1.1 riastrad } 259 1.1 riastrad 260 1.1 riastrad static int intel_dsi_compute_config(struct intel_encoder *encoder, 261 1.1 riastrad struct intel_crtc_state *pipe_config, 262 1.1 riastrad struct drm_connector_state *conn_state) 263 1.1 riastrad { 264 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 265 1.1 riastrad struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, 266 1.1 riastrad base); 267 1.1 riastrad struct intel_connector *intel_connector = intel_dsi->attached_connector; 268 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 269 1.1 riastrad const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; 270 1.1 riastrad struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 271 1.1 riastrad int ret; 272 1.1 riastrad 273 1.1 riastrad DRM_DEBUG_KMS("\n"); 274 1.1 riastrad pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 275 1.1 riastrad 276 1.1 riastrad if (fixed_mode) { 277 1.1 riastrad intel_fixed_panel_mode(fixed_mode, adjusted_mode); 278 1.1 riastrad 279 1.1 riastrad if (HAS_GMCH(dev_priv)) 280 1.1 riastrad intel_gmch_panel_fitting(crtc, pipe_config, 281 1.1 riastrad conn_state->scaling_mode); 282 1.1 riastrad else 283 1.1 riastrad intel_pch_panel_fitting(crtc, pipe_config, 284 1.1 riastrad conn_state->scaling_mode); 285 1.1 riastrad } 286 1.1 riastrad 287 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 288 1.1 riastrad return -EINVAL; 289 1.1 riastrad 290 1.1 riastrad /* DSI uses short packets for sync events, so clear mode flags for DSI */ 291 1.1 riastrad adjusted_mode->flags = 0; 292 1.1 riastrad 293 1.1 riastrad if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888) 294 1.1 riastrad pipe_config->pipe_bpp = 24; 295 1.1 riastrad else 296 1.1 riastrad pipe_config->pipe_bpp = 18; 297 1.1 riastrad 298 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 299 1.1 riastrad /* Enable Frame time stamp based scanline reporting */ 300 1.1 riastrad adjusted_mode->private_flags |= 301 1.1 riastrad I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP; 302 1.1 riastrad 303 1.1 riastrad /* Dual link goes to DSI transcoder A. */ 304 1.1 riastrad if (intel_dsi->ports == BIT(PORT_C)) 305 1.1 riastrad pipe_config->cpu_transcoder = TRANSCODER_DSI_C; 306 1.1 riastrad else 307 1.1 riastrad pipe_config->cpu_transcoder = TRANSCODER_DSI_A; 308 1.1 riastrad 309 1.1 riastrad ret = bxt_dsi_pll_compute(encoder, pipe_config); 310 1.1 riastrad if (ret) 311 1.1 riastrad return -EINVAL; 312 1.1 riastrad } else { 313 1.1 riastrad ret = vlv_dsi_pll_compute(encoder, pipe_config); 314 1.1 riastrad if (ret) 315 1.1 riastrad return -EINVAL; 316 1.1 riastrad } 317 1.1 riastrad 318 1.1 riastrad pipe_config->clock_set = true; 319 1.1 riastrad 320 1.1 riastrad return 0; 321 1.1 riastrad } 322 1.1 riastrad 323 1.1 riastrad static bool glk_dsi_enable_io(struct intel_encoder *encoder) 324 1.1 riastrad { 325 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 326 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 327 1.1 riastrad enum port port; 328 1.1 riastrad u32 tmp; 329 1.1 riastrad bool cold_boot = false; 330 1.1 riastrad 331 1.1 riastrad /* Set the MIPI mode 332 1.1 riastrad * If MIPI_Mode is off, then writing to LP_Wake bit is not reflecting. 333 1.1 riastrad * Power ON MIPI IO first and then write into IO reset and LP wake bits 334 1.1 riastrad */ 335 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 336 1.1 riastrad tmp = I915_READ(MIPI_CTRL(port)); 337 1.1 riastrad I915_WRITE(MIPI_CTRL(port), tmp | GLK_MIPIIO_ENABLE); 338 1.1 riastrad } 339 1.1 riastrad 340 1.1 riastrad /* Put the IO into reset */ 341 1.1 riastrad tmp = I915_READ(MIPI_CTRL(PORT_A)); 342 1.1 riastrad tmp &= ~GLK_MIPIIO_RESET_RELEASED; 343 1.1 riastrad I915_WRITE(MIPI_CTRL(PORT_A), tmp); 344 1.1 riastrad 345 1.1 riastrad /* Program LP Wake */ 346 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 347 1.1 riastrad tmp = I915_READ(MIPI_CTRL(port)); 348 1.1 riastrad if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY)) 349 1.1 riastrad tmp &= ~GLK_LP_WAKE; 350 1.1 riastrad else 351 1.1 riastrad tmp |= GLK_LP_WAKE; 352 1.1 riastrad I915_WRITE(MIPI_CTRL(port), tmp); 353 1.1 riastrad } 354 1.1 riastrad 355 1.1 riastrad /* Wait for Pwr ACK */ 356 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 357 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port), 358 1.1 riastrad GLK_MIPIIO_PORT_POWERED, 20)) 359 1.1 riastrad DRM_ERROR("MIPIO port is powergated\n"); 360 1.1 riastrad } 361 1.1 riastrad 362 1.1 riastrad /* Check for cold boot scenario */ 363 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 364 1.1 riastrad cold_boot |= 365 1.1 riastrad !(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY); 366 1.1 riastrad } 367 1.1 riastrad 368 1.1 riastrad return cold_boot; 369 1.1 riastrad } 370 1.1 riastrad 371 1.1 riastrad static void glk_dsi_device_ready(struct intel_encoder *encoder) 372 1.1 riastrad { 373 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 374 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 375 1.1 riastrad enum port port; 376 1.1 riastrad u32 val; 377 1.1 riastrad 378 1.1 riastrad /* Wait for MIPI PHY status bit to set */ 379 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 380 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port), 381 1.1 riastrad GLK_PHY_STATUS_PORT_READY, 20)) 382 1.1 riastrad DRM_ERROR("PHY is not ON\n"); 383 1.1 riastrad } 384 1.1 riastrad 385 1.1 riastrad /* Get IO out of reset */ 386 1.1 riastrad val = I915_READ(MIPI_CTRL(PORT_A)); 387 1.1 riastrad I915_WRITE(MIPI_CTRL(PORT_A), val | GLK_MIPIIO_RESET_RELEASED); 388 1.1 riastrad 389 1.1 riastrad /* Get IO out of Low power state*/ 390 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 391 1.1 riastrad if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY)) { 392 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 393 1.1 riastrad val &= ~ULPS_STATE_MASK; 394 1.1 riastrad val |= DEVICE_READY; 395 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 396 1.1 riastrad usleep_range(10, 15); 397 1.1 riastrad } else { 398 1.1 riastrad /* Enter ULPS */ 399 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 400 1.1 riastrad val &= ~ULPS_STATE_MASK; 401 1.1 riastrad val |= (ULPS_STATE_ENTER | DEVICE_READY); 402 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 403 1.1 riastrad 404 1.1 riastrad /* Wait for ULPS active */ 405 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port), 406 1.1 riastrad GLK_ULPS_NOT_ACTIVE, 20)) 407 1.1 riastrad DRM_ERROR("ULPS not active\n"); 408 1.1 riastrad 409 1.1 riastrad /* Exit ULPS */ 410 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 411 1.1 riastrad val &= ~ULPS_STATE_MASK; 412 1.1 riastrad val |= (ULPS_STATE_EXIT | DEVICE_READY); 413 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 414 1.1 riastrad 415 1.1 riastrad /* Enter Normal Mode */ 416 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 417 1.1 riastrad val &= ~ULPS_STATE_MASK; 418 1.1 riastrad val |= (ULPS_STATE_NORMAL_OPERATION | DEVICE_READY); 419 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 420 1.1 riastrad 421 1.1 riastrad val = I915_READ(MIPI_CTRL(port)); 422 1.1 riastrad val &= ~GLK_LP_WAKE; 423 1.1 riastrad I915_WRITE(MIPI_CTRL(port), val); 424 1.1 riastrad } 425 1.1 riastrad } 426 1.1 riastrad 427 1.1 riastrad /* Wait for Stop state */ 428 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 429 1.1 riastrad if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port), 430 1.1 riastrad GLK_DATA_LANE_STOP_STATE, 20)) 431 1.1 riastrad DRM_ERROR("Date lane not in STOP state\n"); 432 1.1 riastrad } 433 1.1 riastrad 434 1.1 riastrad /* Wait for AFE LATCH */ 435 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 436 1.1 riastrad if (intel_de_wait_for_set(dev_priv, BXT_MIPI_PORT_CTRL(port), 437 1.1 riastrad AFE_LATCHOUT, 20)) 438 1.1 riastrad DRM_ERROR("D-PHY not entering LP-11 state\n"); 439 1.1 riastrad } 440 1.1 riastrad } 441 1.1 riastrad 442 1.1 riastrad static void bxt_dsi_device_ready(struct intel_encoder *encoder) 443 1.1 riastrad { 444 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 445 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 446 1.1 riastrad enum port port; 447 1.1 riastrad u32 val; 448 1.1 riastrad 449 1.1 riastrad DRM_DEBUG_KMS("\n"); 450 1.1 riastrad 451 1.1 riastrad /* Enable MIPI PHY transparent latch */ 452 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 453 1.1 riastrad val = I915_READ(BXT_MIPI_PORT_CTRL(port)); 454 1.1 riastrad I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD); 455 1.1 riastrad usleep_range(2000, 2500); 456 1.1 riastrad } 457 1.1 riastrad 458 1.1 riastrad /* Clear ULPS and set device ready */ 459 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 460 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 461 1.1 riastrad val &= ~ULPS_STATE_MASK; 462 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 463 1.1 riastrad usleep_range(2000, 2500); 464 1.1 riastrad val |= DEVICE_READY; 465 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 466 1.1 riastrad } 467 1.1 riastrad } 468 1.1 riastrad 469 1.1 riastrad static void vlv_dsi_device_ready(struct intel_encoder *encoder) 470 1.1 riastrad { 471 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 472 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 473 1.1 riastrad enum port port; 474 1.1 riastrad u32 val; 475 1.1 riastrad 476 1.1 riastrad DRM_DEBUG_KMS("\n"); 477 1.1 riastrad 478 1.1 riastrad vlv_flisdsi_get(dev_priv); 479 1.1 riastrad /* program rcomp for compliance, reduce from 50 ohms to 45 ohms 480 1.1 riastrad * needed everytime after power gate */ 481 1.1 riastrad vlv_flisdsi_write(dev_priv, 0x04, 0x0004); 482 1.1 riastrad vlv_flisdsi_put(dev_priv); 483 1.1 riastrad 484 1.1 riastrad /* bandgap reset is needed after everytime we do power gate */ 485 1.1 riastrad band_gap_reset(dev_priv); 486 1.1 riastrad 487 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 488 1.1 riastrad 489 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER); 490 1.1 riastrad usleep_range(2500, 3000); 491 1.1 riastrad 492 1.1 riastrad /* Enable MIPI PHY transparent latch 493 1.1 riastrad * Common bit for both MIPI Port A & MIPI Port C 494 1.1 riastrad * No similar bit in MIPI Port C reg 495 1.1 riastrad */ 496 1.1 riastrad val = I915_READ(MIPI_PORT_CTRL(PORT_A)); 497 1.1 riastrad I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD); 498 1.1 riastrad usleep_range(1000, 1500); 499 1.1 riastrad 500 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT); 501 1.1 riastrad usleep_range(2500, 3000); 502 1.1 riastrad 503 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY); 504 1.1 riastrad usleep_range(2500, 3000); 505 1.1 riastrad } 506 1.1 riastrad } 507 1.1 riastrad 508 1.1 riastrad static void intel_dsi_device_ready(struct intel_encoder *encoder) 509 1.1 riastrad { 510 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 511 1.1 riastrad 512 1.1 riastrad if (IS_GEMINILAKE(dev_priv)) 513 1.1 riastrad glk_dsi_device_ready(encoder); 514 1.1 riastrad else if (IS_GEN9_LP(dev_priv)) 515 1.1 riastrad bxt_dsi_device_ready(encoder); 516 1.1 riastrad else 517 1.1 riastrad vlv_dsi_device_ready(encoder); 518 1.1 riastrad } 519 1.1 riastrad 520 1.1 riastrad static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder) 521 1.1 riastrad { 522 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 523 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 524 1.1 riastrad enum port port; 525 1.1 riastrad u32 val; 526 1.1 riastrad 527 1.1 riastrad /* Enter ULPS */ 528 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 529 1.1 riastrad val = I915_READ(MIPI_DEVICE_READY(port)); 530 1.1 riastrad val &= ~ULPS_STATE_MASK; 531 1.1 riastrad val |= (ULPS_STATE_ENTER | DEVICE_READY); 532 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), val); 533 1.1 riastrad } 534 1.1 riastrad 535 1.1 riastrad /* Wait for MIPI PHY status bit to unset */ 536 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 537 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port), 538 1.1 riastrad GLK_PHY_STATUS_PORT_READY, 20)) 539 1.1 riastrad DRM_ERROR("PHY is not turning OFF\n"); 540 1.1 riastrad } 541 1.1 riastrad 542 1.1 riastrad /* Wait for Pwr ACK bit to unset */ 543 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 544 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port), 545 1.1 riastrad GLK_MIPIIO_PORT_POWERED, 20)) 546 1.1 riastrad DRM_ERROR("MIPI IO Port is not powergated\n"); 547 1.1 riastrad } 548 1.1 riastrad } 549 1.1 riastrad 550 1.1 riastrad static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder) 551 1.1 riastrad { 552 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 553 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 554 1.1 riastrad enum port port; 555 1.1 riastrad u32 tmp; 556 1.1 riastrad 557 1.1 riastrad /* Put the IO into reset */ 558 1.1 riastrad tmp = I915_READ(MIPI_CTRL(PORT_A)); 559 1.1 riastrad tmp &= ~GLK_MIPIIO_RESET_RELEASED; 560 1.1 riastrad I915_WRITE(MIPI_CTRL(PORT_A), tmp); 561 1.1 riastrad 562 1.1 riastrad /* Wait for MIPI PHY status bit to unset */ 563 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 564 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port), 565 1.1 riastrad GLK_PHY_STATUS_PORT_READY, 20)) 566 1.1 riastrad DRM_ERROR("PHY is not turning OFF\n"); 567 1.1 riastrad } 568 1.1 riastrad 569 1.1 riastrad /* Clear MIPI mode */ 570 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 571 1.1 riastrad tmp = I915_READ(MIPI_CTRL(port)); 572 1.1 riastrad tmp &= ~GLK_MIPIIO_ENABLE; 573 1.1 riastrad I915_WRITE(MIPI_CTRL(port), tmp); 574 1.1 riastrad } 575 1.1 riastrad } 576 1.1 riastrad 577 1.1 riastrad static void glk_dsi_clear_device_ready(struct intel_encoder *encoder) 578 1.1 riastrad { 579 1.1 riastrad glk_dsi_enter_low_power_mode(encoder); 580 1.1 riastrad glk_dsi_disable_mipi_io(encoder); 581 1.1 riastrad } 582 1.1 riastrad 583 1.1 riastrad static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder) 584 1.1 riastrad { 585 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 586 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 587 1.1 riastrad enum port port; 588 1.1 riastrad 589 1.1 riastrad DRM_DEBUG_KMS("\n"); 590 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 591 1.1 riastrad /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */ 592 1.1 riastrad i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ? 593 1.1 riastrad BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A); 594 1.1 riastrad u32 val; 595 1.1 riastrad 596 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | 597 1.1 riastrad ULPS_STATE_ENTER); 598 1.1 riastrad usleep_range(2000, 2500); 599 1.1 riastrad 600 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | 601 1.1 riastrad ULPS_STATE_EXIT); 602 1.1 riastrad usleep_range(2000, 2500); 603 1.1 riastrad 604 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | 605 1.1 riastrad ULPS_STATE_ENTER); 606 1.1 riastrad usleep_range(2000, 2500); 607 1.1 riastrad 608 1.1 riastrad /* 609 1.1 riastrad * On VLV/CHV, wait till Clock lanes are in LP-00 state for MIPI 610 1.1 riastrad * Port A only. MIPI Port C has no similar bit for checking. 611 1.1 riastrad */ 612 1.1 riastrad if ((IS_GEN9_LP(dev_priv) || port == PORT_A) && 613 1.1 riastrad intel_de_wait_for_clear(dev_priv, port_ctrl, 614 1.1 riastrad AFE_LATCHOUT, 30)) 615 1.1 riastrad DRM_ERROR("DSI LP not going Low\n"); 616 1.1 riastrad 617 1.1 riastrad /* Disable MIPI PHY transparent latch */ 618 1.1 riastrad val = I915_READ(port_ctrl); 619 1.1 riastrad I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD); 620 1.1 riastrad usleep_range(1000, 1500); 621 1.1 riastrad 622 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), 0x00); 623 1.1 riastrad usleep_range(2000, 2500); 624 1.1 riastrad } 625 1.1 riastrad } 626 1.1 riastrad 627 1.1 riastrad static void intel_dsi_port_enable(struct intel_encoder *encoder, 628 1.1 riastrad const struct intel_crtc_state *crtc_state) 629 1.1 riastrad { 630 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 631 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 632 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 633 1.1 riastrad enum port port; 634 1.1 riastrad 635 1.1 riastrad if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { 636 1.1 riastrad u32 temp; 637 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 638 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 639 1.1 riastrad temp = I915_READ(MIPI_CTRL(port)); 640 1.1 riastrad temp &= ~BXT_PIXEL_OVERLAP_CNT_MASK | 641 1.1 riastrad intel_dsi->pixel_overlap << 642 1.1 riastrad BXT_PIXEL_OVERLAP_CNT_SHIFT; 643 1.1 riastrad I915_WRITE(MIPI_CTRL(port), temp); 644 1.1 riastrad } 645 1.1 riastrad } else { 646 1.1 riastrad temp = I915_READ(VLV_CHICKEN_3); 647 1.1 riastrad temp &= ~PIXEL_OVERLAP_CNT_MASK | 648 1.1 riastrad intel_dsi->pixel_overlap << 649 1.1 riastrad PIXEL_OVERLAP_CNT_SHIFT; 650 1.1 riastrad I915_WRITE(VLV_CHICKEN_3, temp); 651 1.1 riastrad } 652 1.1 riastrad } 653 1.1 riastrad 654 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 655 1.1 riastrad i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ? 656 1.1 riastrad BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); 657 1.1 riastrad u32 temp; 658 1.1 riastrad 659 1.1 riastrad temp = I915_READ(port_ctrl); 660 1.1 riastrad 661 1.1 riastrad temp &= ~LANE_CONFIGURATION_MASK; 662 1.1 riastrad temp &= ~DUAL_LINK_MODE_MASK; 663 1.1 riastrad 664 1.1 riastrad if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) { 665 1.1 riastrad temp |= (intel_dsi->dual_link - 1) 666 1.1 riastrad << DUAL_LINK_MODE_SHIFT; 667 1.1 riastrad if (IS_BROXTON(dev_priv)) 668 1.1 riastrad temp |= LANE_CONFIGURATION_DUAL_LINK_A; 669 1.1 riastrad else 670 1.1 riastrad temp |= crtc->pipe ? 671 1.1 riastrad LANE_CONFIGURATION_DUAL_LINK_B : 672 1.1 riastrad LANE_CONFIGURATION_DUAL_LINK_A; 673 1.1 riastrad } 674 1.1 riastrad 675 1.1 riastrad if (intel_dsi->pixel_format != MIPI_DSI_FMT_RGB888) 676 1.1 riastrad temp |= DITHERING_ENABLE; 677 1.1 riastrad 678 1.1 riastrad /* assert ip_tg_enable signal */ 679 1.1 riastrad I915_WRITE(port_ctrl, temp | DPI_ENABLE); 680 1.1 riastrad POSTING_READ(port_ctrl); 681 1.1 riastrad } 682 1.1 riastrad } 683 1.1 riastrad 684 1.1 riastrad static void intel_dsi_port_disable(struct intel_encoder *encoder) 685 1.1 riastrad { 686 1.1 riastrad struct drm_device *dev = encoder->base.dev; 687 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 688 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 689 1.1 riastrad enum port port; 690 1.1 riastrad 691 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 692 1.1 riastrad i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ? 693 1.1 riastrad BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); 694 1.1 riastrad u32 temp; 695 1.1 riastrad 696 1.1 riastrad /* de-assert ip_tg_enable signal */ 697 1.1 riastrad temp = I915_READ(port_ctrl); 698 1.1 riastrad I915_WRITE(port_ctrl, temp & ~DPI_ENABLE); 699 1.1 riastrad POSTING_READ(port_ctrl); 700 1.1 riastrad } 701 1.1 riastrad } 702 1.1 riastrad 703 1.1 riastrad static void intel_dsi_prepare(struct intel_encoder *intel_encoder, 704 1.1 riastrad const struct intel_crtc_state *pipe_config); 705 1.1 riastrad static void intel_dsi_unprepare(struct intel_encoder *encoder); 706 1.1 riastrad 707 1.1 riastrad /* 708 1.1 riastrad * Panel enable/disable sequences from the VBT spec. 709 1.1 riastrad * 710 1.1 riastrad * Note the spec has AssertReset / DeassertReset swapped from their 711 1.1 riastrad * usual naming. We use the normal names to avoid confusion (so below 712 1.1 riastrad * they are swapped compared to the spec). 713 1.1 riastrad * 714 1.1 riastrad * Steps starting with MIPI refer to VBT sequences, note that for v2 715 1.1 riastrad * VBTs several steps which have a VBT in v2 are expected to be handled 716 1.1 riastrad * directly by the driver, by directly driving gpios for example. 717 1.1 riastrad * 718 1.1 riastrad * v2 video mode seq v3 video mode seq command mode seq 719 1.1 riastrad * - power on - MIPIPanelPowerOn - power on 720 1.1 riastrad * - wait t1+t2 - wait t1+t2 721 1.1 riastrad * - MIPIDeassertResetPin - MIPIDeassertResetPin - MIPIDeassertResetPin 722 1.1 riastrad * - io lines to lp-11 - io lines to lp-11 - io lines to lp-11 723 1.1 riastrad * - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds 724 1.1 riastrad * - MIPITearOn 725 1.1 riastrad * - MIPIDisplayOn 726 1.1 riastrad * - turn on DPI - turn on DPI - set pipe to dsr mode 727 1.1 riastrad * - MIPIDisplayOn - MIPIDisplayOn 728 1.1 riastrad * - wait t5 - wait t5 729 1.1 riastrad * - backlight on - MIPIBacklightOn - backlight on 730 1.1 riastrad * ... ... ... issue mem cmds ... 731 1.1 riastrad * - backlight off - MIPIBacklightOff - backlight off 732 1.1 riastrad * - wait t6 - wait t6 733 1.1 riastrad * - MIPIDisplayOff 734 1.1 riastrad * - turn off DPI - turn off DPI - disable pipe dsr mode 735 1.1 riastrad * - MIPITearOff 736 1.1 riastrad * - MIPIDisplayOff - MIPIDisplayOff 737 1.1 riastrad * - io lines to lp-00 - io lines to lp-00 - io lines to lp-00 738 1.1 riastrad * - MIPIAssertResetPin - MIPIAssertResetPin - MIPIAssertResetPin 739 1.1 riastrad * - wait t3 - wait t3 740 1.1 riastrad * - power off - MIPIPanelPowerOff - power off 741 1.1 riastrad * - wait t4 - wait t4 742 1.1 riastrad */ 743 1.1 riastrad 744 1.1 riastrad /* 745 1.1 riastrad * DSI port enable has to be done before pipe and plane enable, so we do it in 746 1.1 riastrad * the pre_enable hook instead of the enable hook. 747 1.1 riastrad */ 748 1.1 riastrad static void intel_dsi_pre_enable(struct intel_encoder *encoder, 749 1.1 riastrad const struct intel_crtc_state *pipe_config, 750 1.1 riastrad const struct drm_connector_state *conn_state) 751 1.1 riastrad { 752 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 753 1.1 riastrad struct drm_crtc *crtc = pipe_config->uapi.crtc; 754 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 755 1.1 riastrad struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 756 1.1 riastrad enum pipe pipe = intel_crtc->pipe; 757 1.1 riastrad enum port port; 758 1.1 riastrad u32 val; 759 1.1 riastrad bool glk_cold_boot = false; 760 1.1 riastrad 761 1.1 riastrad DRM_DEBUG_KMS("\n"); 762 1.1 riastrad 763 1.1 riastrad intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 764 1.1 riastrad 765 1.1 riastrad /* 766 1.1 riastrad * The BIOS may leave the PLL in a wonky state where it doesn't 767 1.1 riastrad * lock. It needs to be fully powered down to fix it. 768 1.1 riastrad */ 769 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 770 1.1 riastrad bxt_dsi_pll_disable(encoder); 771 1.1 riastrad bxt_dsi_pll_enable(encoder, pipe_config); 772 1.1 riastrad } else { 773 1.1 riastrad vlv_dsi_pll_disable(encoder); 774 1.1 riastrad vlv_dsi_pll_enable(encoder, pipe_config); 775 1.1 riastrad } 776 1.1 riastrad 777 1.1 riastrad if (IS_BROXTON(dev_priv)) { 778 1.1 riastrad /* Add MIPI IO reset programming for modeset */ 779 1.1 riastrad val = I915_READ(BXT_P_CR_GT_DISP_PWRON); 780 1.1 riastrad I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 781 1.1 riastrad val | MIPIO_RST_CTRL); 782 1.1 riastrad 783 1.1 riastrad /* Power up DSI regulator */ 784 1.1 riastrad I915_WRITE(BXT_P_DSI_REGULATOR_CFG, STAP_SELECT); 785 1.1 riastrad I915_WRITE(BXT_P_DSI_REGULATOR_TX_CTRL, 0); 786 1.1 riastrad } 787 1.1 riastrad 788 1.1 riastrad if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 789 1.1 riastrad u32 val; 790 1.1 riastrad 791 1.1 riastrad /* Disable DPOunit clock gating, can stall pipe */ 792 1.1 riastrad val = I915_READ(DSPCLK_GATE_D); 793 1.1 riastrad val |= DPOUNIT_CLOCK_GATE_DISABLE; 794 1.1 riastrad I915_WRITE(DSPCLK_GATE_D, val); 795 1.1 riastrad } 796 1.1 riastrad 797 1.1 riastrad if (!IS_GEMINILAKE(dev_priv)) 798 1.1 riastrad intel_dsi_prepare(encoder, pipe_config); 799 1.1 riastrad 800 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON); 801 1.1 riastrad intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay); 802 1.1 riastrad 803 1.1 riastrad /* Deassert reset */ 804 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET); 805 1.1 riastrad 806 1.1 riastrad if (IS_GEMINILAKE(dev_priv)) { 807 1.1 riastrad glk_cold_boot = glk_dsi_enable_io(encoder); 808 1.1 riastrad 809 1.1 riastrad /* Prepare port in cold boot(s3/s4) scenario */ 810 1.1 riastrad if (glk_cold_boot) 811 1.1 riastrad intel_dsi_prepare(encoder, pipe_config); 812 1.1 riastrad } 813 1.1 riastrad 814 1.1 riastrad /* Put device in ready state (LP-11) */ 815 1.1 riastrad intel_dsi_device_ready(encoder); 816 1.1 riastrad 817 1.1 riastrad /* Prepare port in normal boot scenario */ 818 1.1 riastrad if (IS_GEMINILAKE(dev_priv) && !glk_cold_boot) 819 1.1 riastrad intel_dsi_prepare(encoder, pipe_config); 820 1.1 riastrad 821 1.1 riastrad /* Send initialization commands in LP mode */ 822 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP); 823 1.1 riastrad 824 1.1 riastrad /* Enable port in pre-enable phase itself because as per hw team 825 1.1 riastrad * recommendation, port should be enabled befor plane & pipe */ 826 1.1 riastrad if (is_cmd_mode(intel_dsi)) { 827 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) 828 1.1 riastrad I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4); 829 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_ON); 830 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); 831 1.1 riastrad } else { 832 1.1 riastrad msleep(20); /* XXX */ 833 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) 834 1.1 riastrad dpi_send_cmd(intel_dsi, TURN_ON, false, port); 835 1.1 riastrad intel_dsi_msleep(intel_dsi, 100); 836 1.1 riastrad 837 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); 838 1.1 riastrad 839 1.1 riastrad intel_dsi_port_enable(encoder, pipe_config); 840 1.1 riastrad } 841 1.1 riastrad 842 1.1 riastrad intel_panel_enable_backlight(pipe_config, conn_state); 843 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON); 844 1.1 riastrad } 845 1.1 riastrad 846 1.1 riastrad /* 847 1.1 riastrad * DSI port disable has to be done after pipe and plane disable, so we do it in 848 1.1 riastrad * the post_disable hook. 849 1.1 riastrad */ 850 1.1 riastrad static void intel_dsi_disable(struct intel_encoder *encoder, 851 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 852 1.1 riastrad const struct drm_connector_state *old_conn_state) 853 1.1 riastrad { 854 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 855 1.1 riastrad enum port port; 856 1.1 riastrad 857 1.1 riastrad DRM_DEBUG_KMS("\n"); 858 1.1 riastrad 859 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF); 860 1.1 riastrad intel_panel_disable_backlight(old_conn_state); 861 1.1 riastrad 862 1.1 riastrad /* 863 1.1 riastrad * According to the spec we should send SHUTDOWN before 864 1.1 riastrad * MIPI_SEQ_DISPLAY_OFF only for v3+ VBTs, but field testing 865 1.1 riastrad * has shown that the v3 sequence works for v2 VBTs too 866 1.1 riastrad */ 867 1.1 riastrad if (is_vid_mode(intel_dsi)) { 868 1.1 riastrad /* Send Shutdown command to the panel in LP mode */ 869 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) 870 1.1 riastrad dpi_send_cmd(intel_dsi, SHUTDOWN, false, port); 871 1.1 riastrad msleep(10); 872 1.1 riastrad } 873 1.1 riastrad } 874 1.1 riastrad 875 1.1 riastrad static void intel_dsi_clear_device_ready(struct intel_encoder *encoder) 876 1.1 riastrad { 877 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 878 1.1 riastrad 879 1.1 riastrad if (IS_GEMINILAKE(dev_priv)) 880 1.1 riastrad glk_dsi_clear_device_ready(encoder); 881 1.1 riastrad else 882 1.1 riastrad vlv_dsi_clear_device_ready(encoder); 883 1.1 riastrad } 884 1.1 riastrad 885 1.1 riastrad static void intel_dsi_post_disable(struct intel_encoder *encoder, 886 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 887 1.1 riastrad const struct drm_connector_state *old_conn_state) 888 1.1 riastrad { 889 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 890 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 891 1.1 riastrad enum port port; 892 1.1 riastrad u32 val; 893 1.1 riastrad 894 1.1 riastrad DRM_DEBUG_KMS("\n"); 895 1.1 riastrad 896 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 897 1.1 riastrad intel_crtc_vblank_off(old_crtc_state); 898 1.1 riastrad 899 1.1 riastrad skl_scaler_disable(old_crtc_state); 900 1.1 riastrad } 901 1.1 riastrad 902 1.1 riastrad if (is_vid_mode(intel_dsi)) { 903 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) 904 1.1 riastrad vlv_dsi_wait_for_fifo_empty(intel_dsi, port); 905 1.1 riastrad 906 1.1 riastrad intel_dsi_port_disable(encoder); 907 1.1 riastrad usleep_range(2000, 5000); 908 1.1 riastrad } 909 1.1 riastrad 910 1.1 riastrad intel_dsi_unprepare(encoder); 911 1.1 riastrad 912 1.1 riastrad /* 913 1.1 riastrad * if disable packets are sent before sending shutdown packet then in 914 1.1 riastrad * some next enable sequence send turn on packet error is observed 915 1.1 riastrad */ 916 1.1 riastrad if (is_cmd_mode(intel_dsi)) 917 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_OFF); 918 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF); 919 1.1 riastrad 920 1.1 riastrad /* Transition to LP-00 */ 921 1.1 riastrad intel_dsi_clear_device_ready(encoder); 922 1.1 riastrad 923 1.1 riastrad if (IS_BROXTON(dev_priv)) { 924 1.1 riastrad /* Power down DSI regulator to save power */ 925 1.1 riastrad I915_WRITE(BXT_P_DSI_REGULATOR_CFG, STAP_SELECT); 926 1.1 riastrad I915_WRITE(BXT_P_DSI_REGULATOR_TX_CTRL, HS_IO_CTRL_SELECT); 927 1.1 riastrad 928 1.1 riastrad /* Add MIPI IO reset programming for modeset */ 929 1.1 riastrad val = I915_READ(BXT_P_CR_GT_DISP_PWRON); 930 1.1 riastrad I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 931 1.1 riastrad val & ~MIPIO_RST_CTRL); 932 1.1 riastrad } 933 1.1 riastrad 934 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 935 1.1 riastrad bxt_dsi_pll_disable(encoder); 936 1.1 riastrad } else { 937 1.1 riastrad u32 val; 938 1.1 riastrad 939 1.1 riastrad vlv_dsi_pll_disable(encoder); 940 1.1 riastrad 941 1.1 riastrad val = I915_READ(DSPCLK_GATE_D); 942 1.1 riastrad val &= ~DPOUNIT_CLOCK_GATE_DISABLE; 943 1.1 riastrad I915_WRITE(DSPCLK_GATE_D, val); 944 1.1 riastrad } 945 1.1 riastrad 946 1.1 riastrad /* Assert reset */ 947 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); 948 1.1 riastrad 949 1.1 riastrad intel_dsi_msleep(intel_dsi, intel_dsi->panel_off_delay); 950 1.1 riastrad intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF); 951 1.1 riastrad 952 1.1 riastrad /* 953 1.1 riastrad * FIXME As we do with eDP, just make a note of the time here 954 1.1 riastrad * and perform the wait before the next panel power on. 955 1.1 riastrad */ 956 1.1 riastrad intel_dsi_msleep(intel_dsi, intel_dsi->panel_pwr_cycle_delay); 957 1.1 riastrad } 958 1.1 riastrad 959 1.1 riastrad static bool intel_dsi_get_hw_state(struct intel_encoder *encoder, 960 1.1 riastrad enum pipe *pipe) 961 1.1 riastrad { 962 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 963 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 964 1.1 riastrad intel_wakeref_t wakeref; 965 1.1 riastrad enum port port; 966 1.1 riastrad bool active = false; 967 1.1 riastrad 968 1.1 riastrad DRM_DEBUG_KMS("\n"); 969 1.1 riastrad 970 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, 971 1.1 riastrad encoder->power_domain); 972 1.1 riastrad if (!wakeref) 973 1.1 riastrad return false; 974 1.1 riastrad 975 1.1 riastrad /* 976 1.1 riastrad * On Broxton the PLL needs to be enabled with a valid divider 977 1.1 riastrad * configuration, otherwise accessing DSI registers will hang the 978 1.1 riastrad * machine. See BSpec North Display Engine registers/MIPI[BXT]. 979 1.1 riastrad */ 980 1.1 riastrad if (IS_GEN9_LP(dev_priv) && !bxt_dsi_pll_is_enabled(dev_priv)) 981 1.1 riastrad goto out_put_power; 982 1.1 riastrad 983 1.1 riastrad /* XXX: this only works for one DSI output */ 984 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 985 1.1 riastrad i915_reg_t ctrl_reg = IS_GEN9_LP(dev_priv) ? 986 1.1 riastrad BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); 987 1.1 riastrad bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE; 988 1.1 riastrad 989 1.1 riastrad /* 990 1.1 riastrad * Due to some hardware limitations on VLV/CHV, the DPI enable 991 1.1 riastrad * bit in port C control register does not get set. As a 992 1.1 riastrad * workaround, check pipe B conf instead. 993 1.1 riastrad */ 994 1.1 riastrad if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 995 1.1 riastrad port == PORT_C) 996 1.1 riastrad enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE; 997 1.1 riastrad 998 1.1 riastrad /* Try command mode if video mode not enabled */ 999 1.1 riastrad if (!enabled) { 1000 1.1 riastrad u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port)); 1001 1.1 riastrad enabled = tmp & CMD_MODE_DATA_WIDTH_MASK; 1002 1.1 riastrad } 1003 1.1 riastrad 1004 1.1 riastrad if (!enabled) 1005 1.1 riastrad continue; 1006 1.1 riastrad 1007 1.1 riastrad if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY)) 1008 1.1 riastrad continue; 1009 1.1 riastrad 1010 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 1011 1.1 riastrad u32 tmp = I915_READ(MIPI_CTRL(port)); 1012 1.1 riastrad tmp &= BXT_PIPE_SELECT_MASK; 1013 1.1 riastrad tmp >>= BXT_PIPE_SELECT_SHIFT; 1014 1.1 riastrad 1015 1.1 riastrad if (WARN_ON(tmp > PIPE_C)) 1016 1.1 riastrad continue; 1017 1.1 riastrad 1018 1.1 riastrad *pipe = tmp; 1019 1.1 riastrad } else { 1020 1.1 riastrad *pipe = port == PORT_A ? PIPE_A : PIPE_B; 1021 1.1 riastrad } 1022 1.1 riastrad 1023 1.1 riastrad active = true; 1024 1.1 riastrad break; 1025 1.1 riastrad } 1026 1.1 riastrad 1027 1.1 riastrad out_put_power: 1028 1.1 riastrad intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1029 1.1 riastrad 1030 1.1 riastrad return active; 1031 1.1 riastrad } 1032 1.1 riastrad 1033 1.1 riastrad static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder, 1034 1.1 riastrad struct intel_crtc_state *pipe_config) 1035 1.1 riastrad { 1036 1.1 riastrad struct drm_device *dev = encoder->base.dev; 1037 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 1038 1.1 riastrad struct drm_display_mode *adjusted_mode = 1039 1.1 riastrad &pipe_config->hw.adjusted_mode; 1040 1.1 riastrad struct drm_display_mode *adjusted_mode_sw; 1041 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1042 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1043 1.1 riastrad unsigned int lane_count = intel_dsi->lane_count; 1044 1.1 riastrad unsigned int bpp, fmt; 1045 1.1 riastrad enum port port; 1046 1.1 riastrad u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp; 1047 1.1 riastrad u16 hfp_sw, hsync_sw, hbp_sw; 1048 1.1 riastrad u16 crtc_htotal_sw, crtc_hsync_start_sw, crtc_hsync_end_sw, 1049 1.1 riastrad crtc_hblank_start_sw, crtc_hblank_end_sw; 1050 1.1 riastrad 1051 1.1 riastrad /* FIXME: hw readout should not depend on SW state */ 1052 1.1 riastrad adjusted_mode_sw = &crtc->config->hw.adjusted_mode; 1053 1.1 riastrad 1054 1.1 riastrad /* 1055 1.1 riastrad * Atleast one port is active as encoder->get_config called only if 1056 1.1 riastrad * encoder->get_hw_state() returns true. 1057 1.1 riastrad */ 1058 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1059 1.1 riastrad if (I915_READ(BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE) 1060 1.1 riastrad break; 1061 1.1 riastrad } 1062 1.1 riastrad 1063 1.1 riastrad fmt = I915_READ(MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK; 1064 1.1 riastrad bpp = mipi_dsi_pixel_format_to_bpp( 1065 1.1 riastrad pixel_format_from_register_bits(fmt)); 1066 1.1 riastrad 1067 1.1 riastrad pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc); 1068 1.1 riastrad 1069 1.1 riastrad /* Enable Frame time stamo based scanline reporting */ 1070 1.1 riastrad adjusted_mode->private_flags |= 1071 1.1 riastrad I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP; 1072 1.1 riastrad 1073 1.1 riastrad /* In terms of pixels */ 1074 1.1 riastrad adjusted_mode->crtc_hdisplay = 1075 1.1 riastrad I915_READ(BXT_MIPI_TRANS_HACTIVE(port)); 1076 1.1 riastrad adjusted_mode->crtc_vdisplay = 1077 1.1 riastrad I915_READ(BXT_MIPI_TRANS_VACTIVE(port)); 1078 1.1 riastrad adjusted_mode->crtc_vtotal = 1079 1.1 riastrad I915_READ(BXT_MIPI_TRANS_VTOTAL(port)); 1080 1.1 riastrad 1081 1.1 riastrad hactive = adjusted_mode->crtc_hdisplay; 1082 1.1 riastrad hfp = I915_READ(MIPI_HFP_COUNT(port)); 1083 1.1 riastrad 1084 1.1 riastrad /* 1085 1.1 riastrad * Meaningful for video mode non-burst sync pulse mode only, 1086 1.1 riastrad * can be zero for non-burst sync events and burst modes 1087 1.1 riastrad */ 1088 1.1 riastrad hsync = I915_READ(MIPI_HSYNC_PADDING_COUNT(port)); 1089 1.1 riastrad hbp = I915_READ(MIPI_HBP_COUNT(port)); 1090 1.1 riastrad 1091 1.1 riastrad /* harizontal values are in terms of high speed byte clock */ 1092 1.1 riastrad hfp = pixels_from_txbyteclkhs(hfp, bpp, lane_count, 1093 1.1 riastrad intel_dsi->burst_mode_ratio); 1094 1.1 riastrad hsync = pixels_from_txbyteclkhs(hsync, bpp, lane_count, 1095 1.1 riastrad intel_dsi->burst_mode_ratio); 1096 1.1 riastrad hbp = pixels_from_txbyteclkhs(hbp, bpp, lane_count, 1097 1.1 riastrad intel_dsi->burst_mode_ratio); 1098 1.1 riastrad 1099 1.1 riastrad if (intel_dsi->dual_link) { 1100 1.1 riastrad hfp *= 2; 1101 1.1 riastrad hsync *= 2; 1102 1.1 riastrad hbp *= 2; 1103 1.1 riastrad } 1104 1.1 riastrad 1105 1.1 riastrad /* vertical values are in terms of lines */ 1106 1.1 riastrad vfp = I915_READ(MIPI_VFP_COUNT(port)); 1107 1.1 riastrad vsync = I915_READ(MIPI_VSYNC_PADDING_COUNT(port)); 1108 1.1 riastrad vbp = I915_READ(MIPI_VBP_COUNT(port)); 1109 1.1 riastrad 1110 1.1 riastrad adjusted_mode->crtc_htotal = hactive + hfp + hsync + hbp; 1111 1.1 riastrad adjusted_mode->crtc_hsync_start = hfp + adjusted_mode->crtc_hdisplay; 1112 1.1 riastrad adjusted_mode->crtc_hsync_end = hsync + adjusted_mode->crtc_hsync_start; 1113 1.1 riastrad adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay; 1114 1.1 riastrad adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal; 1115 1.1 riastrad 1116 1.1 riastrad adjusted_mode->crtc_vsync_start = vfp + adjusted_mode->crtc_vdisplay; 1117 1.1 riastrad adjusted_mode->crtc_vsync_end = vsync + adjusted_mode->crtc_vsync_start; 1118 1.1 riastrad adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay; 1119 1.1 riastrad adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal; 1120 1.1 riastrad 1121 1.1 riastrad /* 1122 1.1 riastrad * In BXT DSI there is no regs programmed with few horizontal timings 1123 1.1 riastrad * in Pixels but txbyteclkhs.. So retrieval process adds some 1124 1.1 riastrad * ROUND_UP ERRORS in the process of PIXELS<==>txbyteclkhs. 1125 1.1 riastrad * Actually here for the given adjusted_mode, we are calculating the 1126 1.1 riastrad * value programmed to the port and then back to the horizontal timing 1127 1.1 riastrad * param in pixels. This is the expected value, including roundup errors 1128 1.1 riastrad * And if that is same as retrieved value from port, then 1129 1.1 riastrad * (HW state) adjusted_mode's horizontal timings are corrected to 1130 1.1 riastrad * match with SW state to nullify the errors. 1131 1.1 riastrad */ 1132 1.1 riastrad /* Calculating the value programmed to the Port register */ 1133 1.1 riastrad hfp_sw = adjusted_mode_sw->crtc_hsync_start - 1134 1.1 riastrad adjusted_mode_sw->crtc_hdisplay; 1135 1.1 riastrad hsync_sw = adjusted_mode_sw->crtc_hsync_end - 1136 1.1 riastrad adjusted_mode_sw->crtc_hsync_start; 1137 1.1 riastrad hbp_sw = adjusted_mode_sw->crtc_htotal - 1138 1.1 riastrad adjusted_mode_sw->crtc_hsync_end; 1139 1.1 riastrad 1140 1.1 riastrad if (intel_dsi->dual_link) { 1141 1.1 riastrad hfp_sw /= 2; 1142 1.1 riastrad hsync_sw /= 2; 1143 1.1 riastrad hbp_sw /= 2; 1144 1.1 riastrad } 1145 1.1 riastrad 1146 1.1 riastrad hfp_sw = txbyteclkhs(hfp_sw, bpp, lane_count, 1147 1.1 riastrad intel_dsi->burst_mode_ratio); 1148 1.1 riastrad hsync_sw = txbyteclkhs(hsync_sw, bpp, lane_count, 1149 1.1 riastrad intel_dsi->burst_mode_ratio); 1150 1.1 riastrad hbp_sw = txbyteclkhs(hbp_sw, bpp, lane_count, 1151 1.1 riastrad intel_dsi->burst_mode_ratio); 1152 1.1 riastrad 1153 1.1 riastrad /* Reverse calculating the adjusted mode parameters from port reg vals*/ 1154 1.1 riastrad hfp_sw = pixels_from_txbyteclkhs(hfp_sw, bpp, lane_count, 1155 1.1 riastrad intel_dsi->burst_mode_ratio); 1156 1.1 riastrad hsync_sw = pixels_from_txbyteclkhs(hsync_sw, bpp, lane_count, 1157 1.1 riastrad intel_dsi->burst_mode_ratio); 1158 1.1 riastrad hbp_sw = pixels_from_txbyteclkhs(hbp_sw, bpp, lane_count, 1159 1.1 riastrad intel_dsi->burst_mode_ratio); 1160 1.1 riastrad 1161 1.1 riastrad if (intel_dsi->dual_link) { 1162 1.1 riastrad hfp_sw *= 2; 1163 1.1 riastrad hsync_sw *= 2; 1164 1.1 riastrad hbp_sw *= 2; 1165 1.1 riastrad } 1166 1.1 riastrad 1167 1.1 riastrad crtc_htotal_sw = adjusted_mode_sw->crtc_hdisplay + hfp_sw + 1168 1.1 riastrad hsync_sw + hbp_sw; 1169 1.1 riastrad crtc_hsync_start_sw = hfp_sw + adjusted_mode_sw->crtc_hdisplay; 1170 1.1 riastrad crtc_hsync_end_sw = hsync_sw + crtc_hsync_start_sw; 1171 1.1 riastrad crtc_hblank_start_sw = adjusted_mode_sw->crtc_hdisplay; 1172 1.1 riastrad crtc_hblank_end_sw = crtc_htotal_sw; 1173 1.1 riastrad 1174 1.1 riastrad if (adjusted_mode->crtc_htotal == crtc_htotal_sw) 1175 1.1 riastrad adjusted_mode->crtc_htotal = adjusted_mode_sw->crtc_htotal; 1176 1.1 riastrad 1177 1.1 riastrad if (adjusted_mode->crtc_hsync_start == crtc_hsync_start_sw) 1178 1.1 riastrad adjusted_mode->crtc_hsync_start = 1179 1.1 riastrad adjusted_mode_sw->crtc_hsync_start; 1180 1.1 riastrad 1181 1.1 riastrad if (adjusted_mode->crtc_hsync_end == crtc_hsync_end_sw) 1182 1.1 riastrad adjusted_mode->crtc_hsync_end = 1183 1.1 riastrad adjusted_mode_sw->crtc_hsync_end; 1184 1.1 riastrad 1185 1.1 riastrad if (adjusted_mode->crtc_hblank_start == crtc_hblank_start_sw) 1186 1.1 riastrad adjusted_mode->crtc_hblank_start = 1187 1.1 riastrad adjusted_mode_sw->crtc_hblank_start; 1188 1.1 riastrad 1189 1.1 riastrad if (adjusted_mode->crtc_hblank_end == crtc_hblank_end_sw) 1190 1.1 riastrad adjusted_mode->crtc_hblank_end = 1191 1.1 riastrad adjusted_mode_sw->crtc_hblank_end; 1192 1.1 riastrad } 1193 1.1 riastrad 1194 1.1 riastrad static void intel_dsi_get_config(struct intel_encoder *encoder, 1195 1.1 riastrad struct intel_crtc_state *pipe_config) 1196 1.1 riastrad { 1197 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1198 1.1 riastrad u32 pclk; 1199 1.1 riastrad DRM_DEBUG_KMS("\n"); 1200 1.1 riastrad 1201 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI); 1202 1.1 riastrad 1203 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 1204 1.1 riastrad bxt_dsi_get_pipe_config(encoder, pipe_config); 1205 1.1 riastrad pclk = bxt_dsi_get_pclk(encoder, pipe_config); 1206 1.1 riastrad } else { 1207 1.1 riastrad pclk = vlv_dsi_get_pclk(encoder, pipe_config); 1208 1.1 riastrad } 1209 1.1 riastrad 1210 1.1 riastrad if (pclk) { 1211 1.1 riastrad pipe_config->hw.adjusted_mode.crtc_clock = pclk; 1212 1.1 riastrad pipe_config->port_clock = pclk; 1213 1.1 riastrad } 1214 1.1 riastrad } 1215 1.1 riastrad 1216 1.1 riastrad /* return txclkesc cycles in terms of divider and duration in us */ 1217 1.1 riastrad static u16 txclkesc(u32 divider, unsigned int us) 1218 1.1 riastrad { 1219 1.1 riastrad switch (divider) { 1220 1.1 riastrad case ESCAPE_CLOCK_DIVIDER_1: 1221 1.1 riastrad default: 1222 1.1 riastrad return 20 * us; 1223 1.1 riastrad case ESCAPE_CLOCK_DIVIDER_2: 1224 1.1 riastrad return 10 * us; 1225 1.1 riastrad case ESCAPE_CLOCK_DIVIDER_4: 1226 1.1 riastrad return 5 * us; 1227 1.1 riastrad } 1228 1.1 riastrad } 1229 1.1 riastrad 1230 1.1 riastrad static void set_dsi_timings(struct drm_encoder *encoder, 1231 1.1 riastrad const struct drm_display_mode *adjusted_mode) 1232 1.1 riastrad { 1233 1.1 riastrad struct drm_device *dev = encoder->dev; 1234 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 1235 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1236 1.1 riastrad enum port port; 1237 1.1 riastrad unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 1238 1.1 riastrad unsigned int lane_count = intel_dsi->lane_count; 1239 1.1 riastrad 1240 1.1 riastrad u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp; 1241 1.1 riastrad 1242 1.1 riastrad hactive = adjusted_mode->crtc_hdisplay; 1243 1.1 riastrad hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay; 1244 1.1 riastrad hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start; 1245 1.1 riastrad hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end; 1246 1.1 riastrad 1247 1.1 riastrad if (intel_dsi->dual_link) { 1248 1.1 riastrad hactive /= 2; 1249 1.1 riastrad if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 1250 1.1 riastrad hactive += intel_dsi->pixel_overlap; 1251 1.1 riastrad hfp /= 2; 1252 1.1 riastrad hsync /= 2; 1253 1.1 riastrad hbp /= 2; 1254 1.1 riastrad } 1255 1.1 riastrad 1256 1.1 riastrad vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay; 1257 1.1 riastrad vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start; 1258 1.1 riastrad vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end; 1259 1.1 riastrad 1260 1.1 riastrad /* horizontal values are in terms of high speed byte clock */ 1261 1.1 riastrad hactive = txbyteclkhs(hactive, bpp, lane_count, 1262 1.1 riastrad intel_dsi->burst_mode_ratio); 1263 1.1 riastrad hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio); 1264 1.1 riastrad hsync = txbyteclkhs(hsync, bpp, lane_count, 1265 1.1 riastrad intel_dsi->burst_mode_ratio); 1266 1.1 riastrad hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio); 1267 1.1 riastrad 1268 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1269 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 1270 1.1 riastrad /* 1271 1.1 riastrad * Program hdisplay and vdisplay on MIPI transcoder. 1272 1.1 riastrad * This is different from calculated hactive and 1273 1.1 riastrad * vactive, as they are calculated per channel basis, 1274 1.1 riastrad * whereas these values should be based on resolution. 1275 1.1 riastrad */ 1276 1.1 riastrad I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port), 1277 1.1 riastrad adjusted_mode->crtc_hdisplay); 1278 1.1 riastrad I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port), 1279 1.1 riastrad adjusted_mode->crtc_vdisplay); 1280 1.1 riastrad I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port), 1281 1.1 riastrad adjusted_mode->crtc_vtotal); 1282 1.1 riastrad } 1283 1.1 riastrad 1284 1.1 riastrad I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive); 1285 1.1 riastrad I915_WRITE(MIPI_HFP_COUNT(port), hfp); 1286 1.1 riastrad 1287 1.1 riastrad /* meaningful for video mode non-burst sync pulse mode only, 1288 1.1 riastrad * can be zero for non-burst sync events and burst modes */ 1289 1.1 riastrad I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync); 1290 1.1 riastrad I915_WRITE(MIPI_HBP_COUNT(port), hbp); 1291 1.1 riastrad 1292 1.1 riastrad /* vertical values are in terms of lines */ 1293 1.1 riastrad I915_WRITE(MIPI_VFP_COUNT(port), vfp); 1294 1.1 riastrad I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync); 1295 1.1 riastrad I915_WRITE(MIPI_VBP_COUNT(port), vbp); 1296 1.1 riastrad } 1297 1.1 riastrad } 1298 1.1 riastrad 1299 1.1 riastrad static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt) 1300 1.1 riastrad { 1301 1.1 riastrad switch (fmt) { 1302 1.1 riastrad case MIPI_DSI_FMT_RGB888: 1303 1.1 riastrad return VID_MODE_FORMAT_RGB888; 1304 1.1 riastrad case MIPI_DSI_FMT_RGB666: 1305 1.1 riastrad return VID_MODE_FORMAT_RGB666; 1306 1.1 riastrad case MIPI_DSI_FMT_RGB666_PACKED: 1307 1.1 riastrad return VID_MODE_FORMAT_RGB666_PACKED; 1308 1.1 riastrad case MIPI_DSI_FMT_RGB565: 1309 1.1 riastrad return VID_MODE_FORMAT_RGB565; 1310 1.1 riastrad default: 1311 1.1 riastrad MISSING_CASE(fmt); 1312 1.1 riastrad return VID_MODE_FORMAT_RGB666; 1313 1.1 riastrad } 1314 1.1 riastrad } 1315 1.1 riastrad 1316 1.1 riastrad static void intel_dsi_prepare(struct intel_encoder *intel_encoder, 1317 1.1 riastrad const struct intel_crtc_state *pipe_config) 1318 1.1 riastrad { 1319 1.1 riastrad struct drm_encoder *encoder = &intel_encoder->base; 1320 1.1 riastrad struct drm_device *dev = encoder->dev; 1321 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 1322 1.1 riastrad struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 1323 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1324 1.1 riastrad const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 1325 1.1 riastrad enum port port; 1326 1.1 riastrad unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 1327 1.1 riastrad u32 val, tmp; 1328 1.1 riastrad u16 mode_hdisplay; 1329 1.1 riastrad 1330 1.1 riastrad DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe)); 1331 1.1 riastrad 1332 1.1 riastrad mode_hdisplay = adjusted_mode->crtc_hdisplay; 1333 1.1 riastrad 1334 1.1 riastrad if (intel_dsi->dual_link) { 1335 1.1 riastrad mode_hdisplay /= 2; 1336 1.1 riastrad if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 1337 1.1 riastrad mode_hdisplay += intel_dsi->pixel_overlap; 1338 1.1 riastrad } 1339 1.1 riastrad 1340 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1341 1.1 riastrad if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 1342 1.1 riastrad /* 1343 1.1 riastrad * escape clock divider, 20MHz, shared for A and C. 1344 1.1 riastrad * device ready must be off when doing this! txclkesc? 1345 1.1 riastrad */ 1346 1.1 riastrad tmp = I915_READ(MIPI_CTRL(PORT_A)); 1347 1.1 riastrad tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK; 1348 1.1 riastrad I915_WRITE(MIPI_CTRL(PORT_A), tmp | 1349 1.1 riastrad ESCAPE_CLOCK_DIVIDER_1); 1350 1.1 riastrad 1351 1.1 riastrad /* read request priority is per pipe */ 1352 1.1 riastrad tmp = I915_READ(MIPI_CTRL(port)); 1353 1.1 riastrad tmp &= ~READ_REQUEST_PRIORITY_MASK; 1354 1.1 riastrad I915_WRITE(MIPI_CTRL(port), tmp | 1355 1.1 riastrad READ_REQUEST_PRIORITY_HIGH); 1356 1.1 riastrad } else if (IS_GEN9_LP(dev_priv)) { 1357 1.1 riastrad enum pipe pipe = intel_crtc->pipe; 1358 1.1 riastrad 1359 1.1 riastrad tmp = I915_READ(MIPI_CTRL(port)); 1360 1.1 riastrad tmp &= ~BXT_PIPE_SELECT_MASK; 1361 1.1 riastrad 1362 1.1 riastrad tmp |= BXT_PIPE_SELECT(pipe); 1363 1.1 riastrad I915_WRITE(MIPI_CTRL(port), tmp); 1364 1.1 riastrad } 1365 1.1 riastrad 1366 1.1 riastrad /* XXX: why here, why like this? handling in irq handler?! */ 1367 1.1 riastrad I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff); 1368 1.1 riastrad I915_WRITE(MIPI_INTR_EN(port), 0xffffffff); 1369 1.1 riastrad 1370 1.1 riastrad I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg); 1371 1.1 riastrad 1372 1.1 riastrad I915_WRITE(MIPI_DPI_RESOLUTION(port), 1373 1.1 riastrad adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | 1374 1.1 riastrad mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT); 1375 1.1 riastrad } 1376 1.1 riastrad 1377 1.1 riastrad set_dsi_timings(encoder, adjusted_mode); 1378 1.1 riastrad 1379 1.1 riastrad val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT; 1380 1.1 riastrad if (is_cmd_mode(intel_dsi)) { 1381 1.1 riastrad val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT; 1382 1.1 riastrad val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */ 1383 1.1 riastrad } else { 1384 1.1 riastrad val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT; 1385 1.1 riastrad val |= pixel_format_to_reg(intel_dsi->pixel_format); 1386 1.1 riastrad } 1387 1.1 riastrad 1388 1.1 riastrad tmp = 0; 1389 1.1 riastrad if (intel_dsi->eotp_pkt == 0) 1390 1.1 riastrad tmp |= EOT_DISABLE; 1391 1.1 riastrad if (intel_dsi->clock_stop) 1392 1.1 riastrad tmp |= CLOCKSTOP; 1393 1.1 riastrad 1394 1.1 riastrad if (IS_GEN9_LP(dev_priv)) { 1395 1.1 riastrad tmp |= BXT_DPHY_DEFEATURE_EN; 1396 1.1 riastrad if (!is_cmd_mode(intel_dsi)) 1397 1.1 riastrad tmp |= BXT_DEFEATURE_DPI_FIFO_CTR; 1398 1.1 riastrad } 1399 1.1 riastrad 1400 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1401 1.1 riastrad I915_WRITE(MIPI_DSI_FUNC_PRG(port), val); 1402 1.1 riastrad 1403 1.1 riastrad /* timeouts for recovery. one frame IIUC. if counter expires, 1404 1.1 riastrad * EOT and stop state. */ 1405 1.1 riastrad 1406 1.1 riastrad /* 1407 1.1 riastrad * In burst mode, value greater than one DPI line Time in byte 1408 1.1 riastrad * clock (txbyteclkhs) To timeout this timer 1+ of the above 1409 1.1 riastrad * said value is recommended. 1410 1.1 riastrad * 1411 1.1 riastrad * In non-burst mode, Value greater than one DPI frame time in 1412 1.1 riastrad * byte clock(txbyteclkhs) To timeout this timer 1+ of the above 1413 1.1 riastrad * said value is recommended. 1414 1.1 riastrad * 1415 1.1 riastrad * In DBI only mode, value greater than one DBI frame time in 1416 1.1 riastrad * byte clock(txbyteclkhs) To timeout this timer 1+ of the above 1417 1.1 riastrad * said value is recommended. 1418 1.1 riastrad */ 1419 1.1 riastrad 1420 1.1 riastrad if (is_vid_mode(intel_dsi) && 1421 1.1 riastrad intel_dsi->video_mode_format == VIDEO_MODE_BURST) { 1422 1.1 riastrad I915_WRITE(MIPI_HS_TX_TIMEOUT(port), 1423 1.1 riastrad txbyteclkhs(adjusted_mode->crtc_htotal, bpp, 1424 1.1 riastrad intel_dsi->lane_count, 1425 1.1 riastrad intel_dsi->burst_mode_ratio) + 1); 1426 1.1 riastrad } else { 1427 1.1 riastrad I915_WRITE(MIPI_HS_TX_TIMEOUT(port), 1428 1.1 riastrad txbyteclkhs(adjusted_mode->crtc_vtotal * 1429 1.1 riastrad adjusted_mode->crtc_htotal, 1430 1.1 riastrad bpp, intel_dsi->lane_count, 1431 1.1 riastrad intel_dsi->burst_mode_ratio) + 1); 1432 1.1 riastrad } 1433 1.1 riastrad I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout); 1434 1.1 riastrad I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), 1435 1.1 riastrad intel_dsi->turn_arnd_val); 1436 1.1 riastrad I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), 1437 1.1 riastrad intel_dsi->rst_timer_val); 1438 1.1 riastrad 1439 1.1 riastrad /* dphy stuff */ 1440 1.1 riastrad 1441 1.1 riastrad /* in terms of low power clock */ 1442 1.1 riastrad I915_WRITE(MIPI_INIT_COUNT(port), 1443 1.1 riastrad txclkesc(intel_dsi->escape_clk_div, 100)); 1444 1.1 riastrad 1445 1.1 riastrad if (IS_GEN9_LP(dev_priv) && (!intel_dsi->dual_link)) { 1446 1.1 riastrad /* 1447 1.1 riastrad * BXT spec says write MIPI_INIT_COUNT for 1448 1.1 riastrad * both the ports, even if only one is 1449 1.1 riastrad * getting used. So write the other port 1450 1.1 riastrad * if not in dual link mode. 1451 1.1 riastrad */ 1452 1.1 riastrad I915_WRITE(MIPI_INIT_COUNT(port == 1453 1.1 riastrad PORT_A ? PORT_C : PORT_A), 1454 1.1 riastrad intel_dsi->init_count); 1455 1.1 riastrad } 1456 1.1 riastrad 1457 1.1 riastrad /* recovery disables */ 1458 1.1 riastrad I915_WRITE(MIPI_EOT_DISABLE(port), tmp); 1459 1.1 riastrad 1460 1.1 riastrad /* in terms of low power clock */ 1461 1.1 riastrad I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count); 1462 1.1 riastrad 1463 1.1 riastrad /* in terms of txbyteclkhs. actual high to low switch + 1464 1.1 riastrad * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK. 1465 1.1 riastrad * 1466 1.1 riastrad * XXX: write MIPI_STOP_STATE_STALL? 1467 1.1 riastrad */ 1468 1.1 riastrad I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port), 1469 1.1 riastrad intel_dsi->hs_to_lp_count); 1470 1.1 riastrad 1471 1.1 riastrad /* XXX: low power clock equivalence in terms of byte clock. 1472 1.1 riastrad * the number of byte clocks occupied in one low power clock. 1473 1.1 riastrad * based on txbyteclkhs and txclkesc. 1474 1.1 riastrad * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL 1475 1.1 riastrad * ) / 105.??? 1476 1.1 riastrad */ 1477 1.1 riastrad I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk); 1478 1.1 riastrad 1479 1.1 riastrad if (IS_GEMINILAKE(dev_priv)) { 1480 1.1 riastrad I915_WRITE(MIPI_TLPX_TIME_COUNT(port), 1481 1.1 riastrad intel_dsi->lp_byte_clk); 1482 1.1 riastrad /* Shadow of DPHY reg */ 1483 1.1 riastrad I915_WRITE(MIPI_CLK_LANE_TIMING(port), 1484 1.1 riastrad intel_dsi->dphy_reg); 1485 1.1 riastrad } 1486 1.1 riastrad 1487 1.1 riastrad /* the bw essential for transmitting 16 long packets containing 1488 1.1 riastrad * 252 bytes meant for dcs write memory command is programmed in 1489 1.1 riastrad * this register in terms of byte clocks. based on dsi transfer 1490 1.1 riastrad * rate and the number of lanes configured the time taken to 1491 1.1 riastrad * transmit 16 long packets in a dsi stream varies. */ 1492 1.1 riastrad I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer); 1493 1.1 riastrad 1494 1.1 riastrad I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port), 1495 1.1 riastrad intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | 1496 1.1 riastrad intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT); 1497 1.1 riastrad 1498 1.1 riastrad if (is_vid_mode(intel_dsi)) 1499 1.1 riastrad /* Some panels might have resolution which is not a 1500 1.1 riastrad * multiple of 64 like 1366 x 768. Enable RANDOM 1501 1.1 riastrad * resolution support for such panels by default */ 1502 1.1 riastrad I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port), 1503 1.1 riastrad intel_dsi->video_frmt_cfg_bits | 1504 1.1 riastrad intel_dsi->video_mode_format | 1505 1.1 riastrad IP_TG_CONFIG | 1506 1.1 riastrad RANDOM_DPI_DISPLAY_RESOLUTION); 1507 1.1 riastrad } 1508 1.1 riastrad } 1509 1.1 riastrad 1510 1.1 riastrad static void intel_dsi_unprepare(struct intel_encoder *encoder) 1511 1.1 riastrad { 1512 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1513 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1514 1.1 riastrad enum port port; 1515 1.1 riastrad u32 val; 1516 1.1 riastrad 1517 1.1 riastrad if (IS_GEMINILAKE(dev_priv)) 1518 1.1 riastrad return; 1519 1.1 riastrad 1520 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1521 1.1 riastrad /* Panel commands can be sent when clock is in LP11 */ 1522 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), 0x0); 1523 1.1 riastrad 1524 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 1525 1.1 riastrad bxt_dsi_reset_clocks(encoder, port); 1526 1.1 riastrad else 1527 1.1 riastrad vlv_dsi_reset_clocks(encoder, port); 1528 1.1 riastrad I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP); 1529 1.1 riastrad 1530 1.1 riastrad val = I915_READ(MIPI_DSI_FUNC_PRG(port)); 1531 1.1 riastrad val &= ~VID_MODE_FORMAT_MASK; 1532 1.1 riastrad I915_WRITE(MIPI_DSI_FUNC_PRG(port), val); 1533 1.1 riastrad 1534 1.1 riastrad I915_WRITE(MIPI_DEVICE_READY(port), 0x1); 1535 1.1 riastrad } 1536 1.1 riastrad } 1537 1.1 riastrad 1538 1.1 riastrad static void intel_dsi_encoder_destroy(struct drm_encoder *encoder) 1539 1.1 riastrad { 1540 1.1 riastrad struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1541 1.1 riastrad 1542 1.1 riastrad intel_dsi_vbt_gpio_cleanup(intel_dsi); 1543 1.1 riastrad intel_encoder_destroy(encoder); 1544 1.1 riastrad } 1545 1.1 riastrad 1546 1.1 riastrad static const struct drm_encoder_funcs intel_dsi_funcs = { 1547 1.1 riastrad .destroy = intel_dsi_encoder_destroy, 1548 1.1 riastrad }; 1549 1.1 riastrad 1550 1.1 riastrad static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = { 1551 1.1 riastrad .get_modes = intel_dsi_get_modes, 1552 1.1 riastrad .mode_valid = intel_dsi_mode_valid, 1553 1.1 riastrad .atomic_check = intel_digital_connector_atomic_check, 1554 1.1 riastrad }; 1555 1.1 riastrad 1556 1.1 riastrad static const struct drm_connector_funcs intel_dsi_connector_funcs = { 1557 1.1 riastrad .late_register = intel_connector_register, 1558 1.1 riastrad .early_unregister = intel_connector_unregister, 1559 1.1 riastrad .destroy = intel_connector_destroy, 1560 1.1 riastrad .fill_modes = drm_helper_probe_single_connector_modes, 1561 1.1 riastrad .atomic_get_property = intel_digital_connector_atomic_get_property, 1562 1.1 riastrad .atomic_set_property = intel_digital_connector_atomic_set_property, 1563 1.1 riastrad .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1564 1.1 riastrad .atomic_duplicate_state = intel_digital_connector_duplicate_state, 1565 1.1 riastrad }; 1566 1.1 riastrad 1567 1.1 riastrad static enum drm_panel_orientation 1568 1.1 riastrad vlv_dsi_get_hw_panel_orientation(struct intel_connector *connector) 1569 1.1 riastrad { 1570 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1571 1.1 riastrad struct intel_encoder *encoder = connector->encoder; 1572 1.1 riastrad enum intel_display_power_domain power_domain; 1573 1.1 riastrad enum drm_panel_orientation orientation; 1574 1.1 riastrad struct intel_plane *plane; 1575 1.1 riastrad struct intel_crtc *crtc; 1576 1.1 riastrad intel_wakeref_t wakeref; 1577 1.1 riastrad enum pipe pipe; 1578 1.1 riastrad u32 val; 1579 1.1 riastrad 1580 1.1 riastrad if (!encoder->get_hw_state(encoder, &pipe)) 1581 1.1 riastrad return DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 1582 1.1 riastrad 1583 1.1 riastrad crtc = intel_get_crtc_for_pipe(dev_priv, pipe); 1584 1.1 riastrad plane = to_intel_plane(crtc->base.primary); 1585 1.1 riastrad 1586 1.1 riastrad power_domain = POWER_DOMAIN_PIPE(pipe); 1587 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); 1588 1.1 riastrad if (!wakeref) 1589 1.1 riastrad return DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 1590 1.1 riastrad 1591 1.1 riastrad val = I915_READ(DSPCNTR(plane->i9xx_plane)); 1592 1.1 riastrad 1593 1.1 riastrad if (!(val & DISPLAY_PLANE_ENABLE)) 1594 1.1 riastrad orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 1595 1.1 riastrad else if (val & DISPPLANE_ROTATE_180) 1596 1.1 riastrad orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP; 1597 1.1 riastrad else 1598 1.1 riastrad orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL; 1599 1.1 riastrad 1600 1.1 riastrad intel_display_power_put(dev_priv, power_domain, wakeref); 1601 1.1 riastrad 1602 1.1 riastrad return orientation; 1603 1.1 riastrad } 1604 1.1 riastrad 1605 1.1 riastrad static enum drm_panel_orientation 1606 1.1 riastrad vlv_dsi_get_panel_orientation(struct intel_connector *connector) 1607 1.1 riastrad { 1608 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1609 1.1 riastrad enum drm_panel_orientation orientation; 1610 1.1 riastrad 1611 1.1 riastrad if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 1612 1.1 riastrad orientation = vlv_dsi_get_hw_panel_orientation(connector); 1613 1.1 riastrad if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 1614 1.1 riastrad return orientation; 1615 1.1 riastrad } 1616 1.1 riastrad 1617 1.1 riastrad return intel_dsi_get_panel_orientation(connector); 1618 1.1 riastrad } 1619 1.1 riastrad 1620 1.1 riastrad static void vlv_dsi_add_properties(struct intel_connector *connector) 1621 1.1 riastrad { 1622 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1623 1.1 riastrad 1624 1.1 riastrad if (connector->panel.fixed_mode) { 1625 1.1 riastrad u32 allowed_scalers; 1626 1.1 riastrad 1627 1.1 riastrad allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN); 1628 1.1 riastrad if (!HAS_GMCH(dev_priv)) 1629 1.1 riastrad allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER); 1630 1.1 riastrad 1631 1.1 riastrad drm_connector_attach_scaling_mode_property(&connector->base, 1632 1.1 riastrad allowed_scalers); 1633 1.1 riastrad 1634 1.1 riastrad connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT; 1635 1.1 riastrad 1636 1.1 riastrad connector->base.display_info.panel_orientation = 1637 1.1 riastrad vlv_dsi_get_panel_orientation(connector); 1638 1.1 riastrad drm_connector_init_panel_orientation_property( 1639 1.1 riastrad &connector->base, 1640 1.1 riastrad connector->panel.fixed_mode->hdisplay, 1641 1.1 riastrad connector->panel.fixed_mode->vdisplay); 1642 1.1 riastrad } 1643 1.1 riastrad } 1644 1.1 riastrad 1645 1.1 riastrad #define NS_KHZ_RATIO 1000000 1646 1.1 riastrad 1647 1.1 riastrad #define PREPARE_CNT_MAX 0x3F 1648 1.1 riastrad #define EXIT_ZERO_CNT_MAX 0x3F 1649 1.1 riastrad #define CLK_ZERO_CNT_MAX 0xFF 1650 1.1 riastrad #define TRAIL_CNT_MAX 0x1F 1651 1.1 riastrad 1652 1.1 riastrad static void vlv_dphy_param_init(struct intel_dsi *intel_dsi) 1653 1.1 riastrad { 1654 1.1 riastrad struct drm_device *dev = intel_dsi->base.base.dev; 1655 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 1656 1.1 riastrad struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; 1657 1.1 riastrad u32 tlpx_ns, extra_byte_count, tlpx_ui; 1658 1.1 riastrad u32 ui_num, ui_den; 1659 1.1 riastrad u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; 1660 1.1 riastrad u32 ths_prepare_ns, tclk_trail_ns; 1661 1.1 riastrad u32 tclk_prepare_clkzero, ths_prepare_hszero; 1662 1.1 riastrad u32 lp_to_hs_switch, hs_to_lp_switch; 1663 1.1 riastrad u32 mul; 1664 1.1 riastrad 1665 1.1 riastrad tlpx_ns = intel_dsi_tlpx_ns(intel_dsi); 1666 1.1 riastrad 1667 1.1 riastrad switch (intel_dsi->lane_count) { 1668 1.1 riastrad case 1: 1669 1.1 riastrad case 2: 1670 1.1 riastrad extra_byte_count = 2; 1671 1.1 riastrad break; 1672 1.1 riastrad case 3: 1673 1.1 riastrad extra_byte_count = 4; 1674 1.1 riastrad break; 1675 1.1 riastrad case 4: 1676 1.1 riastrad default: 1677 1.1 riastrad extra_byte_count = 3; 1678 1.1 riastrad break; 1679 1.1 riastrad } 1680 1.1 riastrad 1681 1.1 riastrad /* in Kbps */ 1682 1.1 riastrad ui_num = NS_KHZ_RATIO; 1683 1.1 riastrad ui_den = intel_dsi_bitrate(intel_dsi); 1684 1.1 riastrad 1685 1.1 riastrad tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero; 1686 1.1 riastrad ths_prepare_hszero = mipi_config->ths_prepare_hszero; 1687 1.1 riastrad 1688 1.1 riastrad /* 1689 1.1 riastrad * B060 1690 1.1 riastrad * LP byte clock = TLPX/ (8UI) 1691 1.1 riastrad */ 1692 1.1 riastrad intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num); 1693 1.1 riastrad 1694 1.1 riastrad /* DDR clock period = 2 * UI 1695 1.1 riastrad * UI(sec) = 1/(bitrate * 10^3) (bitrate is in KHZ) 1696 1.1 riastrad * UI(nsec) = 10^6 / bitrate 1697 1.1 riastrad * DDR clock period (nsec) = 2 * UI = (2 * 10^6)/ bitrate 1698 1.1 riastrad * DDR clock count = ns_value / DDR clock period 1699 1.1 riastrad * 1700 1.1 riastrad * For GEMINILAKE dphy_param_reg will be programmed in terms of 1701 1.1 riastrad * HS byte clock count for other platform in HS ddr clock count 1702 1.1 riastrad */ 1703 1.1 riastrad mul = IS_GEMINILAKE(dev_priv) ? 8 : 2; 1704 1.1 riastrad ths_prepare_ns = max(mipi_config->ths_prepare, 1705 1.1 riastrad mipi_config->tclk_prepare); 1706 1.1 riastrad 1707 1.1 riastrad /* prepare count */ 1708 1.1 riastrad prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul); 1709 1.1 riastrad 1710 1.1 riastrad if (prepare_cnt > PREPARE_CNT_MAX) { 1711 1.1 riastrad DRM_DEBUG_KMS("prepare count too high %u\n", prepare_cnt); 1712 1.1 riastrad prepare_cnt = PREPARE_CNT_MAX; 1713 1.1 riastrad } 1714 1.1 riastrad 1715 1.1 riastrad /* exit zero count */ 1716 1.1 riastrad exit_zero_cnt = DIV_ROUND_UP( 1717 1.1 riastrad (ths_prepare_hszero - ths_prepare_ns) * ui_den, 1718 1.1 riastrad ui_num * mul 1719 1.1 riastrad ); 1720 1.1 riastrad 1721 1.1 riastrad /* 1722 1.1 riastrad * Exit zero is unified val ths_zero and ths_exit 1723 1.1 riastrad * minimum value for ths_exit = 110ns 1724 1.1 riastrad * min (exit_zero_cnt * 2) = 110/UI 1725 1.1 riastrad * exit_zero_cnt = 55/UI 1726 1.1 riastrad */ 1727 1.1 riastrad if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num) 1728 1.1 riastrad exit_zero_cnt += 1; 1729 1.1 riastrad 1730 1.1 riastrad if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) { 1731 1.1 riastrad DRM_DEBUG_KMS("exit zero count too high %u\n", exit_zero_cnt); 1732 1.1 riastrad exit_zero_cnt = EXIT_ZERO_CNT_MAX; 1733 1.1 riastrad } 1734 1.1 riastrad 1735 1.1 riastrad /* clk zero count */ 1736 1.1 riastrad clk_zero_cnt = DIV_ROUND_UP( 1737 1.1 riastrad (tclk_prepare_clkzero - ths_prepare_ns) 1738 1.1 riastrad * ui_den, ui_num * mul); 1739 1.1 riastrad 1740 1.1 riastrad if (clk_zero_cnt > CLK_ZERO_CNT_MAX) { 1741 1.1 riastrad DRM_DEBUG_KMS("clock zero count too high %u\n", clk_zero_cnt); 1742 1.1 riastrad clk_zero_cnt = CLK_ZERO_CNT_MAX; 1743 1.1 riastrad } 1744 1.1 riastrad 1745 1.1 riastrad /* trail count */ 1746 1.1 riastrad tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail); 1747 1.1 riastrad trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul); 1748 1.1 riastrad 1749 1.1 riastrad if (trail_cnt > TRAIL_CNT_MAX) { 1750 1.1 riastrad DRM_DEBUG_KMS("trail count too high %u\n", trail_cnt); 1751 1.1 riastrad trail_cnt = TRAIL_CNT_MAX; 1752 1.1 riastrad } 1753 1.1 riastrad 1754 1.1 riastrad /* B080 */ 1755 1.1 riastrad intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 | 1756 1.1 riastrad clk_zero_cnt << 8 | prepare_cnt; 1757 1.1 riastrad 1758 1.1 riastrad /* 1759 1.1 riastrad * LP to HS switch count = 4TLPX + PREP_COUNT * mul + EXIT_ZERO_COUNT * 1760 1.1 riastrad * mul + 10UI + Extra Byte Count 1761 1.1 riastrad * 1762 1.1 riastrad * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count 1763 1.1 riastrad * Extra Byte Count is calculated according to number of lanes. 1764 1.1 riastrad * High Low Switch Count is the Max of LP to HS and 1765 1.1 riastrad * HS to LP switch count 1766 1.1 riastrad * 1767 1.1 riastrad */ 1768 1.1 riastrad tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num); 1769 1.1 riastrad 1770 1.1 riastrad /* B044 */ 1771 1.1 riastrad /* FIXME: 1772 1.1 riastrad * The comment above does not match with the code */ 1773 1.1 riastrad lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * mul + 1774 1.1 riastrad exit_zero_cnt * mul + 10, 8); 1775 1.1 riastrad 1776 1.1 riastrad hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8); 1777 1.1 riastrad 1778 1.1 riastrad intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch); 1779 1.1 riastrad intel_dsi->hs_to_lp_count += extra_byte_count; 1780 1.1 riastrad 1781 1.1 riastrad /* B088 */ 1782 1.1 riastrad /* LP -> HS for clock lanes 1783 1.1 riastrad * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero + 1784 1.1 riastrad * extra byte count 1785 1.1 riastrad * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt * 1786 1.1 riastrad * 2(in UI) + extra byte count 1787 1.1 riastrad * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) / 1788 1.1 riastrad * 8 + extra byte count 1789 1.1 riastrad */ 1790 1.1 riastrad intel_dsi->clk_lp_to_hs_count = 1791 1.1 riastrad DIV_ROUND_UP( 1792 1.1 riastrad 4 * tlpx_ui + prepare_cnt * 2 + 1793 1.1 riastrad clk_zero_cnt * 2, 1794 1.1 riastrad 8); 1795 1.1 riastrad 1796 1.1 riastrad intel_dsi->clk_lp_to_hs_count += extra_byte_count; 1797 1.1 riastrad 1798 1.1 riastrad /* HS->LP for Clock Lanes 1799 1.1 riastrad * Low Power clock synchronisations + 1Tx byteclk + tclk_trail + 1800 1.1 riastrad * Extra byte count 1801 1.1 riastrad * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count 1802 1.1 riastrad * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 + 1803 1.1 riastrad * Extra byte count 1804 1.1 riastrad */ 1805 1.1 riastrad intel_dsi->clk_hs_to_lp_count = 1806 1.1 riastrad DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8, 1807 1.1 riastrad 8); 1808 1.1 riastrad intel_dsi->clk_hs_to_lp_count += extra_byte_count; 1809 1.1 riastrad 1810 1.1 riastrad intel_dsi_log_params(intel_dsi); 1811 1.1 riastrad } 1812 1.1 riastrad 1813 1.1 riastrad void vlv_dsi_init(struct drm_i915_private *dev_priv) 1814 1.1 riastrad { 1815 1.1 riastrad struct drm_device *dev = &dev_priv->drm; 1816 1.1 riastrad struct intel_dsi *intel_dsi; 1817 1.1 riastrad struct intel_encoder *intel_encoder; 1818 1.1 riastrad struct drm_encoder *encoder; 1819 1.1 riastrad struct intel_connector *intel_connector; 1820 1.1 riastrad struct drm_connector *connector; 1821 1.1 riastrad struct drm_display_mode *current_mode, *fixed_mode; 1822 1.1 riastrad enum port port; 1823 1.1 riastrad enum pipe pipe; 1824 1.1 riastrad 1825 1.1 riastrad DRM_DEBUG_KMS("\n"); 1826 1.1 riastrad 1827 1.1 riastrad /* There is no detection method for MIPI so rely on VBT */ 1828 1.1 riastrad if (!intel_bios_is_dsi_present(dev_priv, &port)) 1829 1.1 riastrad return; 1830 1.1 riastrad 1831 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 1832 1.1 riastrad dev_priv->mipi_mmio_base = BXT_MIPI_BASE; 1833 1.1 riastrad else 1834 1.1 riastrad dev_priv->mipi_mmio_base = VLV_MIPI_BASE; 1835 1.1 riastrad 1836 1.1 riastrad intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); 1837 1.1 riastrad if (!intel_dsi) 1838 1.1 riastrad return; 1839 1.1 riastrad 1840 1.1 riastrad intel_connector = intel_connector_alloc(); 1841 1.1 riastrad if (!intel_connector) { 1842 1.1 riastrad kfree(intel_dsi); 1843 1.1 riastrad return; 1844 1.1 riastrad } 1845 1.1 riastrad 1846 1.1 riastrad intel_encoder = &intel_dsi->base; 1847 1.1 riastrad encoder = &intel_encoder->base; 1848 1.1 riastrad intel_dsi->attached_connector = intel_connector; 1849 1.1 riastrad 1850 1.1 riastrad connector = &intel_connector->base; 1851 1.1 riastrad 1852 1.1 riastrad drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI, 1853 1.1 riastrad "DSI %c", port_name(port)); 1854 1.1 riastrad 1855 1.1 riastrad intel_encoder->compute_config = intel_dsi_compute_config; 1856 1.1 riastrad intel_encoder->pre_enable = intel_dsi_pre_enable; 1857 1.1 riastrad intel_encoder->disable = intel_dsi_disable; 1858 1.1 riastrad intel_encoder->post_disable = intel_dsi_post_disable; 1859 1.1 riastrad intel_encoder->get_hw_state = intel_dsi_get_hw_state; 1860 1.1 riastrad intel_encoder->get_config = intel_dsi_get_config; 1861 1.1 riastrad intel_encoder->update_pipe = intel_panel_update_backlight; 1862 1.1 riastrad 1863 1.1 riastrad intel_connector->get_hw_state = intel_connector_get_hw_state; 1864 1.1 riastrad 1865 1.1 riastrad intel_encoder->port = port; 1866 1.1 riastrad intel_encoder->type = INTEL_OUTPUT_DSI; 1867 1.1 riastrad intel_encoder->power_domain = POWER_DOMAIN_PORT_DSI; 1868 1.1 riastrad intel_encoder->cloneable = 0; 1869 1.1 riastrad 1870 1.1 riastrad /* 1871 1.1 riastrad * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI 1872 1.1 riastrad * port C. BXT isn't limited like this. 1873 1.1 riastrad */ 1874 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 1875 1.1 riastrad intel_encoder->pipe_mask = ~0; 1876 1.1 riastrad else if (port == PORT_A) 1877 1.1 riastrad intel_encoder->pipe_mask = BIT(PIPE_A); 1878 1.1 riastrad else 1879 1.1 riastrad intel_encoder->pipe_mask = BIT(PIPE_B); 1880 1.1 riastrad 1881 1.1 riastrad if (dev_priv->vbt.dsi.config->dual_link) 1882 1.1 riastrad intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C); 1883 1.1 riastrad else 1884 1.1 riastrad intel_dsi->ports = BIT(port); 1885 1.1 riastrad 1886 1.1 riastrad intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports; 1887 1.1 riastrad intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports; 1888 1.1 riastrad 1889 1.1 riastrad /* Create a DSI host (and a device) for each port. */ 1890 1.1 riastrad for_each_dsi_port(port, intel_dsi->ports) { 1891 1.1 riastrad struct intel_dsi_host *host; 1892 1.1 riastrad 1893 1.1 riastrad host = intel_dsi_host_init(intel_dsi, &intel_dsi_host_ops, 1894 1.1 riastrad port); 1895 1.1 riastrad if (!host) 1896 1.1 riastrad goto err; 1897 1.1 riastrad 1898 1.1 riastrad intel_dsi->dsi_hosts[port] = host; 1899 1.1 riastrad } 1900 1.1 riastrad 1901 1.1 riastrad if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) { 1902 1.1 riastrad DRM_DEBUG_KMS("no device found\n"); 1903 1.1 riastrad goto err; 1904 1.1 riastrad } 1905 1.1 riastrad 1906 1.1 riastrad /* Use clock read-back from current hw-state for fastboot */ 1907 1.1 riastrad current_mode = intel_encoder_current_mode(intel_encoder); 1908 1.1 riastrad if (current_mode) { 1909 1.1 riastrad DRM_DEBUG_KMS("Calculated pclk %d GOP %d\n", 1910 1.1 riastrad intel_dsi->pclk, current_mode->clock); 1911 1.1 riastrad if (intel_fuzzy_clock_check(intel_dsi->pclk, 1912 1.1 riastrad current_mode->clock)) { 1913 1.1 riastrad DRM_DEBUG_KMS("Using GOP pclk\n"); 1914 1.1 riastrad intel_dsi->pclk = current_mode->clock; 1915 1.1 riastrad } 1916 1.1 riastrad 1917 1.1 riastrad kfree(current_mode); 1918 1.1 riastrad } 1919 1.1 riastrad 1920 1.1 riastrad vlv_dphy_param_init(intel_dsi); 1921 1.1 riastrad 1922 1.1 riastrad intel_dsi_vbt_gpio_init(intel_dsi, 1923 1.1 riastrad intel_dsi_get_hw_state(intel_encoder, &pipe)); 1924 1.1 riastrad 1925 1.1 riastrad drm_connector_init(dev, connector, &intel_dsi_connector_funcs, 1926 1.1 riastrad DRM_MODE_CONNECTOR_DSI); 1927 1.1 riastrad 1928 1.1 riastrad drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs); 1929 1.1 riastrad 1930 1.1 riastrad connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/ 1931 1.1 riastrad connector->interlace_allowed = false; 1932 1.1 riastrad connector->doublescan_allowed = false; 1933 1.1 riastrad 1934 1.1 riastrad intel_connector_attach_encoder(intel_connector, intel_encoder); 1935 1.1 riastrad 1936 1.1 riastrad mutex_lock(&dev->mode_config.mutex); 1937 1.1 riastrad fixed_mode = intel_panel_vbt_fixed_mode(intel_connector); 1938 1.1 riastrad mutex_unlock(&dev->mode_config.mutex); 1939 1.1 riastrad 1940 1.1 riastrad if (!fixed_mode) { 1941 1.1 riastrad DRM_DEBUG_KMS("no fixed mode\n"); 1942 1.1 riastrad goto err_cleanup_connector; 1943 1.1 riastrad } 1944 1.1 riastrad 1945 1.1 riastrad intel_panel_init(&intel_connector->panel, fixed_mode, NULL); 1946 1.1 riastrad intel_panel_setup_backlight(connector, INVALID_PIPE); 1947 1.1 riastrad 1948 1.1 riastrad vlv_dsi_add_properties(intel_connector); 1949 1.1 riastrad 1950 1.1 riastrad return; 1951 1.1 riastrad 1952 1.1 riastrad err_cleanup_connector: 1953 1.1 riastrad drm_connector_cleanup(&intel_connector->base); 1954 1.1 riastrad err: 1955 1.1 riastrad drm_encoder_cleanup(&intel_encoder->base); 1956 1.1 riastrad kfree(intel_dsi); 1957 1.1 riastrad kfree(intel_connector); 1958 1.1 riastrad } 1959