hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/media/cec/cec-adap.c
....@@ -4,7 +4,7 @@
44 *
55 * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
66 */
7
-
7
+#include <linux/delay.h>
88 #include <linux/errno.h>
99 #include <linux/init.h>
1010 #include <linux/module.h>
....@@ -457,7 +457,12 @@
457457
458458 if (adap->transmit_in_progress) {
459459 int err;
460
+ /* in rk platform 400ms is enough */
461
+ int time_out_ms = 400;
460462
463
+ /* poll msg only need 100ms */
464
+ if (adap->transmitting && adap->transmitting->msg.len == 1)
465
+ time_out_ms = 100;
461466 /*
462467 * We are transmitting a message, so add a timeout
463468 * to prevent the state machine to get stuck waiting
....@@ -471,7 +476,7 @@
471476 kthread_should_stop() ||
472477 (!adap->transmit_in_progress &&
473478 !list_empty(&adap->transmit_queue)),
474
- msecs_to_jiffies(CEC_XFER_TIMEOUT_MS));
479
+ msecs_to_jiffies(time_out_ms));
475480 timeout = err == 0;
476481 } else {
477482 /* Otherwise we just wait for something to happen. */
....@@ -532,19 +537,11 @@
532537 adap->transmitting = data;
533538
534539 /*
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.
539542 */
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
+
548545 /* Set the suggested signal free time */
549546 if (data->attempts) {
550547 /* should be >= 3 data bit periods for a retry */
....@@ -610,6 +607,28 @@
610607 adap->transmit_in_progress = false;
611608 goto wake_thread;
612609 }
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
+
613632 adap->transmit_in_progress = false;
614633
615634 msg = &data->msg;
....@@ -1362,6 +1381,7 @@
13621381 unsigned int type = las->log_addr_type[i];
13631382 const u8 *la_list;
13641383 u8 last_la;
1384
+ const u8 invalid_log_addrs[] = { CEC_LOG_ADDR_INVALID };
13651385
13661386 /*
13671387 * The TV functionality can only map to physical address 0.
....@@ -1386,6 +1406,8 @@
13861406 if (err < 0)
13871407 goto unconfigure;
13881408
1409
+ la_list = invalid_log_addrs;
1410
+
13891411 for (j = 0; la_list[j] != CEC_LOG_ADDR_INVALID; j++) {
13901412 /* Tried this one already, skip it */
13911413 if (la_list[j] == last_la)