.. | .. |
---|
20 | 20 | #define REG_BGAIN 0x01 /* blue gain */ |
---|
21 | 21 | #define REG_RGAIN 0x02 /* red gain */ |
---|
22 | 22 | #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*/ |
---|
24 | 24 | #define REG_BAVG 0x05 /* b channel average */ |
---|
25 | 25 | #define REG_GAVG 0x06 /* g channel average */ |
---|
26 | 26 | #define REG_RAVG 0x07 /* r channel average */ |
---|
.. | .. |
---|
322 | 322 | return 0; |
---|
323 | 323 | } |
---|
324 | 324 | |
---|
325 | | -static struct v4l2_subdev_core_ops ov7740_subdev_core_ops = { |
---|
| 325 | +static const struct v4l2_subdev_core_ops ov7740_subdev_core_ops = { |
---|
326 | 326 | .log_status = v4l2_ctrl_subdev_log_status, |
---|
327 | 327 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
---|
328 | 328 | .g_register = ov7740_get_register, |
---|
.. | .. |
---|
448 | 448 | return 0; |
---|
449 | 449 | } |
---|
450 | 450 | |
---|
| 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 | + |
---|
451 | 472 | static int ov7740_set_exp(struct regmap *regmap, int value) |
---|
452 | 473 | { |
---|
453 | 474 | int ret; |
---|
.. | .. |
---|
494 | 515 | case V4L2_CID_AUTOGAIN: |
---|
495 | 516 | ret = ov7740_get_gain(ov7740, ctrl); |
---|
496 | 517 | break; |
---|
| 518 | + case V4L2_CID_EXPOSURE_AUTO: |
---|
| 519 | + ret = ov7740_get_exp(ov7740, ctrl); |
---|
| 520 | + break; |
---|
497 | 521 | default: |
---|
498 | 522 | ret = -EINVAL; |
---|
499 | 523 | break; |
---|
.. | .. |
---|
508 | 532 | struct i2c_client *client = v4l2_get_subdevdata(&ov7740->subdev); |
---|
509 | 533 | struct regmap *regmap = ov7740->regmap; |
---|
510 | 534 | int ret; |
---|
511 | | - u8 val = 0; |
---|
| 535 | + u8 val; |
---|
512 | 536 | |
---|
513 | 537 | if (!pm_runtime_get_if_in_use(&client->dev)) |
---|
514 | 538 | return 0; |
---|
.. | .. |
---|
527 | 551 | ret = ov7740_set_contrast(regmap, ctrl->val); |
---|
528 | 552 | break; |
---|
529 | 553 | case V4L2_CID_VFLIP: |
---|
| 554 | + val = ctrl->val ? REG0C_IMG_FLIP : 0x00; |
---|
530 | 555 | ret = regmap_update_bits(regmap, REG_REG0C, |
---|
531 | 556 | REG0C_IMG_FLIP, val); |
---|
532 | 557 | break; |
---|
.. | .. |
---|
537 | 562 | break; |
---|
538 | 563 | case V4L2_CID_AUTOGAIN: |
---|
539 | 564 | 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); |
---|
543 | 568 | break; |
---|
544 | 569 | |
---|
545 | 570 | case V4L2_CID_EXPOSURE_AUTO: |
---|
546 | 571 | 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); |
---|
550 | 575 | break; |
---|
551 | 576 | default: |
---|
552 | 577 | ret = -EINVAL; |
---|
.. | .. |
---|
648 | 673 | return 0; |
---|
649 | 674 | } |
---|
650 | 675 | |
---|
651 | | -static struct v4l2_subdev_video_ops ov7740_subdev_video_ops = { |
---|
| 676 | +static const struct v4l2_subdev_video_ops ov7740_subdev_video_ops = { |
---|
652 | 677 | .s_stream = ov7740_set_stream, |
---|
653 | 678 | .s_frame_interval = ov7740_s_frame_interval, |
---|
654 | 679 | .g_frame_interval = ov7740_g_frame_interval, |
---|
.. | .. |
---|
802 | 827 | #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API |
---|
803 | 828 | mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); |
---|
804 | 829 | *mbus_fmt = format->format; |
---|
805 | | - |
---|
| 830 | +#endif |
---|
806 | 831 | mutex_unlock(&ov7740->mutex); |
---|
807 | 832 | return 0; |
---|
808 | | -#else |
---|
809 | | - ret = -ENOTTY; |
---|
810 | | - goto error; |
---|
811 | | -#endif |
---|
812 | 833 | } |
---|
813 | 834 | |
---|
814 | 835 | ret = ov7740_try_fmt_internal(sd, &format->format, &ovfmt, &fsize); |
---|
.. | .. |
---|
843 | 864 | format->format = *mbus_fmt; |
---|
844 | 865 | ret = 0; |
---|
845 | 866 | #else |
---|
846 | | - ret = -ENOTTY; |
---|
| 867 | + ret = -EINVAL; |
---|
847 | 868 | #endif |
---|
848 | 869 | } else { |
---|
849 | 870 | format->format = ov7740->format; |
---|
.. | .. |
---|
987 | 1008 | |
---|
988 | 1009 | ov7740->gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, |
---|
989 | 1010 | V4L2_CID_GAIN, 0, 1023, 1, 500); |
---|
990 | | - if (ov7740->gain) |
---|
991 | | - ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; |
---|
992 | 1011 | |
---|
993 | 1012 | ov7740->auto_gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, |
---|
994 | 1013 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
---|
995 | 1014 | |
---|
996 | 1015 | ov7740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, |
---|
997 | 1016 | V4L2_CID_EXPOSURE, 0, 65535, 1, 500); |
---|
998 | | - if (ov7740->exposure) |
---|
999 | | - ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; |
---|
1000 | 1017 | |
---|
1001 | 1018 | ov7740->auto_exposure = v4l2_ctrl_new_std_menu(ctrl_hdlr, |
---|
1002 | 1019 | &ov7740_ctrl_ops, |
---|
.. | .. |
---|
1007 | 1024 | v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false); |
---|
1008 | 1025 | v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true); |
---|
1009 | 1026 | 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); |
---|
1012 | 1028 | |
---|
1013 | 1029 | if (ctrl_hdlr->error) { |
---|
1014 | 1030 | ret = ctrl_hdlr->error; |
---|
.. | .. |
---|
1046 | 1062 | .max_register = OV7740_MAX_REGISTER, |
---|
1047 | 1063 | }; |
---|
1048 | 1064 | |
---|
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) |
---|
1051 | 1066 | { |
---|
1052 | 1067 | struct ov7740 *ov7740; |
---|
1053 | 1068 | struct v4l2_subdev *sd; |
---|
1054 | 1069 | 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 | | - } |
---|
1062 | 1070 | |
---|
1063 | 1071 | ov7740 = devm_kzalloc(&client->dev, sizeof(*ov7740), GFP_KERNEL); |
---|
1064 | 1072 | if (!ov7740) |
---|
.. | .. |
---|
1076 | 1084 | if (ret) |
---|
1077 | 1085 | return ret; |
---|
1078 | 1086 | |
---|
1079 | | - ov7740->regmap = devm_regmap_init_i2c(client, &ov7740_regmap_config); |
---|
| 1087 | + ov7740->regmap = devm_regmap_init_sccb(client, &ov7740_regmap_config); |
---|
1080 | 1088 | if (IS_ERR(ov7740->regmap)) { |
---|
1081 | 1089 | ret = PTR_ERR(ov7740->regmap); |
---|
1082 | 1090 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
---|
.. | .. |
---|
1085 | 1093 | } |
---|
1086 | 1094 | |
---|
1087 | 1095 | sd = &ov7740->subdev; |
---|
1088 | | - client->flags |= I2C_CLIENT_SCCB; |
---|
1089 | 1096 | v4l2_i2c_subdev_init(sd, client, &ov7740_subdev_ops); |
---|
1090 | 1097 | |
---|
1091 | 1098 | #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API |
---|
.. | .. |
---|
1209 | 1216 | .pm = &ov7740_pm_ops, |
---|
1210 | 1217 | .of_match_table = of_match_ptr(ov7740_of_match), |
---|
1211 | 1218 | }, |
---|
1212 | | - .probe = ov7740_probe, |
---|
| 1219 | + .probe_new = ov7740_probe, |
---|
1213 | 1220 | .remove = ov7740_remove, |
---|
1214 | 1221 | .id_table = ov7740_id, |
---|
1215 | 1222 | }; |
---|