Rev 5271 | Rev 6088 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5271 | Rev 6084 | ||
---|---|---|---|
Line 157... | Line 157... | ||
157 | return 540000; |
157 | return 540000; |
158 | } |
158 | } |
159 | } |
159 | } |
160 | EXPORT_SYMBOL(drm_dp_bw_code_to_link_rate); |
160 | EXPORT_SYMBOL(drm_dp_bw_code_to_link_rate); |
Line -... | Line 161... | ||
- | 161 | ||
- | 162 | #define AUX_RETRY_INTERVAL 500 /* us */ |
|
161 | 163 | ||
162 | /** |
164 | /** |
163 | * DOC: dp helpers |
165 | * DOC: dp helpers |
164 | * |
166 | * |
165 | * The DisplayPort AUX channel is an abstraction to allow generic, driver- |
167 | * The DisplayPort AUX channel is an abstraction to allow generic, driver- |
Line 352... | Line 354... | ||
352 | return 0; |
354 | return 0; |
353 | } |
355 | } |
354 | EXPORT_SYMBOL(drm_dp_link_power_up); |
356 | EXPORT_SYMBOL(drm_dp_link_power_up); |
Line 355... | Line 357... | ||
355 | 357 | ||
- | 358 | /** |
|
- | 359 | * drm_dp_link_power_down() - power down a DisplayPort link |
|
- | 360 | * @aux: DisplayPort AUX channel |
|
- | 361 | * @link: pointer to a structure containing the link configuration |
|
- | 362 | * |
|
- | 363 | * Returns 0 on success or a negative error code on failure. |
|
- | 364 | */ |
|
- | 365 | int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link) |
|
- | 366 | { |
|
- | 367 | u8 value; |
|
- | 368 | int err; |
|
- | 369 | ||
- | 370 | /* DP_SET_POWER register is only available on DPCD v1.1 and later */ |
|
- | 371 | if (link->revision < 0x11) |
|
- | 372 | return 0; |
|
- | 373 | ||
- | 374 | err = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value); |
|
- | 375 | if (err < 0) |
|
- | 376 | return err; |
|
- | 377 | ||
- | 378 | value &= ~DP_SET_POWER_MASK; |
|
- | 379 | value |= DP_SET_POWER_D3; |
|
- | 380 | ||
- | 381 | err = drm_dp_dpcd_writeb(aux, DP_SET_POWER, value); |
|
- | 382 | if (err < 0) |
|
- | 383 | return err; |
|
- | 384 | ||
- | 385 | return 0; |
|
- | 386 | } |
|
- | 387 | EXPORT_SYMBOL(drm_dp_link_power_down); |
|
- | 388 | ||
356 | /** |
389 | /** |
357 | * drm_dp_link_configure() - configure a DisplayPort link |
390 | * drm_dp_link_configure() - configure a DisplayPort link |
358 | * @aux: DisplayPort AUX channel |
391 | * @aux: DisplayPort AUX channel |
359 | * @link: pointer to a structure containing the link configuration |
392 | * @link: pointer to a structure containing the link configuration |
360 | * |
393 | * |
Line 389... | Line 422... | ||
389 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
422 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
390 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
423 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
391 | I2C_FUNC_10BIT_ADDR; |
424 | I2C_FUNC_10BIT_ADDR; |
392 | } |
425 | } |
Line -... | Line 426... | ||
- | 426 | ||
- | 427 | static void drm_dp_i2c_msg_write_status_update(struct drm_dp_aux_msg *msg) |
|
- | 428 | { |
|
- | 429 | /* |
|
- | 430 | * In case of i2c defer or short i2c ack reply to a write, |
|
- | 431 | * we need to switch to WRITE_STATUS_UPDATE to drain the |
|
- | 432 | * rest of the message |
|
- | 433 | */ |
|
- | 434 | if ((msg->request & ~DP_AUX_I2C_MOT) == DP_AUX_I2C_WRITE) { |
|
- | 435 | msg->request &= DP_AUX_I2C_MOT; |
|
- | 436 | msg->request |= DP_AUX_I2C_WRITE_STATUS_UPDATE; |
|
- | 437 | } |
|
- | 438 | } |
|
- | 439 | ||
- | 440 | #define AUX_PRECHARGE_LEN 10 /* 10 to 16 */ |
|
- | 441 | #define AUX_SYNC_LEN (16 + 4) /* preamble + AUX_SYNC_END */ |
|
- | 442 | #define AUX_STOP_LEN 4 |
|
- | 443 | #define AUX_CMD_LEN 4 |
|
- | 444 | #define AUX_ADDRESS_LEN 20 |
|
- | 445 | #define AUX_REPLY_PAD_LEN 4 |
|
- | 446 | #define AUX_LENGTH_LEN 8 |
|
- | 447 | ||
- | 448 | /* |
|
- | 449 | * Calculate the duration of the AUX request/reply in usec. Gives the |
|
- | 450 | * "best" case estimate, ie. successful while as short as possible. |
|
- | 451 | */ |
|
- | 452 | static int drm_dp_aux_req_duration(const struct drm_dp_aux_msg *msg) |
|
- | 453 | { |
|
- | 454 | int len = AUX_PRECHARGE_LEN + AUX_SYNC_LEN + AUX_STOP_LEN + |
|
- | 455 | AUX_CMD_LEN + AUX_ADDRESS_LEN + AUX_LENGTH_LEN; |
|
- | 456 | ||
- | 457 | if ((msg->request & DP_AUX_I2C_READ) == 0) |
|
- | 458 | len += msg->size * 8; |
|
- | 459 | ||
- | 460 | return len; |
|
- | 461 | } |
|
- | 462 | ||
- | 463 | static int drm_dp_aux_reply_duration(const struct drm_dp_aux_msg *msg) |
|
- | 464 | { |
|
- | 465 | int len = AUX_PRECHARGE_LEN + AUX_SYNC_LEN + AUX_STOP_LEN + |
|
- | 466 | AUX_CMD_LEN + AUX_REPLY_PAD_LEN; |
|
- | 467 | ||
- | 468 | /* |
|
- | 469 | * For read we expect what was asked. For writes there will |
|
- | 470 | * be 0 or 1 data bytes. Assume 0 for the "best" case. |
|
- | 471 | */ |
|
- | 472 | if (msg->request & DP_AUX_I2C_READ) |
|
- | 473 | len += msg->size * 8; |
|
- | 474 | ||
- | 475 | return len; |
|
- | 476 | } |
|
- | 477 | ||
- | 478 | #define I2C_START_LEN 1 |
|
- | 479 | #define I2C_STOP_LEN 1 |
|
- | 480 | #define I2C_ADDR_LEN 9 /* ADDRESS + R/W + ACK/NACK */ |
|
- | 481 | #define I2C_DATA_LEN 9 /* DATA + ACK/NACK */ |
|
- | 482 | ||
- | 483 | /* |
|
- | 484 | * Calculate the length of the i2c transfer in usec, assuming |
|
- | 485 | * the i2c bus speed is as specified. Gives the the "worst" |
|
- | 486 | * case estimate, ie. successful while as long as possible. |
|
- | 487 | * Doesn't account the the "MOT" bit, and instead assumes each |
|
- | 488 | * message includes a START, ADDRESS and STOP. Neither does it |
|
- | 489 | * account for additional random variables such as clock stretching. |
|
- | 490 | */ |
|
- | 491 | static int drm_dp_i2c_msg_duration(const struct drm_dp_aux_msg *msg, |
|
- | 492 | int i2c_speed_khz) |
|
- | 493 | { |
|
- | 494 | /* AUX bitrate is 1MHz, i2c bitrate as specified */ |
|
- | 495 | return DIV_ROUND_UP((I2C_START_LEN + I2C_ADDR_LEN + |
|
- | 496 | msg->size * I2C_DATA_LEN + |
|
- | 497 | I2C_STOP_LEN) * 1000, i2c_speed_khz); |
|
- | 498 | } |
|
- | 499 | ||
- | 500 | /* |
|
- | 501 | * Deterine how many retries should be attempted to successfully transfer |
|
- | 502 | * the specified message, based on the estimated durations of the |
|
- | 503 | * i2c and AUX transfers. |
|
- | 504 | */ |
|
- | 505 | static int drm_dp_i2c_retry_count(const struct drm_dp_aux_msg *msg, |
|
- | 506 | int i2c_speed_khz) |
|
- | 507 | { |
|
- | 508 | int aux_time_us = drm_dp_aux_req_duration(msg) + |
|
- | 509 | drm_dp_aux_reply_duration(msg); |
|
- | 510 | int i2c_time_us = drm_dp_i2c_msg_duration(msg, i2c_speed_khz); |
|
- | 511 | ||
- | 512 | return DIV_ROUND_UP(i2c_time_us, aux_time_us + AUX_RETRY_INTERVAL); |
|
- | 513 | } |
|
- | 514 | ||
- | 515 | /* |
|
- | 516 | * FIXME currently assumes 10 kHz as some real world devices seem |
|
- | 517 | * to require it. We should query/set the speed via DPCD if supported. |
|
- | 518 | */ |
|
- | 519 | static int dp_aux_i2c_speed_khz __read_mostly = 10; |
|
- | 520 | module_param_unsafe(dp_aux_i2c_speed_khz, int, 0644); |
|
- | 521 | MODULE_PARM_DESC(dp_aux_i2c_speed_khz, |
|
- | 522 | "Assumed speed of the i2c bus in kHz, (1-400, default 10)"); |
|
393 | 523 | ||
394 | /* |
524 | /* |
395 | * Transfer a single I2C-over-AUX message and handle various error conditions, |
525 | * Transfer a single I2C-over-AUX message and handle various error conditions, |
396 | * retrying the transaction as appropriate. It is assumed that the |
526 | * retrying the transaction as appropriate. It is assumed that the |
397 | * aux->transfer function does not modify anything in the msg other than the |
527 | * aux->transfer function does not modify anything in the msg other than the |
- | 528 | * reply field. |
|
- | 529 | * |
|
398 | * reply field. |
530 | * Returns bytes transferred on success, or a negative error code on failure. |
399 | */ |
531 | */ |
400 | static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) |
532 | static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) |
401 | { |
533 | { |
402 | unsigned int retry; |
534 | unsigned int retry, defer_i2c; |
403 | int err; |
- | |
404 | 535 | int ret; |
|
405 | /* |
536 | /* |
406 | * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device |
537 | * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device |
407 | * is required to retry at least seven times upon receiving AUX_DEFER |
538 | * is required to retry at least seven times upon receiving AUX_DEFER |
- | 539 | * before giving up the AUX transaction. |
|
- | 540 | * |
|
408 | * before giving up the AUX transaction. |
541 | * We also try to account for the i2c bus speed. |
- | 542 | */ |
|
- | 543 | int max_retries = max(7, drm_dp_i2c_retry_count(msg, dp_aux_i2c_speed_khz)); |
|
409 | */ |
544 | |
410 | for (retry = 0; retry < 7; retry++) { |
545 | for (retry = 0, defer_i2c = 0; retry < (max_retries + defer_i2c); retry++) { |
411 | mutex_lock(&aux->hw_mutex); |
546 | mutex_lock(&aux->hw_mutex); |
412 | err = aux->transfer(aux, msg); |
547 | ret = aux->transfer(aux, msg); |
413 | mutex_unlock(&aux->hw_mutex); |
548 | mutex_unlock(&aux->hw_mutex); |
414 | if (err < 0) { |
549 | if (ret < 0) { |
415 | if (err == -EBUSY) |
550 | if (ret == -EBUSY) |
Line 416... | Line 551... | ||
416 | continue; |
551 | continue; |
417 | 552 | ||
418 | DRM_DEBUG_KMS("transaction failed: %d\n", err); |
553 | DRM_DEBUG_KMS("transaction failed: %d\n", ret); |
Line 419... | Line 554... | ||
419 | return err; |
554 | return ret; |
420 | } |
555 | } |
Line 427... | Line 562... | ||
427 | * need to check for the I2C ACK reply. |
562 | * need to check for the I2C ACK reply. |
428 | */ |
563 | */ |
429 | break; |
564 | break; |
Line 430... | Line 565... | ||
430 | 565 | ||
431 | case DP_AUX_NATIVE_REPLY_NACK: |
566 | case DP_AUX_NATIVE_REPLY_NACK: |
432 | DRM_DEBUG_KMS("native nack\n"); |
567 | DRM_DEBUG_KMS("native nack (result=%d, size=%zu)\n", ret, msg->size); |
Line 433... | Line 568... | ||
433 | return -EREMOTEIO; |
568 | return -EREMOTEIO; |
434 | 569 | ||
435 | case DP_AUX_NATIVE_REPLY_DEFER: |
570 | case DP_AUX_NATIVE_REPLY_DEFER: |
436 | DRM_DEBUG_KMS("native defer"); |
571 | DRM_DEBUG_KMS("native defer\n"); |
437 | /* |
572 | /* |
438 | * We could check for I2C bit rate capabilities and if |
573 | * We could check for I2C bit rate capabilities and if |
439 | * available adjust this interval. We could also be |
574 | * available adjust this interval. We could also be |
Line 455... | Line 590... | ||
455 | case DP_AUX_I2C_REPLY_ACK: |
590 | case DP_AUX_I2C_REPLY_ACK: |
456 | /* |
591 | /* |
457 | * Both native ACK and I2C ACK replies received. We |
592 | * Both native ACK and I2C ACK replies received. We |
458 | * can assume the transfer was successful. |
593 | * can assume the transfer was successful. |
459 | */ |
594 | */ |
460 | if (err < msg->size) |
595 | if (ret != msg->size) |
461 | return -EPROTO; |
596 | drm_dp_i2c_msg_write_status_update(msg); |
462 | return 0; |
597 | return ret; |
Line 463... | Line 598... | ||
463 | 598 | ||
464 | case DP_AUX_I2C_REPLY_NACK: |
599 | case DP_AUX_I2C_REPLY_NACK: |
- | 600 | DRM_DEBUG_KMS("I2C nack (result=%d, size=%zu\n", ret, msg->size); |
|
465 | DRM_DEBUG_KMS("I2C nack\n"); |
601 | aux->i2c_nack_count++; |
Line 466... | Line 602... | ||
466 | return -EREMOTEIO; |
602 | return -EREMOTEIO; |
467 | 603 | ||
- | 604 | case DP_AUX_I2C_REPLY_DEFER: |
|
- | 605 | DRM_DEBUG_KMS("I2C defer\n"); |
|
- | 606 | /* DP Compliance Test 4.2.2.5 Requirement: |
|
- | 607 | * Must have at least 7 retries for I2C defers on the |
|
- | 608 | * transaction to pass this test |
|
- | 609 | */ |
|
- | 610 | aux->i2c_defer_count++; |
|
468 | case DP_AUX_I2C_REPLY_DEFER: |
611 | if (defer_i2c < 7) |
- | 612 | defer_i2c++; |
|
- | 613 | usleep_range(400, 500); |
|
469 | DRM_DEBUG_KMS("I2C defer\n"); |
614 | drm_dp_i2c_msg_write_status_update(msg); |
Line 470... | Line 615... | ||
470 | usleep_range(400, 500); |
615 | |
471 | continue; |
616 | continue; |
472 | 617 | ||
Line 478... | Line 623... | ||
478 | 623 | ||
479 | DRM_DEBUG_KMS("too many retries, giving up\n"); |
624 | DRM_DEBUG_KMS("too many retries, giving up\n"); |
480 | return -EREMOTEIO; |
625 | return -EREMOTEIO; |
Line -... | Line 626... | ||
- | 626 | } |
|
- | 627 | ||
- | 628 | static void drm_dp_i2c_msg_set_request(struct drm_dp_aux_msg *msg, |
|
- | 629 | const struct i2c_msg *i2c_msg) |
|
- | 630 | { |
|
- | 631 | msg->request = (i2c_msg->flags & I2C_M_RD) ? |
|
- | 632 | DP_AUX_I2C_READ : DP_AUX_I2C_WRITE; |
|
- | 633 | msg->request |= DP_AUX_I2C_MOT; |
|
- | 634 | } |
|
- | 635 | ||
- | 636 | /* |
|
- | 637 | * Keep retrying drm_dp_i2c_do_msg until all data has been transferred. |
|
- | 638 | * |
|
- | 639 | * Returns an error code on failure, or a recommended transfer size on success. |
|
- | 640 | */ |
|
- | 641 | static int drm_dp_i2c_drain_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *orig_msg) |
|
- | 642 | { |
|
- | 643 | int err, ret = orig_msg->size; |
|
- | 644 | struct drm_dp_aux_msg msg = *orig_msg; |
|
- | 645 | ||
- | 646 | while (msg.size > 0) { |
|
- | 647 | err = drm_dp_i2c_do_msg(aux, &msg); |
|
- | 648 | if (err <= 0) |
|
- | 649 | return err == 0 ? -EPROTO : err; |
|
- | 650 | ||
- | 651 | if (err < msg.size && err < ret) { |
|
- | 652 | DRM_DEBUG_KMS("Partial I2C reply: requested %zu bytes got %d bytes\n", |
|
- | 653 | msg.size, err); |
|
- | 654 | ret = err; |
|
- | 655 | } |
|
- | 656 | ||
- | 657 | msg.size -= err; |
|
- | 658 | msg.buffer += err; |
|
- | 659 | } |
|
- | 660 | ||
- | 661 | return ret; |
|
- | 662 | } |
|
- | 663 | ||
- | 664 | /* |
|
- | 665 | * Bizlink designed DP->DVI-D Dual Link adapters require the I2C over AUX |
|
- | 666 | * packets to be as large as possible. If not, the I2C transactions never |
|
- | 667 | * succeed. Hence the default is maximum. |
|
- | 668 | */ |
|
- | 669 | static int dp_aux_i2c_transfer_size __read_mostly = DP_AUX_MAX_PAYLOAD_BYTES; |
|
- | 670 | module_param_unsafe(dp_aux_i2c_transfer_size, int, 0644); |
|
- | 671 | MODULE_PARM_DESC(dp_aux_i2c_transfer_size, |
|
481 | } |
672 | "Number of bytes to transfer in a single I2C over DP AUX CH message, (1-16, default 16)"); |
482 | 673 | ||
483 | static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, |
674 | static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, |
484 | int num) |
675 | int num) |
485 | { |
676 | { |
- | 677 | struct drm_dp_aux *aux = adapter->algo_data; |
|
486 | struct drm_dp_aux *aux = adapter->algo_data; |
678 | unsigned int i, j; |
487 | unsigned int i, j; |
679 | unsigned transfer_size; |
Line -... | Line 680... | ||
- | 680 | struct drm_dp_aux_msg msg; |
|
- | 681 | int err = 0; |
|
488 | struct drm_dp_aux_msg msg; |
682 | |
Line 489... | Line 683... | ||
489 | int err = 0; |
683 | dp_aux_i2c_transfer_size = clamp(dp_aux_i2c_transfer_size, 1, DP_AUX_MAX_PAYLOAD_BYTES); |
490 | 684 | ||
491 | memset(&msg, 0, sizeof(msg)); |
685 | memset(&msg, 0, sizeof(msg)); |
492 | - | ||
493 | for (i = 0; i < num; i++) { |
- | |
494 | msg.address = msgs[i].addr; |
- | |
495 | msg.request = (msgs[i].flags & I2C_M_RD) ? |
686 | |
496 | DP_AUX_I2C_READ : |
687 | for (i = 0; i < num; i++) { |
497 | DP_AUX_I2C_WRITE; |
688 | msg.address = msgs[i].addr; |
498 | msg.request |= DP_AUX_I2C_MOT; |
689 | drm_dp_i2c_msg_set_request(&msg, &msgs[i]); |
499 | /* Send a bare address packet to start the transaction. |
690 | /* Send a bare address packet to start the transaction. |
500 | * Zero sized messages specify an address only (bare |
691 | * Zero sized messages specify an address only (bare |
501 | * address) transaction. |
692 | * address) transaction. |
- | 693 | */ |
|
- | 694 | msg.buffer = NULL; |
|
- | 695 | msg.size = 0; |
|
- | 696 | err = drm_dp_i2c_do_msg(aux, &msg); |
|
- | 697 | ||
- | 698 | /* |
|
- | 699 | * Reset msg.request in case in case it got |
|
502 | */ |
700 | * changed into a WRITE_STATUS_UPDATE. |
503 | msg.buffer = NULL; |
701 | */ |
504 | msg.size = 0; |
- | |
505 | err = drm_dp_i2c_do_msg(aux, &msg); |
- | |
506 | if (err < 0) |
- | |
507 | break; |
702 | drm_dp_i2c_msg_set_request(&msg, &msgs[i]); |
508 | /* |
703 | |
509 | * Many hardware implementations support FIFOs larger than a |
704 | if (err < 0) |
510 | * single byte, but it has been empirically determined that |
705 | break; |
- | 706 | /* We want each transaction to be as large as possible, but |
|
511 | * transferring data in larger chunks can actually lead to |
707 | * we'll go to smaller sizes if the hardware gives us a |
512 | * decreased performance. Therefore each message is simply |
708 | * short reply. |
- | 709 | */ |
|
- | 710 | transfer_size = dp_aux_i2c_transfer_size; |
|
- | 711 | for (j = 0; j < msgs[i].len; j += msg.size) { |
|
- | 712 | msg.buffer = msgs[i].buf + j; |
|
- | 713 | msg.size = min(transfer_size, msgs[i].len - j); |
|
- | 714 | ||
- | 715 | err = drm_dp_i2c_drain_msg(aux, &msg); |
|
513 | * transferred byte-by-byte. |
716 | |
- | 717 | /* |
|
Line 514... | Line -... | ||
514 | */ |
- | |
515 | for (j = 0; j < msgs[i].len; j++) { |
718 | * Reset msg.request in case in case it got |
516 | msg.buffer = msgs[i].buf + j; |
719 | * changed into a WRITE_STATUS_UPDATE. |
- | 720 | */ |
|
517 | msg.size = 1; |
721 | drm_dp_i2c_msg_set_request(&msg, &msgs[i]); |
518 | 722 | ||
519 | err = drm_dp_i2c_do_msg(aux, &msg); |
723 | if (err < 0) |
520 | if (err < 0) |
724 | break; |
521 | break; |
725 | transfer_size = err; |