Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/nouveau/dp: restructure link training code

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>

+224 -370
+6 -7
drivers/gpu/drm/nouveau/nouveau_bios.c
··· 1179 1179 * 1180 1180 */ 1181 1181 1182 - struct bit_displayport_encoder_table *dpe = NULL; 1183 1182 struct dcb_entry *dcb = bios->display.output; 1184 1183 struct drm_device *dev = bios->dev; 1185 1184 uint8_t cond = bios->data[offset + 1]; 1186 - int dummy; 1185 + uint8_t *table, headerlen; 1187 1186 1188 1187 BIOSLOG(bios, "0x%04X: subop 0x%02X\n", offset, cond); 1189 1188 1190 1189 if (!iexec->execute) 1191 1190 return 3; 1192 1191 1193 - dpe = nouveau_bios_dp_table(dev, dcb, &dummy); 1194 - if (!dpe) { 1192 + table = nouveau_bios_dp_table(dev, dcb, &headerlen); 1193 + if (!table) { 1195 1194 NV_ERROR(dev, "0x%04X: INIT_3A: no encoder table!!\n", offset); 1196 1195 return 3; 1197 1196 } ··· 1207 1208 break; 1208 1209 case 1: 1209 1210 case 2: 1210 - if (!(dpe->unknown & cond)) 1211 + if (!(table[5] & cond)) 1211 1212 iexec->execute = false; 1212 1213 break; 1213 1214 case 5: ··· 4479 4480 4480 4481 void * 4481 4482 nouveau_bios_dp_table(struct drm_device *dev, struct dcb_entry *dcbent, 4482 - int *length) 4483 + uint8_t *headerlen) 4483 4484 { 4484 4485 struct drm_nouveau_private *dev_priv = dev->dev_private; 4485 4486 struct nvbios *bios = &dev_priv->vbios; ··· 4497 4498 return NULL; 4498 4499 } 4499 4500 4500 - *length = table[4]; 4501 + *headerlen = table[4]; 4501 4502 return bios_output_config_match(dev, dcbent, 4502 4503 bios->display.dp_table_ptr + table[1], 4503 4504 table[2], table[3], table[0] >= 0x21);
+217 -345
drivers/gpu/drm/nouveau/nouveau_dp.c
··· 28 28 #include "nouveau_i2c.h" 29 29 #include "nouveau_connector.h" 30 30 #include "nouveau_encoder.h" 31 + #include "nouveau_crtc.h" 31 32 32 33 /****************************************************************************** 33 34 * aux channel util functions ··· 179 178 return 0; 180 179 } 181 180 182 - static int 183 - auxch_wr(struct drm_encoder *encoder, int address, uint8_t *buf, int size) 184 - { 185 - struct drm_device *dev = encoder->dev; 186 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 187 - struct nouveau_i2c_chan *auxch; 188 - int ret; 189 - 190 - auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); 191 - if (!auxch) 192 - return -ENODEV; 193 - 194 - ret = nouveau_dp_auxch(auxch, 8, address, buf, size); 195 - return ret; 196 - } 197 - 198 181 static u32 199 182 dp_link_bw_get(struct drm_device *dev, int or, int link) 200 183 { ··· 289 304 unk); 290 305 } 291 306 292 - static int 293 - nouveau_dp_lane_count_set(struct drm_encoder *encoder, uint8_t cmd) 307 + /****************************************************************************** 308 + * link training 309 + *****************************************************************************/ 310 + struct dp_state { 311 + struct dcb_entry *dcb; 312 + int auxch; 313 + int crtc; 314 + int or; 315 + int link; 316 + int enh_frame; 317 + int link_nr; 318 + u32 link_bw; 319 + u8 stat[6]; 320 + u8 conf[4]; 321 + }; 322 + 323 + static void 324 + dp_set_link_config(struct drm_device *dev, struct dp_state *dp) 294 325 { 295 - struct drm_device *dev = encoder->dev; 296 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 297 - uint32_t tmp; 298 - int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1); 326 + int or = dp->or, link = dp->link; 327 + u32 clk_sor, dp_ctrl; 328 + u8 sink[2]; 299 329 300 - tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); 301 - tmp &= ~(NV50_SOR_DP_CTRL_ENHANCED_FRAME_ENABLED | 302 - NV50_SOR_DP_CTRL_LANE_MASK); 303 - tmp |= ((1 << (cmd & DP_LANE_COUNT_MASK)) - 1) << 16; 304 - if (cmd & DP_LANE_COUNT_ENHANCED_FRAME_EN) 305 - tmp |= NV50_SOR_DP_CTRL_ENHANCED_FRAME_ENABLED; 306 - nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp); 330 + NV_DEBUG_KMS(dev, "%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw); 307 331 308 - return auxch_wr(encoder, DP_LANE_COUNT_SET, &cmd, 1); 332 + switch (dp->link_bw) { 333 + case 270000: 334 + clk_sor = 0x00040000; 335 + sink[0] = DP_LINK_BW_2_7; 336 + break; 337 + default: 338 + clk_sor = 0x00000000; 339 + sink[0] = DP_LINK_BW_1_62; 340 + break; 341 + } 342 + 343 + dp_ctrl = ((1 << dp->link_nr) - 1) << 16; 344 + sink[1] = dp->link_nr; 345 + if (dp->enh_frame) { 346 + dp_ctrl |= 0x00004000; 347 + sink[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; 348 + } 349 + 350 + nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, clk_sor); 351 + nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x001f4000, dp_ctrl); 352 + 353 + auxch_tx(dev, dp->auxch, 8, DP_LINK_BW_SET, sink, 2); 354 + } 355 + 356 + static void 357 + dp_set_training_pattern(struct drm_device *dev, struct dp_state *dp, u8 tp) 358 + { 359 + NV_DEBUG_KMS(dev, "training pattern %d\n", tp); 360 + nv_mask(dev, NV50_SOR_DP_CTRL(dp->or, dp->link), 0x0f000000, tp << 24); 361 + auxch_tx(dev, dp->auxch, 8, DP_TRAINING_PATTERN_SET, &tp, 1); 309 362 } 310 363 311 364 static int 312 - nouveau_dp_link_bw_set(struct drm_encoder *encoder, uint8_t cmd) 365 + dp_link_train_commit(struct drm_device *dev, struct dp_state *dp) 313 366 { 314 - struct drm_device *dev = encoder->dev; 315 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 316 - uint32_t tmp; 317 - int reg = 0x614300 + (nv_encoder->or * 0x800); 367 + u32 mask = 0, drv = 0, pre = 0, unk = 0; 368 + u8 shifts[4] = { 16, 8, 0, 24 }; 369 + u8 *bios, *last, headerlen; 370 + int link = dp->link; 371 + int or = dp->or; 372 + int i; 318 373 319 - tmp = nv_rd32(dev, reg); 320 - tmp &= 0xfff3ffff; 321 - if (cmd == DP_LINK_BW_2_7) 322 - tmp |= 0x00040000; 323 - nv_wr32(dev, reg, tmp); 374 + bios = nouveau_bios_dp_table(dev, dp->dcb, &headerlen); 375 + last = bios + headerlen + (bios[4] * 5); 376 + for (i = 0; i < dp->link_nr; i++) { 377 + u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf; 378 + u8 *conf = bios + headerlen; 324 379 325 - return auxch_wr(encoder, DP_LINK_BW_SET, &cmd, 1); 380 + while (conf < last) { 381 + if ((lane & 3) == conf[0] && 382 + (lane >> 2) == conf[1]) 383 + break; 384 + conf += 5; 385 + } 386 + 387 + if (conf == last) 388 + return -EINVAL; 389 + 390 + dp->conf[i] = (conf[1] << 3) | conf[0]; 391 + if (conf[0] == DP_TRAIN_VOLTAGE_SWING_1200) 392 + dp->conf[i] |= DP_TRAIN_MAX_SWING_REACHED; 393 + if (conf[1] == DP_TRAIN_PRE_EMPHASIS_9_5) 394 + dp->conf[i] |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED; 395 + 396 + NV_DEBUG_KMS(dev, "config lane %d %02x\n", i, dp->conf[i]); 397 + 398 + mask |= 0xff << shifts[i]; 399 + drv |= conf[2] << shifts[i]; 400 + pre |= conf[3] << shifts[i]; 401 + unk = (unk & ~0x0000ff00) | (conf[4] << 8); 402 + unk |= 1 << (shifts[i] >> 3); 403 + } 404 + 405 + nv_mask(dev, NV50_SOR_DP_UNK118(or, link), mask, drv); 406 + nv_mask(dev, NV50_SOR_DP_UNK120(or, link), mask, pre); 407 + nv_mask(dev, NV50_SOR_DP_UNK130(or, link), 0x0000ff0f, unk); 408 + 409 + return auxch_tx(dev, dp->auxch, 8, DP_TRAINING_LANE0_SET, dp->conf, 4); 326 410 } 327 411 328 412 static int 329 - nouveau_dp_link_train_set(struct drm_encoder *encoder, int pattern) 413 + dp_link_train_update(struct drm_device *dev, struct dp_state *dp, u32 delay) 330 414 { 331 - struct drm_device *dev = encoder->dev; 332 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 333 - uint32_t tmp; 334 - uint8_t cmd; 335 - int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1); 336 415 int ret; 337 416 338 - tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); 339 - tmp &= ~NV50_SOR_DP_CTRL_TRAINING_PATTERN; 340 - tmp |= (pattern << 24); 341 - nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp); 417 + udelay(delay); 342 418 343 - ret = auxch_rd(encoder, DP_TRAINING_PATTERN_SET, &cmd, 1); 419 + ret = auxch_tx(dev, dp->auxch, 9, DP_LANE0_1_STATUS, dp->stat, 6); 344 420 if (ret) 345 421 return ret; 346 - cmd &= ~DP_TRAINING_PATTERN_MASK; 347 - cmd |= (pattern & DP_TRAINING_PATTERN_MASK); 348 - return auxch_wr(encoder, DP_TRAINING_PATTERN_SET, &cmd, 1); 422 + 423 + NV_DEBUG_KMS(dev, "status %02x %02x %02x %02x %02x %02x\n", 424 + dp->stat[0], dp->stat[1], dp->stat[2], dp->stat[3], 425 + dp->stat[4], dp->stat[5]); 426 + return 0; 349 427 } 350 428 351 429 static int 352 - nouveau_dp_max_voltage_swing(struct drm_encoder *encoder) 430 + dp_link_train_cr(struct drm_device *dev, struct dp_state *dp) 353 431 { 354 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 355 - struct drm_device *dev = encoder->dev; 356 - struct bit_displayport_encoder_table_entry *dpse; 357 - struct bit_displayport_encoder_table *dpe; 358 - int i, dpe_headerlen, max_vs = 0; 432 + bool cr_done = false, abort = false; 433 + int voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 434 + int tries = 0, i; 359 435 360 - dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 361 - if (!dpe) 362 - return false; 363 - dpse = (void *)((char *)dpe + dpe_headerlen); 436 + dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_1); 364 437 365 - for (i = 0; i < dpe_headerlen; i++, dpse++) { 366 - if (dpse->vs_level > max_vs) 367 - max_vs = dpse->vs_level; 368 - } 369 - 370 - return max_vs; 371 - } 372 - 373 - static int 374 - nouveau_dp_max_pre_emphasis(struct drm_encoder *encoder, int vs) 375 - { 376 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 377 - struct drm_device *dev = encoder->dev; 378 - struct bit_displayport_encoder_table_entry *dpse; 379 - struct bit_displayport_encoder_table *dpe; 380 - int i, dpe_headerlen, max_pre = 0; 381 - 382 - dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 383 - if (!dpe) 384 - return false; 385 - dpse = (void *)((char *)dpe + dpe_headerlen); 386 - 387 - for (i = 0; i < dpe_headerlen; i++, dpse++) { 388 - if (dpse->vs_level != vs) 389 - continue; 390 - 391 - if (dpse->pre_level > max_pre) 392 - max_pre = dpse->pre_level; 393 - } 394 - 395 - return max_pre; 396 - } 397 - 398 - static bool 399 - nouveau_dp_link_train_adjust(struct drm_encoder *encoder, uint8_t *config) 400 - { 401 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 402 - struct drm_device *dev = encoder->dev; 403 - struct bit_displayport_encoder_table *dpe; 404 - int ret, i, dpe_headerlen, vs = 0, pre = 0; 405 - uint8_t request[2]; 406 - 407 - dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 408 - if (!dpe) 409 - return false; 410 - 411 - ret = auxch_rd(encoder, DP_ADJUST_REQUEST_LANE0_1, request, 2); 412 - if (ret) 413 - return false; 414 - 415 - NV_DEBUG_KMS(dev, "\t\tadjust 0x%02x 0x%02x\n", request[0], request[1]); 416 - 417 - /* Keep all lanes at the same level.. */ 418 - for (i = 0; i < nv_encoder->dp.link_nr; i++) { 419 - int lane_req = (request[i >> 1] >> ((i & 1) << 2)) & 0xf; 420 - int lane_vs = lane_req & 3; 421 - int lane_pre = (lane_req >> 2) & 3; 422 - 423 - if (lane_vs > vs) 424 - vs = lane_vs; 425 - if (lane_pre > pre) 426 - pre = lane_pre; 427 - } 428 - 429 - if (vs >= nouveau_dp_max_voltage_swing(encoder)) { 430 - vs = nouveau_dp_max_voltage_swing(encoder); 431 - vs |= 4; 432 - } 433 - 434 - if (pre >= nouveau_dp_max_pre_emphasis(encoder, vs & 3)) { 435 - pre = nouveau_dp_max_pre_emphasis(encoder, vs & 3); 436 - pre |= 4; 437 - } 438 - 439 - /* Update the configuration for all lanes.. */ 440 - for (i = 0; i < nv_encoder->dp.link_nr; i++) 441 - config[i] = (pre << 3) | vs; 442 - 443 - return true; 444 - } 445 - 446 - static bool 447 - nouveau_dp_link_train_commit(struct drm_encoder *encoder, uint8_t *config) 448 - { 449 - struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 450 - struct drm_device *dev = encoder->dev; 451 - struct bit_displayport_encoder_table_entry *dpse; 452 - struct bit_displayport_encoder_table *dpe; 453 - int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1); 454 - int dpe_headerlen, ret, i; 455 - 456 - NV_DEBUG_KMS(dev, "\t\tconfig 0x%02x 0x%02x 0x%02x 0x%02x\n", 457 - config[0], config[1], config[2], config[3]); 458 - 459 - dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 460 - if (!dpe) 461 - return false; 462 - dpse = (void *)((char *)dpe + dpe_headerlen); 463 - 464 - for (i = 0; i < dpe->record_nr; i++, dpse++) { 465 - if (dpse->vs_level == (config[0] & 3) && 466 - dpse->pre_level == ((config[0] >> 3) & 3)) 438 + do { 439 + if (dp_link_train_commit(dev, dp) || 440 + dp_link_train_update(dev, dp, 100)) 467 441 break; 468 - } 469 - BUG_ON(i == dpe->record_nr); 470 442 471 - for (i = 0; i < nv_encoder->dp.link_nr; i++) { 472 - const int shift[4] = { 16, 8, 0, 24 }; 473 - uint32_t mask = 0xff << shift[i]; 474 - uint32_t reg0, reg1, reg2; 443 + cr_done = true; 444 + for (i = 0; i < dp->link_nr; i++) { 445 + u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; 446 + if (!(lane & DP_LANE_CR_DONE)) { 447 + cr_done = false; 448 + if (dp->conf[i] & DP_TRAIN_MAX_SWING_REACHED) 449 + abort = true; 450 + break; 451 + } 452 + } 475 453 476 - reg0 = nv_rd32(dev, NV50_SOR_DP_UNK118(or, link)) & ~mask; 477 - reg0 |= (dpse->reg0 << shift[i]); 478 - reg1 = nv_rd32(dev, NV50_SOR_DP_UNK120(or, link)) & ~mask; 479 - reg1 |= (dpse->reg1 << shift[i]); 480 - reg2 = nv_rd32(dev, NV50_SOR_DP_UNK130(or, link)) & 0xffff00ff; 481 - reg2 |= (dpse->reg2 << 8); 482 - nv_wr32(dev, NV50_SOR_DP_UNK118(or, link), reg0); 483 - nv_wr32(dev, NV50_SOR_DP_UNK120(or, link), reg1); 484 - nv_wr32(dev, NV50_SOR_DP_UNK130(or, link), reg2); 485 - } 454 + if ((dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) { 455 + voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 456 + tries = 0; 457 + } 458 + } while (!cr_done && !abort && ++tries < 5); 486 459 487 - ret = auxch_wr(encoder, DP_TRAINING_LANE0_SET, config, 4); 488 - if (ret) 489 - return false; 460 + return cr_done ? 0 : -1; 461 + } 490 462 491 - return true; 463 + static int 464 + dp_link_train_eq(struct drm_device *dev, struct dp_state *dp) 465 + { 466 + bool eq_done, cr_done = true; 467 + int tries = 0, i; 468 + 469 + dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_2); 470 + 471 + do { 472 + if (dp_link_train_update(dev, dp, 400)) 473 + break; 474 + 475 + eq_done = !!(dp->stat[2] & DP_INTERLANE_ALIGN_DONE); 476 + for (i = 0; i < dp->link_nr && eq_done; i++) { 477 + u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; 478 + if (!(lane & DP_LANE_CR_DONE)) 479 + cr_done = false; 480 + if (!(lane & DP_LANE_CHANNEL_EQ_DONE) || 481 + !(lane & DP_LANE_SYMBOL_LOCKED)) 482 + eq_done = false; 483 + } 484 + 485 + if (dp_link_train_commit(dev, dp)) 486 + break; 487 + } while (!eq_done && cr_done && ++tries <= 5); 488 + 489 + return eq_done ? 0 : -1; 492 490 } 493 491 494 492 bool 495 493 nouveau_dp_link_train(struct drm_encoder *encoder, u32 datarate) 496 494 { 497 - struct drm_device *dev = encoder->dev; 498 - struct drm_nouveau_private *dev_priv = dev->dev_private; 495 + struct drm_nouveau_private *dev_priv = encoder->dev->dev_private; 499 496 struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; 500 497 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 501 - struct nouveau_connector *nv_connector; 502 - struct bit_displayport_encoder_table *dpe; 503 - int dpe_headerlen; 504 - uint8_t config[4], status[3]; 505 - bool cr_done, cr_max_vs, eq_done, hpd_state; 506 - int ret = 0, i, tries, voltage; 498 + struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); 499 + struct nouveau_connector *nv_connector = 500 + nouveau_encoder_connector_get(nv_encoder); 501 + struct drm_device *dev = encoder->dev; 502 + struct nouveau_i2c_chan *auxch; 503 + const u32 bw_list[] = { 270000, 162000, 0 }; 504 + const u32 *link_bw = bw_list; 505 + struct dp_state dp; 506 + u8 *bios, headerlen; 507 + u16 script; 507 508 508 - NV_DEBUG_KMS(dev, "link training!!\n"); 509 - 510 - nv_connector = nouveau_encoder_connector_get(nv_encoder); 511 - if (!nv_connector) 509 + auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); 510 + if (!auxch) 512 511 return false; 513 512 514 - dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 515 - if (!dpe) { 516 - NV_ERROR(dev, "SOR-%d: no DP encoder table!\n", nv_encoder->or); 517 - return false; 518 - } 513 + bios = nouveau_bios_dp_table(dev, nv_encoder->dcb, &headerlen); 514 + if (!bios) 515 + return -EINVAL; 519 516 520 - /* disable hotplug detect, this flips around on some panels during 521 - * link training. 517 + dp.dcb = nv_encoder->dcb; 518 + dp.crtc = nv_crtc->index; 519 + dp.auxch = auxch->rd; 520 + dp.or = nv_encoder->or; 521 + dp.link = !(nv_encoder->dcb->sorconf.link & 1); 522 + dp.enh_frame = nv_encoder->dp.enhanced_frame; 523 + 524 + /* some sinks toggle hotplug in response to some of the actions 525 + * we take during link training (DP_SET_POWER is one), we need 526 + * to ignore them for the moment to avoid races. 522 527 */ 523 - hpd_state = pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, false); 528 + pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, false); 524 529 525 - if (dpe->script0) { 526 - NV_DEBUG_KMS(dev, "SOR-%d: running DP script 0\n", nv_encoder->or); 527 - nouveau_bios_run_init_table(dev, le16_to_cpu(dpe->script0), 528 - nv_encoder->dcb, -1); 530 + /* execute pre-train script from vbios */ 531 + nouveau_bios_run_init_table(dev, ROM16(bios[6]), dp.dcb, dp.crtc); 532 + 533 + /* start off at highest link rate supported by encoder and display */ 534 + if (nv_encoder->dp.link_bw == DP_LINK_BW_1_62) 535 + link_bw++; 536 + 537 + while (link_bw[0]) { 538 + /* find minimum required lane count at this link rate */ 539 + dp.link_nr = nv_encoder->dp.link_nr; 540 + while ((dp.link_nr >> 1) * link_bw[0] > datarate) 541 + dp.link_nr >>= 1; 542 + 543 + /* drop link rate to minimum with this lane count */ 544 + while ((link_bw[1] * dp.link_nr) > datarate) 545 + link_bw++; 546 + dp.link_bw = link_bw[0]; 547 + 548 + /* program selected link configuration */ 549 + dp_set_link_config(dev, &dp); 550 + 551 + /* attempt to train the link at this configuration */ 552 + memset(dp.stat, 0x00, sizeof(dp.stat)); 553 + if (!dp_link_train_cr(dev, &dp) && 554 + !dp_link_train_eq(dev, &dp)) 555 + break; 556 + 557 + /* retry at lower rate */ 558 + link_bw++; 529 559 } 530 560 531 - train: 532 - cr_done = eq_done = false; 561 + /* finish link training */ 562 + dp_set_training_pattern(dev, &dp, DP_TRAINING_PATTERN_DISABLE); 533 563 534 - /* set link configuration */ 535 - NV_DEBUG_KMS(dev, "\tbegin train: bw %d, lanes %d\n", 536 - nv_encoder->dp.link_bw, nv_encoder->dp.link_nr); 537 - 538 - ret = nouveau_dp_link_bw_set(encoder, nv_encoder->dp.link_bw); 539 - if (ret) 540 - return false; 541 - 542 - config[0] = nv_encoder->dp.link_nr; 543 - if (nv_encoder->dp.dpcd_version >= 0x11 && 544 - nv_encoder->dp.enhanced_frame) 545 - config[0] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; 546 - 547 - ret = nouveau_dp_lane_count_set(encoder, config[0]); 548 - if (ret) 549 - return false; 550 - 551 - /* clock recovery */ 552 - NV_DEBUG_KMS(dev, "\tbegin cr\n"); 553 - ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_1); 554 - if (ret) 555 - goto stop; 556 - 557 - tries = 0; 558 - voltage = -1; 559 - memset(config, 0x00, sizeof(config)); 560 - for (;;) { 561 - if (!nouveau_dp_link_train_commit(encoder, config)) 562 - break; 563 - 564 - udelay(100); 565 - 566 - ret = auxch_rd(encoder, DP_LANE0_1_STATUS, status, 2); 567 - if (ret) 568 - break; 569 - NV_DEBUG_KMS(dev, "\t\tstatus: 0x%02x 0x%02x\n", 570 - status[0], status[1]); 571 - 572 - cr_done = true; 573 - cr_max_vs = false; 574 - for (i = 0; i < nv_encoder->dp.link_nr; i++) { 575 - int lane = (status[i >> 1] >> ((i & 1) * 4)) & 0xf; 576 - 577 - if (!(lane & DP_LANE_CR_DONE)) { 578 - cr_done = false; 579 - if (config[i] & DP_TRAIN_MAX_PRE_EMPHASIS_REACHED) 580 - cr_max_vs = true; 581 - break; 582 - } 583 - } 584 - 585 - if ((config[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) { 586 - voltage = config[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 587 - tries = 0; 588 - } 589 - 590 - if (cr_done || cr_max_vs || (++tries == 5)) 591 - break; 592 - 593 - if (!nouveau_dp_link_train_adjust(encoder, config)) 594 - break; 595 - } 596 - 597 - if (!cr_done) 598 - goto stop; 599 - 600 - /* channel equalisation */ 601 - NV_DEBUG_KMS(dev, "\tbegin eq\n"); 602 - ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_2); 603 - if (ret) 604 - goto stop; 605 - 606 - for (tries = 0; tries <= 5; tries++) { 607 - udelay(400); 608 - 609 - ret = auxch_rd(encoder, DP_LANE0_1_STATUS, status, 3); 610 - if (ret) 611 - break; 612 - NV_DEBUG_KMS(dev, "\t\tstatus: 0x%02x 0x%02x\n", 613 - status[0], status[1]); 614 - 615 - eq_done = true; 616 - if (!(status[2] & DP_INTERLANE_ALIGN_DONE)) 617 - eq_done = false; 618 - 619 - for (i = 0; eq_done && i < nv_encoder->dp.link_nr; i++) { 620 - int lane = (status[i >> 1] >> ((i & 1) * 4)) & 0xf; 621 - 622 - if (!(lane & DP_LANE_CR_DONE)) { 623 - cr_done = false; 624 - break; 625 - } 626 - 627 - if (!(lane & DP_LANE_CHANNEL_EQ_DONE) || 628 - !(lane & DP_LANE_SYMBOL_LOCKED)) { 629 - eq_done = false; 630 - break; 631 - } 632 - } 633 - 634 - if (eq_done || !cr_done) 635 - break; 636 - 637 - if (!nouveau_dp_link_train_adjust(encoder, config) || 638 - !nouveau_dp_link_train_commit(encoder, config)) 639 - break; 640 - } 641 - 642 - stop: 643 - /* end link training */ 644 - ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_DISABLE); 645 - if (ret) 646 - return false; 647 - 648 - /* retry at a lower setting, if possible */ 649 - if (!ret && !(eq_done && cr_done)) { 650 - NV_DEBUG_KMS(dev, "\twe failed\n"); 651 - if (nv_encoder->dp.link_bw != DP_LINK_BW_1_62) { 652 - NV_DEBUG_KMS(dev, "retry link training at low rate\n"); 653 - nv_encoder->dp.link_bw = DP_LINK_BW_1_62; 654 - goto train; 655 - } 656 - } 657 - 658 - if (dpe->script1) { 659 - NV_DEBUG_KMS(dev, "SOR-%d: running DP script 1\n", nv_encoder->or); 660 - nouveau_bios_run_init_table(dev, le16_to_cpu(dpe->script1), 661 - nv_encoder->dcb, -1); 662 - } 564 + /* execute post-train script from vbios */ 565 + nouveau_bios_run_init_table(dev, ROM16(bios[8]), dp.dcb, dp.crtc); 663 566 664 567 /* re-enable hotplug detect */ 665 - pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, hpd_state); 666 - 667 - return eq_done; 568 + pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, true); 569 + return true; 668 570 } 669 571 670 572 bool
+1 -1
drivers/gpu/drm/nouveau/nouveau_drv.h
··· 1081 1081 extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk, 1082 1082 struct dcb_entry *, int crtc); 1083 1083 extern void *nouveau_bios_dp_table(struct drm_device *, struct dcb_entry *, 1084 - int *length); 1084 + u8 *headerlen); 1085 1085 extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *); 1086 1086 extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *); 1087 1087 extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
-17
drivers/gpu/drm/nouveau/nouveau_encoder.h
··· 84 84 int nv50_sor_create(struct drm_connector *, struct dcb_entry *); 85 85 int nv50_dac_create(struct drm_connector *, struct dcb_entry *); 86 86 87 - struct bit_displayport_encoder_table { 88 - uint32_t match; 89 - uint8_t record_nr; 90 - uint8_t unknown; 91 - uint16_t script0; 92 - uint16_t script1; 93 - uint16_t unknown_table; 94 - } __attribute__ ((packed)); 95 - 96 - struct bit_displayport_encoder_table_entry { 97 - uint8_t vs_level; 98 - uint8_t pre_level; 99 - uint8_t reg0; 100 - uint8_t reg1; 101 - uint8_t reg2; 102 - } __attribute__ ((packed)); 103 - 104 87 #endif /* __NOUVEAU_ENCODER_H__ */