forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/media/i2c/sc210iot.c
....@@ -89,14 +89,6 @@
8989 #define to_sc210iot(sd) container_of(sd, struct sc210iot, subdev)
9090
9191 enum {
92
- PAD0,
93
- PAD1,
94
- PAD2,
95
- PAD3,
96
- PAD_MAX,
97
-};
98
-
99
-enum {
10092 LINK_FREQ_INDEX,
10193 };
10294
....@@ -148,6 +140,8 @@
148140 struct v4l2_ctrl *link_freq;
149141 struct v4l2_ctrl *pixel_rate;
150142 struct mutex lock;
143
+ struct v4l2_fract cur_fps;
144
+ u32 cur_vts;
151145 bool streaming;
152146 bool power_on;
153147 bool is_thunderboot;
....@@ -371,6 +365,14 @@
371365 return ret;
372366 }
373367
368
+static void sc210iot_modify_fps_info(struct sc210iot *sc210iot)
369
+{
370
+ const struct sc210iot_mode *mode = sc210iot->cur_mode;
371
+
372
+ sc210iot->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def /
373
+ sc210iot->cur_vts;
374
+}
375
+
374376 static int sc210iot_set_ctrl(struct v4l2_ctrl *ctrl)
375377 {
376378 struct sc210iot *sc210iot = container_of(ctrl->handler,
....@@ -402,8 +404,12 @@
402404 dev_dbg(sc210iot->dev, "set vblank 0x%x\n", ctrl->val);
403405 ret = sc210iot_write_reg(sc210iot, SC210IOT_REG_VTS_H,
404406 (ctrl->val + sc210iot->cur_mode->height) >> 8);
405
- ret = sc210iot_write_reg(sc210iot, SC210IOT_REG_VTS_L,
407
+ ret |= sc210iot_write_reg(sc210iot, SC210IOT_REG_VTS_L,
406408 (ctrl->val + sc210iot->cur_mode->height) & 0xff);
409
+ if (!ret)
410
+ sc210iot->cur_vts = ctrl->val + sc210iot->cur_mode->height;
411
+ if (sc210iot->cur_vts != sc210iot->cur_mode->vts_def)
412
+ sc210iot_modify_fps_info(sc210iot);
407413 break;
408414 case V4L2_CID_HFLIP:
409415 regmap_update_bits(sc210iot->regmap, SC210IOT_REG_MIRROR_FLIP,
....@@ -487,6 +493,8 @@
487493 }
488494 sc210iot->subdev.ctrl_handler = handler;
489495 sc210iot->has_init_exp = false;
496
+ sc210iot->cur_fps = mode->max_fps;
497
+ sc210iot->cur_vts = mode->vts_def;
490498 return 0;
491499 err_free_handler:
492500 v4l2_ctrl_handler_free(handler);
....@@ -687,8 +695,11 @@
687695 return ret;
688696 }
689697 ret = sc210iot_ioctl(sd, cmd, inf);
690
- if (!ret)
698
+ if (!ret) {
691699 ret = copy_to_user(up, inf, sizeof(*inf));
700
+ if (ret)
701
+ ret = -EFAULT;
702
+ }
692703 kfree(inf);
693704 break;
694705 case RKMODULE_GET_HDR_CFG:
....@@ -698,16 +709,19 @@
698709 return ret;
699710 }
700711 ret = sc210iot_ioctl(sd, cmd, hdr);
701
- if (!ret)
712
+ if (!ret) {
702713 ret = copy_to_user(up, hdr, sizeof(*hdr));
714
+ if (ret)
715
+ ret = -EFAULT;
716
+ }
703717 kfree(hdr);
704
- break;
705
- case RKMODULE_SET_HDR_CFG:
706718 break;
707719 case RKMODULE_SET_QUICK_STREAM:
708720 ret = copy_from_user(&stream, up, sizeof(u32));
709721 if (!ret)
710722 ret = sc210iot_ioctl(sd, cmd, &stream);
723
+ else
724
+ ret = -EFAULT;
711725 break;
712726 default:
713727 ret = -ENOIOCTLCMD;
....@@ -758,20 +772,21 @@
758772 struct sc210iot *sc210iot = to_sc210iot(sd);
759773 const struct sc210iot_mode *mode = sc210iot->cur_mode;
760774
761
- mutex_lock(&sc210iot->lock);
762
- fi->interval = mode->max_fps;
763
- mutex_unlock(&sc210iot->lock);
775
+ if (sc210iot->streaming)
776
+ fi->interval = sc210iot->cur_fps;
777
+ else
778
+ fi->interval = mode->max_fps;
764779 return 0;
765780 }
766781
767
-static int sc210iot_g_mbus_config(struct v4l2_subdev *sd,
782
+static int sc210iot_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
768783 struct v4l2_mbus_config *config)
769784 {
770785 struct sc210iot *sc210iot = to_sc210iot(sd);
771786
772787 u32 val = 1 << (SC210IOT_LANES - 1) | V4L2_MBUS_CSI2_CHANNEL_0 |
773788 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
774
- config->type = V4L2_MBUS_CSI2;
789
+ config->type = V4L2_MBUS_CSI2_DPHY;
775790 config->flags = (sc210iot->cur_mode->hdr_mode == NO_HDR) ?
776791 val : (val | V4L2_MBUS_CSI2_CHANNEL_1);
777792 return 0;
....@@ -856,6 +871,8 @@
856871 __v4l2_ctrl_modify_range(sc210iot->vblank, vblank_def,
857872 SC210IOT_VTS_MAX - mode->height,
858873 1, vblank_def);
874
+ sc210iot->cur_fps = mode->max_fps;
875
+ sc210iot->cur_vts = mode->vts_def;
859876 }
860877 mutex_unlock(&sc210iot->lock);
861878 return 0;
....@@ -951,7 +968,6 @@
951968 static const struct v4l2_subdev_video_ops sc210iot_video_ops = {
952969 .s_stream = sc210iot_s_stream,
953970 .g_frame_interval = sc210iot_g_frame_interval,
954
- .g_mbus_config = sc210iot_g_mbus_config,
955971 };
956972
957973 static const struct v4l2_subdev_pad_ops sc210iot_pad_ops = {
....@@ -960,6 +976,7 @@
960976 .enum_frame_interval = sc210iot_enum_frame_interval,
961977 .get_fmt = sc210iot_get_fmt,
962978 .set_fmt = sc210iot_set_fmt,
979
+ .get_mbus_config = sc210iot_g_mbus_config,
963980 };
964981
965982 static const struct v4l2_subdev_ops sc210iot_subdev_ops = {