hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/i2c/sc2310.c
....@@ -121,14 +121,6 @@
121121
122122 #define SC2310_NUM_SUPPLIES ARRAY_SIZE(sc2310_supply_names)
123123
124
-enum sc2310_max_pad {
125
- PAD0,
126
- PAD1,
127
- PAD2,
128
- PAD3,
129
- PAD_MAX,
130
-};
131
-
132124 struct regval {
133125 u16 addr;
134126 u8 val;
....@@ -170,6 +162,7 @@
170162 struct v4l2_ctrl *pixel_rate;
171163 struct v4l2_ctrl *link_freq;
172164 struct mutex mutex;
165
+ struct v4l2_fract cur_fps;
173166 bool streaming;
174167 bool power_on;
175168 const struct sc2310_mode *cur_mode;
....@@ -776,6 +769,8 @@
776769 pixel_rate = (u32)link_freq_items[mode->mipi_freq_idx] /
777770 mode->bpp * 2 * SC2310_LANES;
778771 __v4l2_ctrl_s_ctrl_int64(sc2310->pixel_rate, pixel_rate);
772
+ sc2310->cur_fps = mode->max_fps;
773
+ sc2310->cur_vts = mode->vts_def;
779774 }
780775
781776 mutex_unlock(&sc2310->mutex);
....@@ -868,14 +863,15 @@
868863 struct sc2310 *sc2310 = to_sc2310(sd);
869864 const struct sc2310_mode *mode = sc2310->cur_mode;
870865
871
- mutex_lock(&sc2310->mutex);
872
- fi->interval = mode->max_fps;
873
- mutex_unlock(&sc2310->mutex);
866
+ if (sc2310->streaming)
867
+ fi->interval = sc2310->cur_fps;
868
+ else
869
+ fi->interval = mode->max_fps;
874870
875871 return 0;
876872 }
877873
878
-static int sc2310_g_mbus_config(struct v4l2_subdev *sd,
874
+static int sc2310_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
879875 struct v4l2_mbus_config *config)
880876 {
881877 struct sc2310 *sc2310 = to_sc2310(sd);
....@@ -892,7 +888,7 @@
892888 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK |
893889 V4L2_MBUS_CSI2_CHANNEL_1;
894890
895
- config->type = V4L2_MBUS_CSI2;
891
+ config->type = V4L2_MBUS_CSI2_DPHY;
896892 config->flags = val;
897893
898894 return 0;
....@@ -1078,11 +1074,23 @@
10781074 return 0;
10791075 }
10801076
1077
+static int sc2310_get_channel_info(struct sc2310 *sc2310, struct rkmodule_channel_info *ch_info)
1078
+{
1079
+ if (ch_info->index < PAD0 || ch_info->index >= PAD_MAX)
1080
+ return -EINVAL;
1081
+ ch_info->vc = sc2310->cur_mode->vc[ch_info->index];
1082
+ ch_info->width = sc2310->cur_mode->width;
1083
+ ch_info->height = sc2310->cur_mode->height;
1084
+ ch_info->bus_fmt = sc2310->cur_mode->bus_fmt;
1085
+ return 0;
1086
+}
1087
+
10811088 static long sc2310_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
10821089 {
10831090 struct sc2310 *sc2310 = to_sc2310(sd);
10841091 struct rkmodule_hdr_cfg *hdr_cfg;
10851092 const struct sc2310_mode *mode;
1093
+ struct rkmodule_channel_info *ch_info;
10861094 long ret = 0;
10871095 u64 pixel_rate = 0;
10881096 u32 i, h, w, stream;
....@@ -1127,6 +1135,8 @@
11271135 mode->bpp * 2 * SC2310_LANES;
11281136 __v4l2_ctrl_s_ctrl_int64(sc2310->pixel_rate,
11291137 pixel_rate);
1138
+ sc2310->cur_fps = mode->max_fps;
1139
+ sc2310->cur_vts = mode->vts_def;
11301140 dev_info(&sc2310->client->dev,
11311141 "sensor mode: %d\n", mode->hdr_mode);
11321142 }
....@@ -1150,6 +1160,10 @@
11501160 ret = sc2310_write_reg(sc2310->client, SC2310_REG_CTRL_MODE,
11511161 SC2310_REG_VALUE_08BIT, SC2310_MODE_SW_STANDBY);
11521162 break;
1163
+ case RKMODULE_GET_CHANNEL_INFO:
1164
+ ch_info = (struct rkmodule_channel_info *)arg;
1165
+ ret = sc2310_get_channel_info(sc2310, ch_info);
1166
+ break;
11531167 default:
11541168 ret = -ENOIOCTLCMD;
11551169 break;
....@@ -1167,6 +1181,7 @@
11671181 struct rkmodule_awb_cfg *cfg;
11681182 struct rkmodule_hdr_cfg *hdr;
11691183 struct preisp_hdrae_exp_s *hdrae;
1184
+ struct rkmodule_channel_info *ch_info;
11701185 long ret = 0;
11711186 u32 cg = 0;
11721187 u32 stream = 0;
....@@ -1255,6 +1270,21 @@
12551270 if (copy_from_user(&stream, up, sizeof(u32)))
12561271 return -EFAULT;
12571272 ret = sc2310_ioctl(sd, cmd, &stream);
1273
+ break;
1274
+ case RKMODULE_GET_CHANNEL_INFO:
1275
+ ch_info = kzalloc(sizeof(*ch_info), GFP_KERNEL);
1276
+ if (!ch_info) {
1277
+ ret = -ENOMEM;
1278
+ return ret;
1279
+ }
1280
+
1281
+ ret = sc2310_ioctl(sd, cmd, ch_info);
1282
+ if (!ret) {
1283
+ ret = copy_to_user(up, ch_info, sizeof(*ch_info));
1284
+ if (ret)
1285
+ ret = -EFAULT;
1286
+ }
1287
+ kfree(ch_info);
12581288 break;
12591289 default:
12601290 ret = -ENOIOCTLCMD;
....@@ -1523,7 +1553,6 @@
15231553 static const struct v4l2_subdev_video_ops sc2310_video_ops = {
15241554 .s_stream = sc2310_s_stream,
15251555 .g_frame_interval = sc2310_g_frame_interval,
1526
- .g_mbus_config = sc2310_g_mbus_config,
15271556 };
15281557
15291558 static const struct v4l2_subdev_pad_ops sc2310_pad_ops = {
....@@ -1532,6 +1561,7 @@
15321561 .enum_frame_interval = sc2310_enum_frame_interval,
15331562 .get_fmt = sc2310_get_fmt,
15341563 .set_fmt = sc2310_set_fmt,
1564
+ .get_mbus_config = sc2310_g_mbus_config,
15351565 };
15361566
15371567 static const struct v4l2_subdev_ops sc2310_subdev_ops = {
....@@ -1539,6 +1569,14 @@
15391569 .video = &sc2310_video_ops, /* */
15401570 .pad = &sc2310_pad_ops, /* */
15411571 };
1572
+
1573
+static void sc2310_modify_fps_info(struct sc2310 *sc2310)
1574
+{
1575
+ const struct sc2310_mode *mode = sc2310->cur_mode;
1576
+
1577
+ sc2310->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def /
1578
+ sc2310->cur_vts;
1579
+}
15421580
15431581 static int sc2310_set_ctrl(struct v4l2_ctrl *ctrl)
15441582 {
....@@ -1613,6 +1651,10 @@
16131651 ret = sc2310_write_reg(sc2310->client, SC2310_REG_VTS,
16141652 SC2310_REG_VALUE_16BIT,
16151653 ctrl->val + sc2310->cur_mode->height);
1654
+ if (!ret)
1655
+ sc2310->cur_vts = ctrl->val + sc2310->cur_mode->height;
1656
+ if (sc2310->cur_vts != sc2310->cur_mode->vts_def)
1657
+ sc2310_modify_fps_info(sc2310);
16161658 dev_dbg(&client->dev, "set vblank 0x%x\n",
16171659 ctrl->val);
16181660 break;
....@@ -1727,6 +1769,8 @@
17271769
17281770 sc2310->subdev.ctrl_handler = handler;
17291771 sc2310->has_init_exp = false;
1772
+ sc2310->cur_fps = mode->max_fps;
1773
+ sc2310->cur_vts = mode->vts_def;
17301774
17311775 return 0;
17321776