hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/media/platform/rockchip/hdmirx/rk_hdmirx.c
....@@ -45,11 +45,11 @@
4545 #include <media/videobuf2-v4l2.h>
4646 #include <soc/rockchip/rockchip-system-status.h>
4747 #include <sound/hdmi-codec.h>
48
+#include <linux/rk_hdmirx_class.h>
4849 #include "rk_hdmirx.h"
4950 #include "rk_hdmirx_cec.h"
5051 #include "rk_hdmirx_hdcp.h"
5152
52
-static struct class *hdmirx_class;
5353 static int debug;
5454 module_param(debug, int, 0644);
5555 MODULE_PARM_DESC(debug, "debug level (0-3)");
....@@ -269,6 +269,7 @@
269269 static void hdmirx_cancel_cpu_limit_freq(struct rk_hdmirx_dev *hdmirx_dev);
270270 static void hdmirx_plugout(struct rk_hdmirx_dev *hdmirx_dev);
271271 static void process_signal_change(struct rk_hdmirx_dev *hdmirx_dev);
272
+static void hdmirx_interrupts_setup(struct rk_hdmirx_dev *hdmirx_dev, bool en);
272273
273274 static u8 edid_init_data_340M[] = {
274275 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
....@@ -529,6 +530,16 @@
529530 struct v4l2_device *v4l2_dev = &hdmirx_dev->v4l2_dev;
530531 u32 dma_cfg1;
531532
533
+ if (port_no_link(hdmirx_dev)) {
534
+ v4l2_err(v4l2_dev, "%s port has no link!\n", __func__);
535
+ return -ENOLINK;
536
+ }
537
+
538
+ if (signal_not_lock(hdmirx_dev)) {
539
+ v4l2_err(v4l2_dev, "%s signal is not locked!\n", __func__);
540
+ return -ENOLCK;
541
+ }
542
+
532543 *timings = hdmirx_dev->timings;
533544 dma_cfg1 = hdmirx_readl(hdmirx_dev, DMA_CONFIG1);
534545 v4l2_dbg(1, debug, v4l2_dev, "%s: pix_fmt: %s, DMA_CONFIG1:%#x\n",
....@@ -615,8 +626,10 @@
615626 static void hdmirx_get_pix_fmt(struct rk_hdmirx_dev *hdmirx_dev)
616627 {
617628 u32 val;
629
+ int timeout = 10;
618630 struct v4l2_device *v4l2_dev = &hdmirx_dev->v4l2_dev;
619631
632
+try_loop:
620633 val = hdmirx_readl(hdmirx_dev, DMA_STATUS11);
621634 hdmirx_dev->pix_fmt = val & HDMIRX_FORMAT_MASK;
622635
....@@ -635,11 +648,16 @@
635648 break;
636649
637650 default:
651
+ if (timeout-- > 0) {
652
+ usleep_range(200 * 1000, 200 * 1010);
653
+ v4l2_err(v4l2_dev, "%s: get format failed, read again!\n", __func__);
654
+ goto try_loop;
655
+ }
656
+ hdmirx_dev->pix_fmt = HDMIRX_RGB888;
657
+ hdmirx_dev->cur_fmt_fourcc = V4L2_PIX_FMT_BGR24;
638658 v4l2_err(v4l2_dev,
639659 "%s: err pix_fmt: %d, set RGB888 as default\n",
640660 __func__, hdmirx_dev->pix_fmt);
641
- hdmirx_dev->pix_fmt = HDMIRX_RGB888;
642
- hdmirx_dev->cur_fmt_fourcc = V4L2_PIX_FMT_BGR24;
643661 break;
644662 }
645663
....@@ -880,9 +898,12 @@
880898 struct v4l2_device *v4l2_dev = &hdmirx_dev->v4l2_dev;
881899 u32 last_w, last_h;
882900 struct v4l2_bt_timings *bt = &timings->bt;
901
+ enum hdmirx_pix_fmt last_fmt;
883902
884903 last_w = 0;
885904 last_h = 0;
905
+ last_fmt = HDMIRX_RGB888;
906
+
886907 for (i = 0; i < try_cnt; i++) {
887908 ret = hdmirx_get_detected_timings(hdmirx_dev, timings, from_dma);
888909
....@@ -891,7 +912,8 @@
891912 last_h = bt->height;
892913 }
893914
894
- if (ret || (last_w != bt->width) || (last_h != bt->height))
915
+ if (ret || (last_w != bt->width) || (last_h != bt->height)
916
+ || (last_fmt != hdmirx_dev->pix_fmt))
895917 cnt = 0;
896918 else
897919 cnt++;
....@@ -901,6 +923,7 @@
901923
902924 last_w = bt->width;
903925 last_h = bt->height;
926
+ last_fmt = hdmirx_dev->pix_fmt;
904927 usleep_range(10*1000, 10*1100);
905928 }
906929
....@@ -1545,7 +1568,7 @@
15451568 }
15461569
15471570 hdmirx_reset_dma(hdmirx_dev);
1548
- usleep_range(200*1000, 200*1010);
1571
+ usleep_range(500*1000, 500*1010);
15491572 hdmirx_format_change(hdmirx_dev);
15501573
15511574 return 0;
....@@ -2349,6 +2372,7 @@
23492372 FIFO_UNDERFLOW_INT_EN |
23502373 HDMIRX_AXI_ERROR_INT_EN, 0);
23512374 hdmirx_reset_dma(hdmirx_dev);
2375
+ hdmirx_interrupts_setup(hdmirx_dev, false);
23522376 v4l2_event_queue(&stream->vdev, &evt_signal_lost);
23532377 if (hdmirx_dev->hdcp && hdmirx_dev->hdcp->hdcp_stop)
23542378 hdmirx_dev->hdcp->hdcp_stop(hdmirx_dev->hdcp);
....@@ -2459,13 +2483,28 @@
24592483 hdmirx_writel(hdmirx_dev, MAINUNIT_2_INT_FORCE, 0x0);
24602484 }
24612485
2486
+/*
2487
+ * In the normal preview, some scenarios will trigger the change interrupt
2488
+ * by mistake, and the trigger source of the interrupt needs to be detected
2489
+ * to avoid the problem.
2490
+ */
24622491 static void pkt_0_int_handler(struct rk_hdmirx_dev *hdmirx_dev,
24632492 int status, bool *handled)
24642493 {
24652494 struct v4l2_device *v4l2_dev = &hdmirx_dev->v4l2_dev;
2495
+ u32 pre_fmt_fourcc = hdmirx_dev->cur_fmt_fourcc;
2496
+ u32 pre_color_range = hdmirx_dev->cur_color_range;
2497
+ u32 pre_color_space = hdmirx_dev->cur_color_space;
24662498
24672499 if ((status & PKTDEC_AVIIF_CHG_IRQ)) {
2468
- process_signal_change(hdmirx_dev);
2500
+ hdmirx_get_color_range(hdmirx_dev);
2501
+ hdmirx_get_color_space(hdmirx_dev);
2502
+ hdmirx_get_pix_fmt(hdmirx_dev);
2503
+ if (hdmirx_dev->cur_fmt_fourcc != pre_fmt_fourcc ||
2504
+ hdmirx_dev->cur_color_range != pre_color_range ||
2505
+ hdmirx_dev->cur_color_space != pre_color_space) {
2506
+ process_signal_change(hdmirx_dev);
2507
+ }
24692508 v4l2_dbg(2, debug, v4l2_dev, "%s: ptk0_st:%#x\n",
24702509 __func__, status);
24712510 *handled = true;
....@@ -3158,7 +3197,7 @@
31583197 struct rk_hdmirx_dev,
31593198 delayed_work_audio);
31603199 struct hdmirx_audiostate *as = &hdmirx_dev->audio_state;
3161
- u32 fs_audio, ch_audio;
3200
+ u32 fs_audio, ch_audio, sample_flat;
31623201 int cur_state, init_state, pre_state, fifo_status2;
31633202 unsigned long delay = 200;
31643203
....@@ -3223,6 +3262,10 @@
32233262 }
32243263 }
32253264 as->pre_state = cur_state;
3265
+
3266
+ sample_flat = hdmirx_readl(hdmirx_dev, AUDIO_PROC_STATUS1) & AUD_SAMPLE_FLAT;
3267
+ hdmirx_update_bits(hdmirx_dev, AUDIO_PROC_CONFIG0, I2S_EN, sample_flat ? 0 : I2S_EN);
3268
+
32263269 exit:
32273270 schedule_delayed_work_on(hdmirx_dev->bound_cpu,
32283271 &hdmirx_dev->delayed_work_audio,
....@@ -3243,7 +3286,6 @@
32433286 plugin = tx_5v_power_present(hdmirx_dev);
32443287 v4l2_dbg(1, debug, v4l2_dev, "%s: plugin:%d\n", __func__, plugin);
32453288 if (plugin) {
3246
- hdmirx_interrupts_setup(hdmirx_dev, false);
32473289 hdmirx_submodule_init(hdmirx_dev);
32483290 hdmirx_update_bits(hdmirx_dev, SCDC_CONFIG, POWERPROVIDED,
32493291 POWERPROVIDED);
....@@ -4280,7 +4322,7 @@
42804322 if (ret)
42814323 goto err_unreg_video_dev;
42824324
4283
- hdmirx_dev->classdev = device_create_with_groups(hdmirx_class,
4325
+ hdmirx_dev->classdev = device_create_with_groups(rk_hdmirx_class(),
42844326 dev, MKDEV(0, 0),
42854327 hdmirx_dev,
42864328 hdmirx_groups,
....@@ -4438,9 +4480,6 @@
44384480
44394481 static int __init hdmirx_init(void)
44404482 {
4441
- hdmirx_class = class_create(THIS_MODULE, "hdmirx");
4442
- if (IS_ERR(hdmirx_class))
4443
- return PTR_ERR(hdmirx_class);
44444483 return platform_driver_register(&hdmirx_driver);
44454484 }
44464485 module_init(hdmirx_init);
....@@ -4448,7 +4487,6 @@
44484487 static void __exit hdmirx_exit(void)
44494488 {
44504489 platform_driver_unregister(&hdmirx_driver);
4451
- class_destroy(hdmirx_class);
44524490 }
44534491 module_exit(hdmirx_exit);
44544492