1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Support for OmniVision OV2680 5M camera sensor.
5 * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/i2c.h>
24 #include <linux/delay.h>
25 #include <linux/videodev2.h>
26 #include <linux/spinlock.h>
27 #include <media/v4l2-subdev.h>
28 #include <media/v4l2-device.h>
29 #include <media/v4l2-ctrls.h>
30 #include <linux/v4l2-mediabus.h>
31 #include <media/media-entity.h>
33 #include "../include/linux/atomisp_platform.h"
35 #define OV2680_NATIVE_WIDTH 1616
36 #define OV2680_NATIVE_HEIGHT 1216
38 /* 1704 * 1294 * 30fps = 66MHz pixel clock */
39 #define OV2680_PIXELS_PER_LINE 1704
40 #define OV2680_LINES_PER_FRAME 1294
42 #define OV2680_SKIP_FRAMES 3
44 /* If possible send 16 extra rows / lines to the ISP as padding */
45 #define OV2680_END_MARGIN 16
47 #define OV2680_FOCAL_LENGTH_NUM 334 /*3.34mm*/
49 #define OV2680_INTEGRATION_TIME_MARGIN 8
50 #define OV2680_ID 0x2680
53 * OV2680 System control registers
55 #define OV2680_SW_SLEEP 0x0100
56 #define OV2680_SW_RESET 0x0103
57 #define OV2680_SW_STREAM 0x0100
59 #define OV2680_SC_CMMN_CHIP_ID_H 0x300A
60 #define OV2680_SC_CMMN_CHIP_ID_L 0x300B
61 #define OV2680_SC_CMMN_SCCB_ID 0x302B /* 0x300C*/
62 #define OV2680_SC_CMMN_SUB_ID 0x302A /* process, version*/
64 #define OV2680_GROUP_ACCESS 0x3208 /*Bit[7:4] Group control, Bit[3:0] Group ID*/
66 #define OV2680_REG_EXPOSURE_PK_HIGH 0x3500
67 #define OV2680_REG_GAIN_PK 0x350a
69 #define OV2680_HORIZONTAL_START_H 0x3800 /* Bit[11:8] */
70 #define OV2680_HORIZONTAL_START_L 0x3801 /* Bit[7:0] */
71 #define OV2680_VERTICAL_START_H 0x3802 /* Bit[11:8] */
72 #define OV2680_VERTICAL_START_L 0x3803 /* Bit[7:0] */
73 #define OV2680_HORIZONTAL_END_H 0x3804 /* Bit[11:8] */
74 #define OV2680_HORIZONTAL_END_L 0x3805 /* Bit[7:0] */
75 #define OV2680_VERTICAL_END_H 0x3806 /* Bit[11:8] */
76 #define OV2680_VERTICAL_END_L 0x3807 /* Bit[7:0] */
77 #define OV2680_HORIZONTAL_OUTPUT_SIZE_H 0x3808 /* Bit[11:8] */
78 #define OV2680_HORIZONTAL_OUTPUT_SIZE_L 0x3809 /* Bit[7:0] */
79 #define OV2680_VERTICAL_OUTPUT_SIZE_H 0x380a /* Bit[11:8] */
80 #define OV2680_VERTICAL_OUTPUT_SIZE_L 0x380b /* Bit[7:0] */
81 #define OV2680_HTS 0x380c
82 #define OV2680_VTS 0x380e
83 #define OV2680_ISP_X_WIN 0x3810
84 #define OV2680_ISP_Y_WIN 0x3812
85 #define OV2680_X_INC 0x3814
86 #define OV2680_Y_INC 0x3815
88 #define OV2680_FRAME_OFF_NUM 0x4202
91 #define OV2680_REG_FORMAT1 0x3820
92 #define OV2680_REG_FORMAT2 0x3821
94 #define OV2680_MWB_RED_GAIN_H 0x5004/*0x3400*/
95 #define OV2680_MWB_GREEN_GAIN_H 0x5006/*0x3402*/
96 #define OV2680_MWB_BLUE_GAIN_H 0x5008/*0x3404*/
97 #define OV2680_MWB_GAIN_MAX 0x0fff
99 #define OV2680_REG_ISP_CTRL00 0x5080
101 #define OV2680_X_WIN 0x5704
102 #define OV2680_Y_WIN 0x5706
103 #define OV2680_WIN_CONTROL 0x5708
105 #define OV2680_START_STREAMING 0x01
106 #define OV2680_STOP_STREAMING 0x00
109 * ov2680 device structure.
111 struct ov2680_device {
112 struct v4l2_subdev sd;
113 struct media_pad pad;
114 struct mutex input_lock;
115 struct i2c_client *client;
116 struct gpio_desc *powerdown;
120 struct v4l2_mbus_framefmt fmt;
132 struct ov2680_ctrls {
133 struct v4l2_ctrl_handler handler;
134 struct v4l2_ctrl *hflip;
135 struct v4l2_ctrl *vflip;
136 struct v4l2_ctrl *exposure;
137 struct v4l2_ctrl *gain;
138 struct v4l2_ctrl *test_pattern;
143 * struct ov2680_reg - MI sensor register format
144 * @type: type of the register
145 * @reg: 16-bit offset to register
146 * @val: 8/16/32-bit register value
148 * Define a structure for sensor register initialization values
152 u32 val; /* @set value for read/mod/write, @mask */
155 #define to_ov2680_sensor(x) container_of(x, struct ov2680_device, sd)
157 static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
159 struct ov2680_device *sensor =
160 container_of(ctrl->handler, struct ov2680_device, ctrls.handler);
165 static struct ov2680_reg const ov2680_global_setting[] = {
208 {0x5004, 0x04},//manual awb 1x
216 {0x5708, 0x01}, /* add for full size flip off and mirror off 2014/09/11 */
217 {0x3701, 0x64}, //add on 14/05/13
218 {0x3784, 0x0c}, //based OV2680_R1A_AM10.ovt add on 14/06/13
219 {0x5780, 0x3e}, //based OV2680_R1A_AM10.ovt,Adjust DPC setting (57xx) on 14/06/13
239 {0x5794, 0x03}, //based OV2680_R1A_AM10.ovt,Adjust DPC setting (57xx) on 14/06/13
240 {0x0100, 0x00}, //stream off