hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/media/i2c/jaguar1_drv/jaguar1_v4l2.c
....@@ -1,8 +1,9 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
33 * jaguar1 driver
4
- *
5
- * V0.0X01.0X01 add workqueue to detect ahd state.
4
+ * V0.0X01.0X00 first version.
5
+ * V0.0X01.0X01 fix kernel5.10 compile error.
6
+ * V0.0X01.0X02 add workqueue to detect ahd state.
67 *
78 */
89
....@@ -39,6 +40,7 @@
3940 #include "jaguar1_video_eq.h"
4041 #include "jaguar1_mipi.h"
4142 #include "jaguar1_drv.h"
43
+#include "jaguar1_v4l2.h"
4244
4345 #define WORK_QUEUE
4446
....@@ -52,7 +54,7 @@
5254
5355 #endif
5456
55
-#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x1)
57
+#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x2)
5658
5759 #ifndef V4L2_CID_DIGITAL_GAIN
5860 #define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
....@@ -81,14 +83,6 @@
8183
8284 /* #define FORCE_720P */
8385
84
-enum jaguar1_max_pad {
85
- PAD0,
86
- PAD1,
87
- PAD2,
88
- PAD3,
89
- PAD_MAX,
90
-};
91
-
9286 struct jaguar1_gpio {
9387 int pltfrm_gpio;
9488 const char *label;
....@@ -113,7 +107,9 @@
113107 struct jaguar1_framesize {
114108 u16 width;
115109 u16 height;
110
+ struct v4l2_fract max_fps;
116111 enum NC_VIVO_CH_FORMATDEF fmt_idx;
112
+ __u32 field;
117113 };
118114
119115 struct jaguar1_default_rect {
....@@ -176,23 +172,62 @@
176172 {
177173 .width = 2560,
178174 .height = 1440,
175
+ .max_fps = {
176
+ .numerator = 10000,
177
+ .denominator = 250000,
178
+ },
179179 .fmt_idx = AHD20_720P_25P,
180180 }
181181 #else
182182 {
183
+ .width = 960,
184
+ .height = 480,
185
+ .max_fps = {
186
+ .numerator = 10000,
187
+ .denominator = 250000,
188
+ },
189
+ .fmt_idx = AHD20_SD_H960_2EX_Btype_NT,
190
+ .field = V4L2_FIELD_INTERLACED,
191
+ },
192
+ {
193
+ .width = 960,
194
+ .height = 576,
195
+ .max_fps = {
196
+ .numerator = 10000,
197
+ .denominator = 300000,
198
+ },
199
+ .fmt_idx = AHD20_SD_H960_2EX_Btype_PAL,
200
+ .field = V4L2_FIELD_INTERLACED,
201
+ },
202
+ {
183203 .width = 1280,
184204 .height = 720,
205
+ .max_fps = {
206
+ .numerator = 10000,
207
+ .denominator = 250000,
208
+ },
185209 .fmt_idx = AHD20_720P_25P_EX_Btype,
210
+ .field = V4L2_FIELD_NONE
186211 },
187212 {
188213 .width = 1920,
189214 .height = 1080,
215
+ .max_fps = {
216
+ .numerator = 10000,
217
+ .denominator = 250000,
218
+ },
190219 .fmt_idx = AHD20_1080P_25P,
220
+ .field = V4L2_FIELD_NONE
191221 },
192222 {
193223 .width = 2560,
194224 .height = 1440,
225
+ .max_fps = {
226
+ .numerator = 10000,
227
+ .denominator = 250000,
228
+ },
195229 .fmt_idx = AHD20_720P_25P,
230
+ .field = V4L2_FIELD_NONE
196231 }
197232 #endif
198233 };
....@@ -479,7 +514,7 @@
479514 format->colorspace = V4L2_COLORSPACE_SRGB;
480515 format->code = jaguar1_formats[0].code;
481516 jaguar1->frame_size = match;
482
- format->field = V4L2_FIELD_NONE;
517
+ format->field = match->field;
483518 }
484519
485520 static inline bool jaguar1_no_signal(struct v4l2_subdev *sd, u8 *novid);
....@@ -716,13 +751,29 @@
716751 return 0;
717752 }
718753
719
-static int jaguar1_g_mbus_config(struct v4l2_subdev *sd,
754
+static int jaguar1_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
720755 struct v4l2_mbus_config *cfg)
721756 {
722
- cfg->type = V4L2_MBUS_CSI2;
757
+ cfg->type = V4L2_MBUS_CSI2_DPHY;
723758 cfg->flags = V4L2_MBUS_CSI2_4_LANE |
724759 V4L2_MBUS_CSI2_CHANNELS |
725760 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
761
+
762
+ return 0;
763
+}
764
+
765
+static int jaguar1_enum_frame_interval(struct v4l2_subdev *sd,
766
+ struct v4l2_subdev_pad_config *cfg,
767
+ struct v4l2_subdev_frame_interval_enum *fie)
768
+{
769
+ if (fie->index >= ARRAY_SIZE(jaguar1_framesizes))
770
+ return -EINVAL;
771
+
772
+ fie->code = jaguar1_formats[0].code;
773
+
774
+ fie->width = jaguar1_framesizes[fie->index].width;
775
+ fie->height = jaguar1_framesizes[fie->index].height;
776
+ fie->interval = jaguar1_framesizes[fie->index].max_fps;
726777
727778 return 0;
728779 }
....@@ -831,6 +882,19 @@
831882
832883 mutex_unlock(&jaguar1->mutex);
833884 return ret;
885
+}
886
+
887
+static int jaguar1_g_frame_interval(struct v4l2_subdev *sd,
888
+ struct v4l2_subdev_frame_interval *fi)
889
+{
890
+ struct jaguar1 *jaguar1 = to_jaguar1(sd);
891
+ const struct jaguar1_framesize *size = jaguar1->frame_size;
892
+
893
+ mutex_lock(&jaguar1->mutex);
894
+ fi->interval = size->max_fps;
895
+ mutex_unlock(&jaguar1->mutex);
896
+
897
+ return 0;
834898 }
835899
836900 static void jaguar1_get_module_inf(struct jaguar1 *jaguar1,
....@@ -1043,14 +1107,16 @@
10431107 static const struct v4l2_subdev_video_ops jaguar1_video_ops = {
10441108 .g_input_status = jaguar1_g_input_status,
10451109 .s_stream = jaguar1_stream,
1046
- .g_mbus_config = jaguar1_g_mbus_config,
1110
+ .g_frame_interval = jaguar1_g_frame_interval,
10471111 };
10481112
10491113 static const struct v4l2_subdev_pad_ops jaguar1_subdev_pad_ops = {
10501114 .enum_mbus_code = jaguar1_enum_mbus_code,
10511115 .enum_frame_size = jaguar1_enum_frame_sizes,
1116
+ .enum_frame_interval = jaguar1_enum_frame_interval,
10521117 .get_fmt = jaguar1_get_fmt,
10531118 .set_fmt = jaguar1_set_fmt,
1119
+ .get_mbus_config = jaguar1_g_mbus_config,
10541120 };
10551121
10561122 static const struct v4l2_subdev_core_ops jaguar1_core_ops = {
....@@ -1248,6 +1314,10 @@
12481314 sd = &jaguar1->subdev;
12491315 v4l2_i2c_subdev_init(sd, client, &jaguar1_subdev_ops);
12501316 ret = jaguar1_initialize_controls(jaguar1);
1317
+ if (ret) {
1318
+ dev_err(dev, "Failed to initialize controls jaguar1\n");
1319
+ return ret;
1320
+ }
12511321
12521322 __jaguar1_power_on(jaguar1);
12531323 ret |= jaguar1_init(i2c_adapter_id(client->adapter));
....@@ -1298,6 +1368,8 @@
12981368 pm_runtime_enable(dev);
12991369 pm_runtime_idle(dev);
13001370
1371
+ v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
1372
+ client->addr << 1, client->adapter->name);
13011373 #ifdef WORK_QUEUE
13021374 /* init work_queue for state_check */
13031375 INIT_DELAYED_WORK(&jaguar1->plug_state_check.d_work, jaguar1_plug_state_check_work);
....@@ -1371,17 +1443,20 @@
13711443 .id_table = jaguar1_match_id,
13721444 };
13731445
1374
-static int __init sensor_mod_init(void)
1446
+int nvp6324_sensor_mod_init(void)
13751447 {
13761448 return i2c_add_driver(&jaguar1_i2c_driver);
13771449 }
1450
+
1451
+#ifndef CONFIG_VIDEO_REVERSE_IMAGE
1452
+device_initcall_sync(nvp6324_sensor_mod_init);
1453
+#endif
13781454
13791455 static void __exit sensor_mod_exit(void)
13801456 {
13811457 i2c_del_driver(&jaguar1_i2c_driver);
13821458 }
13831459
1384
-device_initcall_sync(sensor_mod_init);
13851460 module_exit(sensor_mod_exit);
13861461
13871462 MODULE_DESCRIPTION("jaguar1 sensor driver");