forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/i2c/ov2640.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ov2640 Camera Driver
34 *
....@@ -7,10 +8,6 @@
78 *
89 * Copyright 2005-2009 Freescale Semiconductor, Inc. All Rights Reserved.
910 * Copyright (C) 2006, OmniVision
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License version 2 as
13
- * published by the Free Software Foundation.
1411 */
1512
1613 #include <linux/init.h>
....@@ -26,6 +23,7 @@
2623 #include <linux/videodev2.h>
2724
2825 #include <media/v4l2-device.h>
26
+#include <media/v4l2-event.h>
2927 #include <media/v4l2-subdev.h>
3028 #include <media/v4l2-ctrls.h>
3129 #include <media/v4l2-image-sizes.h>
....@@ -705,6 +703,11 @@
705703 return ret;
706704 }
707705
706
+static const char * const ov2640_test_pattern_menu[] = {
707
+ "Disabled",
708
+ "Eight Vertical Colour Bars",
709
+};
710
+
708711 /*
709712 * functions
710713 */
....@@ -740,6 +743,9 @@
740743 case V4L2_CID_HFLIP:
741744 val = ctrl->val ? REG04_HFLIP_IMG : 0x00;
742745 return ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
746
+ case V4L2_CID_TEST_PATTERN:
747
+ val = ctrl->val ? COM7_COLOR_BAR_TEST : 0x00;
748
+ return ov2640_mask_set(client, COM7, COM7_COLOR_BAR_TEST, val);
743749 }
744750
745751 return -EINVAL;
....@@ -833,9 +839,6 @@
833839 u8 val;
834840 int ret;
835841
836
- if (!win)
837
- return -EINVAL;
838
-
839842 switch (code) {
840843 case MEDIA_BUS_FMT_RGB565_2X8_BE:
841844 dev_dbg(&client->dev, "%s: Selected cfmt RGB565 BE", __func__);
....@@ -920,9 +923,14 @@
920923 if (format->pad)
921924 return -EINVAL;
922925
923
- if (!priv->win) {
924
- priv->win = ov2640_select_win(SVGA_WIDTH, SVGA_HEIGHT);
925
- priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
926
+ if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
927
+#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
928
+ mf = v4l2_subdev_get_try_format(sd, cfg, 0);
929
+ format->format = *mf;
930
+ return 0;
931
+#else
932
+ return -EINVAL;
933
+#endif
926934 }
927935
928936 mf->width = priv->win->width;
....@@ -930,6 +938,9 @@
930938 mf->code = priv->cfmt_code;
931939 mf->colorspace = V4L2_COLORSPACE_SRGB;
932940 mf->field = V4L2_FIELD_NONE;
941
+ mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
942
+ mf->quantization = V4L2_QUANTIZATION_DEFAULT;
943
+ mf->xfer_func = V4L2_XFER_FUNC_DEFAULT;
933944
934945 return 0;
935946 }
....@@ -956,6 +967,9 @@
956967
957968 mf->field = V4L2_FIELD_NONE;
958969 mf->colorspace = V4L2_COLORSPACE_SRGB;
970
+ mf->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
971
+ mf->quantization = V4L2_QUANTIZATION_DEFAULT;
972
+ mf->xfer_func = V4L2_XFER_FUNC_DEFAULT;
959973
960974 switch (mf->code) {
961975 case MEDIA_BUS_FMT_RGB565_2X8_BE:
....@@ -990,6 +1004,27 @@
9901004 return ret;
9911005 }
9921006
1007
+static int ov2640_init_cfg(struct v4l2_subdev *sd,
1008
+ struct v4l2_subdev_pad_config *cfg)
1009
+{
1010
+#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1011
+ struct v4l2_mbus_framefmt *try_fmt =
1012
+ v4l2_subdev_get_try_format(sd, cfg, 0);
1013
+ const struct ov2640_win_size *win =
1014
+ ov2640_select_win(SVGA_WIDTH, SVGA_HEIGHT);
1015
+
1016
+ try_fmt->width = win->width;
1017
+ try_fmt->height = win->height;
1018
+ try_fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
1019
+ try_fmt->colorspace = V4L2_COLORSPACE_SRGB;
1020
+ try_fmt->field = V4L2_FIELD_NONE;
1021
+ try_fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
1022
+ try_fmt->quantization = V4L2_QUANTIZATION_DEFAULT;
1023
+ try_fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT;
1024
+#endif
1025
+ return 0;
1026
+}
1027
+
9931028 static int ov2640_enum_mbus_code(struct v4l2_subdev *sd,
9941029 struct v4l2_subdev_pad_config *cfg,
9951030 struct v4l2_subdev_mbus_code_enum *code)
....@@ -1010,7 +1045,6 @@
10101045
10111046 switch (sel->target) {
10121047 case V4L2_SEL_TGT_CROP_BOUNDS:
1013
- case V4L2_SEL_TGT_CROP_DEFAULT:
10141048 case V4L2_SEL_TGT_CROP:
10151049 sel->r.left = 0;
10161050 sel->r.top = 0;
....@@ -1089,6 +1123,9 @@
10891123 };
10901124
10911125 static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1126
+ .log_status = v4l2_ctrl_subdev_log_status,
1127
+ .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1128
+ .unsubscribe_event = v4l2_event_subdev_unsubscribe,
10921129 #ifdef CONFIG_VIDEO_ADV_DEBUG
10931130 .g_register = ov2640_g_register,
10941131 .s_register = ov2640_s_register,
....@@ -1097,6 +1134,7 @@
10971134 };
10981135
10991136 static const struct v4l2_subdev_pad_ops ov2640_subdev_pad_ops = {
1137
+ .init_cfg = ov2640_init_cfg,
11001138 .enum_mbus_code = ov2640_enum_mbus_code,
11011139 .get_selection = ov2640_get_selection,
11021140 .get_fmt = ov2640_get_fmt,
....@@ -1152,11 +1190,10 @@
11521190 /*
11531191 * i2c_driver functions
11541192 */
1155
-static int ov2640_probe(struct i2c_client *client,
1156
- const struct i2c_device_id *did)
1193
+static int ov2640_probe(struct i2c_client *client)
11571194 {
11581195 struct ov2640_priv *priv;
1159
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1196
+ struct i2c_adapter *adapter = client->adapter;
11601197 int ret;
11611198
11621199 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
....@@ -1182,15 +1219,23 @@
11821219 if (ret)
11831220 goto err_clk;
11841221
1222
+ priv->win = ov2640_select_win(SVGA_WIDTH, SVGA_HEIGHT);
1223
+ priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
1224
+
11851225 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
1186
- priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1226
+ priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
1227
+ V4L2_SUBDEV_FL_HAS_EVENTS;
11871228 mutex_init(&priv->lock);
1188
- v4l2_ctrl_handler_init(&priv->hdl, 2);
1229
+ v4l2_ctrl_handler_init(&priv->hdl, 3);
11891230 priv->hdl.lock = &priv->lock;
11901231 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
11911232 V4L2_CID_VFLIP, 0, 1, 1, 0);
11921233 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
11931234 V4L2_CID_HFLIP, 0, 1, 1, 0);
1235
+ v4l2_ctrl_new_std_menu_items(&priv->hdl, &ov2640_ctrl_ops,
1236
+ V4L2_CID_TEST_PATTERN,
1237
+ ARRAY_SIZE(ov2640_test_pattern_menu) - 1, 0, 0,
1238
+ ov2640_test_pattern_menu);
11941239 priv->subdev.ctrl_handler = &priv->hdl;
11951240 if (priv->hdl.error) {
11961241 ret = priv->hdl.error;
....@@ -1256,7 +1301,7 @@
12561301 .name = "ov2640",
12571302 .of_match_table = of_match_ptr(ov2640_of_match),
12581303 },
1259
- .probe = ov2640_probe,
1304
+ .probe_new = ov2640_probe,
12601305 .remove = ov2640_remove,
12611306 .id_table = ov2640_id,
12621307 };