forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/media/spi/rk1608_core.c
....@@ -556,16 +556,17 @@
556556 }
557557
558558 static int rk1608_msg_init_sensor(struct rk1608_state *pdata,
559
- struct msg_init *msg, int id)
559
+ struct msg_init *msg, int in_mipi, int out_mipi,
560
+ int id, int cam_id)
560561 {
561562 u32 idx = pdata->dphy[id]->fmt_inf_idx;
562563
563564 msg->msg_head.size = sizeof(struct msg_init);
564565 msg->msg_head.type = id_msg_init_sensor_t;
565
- msg->msg_head.id.camera_id = id;
566
+ msg->msg_head.id.camera_id = cam_id;
566567 msg->msg_head.mux.sync = 1;
567
- msg->in_mipi_phy = pdata->dphy[id]->in_mipi;
568
- msg->out_mipi_phy = pdata->dphy[id]->out_mipi;
568
+ msg->in_mipi_phy = in_mipi;
569
+ msg->out_mipi_phy = out_mipi;
569570 msg->mipi_lane = pdata->dphy[id]->fmt_inf[idx].mipi_lane;
570571 msg->bayer = 0;
571572 memcpy(msg->sensor_name, pdata->dphy[id]->sensor_name,
....@@ -573,6 +574,7 @@
573574
574575 msg->i2c_slave_addr = pdata->dphy[id]->i2c_addr;
575576 msg->i2c_bus = pdata->dphy[id]->i2c_bus;
577
+ msg->sub_sensor_num = pdata->dphy[id]->sub_sensor_num;
576578
577579 return rk1608_send_msg_to_dsp(pdata, &msg->msg_head);
578580 }
....@@ -580,22 +582,25 @@
580582 static int rk1608_msg_init_dsp_time(struct rk1608_state *pdata,
581583 struct msg_init_dsp_time *msg, int id)
582584 {
583
- struct timeval tv;
585
+ u64 usecs64;
586
+ u32 mod;
584587
585588 msg->msg_head.size = sizeof(struct msg_init_dsp_time);
586589 msg->msg_head.type = id_msg_sys_time_set_t;
587590 msg->msg_head.id.camera_id = id;
588591 msg->msg_head.mux.sync = 0;
589592
590
- do_gettimeofday(&tv);
591
- msg->tv_sec = tv.tv_sec;
592
- msg->tv_usec = tv.tv_usec;
593
+ usecs64 = ktime_to_us(ktime_get());
594
+
595
+ mod = do_div(usecs64, USEC_PER_MSEC);
596
+ msg->tv_usec = mod;
597
+ msg->tv_sec = usecs64;
593598
594599 return rk1608_send_msg_to_dsp(pdata, &msg->msg_head);
595600 }
596601
597602 static int rk1608_msg_set_input_size(struct rk1608_state *pdata,
598
- struct msg_in_size *msg, int id)
603
+ struct msg_in_size *msg, int id, int cam_id)
599604 {
600605 u32 i;
601606 u32 msg_size = sizeof(struct msg);
....@@ -617,14 +622,14 @@
617622
618623 msg->msg_head.size = msg_size / sizeof(int);
619624 msg->msg_head.type = id_msg_set_input_size_t;
620
- msg->msg_head.id.camera_id = id;
625
+ msg->msg_head.id.camera_id = cam_id;
621626 msg->msg_head.mux.sync = 1;
622627
623628 return rk1608_send_msg_to_dsp(pdata, &msg->msg_head);
624629 }
625630
626631 static int rk1608_msg_set_output_size(struct rk1608_state *pdata,
627
- struct msg_set_output_size *msg, int id)
632
+ struct msg_set_output_size *msg, int id, int cam_id)
628633 {
629634 u32 i;
630635 u32 msg_size = sizeof(struct msg_out_size_head);
....@@ -646,14 +651,14 @@
646651
647652 msg->head.msg_head.size = msg_size / sizeof(int);
648653 msg->head.msg_head.type = id_msg_set_output_size_t;
649
- msg->head.msg_head.id.camera_id = id;
654
+ msg->head.msg_head.id.camera_id = cam_id;
650655 msg->head.msg_head.mux.sync = 1;
651656 msg->head.width = fmt_inf->hactive;
652657 msg->head.height = fmt_inf->vactive;
653658 msg->head.mipi_clk = 2 * pdata->dphy[id]->link_freqs;
654659 msg->head.line_length_pclk = fmt_inf->htotal;
655660 msg->head.frame_length_lines = fmt_inf->vtotal;
656
- msg->head.mipi_lane = fmt_inf->mipi_lane;
661
+ msg->head.mipi_lane = fmt_inf->mipi_lane_out;
657662 msg->head.flip = pdata->flip;
658663
659664 return rk1608_send_msg_to_dsp(pdata, &msg->head.msg_head);
....@@ -930,6 +935,54 @@
930935 return ret;
931936 }
932937
938
+static int rk1608_init_virtual_sub_sensor(
939
+ struct rk1608_state *pdata, int id, int index)
940
+{
941
+ struct msg *msg = NULL;
942
+ struct msg_init *msg_init = NULL;
943
+ struct msg_in_size *msg_in_size = NULL;
944
+ struct msg_set_output_size *msg_out_size = NULL;
945
+ int cam_id = pdata->dphy[id]->sub_sensor[index].id;
946
+ int in_mipi = pdata->dphy[id]->sub_sensor[index].in_mipi;
947
+ int out_mipi = pdata->dphy[id]->sub_sensor[index].out_mipi;
948
+ int ret = 0;
949
+
950
+ msg = kzalloc(sizeof(*msg), GFP_KERNEL);
951
+ if (!msg) {
952
+ ret = -ENOMEM;
953
+ goto err;
954
+ }
955
+ msg_init = kzalloc(sizeof(*msg_init), GFP_KERNEL);
956
+ if (!msg_init) {
957
+ ret = -ENOMEM;
958
+ goto err;
959
+ }
960
+
961
+ msg_in_size = kzalloc(sizeof(*msg_in_size), GFP_KERNEL);
962
+ if (!msg_in_size) {
963
+ ret = -ENOMEM;
964
+ goto err;
965
+ }
966
+ msg_out_size = kzalloc(sizeof(*msg_out_size), GFP_KERNEL);
967
+ if (!msg_out_size) {
968
+ ret = -ENOMEM;
969
+ goto err;
970
+ }
971
+
972
+ ret = rk1608_msg_init_sensor(pdata, msg_init, in_mipi, out_mipi, id, cam_id);
973
+ ret |= rk1608_msg_set_input_size(pdata, msg_in_size, id, cam_id);
974
+ ret |= rk1608_msg_set_output_size(pdata, msg_out_size, id, cam_id);
975
+ ret |= rk1608_msg_set_stream_in_on(pdata, msg, cam_id);
976
+
977
+err:
978
+ kfree(msg_init);
979
+ kfree(msg_in_size);
980
+ kfree(msg_out_size);
981
+ kfree(msg);
982
+
983
+ return ret;
984
+}
985
+
933986 static int rk1608_init_sensor(struct rk1608_state *pdata, int id)
934987 {
935988 struct msg *msg = NULL;
....@@ -937,6 +990,9 @@
937990 struct msg_in_size *msg_in_size = NULL;
938991 struct msg_set_output_size *msg_out_size = NULL;
939992 struct msg_init_dsp_time *msg_init_time = NULL;
993
+ int in_mipi = pdata->dphy[id]->in_mipi;
994
+ int out_mipi = pdata->dphy[id]->out_mipi;
995
+ int cam_id = id;
940996 int ret = 0;
941997
942998 if (!pdata->sensor[id]) {
....@@ -972,12 +1028,13 @@
9721028 goto err;
9731029 }
9741030
975
- ret = rk1608_msg_init_sensor(pdata, msg_init, id);
1031
+
1032
+ ret = rk1608_msg_init_sensor(pdata, msg_init, in_mipi, out_mipi, id, cam_id);
9761033 ret |= rk1608_msg_init_dsp_time(pdata, msg_init_time, id);
977
- ret |= rk1608_msg_set_input_size(pdata, msg_in_size, id);
978
- ret |= rk1608_msg_set_output_size(pdata, msg_out_size, id);
979
- ret |= rk1608_msg_set_stream_in_on(pdata, msg, id);
980
- ret |= rk1608_msg_set_stream_out_on(pdata, msg, id);
1034
+ ret |= rk1608_msg_set_input_size(pdata, msg_in_size, id, cam_id);
1035
+ ret |= rk1608_msg_set_output_size(pdata, msg_out_size, id, cam_id);
1036
+ ret |= rk1608_msg_set_stream_in_on(pdata, msg, cam_id);
1037
+ ret |= rk1608_msg_set_stream_out_on(pdata, msg, cam_id);
9811038
9821039 err:
9831040 kfree(msg_init);
....@@ -1029,6 +1086,9 @@
10291086 {
10301087 struct spi_device *spi = pdata->spi;
10311088 int ret = 0;
1089
+
1090
+ if (pdata->pwren_gpio)
1091
+ gpiod_direction_output(pdata->pwren_gpio, 1);
10321092
10331093 if (!IS_ERR(pdata->mclk)) {
10341094 ret = clk_set_rate(pdata->mclk, RK1608_MCLK_RATE);
....@@ -1093,6 +1153,9 @@
10931153 if (pdata->reset_gpio)
10941154 gpiod_direction_output(pdata->reset_gpio, 0);
10951155 rk1608_cs_set_value(pdata, 0);
1156
+
1157
+ if (pdata->pwren_gpio)
1158
+ gpiod_direction_output(pdata->pwren_gpio, 0);
10961159
10971160 if (!IS_ERR(pdata->mclk))
10981161 clk_disable_unprepare(pdata->mclk);
....@@ -1166,11 +1229,25 @@
11661229 static int rk1608_stream_on(struct rk1608_state *pdata)
11671230 {
11681231 int id = 0, cnt = 0, ret = 0;
1232
+ int sub_sensor_num = 0, index = 0;
11691233
11701234 mutex_lock(&pdata->lock);
11711235 id = pdata->sd.grp_id;
11721236 pdata->sensor_cnt = 0;
11731237 pdata->set_exp_cnt = 1;
1238
+
1239
+ sub_sensor_num = pdata->dphy[id]->sub_sensor_num;
1240
+ for (index = 0; index < sub_sensor_num; index++) {
1241
+ ret = rk1608_init_virtual_sub_sensor(pdata, id, index);
1242
+ if (ret) {
1243
+ dev_err(pdata->dev, "Init rk1608[%d] sub[%d] is failed!",
1244
+ id,
1245
+ index);
1246
+ mutex_unlock(&pdata->lock);
1247
+ return ret;
1248
+ }
1249
+ }
1250
+
11741251 ret = rk1608_init_sensor(pdata, id);
11751252 if (ret) {
11761253 dev_err(pdata->dev, "Init rk1608[%d] is failed!",
....@@ -1212,12 +1289,31 @@
12121289
12131290 static int rk1608_stream_off(struct rk1608_state *pdata)
12141291 {
1292
+ u32 sub_sensor_num = 0, index = 0, sub_id = 0;
1293
+
12151294 mutex_lock(&pdata->sensor_lock);
12161295 pdata->sensor_cnt = 0;
12171296 mutex_unlock(&pdata->sensor_lock);
1297
+
1298
+ sub_sensor_num = pdata->dphy[pdata->sd.grp_id]->sub_sensor_num;
1299
+ for (index = 0; index < sub_sensor_num; index++) {
1300
+ sub_id = pdata->dphy[pdata->sd.grp_id]->sub_sensor[index].id;
1301
+ rk1608_deinit(pdata, sub_id);
1302
+ }
1303
+
12181304 rk1608_deinit(pdata, pdata->sd.grp_id);
12191305
12201306 return 0;
1307
+}
1308
+
1309
+static int rk1608_set_quick_stream(struct rk1608_state *pdata, void *args)
1310
+{
1311
+ u32 stream = *(u32 *)args;
1312
+
1313
+ if (stream)
1314
+ return rk1608_stream_on(pdata);
1315
+ else
1316
+ return rk1608_stream_off(pdata);
12211317 }
12221318
12231319 static int rk1608_s_stream(struct v4l2_subdev *sd, int enable)
....@@ -1338,6 +1434,9 @@
13381434 break;
13391435 case PREISP_DISP_SET_LED_ON_OFF:
13401436 rk1608_disp_set_led_on_off(pdata, arg);
1437
+ break;
1438
+ case RKMODULE_SET_QUICK_STREAM:
1439
+ rk1608_set_quick_stream(pdata, arg);
13411440 break;
13421441 default:
13431442 return -ENOTTY;
....@@ -1880,7 +1979,6 @@
18801979 unsigned int file_size = 0;
18811980 unsigned int write_size = 0;
18821981 char *file_data = NULL;
1883
- struct kstat *stat;
18841982 struct msg_xfile *xfile;
18851983
18861984 char *ref_data_path = REF_DATA_PATH;
....@@ -1899,30 +1997,21 @@
18991997 return -EFAULT;
19001998 }
19011999
1902
- stat = kmalloc(sizeof(*stat), GFP_KERNEL);
1903
- if (!stat) {
1904
- ret = -ENOMEM;
1905
- goto err;
1906
- }
1907
-
1908
- vfs_stat(file_path, stat);
1909
-
1910
- file_size = stat->size;
1911
- file_size = (file_size+0x3)&(~0x3);
1912
-
19132000 dev_info(pdata->dev, "start import %s to addr:0x%x size:%d\n",
1914
- file_path, xfile->addr, file_size);
2001
+ file_path, xfile->addr, xfile->data_size);
19152002
1916
- file_data = vmalloc(file_size);
2003
+ file_data = vmalloc(xfile->data_size);
19172004 if (!file_data) {
19182005 ret = -ENOMEM;
19192006 goto err;
19202007 }
19212008
1922
- ret = kernel_read(fp, file_data, file_size, &pos);
1923
- if (ret <= 0)
2009
+ file_size = kernel_read(fp, file_data, xfile->data_size, &pos);
2010
+ if (file_size <= 0) {
19242011 dev_err(pdata->dev, "%s: read error: ret=%d\n",
19252012 __func__, ret);
2013
+ goto err;
2014
+ }
19262015
19272016 write_size = (file_size <= xfile->data_size)?file_size:xfile->data_size;
19282017 if (file_size != xfile->data_size)
....@@ -1946,7 +2035,6 @@
19462035 xfile->path, xfile->addr, file_size);
19472036
19482037 err:
1949
- kfree(stat);
19502038 if (file_data)
19512039 vfree(file_data);
19522040 if (fp)
....@@ -2098,7 +2186,7 @@
20982186 goto err;
20992187 }
21002188
2101
- if (head->item[i].size > 128) {
2189
+ if (head->item[i].size > sizeof(calibdata_->calib_sn_code)) {
21022190 dev_err(pdata->dev, "%s: %s size:%d error!\n",
21032191 __func__, head->item[i].name, head->item[i].size);
21042192 goto err;
....@@ -2115,7 +2203,7 @@
21152203
21162204 pos = head->item[i].offset;
21172205
2118
- ret = kernel_read(fp, (char *)&calibdata_->calib_sn_code, head->item[i].size, &pos);
2206
+ ret = kernel_read(fp, (char *)calibdata_->calib_sn_code, head->item[i].size, &pos);
21192207 if (ret <= 0) {
21202208 dev_err(pdata->dev, "%s: read error: ret=%d\n", __func__, ret);
21212209 goto err;
....@@ -2299,7 +2387,7 @@
22992387 #define PREISP_DCROP_CALIB_RATIO 192
23002388 #define PREISP_DCROP_CALIB_XOFFSET 196
23012389 #define PREISP_DCROP_CALIB_YOFFSET 198
2302
-static int rk1608_get_dcrop_cfg(struct v4l2_rect *crop_in,
2390
+int rk1608_get_dcrop_cfg(struct v4l2_rect *crop_in,
23032391 struct v4l2_rect *crop_out)
23042392 {
23052393 struct file *fp;
....@@ -2706,3 +2794,4 @@
27062794 MODULE_AUTHOR("Rockchip Camera/ISP team");
27072795 MODULE_DESCRIPTION("A DSP driver for rk1608 chip");
27082796 MODULE_LICENSE("GPL v2");
2797
+MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);