forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 223293205a7265c8b02882461ba8996650048ade
kernel/drivers/media/platform/rockchip/cif/mipi-csi2.c
....@@ -15,157 +15,19 @@
1515 #include <linux/of_graph.h>
1616 #include <linux/platform_device.h>
1717 #include <linux/reset.h>
18
-#include <media/v4l2-device.h>
19
-#include <media/v4l2-fwnode.h>
20
-#include <media/v4l2-subdev.h>
21
-#include <media/v4l2-event.h>
2218 #include <linux/rk-camera-module.h>
2319 #include <media/v4l2-ioctl.h>
2420 #include "mipi-csi2.h"
21
+#include <linux/rkcif-config.h>
22
+#include <linux/regulator/consumer.h>
2523
2624 static int csi2_debug;
2725 module_param_named(debug_csi2, csi2_debug, int, 0644);
2826 MODULE_PARM_DESC(debug_csi2, "Debug level (0-1)");
2927
30
-/*
31
- * there must be 5 pads: 1 input pad from sensor, and
32
- * the 4 virtual channel output pads
33
- */
34
-#define CSI2_SINK_PAD 0
35
-#define CSI2_NUM_SINK_PADS 1
36
-#define CSI2_NUM_SRC_PADS 4
37
-#define CSI2_NUM_PADS 5
38
-#define CSI2_NUM_PADS_SINGLE_LINK 2
39
-#define MAX_CSI2_SENSORS 2
40
-
41
-#define RKCIF_DEFAULT_WIDTH 640
42
-#define RKCIF_DEFAULT_HEIGHT 480
43
-
44
-/*
45
- * The default maximum bit-rate per lane in Mbps, if the
46
- * source subdev does not provide V4L2_CID_LINK_FREQ.
47
- */
48
-#define CSI2_DEFAULT_MAX_MBPS 849
49
-
50
-#define IMX_MEDIA_GRP_ID_CSI2 BIT(8)
51
-#define CSIHOST_MAX_ERRINT_COUNT 10
52
-
53
-/*
54
- * add new chip id in tail in time order
55
- * by increasing to distinguish csi2 host version
56
- */
57
-enum rkcsi2_chip_id {
58
- CHIP_PX30_CSI2,
59
- CHIP_RK1808_CSI2,
60
- CHIP_RK3128_CSI2,
61
- CHIP_RK3288_CSI2,
62
- CHIP_RV1126_CSI2,
63
- CHIP_RK3568_CSI2,
64
-};
65
-
66
-enum csi2_pads {
67
- RK_CSI2_PAD_SINK = 0,
68
- RK_CSI2X_PAD_SOURCE0,
69
- RK_CSI2X_PAD_SOURCE1,
70
- RK_CSI2X_PAD_SOURCE2,
71
- RK_CSI2X_PAD_SOURCE3
72
-};
73
-
74
-enum csi2_err {
75
- RK_CSI2_ERR_SOTSYN = 0x0,
76
- RK_CSI2_ERR_FS_FE_MIS,
77
- RK_CSI2_ERR_FRM_SEQ_ERR,
78
- RK_CSI2_ERR_CRC_ONCE,
79
- RK_CSI2_ERR_CRC,
80
- RK_CSI2_ERR_ALL,
81
- RK_CSI2_ERR_MAX
82
-};
83
-
84
-enum host_type_t {
85
- RK_CSI_RXHOST,
86
- RK_DSI_RXHOST
87
-};
88
-
89
-struct csi2_match_data {
90
- int chip_id;
91
- int num_pads;
92
-};
93
-
94
-struct csi2_sensor {
95
- struct v4l2_subdev *sd;
96
- struct v4l2_mbus_config mbus;
97
- int lanes;
98
-};
99
-
100
-struct csi2_err_stats {
101
- unsigned int cnt;
102
-};
103
-
104
-struct csi2_dev {
105
- struct device *dev;
106
- struct v4l2_subdev sd;
107
- struct media_pad pad[CSI2_NUM_PADS];
108
- struct clk_bulk_data *clks_bulk;
109
- int clks_num;
110
- struct reset_control *rsts_bulk;
111
-
112
- void __iomem *base;
113
- struct v4l2_async_notifier notifier;
114
- struct v4l2_fwnode_bus_mipi_csi2 bus;
115
-
116
- /* lock to protect all members below */
117
- struct mutex lock;
118
-
119
- struct v4l2_mbus_framefmt format_mbus;
120
- struct v4l2_rect crop;
121
- int stream_count;
122
- struct v4l2_subdev *src_sd;
123
- bool sink_linked[CSI2_NUM_SRC_PADS];
124
- struct csi2_sensor sensors[MAX_CSI2_SENSORS];
125
- const struct csi2_match_data *match_data;
126
- int num_sensors;
127
- atomic_t frm_sync_seq;
128
- struct csi2_err_stats err_list[RK_CSI2_ERR_MAX];
129
- int dsi_input_en;
130
-};
131
-
132
-#define DEVICE_NAME "rockchip-mipi-csi2"
133
-
134
-/* CSI Host Registers Define */
135
-#define CSIHOST_N_LANES 0x04
136
-#define CSIHOST_DPHY_SHUTDOWNZ 0x08
137
-#define CSIHOST_PHY_RSTZ 0x0c
138
-#define CSIHOST_RESETN 0x10
139
-#define CSIHOST_PHY_STATE 0x14
140
-#define CSIHOST_ERR1 0x20
141
-#define CSIHOST_ERR2 0x24
142
-#define CSIHOST_MSK1 0x28
143
-#define CSIHOST_MSK2 0x2c
144
-#define CSIHOST_CONTROL 0x40
145
-
146
-#define CSIHOST_ERR1_PHYERR_SPTSYNCHS 0x0000000f
147
-#define CSIHOST_ERR1_ERR_BNDRY_MATCH 0x000000f0
148
-#define CSIHOST_ERR1_ERR_SEQ 0x00000f00
149
-#define CSIHOST_ERR1_ERR_FRM_DATA 0x0000f000
150
-#define CSIHOST_ERR1_ERR_CRC 0x1f000000
151
-
152
-#define CSIHOST_ERR2_PHYERR_ESC 0x0000000f
153
-#define CSIHOST_ERR2_PHYERR_SOTHS 0x000000f0
154
-#define CSIHOST_ERR2_ECC_CORRECTED 0x00000f00
155
-#define CSIHOST_ERR2_ERR_ID 0x0000f000
156
-#define CSIHOST_ERR2_PHYERR_CODEHS 0x01000000
157
-
158
-#define SW_CPHY_EN(x) ((x) << 0)
159
-#define SW_DSI_EN(x) ((x) << 4)
160
-#define SW_DATATYPE_FS(x) ((x) << 8)
161
-#define SW_DATATYPE_FE(x) ((x) << 14)
162
-#define SW_DATATYPE_LS(x) ((x) << 20)
163
-#define SW_DATATYPE_LE(x) ((x) << 26)
164
-
16528 #define write_csihost_reg(base, addr, val) writel(val, (addr) + (base))
16629 #define read_csihost_reg(base, addr) readl((addr) + (base))
16730
168
-static struct csi2_dev *g_csi2_dev;
16931 static ATOMIC_NOTIFIER_HEAD(g_csi_host_chain);
17032
17133 int rkcif_csi2_register_notifier(struct notifier_block *nb)
....@@ -183,7 +45,7 @@
18345 return container_of(sdev, struct csi2_dev, sd);
18446 }
18547
186
-static struct csi2_sensor *sd_to_sensor(struct csi2_dev *csi2,
48
+static struct csi2_sensor_info *sd_to_sensor(struct csi2_dev *csi2,
18749 struct v4l2_subdev *sd)
18850 {
18951 int i;
....@@ -227,6 +89,7 @@
22789 *sensor_sd = NULL;
22890 return;
22991 }
92
+
23093 media_graph_walk_start(&graph, entity);
23194 while ((entity = media_graph_walk_next(&graph))) {
23295 if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
....@@ -234,6 +97,7 @@
23497 }
23598 mutex_unlock(&mdev->graph_mutex);
23699 media_graph_walk_cleanup(&graph);
100
+
237101 if (entity)
238102 *sensor_sd = media_entity_to_v4l2_subdev(entity);
239103 else
....@@ -242,24 +106,25 @@
242106
243107 static void csi2_update_sensor_info(struct csi2_dev *csi2)
244108 {
245
- struct csi2_sensor *sensor = &csi2->sensors[0];
246109 struct v4l2_subdev *terminal_sensor_sd = NULL;
110
+ struct csi2_sensor_info *sensor = &csi2->sensors[0];
247111 struct v4l2_mbus_config mbus;
248112 int ret = 0;
249113
250
- ret = v4l2_subdev_call(sensor->sd, video, g_mbus_config, &mbus);
114
+ ret = v4l2_subdev_call(sensor->sd, pad, get_mbus_config, 0, &mbus);
251115 if (ret) {
252116 v4l2_err(&csi2->sd, "update sensor info failed!\n");
253117 return;
254118 }
255119
256120 get_remote_terminal_sensor(&csi2->sd, &terminal_sensor_sd);
257
- if (terminal_sensor_sd) {
258
- ret = v4l2_subdev_call(terminal_sensor_sd, core, ioctl,
259
- RKMODULE_GET_CSI_DSI_INFO, &csi2->dsi_input_en);
260
- if (ret)
261
- csi2->dsi_input_en = 0;
121
+ ret = v4l2_subdev_call(terminal_sensor_sd, core, ioctl,
122
+ RKMODULE_GET_CSI_DSI_INFO, &csi2->dsi_input_en);
123
+ if (ret) {
124
+ v4l2_dbg(1, csi2_debug, &csi2->sd, "get CSI/DSI sel failed, default csi!\n");
125
+ csi2->dsi_input_en = 0;
262126 }
127
+
263128 csi2->bus.flags = mbus.flags;
264129 switch (csi2->bus.flags & V4L2_MBUS_CSI2_LANES) {
265130 case V4L2_MBUS_CSI2_1_LANE:
....@@ -316,27 +181,41 @@
316181 write_csihost_reg(base, CSIHOST_MSK2, 0xffffffff);
317182 }
318183
184
+static int csi2_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
185
+ struct v4l2_mbus_config *mbus);
186
+
319187 static void csi2_enable(struct csi2_dev *csi2,
320188 enum host_type_t host_type)
321189 {
322190 void __iomem *base = csi2->base;
323191 int lanes = csi2->bus.num_data_lanes;
192
+ struct v4l2_mbus_config mbus;
193
+ u32 val = 0;
194
+
195
+ csi2_g_mbus_config(&csi2->sd, 0, &mbus);
196
+ if (mbus.type == V4L2_MBUS_CSI2_DPHY)
197
+ val = SW_CPHY_EN(0);
198
+ else if (mbus.type == V4L2_MBUS_CSI2_CPHY)
199
+ val = SW_CPHY_EN(1);
324200
325201 write_csihost_reg(base, CSIHOST_N_LANES, lanes - 1);
326202
327203 if (host_type == RK_DSI_RXHOST) {
328
- write_csihost_reg(base, CSIHOST_CONTROL,
329
- SW_CPHY_EN(0) | SW_DSI_EN(1) |
330
- SW_DATATYPE_FS(0x01) | SW_DATATYPE_FE(0x11) |
331
- SW_DATATYPE_LS(0x21) | SW_DATATYPE_LE(0x31));
204
+ val |= SW_DSI_EN(1) | SW_DATATYPE_FS(0x01) |
205
+ SW_DATATYPE_FE(0x11) | SW_DATATYPE_LS(0x21) |
206
+ SW_DATATYPE_LE(0x31);
207
+ write_csihost_reg(base, CSIHOST_CONTROL, val);
332208 /* Disable some error interrupt when HOST work on DSI RX mode */
333209 write_csihost_reg(base, CSIHOST_MSK1, 0xe00000f0);
334210 write_csihost_reg(base, CSIHOST_MSK2, 0xff00);
335211 } else {
336
- write_csihost_reg(base, CSIHOST_CONTROL,
337
- SW_CPHY_EN(0) | SW_DSI_EN(0));
338
- write_csihost_reg(base, CSIHOST_MSK1, 0);
212
+ val |= SW_DSI_EN(0) | SW_DATATYPE_FS(0x0) |
213
+ SW_DATATYPE_FE(0x01) | SW_DATATYPE_LS(0x02) |
214
+ SW_DATATYPE_LE(0x03);
215
+ write_csihost_reg(base, CSIHOST_CONTROL, val);
216
+ write_csihost_reg(base, CSIHOST_MSK1, 0x0);
339217 write_csihost_reg(base, CSIHOST_MSK2, 0xf000);
218
+ csi2->is_check_sot_sync = true;
340219 }
341220
342221 write_csihost_reg(base, CSIHOST_RESETN, 1);
....@@ -500,6 +379,7 @@
500379 csi2->crop.left = 0;
501380 csi2->crop.width = RKCIF_DEFAULT_WIDTH;
502381 csi2->crop.height = RKCIF_DEFAULT_HEIGHT;
382
+ csi2->csi_idx = 0;
503383
504384 return media_entity_pads_init(&sd->entity, num_pads, csi2->pad);
505385 }
....@@ -556,10 +436,12 @@
556436 switch (sel->target) {
557437 case V4L2_SEL_TGT_CROP_BOUNDS:
558438 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
439
+ sel->pad = 0;
559440 ret = v4l2_subdev_call(sensor, pad, get_selection,
560441 cfg, sel);
561442 if (ret) {
562443 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
444
+ fmt.pad = 0;
563445 ret = v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt);
564446 if (!ret) {
565447 csi2->format_mbus = fmt.format;
....@@ -608,16 +490,16 @@
608490 return ret;
609491 }
610492
611
-static int csi2_g_mbus_config(struct v4l2_subdev *sd,
493
+static int csi2_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
612494 struct v4l2_mbus_config *mbus)
613495 {
614496 struct csi2_dev *csi2 = sd_to_dev(sd);
615497 struct v4l2_subdev *sensor_sd = get_remote_sensor(sd);
616498 int ret;
617499
618
- ret = v4l2_subdev_call(sensor_sd, video, g_mbus_config, mbus);
500
+ ret = v4l2_subdev_call(sensor_sd, pad, get_mbus_config, 0, mbus);
619501 if (ret) {
620
- mbus->type = V4L2_MBUS_CSI2;
502
+ mbus->type = V4L2_MBUS_CSI2_DPHY;
621503 mbus->flags = csi2->bus.flags;
622504 mbus->flags |= BIT(csi2->bus.num_data_lanes - 1);
623505 }
....@@ -630,50 +512,110 @@
630512 .link_validate = v4l2_subdev_link_validate,
631513 };
632514
633
-void rkcif_csi2_event_inc_sof(void)
515
+void rkcif_csi2_event_reset_pipe(struct csi2_dev *csi2_dev, int reset_src)
634516 {
635
- if (g_csi2_dev) {
517
+ if (csi2_dev) {
636518 struct v4l2_event event = {
637
- .type = V4L2_EVENT_FRAME_SYNC,
638
- .u.frame_sync.frame_sequence =
639
- atomic_inc_return(&g_csi2_dev->frm_sync_seq) - 1,
519
+ .type = V4L2_EVENT_RESET_DEV,
520
+ .reserved[0] = reset_src,
640521 };
641
- v4l2_event_queue(g_csi2_dev->sd.devnode, &event);
522
+ v4l2_event_queue(csi2_dev->sd.devnode, &event);
642523 }
643524 }
644525
645
-u32 rkcif_csi2_get_sof(void)
526
+void rkcif_csi2_event_inc_sof(struct csi2_dev *csi2_dev)
646527 {
647
- if (g_csi2_dev) {
648
- return atomic_read(&g_csi2_dev->frm_sync_seq) - 1;
528
+ if (csi2_dev) {
529
+ struct v4l2_event event = {
530
+ .type = V4L2_EVENT_FRAME_SYNC,
531
+ .u.frame_sync.frame_sequence =
532
+ atomic_inc_return(&csi2_dev->frm_sync_seq) - 1,
533
+ };
534
+ v4l2_event_queue(csi2_dev->sd.devnode, &event);
649535 }
536
+}
537
+
538
+u32 rkcif_csi2_get_sof(struct csi2_dev *csi2_dev)
539
+{
540
+ if (csi2_dev)
541
+ return atomic_read(&csi2_dev->frm_sync_seq) - 1;
650542
651543 return 0;
652544 }
653545
654
-void rkcif_csi2_set_sof(u32 seq)
546
+void rkcif_csi2_set_sof(struct csi2_dev *csi2_dev, u32 seq)
655547 {
656
- if (g_csi2_dev) {
657
- atomic_set(&g_csi2_dev->frm_sync_seq, seq);
658
- }
548
+ if (csi2_dev)
549
+ atomic_set(&csi2_dev->frm_sync_seq, seq);
659550 }
660551
661552 static int rkcif_csi2_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
662553 struct v4l2_event_subscription *sub)
663554 {
664
- if (sub->type != V4L2_EVENT_FRAME_SYNC)
555
+ if (sub->type == V4L2_EVENT_FRAME_SYNC ||
556
+ sub->type == V4L2_EVENT_RESET_DEV)
557
+ return v4l2_event_subscribe(fh, sub, RKCIF_V4L2_EVENT_ELEMS, NULL);
558
+ else
665559 return -EINVAL;
666
-
667
- return v4l2_event_subscribe(fh, sub, 0, NULL);
668560 }
561
+
562
+static int rkcif_csi2_s_power(struct v4l2_subdev *sd, int on)
563
+{
564
+ return 0;
565
+}
566
+
567
+static long rkcif_csi2_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
568
+{
569
+ struct csi2_dev *csi2 = sd_to_dev(sd);
570
+ long ret = 0;
571
+
572
+ switch (cmd) {
573
+ case RKCIF_CMD_SET_CSI_IDX:
574
+ csi2->csi_idx = *((u32 *)arg);
575
+ break;
576
+ default:
577
+ ret = -ENOIOCTLCMD;
578
+ break;
579
+ }
580
+
581
+ return ret;
582
+}
583
+
584
+#ifdef CONFIG_COMPAT
585
+static long rkcif_csi2_compat_ioctl32(struct v4l2_subdev *sd,
586
+ unsigned int cmd, unsigned long arg)
587
+{
588
+ void __user *up = compat_ptr(arg);
589
+ u32 csi_idx = 0;
590
+ long ret;
591
+
592
+ switch (cmd) {
593
+ case RKCIF_CMD_SET_CSI_IDX:
594
+ if (copy_from_user(&csi_idx, up, sizeof(u32)))
595
+ return -EFAULT;
596
+
597
+ ret = rkcif_csi2_ioctl(sd, cmd, &csi_idx);
598
+ break;
599
+ default:
600
+ ret = -ENOIOCTLCMD;
601
+ break;
602
+ }
603
+
604
+ return ret;
605
+}
606
+#endif
669607
670608 static const struct v4l2_subdev_core_ops csi2_core_ops = {
671609 .subscribe_event = rkcif_csi2_subscribe_event,
672610 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
611
+ .s_power = rkcif_csi2_s_power,
612
+ .ioctl = rkcif_csi2_ioctl,
613
+#ifdef CONFIG_COMPAT
614
+ .compat_ioctl32 = rkcif_csi2_compat_ioctl32,
615
+#endif
673616 };
674617
675618 static const struct v4l2_subdev_video_ops csi2_video_ops = {
676
- .g_mbus_config = csi2_g_mbus_config,
677619 .s_stream = csi2_s_stream,
678620 };
679621
....@@ -682,6 +624,7 @@
682624 .set_fmt = csi2_get_set_fmt,
683625 .get_selection = csi2_get_selection,
684626 .set_selection = csi2_set_selection,
627
+ .get_mbus_config = csi2_g_mbus_config,
685628 };
686629
687630 static const struct v4l2_subdev_ops csi2_subdev_ops = {
....@@ -716,7 +659,7 @@
716659 struct csi2_dev *csi2 = container_of(notifier,
717660 struct csi2_dev,
718661 notifier);
719
- struct csi2_sensor *sensor;
662
+ struct csi2_sensor_info *sensor;
720663 struct media_link *link;
721664 unsigned int pad, ret;
722665
....@@ -772,10 +715,10 @@
772715 struct csi2_dev *csi2 = container_of(notifier,
773716 struct csi2_dev,
774717 notifier);
775
- struct csi2_sensor *sensor = sd_to_sensor(csi2, sd);
718
+ struct csi2_sensor_info *sensor = sd_to_sensor(csi2, sd);
776719
777
- sensor->sd = NULL;
778
-
720
+ if (sensor)
721
+ sensor->sd = NULL;
779722 }
780723
781724 static const struct
....@@ -784,6 +727,25 @@
784727 .unbind = csi2_notifier_unbind,
785728 };
786729
730
+static void csi2_find_err_vc(int val, char *vc_info)
731
+{
732
+ int i;
733
+ char cur_str[CSI_VCINFO_LEN] = {0};
734
+
735
+ memset(vc_info, 0, sizeof(*vc_info));
736
+ for (i = 0; i < 4; i++) {
737
+ if ((val >> i) & 0x1) {
738
+ snprintf(cur_str, CSI_VCINFO_LEN, " %d", i);
739
+ if (strlen(vc_info) + strlen(cur_str) < CSI_VCINFO_LEN)
740
+ strncat(vc_info, cur_str, strlen(cur_str));
741
+ }
742
+ }
743
+}
744
+
745
+#define csi2_err_strncat(dst_str, src_str) {\
746
+ if (strlen(dst_str) + strlen(src_str) < CSI_ERRSTR_LEN)\
747
+ strncat(dst_str, src_str, strlen(src_str)); }
748
+
787749 static irqreturn_t rk_csirx_irq1_handler(int irq, void *ctx)
788750 {
789751 struct device *dev = ctx;
....@@ -791,58 +753,96 @@
791753 struct csi2_err_stats *err_list = NULL;
792754 unsigned long err_stat = 0;
793755 u32 val;
756
+ char err_str[CSI_ERRSTR_LEN] = {0};
757
+ char cur_str[CSI_ERRSTR_LEN] = {0};
758
+ char vc_info[CSI_VCINFO_LEN] = {0};
759
+ bool is_add_cnt = false;
794760
795761 val = read_csihost_reg(csi2->base, CSIHOST_ERR1);
796762 if (val) {
797
- write_csihost_reg(csi2->base,
798
- CSIHOST_ERR1, 0x0);
799
-
800763 if (val & CSIHOST_ERR1_PHYERR_SPTSYNCHS) {
801764 err_list = &csi2->err_list[RK_CSI2_ERR_SOTSYN];
802765 err_list->cnt++;
803
- v4l2_err(&csi2->sd,
804
- "ERR1: start of transmission error(no synchronization achieved), reg: 0x%x,cnt:%d\n",
805
- val, err_list->cnt);
766
+ if (csi2->match_data->chip_id == CHIP_RK3588_CSI2) {
767
+ if (err_list->cnt > 3 &&
768
+ csi2->err_list[RK_CSI2_ERR_ALL].cnt <= err_list->cnt) {
769
+ csi2->is_check_sot_sync = false;
770
+ write_csihost_reg(csi2->base, CSIHOST_MSK1, 0xf);
771
+ }
772
+ if (csi2->is_check_sot_sync) {
773
+ csi2_find_err_vc(val & 0xf, vc_info);
774
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(sot sync,lane:%s) ", vc_info);
775
+ csi2_err_strncat(err_str, cur_str);
776
+ }
777
+ } else {
778
+ csi2_find_err_vc(val & 0xf, vc_info);
779
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(sot sync,lane:%s) ", vc_info);
780
+ csi2_err_strncat(err_str, cur_str);
781
+ is_add_cnt = true;
782
+ }
806783 }
807784
808785 if (val & CSIHOST_ERR1_ERR_BNDRY_MATCH) {
809786 err_list = &csi2->err_list[RK_CSI2_ERR_FS_FE_MIS];
810787 err_list->cnt++;
811
- v4l2_err(&csi2->sd,
812
- "ERR1: error matching frame start with frame end, reg: 0x%x,cnt:%d\n",
813
- val, err_list->cnt);
788
+ csi2_find_err_vc((val >> 4) & 0xf, vc_info);
789
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(fs/fe mis,vc:%s) ", vc_info);
790
+ csi2_err_strncat(err_str, cur_str);
791
+ if (csi2->match_data->chip_id < CHIP_RK3588_CSI2)
792
+ is_add_cnt = true;
814793 }
815794
816795 if (val & CSIHOST_ERR1_ERR_SEQ) {
817796 err_list = &csi2->err_list[RK_CSI2_ERR_FRM_SEQ_ERR];
818797 err_list->cnt++;
819
- v4l2_err(&csi2->sd,
820
- "ERR1: incorrect frame sequence detected, reg: 0x%x,cnt:%d\n",
821
- val, err_list->cnt);
798
+ csi2_find_err_vc((val >> 8) & 0xf, vc_info);
799
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(f_seq,vc:%s) ", vc_info);
800
+ csi2_err_strncat(err_str, cur_str);
822801 }
823802
824803 if (val & CSIHOST_ERR1_ERR_FRM_DATA) {
825804 err_list = &csi2->err_list[RK_CSI2_ERR_CRC_ONCE];
805
+ is_add_cnt = true;
826806 err_list->cnt++;
827
- v4l2_dbg(1, csi2_debug, &csi2->sd,
828
- "ERR1: at least one crc error, reg: 0x%x\n,cnt:%d", val, err_list->cnt);
807
+ csi2_find_err_vc((val >> 12) & 0xf, vc_info);
808
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err_data,vc:%s) ", vc_info);
809
+ csi2_err_strncat(err_str, cur_str);
829810 }
830811
831812 if (val & CSIHOST_ERR1_ERR_CRC) {
832813 err_list = &csi2->err_list[RK_CSI2_ERR_CRC];
833814 err_list->cnt++;
834
- v4l2_err(&csi2->sd,
835
- "ERR1: crc errors, reg: 0x%x, cnt:%d\n",
836
- val, err_list->cnt);
815
+ is_add_cnt = true;
816
+ csi2_find_err_vc((val >> 24) & 0xf, vc_info);
817
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(crc,vc:%s) ", vc_info);
818
+ csi2_err_strncat(err_str, cur_str);
837819 }
838820
839
- csi2->err_list[RK_CSI2_ERR_ALL].cnt++;
840
- err_stat = ((csi2->err_list[RK_CSI2_ERR_FS_FE_MIS].cnt & 0xff) << 8) |
841
- ((csi2->err_list[RK_CSI2_ERR_ALL].cnt) & 0xff);
821
+ if (val & CSIHOST_ERR1_ERR_ECC2) {
822
+ err_list = &csi2->err_list[RK_CSI2_ERR_CRC];
823
+ err_list->cnt++;
824
+ is_add_cnt = true;
825
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc2) ");
826
+ csi2_err_strncat(err_str, cur_str);
827
+ }
842828
843
- atomic_notifier_call_chain(&g_csi_host_chain,
844
- err_stat,
845
- NULL);
829
+ if (val & CSIHOST_ERR1_ERR_CTRL) {
830
+ csi2_find_err_vc((val >> 16) & 0xf, vc_info);
831
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ctrl,vc:%s) ", vc_info);
832
+ csi2_err_strncat(err_str, cur_str);
833
+ }
834
+
835
+ pr_err("%s ERR1:0x%x %s\n", csi2->dev_name, val, err_str);
836
+
837
+ if (is_add_cnt) {
838
+ csi2->err_list[RK_CSI2_ERR_ALL].cnt++;
839
+ err_stat = ((csi2->err_list[RK_CSI2_ERR_FS_FE_MIS].cnt & 0xff) << 8) |
840
+ ((csi2->err_list[RK_CSI2_ERR_ALL].cnt) & 0xff);
841
+
842
+ atomic_notifier_call_chain(&g_csi_host_chain,
843
+ err_stat,
844
+ &csi2->csi_idx);
845
+ }
846846
847847 }
848848
....@@ -854,25 +854,38 @@
854854 struct device *dev = ctx;
855855 struct csi2_dev *csi2 = sd_to_dev(dev_get_drvdata(dev));
856856 u32 val;
857
+ char cur_str[CSI_ERRSTR_LEN] = {0};
858
+ char err_str[CSI_ERRSTR_LEN] = {0};
859
+ char vc_info[CSI_VCINFO_LEN] = {0};
857860
858861 val = read_csihost_reg(csi2->base, CSIHOST_ERR2);
859862 if (val) {
860
- if (val & CSIHOST_ERR2_PHYERR_ESC)
861
- v4l2_err(&csi2->sd, "ERR2: escape entry error(ULPM), reg: 0x%x\n", val);
862
- if (val & CSIHOST_ERR2_PHYERR_SOTHS)
863
- v4l2_err(&csi2->sd,
864
- "ERR2: start of transmission error(synchronization can still be achieved), reg: 0x%x\n",
865
- val);
866
- if (val & CSIHOST_ERR2_ECC_CORRECTED)
867
- v4l2_dbg(1, csi2_debug, &csi2->sd,
868
- "ERR2: header error detected and corrected, reg: 0x%x\n",
869
- val);
870
- if (val & CSIHOST_ERR2_ERR_ID)
871
- v4l2_err(&csi2->sd,
872
- "ERR2: unrecognized or unimplemented data type detected, reg: 0x%x\n",
873
- val);
874
- if (val & CSIHOST_ERR2_PHYERR_CODEHS)
875
- v4l2_err(&csi2->sd, "ERR2: receiv error code, reg: 0x%x\n", val);
863
+ if (val & CSIHOST_ERR2_PHYERR_ESC) {
864
+ csi2_find_err_vc(val & 0xf, vc_info);
865
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ULPM,lane:%s) ", vc_info);
866
+ csi2_err_strncat(err_str, cur_str);
867
+ }
868
+ if (val & CSIHOST_ERR2_PHYERR_SOTHS) {
869
+ csi2_find_err_vc((val >> 4) & 0xf, vc_info);
870
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(sot,lane:%s) ", vc_info);
871
+ csi2_err_strncat(err_str, cur_str);
872
+ }
873
+ if (val & CSIHOST_ERR2_ECC_CORRECTED) {
874
+ csi2_find_err_vc((val >> 8) & 0xf, vc_info);
875
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc,vc:%s) ", vc_info);
876
+ csi2_err_strncat(err_str, cur_str);
877
+ }
878
+ if (val & CSIHOST_ERR2_ERR_ID) {
879
+ csi2_find_err_vc((val >> 12) & 0xf, vc_info);
880
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err id,vc:%s) ", vc_info);
881
+ csi2_err_strncat(err_str, cur_str);
882
+ }
883
+ if (val & CSIHOST_ERR2_PHYERR_CODEHS) {
884
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err code) ");
885
+ csi2_err_strncat(err_str, cur_str);
886
+ }
887
+
888
+ pr_err("%s ERR2:0x%x %s\n", csi2->dev_name, val, err_str);
876889 }
877890
878891 return IRQ_HANDLED;
....@@ -883,15 +896,14 @@
883896 struct v4l2_async_notifier *ntf = &csi2->notifier;
884897 int ret;
885898
899
+ v4l2_async_notifier_init(ntf);
900
+
886901 ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(csi2->dev,
887902 &csi2->notifier,
888903 sizeof(struct v4l2_async_subdev), 0,
889904 csi2_parse_endpoint);
890905 if (ret < 0)
891906 return ret;
892
-
893
- if (!ntf->num_subdevs)
894
- return -ENODEV; /* no endpoint */
895907
896908 csi2->sd.subdev_notifier = &csi2->notifier;
897909 csi2->notifier.ops = &csi2_async_ops;
....@@ -929,6 +941,16 @@
929941 .num_pads = CSI2_NUM_PADS,
930942 };
931943
944
+static const struct csi2_match_data rk3588_csi2_match_data = {
945
+ .chip_id = CHIP_RK3588_CSI2,
946
+ .num_pads = CSI2_NUM_PADS_MAX,
947
+};
948
+
949
+static const struct csi2_match_data rk3562_csi2_match_data = {
950
+ .chip_id = CHIP_RK3562_CSI2,
951
+ .num_pads = CSI2_NUM_PADS_MAX,
952
+};
953
+
932954 static const struct of_device_id csi2_dt_ids[] = {
933955 {
934956 .compatible = "rockchip,rk1808-mipi-csi2",
....@@ -945,6 +967,14 @@
945967 {
946968 .compatible = "rockchip,rv1126-mipi-csi2",
947969 .data = &rv1126_csi2_match_data,
970
+ },
971
+ {
972
+ .compatible = "rockchip,rk3588-mipi-csi2",
973
+ .data = &rk3588_csi2_match_data,
974
+ },
975
+ {
976
+ .compatible = "rockchip,rk3562-mipi-csi2",
977
+ .data = &rk3562_csi2_match_data,
948978 },
949979 { /* sentinel */ }
950980 };
....@@ -972,6 +1002,7 @@
9721002 csi2->dev = &pdev->dev;
9731003 csi2->match_data = data;
9741004
1005
+ csi2->dev_name = node->name;
9751006 v4l2_subdev_init(&csi2->sd, &csi2_subdev_ops);
9761007 v4l2_set_subdevdata(&csi2->sd, &pdev->dev);
9771008 csi2->sd.entity.ops = &csi2_entity_ops;
....@@ -984,14 +1015,16 @@
9841015 platform_set_drvdata(pdev, &csi2->sd);
9851016
9861017 csi2->clks_num = devm_clk_bulk_get_all(dev, &csi2->clks_bulk);
987
- if (csi2->clks_num < 0)
1018
+ if (csi2->clks_num < 0) {
1019
+ csi2->clks_num = 0;
9881020 dev_err(dev, "failed to get csi2 clks\n");
1021
+ }
9891022
9901023 csi2->rsts_bulk = devm_reset_control_array_get_optional_exclusive(dev);
9911024 if (IS_ERR(csi2->rsts_bulk)) {
9921025 if (PTR_ERR(csi2->rsts_bulk) != -EPROBE_DEFER)
9931026 dev_err(dev, "failed to get csi2 reset\n");
994
- return PTR_ERR(csi2->rsts_bulk);
1027
+ csi2->rsts_bulk = NULL;
9951028 }
9961029
9971030 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
....@@ -1019,6 +1052,7 @@
10191052 if (ret < 0)
10201053 v4l2_err(&csi2->sd, "request csi-intr1 irq failed: %d\n",
10211054 ret);
1055
+ csi2->irq1 = irq;
10221056 } else {
10231057 v4l2_err(&csi2->sd, "No found irq csi-intr1\n");
10241058 }
....@@ -1032,6 +1066,7 @@
10321066 if (ret < 0)
10331067 v4l2_err(&csi2->sd, "request csi-intr2 failed: %d\n",
10341068 ret);
1069
+ csi2->irq2 = irq;
10351070 } else {
10361071 v4l2_err(&csi2->sd, "No found irq csi-intr2\n");
10371072 }
....@@ -1044,10 +1079,6 @@
10441079 ret = csi2_notifier(csi2);
10451080 if (ret)
10461081 goto rmmutex;
1047
-
1048
- csi2_hw_do_reset(csi2);
1049
-
1050
- g_csi2_dev = csi2;
10511082
10521083 v4l2_info(&csi2->sd, "probe success, v4l2_dev:%s!\n", csi2->sd.v4l2_dev->name);
10531084
....@@ -1079,7 +1110,7 @@
10791110 .remove = csi2_remove,
10801111 };
10811112
1082
-int __init rkcif_csi2_plat_drv_init(void)
1113
+int rkcif_csi2_plat_drv_init(void)
10831114 {
10841115 return platform_driver_register(&csi2_driver);
10851116 }