hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
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,11 @@
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
+ sc210iot_modify_fps_info(sc210iot);
407412 break;
408413 case V4L2_CID_HFLIP:
409414 regmap_update_bits(sc210iot->regmap, SC210IOT_REG_MIRROR_FLIP,
....@@ -487,6 +492,8 @@
487492 }
488493 sc210iot->subdev.ctrl_handler = handler;
489494 sc210iot->has_init_exp = false;
495
+ sc210iot->cur_fps = mode->max_fps;
496
+ sc210iot->cur_vts = mode->vts_def;
490497 return 0;
491498 err_free_handler:
492499 v4l2_ctrl_handler_free(handler);
....@@ -687,8 +694,11 @@
687694 return ret;
688695 }
689696 ret = sc210iot_ioctl(sd, cmd, inf);
690
- if (!ret)
697
+ if (!ret) {
691698 ret = copy_to_user(up, inf, sizeof(*inf));
699
+ if (ret)
700
+ ret = -EFAULT;
701
+ }
692702 kfree(inf);
693703 break;
694704 case RKMODULE_GET_HDR_CFG:
....@@ -698,16 +708,19 @@
698708 return ret;
699709 }
700710 ret = sc210iot_ioctl(sd, cmd, hdr);
701
- if (!ret)
711
+ if (!ret) {
702712 ret = copy_to_user(up, hdr, sizeof(*hdr));
713
+ if (ret)
714
+ ret = -EFAULT;
715
+ }
703716 kfree(hdr);
704
- break;
705
- case RKMODULE_SET_HDR_CFG:
706717 break;
707718 case RKMODULE_SET_QUICK_STREAM:
708719 ret = copy_from_user(&stream, up, sizeof(u32));
709720 if (!ret)
710721 ret = sc210iot_ioctl(sd, cmd, &stream);
722
+ else
723
+ ret = -EFAULT;
711724 break;
712725 default:
713726 ret = -ENOIOCTLCMD;
....@@ -758,20 +771,21 @@
758771 struct sc210iot *sc210iot = to_sc210iot(sd);
759772 const struct sc210iot_mode *mode = sc210iot->cur_mode;
760773
761
- mutex_lock(&sc210iot->lock);
762
- fi->interval = mode->max_fps;
763
- mutex_unlock(&sc210iot->lock);
774
+ if (sc210iot->streaming)
775
+ fi->interval = sc210iot->cur_fps;
776
+ else
777
+ fi->interval = mode->max_fps;
764778 return 0;
765779 }
766780
767
-static int sc210iot_g_mbus_config(struct v4l2_subdev *sd,
781
+static int sc210iot_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
768782 struct v4l2_mbus_config *config)
769783 {
770784 struct sc210iot *sc210iot = to_sc210iot(sd);
771785
772786 u32 val = 1 << (SC210IOT_LANES - 1) | V4L2_MBUS_CSI2_CHANNEL_0 |
773787 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
774
- config->type = V4L2_MBUS_CSI2;
788
+ config->type = V4L2_MBUS_CSI2_DPHY;
775789 config->flags = (sc210iot->cur_mode->hdr_mode == NO_HDR) ?
776790 val : (val | V4L2_MBUS_CSI2_CHANNEL_1);
777791 return 0;
....@@ -856,6 +870,8 @@
856870 __v4l2_ctrl_modify_range(sc210iot->vblank, vblank_def,
857871 SC210IOT_VTS_MAX - mode->height,
858872 1, vblank_def);
873
+ sc210iot->cur_fps = mode->max_fps;
874
+ sc210iot->cur_vts = mode->vts_def;
859875 }
860876 mutex_unlock(&sc210iot->lock);
861877 return 0;
....@@ -951,7 +967,6 @@
951967 static const struct v4l2_subdev_video_ops sc210iot_video_ops = {
952968 .s_stream = sc210iot_s_stream,
953969 .g_frame_interval = sc210iot_g_frame_interval,
954
- .g_mbus_config = sc210iot_g_mbus_config,
955970 };
956971
957972 static const struct v4l2_subdev_pad_ops sc210iot_pad_ops = {
....@@ -960,6 +975,7 @@
960975 .enum_frame_interval = sc210iot_enum_frame_interval,
961976 .get_fmt = sc210iot_get_fmt,
962977 .set_fmt = sc210iot_set_fmt,
978
+ .get_mbus_config = sc210iot_g_mbus_config,
963979 };
964980
965981 static const struct v4l2_subdev_ops sc210iot_subdev_ops = {