1 /* 2 * Copyright © 2018 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Madhav Chauhan <madhav.chauhan@intel.com> 25 * Jani Nikula <jani.nikula@intel.com> 26 */ 27 28 #include <drm/display/drm_dsc_helper.h> 29 #include <drm/drm_atomic_helper.h> 30 #include <drm/drm_mipi_dsi.h> 31 32 #include "i915_reg.h" 33 #include "icl_dsi.h" 34 #include "icl_dsi_regs.h" 35 #include "intel_atomic.h" 36 #include "intel_backlight.h" 37 #include "intel_backlight_regs.h" 38 #include "intel_combo_phy.h" 39 #include "intel_combo_phy_regs.h" 40 #include "intel_connector.h" 41 #include "intel_crtc.h" 42 #include "intel_ddi.h" 43 #include "intel_de.h" 44 #include "intel_dsi.h" 45 #include "intel_dsi_vbt.h" 46 #include "intel_panel.h" 47 #include "intel_vdsc.h" 48 #include "intel_vdsc_regs.h" 49 #include "skl_scaler.h" 50 #include "skl_universal_plane.h" 51 52 static int header_credits_available(struct drm_i915_private *dev_priv, 53 enum transcoder dsi_trans) 54 { 55 return (intel_de_read(dev_priv, DSI_CMD_TXCTL(dsi_trans)) & FREE_HEADER_CREDIT_MASK) 56 >> FREE_HEADER_CREDIT_SHIFT; 57 } 58 59 static int payload_credits_available(struct drm_i915_private *dev_priv, 60 enum transcoder dsi_trans) 61 { 62 return (intel_de_read(dev_priv, DSI_CMD_TXCTL(dsi_trans)) & FREE_PLOAD_CREDIT_MASK) 63 >> FREE_PLOAD_CREDIT_SHIFT; 64 } 65 66 static bool wait_for_header_credits(struct drm_i915_private *dev_priv, 67 enum transcoder dsi_trans, int hdr_credit) 68 { 69 if (wait_for_us(header_credits_available(dev_priv, dsi_trans) >= 70 hdr_credit, 100)) { 71 drm_err(&dev_priv->drm, "DSI header credits not released\n"); 72 return false; 73 } 74 75 return true; 76 } 77 78 static bool wait_for_payload_credits(struct drm_i915_private *dev_priv, 79 enum transcoder dsi_trans, int payld_credit) 80 { 81 if (wait_for_us(payload_credits_available(dev_priv, dsi_trans) >= 82 payld_credit, 100)) { 83 drm_err(&dev_priv->drm, "DSI payload credits not released\n"); 84 return false; 85 } 86 87 return true; 88 } 89 90 static enum transcoder dsi_port_to_transcoder(enum port port) 91 { 92 if (port == PORT_A) 93 return TRANSCODER_DSI_0; 94 else 95 return TRANSCODER_DSI_1; 96 } 97 98 static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder) 99 { 100 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 101 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 102 struct mipi_dsi_device *dsi; 103 enum port port; 104 enum transcoder dsi_trans; 105 int ret; 106 107 /* wait for header/payload credits to be released */ 108 for_each_dsi_port(port, intel_dsi->ports) { 109 dsi_trans = dsi_port_to_transcoder(port); 110 wait_for_header_credits(dev_priv, dsi_trans, MAX_HEADER_CREDIT); 111 wait_for_payload_credits(dev_priv, dsi_trans, MAX_PLOAD_CREDIT); 112 } 113 114 /* send nop DCS command */ 115 for_each_dsi_port(port, intel_dsi->ports) { 116 dsi = intel_dsi->dsi_hosts[port]->device; 117 dsi->mode_flags |= MIPI_DSI_MODE_LPM; 118 dsi->channel = 0; 119 ret = mipi_dsi_dcs_nop(dsi); 120 if (ret < 0) 121 drm_err(&dev_priv->drm, 122 "error sending DCS NOP command\n"); 123 } 124 125 /* wait for header credits to be released */ 126 for_each_dsi_port(port, intel_dsi->ports) { 127 dsi_trans = dsi_port_to_transcoder(port); 128 wait_for_header_credits(dev_priv, dsi_trans, MAX_HEADER_CREDIT); 129 } 130 131 /* wait for LP TX in progress bit to be cleared */ 132 for_each_dsi_port(port, intel_dsi->ports) { 133 dsi_trans = dsi_port_to_transcoder(port); 134 if (wait_for_us(!(intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)) & 135 LPTX_IN_PROGRESS), 20)) 136 drm_err(&dev_priv->drm, "LPTX bit not cleared\n"); 137 } 138 } 139 140 static int dsi_send_pkt_payld(struct intel_dsi_host *host, 141 const struct mipi_dsi_packet *packet) 142 { 143 struct intel_dsi *intel_dsi = host->intel_dsi; 144 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev); 145 enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 146 const u8 *data = packet->payload; 147 u32 len = packet->payload_length; 148 int i, j; 149 150 /* payload queue can accept *256 bytes*, check limit */ 151 if (len > MAX_PLOAD_CREDIT * 4) { 152 drm_err(&i915->drm, "payload size exceeds max queue limit\n"); 153 return -EINVAL; 154 } 155 156 for (i = 0; i < len; i += 4) { 157 u32 tmp = 0; 158 159 if (!wait_for_payload_credits(i915, dsi_trans, 1)) 160 return -EBUSY; 161 162 for (j = 0; j < min_t(u32, len - i, 4); j++) 163 tmp |= *data++ << 8 * j; 164 165 intel_de_write(i915, DSI_CMD_TXPYLD(dsi_trans), tmp); 166 } 167 168 return 0; 169 } 170 171 static int dsi_send_pkt_hdr(struct intel_dsi_host *host, 172 const struct mipi_dsi_packet *packet, 173 bool enable_lpdt) 174 { 175 struct intel_dsi *intel_dsi = host->intel_dsi; 176 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 177 enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 178 u32 tmp; 179 180 if (!wait_for_header_credits(dev_priv, dsi_trans, 1)) 181 return -EBUSY; 182 183 tmp = intel_de_read(dev_priv, DSI_CMD_TXHDR(dsi_trans)); 184 185 if (packet->payload) 186 tmp |= PAYLOAD_PRESENT; 187 else 188 tmp &= ~PAYLOAD_PRESENT; 189 190 tmp &= ~VBLANK_FENCE; 191 192 if (enable_lpdt) 193 tmp |= LP_DATA_TRANSFER; 194 else 195 tmp &= ~LP_DATA_TRANSFER; 196 197 tmp &= ~(PARAM_WC_MASK | VC_MASK | DT_MASK); 198 tmp |= ((packet->header[0] & VC_MASK) << VC_SHIFT); 199 tmp |= ((packet->header[0] & DT_MASK) << DT_SHIFT); 200 tmp |= (packet->header[1] << PARAM_WC_LOWER_SHIFT); 201 tmp |= (packet->header[2] << PARAM_WC_UPPER_SHIFT); 202 intel_de_write(dev_priv, DSI_CMD_TXHDR(dsi_trans), tmp); 203 204 return 0; 205 } 206 207 void icl_dsi_frame_update(struct intel_crtc_state *crtc_state) 208 { 209 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 210 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 211 u32 mode_flags; 212 enum port port; 213 214 mode_flags = crtc_state->mode_flags; 215 216 /* 217 * case 1 also covers dual link 218 * In case of dual link, frame update should be set on 219 * DSI_0 220 */ 221 if (mode_flags & I915_MODE_FLAG_DSI_USE_TE0) 222 port = PORT_A; 223 else if (mode_flags & I915_MODE_FLAG_DSI_USE_TE1) 224 port = PORT_B; 225 else 226 return; 227 228 intel_de_rmw(dev_priv, DSI_CMD_FRMCTL(port), 0, DSI_FRAME_UPDATE_REQUEST); 229 } 230 231 static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder) 232 { 233 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 234 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 235 enum phy phy; 236 u32 tmp, mask, val; 237 int lane; 238 239 for_each_dsi_phy(phy, intel_dsi->phys) { 240 /* 241 * Program voltage swing and pre-emphasis level values as per 242 * table in BSPEC under DDI buffer programing 243 */ 244 mask = SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK; 245 val = SCALING_MODE_SEL(0x2) | TAP2_DISABLE | TAP3_DISABLE | 246 RTERM_SELECT(0x6); 247 tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN(0, phy)); 248 tmp &= ~mask; 249 tmp |= val; 250 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 251 intel_de_rmw(dev_priv, ICL_PORT_TX_DW5_AUX(phy), mask, val); 252 253 mask = SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 254 RCOMP_SCALAR_MASK; 255 val = SWING_SEL_UPPER(0x2) | SWING_SEL_LOWER(0x2) | 256 RCOMP_SCALAR(0x98); 257 tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN(0, phy)); 258 tmp &= ~mask; 259 tmp |= val; 260 intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), tmp); 261 intel_de_rmw(dev_priv, ICL_PORT_TX_DW2_AUX(phy), mask, val); 262 263 mask = POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 264 CURSOR_COEFF_MASK; 265 val = POST_CURSOR_1(0x0) | POST_CURSOR_2(0x0) | 266 CURSOR_COEFF(0x3f); 267 intel_de_rmw(dev_priv, ICL_PORT_TX_DW4_AUX(phy), mask, val); 268 269 /* Bspec: must not use GRP register for write */ 270 for (lane = 0; lane <= 3; lane++) 271 intel_de_rmw(dev_priv, ICL_PORT_TX_DW4_LN(lane, phy), 272 mask, val); 273 } 274 } 275 276 static void configure_dual_link_mode(struct intel_encoder *encoder, 277 const struct intel_crtc_state *pipe_config) 278 { 279 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 280 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 281 i915_reg_t dss_ctl1_reg, dss_ctl2_reg; 282 u32 dss_ctl1; 283 284 /* FIXME: Move all DSS handling to intel_vdsc.c */ 285 if (DISPLAY_VER(dev_priv) >= 12) { 286 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 287 288 dss_ctl1_reg = ICL_PIPE_DSS_CTL1(crtc->pipe); 289 dss_ctl2_reg = ICL_PIPE_DSS_CTL2(crtc->pipe); 290 } else { 291 dss_ctl1_reg = DSS_CTL1; 292 dss_ctl2_reg = DSS_CTL2; 293 } 294 295 dss_ctl1 = intel_de_read(dev_priv, dss_ctl1_reg); 296 dss_ctl1 |= SPLITTER_ENABLE; 297 dss_ctl1 &= ~OVERLAP_PIXELS_MASK; 298 dss_ctl1 |= OVERLAP_PIXELS(intel_dsi->pixel_overlap); 299 300 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { 301 const struct drm_display_mode *adjusted_mode = 302 &pipe_config->hw.adjusted_mode; 303 u16 hactive = adjusted_mode->crtc_hdisplay; 304 u16 dl_buffer_depth; 305 306 dss_ctl1 &= ~DUAL_LINK_MODE_INTERLEAVE; 307 dl_buffer_depth = hactive / 2 + intel_dsi->pixel_overlap; 308 309 if (dl_buffer_depth > MAX_DL_BUFFER_TARGET_DEPTH) 310 drm_err(&dev_priv->drm, 311 "DL buffer depth exceed max value\n"); 312 313 dss_ctl1 &= ~LEFT_DL_BUF_TARGET_DEPTH_MASK; 314 dss_ctl1 |= LEFT_DL_BUF_TARGET_DEPTH(dl_buffer_depth); 315 intel_de_rmw(dev_priv, dss_ctl2_reg, RIGHT_DL_BUF_TARGET_DEPTH_MASK, 316 RIGHT_DL_BUF_TARGET_DEPTH(dl_buffer_depth)); 317 } else { 318 /* Interleave */ 319 dss_ctl1 |= DUAL_LINK_MODE_INTERLEAVE; 320 } 321 322 intel_de_write(dev_priv, dss_ctl1_reg, dss_ctl1); 323 } 324 325 /* aka DSI 8X clock */ 326 static int afe_clk(struct intel_encoder *encoder, 327 const struct intel_crtc_state *crtc_state) 328 { 329 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 330 int bpp; 331 332 if (crtc_state->dsc.compression_enable) 333 bpp = to_bpp_int(crtc_state->dsc.compressed_bpp_x16); 334 else 335 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 336 337 return DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp, intel_dsi->lane_count); 338 } 339 340 static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder, 341 const struct intel_crtc_state *crtc_state) 342 { 343 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 344 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 345 enum port port; 346 int afe_clk_khz; 347 int theo_word_clk, act_word_clk; 348 u32 esc_clk_div_m, esc_clk_div_m_phy; 349 350 afe_clk_khz = afe_clk(encoder, crtc_state); 351 352 if (IS_ALDERLAKE_S(dev_priv) || IS_ALDERLAKE_P(dev_priv)) { 353 theo_word_clk = DIV_ROUND_UP(afe_clk_khz, 8 * DSI_MAX_ESC_CLK); 354 act_word_clk = max(3, theo_word_clk + (theo_word_clk + 1) % 2); 355 esc_clk_div_m = act_word_clk * 8; 356 esc_clk_div_m_phy = (act_word_clk - 1) / 2; 357 } else { 358 esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK); 359 } 360 361 for_each_dsi_port(port, intel_dsi->ports) { 362 intel_de_write(dev_priv, ICL_DSI_ESC_CLK_DIV(port), 363 esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 364 intel_de_posting_read(dev_priv, ICL_DSI_ESC_CLK_DIV(port)); 365 } 366 367 for_each_dsi_port(port, intel_dsi->ports) { 368 intel_de_write(dev_priv, ICL_DPHY_ESC_CLK_DIV(port), 369 esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 370 intel_de_posting_read(dev_priv, ICL_DPHY_ESC_CLK_DIV(port)); 371 } 372 373 if (IS_ALDERLAKE_S(dev_priv) || IS_ALDERLAKE_P(dev_priv)) { 374 for_each_dsi_port(port, intel_dsi->ports) { 375 intel_de_write(dev_priv, ADL_MIPIO_DW(port, 8), 376 esc_clk_div_m_phy & TX_ESC_CLK_DIV_PHY); 377 intel_de_posting_read(dev_priv, ADL_MIPIO_DW(port, 8)); 378 } 379 } 380 } 381 382 static void get_dsi_io_power_domains(struct drm_i915_private *dev_priv, 383 struct intel_dsi *intel_dsi) 384 { 385 enum port port; 386 387 for_each_dsi_port(port, intel_dsi->ports) { 388 drm_WARN_ON(&dev_priv->drm, intel_dsi->io_wakeref[port]); 389 intel_dsi->io_wakeref[port] = 390 intel_display_power_get(dev_priv, 391 port == PORT_A ? 392 POWER_DOMAIN_PORT_DDI_IO_A : 393 POWER_DOMAIN_PORT_DDI_IO_B); 394 } 395 } 396 397 static void gen11_dsi_enable_io_power(struct intel_encoder *encoder) 398 { 399 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 400 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 401 enum port port; 402 403 for_each_dsi_port(port, intel_dsi->ports) 404 intel_de_rmw(dev_priv, ICL_DSI_IO_MODECTL(port), 405 0, COMBO_PHY_MODE_DSI); 406 407 get_dsi_io_power_domains(dev_priv, intel_dsi); 408 } 409 410 static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder) 411 { 412 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 413 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 414 enum phy phy; 415 416 for_each_dsi_phy(phy, intel_dsi->phys) 417 intel_combo_phy_power_up_lanes(dev_priv, phy, true, 418 intel_dsi->lane_count, false); 419 } 420 421 static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder) 422 { 423 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 424 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 425 enum phy phy; 426 u32 tmp; 427 int lane; 428 429 /* Step 4b(i) set loadgen select for transmit and aux lanes */ 430 for_each_dsi_phy(phy, intel_dsi->phys) { 431 intel_de_rmw(dev_priv, ICL_PORT_TX_DW4_AUX(phy), LOADGEN_SELECT, 0); 432 for (lane = 0; lane <= 3; lane++) 433 intel_de_rmw(dev_priv, ICL_PORT_TX_DW4_LN(lane, phy), 434 LOADGEN_SELECT, lane != 2 ? LOADGEN_SELECT : 0); 435 } 436 437 /* Step 4b(ii) set latency optimization for transmit and aux lanes */ 438 for_each_dsi_phy(phy, intel_dsi->phys) { 439 intel_de_rmw(dev_priv, ICL_PORT_TX_DW2_AUX(phy), 440 FRC_LATENCY_OPTIM_MASK, FRC_LATENCY_OPTIM_VAL(0x5)); 441 tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN(0, phy)); 442 tmp &= ~FRC_LATENCY_OPTIM_MASK; 443 tmp |= FRC_LATENCY_OPTIM_VAL(0x5); 444 intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), tmp); 445 446 /* For EHL, TGL, set latency optimization for PCS_DW1 lanes */ 447 if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv) || 448 (DISPLAY_VER(dev_priv) >= 12)) { 449 intel_de_rmw(dev_priv, ICL_PORT_PCS_DW1_AUX(phy), 450 LATENCY_OPTIM_MASK, LATENCY_OPTIM_VAL(0)); 451 452 tmp = intel_de_read(dev_priv, 453 ICL_PORT_PCS_DW1_LN(0, phy)); 454 tmp &= ~LATENCY_OPTIM_MASK; 455 tmp |= LATENCY_OPTIM_VAL(0x1); 456 intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), 457 tmp); 458 } 459 } 460 461 } 462 463 static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder) 464 { 465 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 466 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 467 u32 tmp; 468 enum phy phy; 469 470 /* clear common keeper enable bit */ 471 for_each_dsi_phy(phy, intel_dsi->phys) { 472 tmp = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN(0, phy)); 473 tmp &= ~COMMON_KEEPER_EN; 474 intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), tmp); 475 intel_de_rmw(dev_priv, ICL_PORT_PCS_DW1_AUX(phy), COMMON_KEEPER_EN, 0); 476 } 477 478 /* 479 * Set SUS Clock Config bitfield to 11b 480 * Note: loadgen select program is done 481 * as part of lane phy sequence configuration 482 */ 483 for_each_dsi_phy(phy, intel_dsi->phys) 484 intel_de_rmw(dev_priv, ICL_PORT_CL_DW5(phy), 0, SUS_CLOCK_CONFIG); 485 486 /* Clear training enable to change swing values */ 487 for_each_dsi_phy(phy, intel_dsi->phys) { 488 tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN(0, phy)); 489 tmp &= ~TX_TRAINING_EN; 490 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 491 intel_de_rmw(dev_priv, ICL_PORT_TX_DW5_AUX(phy), TX_TRAINING_EN, 0); 492 } 493 494 /* Program swing and de-emphasis */ 495 dsi_program_swing_and_deemphasis(encoder); 496 497 /* Set training enable to trigger update */ 498 for_each_dsi_phy(phy, intel_dsi->phys) { 499 tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN(0, phy)); 500 tmp |= TX_TRAINING_EN; 501 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 502 intel_de_rmw(dev_priv, ICL_PORT_TX_DW5_AUX(phy), 0, TX_TRAINING_EN); 503 } 504 } 505 506 static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder) 507 { 508 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 509 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 510 enum port port; 511 512 for_each_dsi_port(port, intel_dsi->ports) { 513 intel_de_rmw(dev_priv, DDI_BUF_CTL(port), 0, DDI_BUF_CTL_ENABLE); 514 515 if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 516 DDI_BUF_IS_IDLE), 517 500)) 518 drm_err(&dev_priv->drm, "DDI port:%c buffer idle\n", 519 port_name(port)); 520 } 521 } 522 523 static void 524 gen11_dsi_setup_dphy_timings(struct intel_encoder *encoder, 525 const struct intel_crtc_state *crtc_state) 526 { 527 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 528 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 529 enum port port; 530 enum phy phy; 531 532 /* Program DPHY clock lanes timings */ 533 for_each_dsi_port(port, intel_dsi->ports) 534 intel_de_write(dev_priv, DPHY_CLK_TIMING_PARAM(port), 535 intel_dsi->dphy_reg); 536 537 /* Program DPHY data lanes timings */ 538 for_each_dsi_port(port, intel_dsi->ports) 539 intel_de_write(dev_priv, DPHY_DATA_TIMING_PARAM(port), 540 intel_dsi->dphy_data_lane_reg); 541 542 /* 543 * If DSI link operating at or below an 800 MHz, 544 * TA_SURE should be override and programmed to 545 * a value '0' inside TA_PARAM_REGISTERS otherwise 546 * leave all fields at HW default values. 547 */ 548 if (DISPLAY_VER(dev_priv) == 11) { 549 if (afe_clk(encoder, crtc_state) <= 800000) { 550 for_each_dsi_port(port, intel_dsi->ports) 551 intel_de_rmw(dev_priv, DPHY_TA_TIMING_PARAM(port), 552 TA_SURE_MASK, 553 TA_SURE_OVERRIDE | TA_SURE(0)); 554 } 555 } 556 557 if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv)) { 558 for_each_dsi_phy(phy, intel_dsi->phys) 559 intel_de_rmw(dev_priv, ICL_DPHY_CHKN(phy), 560 0, ICL_DPHY_CHKN_AFE_OVER_PPI_STRAP); 561 } 562 } 563 564 static void 565 gen11_dsi_setup_timings(struct intel_encoder *encoder, 566 const struct intel_crtc_state *crtc_state) 567 { 568 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 569 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 570 enum port port; 571 572 /* Program T-INIT master registers */ 573 for_each_dsi_port(port, intel_dsi->ports) 574 intel_de_rmw(dev_priv, ICL_DSI_T_INIT_MASTER(port), 575 DSI_T_INIT_MASTER_MASK, intel_dsi->init_count); 576 577 /* shadow register inside display core */ 578 for_each_dsi_port(port, intel_dsi->ports) 579 intel_de_write(dev_priv, DSI_CLK_TIMING_PARAM(port), 580 intel_dsi->dphy_reg); 581 582 /* shadow register inside display core */ 583 for_each_dsi_port(port, intel_dsi->ports) 584 intel_de_write(dev_priv, DSI_DATA_TIMING_PARAM(port), 585 intel_dsi->dphy_data_lane_reg); 586 587 /* shadow register inside display core */ 588 if (DISPLAY_VER(dev_priv) == 11) { 589 if (afe_clk(encoder, crtc_state) <= 800000) { 590 for_each_dsi_port(port, intel_dsi->ports) { 591 intel_de_rmw(dev_priv, DSI_TA_TIMING_PARAM(port), 592 TA_SURE_MASK, 593 TA_SURE_OVERRIDE | TA_SURE(0)); 594 } 595 } 596 } 597 } 598 599 static void gen11_dsi_gate_clocks(struct intel_encoder *encoder) 600 { 601 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 602 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 603 u32 tmp; 604 enum phy phy; 605 606 mutex_lock(&dev_priv->display.dpll.lock); 607 tmp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 608 for_each_dsi_phy(phy, intel_dsi->phys) 609 tmp |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 610 611 intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, tmp); 612 mutex_unlock(&dev_priv->display.dpll.lock); 613 } 614 615 static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder) 616 { 617 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 618 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 619 u32 tmp; 620 enum phy phy; 621 622 mutex_lock(&dev_priv->display.dpll.lock); 623 tmp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 624 for_each_dsi_phy(phy, intel_dsi->phys) 625 tmp &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 626 627 intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, tmp); 628 mutex_unlock(&dev_priv->display.dpll.lock); 629 } 630 631 static bool gen11_dsi_is_clock_enabled(struct intel_encoder *encoder) 632 { 633 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 634 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 635 bool clock_enabled = false; 636 enum phy phy; 637 u32 tmp; 638 639 tmp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 640 641 for_each_dsi_phy(phy, intel_dsi->phys) { 642 if (!(tmp & ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy))) 643 clock_enabled = true; 644 } 645 646 return clock_enabled; 647 } 648 649 static void gen11_dsi_map_pll(struct intel_encoder *encoder, 650 const struct intel_crtc_state *crtc_state) 651 { 652 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 653 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 654 struct intel_shared_dpll *pll = crtc_state->shared_dpll; 655 enum phy phy; 656 u32 val; 657 658 mutex_lock(&dev_priv->display.dpll.lock); 659 660 val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 661 for_each_dsi_phy(phy, intel_dsi->phys) { 662 val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 663 val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 664 } 665 intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 666 667 for_each_dsi_phy(phy, intel_dsi->phys) { 668 val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 669 } 670 intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 671 672 intel_de_posting_read(dev_priv, ICL_DPCLKA_CFGCR0); 673 674 mutex_unlock(&dev_priv->display.dpll.lock); 675 } 676 677 static void 678 gen11_dsi_configure_transcoder(struct intel_encoder *encoder, 679 const struct intel_crtc_state *pipe_config) 680 { 681 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 682 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 683 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 684 enum pipe pipe = crtc->pipe; 685 u32 tmp; 686 enum port port; 687 enum transcoder dsi_trans; 688 689 for_each_dsi_port(port, intel_dsi->ports) { 690 dsi_trans = dsi_port_to_transcoder(port); 691 tmp = intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)); 692 693 if (intel_dsi->eotp_pkt) 694 tmp &= ~EOTP_DISABLED; 695 else 696 tmp |= EOTP_DISABLED; 697 698 /* enable link calibration if freq > 1.5Gbps */ 699 if (afe_clk(encoder, pipe_config) >= 1500 * 1000) { 700 tmp &= ~LINK_CALIBRATION_MASK; 701 tmp |= CALIBRATION_ENABLED_INITIAL_ONLY; 702 } 703 704 /* configure continuous clock */ 705 tmp &= ~CONTINUOUS_CLK_MASK; 706 if (intel_dsi->clock_stop) 707 tmp |= CLK_ENTER_LP_AFTER_DATA; 708 else 709 tmp |= CLK_HS_CONTINUOUS; 710 711 /* configure buffer threshold limit to minimum */ 712 tmp &= ~PIX_BUF_THRESHOLD_MASK; 713 tmp |= PIX_BUF_THRESHOLD_1_4; 714 715 /* set virtual channel to '0' */ 716 tmp &= ~PIX_VIRT_CHAN_MASK; 717 tmp |= PIX_VIRT_CHAN(0); 718 719 /* program BGR transmission */ 720 if (intel_dsi->bgr_enabled) 721 tmp |= BGR_TRANSMISSION; 722 723 /* select pixel format */ 724 tmp &= ~PIX_FMT_MASK; 725 if (pipe_config->dsc.compression_enable) { 726 tmp |= PIX_FMT_COMPRESSED; 727 } else { 728 switch (intel_dsi->pixel_format) { 729 default: 730 MISSING_CASE(intel_dsi->pixel_format); 731 fallthrough; 732 case MIPI_DSI_FMT_RGB565: 733 tmp |= PIX_FMT_RGB565; 734 break; 735 case MIPI_DSI_FMT_RGB666_PACKED: 736 tmp |= PIX_FMT_RGB666_PACKED; 737 break; 738 case MIPI_DSI_FMT_RGB666: 739 tmp |= PIX_FMT_RGB666_LOOSE; 740 break; 741 case MIPI_DSI_FMT_RGB888: 742 tmp |= PIX_FMT_RGB888; 743 break; 744 } 745 } 746 747 if (DISPLAY_VER(dev_priv) >= 12) { 748 if (is_vid_mode(intel_dsi)) 749 tmp |= BLANKING_PACKET_ENABLE; 750 } 751 752 /* program DSI operation mode */ 753 if (is_vid_mode(intel_dsi)) { 754 tmp &= ~OP_MODE_MASK; 755 switch (intel_dsi->video_mode) { 756 default: 757 MISSING_CASE(intel_dsi->video_mode); 758 fallthrough; 759 case NON_BURST_SYNC_EVENTS: 760 tmp |= VIDEO_MODE_SYNC_EVENT; 761 break; 762 case NON_BURST_SYNC_PULSE: 763 tmp |= VIDEO_MODE_SYNC_PULSE; 764 break; 765 } 766 } else { 767 /* 768 * FIXME: Retrieve this info from VBT. 769 * As per the spec when dsi transcoder is operating 770 * in TE GATE mode, TE comes from GPIO 771 * which is UTIL PIN for DSI 0. 772 * Also this GPIO would not be used for other 773 * purposes is an assumption. 774 */ 775 tmp &= ~OP_MODE_MASK; 776 tmp |= CMD_MODE_TE_GATE; 777 tmp |= TE_SOURCE_GPIO; 778 } 779 780 intel_de_write(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans), tmp); 781 } 782 783 /* enable port sync mode if dual link */ 784 if (intel_dsi->dual_link) { 785 for_each_dsi_port(port, intel_dsi->ports) { 786 dsi_trans = dsi_port_to_transcoder(port); 787 intel_de_rmw(dev_priv, 788 TRANS_DDI_FUNC_CTL2(dev_priv, dsi_trans), 789 0, PORT_SYNC_MODE_ENABLE); 790 } 791 792 /* configure stream splitting */ 793 configure_dual_link_mode(encoder, pipe_config); 794 } 795 796 for_each_dsi_port(port, intel_dsi->ports) { 797 dsi_trans = dsi_port_to_transcoder(port); 798 799 /* select data lane width */ 800 tmp = intel_de_read(dev_priv, 801 TRANS_DDI_FUNC_CTL(dev_priv, dsi_trans)); 802 tmp &= ~DDI_PORT_WIDTH_MASK; 803 tmp |= DDI_PORT_WIDTH(intel_dsi->lane_count); 804 805 /* select input pipe */ 806 tmp &= ~TRANS_DDI_EDP_INPUT_MASK; 807 switch (pipe) { 808 default: 809 MISSING_CASE(pipe); 810 fallthrough; 811 case PIPE_A: 812 tmp |= TRANS_DDI_EDP_INPUT_A_ON; 813 break; 814 case PIPE_B: 815 tmp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 816 break; 817 case PIPE_C: 818 tmp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 819 break; 820 case PIPE_D: 821 tmp |= TRANS_DDI_EDP_INPUT_D_ONOFF; 822 break; 823 } 824 825 /* enable DDI buffer */ 826 tmp |= TRANS_DDI_FUNC_ENABLE; 827 intel_de_write(dev_priv, 828 TRANS_DDI_FUNC_CTL(dev_priv, dsi_trans), tmp); 829 } 830 831 /* wait for link ready */ 832 for_each_dsi_port(port, intel_dsi->ports) { 833 dsi_trans = dsi_port_to_transcoder(port); 834 if (wait_for_us((intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)) & 835 LINK_READY), 2500)) 836 drm_err(&dev_priv->drm, "DSI link not ready\n"); 837 } 838 } 839 840 static void 841 gen11_dsi_set_transcoder_timings(struct intel_encoder *encoder, 842 const struct intel_crtc_state *crtc_state) 843 { 844 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 845 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 846 const struct drm_display_mode *adjusted_mode = 847 &crtc_state->hw.adjusted_mode; 848 enum port port; 849 enum transcoder dsi_trans; 850 /* horizontal timings */ 851 u16 htotal, hactive, hsync_start, hsync_end, hsync_size; 852 u16 hback_porch; 853 /* vertical timings */ 854 u16 vtotal, vactive, vsync_start, vsync_end, vsync_shift; 855 int mul = 1, div = 1; 856 857 /* 858 * Adjust horizontal timings (htotal, hsync_start, hsync_end) to account 859 * for slower link speed if DSC is enabled. 860 * 861 * The compression frequency ratio is the ratio between compressed and 862 * non-compressed link speeds, and simplifies down to the ratio between 863 * compressed and non-compressed bpp. 864 */ 865 if (crtc_state->dsc.compression_enable) { 866 mul = to_bpp_int(crtc_state->dsc.compressed_bpp_x16); 867 div = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 868 } 869 870 hactive = adjusted_mode->crtc_hdisplay; 871 872 if (is_vid_mode(intel_dsi)) 873 htotal = DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div); 874 else 875 htotal = DIV_ROUND_UP((hactive + 160) * mul, div); 876 877 hsync_start = DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div); 878 hsync_end = DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div); 879 hsync_size = hsync_end - hsync_start; 880 hback_porch = (adjusted_mode->crtc_htotal - 881 adjusted_mode->crtc_hsync_end); 882 vactive = adjusted_mode->crtc_vdisplay; 883 884 if (is_vid_mode(intel_dsi)) { 885 vtotal = adjusted_mode->crtc_vtotal; 886 } else { 887 int bpp, line_time_us, byte_clk_period_ns; 888 889 if (crtc_state->dsc.compression_enable) 890 bpp = to_bpp_int(crtc_state->dsc.compressed_bpp_x16); 891 else 892 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 893 894 byte_clk_period_ns = 1000000 / afe_clk(encoder, crtc_state); 895 line_time_us = (htotal * (bpp / 8) * byte_clk_period_ns) / (1000 * intel_dsi->lane_count); 896 vtotal = vactive + DIV_ROUND_UP(400, line_time_us); 897 } 898 vsync_start = adjusted_mode->crtc_vsync_start; 899 vsync_end = adjusted_mode->crtc_vsync_end; 900 vsync_shift = hsync_start - htotal / 2; 901 902 if (intel_dsi->dual_link) { 903 hactive /= 2; 904 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 905 hactive += intel_dsi->pixel_overlap; 906 htotal /= 2; 907 } 908 909 /* minimum hactive as per bspec: 256 pixels */ 910 if (adjusted_mode->crtc_hdisplay < 256) 911 drm_err(&dev_priv->drm, "hactive is less then 256 pixels\n"); 912 913 /* if RGB666 format, then hactive must be multiple of 4 pixels */ 914 if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB666 && hactive % 4 != 0) 915 drm_err(&dev_priv->drm, 916 "hactive pixels are not multiple of 4\n"); 917 918 /* program TRANS_HTOTAL register */ 919 for_each_dsi_port(port, intel_dsi->ports) { 920 dsi_trans = dsi_port_to_transcoder(port); 921 intel_de_write(dev_priv, TRANS_HTOTAL(dev_priv, dsi_trans), 922 HACTIVE(hactive - 1) | HTOTAL(htotal - 1)); 923 } 924 925 /* TRANS_HSYNC register to be programmed only for video mode */ 926 if (is_vid_mode(intel_dsi)) { 927 if (intel_dsi->video_mode == NON_BURST_SYNC_PULSE) { 928 /* BSPEC: hsync size should be atleast 16 pixels */ 929 if (hsync_size < 16) 930 drm_err(&dev_priv->drm, 931 "hsync size < 16 pixels\n"); 932 } 933 934 if (hback_porch < 16) 935 drm_err(&dev_priv->drm, "hback porch < 16 pixels\n"); 936 937 if (intel_dsi->dual_link) { 938 hsync_start /= 2; 939 hsync_end /= 2; 940 } 941 942 for_each_dsi_port(port, intel_dsi->ports) { 943 dsi_trans = dsi_port_to_transcoder(port); 944 intel_de_write(dev_priv, 945 TRANS_HSYNC(dev_priv, dsi_trans), 946 HSYNC_START(hsync_start - 1) | HSYNC_END(hsync_end - 1)); 947 } 948 } 949 950 /* program TRANS_VTOTAL register */ 951 for_each_dsi_port(port, intel_dsi->ports) { 952 dsi_trans = dsi_port_to_transcoder(port); 953 /* 954 * FIXME: Programing this by assuming progressive mode, since 955 * non-interlaced info from VBT is not saved inside 956 * struct drm_display_mode. 957 * For interlace mode: program required pixel minus 2 958 */ 959 intel_de_write(dev_priv, TRANS_VTOTAL(dev_priv, dsi_trans), 960 VACTIVE(vactive - 1) | VTOTAL(vtotal - 1)); 961 } 962 963 if (vsync_end < vsync_start || vsync_end > vtotal) 964 drm_err(&dev_priv->drm, "Invalid vsync_end value\n"); 965 966 if (vsync_start < vactive) 967 drm_err(&dev_priv->drm, "vsync_start less than vactive\n"); 968 969 /* program TRANS_VSYNC register for video mode only */ 970 if (is_vid_mode(intel_dsi)) { 971 for_each_dsi_port(port, intel_dsi->ports) { 972 dsi_trans = dsi_port_to_transcoder(port); 973 intel_de_write(dev_priv, 974 TRANS_VSYNC(dev_priv, dsi_trans), 975 VSYNC_START(vsync_start - 1) | VSYNC_END(vsync_end - 1)); 976 } 977 } 978 979 /* 980 * FIXME: It has to be programmed only for video modes and interlaced 981 * modes. Put the check condition here once interlaced 982 * info available as described above. 983 * program TRANS_VSYNCSHIFT register 984 */ 985 if (is_vid_mode(intel_dsi)) { 986 for_each_dsi_port(port, intel_dsi->ports) { 987 dsi_trans = dsi_port_to_transcoder(port); 988 intel_de_write(dev_priv, 989 TRANS_VSYNCSHIFT(dev_priv, dsi_trans), 990 vsync_shift); 991 } 992 } 993 994 /* 995 * program TRANS_VBLANK register, should be same as vtotal programmed 996 * 997 * FIXME get rid of these local hacks and do it right, 998 * this will not handle eg. delayed vblank correctly. 999 */ 1000 if (DISPLAY_VER(dev_priv) >= 12) { 1001 for_each_dsi_port(port, intel_dsi->ports) { 1002 dsi_trans = dsi_port_to_transcoder(port); 1003 intel_de_write(dev_priv, 1004 TRANS_VBLANK(dev_priv, dsi_trans), 1005 VBLANK_START(vactive - 1) | VBLANK_END(vtotal - 1)); 1006 } 1007 } 1008 } 1009 1010 static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder) 1011 { 1012 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1013 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1014 enum port port; 1015 enum transcoder dsi_trans; 1016 1017 for_each_dsi_port(port, intel_dsi->ports) { 1018 dsi_trans = dsi_port_to_transcoder(port); 1019 intel_de_rmw(dev_priv, TRANSCONF(dev_priv, dsi_trans), 0, 1020 TRANSCONF_ENABLE); 1021 1022 /* wait for transcoder to be enabled */ 1023 if (intel_de_wait_for_set(dev_priv, TRANSCONF(dev_priv, dsi_trans), 1024 TRANSCONF_STATE_ENABLE, 10)) 1025 drm_err(&dev_priv->drm, 1026 "DSI transcoder not enabled\n"); 1027 } 1028 } 1029 1030 static void gen11_dsi_setup_timeouts(struct intel_encoder *encoder, 1031 const struct intel_crtc_state *crtc_state) 1032 { 1033 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1034 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1035 enum port port; 1036 enum transcoder dsi_trans; 1037 u32 hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul; 1038 1039 /* 1040 * escape clock count calculation: 1041 * BYTE_CLK_COUNT = TIME_NS/(8 * UI) 1042 * UI (nsec) = (10^6)/Bitrate 1043 * TIME_NS = (BYTE_CLK_COUNT * 8 * 10^6)/ Bitrate 1044 * ESCAPE_CLK_COUNT = TIME_NS/ESC_CLK_NS 1045 */ 1046 divisor = intel_dsi_tlpx_ns(intel_dsi) * afe_clk(encoder, crtc_state) * 1000; 1047 mul = 8 * 1000000; 1048 hs_tx_timeout = DIV_ROUND_UP(intel_dsi->hs_tx_timeout * mul, 1049 divisor); 1050 lp_rx_timeout = DIV_ROUND_UP(intel_dsi->lp_rx_timeout * mul, divisor); 1051 ta_timeout = DIV_ROUND_UP(intel_dsi->turn_arnd_val * mul, divisor); 1052 1053 for_each_dsi_port(port, intel_dsi->ports) { 1054 dsi_trans = dsi_port_to_transcoder(port); 1055 1056 /* program hst_tx_timeout */ 1057 intel_de_rmw(dev_priv, DSI_HSTX_TO(dsi_trans), 1058 HSTX_TIMEOUT_VALUE_MASK, 1059 HSTX_TIMEOUT_VALUE(hs_tx_timeout)); 1060 1061 /* FIXME: DSI_CALIB_TO */ 1062 1063 /* program lp_rx_host timeout */ 1064 intel_de_rmw(dev_priv, DSI_LPRX_HOST_TO(dsi_trans), 1065 LPRX_TIMEOUT_VALUE_MASK, 1066 LPRX_TIMEOUT_VALUE(lp_rx_timeout)); 1067 1068 /* FIXME: DSI_PWAIT_TO */ 1069 1070 /* program turn around timeout */ 1071 intel_de_rmw(dev_priv, DSI_TA_TO(dsi_trans), 1072 TA_TIMEOUT_VALUE_MASK, 1073 TA_TIMEOUT_VALUE(ta_timeout)); 1074 } 1075 } 1076 1077 static void gen11_dsi_config_util_pin(struct intel_encoder *encoder, 1078 bool enable) 1079 { 1080 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1081 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1082 u32 tmp; 1083 1084 /* 1085 * used as TE i/p for DSI0, 1086 * for dual link/DSI1 TE is from slave DSI1 1087 * through GPIO. 1088 */ 1089 if (is_vid_mode(intel_dsi) || (intel_dsi->ports & BIT(PORT_B))) 1090 return; 1091 1092 tmp = intel_de_read(dev_priv, UTIL_PIN_CTL); 1093 1094 if (enable) { 1095 tmp |= UTIL_PIN_DIRECTION_INPUT; 1096 tmp |= UTIL_PIN_ENABLE; 1097 } else { 1098 tmp &= ~UTIL_PIN_ENABLE; 1099 } 1100 intel_de_write(dev_priv, UTIL_PIN_CTL, tmp); 1101 } 1102 1103 static void 1104 gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder, 1105 const struct intel_crtc_state *crtc_state) 1106 { 1107 /* step 4a: power up all lanes of the DDI used by DSI */ 1108 gen11_dsi_power_up_lanes(encoder); 1109 1110 /* step 4b: configure lane sequencing of the Combo-PHY transmitters */ 1111 gen11_dsi_config_phy_lanes_sequence(encoder); 1112 1113 /* step 4c: configure voltage swing and skew */ 1114 gen11_dsi_voltage_swing_program_seq(encoder); 1115 1116 /* setup D-PHY timings */ 1117 gen11_dsi_setup_dphy_timings(encoder, crtc_state); 1118 1119 /* enable DDI buffer */ 1120 gen11_dsi_enable_ddi_buffer(encoder); 1121 1122 gen11_dsi_gate_clocks(encoder); 1123 1124 gen11_dsi_setup_timings(encoder, crtc_state); 1125 1126 /* Since transcoder is configured to take events from GPIO */ 1127 gen11_dsi_config_util_pin(encoder, true); 1128 1129 /* step 4h: setup DSI protocol timeouts */ 1130 gen11_dsi_setup_timeouts(encoder, crtc_state); 1131 1132 /* Step (4h, 4i, 4j, 4k): Configure transcoder */ 1133 gen11_dsi_configure_transcoder(encoder, crtc_state); 1134 } 1135 1136 static void gen11_dsi_powerup_panel(struct intel_encoder *encoder) 1137 { 1138 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1139 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1140 struct mipi_dsi_device *dsi; 1141 enum port port; 1142 enum transcoder dsi_trans; 1143 u32 tmp; 1144 int ret; 1145 1146 /* set maximum return packet size */ 1147 for_each_dsi_port(port, intel_dsi->ports) { 1148 dsi_trans = dsi_port_to_transcoder(port); 1149 1150 /* 1151 * FIXME: This uses the number of DW's currently in the payload 1152 * receive queue. This is probably not what we want here. 1153 */ 1154 tmp = intel_de_read(dev_priv, DSI_CMD_RXCTL(dsi_trans)); 1155 tmp &= NUMBER_RX_PLOAD_DW_MASK; 1156 /* multiply "Number Rx Payload DW" by 4 to get max value */ 1157 tmp = tmp * 4; 1158 dsi = intel_dsi->dsi_hosts[port]->device; 1159 ret = mipi_dsi_set_maximum_return_packet_size(dsi, tmp); 1160 if (ret < 0) 1161 drm_err(&dev_priv->drm, 1162 "error setting max return pkt size%d\n", tmp); 1163 } 1164 1165 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP); 1166 1167 /* ensure all panel commands dispatched before enabling transcoder */ 1168 wait_for_cmds_dispatched_to_panel(encoder); 1169 } 1170 1171 static void gen11_dsi_pre_pll_enable(struct intel_atomic_state *state, 1172 struct intel_encoder *encoder, 1173 const struct intel_crtc_state *crtc_state, 1174 const struct drm_connector_state *conn_state) 1175 { 1176 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1177 1178 intel_dsi_wait_panel_power_cycle(intel_dsi); 1179 1180 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON); 1181 msleep(intel_dsi->panel_on_delay); 1182 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET); 1183 1184 /* step2: enable IO power */ 1185 gen11_dsi_enable_io_power(encoder); 1186 1187 /* step3: enable DSI PLL */ 1188 gen11_dsi_program_esc_clk_div(encoder, crtc_state); 1189 } 1190 1191 static void gen11_dsi_pre_enable(struct intel_atomic_state *state, 1192 struct intel_encoder *encoder, 1193 const struct intel_crtc_state *pipe_config, 1194 const struct drm_connector_state *conn_state) 1195 { 1196 /* step3b */ 1197 gen11_dsi_map_pll(encoder, pipe_config); 1198 1199 /* step4: enable DSI port and DPHY */ 1200 gen11_dsi_enable_port_and_phy(encoder, pipe_config); 1201 1202 /* step5: program and powerup panel */ 1203 gen11_dsi_powerup_panel(encoder); 1204 1205 intel_dsc_dsi_pps_write(encoder, pipe_config); 1206 1207 /* step6c: configure transcoder timings */ 1208 gen11_dsi_set_transcoder_timings(encoder, pipe_config); 1209 } 1210 1211 /* 1212 * Wa_1409054076:icl,jsl,ehl 1213 * When pipe A is disabled and MIPI DSI is enabled on pipe B, 1214 * the AMT KVMR feature will incorrectly see pipe A as enabled. 1215 * Set 0x42080 bit 23=1 before enabling DSI on pipe B and leave 1216 * it set while DSI is enabled on pipe B 1217 */ 1218 static void icl_apply_kvmr_pipe_a_wa(struct intel_encoder *encoder, 1219 enum pipe pipe, bool enable) 1220 { 1221 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1222 1223 if (DISPLAY_VER(dev_priv) == 11 && pipe == PIPE_B) 1224 intel_de_rmw(dev_priv, CHICKEN_PAR1_1, 1225 IGNORE_KVMR_PIPE_A, 1226 enable ? IGNORE_KVMR_PIPE_A : 0); 1227 } 1228 1229 /* 1230 * Wa_16012360555:adl-p 1231 * SW will have to program the "LP to HS Wakeup Guardband" 1232 * to account for the repeaters on the HS Request/Ready 1233 * PPI signaling between the Display engine and the DPHY. 1234 */ 1235 static void adlp_set_lp_hs_wakeup_gb(struct intel_encoder *encoder) 1236 { 1237 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 1238 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1239 enum port port; 1240 1241 if (DISPLAY_VER(i915) == 13) { 1242 for_each_dsi_port(port, intel_dsi->ports) 1243 intel_de_rmw(i915, TGL_DSI_CHKN_REG(port), 1244 TGL_DSI_CHKN_LSHS_GB_MASK, 1245 TGL_DSI_CHKN_LSHS_GB(4)); 1246 } 1247 } 1248 1249 static void gen11_dsi_enable(struct intel_atomic_state *state, 1250 struct intel_encoder *encoder, 1251 const struct intel_crtc_state *crtc_state, 1252 const struct drm_connector_state *conn_state) 1253 { 1254 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1255 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1256 1257 /* Wa_1409054076:icl,jsl,ehl */ 1258 icl_apply_kvmr_pipe_a_wa(encoder, crtc->pipe, true); 1259 1260 /* Wa_16012360555:adl-p */ 1261 adlp_set_lp_hs_wakeup_gb(encoder); 1262 1263 /* step6d: enable dsi transcoder */ 1264 gen11_dsi_enable_transcoder(encoder); 1265 1266 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); 1267 1268 /* step7: enable backlight */ 1269 intel_backlight_enable(crtc_state, conn_state); 1270 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON); 1271 1272 intel_crtc_vblank_on(crtc_state); 1273 } 1274 1275 static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder) 1276 { 1277 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1278 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1279 enum port port; 1280 enum transcoder dsi_trans; 1281 1282 for_each_dsi_port(port, intel_dsi->ports) { 1283 dsi_trans = dsi_port_to_transcoder(port); 1284 1285 /* disable transcoder */ 1286 intel_de_rmw(dev_priv, TRANSCONF(dev_priv, dsi_trans), 1287 TRANSCONF_ENABLE, 0); 1288 1289 /* wait for transcoder to be disabled */ 1290 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(dev_priv, dsi_trans), 1291 TRANSCONF_STATE_ENABLE, 50)) 1292 drm_err(&dev_priv->drm, 1293 "DSI trancoder not disabled\n"); 1294 } 1295 } 1296 1297 static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder) 1298 { 1299 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1300 1301 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF); 1302 1303 /* ensure cmds dispatched to panel */ 1304 wait_for_cmds_dispatched_to_panel(encoder); 1305 } 1306 1307 static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder) 1308 { 1309 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1310 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1311 enum port port; 1312 enum transcoder dsi_trans; 1313 u32 tmp; 1314 1315 /* disable periodic update mode */ 1316 if (is_cmd_mode(intel_dsi)) { 1317 for_each_dsi_port(port, intel_dsi->ports) 1318 intel_de_rmw(dev_priv, DSI_CMD_FRMCTL(port), 1319 DSI_PERIODIC_FRAME_UPDATE_ENABLE, 0); 1320 } 1321 1322 /* put dsi link in ULPS */ 1323 for_each_dsi_port(port, intel_dsi->ports) { 1324 dsi_trans = dsi_port_to_transcoder(port); 1325 tmp = intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)); 1326 tmp |= LINK_ENTER_ULPS; 1327 tmp &= ~LINK_ULPS_TYPE_LP11; 1328 intel_de_write(dev_priv, DSI_LP_MSG(dsi_trans), tmp); 1329 1330 if (wait_for_us((intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)) & 1331 LINK_IN_ULPS), 1332 10)) 1333 drm_err(&dev_priv->drm, "DSI link not in ULPS\n"); 1334 } 1335 1336 /* disable ddi function */ 1337 for_each_dsi_port(port, intel_dsi->ports) { 1338 dsi_trans = dsi_port_to_transcoder(port); 1339 intel_de_rmw(dev_priv, 1340 TRANS_DDI_FUNC_CTL(dev_priv, dsi_trans), 1341 TRANS_DDI_FUNC_ENABLE, 0); 1342 } 1343 1344 /* disable port sync mode if dual link */ 1345 if (intel_dsi->dual_link) { 1346 for_each_dsi_port(port, intel_dsi->ports) { 1347 dsi_trans = dsi_port_to_transcoder(port); 1348 intel_de_rmw(dev_priv, 1349 TRANS_DDI_FUNC_CTL2(dev_priv, dsi_trans), 1350 PORT_SYNC_MODE_ENABLE, 0); 1351 } 1352 } 1353 } 1354 1355 static void gen11_dsi_disable_port(struct intel_encoder *encoder) 1356 { 1357 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1358 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1359 enum port port; 1360 1361 gen11_dsi_ungate_clocks(encoder); 1362 for_each_dsi_port(port, intel_dsi->ports) { 1363 intel_de_rmw(dev_priv, DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE, 0); 1364 1365 if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 1366 DDI_BUF_IS_IDLE), 1367 8)) 1368 drm_err(&dev_priv->drm, 1369 "DDI port:%c buffer not idle\n", 1370 port_name(port)); 1371 } 1372 gen11_dsi_gate_clocks(encoder); 1373 } 1374 1375 static void gen11_dsi_disable_io_power(struct intel_encoder *encoder) 1376 { 1377 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1378 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1379 enum port port; 1380 1381 for_each_dsi_port(port, intel_dsi->ports) { 1382 intel_wakeref_t wakeref; 1383 1384 wakeref = fetch_and_zero(&intel_dsi->io_wakeref[port]); 1385 intel_display_power_put(dev_priv, 1386 port == PORT_A ? 1387 POWER_DOMAIN_PORT_DDI_IO_A : 1388 POWER_DOMAIN_PORT_DDI_IO_B, 1389 wakeref); 1390 } 1391 1392 /* set mode to DDI */ 1393 for_each_dsi_port(port, intel_dsi->ports) 1394 intel_de_rmw(dev_priv, ICL_DSI_IO_MODECTL(port), 1395 COMBO_PHY_MODE_DSI, 0); 1396 } 1397 1398 static void gen11_dsi_disable(struct intel_atomic_state *state, 1399 struct intel_encoder *encoder, 1400 const struct intel_crtc_state *old_crtc_state, 1401 const struct drm_connector_state *old_conn_state) 1402 { 1403 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1404 1405 /* step1: turn off backlight */ 1406 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF); 1407 intel_backlight_disable(old_conn_state); 1408 } 1409 1410 static void gen11_dsi_post_disable(struct intel_atomic_state *state, 1411 struct intel_encoder *encoder, 1412 const struct intel_crtc_state *old_crtc_state, 1413 const struct drm_connector_state *old_conn_state) 1414 { 1415 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1416 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 1417 1418 intel_crtc_vblank_off(old_crtc_state); 1419 1420 /* step2d,e: disable transcoder and wait */ 1421 gen11_dsi_disable_transcoder(encoder); 1422 1423 /* Wa_1409054076:icl,jsl,ehl */ 1424 icl_apply_kvmr_pipe_a_wa(encoder, crtc->pipe, false); 1425 1426 /* step2f,g: powerdown panel */ 1427 gen11_dsi_powerdown_panel(encoder); 1428 1429 /* step2h,i,j: deconfig trancoder */ 1430 gen11_dsi_deconfigure_trancoder(encoder); 1431 1432 intel_dsc_disable(old_crtc_state); 1433 skl_scaler_disable(old_crtc_state); 1434 1435 /* step3: disable port */ 1436 gen11_dsi_disable_port(encoder); 1437 1438 gen11_dsi_config_util_pin(encoder, false); 1439 1440 /* step4: disable IO power */ 1441 gen11_dsi_disable_io_power(encoder); 1442 1443 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); 1444 1445 msleep(intel_dsi->panel_off_delay); 1446 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF); 1447 1448 intel_dsi->panel_power_off_time = ktime_get_boottime(); 1449 } 1450 1451 static enum drm_mode_status gen11_dsi_mode_valid(struct drm_connector *connector, 1452 struct drm_display_mode *mode) 1453 { 1454 struct drm_i915_private *i915 = to_i915(connector->dev); 1455 enum drm_mode_status status; 1456 1457 status = intel_cpu_transcoder_mode_valid(i915, mode); 1458 if (status != MODE_OK) 1459 return status; 1460 1461 /* FIXME: DSC? */ 1462 return intel_dsi_mode_valid(connector, mode); 1463 } 1464 1465 static void gen11_dsi_get_timings(struct intel_encoder *encoder, 1466 struct intel_crtc_state *pipe_config) 1467 { 1468 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1469 struct drm_display_mode *adjusted_mode = 1470 &pipe_config->hw.adjusted_mode; 1471 1472 if (pipe_config->dsc.compressed_bpp_x16) { 1473 int div = to_bpp_int(pipe_config->dsc.compressed_bpp_x16); 1474 int mul = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 1475 1476 adjusted_mode->crtc_htotal = 1477 DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div); 1478 adjusted_mode->crtc_hsync_start = 1479 DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div); 1480 adjusted_mode->crtc_hsync_end = 1481 DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div); 1482 } 1483 1484 if (intel_dsi->dual_link) { 1485 adjusted_mode->crtc_hdisplay *= 2; 1486 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 1487 adjusted_mode->crtc_hdisplay -= 1488 intel_dsi->pixel_overlap; 1489 adjusted_mode->crtc_htotal *= 2; 1490 } 1491 adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay; 1492 adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal; 1493 1494 if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) { 1495 if (intel_dsi->dual_link) { 1496 adjusted_mode->crtc_hsync_start *= 2; 1497 adjusted_mode->crtc_hsync_end *= 2; 1498 } 1499 } 1500 adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay; 1501 adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal; 1502 } 1503 1504 static bool gen11_dsi_is_periodic_cmd_mode(struct intel_dsi *intel_dsi) 1505 { 1506 struct drm_device *dev = intel_dsi->base.base.dev; 1507 struct drm_i915_private *dev_priv = to_i915(dev); 1508 enum transcoder dsi_trans; 1509 u32 val; 1510 1511 if (intel_dsi->ports == BIT(PORT_B)) 1512 dsi_trans = TRANSCODER_DSI_1; 1513 else 1514 dsi_trans = TRANSCODER_DSI_0; 1515 1516 val = intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)); 1517 return (val & DSI_PERIODIC_FRAME_UPDATE_ENABLE); 1518 } 1519 1520 static void gen11_dsi_get_cmd_mode_config(struct intel_dsi *intel_dsi, 1521 struct intel_crtc_state *pipe_config) 1522 { 1523 if (intel_dsi->ports == (BIT(PORT_B) | BIT(PORT_A))) 1524 pipe_config->mode_flags |= I915_MODE_FLAG_DSI_USE_TE1 | 1525 I915_MODE_FLAG_DSI_USE_TE0; 1526 else if (intel_dsi->ports == BIT(PORT_B)) 1527 pipe_config->mode_flags |= I915_MODE_FLAG_DSI_USE_TE1; 1528 else 1529 pipe_config->mode_flags |= I915_MODE_FLAG_DSI_USE_TE0; 1530 } 1531 1532 static void gen11_dsi_get_config(struct intel_encoder *encoder, 1533 struct intel_crtc_state *pipe_config) 1534 { 1535 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1536 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1537 1538 intel_ddi_get_clock(encoder, pipe_config, icl_ddi_combo_get_pll(encoder)); 1539 1540 pipe_config->hw.adjusted_mode.crtc_clock = intel_dsi->pclk; 1541 if (intel_dsi->dual_link) 1542 pipe_config->hw.adjusted_mode.crtc_clock *= 2; 1543 1544 gen11_dsi_get_timings(encoder, pipe_config); 1545 pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI); 1546 pipe_config->pipe_bpp = bdw_get_pipe_misc_bpp(crtc); 1547 1548 /* Get the details on which TE should be enabled */ 1549 if (is_cmd_mode(intel_dsi)) 1550 gen11_dsi_get_cmd_mode_config(intel_dsi, pipe_config); 1551 1552 if (gen11_dsi_is_periodic_cmd_mode(intel_dsi)) 1553 pipe_config->mode_flags |= I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE; 1554 } 1555 1556 static void gen11_dsi_sync_state(struct intel_encoder *encoder, 1557 const struct intel_crtc_state *crtc_state) 1558 { 1559 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1560 struct intel_crtc *intel_crtc; 1561 enum pipe pipe; 1562 1563 if (!crtc_state) 1564 return; 1565 1566 intel_crtc = to_intel_crtc(crtc_state->uapi.crtc); 1567 pipe = intel_crtc->pipe; 1568 1569 /* wa verify 1409054076:icl,jsl,ehl */ 1570 if (DISPLAY_VER(dev_priv) == 11 && pipe == PIPE_B && 1571 !(intel_de_read(dev_priv, CHICKEN_PAR1_1) & IGNORE_KVMR_PIPE_A)) 1572 drm_dbg_kms(&dev_priv->drm, 1573 "[ENCODER:%d:%s] BIOS left IGNORE_KVMR_PIPE_A cleared with pipe B enabled\n", 1574 encoder->base.base.id, 1575 encoder->base.name); 1576 } 1577 1578 static int gen11_dsi_dsc_compute_config(struct intel_encoder *encoder, 1579 struct intel_crtc_state *crtc_state) 1580 { 1581 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1582 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 1583 int dsc_max_bpc = DISPLAY_VER(dev_priv) >= 12 ? 12 : 10; 1584 bool use_dsc; 1585 int ret; 1586 1587 use_dsc = intel_bios_get_dsc_params(encoder, crtc_state, dsc_max_bpc); 1588 if (!use_dsc) 1589 return 0; 1590 1591 if (crtc_state->pipe_bpp < 8 * 3) 1592 return -EINVAL; 1593 1594 /* FIXME: split only when necessary */ 1595 if (crtc_state->dsc.slice_count > 1) 1596 crtc_state->dsc.dsc_split = true; 1597 1598 /* FIXME: initialize from VBT */ 1599 vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST; 1600 1601 vdsc_cfg->pic_height = crtc_state->hw.adjusted_mode.crtc_vdisplay; 1602 1603 ret = intel_dsc_compute_params(crtc_state); 1604 if (ret) 1605 return ret; 1606 1607 /* DSI specific sanity checks on the common code */ 1608 drm_WARN_ON(&dev_priv->drm, vdsc_cfg->vbr_enable); 1609 drm_WARN_ON(&dev_priv->drm, vdsc_cfg->simple_422); 1610 drm_WARN_ON(&dev_priv->drm, 1611 vdsc_cfg->pic_width % vdsc_cfg->slice_width); 1612 drm_WARN_ON(&dev_priv->drm, vdsc_cfg->slice_height < 8); 1613 drm_WARN_ON(&dev_priv->drm, 1614 vdsc_cfg->pic_height % vdsc_cfg->slice_height); 1615 1616 ret = drm_dsc_compute_rc_parameters(vdsc_cfg); 1617 if (ret) 1618 return ret; 1619 1620 crtc_state->dsc.compression_enable = true; 1621 1622 return 0; 1623 } 1624 1625 static int gen11_dsi_compute_config(struct intel_encoder *encoder, 1626 struct intel_crtc_state *pipe_config, 1627 struct drm_connector_state *conn_state) 1628 { 1629 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 1630 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1631 struct intel_connector *intel_connector = intel_dsi->attached_connector; 1632 struct drm_display_mode *adjusted_mode = 1633 &pipe_config->hw.adjusted_mode; 1634 int ret; 1635 1636 pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB; 1637 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 1638 1639 ret = intel_panel_compute_config(intel_connector, adjusted_mode); 1640 if (ret) 1641 return ret; 1642 1643 ret = intel_panel_fitting(pipe_config, conn_state); 1644 if (ret) 1645 return ret; 1646 1647 adjusted_mode->flags = 0; 1648 1649 /* Dual link goes to trancoder DSI'0' */ 1650 if (intel_dsi->ports == BIT(PORT_B)) 1651 pipe_config->cpu_transcoder = TRANSCODER_DSI_1; 1652 else 1653 pipe_config->cpu_transcoder = TRANSCODER_DSI_0; 1654 1655 if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888) 1656 pipe_config->pipe_bpp = 24; 1657 else 1658 pipe_config->pipe_bpp = 18; 1659 1660 pipe_config->clock_set = true; 1661 1662 if (gen11_dsi_dsc_compute_config(encoder, pipe_config)) 1663 drm_dbg_kms(&i915->drm, "Attempting to use DSC failed\n"); 1664 1665 pipe_config->port_clock = afe_clk(encoder, pipe_config) / 5; 1666 1667 /* 1668 * In case of TE GATE cmd mode, we 1669 * receive TE from the slave if 1670 * dual link is enabled 1671 */ 1672 if (is_cmd_mode(intel_dsi)) 1673 gen11_dsi_get_cmd_mode_config(intel_dsi, pipe_config); 1674 1675 return 0; 1676 } 1677 1678 static void gen11_dsi_get_power_domains(struct intel_encoder *encoder, 1679 struct intel_crtc_state *crtc_state) 1680 { 1681 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 1682 1683 get_dsi_io_power_domains(i915, 1684 enc_to_intel_dsi(encoder)); 1685 } 1686 1687 static bool gen11_dsi_get_hw_state(struct intel_encoder *encoder, 1688 enum pipe *pipe) 1689 { 1690 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1691 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1692 enum transcoder dsi_trans; 1693 intel_wakeref_t wakeref; 1694 enum port port; 1695 bool ret = false; 1696 u32 tmp; 1697 1698 wakeref = intel_display_power_get_if_enabled(dev_priv, 1699 encoder->power_domain); 1700 if (!wakeref) 1701 return false; 1702 1703 for_each_dsi_port(port, intel_dsi->ports) { 1704 dsi_trans = dsi_port_to_transcoder(port); 1705 tmp = intel_de_read(dev_priv, 1706 TRANS_DDI_FUNC_CTL(dev_priv, dsi_trans)); 1707 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 1708 case TRANS_DDI_EDP_INPUT_A_ON: 1709 *pipe = PIPE_A; 1710 break; 1711 case TRANS_DDI_EDP_INPUT_B_ONOFF: 1712 *pipe = PIPE_B; 1713 break; 1714 case TRANS_DDI_EDP_INPUT_C_ONOFF: 1715 *pipe = PIPE_C; 1716 break; 1717 case TRANS_DDI_EDP_INPUT_D_ONOFF: 1718 *pipe = PIPE_D; 1719 break; 1720 default: 1721 drm_err(&dev_priv->drm, "Invalid PIPE input\n"); 1722 goto out; 1723 } 1724 1725 tmp = intel_de_read(dev_priv, TRANSCONF(dev_priv, dsi_trans)); 1726 ret = tmp & TRANSCONF_ENABLE; 1727 } 1728 out: 1729 intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1730 return ret; 1731 } 1732 1733 static bool gen11_dsi_initial_fastset_check(struct intel_encoder *encoder, 1734 struct intel_crtc_state *crtc_state) 1735 { 1736 if (crtc_state->dsc.compression_enable) { 1737 drm_dbg_kms(encoder->base.dev, "Forcing full modeset due to DSC being enabled\n"); 1738 crtc_state->uapi.mode_changed = true; 1739 1740 return false; 1741 } 1742 1743 return true; 1744 } 1745 1746 static void gen11_dsi_encoder_destroy(struct drm_encoder *encoder) 1747 { 1748 intel_encoder_destroy(encoder); 1749 } 1750 1751 static const struct drm_encoder_funcs gen11_dsi_encoder_funcs = { 1752 .destroy = gen11_dsi_encoder_destroy, 1753 }; 1754 1755 static const struct drm_connector_funcs gen11_dsi_connector_funcs = { 1756 .detect = intel_panel_detect, 1757 .late_register = intel_connector_register, 1758 .early_unregister = intel_connector_unregister, 1759 .destroy = intel_connector_destroy, 1760 .fill_modes = drm_helper_probe_single_connector_modes, 1761 .atomic_get_property = intel_digital_connector_atomic_get_property, 1762 .atomic_set_property = intel_digital_connector_atomic_set_property, 1763 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1764 .atomic_duplicate_state = intel_digital_connector_duplicate_state, 1765 }; 1766 1767 static const struct drm_connector_helper_funcs gen11_dsi_connector_helper_funcs = { 1768 .get_modes = intel_dsi_get_modes, 1769 .mode_valid = gen11_dsi_mode_valid, 1770 .atomic_check = intel_digital_connector_atomic_check, 1771 }; 1772 1773 static int gen11_dsi_host_attach(struct mipi_dsi_host *host, 1774 struct mipi_dsi_device *dsi) 1775 { 1776 return 0; 1777 } 1778 1779 static int gen11_dsi_host_detach(struct mipi_dsi_host *host, 1780 struct mipi_dsi_device *dsi) 1781 { 1782 return 0; 1783 } 1784 1785 static ssize_t gen11_dsi_host_transfer(struct mipi_dsi_host *host, 1786 const struct mipi_dsi_msg *msg) 1787 { 1788 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); 1789 struct mipi_dsi_packet dsi_pkt; 1790 ssize_t ret; 1791 bool enable_lpdt = false; 1792 1793 ret = mipi_dsi_create_packet(&dsi_pkt, msg); 1794 if (ret < 0) 1795 return ret; 1796 1797 if (msg->flags & MIPI_DSI_MSG_USE_LPM) 1798 enable_lpdt = true; 1799 1800 /* only long packet contains payload */ 1801 if (mipi_dsi_packet_format_is_long(msg->type)) { 1802 ret = dsi_send_pkt_payld(intel_dsi_host, &dsi_pkt); 1803 if (ret < 0) 1804 return ret; 1805 } 1806 1807 /* send packet header */ 1808 ret = dsi_send_pkt_hdr(intel_dsi_host, &dsi_pkt, enable_lpdt); 1809 if (ret < 0) 1810 return ret; 1811 1812 //TODO: add payload receive code if needed 1813 1814 ret = sizeof(dsi_pkt.header) + dsi_pkt.payload_length; 1815 1816 return ret; 1817 } 1818 1819 static const struct mipi_dsi_host_ops gen11_dsi_host_ops = { 1820 .attach = gen11_dsi_host_attach, 1821 .detach = gen11_dsi_host_detach, 1822 .transfer = gen11_dsi_host_transfer, 1823 }; 1824 1825 #define ICL_PREPARE_CNT_MAX 0x7 1826 #define ICL_CLK_ZERO_CNT_MAX 0xf 1827 #define ICL_TRAIL_CNT_MAX 0x7 1828 #define ICL_TCLK_PRE_CNT_MAX 0x3 1829 #define ICL_TCLK_POST_CNT_MAX 0x7 1830 #define ICL_HS_ZERO_CNT_MAX 0xf 1831 #define ICL_EXIT_ZERO_CNT_MAX 0x7 1832 1833 static void icl_dphy_param_init(struct intel_dsi *intel_dsi) 1834 { 1835 struct drm_device *dev = intel_dsi->base.base.dev; 1836 struct drm_i915_private *dev_priv = to_i915(dev); 1837 struct intel_connector *connector = intel_dsi->attached_connector; 1838 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config; 1839 u32 tlpx_ns; 1840 u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; 1841 u32 ths_prepare_ns, tclk_trail_ns; 1842 u32 hs_zero_cnt; 1843 u32 tclk_pre_cnt; 1844 1845 tlpx_ns = intel_dsi_tlpx_ns(intel_dsi); 1846 1847 tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail); 1848 ths_prepare_ns = max(mipi_config->ths_prepare, 1849 mipi_config->tclk_prepare); 1850 1851 /* 1852 * prepare cnt in escape clocks 1853 * this field represents a hexadecimal value with a precision 1854 * of 1.2 – i.e. the most significant bit is the integer 1855 * and the least significant 2 bits are fraction bits. 1856 * so, the field can represent a range of 0.25 to 1.75 1857 */ 1858 prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * 4, tlpx_ns); 1859 if (prepare_cnt > ICL_PREPARE_CNT_MAX) { 1860 drm_dbg_kms(&dev_priv->drm, "prepare_cnt out of range (%d)\n", 1861 prepare_cnt); 1862 prepare_cnt = ICL_PREPARE_CNT_MAX; 1863 } 1864 1865 /* clk zero count in escape clocks */ 1866 clk_zero_cnt = DIV_ROUND_UP(mipi_config->tclk_prepare_clkzero - 1867 ths_prepare_ns, tlpx_ns); 1868 if (clk_zero_cnt > ICL_CLK_ZERO_CNT_MAX) { 1869 drm_dbg_kms(&dev_priv->drm, 1870 "clk_zero_cnt out of range (%d)\n", clk_zero_cnt); 1871 clk_zero_cnt = ICL_CLK_ZERO_CNT_MAX; 1872 } 1873 1874 /* trail cnt in escape clocks*/ 1875 trail_cnt = DIV_ROUND_UP(tclk_trail_ns, tlpx_ns); 1876 if (trail_cnt > ICL_TRAIL_CNT_MAX) { 1877 drm_dbg_kms(&dev_priv->drm, "trail_cnt out of range (%d)\n", 1878 trail_cnt); 1879 trail_cnt = ICL_TRAIL_CNT_MAX; 1880 } 1881 1882 /* tclk pre count in escape clocks */ 1883 tclk_pre_cnt = DIV_ROUND_UP(mipi_config->tclk_pre, tlpx_ns); 1884 if (tclk_pre_cnt > ICL_TCLK_PRE_CNT_MAX) { 1885 drm_dbg_kms(&dev_priv->drm, 1886 "tclk_pre_cnt out of range (%d)\n", tclk_pre_cnt); 1887 tclk_pre_cnt = ICL_TCLK_PRE_CNT_MAX; 1888 } 1889 1890 /* hs zero cnt in escape clocks */ 1891 hs_zero_cnt = DIV_ROUND_UP(mipi_config->ths_prepare_hszero - 1892 ths_prepare_ns, tlpx_ns); 1893 if (hs_zero_cnt > ICL_HS_ZERO_CNT_MAX) { 1894 drm_dbg_kms(&dev_priv->drm, "hs_zero_cnt out of range (%d)\n", 1895 hs_zero_cnt); 1896 hs_zero_cnt = ICL_HS_ZERO_CNT_MAX; 1897 } 1898 1899 /* hs exit zero cnt in escape clocks */ 1900 exit_zero_cnt = DIV_ROUND_UP(mipi_config->ths_exit, tlpx_ns); 1901 if (exit_zero_cnt > ICL_EXIT_ZERO_CNT_MAX) { 1902 drm_dbg_kms(&dev_priv->drm, 1903 "exit_zero_cnt out of range (%d)\n", 1904 exit_zero_cnt); 1905 exit_zero_cnt = ICL_EXIT_ZERO_CNT_MAX; 1906 } 1907 1908 /* clock lane dphy timings */ 1909 intel_dsi->dphy_reg = (CLK_PREPARE_OVERRIDE | 1910 CLK_PREPARE(prepare_cnt) | 1911 CLK_ZERO_OVERRIDE | 1912 CLK_ZERO(clk_zero_cnt) | 1913 CLK_PRE_OVERRIDE | 1914 CLK_PRE(tclk_pre_cnt) | 1915 CLK_TRAIL_OVERRIDE | 1916 CLK_TRAIL(trail_cnt)); 1917 1918 /* data lanes dphy timings */ 1919 intel_dsi->dphy_data_lane_reg = (HS_PREPARE_OVERRIDE | 1920 HS_PREPARE(prepare_cnt) | 1921 HS_ZERO_OVERRIDE | 1922 HS_ZERO(hs_zero_cnt) | 1923 HS_TRAIL_OVERRIDE | 1924 HS_TRAIL(trail_cnt) | 1925 HS_EXIT_OVERRIDE | 1926 HS_EXIT(exit_zero_cnt)); 1927 1928 intel_dsi_log_params(intel_dsi); 1929 } 1930 1931 static void icl_dsi_add_properties(struct intel_connector *connector) 1932 { 1933 const struct drm_display_mode *fixed_mode = 1934 intel_panel_preferred_fixed_mode(connector); 1935 1936 intel_attach_scaling_mode_property(&connector->base); 1937 1938 drm_connector_set_panel_orientation_with_quirk(&connector->base, 1939 intel_dsi_get_panel_orientation(connector), 1940 fixed_mode->hdisplay, 1941 fixed_mode->vdisplay); 1942 } 1943 1944 void icl_dsi_init(struct drm_i915_private *dev_priv, 1945 const struct intel_bios_encoder_data *devdata) 1946 { 1947 struct intel_dsi *intel_dsi; 1948 struct intel_encoder *encoder; 1949 struct intel_connector *intel_connector; 1950 struct drm_connector *connector; 1951 enum port port; 1952 1953 port = intel_bios_encoder_port(devdata); 1954 if (port == PORT_NONE) 1955 return; 1956 1957 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); 1958 if (!intel_dsi) 1959 return; 1960 1961 intel_connector = intel_connector_alloc(); 1962 if (!intel_connector) { 1963 kfree(intel_dsi); 1964 return; 1965 } 1966 1967 encoder = &intel_dsi->base; 1968 intel_dsi->attached_connector = intel_connector; 1969 connector = &intel_connector->base; 1970 1971 encoder->devdata = devdata; 1972 1973 /* register DSI encoder with DRM subsystem */ 1974 drm_encoder_init(&dev_priv->drm, &encoder->base, &gen11_dsi_encoder_funcs, 1975 DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port)); 1976 1977 encoder->pre_pll_enable = gen11_dsi_pre_pll_enable; 1978 encoder->pre_enable = gen11_dsi_pre_enable; 1979 encoder->enable = gen11_dsi_enable; 1980 encoder->disable = gen11_dsi_disable; 1981 encoder->post_disable = gen11_dsi_post_disable; 1982 encoder->port = port; 1983 encoder->get_config = gen11_dsi_get_config; 1984 encoder->sync_state = gen11_dsi_sync_state; 1985 encoder->update_pipe = intel_backlight_update; 1986 encoder->compute_config = gen11_dsi_compute_config; 1987 encoder->get_hw_state = gen11_dsi_get_hw_state; 1988 encoder->initial_fastset_check = gen11_dsi_initial_fastset_check; 1989 encoder->type = INTEL_OUTPUT_DSI; 1990 encoder->cloneable = 0; 1991 encoder->pipe_mask = ~0; 1992 encoder->power_domain = POWER_DOMAIN_PORT_DSI; 1993 encoder->get_power_domains = gen11_dsi_get_power_domains; 1994 encoder->disable_clock = gen11_dsi_gate_clocks; 1995 encoder->is_clock_enabled = gen11_dsi_is_clock_enabled; 1996 encoder->shutdown = intel_dsi_shutdown; 1997 1998 /* register DSI connector with DRM subsystem */ 1999 drm_connector_init(&dev_priv->drm, connector, &gen11_dsi_connector_funcs, 2000 DRM_MODE_CONNECTOR_DSI); 2001 drm_connector_helper_add(connector, &gen11_dsi_connector_helper_funcs); 2002 connector->display_info.subpixel_order = SubPixelHorizontalRGB; 2003 intel_connector->get_hw_state = intel_connector_get_hw_state; 2004 2005 /* attach connector to encoder */ 2006 intel_connector_attach_encoder(intel_connector, encoder); 2007 2008 intel_dsi->panel_power_off_time = ktime_get_boottime(); 2009 2010 intel_bios_init_panel_late(dev_priv, &intel_connector->panel, encoder->devdata, NULL); 2011 2012 mutex_lock(&dev_priv->drm.mode_config.mutex); 2013 intel_panel_add_vbt_lfp_fixed_mode(intel_connector); 2014 mutex_unlock(&dev_priv->drm.mode_config.mutex); 2015 2016 if (!intel_panel_preferred_fixed_mode(intel_connector)) { 2017 drm_err(&dev_priv->drm, "DSI fixed mode info missing\n"); 2018 goto err; 2019 } 2020 2021 intel_panel_init(intel_connector, NULL); 2022 2023 intel_backlight_setup(intel_connector, INVALID_PIPE); 2024 2025 if (intel_connector->panel.vbt.dsi.config->dual_link) 2026 intel_dsi->ports = BIT(PORT_A) | BIT(PORT_B); 2027 else 2028 intel_dsi->ports = BIT(port); 2029 2030 if (drm_WARN_ON(&dev_priv->drm, intel_connector->panel.vbt.dsi.bl_ports & ~intel_dsi->ports)) 2031 intel_connector->panel.vbt.dsi.bl_ports &= intel_dsi->ports; 2032 2033 if (drm_WARN_ON(&dev_priv->drm, intel_connector->panel.vbt.dsi.cabc_ports & ~intel_dsi->ports)) 2034 intel_connector->panel.vbt.dsi.cabc_ports &= intel_dsi->ports; 2035 2036 for_each_dsi_port(port, intel_dsi->ports) { 2037 struct intel_dsi_host *host; 2038 2039 host = intel_dsi_host_init(intel_dsi, &gen11_dsi_host_ops, port); 2040 if (!host) 2041 goto err; 2042 2043 intel_dsi->dsi_hosts[port] = host; 2044 } 2045 2046 if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) { 2047 drm_dbg_kms(&dev_priv->drm, "no device found\n"); 2048 goto err; 2049 } 2050 2051 icl_dphy_param_init(intel_dsi); 2052 2053 icl_dsi_add_properties(intel_connector); 2054 return; 2055 2056 err: 2057 drm_connector_cleanup(connector); 2058 drm_encoder_cleanup(&encoder->base); 2059 kfree(intel_dsi); 2060 kfree(intel_connector); 2061 } 2062