| .. | .. |
|---|
| 4 | 4 | * |
|---|
| 5 | 5 | * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
|---|
| 6 | 6 | */ |
|---|
| 7 | | - |
|---|
| 7 | +#include <linux/delay.h> |
|---|
| 8 | 8 | #include <linux/errno.h> |
|---|
| 9 | 9 | #include <linux/init.h> |
|---|
| 10 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 457 | 457 | |
|---|
| 458 | 458 | if (adap->transmit_in_progress) { |
|---|
| 459 | 459 | int err; |
|---|
| 460 | + /* in rk platform 400ms is enough */ |
|---|
| 461 | + int time_out_ms = 400; |
|---|
| 460 | 462 | |
|---|
| 463 | + /* poll msg only need 100ms */ |
|---|
| 464 | + if (adap->transmitting && adap->transmitting->msg.len == 1) |
|---|
| 465 | + time_out_ms = 100; |
|---|
| 461 | 466 | /* |
|---|
| 462 | 467 | * We are transmitting a message, so add a timeout |
|---|
| 463 | 468 | * to prevent the state machine to get stuck waiting |
|---|
| .. | .. |
|---|
| 471 | 476 | kthread_should_stop() || |
|---|
| 472 | 477 | (!adap->transmit_in_progress && |
|---|
| 473 | 478 | !list_empty(&adap->transmit_queue)), |
|---|
| 474 | | - msecs_to_jiffies(CEC_XFER_TIMEOUT_MS)); |
|---|
| 479 | + msecs_to_jiffies(time_out_ms)); |
|---|
| 475 | 480 | timeout = err == 0; |
|---|
| 476 | 481 | } else { |
|---|
| 477 | 482 | /* Otherwise we just wait for something to happen. */ |
|---|
| .. | .. |
|---|
| 532 | 537 | adap->transmitting = data; |
|---|
| 533 | 538 | |
|---|
| 534 | 539 | /* |
|---|
| 535 | | - * Suggested number of attempts as per the CEC 2.0 spec: |
|---|
| 536 | | - * 4 attempts is the default, except for 'secondary poll |
|---|
| 537 | | - * messages', i.e. poll messages not sent during the adapter |
|---|
| 538 | | - * configuration phase when it allocates logical addresses. |
|---|
| 540 | + * The number of retries is not set before the first sending, |
|---|
| 541 | + * but is set according to the actual sending result. |
|---|
| 539 | 542 | */ |
|---|
| 540 | | - if (data->msg.len == 1 && adap->is_configured) |
|---|
| 541 | | - attempts = 2; |
|---|
| 542 | | - else |
|---|
| 543 | | -#ifdef CONFIG_ANDROID |
|---|
| 544 | | - attempts = 1; |
|---|
| 545 | | -#else |
|---|
| 546 | | - attempts = 4; |
|---|
| 547 | | -#endif |
|---|
| 543 | + attempts = 0; |
|---|
| 544 | + |
|---|
| 548 | 545 | /* Set the suggested signal free time */ |
|---|
| 549 | 546 | if (data->attempts) { |
|---|
| 550 | 547 | /* should be >= 3 data bit periods for a retry */ |
|---|
| .. | .. |
|---|
| 610 | 607 | adap->transmit_in_progress = false; |
|---|
| 611 | 608 | goto wake_thread; |
|---|
| 612 | 609 | } |
|---|
| 610 | + |
|---|
| 611 | + if (!(status & CEC_TX_STATUS_OK)) { |
|---|
| 612 | + /* poll message is prefer to send twice */ |
|---|
| 613 | + if (nack_cnt && data->msg.len == 1) { |
|---|
| 614 | + /* first send is successful or recover from bus busy */ |
|---|
| 615 | + if (!data->attempts || data->attempts > 2) |
|---|
| 616 | + data->attempts = 2; |
|---|
| 617 | + usleep_range(200, 300); |
|---|
| 618 | + /* |
|---|
| 619 | + * If cec bus is busy, need retry. |
|---|
| 620 | + * Especially when TV wakes up STB, TV will |
|---|
| 621 | + * send cec messages then occupy cec bus. |
|---|
| 622 | + * The longest cec message takes more than 300 ms to send, |
|---|
| 623 | + * so retry in 400 ms. |
|---|
| 624 | + */ |
|---|
| 625 | + } else { |
|---|
| 626 | + if (!data->attempts) |
|---|
| 627 | + data->attempts = 200; |
|---|
| 628 | + usleep_range(2000, 2200); |
|---|
| 629 | + } |
|---|
| 630 | + } |
|---|
| 631 | + |
|---|
| 613 | 632 | adap->transmit_in_progress = false; |
|---|
| 614 | 633 | |
|---|
| 615 | 634 | msg = &data->msg; |
|---|
| .. | .. |
|---|
| 1362 | 1381 | unsigned int type = las->log_addr_type[i]; |
|---|
| 1363 | 1382 | const u8 *la_list; |
|---|
| 1364 | 1383 | u8 last_la; |
|---|
| 1384 | + const u8 invalid_log_addrs[] = { CEC_LOG_ADDR_INVALID }; |
|---|
| 1365 | 1385 | |
|---|
| 1366 | 1386 | /* |
|---|
| 1367 | 1387 | * The TV functionality can only map to physical address 0. |
|---|
| .. | .. |
|---|
| 1386 | 1406 | if (err < 0) |
|---|
| 1387 | 1407 | goto unconfigure; |
|---|
| 1388 | 1408 | |
|---|
| 1409 | + la_list = invalid_log_addrs; |
|---|
| 1410 | + |
|---|
| 1389 | 1411 | for (j = 0; la_list[j] != CEC_LOG_ADDR_INVALID; j++) { |
|---|
| 1390 | 1412 | /* Tried this one already, skip it */ |
|---|
| 1391 | 1413 | if (la_list[j] == last_la) |
|---|