forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/media/platform/rockchip/cif/dev.c
....@@ -26,6 +26,10 @@
2626 #include <linux/mfd/syscon.h>
2727 #include "dev.h"
2828 #include "procfs.h"
29
+#include <linux/kthread.h>
30
+#include "../../../../phy/rockchip/phy-rockchip-csi2-dphy-common.h"
31
+#include <linux/of_reserved_mem.h>
32
+#include <linux/of_address.h>
2933
3034 #define RKCIF_VERNO_LEN 10
3135
....@@ -92,6 +96,9 @@
9296 return len;
9397 }
9498
99
+static DEVICE_ATTR(compact_test, S_IWUSR | S_IRUSR,
100
+ rkcif_show_compact_mode, rkcif_store_compact_mode);
101
+
95102 static ssize_t rkcif_show_line_int_num(struct device *dev,
96103 struct device_attribute *attr,
97104 char *buf)
....@@ -109,9 +116,15 @@
109116 const char *buf, size_t len)
110117 {
111118 struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
119
+ struct sditf_priv *priv = cif_dev->sditf[0];
112120 int val = 0;
113121 int ret = 0;
114122
123
+ if (priv && priv->mode.rdbk_mode == RKISP_VICAP_ONLINE) {
124
+ dev_info(cif_dev->dev,
125
+ "current mode is on the fly, wake up mode wouldn't used\n");
126
+ return len;
127
+ }
115128 ret = kstrtoint(buf, 0, &val);
116129 if (!ret && val >= 0 && val <= 0x3fff)
117130 cif_dev->wait_line_cache = val;
....@@ -119,6 +132,9 @@
119132 dev_info(cif_dev->dev, "set line int num failed\n");
120133 return len;
121134 }
135
+
136
+static DEVICE_ATTR(wait_line, S_IWUSR | S_IRUSR,
137
+ rkcif_show_line_int_num, rkcif_store_line_int_num);
122138
123139 static ssize_t rkcif_show_dummybuf_mode(struct device *dev,
124140 struct device_attribute *attr,
....@@ -152,8 +168,11 @@
152168 return len;
153169 }
154170
155
-/* show the compact mode of each stream in stream index order,
156
- * 1 for compact, 0 for 16bit
171
+static DEVICE_ATTR(is_use_dummybuf, S_IWUSR | S_IRUSR,
172
+ rkcif_show_dummybuf_mode, rkcif_store_dummybuf_mode);
173
+
174
+/* show the memory mode of each stream in stream index order,
175
+ * 1 for high align, 0 for low align
157176 */
158177 static ssize_t rkcif_show_memory_mode(struct device *dev,
159178 struct device_attribute *attr,
....@@ -210,24 +229,388 @@
210229 return len;
211230 }
212231
213
-static DEVICE_ATTR(compact_test, S_IWUSR | S_IRUSR,
214
- rkcif_show_compact_mode, rkcif_store_compact_mode);
215
-
216
-static DEVICE_ATTR(wait_line, S_IWUSR | S_IRUSR,
217
- rkcif_show_line_int_num, rkcif_store_line_int_num);
218
-
219
-static DEVICE_ATTR(is_use_dummybuf, S_IWUSR | S_IRUSR,
220
- rkcif_show_dummybuf_mode, rkcif_store_dummybuf_mode);
221
-
222232 static DEVICE_ATTR(is_high_align, S_IWUSR | S_IRUSR,
223233 rkcif_show_memory_mode, rkcif_store_memory_mode);
224234
235
+static ssize_t rkcif_show_scale_ch0_blc(struct device *dev,
236
+ struct device_attribute *attr,
237
+ char *buf)
238
+{
239
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
240
+ int ret;
241
+
242
+ ret = snprintf(buf, PAGE_SIZE, "ch0 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
243
+ cif_dev->scale_vdev[0].blc.pattern00,
244
+ cif_dev->scale_vdev[0].blc.pattern01,
245
+ cif_dev->scale_vdev[0].blc.pattern02,
246
+ cif_dev->scale_vdev[0].blc.pattern03);
247
+ return ret;
248
+}
249
+
250
+static ssize_t rkcif_store_scale_ch0_blc(struct device *dev,
251
+ struct device_attribute *attr,
252
+ const char *buf, size_t len)
253
+{
254
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
255
+ int i = 0, index = 0;
256
+ unsigned int val[4] = {0};
257
+ unsigned int temp = 0;
258
+ int ret = 0;
259
+ int j = 0;
260
+ char cha[2] = {0};
261
+
262
+ if (buf) {
263
+ index = 0;
264
+ for (i = 0; i < len; i++) {
265
+ if (((buf[i] == ' ') || (buf[i] == '\n')) && j) {
266
+ index++;
267
+ j = 0;
268
+ if (index == 4)
269
+ break;
270
+ continue;
271
+ } else {
272
+ if (buf[i] < '0' || buf[i] > '9')
273
+ continue;
274
+ cha[0] = buf[i];
275
+ cha[1] = '\0';
276
+ ret = kstrtoint(cha, 0, &temp);
277
+ if (!ret) {
278
+ if (j)
279
+ val[index] *= 10;
280
+ val[index] += temp;
281
+ j++;
282
+ }
283
+ }
284
+ }
285
+ if (val[0] > 255 || val[1] > 255 || val[2] > 255 || val[3] > 255)
286
+ return -EINVAL;
287
+ cif_dev->scale_vdev[0].blc.pattern00 = val[0];
288
+ cif_dev->scale_vdev[0].blc.pattern01 = val[1];
289
+ cif_dev->scale_vdev[0].blc.pattern02 = val[2];
290
+ cif_dev->scale_vdev[0].blc.pattern03 = val[3];
291
+ dev_info(cif_dev->dev,
292
+ "set ch0 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
293
+ cif_dev->scale_vdev[0].blc.pattern00,
294
+ cif_dev->scale_vdev[0].blc.pattern01,
295
+ cif_dev->scale_vdev[0].blc.pattern02,
296
+ cif_dev->scale_vdev[0].blc.pattern03);
297
+ }
298
+
299
+ return len;
300
+}
301
+
302
+static DEVICE_ATTR(scale_ch0_blc, S_IWUSR | S_IRUSR,
303
+ rkcif_show_scale_ch0_blc, rkcif_store_scale_ch0_blc);
304
+
305
+static ssize_t rkcif_show_scale_ch1_blc(struct device *dev,
306
+ struct device_attribute *attr,
307
+ char *buf)
308
+{
309
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
310
+ int ret;
311
+
312
+ ret = snprintf(buf, PAGE_SIZE, "ch1 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
313
+ cif_dev->scale_vdev[1].blc.pattern00,
314
+ cif_dev->scale_vdev[1].blc.pattern01,
315
+ cif_dev->scale_vdev[1].blc.pattern02,
316
+ cif_dev->scale_vdev[1].blc.pattern03);
317
+ return ret;
318
+}
319
+
320
+static ssize_t rkcif_store_scale_ch1_blc(struct device *dev,
321
+ struct device_attribute *attr,
322
+ const char *buf, size_t len)
323
+{
324
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
325
+ int i = 0, index = 0;
326
+ unsigned int val[4] = {0};
327
+ unsigned int temp = 0;
328
+ int ret = 0;
329
+ int j = 0;
330
+ char cha[2] = {0};
331
+
332
+ if (buf) {
333
+ index = 0;
334
+ for (i = 0; i < len; i++) {
335
+ if (((buf[i] == ' ') || (buf[i] == '\n')) && j) {
336
+ index++;
337
+ j = 0;
338
+ if (index == 4)
339
+ break;
340
+ continue;
341
+ } else {
342
+ if (buf[i] < '0' || buf[i] > '9')
343
+ continue;
344
+ cha[0] = buf[i];
345
+ cha[1] = '\0';
346
+ ret = kstrtoint(cha, 0, &temp);
347
+ if (!ret) {
348
+ if (j)
349
+ val[index] *= 10;
350
+ val[index] += temp;
351
+ j++;
352
+ }
353
+ }
354
+ }
355
+ if (val[0] > 255 || val[1] > 255 || val[2] > 255 || val[3] > 255)
356
+ return -EINVAL;
357
+
358
+ cif_dev->scale_vdev[1].blc.pattern00 = val[0];
359
+ cif_dev->scale_vdev[1].blc.pattern01 = val[1];
360
+ cif_dev->scale_vdev[1].blc.pattern02 = val[2];
361
+ cif_dev->scale_vdev[1].blc.pattern03 = val[3];
362
+
363
+ dev_info(cif_dev->dev,
364
+ "set ch1 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
365
+ cif_dev->scale_vdev[1].blc.pattern00,
366
+ cif_dev->scale_vdev[1].blc.pattern01,
367
+ cif_dev->scale_vdev[1].blc.pattern02,
368
+ cif_dev->scale_vdev[1].blc.pattern03);
369
+ }
370
+
371
+ return len;
372
+}
373
+
374
+static DEVICE_ATTR(scale_ch1_blc, S_IWUSR | S_IRUSR,
375
+ rkcif_show_scale_ch1_blc, rkcif_store_scale_ch1_blc);
376
+
377
+static ssize_t rkcif_show_scale_ch2_blc(struct device *dev,
378
+ struct device_attribute *attr,
379
+ char *buf)
380
+{
381
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
382
+ int ret;
383
+
384
+ ret = snprintf(buf, PAGE_SIZE, "ch2 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
385
+ cif_dev->scale_vdev[2].blc.pattern00,
386
+ cif_dev->scale_vdev[2].blc.pattern01,
387
+ cif_dev->scale_vdev[2].blc.pattern02,
388
+ cif_dev->scale_vdev[2].blc.pattern03);
389
+ return ret;
390
+}
391
+
392
+static ssize_t rkcif_store_scale_ch2_blc(struct device *dev,
393
+ struct device_attribute *attr,
394
+ const char *buf, size_t len)
395
+{
396
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
397
+ int i = 0, index = 0;
398
+ unsigned int val[4] = {0};
399
+ unsigned int temp = 0;
400
+ int ret = 0;
401
+ int j = 0;
402
+ char cha[2] = {0};
403
+
404
+ if (buf) {
405
+ index = 0;
406
+ for (i = 0; i < len; i++) {
407
+ if (((buf[i] == ' ') || (buf[i] == '\n')) && j) {
408
+ index++;
409
+ j = 0;
410
+ if (index == 4)
411
+ break;
412
+ continue;
413
+ } else {
414
+ if (buf[i] < '0' || buf[i] > '9')
415
+ continue;
416
+ cha[0] = buf[i];
417
+ cha[1] = '\0';
418
+ ret = kstrtoint(cha, 0, &temp);
419
+ if (!ret) {
420
+ if (j)
421
+ val[index] *= 10;
422
+ val[index] += temp;
423
+ j++;
424
+ }
425
+ }
426
+ }
427
+ if (val[0] > 255 || val[1] > 255 || val[2] > 255 || val[3] > 255)
428
+ return -EINVAL;
429
+
430
+ cif_dev->scale_vdev[2].blc.pattern00 = val[0];
431
+ cif_dev->scale_vdev[2].blc.pattern01 = val[1];
432
+ cif_dev->scale_vdev[2].blc.pattern02 = val[2];
433
+ cif_dev->scale_vdev[2].blc.pattern03 = val[3];
434
+
435
+ dev_info(cif_dev->dev,
436
+ "set ch2 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
437
+ cif_dev->scale_vdev[2].blc.pattern00,
438
+ cif_dev->scale_vdev[2].blc.pattern01,
439
+ cif_dev->scale_vdev[2].blc.pattern02,
440
+ cif_dev->scale_vdev[2].blc.pattern03);
441
+ }
442
+
443
+ return len;
444
+}
445
+static DEVICE_ATTR(scale_ch2_blc, S_IWUSR | S_IRUSR,
446
+ rkcif_show_scale_ch2_blc, rkcif_store_scale_ch2_blc);
447
+
448
+static ssize_t rkcif_show_scale_ch3_blc(struct device *dev,
449
+ struct device_attribute *attr,
450
+ char *buf)
451
+{
452
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
453
+ int ret;
454
+
455
+ ret = snprintf(buf, PAGE_SIZE, "ch3 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
456
+ cif_dev->scale_vdev[3].blc.pattern00,
457
+ cif_dev->scale_vdev[3].blc.pattern01,
458
+ cif_dev->scale_vdev[3].blc.pattern02,
459
+ cif_dev->scale_vdev[3].blc.pattern03);
460
+ return ret;
461
+}
462
+
463
+static ssize_t rkcif_store_scale_ch3_blc(struct device *dev,
464
+ struct device_attribute *attr,
465
+ const char *buf, size_t len)
466
+{
467
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
468
+ int i = 0, index = 0;
469
+ unsigned int val[4] = {0};
470
+ unsigned int temp = 0;
471
+ int ret = 0;
472
+ int j = 0;
473
+ char cha[2] = {0};
474
+
475
+ if (buf) {
476
+ index = 0;
477
+ for (i = 0; i < len; i++) {
478
+ if (((buf[i] == ' ') || (buf[i] == '\n')) && j) {
479
+ index++;
480
+ j = 0;
481
+ if (index == 4)
482
+ break;
483
+ continue;
484
+ } else {
485
+ if (buf[i] < '0' || buf[i] > '9')
486
+ continue;
487
+ cha[0] = buf[i];
488
+ cha[1] = '\0';
489
+ ret = kstrtoint(cha, 0, &temp);
490
+ if (!ret) {
491
+ if (j)
492
+ val[index] *= 10;
493
+ val[index] += temp;
494
+ j++;
495
+ }
496
+ }
497
+ }
498
+ if (val[0] > 255 || val[1] > 255 || val[2] > 255 || val[3] > 255)
499
+ return -EINVAL;
500
+
501
+ cif_dev->scale_vdev[3].blc.pattern00 = val[0];
502
+ cif_dev->scale_vdev[3].blc.pattern01 = val[1];
503
+ cif_dev->scale_vdev[3].blc.pattern02 = val[2];
504
+ cif_dev->scale_vdev[3].blc.pattern03 = val[3];
505
+
506
+ dev_info(cif_dev->dev,
507
+ "set ch3 pattern00: %d, pattern01: %d, pattern02: %d, pattern03: %d\n",
508
+ cif_dev->scale_vdev[3].blc.pattern00,
509
+ cif_dev->scale_vdev[3].blc.pattern01,
510
+ cif_dev->scale_vdev[3].blc.pattern02,
511
+ cif_dev->scale_vdev[3].blc.pattern03);
512
+ }
513
+
514
+ return len;
515
+}
516
+
517
+static DEVICE_ATTR(scale_ch3_blc, S_IWUSR | S_IRUSR,
518
+ rkcif_show_scale_ch3_blc, rkcif_store_scale_ch3_blc);
519
+
520
+static ssize_t rkcif_store_capture_fps(struct device *dev,
521
+ struct device_attribute *attr,
522
+ const char *buf, size_t len)
523
+{
524
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
525
+ struct rkcif_stream *stream = NULL;
526
+ int i = 0, index = 0;
527
+ unsigned int val[4] = {0};
528
+ unsigned int temp = 0;
529
+ int ret = 0;
530
+ int j = 0;
531
+ char cha[2] = {0};
532
+ struct rkcif_fps fps = {0};
533
+
534
+ if (buf) {
535
+ index = 0;
536
+ for (i = 0; i < len; i++) {
537
+ if (((buf[i] == ' ') || (buf[i] == '\n')) && j) {
538
+ index++;
539
+ j = 0;
540
+ if (index == 4)
541
+ break;
542
+ continue;
543
+ } else {
544
+ if (buf[i] < '0' || buf[i] > '9')
545
+ continue;
546
+ cha[0] = buf[i];
547
+ cha[1] = '\0';
548
+ ret = kstrtoint(cha, 0, &temp);
549
+ if (!ret) {
550
+ if (j)
551
+ val[index] *= 10;
552
+ val[index] += temp;
553
+ j++;
554
+ }
555
+ }
556
+ }
557
+
558
+ for (i = 0; i < index; i++) {
559
+ if ((val[i] - '0' != 0) && cif_dev->chip_id >= CHIP_RV1106_CIF) {
560
+ stream = &cif_dev->stream[i];
561
+ fps.fps = val[i];
562
+ rkcif_set_fps(stream, &fps);
563
+ }
564
+ }
565
+ dev_info(cif_dev->dev,
566
+ "set fps id0: %d, id1: %d, id2: %d, id3: %d\n",
567
+ val[0], val[1], val[2], val[3]);
568
+ }
569
+
570
+ return len;
571
+}
572
+static DEVICE_ATTR(fps, 0200, NULL, rkcif_store_capture_fps);
573
+
574
+static ssize_t rkcif_show_rdbk_debug(struct device *dev,
575
+ struct device_attribute *attr,
576
+ char *buf)
577
+{
578
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
579
+ int ret;
580
+
581
+ ret = snprintf(buf, PAGE_SIZE, "%d\n",
582
+ cif_dev->rdbk_debug);
583
+ return ret;
584
+}
585
+
586
+static ssize_t rkcif_store_rdbk_debug(struct device *dev,
587
+ struct device_attribute *attr,
588
+ const char *buf, size_t len)
589
+{
590
+ struct rkcif_device *cif_dev = (struct rkcif_device *)dev_get_drvdata(dev);
591
+ int val = 0;
592
+ int ret = 0;
593
+
594
+ ret = kstrtoint(buf, 0, &val);
595
+ if (!ret)
596
+ cif_dev->rdbk_debug = val;
597
+ else
598
+ dev_info(cif_dev->dev, "set rdbk debug failed\n");
599
+ return len;
600
+}
601
+static DEVICE_ATTR(rdbk_debug, 0200, rkcif_show_rdbk_debug, rkcif_store_rdbk_debug);
225602
226603 static struct attribute *dev_attrs[] = {
227604 &dev_attr_compact_test.attr,
228605 &dev_attr_wait_line.attr,
229606 &dev_attr_is_use_dummybuf.attr,
230607 &dev_attr_is_high_align.attr,
608
+ &dev_attr_scale_ch0_blc.attr,
609
+ &dev_attr_scale_ch1_blc.attr,
610
+ &dev_attr_scale_ch2_blc.attr,
611
+ &dev_attr_scale_ch3_blc.attr,
612
+ &dev_attr_fps.attr,
613
+ &dev_attr_rdbk_debug.attr,
231614 NULL,
232615 };
233616
....@@ -244,11 +627,25 @@
244627 {
245628 void __iomem *base = dev->hw_dev->base_addr;
246629 const struct cif_reg *reg = &dev->hw_dev->cif_regs[index];
630
+ int csi_offset = 0;
247631
632
+ if (dev->inf_id == RKCIF_MIPI_LVDS &&
633
+ index >= CIF_REG_MIPI_LVDS_ID0_CTRL0 &&
634
+ index <= CIF_REG_MIPI_ON_PAD) {
635
+ if (dev->chip_id == CHIP_RK3588_CIF) {
636
+ csi_offset = dev->csi_host_idx * 0x100;
637
+ } else if (dev->chip_id == CHIP_RV1106_CIF) {
638
+ csi_offset = dev->csi_host_idx * 0x200;
639
+ } else if (dev->chip_id == CHIP_RK3562_CIF) {
640
+ if (dev->csi_host_idx < 3)
641
+ csi_offset = dev->csi_host_idx * 0x200;
642
+ else
643
+ csi_offset = 0x500;
644
+ }
645
+ }
248646 if (index < CIF_REG_INDEX_MAX) {
249
- if (index == CIF_REG_DVP_CTRL ||
250
- (index != CIF_REG_DVP_CTRL && reg->offset != 0x0))
251
- write_cif_reg(base, reg->offset, val);
647
+ if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0)
648
+ write_cif_reg(base, reg->offset + csi_offset, val);
252649 else
253650 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
254651 "write reg[%d]:0x%x failed, maybe useless!!!\n",
....@@ -262,13 +659,28 @@
262659 unsigned int reg_val = 0x0;
263660 void __iomem *base = dev->hw_dev->base_addr;
264661 const struct cif_reg *reg = &dev->hw_dev->cif_regs[index];
662
+ int csi_offset = 0;
663
+
664
+ if (dev->inf_id == RKCIF_MIPI_LVDS &&
665
+ index >= CIF_REG_MIPI_LVDS_ID0_CTRL0 &&
666
+ index <= CIF_REG_MIPI_ON_PAD) {
667
+ if (dev->chip_id == CHIP_RK3588_CIF) {
668
+ csi_offset = dev->csi_host_idx * 0x100;
669
+ } else if (dev->chip_id == CHIP_RV1106_CIF) {
670
+ csi_offset = dev->csi_host_idx * 0x200;
671
+ } else if (dev->chip_id == CHIP_RK3562_CIF) {
672
+ if (dev->csi_host_idx < 3)
673
+ csi_offset = dev->csi_host_idx * 0x200;
674
+ else
675
+ csi_offset = 0x500;
676
+ }
677
+ }
265678
266679 if (index < CIF_REG_INDEX_MAX) {
267
- if (index == CIF_REG_DVP_CTRL ||
268
- (index != CIF_REG_DVP_CTRL && reg->offset != 0x0)) {
269
- reg_val = read_cif_reg(base, reg->offset);
680
+ if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0) {
681
+ reg_val = read_cif_reg(base, reg->offset + csi_offset);
270682 reg_val |= val;
271
- write_cif_reg(base, reg->offset, reg_val);
683
+ write_cif_reg(base, reg->offset + csi_offset, reg_val);
272684 } else {
273685 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
274686 "write reg[%d]:0x%x with OR failed, maybe useless!!!\n",
....@@ -283,13 +695,28 @@
283695 unsigned int reg_val = 0x0;
284696 void __iomem *base = dev->hw_dev->base_addr;
285697 const struct cif_reg *reg = &dev->hw_dev->cif_regs[index];
698
+ int csi_offset = 0;
699
+
700
+ if (dev->inf_id == RKCIF_MIPI_LVDS &&
701
+ index >= CIF_REG_MIPI_LVDS_ID0_CTRL0 &&
702
+ index <= CIF_REG_MIPI_ON_PAD) {
703
+ if (dev->chip_id == CHIP_RK3588_CIF) {
704
+ csi_offset = dev->csi_host_idx * 0x100;
705
+ } else if (dev->chip_id == CHIP_RV1106_CIF) {
706
+ csi_offset = dev->csi_host_idx * 0x200;
707
+ } else if (dev->chip_id == CHIP_RK3562_CIF) {
708
+ if (dev->csi_host_idx < 3)
709
+ csi_offset = dev->csi_host_idx * 0x200;
710
+ else
711
+ csi_offset = 0x500;
712
+ }
713
+ }
286714
287715 if (index < CIF_REG_INDEX_MAX) {
288
- if (index == CIF_REG_DVP_CTRL ||
289
- (index != CIF_REG_DVP_CTRL && reg->offset != 0x0)) {
290
- reg_val = read_cif_reg(base, reg->offset);
716
+ if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0) {
717
+ reg_val = read_cif_reg(base, reg->offset + csi_offset);
291718 reg_val &= val;
292
- write_cif_reg(base, reg->offset, reg_val);
719
+ write_cif_reg(base, reg->offset + csi_offset, reg_val);
293720 } else {
294721 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
295722 "write reg[%d]:0x%x with OR failed, maybe useless!!!\n",
....@@ -304,11 +731,26 @@
304731 unsigned int val = 0x0;
305732 void __iomem *base = dev->hw_dev->base_addr;
306733 const struct cif_reg *reg = &dev->hw_dev->cif_regs[index];
734
+ int csi_offset = 0;
735
+
736
+ if (dev->inf_id == RKCIF_MIPI_LVDS &&
737
+ index >= CIF_REG_MIPI_LVDS_ID0_CTRL0 &&
738
+ index <= CIF_REG_MIPI_ON_PAD) {
739
+ if (dev->chip_id == CHIP_RK3588_CIF) {
740
+ csi_offset = dev->csi_host_idx * 0x100;
741
+ } else if (dev->chip_id == CHIP_RV1106_CIF) {
742
+ csi_offset = dev->csi_host_idx * 0x200;
743
+ } else if (dev->chip_id == CHIP_RK3562_CIF) {
744
+ if (dev->csi_host_idx < 3)
745
+ csi_offset = dev->csi_host_idx * 0x200;
746
+ else
747
+ csi_offset = 0x500;
748
+ }
749
+ }
307750
308751 if (index < CIF_REG_INDEX_MAX) {
309
- if (index == CIF_REG_DVP_CTRL ||
310
- (index != CIF_REG_DVP_CTRL && reg->offset != 0x0))
311
- val = read_cif_reg(base, reg->offset);
752
+ if (index == CIF_REG_DVP_CTRL || reg->offset != 0x0)
753
+ val = read_cif_reg(base, reg->offset + csi_offset);
312754 else
313755 v4l2_dbg(1, rkcif_debug, &dev->v4l2_dev,
314756 "read reg[%d] failed, maybe useless!!!\n",
....@@ -375,6 +817,18 @@
375817 else
376818 val = CIF_SAMPLING_EDGE_SINGLE;
377819 rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, val);
820
+ } else if (dev->chip_id == CHIP_RK3588_CIF) {
821
+ if (on)
822
+ val = RK3588_CIF_PCLK_DUAL_EDGE;
823
+ else
824
+ val = RK3588_CIF_PCLK_SINGLE_EDGE;
825
+ rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, val);
826
+ } else if (dev->chip_id == CHIP_RV1106_CIF) {
827
+ if (on)
828
+ val = RV1106_CIF_PCLK_DUAL_EDGE;
829
+ else
830
+ val = RV1106_CIF_PCLK_SINGLE_EDGE;
831
+ rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, val);
378832 }
379833 }
380834
....@@ -402,7 +856,42 @@
402856 else
403857 val = RK3568_CIF_PCLK_SAMPLING_EDGE_FALLING;
404858 }
859
+
860
+ if (dev->chip_id == CHIP_RK3588_CIF) {
861
+ if (edge == RKCIF_CLK_RISING)
862
+ val = RK3588_CIF_PCLK_SAMPLING_EDGE_RISING;
863
+ else
864
+ val = RK3588_CIF_PCLK_SAMPLING_EDGE_FALLING;
865
+ }
866
+ if (dev->chip_id == CHIP_RV1106_CIF) {
867
+ if (dev->dphy_hw) {
868
+ if (edge == RKCIF_CLK_RISING)
869
+ val = RV1106_CIF_PCLK_EDGE_RISING_M0;
870
+ else
871
+ val = RV1106_CIF_PCLK_EDGE_FALLING_M0;
872
+ } else {
873
+ if (edge == RKCIF_CLK_RISING)
874
+ val = RV1106_CIF_PCLK_EDGE_RISING_M1;
875
+ else
876
+ val = RV1106_CIF_PCLK_EDGE_FALLING_M1;
877
+ rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_VENC, val);
878
+ return;
879
+ }
880
+ }
405881 rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, val);
882
+ }
883
+}
884
+
885
+void rkcif_config_dvp_pin(struct rkcif_device *dev, bool on)
886
+{
887
+ if (dev->dphy_hw && dev->dphy_hw->ttl_mode_enable && dev->dphy_hw->ttl_mode_disable) {
888
+ rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, RV1106_CIF_GRF_SEL_M0);
889
+ if (on)
890
+ dev->dphy_hw->ttl_mode_enable(dev->dphy_hw);
891
+ else
892
+ dev->dphy_hw->ttl_mode_disable(dev->dphy_hw);
893
+ } else {
894
+ rkcif_write_grf_reg(dev, CIF_REG_GRF_CIFIO_CON, RV1106_CIF_GRF_SEL_M1);
406895 }
407896 }
408897
....@@ -480,6 +969,119 @@
480969 return 0;
481970 }
482971
972
+static void rkcif_set_sensor_streamon_in_sync_mode(struct rkcif_device *cif_dev)
973
+{
974
+ struct rkcif_hw *hw = cif_dev->hw_dev;
975
+ struct rkcif_device *dev = NULL;
976
+ int i = 0, j = 0;
977
+ int on = 1;
978
+ int ret = 0;
979
+ bool is_streaming = false;
980
+ struct rkcif_multi_sync_config *sync_config;
981
+
982
+ if (!cif_dev->sync_cfg.type)
983
+ return;
984
+
985
+ mutex_lock(&hw->dev_lock);
986
+ sync_config = &hw->sync_config[cif_dev->sync_cfg.group];
987
+ sync_config->streaming_cnt++;
988
+ if (sync_config->streaming_cnt < sync_config->dev_cnt) {
989
+ mutex_unlock(&hw->dev_lock);
990
+ return;
991
+ }
992
+
993
+ if (sync_config->mode == RKCIF_MASTER_MASTER ||
994
+ sync_config->mode == RKCIF_MASTER_SLAVE) {
995
+ for (i = 0; i < sync_config->slave.count; i++) {
996
+ dev = sync_config->slave.cif_dev[i];
997
+ is_streaming = sync_config->slave.is_streaming[i];
998
+ if (!is_streaming) {
999
+ if (dev->sditf_cnt == 1) {
1000
+ ret = v4l2_subdev_call(dev->terminal_sensor.sd, core, ioctl,
1001
+ RKMODULE_SET_QUICK_STREAM, &on);
1002
+ if (ret)
1003
+ dev_info(dev->dev,
1004
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1005
+ } else {
1006
+ for (j = 0; j < dev->sditf_cnt; j++)
1007
+ ret |= v4l2_subdev_call(dev->sditf[j]->sensor_sd,
1008
+ core,
1009
+ ioctl,
1010
+ RKMODULE_SET_QUICK_STREAM,
1011
+ &on);
1012
+ if (ret)
1013
+ dev_info(dev->dev,
1014
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1015
+ }
1016
+ sync_config->slave.is_streaming[i] = true;
1017
+ }
1018
+ v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
1019
+ "quick stream in sync mode, slave_dev[%d]\n", i);
1020
+
1021
+ }
1022
+ for (i = 0; i < sync_config->ext_master.count; i++) {
1023
+ dev = sync_config->ext_master.cif_dev[i];
1024
+ is_streaming = sync_config->ext_master.is_streaming[i];
1025
+ if (!is_streaming) {
1026
+ if (dev->sditf_cnt == 1) {
1027
+ ret = v4l2_subdev_call(dev->terminal_sensor.sd, core, ioctl,
1028
+ RKMODULE_SET_QUICK_STREAM, &on);
1029
+ if (ret)
1030
+ dev_info(dev->dev,
1031
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1032
+ } else {
1033
+ for (j = 0; j < dev->sditf_cnt; j++)
1034
+ ret |= v4l2_subdev_call(dev->sditf[j]->sensor_sd,
1035
+ core,
1036
+ ioctl,
1037
+ RKMODULE_SET_QUICK_STREAM,
1038
+ &on);
1039
+ if (ret)
1040
+ dev_info(dev->dev,
1041
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1042
+ }
1043
+ sync_config->ext_master.is_streaming[i] = true;
1044
+ }
1045
+ v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
1046
+ "quick stream in sync mode, ext_master_dev[%d]\n", i);
1047
+ }
1048
+ for (i = 0; i < sync_config->int_master.count; i++) {
1049
+ dev = sync_config->int_master.cif_dev[i];
1050
+ is_streaming = sync_config->int_master.is_streaming[i];
1051
+ if (!is_streaming) {
1052
+ if (dev->sditf_cnt == 1) {
1053
+ ret = v4l2_subdev_call(dev->terminal_sensor.sd, core, ioctl,
1054
+ RKMODULE_SET_QUICK_STREAM, &on);
1055
+ if (ret)
1056
+ dev_info(hw->dev,
1057
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1058
+ } else {
1059
+ for (j = 0; j < dev->sditf_cnt; j++)
1060
+ ret |= v4l2_subdev_call(dev->sditf[j]->sensor_sd,
1061
+ core,
1062
+ ioctl,
1063
+ RKMODULE_SET_QUICK_STREAM,
1064
+ &on);
1065
+ if (ret)
1066
+ dev_info(dev->dev,
1067
+ "set RKMODULE_SET_QUICK_STREAM failed\n");
1068
+ }
1069
+ sync_config->int_master.is_streaming[i] = true;
1070
+ }
1071
+ v4l2_dbg(3, rkcif_debug, &dev->v4l2_dev,
1072
+ "quick stream in sync mode, int_master_dev[%d]\n", i);
1073
+ }
1074
+ }
1075
+ mutex_unlock(&hw->dev_lock);
1076
+}
1077
+
1078
+static void rkcif_sensor_streaming_cb(void *data)
1079
+{
1080
+ struct v4l2_subdev *subdevs = (struct v4l2_subdev *)data;
1081
+
1082
+ v4l2_subdev_call(subdevs, video, s_stream, 1);
1083
+}
1084
+
4831085 /*
4841086 * stream-on order: isp_subdev, mipi dphy, sensor
4851087 * stream-off order: mipi dphy, sensor, isp_subdev
....@@ -487,11 +1089,10 @@
4871089 static int rkcif_pipeline_set_stream(struct rkcif_pipeline *p, bool on)
4881090 {
4891091 struct rkcif_device *cif_dev = container_of(p, struct rkcif_device, pipe);
490
- struct rkcif_stream *stream = NULL;
4911092 bool can_be_set = false;
492
- int i, ret;
1093
+ int i, ret = 0;
4931094
494
- if (cif_dev->hdr.mode == NO_HDR) {
1095
+ if (cif_dev->hdr.hdr_mode == NO_HDR || cif_dev->hdr.hdr_mode == HDR_COMPR) {
4951096 if ((on && atomic_inc_return(&p->stream_cnt) > 1) ||
4961097 (!on && atomic_dec_return(&p->stream_cnt) > 0))
4971098 return 0;
....@@ -505,34 +1106,72 @@
5051106 cif_dev->irq_stats.dvp_overflow_cnt = 0;
5061107 cif_dev->irq_stats.dvp_pix_err_cnt = 0;
5071108 cif_dev->irq_stats.all_err_cnt = 0;
508
- cif_dev->irq_stats.all_frm_end_cnt = 0;
1109
+ cif_dev->irq_stats.csi_size_err_cnt = 0;
1110
+ cif_dev->irq_stats.dvp_size_err_cnt = 0;
1111
+ cif_dev->irq_stats.dvp_bwidth_lack_cnt = 0;
1112
+ cif_dev->irq_stats.frm_end_cnt[0] = 0;
1113
+ cif_dev->irq_stats.frm_end_cnt[1] = 0;
1114
+ cif_dev->irq_stats.frm_end_cnt[2] = 0;
1115
+ cif_dev->irq_stats.frm_end_cnt[3] = 0;
1116
+ cif_dev->irq_stats.not_active_buf_cnt[0] = 0;
1117
+ cif_dev->irq_stats.not_active_buf_cnt[1] = 0;
1118
+ cif_dev->irq_stats.not_active_buf_cnt[2] = 0;
1119
+ cif_dev->irq_stats.not_active_buf_cnt[3] = 0;
1120
+ cif_dev->irq_stats.trig_simult_cnt[0] = 0;
1121
+ cif_dev->irq_stats.trig_simult_cnt[1] = 0;
1122
+ cif_dev->irq_stats.trig_simult_cnt[2] = 0;
1123
+ cif_dev->irq_stats.trig_simult_cnt[3] = 0;
5091124 cif_dev->reset_watchdog_timer.is_triggered = false;
1125
+ cif_dev->reset_watchdog_timer.is_running = false;
1126
+ cif_dev->err_state_work.last_timestamp = 0;
5101127 for (i = 0; i < cif_dev->num_channels; i++)
5111128 cif_dev->reset_watchdog_timer.last_buf_wakeup_cnt[i] = 0;
1129
+ cif_dev->reset_watchdog_timer.run_cnt = 0;
5121130 }
5131131
5141132 /* phy -> sensor */
5151133 for (i = 0; i < p->num_subdevs; i++) {
516
- ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on);
1134
+ if (p->subdevs[i] == cif_dev->terminal_sensor.sd &&
1135
+ on &&
1136
+ cif_dev->is_thunderboot &&
1137
+ !rk_tb_mcu_is_done()) {
1138
+ cif_dev->tb_client.data = p->subdevs[i];
1139
+ cif_dev->tb_client.cb = rkcif_sensor_streaming_cb;
1140
+ rk_tb_client_register_cb(&cif_dev->tb_client);
1141
+ } else {
1142
+ ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on);
1143
+ }
5171144 if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
5181145 goto err_stream_off;
5191146 }
1147
+
1148
+ if (cif_dev->sditf_cnt > 1) {
1149
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
1150
+ ret = v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd,
1151
+ video,
1152
+ s_stream,
1153
+ on);
1154
+ if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
1155
+ goto err_stream_off;
1156
+ }
1157
+ }
1158
+
5201159 if (on)
521
- rkcif_monitor_reset_event(cif_dev->hw_dev);
1160
+ rkcif_set_sensor_streamon_in_sync_mode(cif_dev);
5221161 } else {
5231162 if (!on && atomic_dec_return(&p->stream_cnt) > 0)
5241163 return 0;
5251164
5261165 if (on) {
5271166 atomic_inc(&p->stream_cnt);
528
- if (cif_dev->hdr.mode == HDR_X2) {
1167
+ if (cif_dev->hdr.hdr_mode == HDR_X2) {
5291168 if (atomic_read(&p->stream_cnt) == 1) {
5301169 rockchip_set_system_status(SYS_STATUS_CIF0);
5311170 can_be_set = false;
5321171 } else if (atomic_read(&p->stream_cnt) == 2) {
5331172 can_be_set = true;
5341173 }
535
- } else if (cif_dev->hdr.mode == HDR_X3) {
1174
+ } else if (cif_dev->hdr.hdr_mode == HDR_X3) {
5361175 if (atomic_read(&p->stream_cnt) == 1) {
5371176 rockchip_set_system_status(SYS_STATUS_CIF0);
5381177 can_be_set = false;
....@@ -550,28 +1189,58 @@
5501189 cif_dev->irq_stats.dvp_line_err_cnt = 0;
5511190 cif_dev->irq_stats.dvp_overflow_cnt = 0;
5521191 cif_dev->irq_stats.dvp_pix_err_cnt = 0;
1192
+ cif_dev->irq_stats.dvp_bwidth_lack_cnt = 0;
5531193 cif_dev->irq_stats.all_err_cnt = 0;
554
- cif_dev->irq_stats.all_frm_end_cnt = 0;
1194
+ cif_dev->irq_stats.csi_size_err_cnt = 0;
1195
+ cif_dev->irq_stats.dvp_size_err_cnt = 0;
1196
+ cif_dev->irq_stats.frm_end_cnt[0] = 0;
1197
+ cif_dev->irq_stats.frm_end_cnt[1] = 0;
1198
+ cif_dev->irq_stats.frm_end_cnt[2] = 0;
1199
+ cif_dev->irq_stats.frm_end_cnt[3] = 0;
1200
+ cif_dev->irq_stats.not_active_buf_cnt[0] = 0;
1201
+ cif_dev->irq_stats.not_active_buf_cnt[1] = 0;
1202
+ cif_dev->irq_stats.not_active_buf_cnt[2] = 0;
1203
+ cif_dev->irq_stats.not_active_buf_cnt[3] = 0;
1204
+ cif_dev->irq_stats.trig_simult_cnt[0] = 0;
1205
+ cif_dev->irq_stats.trig_simult_cnt[1] = 0;
1206
+ cif_dev->irq_stats.trig_simult_cnt[2] = 0;
1207
+ cif_dev->irq_stats.trig_simult_cnt[3] = 0;
5551208 cif_dev->is_start_hdr = true;
5561209 cif_dev->reset_watchdog_timer.is_triggered = false;
1210
+ cif_dev->reset_watchdog_timer.is_running = false;
5571211 for (i = 0; i < cif_dev->num_channels; i++)
5581212 cif_dev->reset_watchdog_timer.last_buf_wakeup_cnt[i] = 0;
1213
+ cif_dev->reset_watchdog_timer.run_cnt = 0;
5591214 }
5601215
5611216 /* phy -> sensor */
5621217 for (i = 0; i < p->num_subdevs; i++) {
563
- ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on);
564
-
1218
+ if (p->subdevs[i] == cif_dev->terminal_sensor.sd &&
1219
+ on &&
1220
+ cif_dev->is_thunderboot &&
1221
+ !rk_tb_mcu_is_done()) {
1222
+ cif_dev->tb_client.data = p->subdevs[i];
1223
+ cif_dev->tb_client.cb = rkcif_sensor_streaming_cb;
1224
+ rk_tb_client_register_cb(&cif_dev->tb_client);
1225
+ } else {
1226
+ ret = v4l2_subdev_call(p->subdevs[i], video, s_stream, on);
1227
+ }
5651228 if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
5661229 goto err_stream_off;
5671230 }
568
- if (on) {
569
- rkcif_monitor_reset_event(cif_dev->hw_dev);
570
- for (i = 0; i < atomic_read(&p->stream_cnt); i++) {
571
- stream = &cif_dev->stream[i];
572
- stream->streamon_timestamp = ktime_get_ns();
1231
+ if (cif_dev->sditf_cnt > 1) {
1232
+ for (i = 0; i < cif_dev->sditf_cnt; i++) {
1233
+ ret = v4l2_subdev_call(cif_dev->sditf[i]->sensor_sd,
1234
+ video,
1235
+ s_stream,
1236
+ on);
1237
+ if (on && ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
1238
+ goto err_stream_off;
5731239 }
5741240 }
1241
+
1242
+ if (on)
1243
+ rkcif_set_sensor_streamon_in_sync_mode(cif_dev);
5751244 }
5761245 }
5771246
....@@ -587,98 +1256,131 @@
5871256 return ret;
5881257 }
5891258
590
-/***************************** media controller *******************************/
591
-static int rkcif_create_links(struct rkcif_device *dev)
1259
+static int rkcif_create_link(struct rkcif_device *dev,
1260
+ struct rkcif_sensor_info *sensor,
1261
+ u32 stream_num,
1262
+ bool *mipi_lvds_linked)
5921263 {
593
- int ret;
594
- u32 flags;
595
- unsigned int s, pad, id, stream_num = 0;
596
- bool mipi_lvds_linked = false;
1264
+ struct rkcif_sensor_info linked_sensor;
1265
+ struct media_entity *source_entity, *sink_entity;
1266
+ int ret = 0;
1267
+ u32 flags, pad, id;
1268
+ int pad_offset = 0;
5971269
598
- if (dev->chip_id < CHIP_RV1126_CIF) {
599
- if (dev->inf_id == RKCIF_MIPI_LVDS)
600
- stream_num = RKCIF_MAX_STREAM_MIPI;
601
- else
602
- stream_num = RKCIF_SINGLE_STREAM;
1270
+ if (dev->chip_id >= CHIP_RK3588_CIF)
1271
+ pad_offset = 4;
1272
+
1273
+ linked_sensor.lanes = sensor->lanes;
1274
+
1275
+ if (sensor->mbus.type == V4L2_MBUS_CCP2) {
1276
+ linked_sensor.sd = &dev->lvds_subdev.sd;
1277
+ dev->lvds_subdev.sensor_self.sd = &dev->lvds_subdev.sd;
1278
+ dev->lvds_subdev.sensor_self.lanes = sensor->lanes;
1279
+ memcpy(&dev->lvds_subdev.sensor_self.mbus, &sensor->mbus,
1280
+ sizeof(struct v4l2_mbus_config));
6031281 } else {
604
- stream_num = RKCIF_MAX_STREAM_MIPI;
1282
+ linked_sensor.sd = sensor->sd;
6051283 }
6061284
607
- /* sensor links(or mipi-phy) */
608
- for (s = 0; s < dev->num_sensors; ++s) {
609
- struct rkcif_sensor_info *sensor = &dev->sensors[s];
610
- struct rkcif_sensor_info linked_sensor;
611
- struct media_entity *source_entity, *sink_entity;
1285
+ memcpy(&linked_sensor.mbus, &sensor->mbus,
1286
+ sizeof(struct v4l2_mbus_config));
6121287
613
- linked_sensor.lanes = sensor->lanes;
1288
+ for (pad = 0; pad < linked_sensor.sd->entity.num_pads; pad++) {
1289
+ if (linked_sensor.sd->entity.pads[pad].flags &
1290
+ MEDIA_PAD_FL_SOURCE) {
1291
+ if (pad == linked_sensor.sd->entity.num_pads) {
1292
+ dev_err(dev->dev,
1293
+ "failed to find src pad for %s\n",
1294
+ linked_sensor.sd->name);
6141295
615
- if (sensor->mbus.type == V4L2_MBUS_CCP2) {
616
- linked_sensor.sd = &dev->lvds_subdev.sd;
617
- dev->lvds_subdev.sensor_self.sd = &dev->lvds_subdev.sd;
618
- dev->lvds_subdev.sensor_self.lanes = sensor->lanes;
619
- memcpy(&dev->lvds_subdev.sensor_self.mbus, &sensor->mbus,
620
- sizeof(struct v4l2_mbus_config));
621
- } else {
622
- linked_sensor.sd = sensor->sd;
623
- }
1296
+ break;
1297
+ }
6241298
625
- memcpy(&linked_sensor.mbus, &sensor->mbus,
626
- sizeof(struct v4l2_mbus_config));
1299
+ if ((linked_sensor.mbus.type == V4L2_MBUS_BT656 ||
1300
+ linked_sensor.mbus.type == V4L2_MBUS_PARALLEL) &&
1301
+ (dev->chip_id == CHIP_RK1808_CIF)) {
1302
+ source_entity = &linked_sensor.sd->entity;
1303
+ sink_entity = &dev->stream[RKCIF_STREAM_CIF].vnode.vdev.entity;
6271304
628
- for (pad = 0; pad < linked_sensor.sd->entity.num_pads; pad++) {
629
- if (linked_sensor.sd->entity.pads[pad].flags &
630
- MEDIA_PAD_FL_SOURCE) {
631
- if (pad == linked_sensor.sd->entity.num_pads) {
632
- dev_err(dev->dev,
633
- "failed to find src pad for %s\n",
1305
+ ret = media_create_pad_link(source_entity,
1306
+ pad,
1307
+ sink_entity,
1308
+ 0,
1309
+ MEDIA_LNK_FL_ENABLED);
1310
+ if (ret)
1311
+ dev_err(dev->dev, "failed to create link for %s\n",
6341312 linked_sensor.sd->name);
1313
+ break;
1314
+ }
6351315
1316
+ if ((linked_sensor.mbus.type == V4L2_MBUS_BT656 ||
1317
+ linked_sensor.mbus.type == V4L2_MBUS_PARALLEL) &&
1318
+ (dev->chip_id >= CHIP_RV1126_CIF)) {
1319
+ source_entity = &linked_sensor.sd->entity;
1320
+ sink_entity = &dev->stream[pad].vnode.vdev.entity;
1321
+
1322
+ ret = media_create_pad_link(source_entity,
1323
+ pad,
1324
+ sink_entity,
1325
+ 0,
1326
+ MEDIA_LNK_FL_ENABLED);
1327
+ if (ret)
1328
+ dev_err(dev->dev, "failed to create link for %s pad[%d]\n",
1329
+ linked_sensor.sd->name, pad);
1330
+ continue;
1331
+ }
1332
+
1333
+ for (id = 0; id < stream_num; id++) {
1334
+ source_entity = &linked_sensor.sd->entity;
1335
+ sink_entity = &dev->stream[id].vnode.vdev.entity;
1336
+
1337
+ if ((dev->chip_id < CHIP_RK1808_CIF) ||
1338
+ (id == pad - 1 && !(*mipi_lvds_linked)))
1339
+ flags = MEDIA_LNK_FL_ENABLED;
1340
+ else
1341
+ flags = 0;
1342
+
1343
+ ret = media_create_pad_link(source_entity,
1344
+ pad,
1345
+ sink_entity,
1346
+ 0,
1347
+ flags);
1348
+ if (ret) {
1349
+ dev_err(dev->dev,
1350
+ "failed to create link for %s\n",
1351
+ linked_sensor.sd->name);
6361352 break;
6371353 }
638
-
639
- if ((linked_sensor.mbus.type == V4L2_MBUS_BT656 ||
640
- linked_sensor.mbus.type == V4L2_MBUS_PARALLEL) &&
641
- (dev->chip_id == CHIP_RK1808_CIF)) {
642
- source_entity = &linked_sensor.sd->entity;
643
- sink_entity = &dev->stream[RKCIF_STREAM_CIF].vnode.vdev.entity;
644
-
645
- ret = media_create_pad_link(source_entity,
646
- pad,
647
- sink_entity,
648
- 0,
649
- MEDIA_LNK_FL_ENABLED);
650
- if (ret)
651
- dev_err(dev->dev, "failed to create link for %s\n",
652
- linked_sensor.sd->name);
653
- break;
654
- }
655
-
656
- if ((linked_sensor.mbus.type == V4L2_MBUS_BT656 ||
657
- linked_sensor.mbus.type == V4L2_MBUS_PARALLEL) &&
658
- (dev->chip_id >= CHIP_RV1126_CIF)) {
659
- source_entity = &linked_sensor.sd->entity;
660
- sink_entity = &dev->stream[pad].vnode.vdev.entity;
661
-
662
- ret = media_create_pad_link(source_entity,
663
- pad,
664
- sink_entity,
665
- 0,
666
- MEDIA_LNK_FL_ENABLED);
667
- if (ret)
668
- dev_err(dev->dev, "failed to create link for %s pad[%d]\n",
669
- linked_sensor.sd->name, pad);
670
- continue;
671
- }
672
-
1354
+ }
1355
+ if (dev->chip_id >= CHIP_RK3588_CIF) {
6731356 for (id = 0; id < stream_num; id++) {
6741357 source_entity = &linked_sensor.sd->entity;
675
- sink_entity = &dev->stream[id].vnode.vdev.entity;
1358
+ sink_entity = &dev->scale_vdev[id].vnode.vdev.entity;
6761359
677
- if ((dev->chip_id != CHIP_RK1808_CIF &&
678
- dev->chip_id != CHIP_RV1126_CIF &&
679
- dev->chip_id != CHIP_RV1126_CIF_LITE &&
680
- dev->chip_id != CHIP_RK3568_CIF) ||
681
- (id == pad - 1 && !mipi_lvds_linked))
1360
+ if ((id + stream_num) == pad - 1 && !(*mipi_lvds_linked))
1361
+ flags = MEDIA_LNK_FL_ENABLED;
1362
+ else
1363
+ flags = 0;
1364
+
1365
+ ret = media_create_pad_link(source_entity,
1366
+ pad,
1367
+ sink_entity,
1368
+ 0,
1369
+ flags);
1370
+ if (ret) {
1371
+ dev_err(dev->dev,
1372
+ "failed to create link for %s\n",
1373
+ linked_sensor.sd->name);
1374
+ break;
1375
+ }
1376
+ }
1377
+ }
1378
+ if (dev->chip_id > CHIP_RK1808_CIF) {
1379
+ for (id = 0; id < RKCIF_MAX_TOOLS_CH; id++) {
1380
+ source_entity = &linked_sensor.sd->entity;
1381
+ sink_entity = &dev->tools_vdev[id].vnode.vdev.entity;
1382
+
1383
+ if ((id + stream_num + pad_offset) == pad - 1 && !(*mipi_lvds_linked))
6821384 flags = MEDIA_LNK_FL_ENABLED;
6831385 else
6841386 flags = 0;
....@@ -697,24 +1399,49 @@
6971399 }
6981400 }
6991401 }
1402
+ }
7001403
701
- if (sensor->mbus.type == V4L2_MBUS_CCP2) {
702
- source_entity = &sensor->sd->entity;
703
- sink_entity = &linked_sensor.sd->entity;
704
- ret = media_create_pad_link(source_entity,
705
- 1,
706
- sink_entity,
707
- 0,
708
- MEDIA_LNK_FL_ENABLED);
709
- if (ret)
710
- dev_err(dev->dev, "failed to create link between %s and %s\n",
711
- linked_sensor.sd->name,
712
- sensor->sd->name);
713
- }
1404
+ if (sensor->mbus.type == V4L2_MBUS_CCP2) {
1405
+ source_entity = &sensor->sd->entity;
1406
+ sink_entity = &linked_sensor.sd->entity;
1407
+ ret = media_create_pad_link(source_entity,
1408
+ 1,
1409
+ sink_entity,
1410
+ 0,
1411
+ MEDIA_LNK_FL_ENABLED);
1412
+ if (ret)
1413
+ dev_err(dev->dev, "failed to create link between %s and %s\n",
1414
+ linked_sensor.sd->name,
1415
+ sensor->sd->name);
1416
+ }
7141417
715
- if (linked_sensor.mbus.type != V4L2_MBUS_BT656 &&
716
- linked_sensor.mbus.type != V4L2_MBUS_PARALLEL)
717
- mipi_lvds_linked = true;
1418
+ if (linked_sensor.mbus.type != V4L2_MBUS_BT656 &&
1419
+ linked_sensor.mbus.type != V4L2_MBUS_PARALLEL)
1420
+ *mipi_lvds_linked = true;
1421
+ return ret;
1422
+}
1423
+
1424
+/***************************** media controller *******************************/
1425
+static int rkcif_create_links(struct rkcif_device *dev)
1426
+{
1427
+ u32 s = 0;
1428
+ u32 stream_num = 0;
1429
+ bool mipi_lvds_linked = false;
1430
+
1431
+ if (dev->chip_id < CHIP_RV1126_CIF) {
1432
+ if (dev->inf_id == RKCIF_MIPI_LVDS)
1433
+ stream_num = RKCIF_MAX_STREAM_MIPI;
1434
+ else
1435
+ stream_num = RKCIF_SINGLE_STREAM;
1436
+ } else {
1437
+ stream_num = RKCIF_MAX_STREAM_MIPI;
1438
+ }
1439
+
1440
+ /* sensor links(or mipi-phy) */
1441
+ for (s = 0; s < dev->num_sensors; ++s) {
1442
+ struct rkcif_sensor_info *sensor = &dev->sensors[s];
1443
+
1444
+ rkcif_create_link(dev, sensor, stream_num, &mipi_lvds_linked);
7181445 }
7191446
7201447 return 0;
....@@ -728,11 +1455,20 @@
7281455
7291456 static int subdev_asyn_register_itf(struct rkcif_device *dev)
7301457 {
731
- struct sditf_priv *sditf = dev->sditf;
1458
+ struct sditf_priv *sditf = NULL;
7321459 int ret = 0;
7331460
734
- if (sditf)
1461
+ ret = rkcif_update_sensor_info(&dev->stream[0]);
1462
+ if (ret) {
1463
+ v4l2_err(&dev->v4l2_dev,
1464
+ "There is not terminal subdev, not synchronized with ISP\n");
1465
+ return 0;
1466
+ }
1467
+ sditf = dev->sditf[0];
1468
+ if (sditf && (!sditf->is_combine_mode) && (!dev->is_notifier_isp)) {
7351469 ret = v4l2_async_register_subdev_sensor_common(&sditf->sd);
1470
+ dev->is_notifier_isp = true;
1471
+ }
7361472
7371473 return ret;
7381474 }
....@@ -756,8 +1492,9 @@
7561492 if (sd->ops) {
7571493 if (sd == sensor->sd) {
7581494 ret = v4l2_subdev_call(sd,
759
- video,
760
- g_mbus_config,
1495
+ pad,
1496
+ get_mbus_config,
1497
+ 0,
7611498 &sensor->mbus);
7621499 if (ret)
7631500 v4l2_err(v4l2_dev,
....@@ -767,7 +1504,8 @@
7671504 }
7681505
7691506 if (sensor->mbus.type == V4L2_MBUS_CCP2 ||
770
- sensor->mbus.type == V4L2_MBUS_CSI2) {
1507
+ sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
1508
+ sensor->mbus.type == V4L2_MBUS_CSI2_CPHY) {
7711509
7721510 switch (sensor->mbus.flags & V4L2_MBUS_CSI2_LANES) {
7731511 case V4L2_MBUS_CSI2_1_LANE:
....@@ -821,6 +1559,18 @@
8211559 if (ret < 0)
8221560 goto unregister_lvds;
8231561
1562
+ if (!completion_done(&dev->cmpl_ntf))
1563
+ complete(&dev->cmpl_ntf);
1564
+ if (dev->active_sensor &&
1565
+ (dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_DPHY ||
1566
+ dev->active_sensor->mbus.type == V4L2_MBUS_CSI2_CPHY)) {
1567
+ ret = v4l2_subdev_call(dev->active_sensor->sd,
1568
+ core, ioctl,
1569
+ RKCIF_CMD_SET_CSI_IDX,
1570
+ &dev->csi_host_idx);
1571
+ if (ret)
1572
+ v4l2_err(&dev->v4l2_dev, "set csi idx %d fail\n", dev->csi_host_idx);
1573
+ }
8241574 v4l2_info(&dev->v4l2_dev, "Async subdev notifier completed\n");
8251575
8261576 return ret;
....@@ -874,13 +1624,15 @@
8741624
8751625 if (vep->bus_type != V4L2_MBUS_BT656 &&
8761626 vep->bus_type != V4L2_MBUS_PARALLEL &&
877
- vep->bus_type != V4L2_MBUS_CSI2 &&
1627
+ vep->bus_type != V4L2_MBUS_CSI2_DPHY &&
1628
+ vep->bus_type != V4L2_MBUS_CSI2_CPHY &&
8781629 vep->bus_type != V4L2_MBUS_CCP2)
8791630 return 0;
8801631
8811632 rk_asd->mbus.type = vep->bus_type;
8821633
883
- if (vep->bus_type == V4L2_MBUS_CSI2) {
1634
+ if (vep->bus_type == V4L2_MBUS_CSI2_DPHY ||
1635
+ vep->bus_type == V4L2_MBUS_CSI2_CPHY) {
8841636 rk_asd->mbus.flags = vep->bus.mipi_csi2.flags;
8851637 rk_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
8861638 } else if (vep->bus_type == V4L2_MBUS_CCP2) {
....@@ -903,6 +1655,8 @@
9031655 struct device *dev = cif_dev->dev;
9041656 int ret;
9051657
1658
+ v4l2_async_notifier_init(ntf);
1659
+
9061660 ret = v4l2_async_notifier_parse_fwnode_endpoints(
9071661 dev, ntf, sizeof(struct rkcif_async_subdev), rkcif_fwnode_parse);
9081662
....@@ -912,17 +1666,25 @@
9121666 return ret;
9131667 }
9141668
915
- if (!ntf->num_subdevs) {
916
- v4l2_warn(&cif_dev->v4l2_dev,
917
- "%s: no subdev be found!\n", __func__);
918
- return -ENODEV; /* no endpoint */
919
- }
920
-
9211669 ntf->ops = &subdev_notifier_ops;
9221670
9231671 ret = v4l2_async_notifier_register(&cif_dev->v4l2_dev, ntf);
9241672
9251673 return ret;
1674
+}
1675
+
1676
+static int notifier_isp_thread(void *data)
1677
+{
1678
+ struct rkcif_device *dev = data;
1679
+ int ret = 0;
1680
+
1681
+ ret = wait_for_completion_timeout(&dev->cmpl_ntf, msecs_to_jiffies(5000));
1682
+ if (ret) {
1683
+ mutex_lock(&rkcif_dev_mutex);
1684
+ subdev_asyn_register_itf(dev);
1685
+ mutex_unlock(&rkcif_dev_mutex);
1686
+ }
1687
+ return 0;
9261688 }
9271689
9281690 /***************************** platform deive *******************************/
....@@ -945,12 +1707,35 @@
9451707 stream_num = RKCIF_MAX_STREAM_MIPI;
9461708 ret = rkcif_register_stream_vdevs(cif_dev, stream_num, true);
9471709 }
948
- cif_dev->num_channels = stream_num;
1710
+
9491711 if (ret < 0) {
9501712 dev_err(cif_dev->dev, "cif register stream[%d] failed!\n", stream_num);
9511713 return -EINVAL;
9521714 }
9531715
1716
+ if (cif_dev->chip_id == CHIP_RK3588_CIF ||
1717
+ cif_dev->chip_id == CHIP_RV1106_CIF ||
1718
+ cif_dev->chip_id == CHIP_RK3562_CIF) {
1719
+ ret = rkcif_register_scale_vdevs(cif_dev, RKCIF_MAX_SCALE_CH, true);
1720
+
1721
+ if (ret < 0) {
1722
+ dev_err(cif_dev->dev, "cif register scale_vdev[%d] failed!\n", stream_num);
1723
+ goto err_unreg_stream_vdev;
1724
+ }
1725
+ }
1726
+ if (cif_dev->chip_id > CHIP_RK1808_CIF) {
1727
+ ret = rkcif_register_tools_vdevs(cif_dev, RKCIF_MAX_TOOLS_CH, true);
1728
+
1729
+ if (ret < 0) {
1730
+ dev_err(cif_dev->dev, "cif register tools_vdev[%d] failed!\n", RKCIF_MAX_TOOLS_CH);
1731
+ goto err_unreg_stream_vdev;
1732
+ }
1733
+ cif_dev->is_support_tools = true;
1734
+ } else {
1735
+ cif_dev->is_support_tools = false;
1736
+ }
1737
+ init_completion(&cif_dev->cmpl_ntf);
1738
+ kthread_run(notifier_isp_thread, cif_dev, "notifier isp");
9541739 ret = cif_subdev_notifier(cif_dev);
9551740 if (ret < 0) {
9561741 v4l2_err(&cif_dev->v4l2_dev,
....@@ -961,17 +1746,27 @@
9611746 return 0;
9621747 err_unreg_stream_vdev:
9631748 rkcif_unregister_stream_vdevs(cif_dev, stream_num);
1749
+ if (cif_dev->chip_id == CHIP_RK3588_CIF ||
1750
+ cif_dev->chip_id == CHIP_RV1106_CIF ||
1751
+ cif_dev->chip_id == CHIP_RK3562_CIF)
1752
+ rkcif_unregister_scale_vdevs(cif_dev, RKCIF_MAX_SCALE_CH);
1753
+
1754
+ if (cif_dev->chip_id > CHIP_RK1808_CIF)
1755
+ rkcif_unregister_tools_vdevs(cif_dev, RKCIF_MAX_TOOLS_CH);
9641756
9651757 return ret;
9661758 }
9671759
9681760 static irqreturn_t rkcif_irq_handler(int irq, struct rkcif_device *cif_dev)
9691761 {
970
- if (cif_dev->workmode == RKCIF_WORKMODE_PINGPONG)
971
- rkcif_irq_pingpong(cif_dev);
972
- else
1762
+ if (cif_dev->workmode == RKCIF_WORKMODE_PINGPONG) {
1763
+ if (cif_dev->chip_id < CHIP_RK3588_CIF)
1764
+ rkcif_irq_pingpong(cif_dev);
1765
+ else
1766
+ rkcif_irq_pingpong_v1(cif_dev);
1767
+ } else {
9731768 rkcif_irq_oneframe(cif_dev);
974
-
1769
+ }
9751770 return IRQ_HANDLED;
9761771 }
9771772
....@@ -982,23 +1777,35 @@
9821777 return IRQ_HANDLED;
9831778 }
9841779
985
-void rkcif_soft_reset(struct rkcif_device *cif_dev, bool is_rst_iommu)
1780
+static void rkcif_attach_dphy_hw(struct rkcif_device *cif_dev)
9861781 {
987
- struct rkcif_hw *hw_dev = cif_dev->hw_dev;
988
- bool can_reset = true;
989
- int i;
1782
+ struct platform_device *plat_dev;
1783
+ struct device *dev = cif_dev->dev;
1784
+ struct device_node *np;
1785
+ struct csi2_dphy_hw *dphy_hw;
9901786
991
- if (!cif_dev->hw_dev)
1787
+ np = of_parse_phandle(dev->of_node, "rockchip,dphy_hw", 0);
1788
+ if (!np || !of_device_is_available(np)) {
1789
+ dev_err(dev,
1790
+ "failed to get dphy hw node\n");
9921791 return;
1792
+ }
9931793
994
- for (i = 0; i < hw_dev->dev_num; i++)
995
- if (atomic_read(&hw_dev->cif_dev[i]->pipe.stream_cnt) != 0) {
996
- can_reset = false;
997
- break;
998
- }
1794
+ plat_dev = of_find_device_by_node(np);
1795
+ of_node_put(np);
1796
+ if (!plat_dev) {
1797
+ dev_err(dev,
1798
+ "failed to get dphy hw from node\n");
1799
+ return;
1800
+ }
9991801
1000
- if (can_reset)
1001
- rkcif_hw_soft_reset(cif_dev->hw_dev, is_rst_iommu);
1802
+ dphy_hw = platform_get_drvdata(plat_dev);
1803
+ if (!dphy_hw) {
1804
+ dev_err(dev,
1805
+ "failed attach dphy hw\n");
1806
+ return;
1807
+ }
1808
+ cif_dev->dphy_hw = dphy_hw;
10021809 }
10031810
10041811 int rkcif_attach_hw(struct rkcif_device *cif_dev)
....@@ -1035,6 +1842,8 @@
10351842 cif_dev->hw_dev = hw;
10361843 cif_dev->chip_id = hw->chip_id;
10371844 dev_info(cif_dev->dev, "attach to cif hw node\n");
1845
+ if (IS_ENABLED(CONFIG_CPU_RV1106))
1846
+ rkcif_attach_dphy_hw(cif_dev);
10381847
10391848 return 0;
10401849 }
....@@ -1065,8 +1874,26 @@
10651874 static void rkcif_init_reset_monitor(struct rkcif_device *dev)
10661875 {
10671876 struct rkcif_timer *timer = &dev->reset_watchdog_timer;
1068
- struct notifier_block *notifier = &dev->reset_notifier;
10691877
1878
+#if defined(CONFIG_ROCKCHIP_CIF_USE_MONITOR)
1879
+ timer->monitor_mode = CONFIG_ROCKCHIP_CIF_MONITOR_MODE;
1880
+ timer->err_time_interval = CONFIG_ROCKCHIP_CIF_MONITOR_KEEP_TIME;
1881
+ timer->frm_num_of_monitor_cycle = CONFIG_ROCKCHIP_CIF_MONITOR_CYCLE;
1882
+ timer->triggered_frame_num = CONFIG_ROCKCHIP_CIF_MONITOR_START_FRAME;
1883
+ timer->csi2_err_ref_cnt = CONFIG_ROCKCHIP_CIF_MONITOR_ERR_CNT;
1884
+ #if defined(CONFIG_ROCKCHIP_CIF_RESET_BY_USER)
1885
+ timer->is_ctrl_by_user = true;
1886
+ #else
1887
+ timer->is_ctrl_by_user = false;
1888
+ #endif
1889
+#else
1890
+ timer->monitor_mode = RKCIF_MONITOR_MODE_IDLE;
1891
+ timer->err_time_interval = 0xffffffff;
1892
+ timer->frm_num_of_monitor_cycle = 0xffffffff;
1893
+ timer->triggered_frame_num = 0xffffffff;
1894
+ timer->csi2_err_ref_cnt = 0xffffffff;
1895
+#endif
1896
+ timer->is_running = false;
10701897 timer->is_triggered = false;
10711898 timer->is_buf_stop_update = false;
10721899 timer->csi2_err_cnt_even = 0;
....@@ -1076,11 +1903,8 @@
10761903 timer->csi2_err_triggered_cnt = 0;
10771904 timer->csi2_first_err_timestamp = 0;
10781905
1079
- if (dev->inf_id == RKCIF_MIPI_LVDS) {
1080
- notifier->priority = 1;
1081
- notifier->notifier_call = rkcif_reset_notifier;
1082
- rkcif_csi2_register_notifier(notifier);
1083
- }
1906
+ timer_setup(&timer->timer, rkcif_reset_watchdog_timer_handler, 0);
1907
+
10841908 INIT_WORK(&dev->reset_work.work, rkcif_reset_work);
10851909 }
10861910
....@@ -1090,22 +1914,36 @@
10901914 struct v4l2_device *v4l2_dev;
10911915 int ret;
10921916
1093
- cif_dev->hdr.mode = NO_HDR;
1917
+ cif_dev->hdr.hdr_mode = NO_HDR;
10941918 cif_dev->inf_id = inf_id;
10951919
10961920 mutex_init(&cif_dev->stream_lock);
1921
+ mutex_init(&cif_dev->scale_lock);
1922
+ mutex_init(&cif_dev->tools_lock);
10971923 spin_lock_init(&cif_dev->hdr_lock);
1924
+ spin_lock_init(&cif_dev->buffree_lock);
1925
+ spin_lock_init(&cif_dev->reset_watchdog_timer.timer_lock);
10981926 spin_lock_init(&cif_dev->reset_watchdog_timer.csi2_err_lock);
10991927 atomic_set(&cif_dev->pipe.power_cnt, 0);
11001928 atomic_set(&cif_dev->pipe.stream_cnt, 0);
1101
- atomic_set(&cif_dev->fh_cnt, 0);
1929
+ atomic_set(&cif_dev->power_cnt, 0);
11021930 cif_dev->is_start_hdr = false;
11031931 cif_dev->pipe.open = rkcif_pipeline_open;
11041932 cif_dev->pipe.close = rkcif_pipeline_close;
11051933 cif_dev->pipe.set_stream = rkcif_pipeline_set_stream;
11061934 cif_dev->isr_hdl = rkcif_irq_handler;
1935
+ cif_dev->id_use_cnt = 0;
1936
+ memset(&cif_dev->sync_cfg, 0, sizeof(cif_dev->sync_cfg));
1937
+ cif_dev->sditf_cnt = 0;
1938
+ cif_dev->is_notifier_isp = false;
1939
+ cif_dev->sensor_linetime = 0;
1940
+ cif_dev->early_line = 0;
1941
+ cif_dev->is_thunderboot = false;
1942
+ cif_dev->rdbk_debug = 0;
11071943 if (cif_dev->chip_id == CHIP_RV1126_CIF_LITE)
11081944 cif_dev->isr_hdl = rkcif_irq_lite_handler;
1945
+
1946
+ INIT_WORK(&cif_dev->err_state_work.work, rkcif_err_print_work);
11091947
11101948 if (cif_dev->chip_id < CHIP_RV1126_CIF) {
11111949 if (cif_dev->inf_id == RKCIF_MIPI_LVDS) {
....@@ -1124,6 +1962,20 @@
11241962 rkcif_stream_init(cif_dev, RKCIF_STREAM_MIPI_ID3);
11251963 }
11261964
1965
+ if (cif_dev->chip_id == CHIP_RK3588_CIF ||
1966
+ cif_dev->chip_id == CHIP_RV1106_CIF ||
1967
+ cif_dev->chip_id == CHIP_RK3562_CIF) {
1968
+ rkcif_init_scale_vdev(cif_dev, RKCIF_SCALE_CH0);
1969
+ rkcif_init_scale_vdev(cif_dev, RKCIF_SCALE_CH1);
1970
+ rkcif_init_scale_vdev(cif_dev, RKCIF_SCALE_CH2);
1971
+ rkcif_init_scale_vdev(cif_dev, RKCIF_SCALE_CH3);
1972
+ }
1973
+
1974
+ if (cif_dev->chip_id > CHIP_RK1808_CIF) {
1975
+ rkcif_init_tools_vdev(cif_dev, RKCIF_TOOLS_CH0);
1976
+ rkcif_init_tools_vdev(cif_dev, RKCIF_TOOLS_CH1);
1977
+ rkcif_init_tools_vdev(cif_dev, RKCIF_TOOLS_CH2);
1978
+ }
11271979 #if defined(CONFIG_ROCKCHIP_CIF_WORKMODE_PINGPONG)
11281980 cif_dev->workmode = RKCIF_WORKMODE_PINGPONG;
11291981 #elif defined(CONFIG_ROCKCHIP_CIF_WORKMODE_ONEFRAME)
....@@ -1137,9 +1989,14 @@
11371989 #else
11381990 cif_dev->is_use_dummybuf = false;
11391991 #endif
1992
+ if (cif_dev->chip_id == CHIP_RV1106_CIF)
1993
+ cif_dev->is_use_dummybuf = false;
11401994
11411995 strlcpy(cif_dev->media_dev.model, dev_name(dev),
11421996 sizeof(cif_dev->media_dev.model));
1997
+ cif_dev->csi_host_idx = of_alias_get_id(node, "rkcif_mipi_lvds");
1998
+ if (cif_dev->csi_host_idx < 0 || cif_dev->csi_host_idx > 5)
1999
+ cif_dev->csi_host_idx = 0;
11432000 cif_dev->media_dev.dev = dev;
11442001 v4l2_dev = &cif_dev->v4l2_dev;
11452002 v4l2_dev->mdev = &cif_dev->media_dev;
....@@ -1204,6 +2061,8 @@
12042061 }
12052062 rkcif_unregister_stream_vdevs(cif_dev, stream_num);
12062063
2064
+ if (cif_dev->chip_id == CHIP_RV1106_CIF)
2065
+ rkcif_rockit_dev_deinit();
12072066 return 0;
12082067 }
12092068
....@@ -1240,6 +2099,35 @@
12402099 dev_info(cif_dev->dev, "rkcif wait line %d\n", cif_dev->wait_line);
12412100 }
12422101
2102
+static int rkcif_get_reserved_mem(struct rkcif_device *cif_dev)
2103
+{
2104
+ struct device *dev = cif_dev->dev;
2105
+ struct device_node *np;
2106
+ struct resource r;
2107
+ int ret;
2108
+
2109
+ /* Get reserved memory region from Device-tree */
2110
+ np = of_parse_phandle(dev->of_node, "memory-region-thunderboot", 0);
2111
+ if (!np) {
2112
+ dev_info(dev, "No memory-region-thunderboot specified\n");
2113
+ return 0;
2114
+ }
2115
+
2116
+ ret = of_address_to_resource(np, 0, &r);
2117
+ if (ret) {
2118
+ dev_err(dev, "No memory address assigned to the region\n");
2119
+ return ret;
2120
+ }
2121
+
2122
+ cif_dev->resmem_pa = r.start;
2123
+ cif_dev->resmem_size = resource_size(&r);
2124
+ cif_dev->is_thunderboot = true;
2125
+ dev_info(dev, "Allocated reserved memory, paddr: 0x%x, size 0x%x\n",
2126
+ (u32)cif_dev->resmem_pa,
2127
+ (u32)cif_dev->resmem_size);
2128
+ return ret;
2129
+}
2130
+
12432131 static int rkcif_plat_probe(struct platform_device *pdev)
12442132 {
12452133 const struct of_device_id *match;
....@@ -1268,6 +2156,9 @@
12682156 dev_set_drvdata(dev, cif_dev);
12692157 cif_dev->dev = dev;
12702158
2159
+ if (sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp))
2160
+ return -ENODEV;
2161
+
12712162 rkcif_attach_hw(cif_dev);
12722163
12732164 rkcif_parse_dts(cif_dev);
....@@ -1278,14 +2169,16 @@
12782169 return ret;
12792170 }
12802171
1281
- if (sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp))
1282
- return -ENODEV;
2172
+ ret = rkcif_get_reserved_mem(cif_dev);
2173
+ if (ret)
2174
+ return ret;
12832175
12842176 if (rkcif_proc_init(cif_dev))
12852177 dev_warn(dev, "dev:%s create proc failed\n", dev_name(dev));
12862178
12872179 rkcif_init_reset_monitor(cif_dev);
1288
- rkcif_soft_reset(cif_dev, false);
2180
+ if (cif_dev->chip_id == CHIP_RV1106_CIF)
2181
+ rkcif_rockit_dev_init(cif_dev);
12892182 pm_runtime_enable(&pdev->dev);
12902183
12912184 return 0;
....@@ -1298,8 +2191,8 @@
12982191 rkcif_plat_uninit(cif_dev);
12992192 rkcif_detach_hw(cif_dev);
13002193 rkcif_proc_cleanup(cif_dev);
1301
- rkcif_csi2_unregister_notifier(&cif_dev->reset_notifier);
13022194 sysfs_remove_group(&pdev->dev.kobj, &dev_attr_grp);
2195
+ del_timer_sync(&cif_dev->reset_watchdog_timer.timer);
13032196
13042197 return 0;
13052198 }
....@@ -1309,7 +2202,7 @@
13092202 struct rkcif_device *cif_dev = dev_get_drvdata(dev);
13102203 int ret = 0;
13112204
1312
- if (atomic_dec_return(&cif_dev->hw_dev->power_cnt))
2205
+ if (atomic_dec_return(&cif_dev->power_cnt))
13132206 return 0;
13142207
13152208 mutex_lock(&cif_dev->hw_dev->dev_lock);
....@@ -1323,11 +2216,13 @@
13232216 struct rkcif_device *cif_dev = dev_get_drvdata(dev);
13242217 int ret = 0;
13252218
1326
- if (atomic_inc_return(&cif_dev->hw_dev->power_cnt) > 1)
2219
+ if (atomic_inc_return(&cif_dev->power_cnt) > 1)
13272220 return 0;
2221
+
13282222 mutex_lock(&cif_dev->hw_dev->dev_lock);
1329
- ret = pm_runtime_get_sync(cif_dev->hw_dev->dev);
2223
+ ret = pm_runtime_resume_and_get(cif_dev->hw_dev->dev);
13302224 mutex_unlock(&cif_dev->hw_dev->dev_lock);
2225
+ rkcif_do_soft_reset(cif_dev);
13312226 return (ret > 0) ? 0 : ret;
13322227 }
13332228
....@@ -1360,14 +2255,16 @@
13602255 MODULE_PARM_DESC(clr_unready_dev, "clear unready devices");
13612256
13622257 #ifndef MODULE
1363
-static int __init rkcif_clr_unready_dev(void)
2258
+int rkcif_clr_unready_dev(void)
13642259 {
13652260 __rkcif_clr_unready_dev();
13662261
13672262 return 0;
13682263 }
2264
+#ifndef CONFIG_VIDEO_REVERSE_IMAGE
13692265 late_initcall(rkcif_clr_unready_dev);
13702266 #endif
2267
+#endif
13712268
13722269 static const struct dev_pm_ops rkcif_plat_pm_ops = {
13732270 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,