ov5645.c (1c2177fd99ab9e622126b1ec29f2a452140edf86) ov5645.c (e72e6cbe7962fc72e9b13ffaa746ab93d7a20a9b)
1/*
2 * Driver for the OV5645 camera sensor.
3 *
4 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
5 * Copyright (C) 2015 By Tech Design S.L. All Rights Reserved.
6 * Copyright (C) 2012-2013 Freescale Semiconductor, Inc. All Rights Reserved.
7 *
8 * Based on:

--- 67 unchanged lines hidden (view full) ---

76};
77
78struct ov5645_mode_info {
79 u32 width;
80 u32 height;
81 const struct reg_value *data;
82 u32 data_size;
83 u32 pixel_clock;
1/*
2 * Driver for the OV5645 camera sensor.
3 *
4 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
5 * Copyright (C) 2015 By Tech Design S.L. All Rights Reserved.
6 * Copyright (C) 2012-2013 Freescale Semiconductor, Inc. All Rights Reserved.
7 *
8 * Based on:

--- 67 unchanged lines hidden (view full) ---

76};
77
78struct ov5645_mode_info {
79 u32 width;
80 u32 height;
81 const struct reg_value *data;
82 u32 data_size;
83 u32 pixel_clock;
84 u32 link_freq;
84};
85
86struct ov5645 {
87 struct i2c_client *i2c_client;
88 struct device *dev;
89 struct v4l2_subdev sd;
90 struct media_pad pad;
91 struct v4l2_fwnode_endpoint ep;

--- 4 unchanged lines hidden (view full) ---

96 struct regulator *io_regulator;
97 struct regulator *core_regulator;
98 struct regulator *analog_regulator;
99
100 const struct ov5645_mode_info *current_mode;
101
102 struct v4l2_ctrl_handler ctrls;
103 struct v4l2_ctrl *pixel_clock;
85};
86
87struct ov5645 {
88 struct i2c_client *i2c_client;
89 struct device *dev;
90 struct v4l2_subdev sd;
91 struct media_pad pad;
92 struct v4l2_fwnode_endpoint ep;

--- 4 unchanged lines hidden (view full) ---

97 struct regulator *io_regulator;
98 struct regulator *core_regulator;
99 struct regulator *analog_regulator;
100
101 const struct ov5645_mode_info *current_mode;
102
103 struct v4l2_ctrl_handler ctrls;
104 struct v4l2_ctrl *pixel_clock;
105 struct v4l2_ctrl *link_freq;
104
105 /* Cached register values */
106 u8 aec_pk_manual;
107 u8 timing_tc_reg20;
108 u8 timing_tc_reg21;
109
110 struct mutex power_lock; /* lock to protect power state */
111 int power_count;

--- 390 unchanged lines hidden (view full) ---

502 { 0x3a18, 0x01 },
503 { 0x4004, 0x06 },
504 { 0x4005, 0x18 },
505 { 0x4300, 0x32 },
506 { 0x4837, 0x0b },
507 { 0x4202, 0x00 }
508};
509
106
107 /* Cached register values */
108 u8 aec_pk_manual;
109 u8 timing_tc_reg20;
110 u8 timing_tc_reg21;
111
112 struct mutex power_lock; /* lock to protect power state */
113 int power_count;

--- 390 unchanged lines hidden (view full) ---

504 { 0x3a18, 0x01 },
505 { 0x4004, 0x06 },
506 { 0x4005, 0x18 },
507 { 0x4300, 0x32 },
508 { 0x4837, 0x0b },
509 { 0x4202, 0x00 }
510};
511
512static const s64 link_freq[] = {
513 222880000,
514 334320000
515};
516
510static const struct ov5645_mode_info ov5645_mode_info_data[] = {
511 {
512 .width = 1280,
513 .height = 960,
514 .data = ov5645_setting_sxga,
515 .data_size = ARRAY_SIZE(ov5645_setting_sxga),
517static const struct ov5645_mode_info ov5645_mode_info_data[] = {
518 {
519 .width = 1280,
520 .height = 960,
521 .data = ov5645_setting_sxga,
522 .data_size = ARRAY_SIZE(ov5645_setting_sxga),
516 .pixel_clock = 111440000
523 .pixel_clock = 111440000,
524 .link_freq = 0 /* an index in link_freq[] */
517 },
518 {
519 .width = 1920,
520 .height = 1080,
521 .data = ov5645_setting_1080p,
522 .data_size = ARRAY_SIZE(ov5645_setting_1080p),
525 },
526 {
527 .width = 1920,
528 .height = 1080,
529 .data = ov5645_setting_1080p,
530 .data_size = ARRAY_SIZE(ov5645_setting_1080p),
523 .pixel_clock = 167160000
531 .pixel_clock = 167160000,
532 .link_freq = 1 /* an index in link_freq[] */
524 },
525 {
526 .width = 2592,
527 .height = 1944,
528 .data = ov5645_setting_full,
529 .data_size = ARRAY_SIZE(ov5645_setting_full),
533 },
534 {
535 .width = 2592,
536 .height = 1944,
537 .data = ov5645_setting_full,
538 .data_size = ARRAY_SIZE(ov5645_setting_full),
530 .pixel_clock = 167160000
539 .pixel_clock = 167160000,
540 .link_freq = 1 /* an index in link_freq[] */
531 },
532};
533
534static int ov5645_regulators_enable(struct ov5645 *ov5645)
535{
536 int ret;
537
538 ret = regulator_enable(ov5645->io_regulator);

--- 446 unchanged lines hidden (view full) ---

985 __crop->height = new_mode->height;
986
987 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
988 ret = v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock,
989 new_mode->pixel_clock);
990 if (ret < 0)
991 return ret;
992
541 },
542};
543
544static int ov5645_regulators_enable(struct ov5645 *ov5645)
545{
546 int ret;
547
548 ret = regulator_enable(ov5645->io_regulator);

--- 446 unchanged lines hidden (view full) ---

995 __crop->height = new_mode->height;
996
997 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
998 ret = v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock,
999 new_mode->pixel_clock);
1000 if (ret < 0)
1001 return ret;
1002
1003 ret = v4l2_ctrl_s_ctrl(ov5645->link_freq,
1004 new_mode->link_freq);
1005 if (ret < 0)
1006 return ret;
1007
993 ov5645->current_mode = new_mode;
994 }
995
996 __format = __ov5645_get_pad_format(ov5645, cfg, format->pad,
997 format->which);
998 __format->width = __crop->width;
999 __format->height = __crop->height;
1000 __format->code = MEDIA_BUS_FMT_UYVY8_2X8;

--- 203 unchanged lines hidden (view full) ---

1204 ov5645->rst_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
1205 if (IS_ERR(ov5645->rst_gpio)) {
1206 dev_err(dev, "cannot get reset gpio\n");
1207 return PTR_ERR(ov5645->rst_gpio);
1208 }
1209
1210 mutex_init(&ov5645->power_lock);
1211
1008 ov5645->current_mode = new_mode;
1009 }
1010
1011 __format = __ov5645_get_pad_format(ov5645, cfg, format->pad,
1012 format->which);
1013 __format->width = __crop->width;
1014 __format->height = __crop->height;
1015 __format->code = MEDIA_BUS_FMT_UYVY8_2X8;

--- 203 unchanged lines hidden (view full) ---

1219 ov5645->rst_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
1220 if (IS_ERR(ov5645->rst_gpio)) {
1221 dev_err(dev, "cannot get reset gpio\n");
1222 return PTR_ERR(ov5645->rst_gpio);
1223 }
1224
1225 mutex_init(&ov5645->power_lock);
1226
1212 v4l2_ctrl_handler_init(&ov5645->ctrls, 8);
1227 v4l2_ctrl_handler_init(&ov5645->ctrls, 9);
1213 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1214 V4L2_CID_SATURATION, -4, 4, 1, 0);
1215 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1216 V4L2_CID_HFLIP, 0, 1, 1, 0);
1217 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1218 V4L2_CID_VFLIP, 0, 1, 1, 0);
1219 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1220 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);

--- 5 unchanged lines hidden (view full) ---

1226 v4l2_ctrl_new_std_menu_items(&ov5645->ctrls, &ov5645_ctrl_ops,
1227 V4L2_CID_TEST_PATTERN,
1228 ARRAY_SIZE(ov5645_test_pattern_menu) - 1,
1229 0, 0, ov5645_test_pattern_menu);
1230 ov5645->pixel_clock = v4l2_ctrl_new_std(&ov5645->ctrls,
1231 &ov5645_ctrl_ops,
1232 V4L2_CID_PIXEL_RATE,
1233 1, INT_MAX, 1, 1);
1228 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1229 V4L2_CID_SATURATION, -4, 4, 1, 0);
1230 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1231 V4L2_CID_HFLIP, 0, 1, 1, 0);
1232 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1233 V4L2_CID_VFLIP, 0, 1, 1, 0);
1234 v4l2_ctrl_new_std(&ov5645->ctrls, &ov5645_ctrl_ops,
1235 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);

--- 5 unchanged lines hidden (view full) ---

1241 v4l2_ctrl_new_std_menu_items(&ov5645->ctrls, &ov5645_ctrl_ops,
1242 V4L2_CID_TEST_PATTERN,
1243 ARRAY_SIZE(ov5645_test_pattern_menu) - 1,
1244 0, 0, ov5645_test_pattern_menu);
1245 ov5645->pixel_clock = v4l2_ctrl_new_std(&ov5645->ctrls,
1246 &ov5645_ctrl_ops,
1247 V4L2_CID_PIXEL_RATE,
1248 1, INT_MAX, 1, 1);
1249 ov5645->link_freq = v4l2_ctrl_new_int_menu(&ov5645->ctrls,
1250 &ov5645_ctrl_ops,
1251 V4L2_CID_LINK_FREQ,
1252 ARRAY_SIZE(link_freq) - 1,
1253 0, link_freq);
1254 if (ov5645->link_freq)
1255 ov5645->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1234
1235 ov5645->sd.ctrl_handler = &ov5645->ctrls;
1236
1237 if (ov5645->ctrls.error) {
1238 dev_err(dev, "%s: control initialization error %d\n",
1239 __func__, ov5645->ctrls.error);
1240 ret = ov5645->ctrls.error;
1241 goto free_ctrl;

--- 122 unchanged lines hidden ---
1256
1257 ov5645->sd.ctrl_handler = &ov5645->ctrls;
1258
1259 if (ov5645->ctrls.error) {
1260 dev_err(dev, "%s: control initialization error %d\n",
1261 __func__, ov5645->ctrls.error);
1262 ret = ov5645->ctrls.error;
1263 goto free_ctrl;

--- 122 unchanged lines hidden ---