hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/media/i2c/ov7740.c
....@@ -20,7 +20,7 @@
2020 #define REG_BGAIN 0x01 /* blue gain */
2121 #define REG_RGAIN 0x02 /* red gain */
2222 #define REG_GGAIN 0x03 /* green gain */
23
-#define REG_REG04 0x04 /* analog setting, dont change*/
23
+#define REG_REG04 0x04 /* analog setting, don't change*/
2424 #define REG_BAVG 0x05 /* b channel average */
2525 #define REG_GAVG 0x06 /* g channel average */
2626 #define REG_RAVG 0x07 /* r channel average */
....@@ -322,7 +322,7 @@
322322 return 0;
323323 }
324324
325
-static struct v4l2_subdev_core_ops ov7740_subdev_core_ops = {
325
+static const struct v4l2_subdev_core_ops ov7740_subdev_core_ops = {
326326 .log_status = v4l2_ctrl_subdev_log_status,
327327 #ifdef CONFIG_VIDEO_ADV_DEBUG
328328 .g_register = ov7740_get_register,
....@@ -448,6 +448,27 @@
448448 return 0;
449449 }
450450
451
+static int ov7740_get_exp(struct ov7740 *ov7740, struct v4l2_ctrl *ctrl)
452
+{
453
+ struct regmap *regmap = ov7740->regmap;
454
+ unsigned int value0, value1;
455
+ int ret;
456
+
457
+ if (ctrl->val == V4L2_EXPOSURE_MANUAL)
458
+ return 0;
459
+
460
+ ret = regmap_read(regmap, REG_AEC, &value0);
461
+ if (ret)
462
+ return ret;
463
+ ret = regmap_read(regmap, REG_HAEC, &value1);
464
+ if (ret)
465
+ return ret;
466
+
467
+ ov7740->exposure->val = (value1 << 8) | (value0 & 0xff);
468
+
469
+ return 0;
470
+}
471
+
451472 static int ov7740_set_exp(struct regmap *regmap, int value)
452473 {
453474 int ret;
....@@ -494,6 +515,9 @@
494515 case V4L2_CID_AUTOGAIN:
495516 ret = ov7740_get_gain(ov7740, ctrl);
496517 break;
518
+ case V4L2_CID_EXPOSURE_AUTO:
519
+ ret = ov7740_get_exp(ov7740, ctrl);
520
+ break;
497521 default:
498522 ret = -EINVAL;
499523 break;
....@@ -508,7 +532,7 @@
508532 struct i2c_client *client = v4l2_get_subdevdata(&ov7740->subdev);
509533 struct regmap *regmap = ov7740->regmap;
510534 int ret;
511
- u8 val = 0;
535
+ u8 val;
512536
513537 if (!pm_runtime_get_if_in_use(&client->dev))
514538 return 0;
....@@ -527,6 +551,7 @@
527551 ret = ov7740_set_contrast(regmap, ctrl->val);
528552 break;
529553 case V4L2_CID_VFLIP:
554
+ val = ctrl->val ? REG0C_IMG_FLIP : 0x00;
530555 ret = regmap_update_bits(regmap, REG_REG0C,
531556 REG0C_IMG_FLIP, val);
532557 break;
....@@ -537,16 +562,16 @@
537562 break;
538563 case V4L2_CID_AUTOGAIN:
539564 if (!ctrl->val)
540
- return ov7740_set_gain(regmap, ov7740->gain->val);
541
-
542
- ret = ov7740_set_autogain(regmap, ctrl->val);
565
+ ret = ov7740_set_gain(regmap, ov7740->gain->val);
566
+ else
567
+ ret = ov7740_set_autogain(regmap, ctrl->val);
543568 break;
544569
545570 case V4L2_CID_EXPOSURE_AUTO:
546571 if (ctrl->val == V4L2_EXPOSURE_MANUAL)
547
- return ov7740_set_exp(regmap, ov7740->exposure->val);
548
-
549
- ret = ov7740_set_autoexp(regmap, ctrl->val);
572
+ ret = ov7740_set_exp(regmap, ov7740->exposure->val);
573
+ else
574
+ ret = ov7740_set_autoexp(regmap, ctrl->val);
550575 break;
551576 default:
552577 ret = -EINVAL;
....@@ -648,7 +673,7 @@
648673 return 0;
649674 }
650675
651
-static struct v4l2_subdev_video_ops ov7740_subdev_video_ops = {
676
+static const struct v4l2_subdev_video_ops ov7740_subdev_video_ops = {
652677 .s_stream = ov7740_set_stream,
653678 .s_frame_interval = ov7740_s_frame_interval,
654679 .g_frame_interval = ov7740_g_frame_interval,
....@@ -802,13 +827,9 @@
802827 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
803828 mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
804829 *mbus_fmt = format->format;
805
-
830
+#endif
806831 mutex_unlock(&ov7740->mutex);
807832 return 0;
808
-#else
809
- ret = -ENOTTY;
810
- goto error;
811
-#endif
812833 }
813834
814835 ret = ov7740_try_fmt_internal(sd, &format->format, &ovfmt, &fsize);
....@@ -843,7 +864,7 @@
843864 format->format = *mbus_fmt;
844865 ret = 0;
845866 #else
846
- ret = -ENOTTY;
867
+ ret = -EINVAL;
847868 #endif
848869 } else {
849870 format->format = ov7740->format;
....@@ -987,16 +1008,12 @@
9871008
9881009 ov7740->gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
9891010 V4L2_CID_GAIN, 0, 1023, 1, 500);
990
- if (ov7740->gain)
991
- ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
9921011
9931012 ov7740->auto_gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
9941013 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
9951014
9961015 ov7740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
9971016 V4L2_CID_EXPOSURE, 0, 65535, 1, 500);
998
- if (ov7740->exposure)
999
- ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
10001017
10011018 ov7740->auto_exposure = v4l2_ctrl_new_std_menu(ctrl_hdlr,
10021019 &ov7740_ctrl_ops,
....@@ -1007,8 +1024,7 @@
10071024 v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false);
10081025 v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true);
10091026 v4l2_ctrl_auto_cluster(2, &ov7740->auto_exposure,
1010
- V4L2_EXPOSURE_MANUAL, false);
1011
- v4l2_ctrl_cluster(2, &ov7740->hflip);
1027
+ V4L2_EXPOSURE_MANUAL, true);
10121028
10131029 if (ctrl_hdlr->error) {
10141030 ret = ctrl_hdlr->error;
....@@ -1046,19 +1062,11 @@
10461062 .max_register = OV7740_MAX_REGISTER,
10471063 };
10481064
1049
-static int ov7740_probe(struct i2c_client *client,
1050
- const struct i2c_device_id *id)
1065
+static int ov7740_probe(struct i2c_client *client)
10511066 {
10521067 struct ov7740 *ov7740;
10531068 struct v4l2_subdev *sd;
10541069 int ret;
1055
-
1056
- if (!i2c_check_functionality(client->adapter,
1057
- I2C_FUNC_SMBUS_BYTE_DATA)) {
1058
- dev_err(&client->dev,
1059
- "OV7740: I2C-Adapter doesn't support SMBUS\n");
1060
- return -EIO;
1061
- }
10621070
10631071 ov7740 = devm_kzalloc(&client->dev, sizeof(*ov7740), GFP_KERNEL);
10641072 if (!ov7740)
....@@ -1076,7 +1084,7 @@
10761084 if (ret)
10771085 return ret;
10781086
1079
- ov7740->regmap = devm_regmap_init_i2c(client, &ov7740_regmap_config);
1087
+ ov7740->regmap = devm_regmap_init_sccb(client, &ov7740_regmap_config);
10801088 if (IS_ERR(ov7740->regmap)) {
10811089 ret = PTR_ERR(ov7740->regmap);
10821090 dev_err(&client->dev, "Failed to allocate register map: %d\n",
....@@ -1085,7 +1093,6 @@
10851093 }
10861094
10871095 sd = &ov7740->subdev;
1088
- client->flags |= I2C_CLIENT_SCCB;
10891096 v4l2_i2c_subdev_init(sd, client, &ov7740_subdev_ops);
10901097
10911098 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
....@@ -1209,7 +1216,7 @@
12091216 .pm = &ov7740_pm_ops,
12101217 .of_match_table = of_match_ptr(ov7740_of_match),
12111218 },
1212
- .probe = ov7740_probe,
1219
+ .probe_new = ov7740_probe,
12131220 .remove = ov7740_remove,
12141221 .id_table = ov7740_id,
12151222 };