1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Omnivision OV2659 CMOS Image Sensor driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2015 Texas Instruments, Inc.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Benoit Parrot <bparrot@ti.com>
8*4882a593Smuzhiyun * Lad, Prabhakar <prabhakar.csengg@gmail.com>
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/clk.h>
12*4882a593Smuzhiyun #include <linux/delay.h>
13*4882a593Smuzhiyun #include <linux/gpio/consumer.h>
14*4882a593Smuzhiyun #include <linux/i2c.h>
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/of_graph.h>
17*4882a593Smuzhiyun #include <linux/pm_runtime.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <media/i2c/ov2659.h>
20*4882a593Smuzhiyun #include <media/v4l2-ctrls.h>
21*4882a593Smuzhiyun #include <media/v4l2-event.h>
22*4882a593Smuzhiyun #include <media/v4l2-fwnode.h>
23*4882a593Smuzhiyun #include <media/v4l2-image-sizes.h>
24*4882a593Smuzhiyun #include <media/v4l2-subdev.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define DRIVER_NAME "ov2659"
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun * OV2659 register definitions
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun #define REG_SOFTWARE_STANDBY 0x0100
32*4882a593Smuzhiyun #define REG_SOFTWARE_RESET 0x0103
33*4882a593Smuzhiyun #define REG_IO_CTRL00 0x3000
34*4882a593Smuzhiyun #define REG_IO_CTRL01 0x3001
35*4882a593Smuzhiyun #define REG_IO_CTRL02 0x3002
36*4882a593Smuzhiyun #define REG_OUTPUT_VALUE00 0x3008
37*4882a593Smuzhiyun #define REG_OUTPUT_VALUE01 0x3009
38*4882a593Smuzhiyun #define REG_OUTPUT_VALUE02 0x300d
39*4882a593Smuzhiyun #define REG_OUTPUT_SELECT00 0x300e
40*4882a593Smuzhiyun #define REG_OUTPUT_SELECT01 0x300f
41*4882a593Smuzhiyun #define REG_OUTPUT_SELECT02 0x3010
42*4882a593Smuzhiyun #define REG_OUTPUT_DRIVE 0x3011
43*4882a593Smuzhiyun #define REG_INPUT_READOUT00 0x302d
44*4882a593Smuzhiyun #define REG_INPUT_READOUT01 0x302e
45*4882a593Smuzhiyun #define REG_INPUT_READOUT02 0x302f
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun #define REG_SC_PLL_CTRL0 0x3003
48*4882a593Smuzhiyun #define REG_SC_PLL_CTRL1 0x3004
49*4882a593Smuzhiyun #define REG_SC_PLL_CTRL2 0x3005
50*4882a593Smuzhiyun #define REG_SC_PLL_CTRL3 0x3006
51*4882a593Smuzhiyun #define REG_SC_CHIP_ID_H 0x300a
52*4882a593Smuzhiyun #define REG_SC_CHIP_ID_L 0x300b
53*4882a593Smuzhiyun #define REG_SC_PWC 0x3014
54*4882a593Smuzhiyun #define REG_SC_CLKRST0 0x301a
55*4882a593Smuzhiyun #define REG_SC_CLKRST1 0x301b
56*4882a593Smuzhiyun #define REG_SC_CLKRST2 0x301c
57*4882a593Smuzhiyun #define REG_SC_CLKRST3 0x301d
58*4882a593Smuzhiyun #define REG_SC_SUB_ID 0x302a
59*4882a593Smuzhiyun #define REG_SC_SCCB_ID 0x302b
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun #define REG_GROUP_ADDRESS_00 0x3200
62*4882a593Smuzhiyun #define REG_GROUP_ADDRESS_01 0x3201
63*4882a593Smuzhiyun #define REG_GROUP_ADDRESS_02 0x3202
64*4882a593Smuzhiyun #define REG_GROUP_ADDRESS_03 0x3203
65*4882a593Smuzhiyun #define REG_GROUP_ACCESS 0x3208
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #define REG_AWB_R_GAIN_H 0x3400
68*4882a593Smuzhiyun #define REG_AWB_R_GAIN_L 0x3401
69*4882a593Smuzhiyun #define REG_AWB_G_GAIN_H 0x3402
70*4882a593Smuzhiyun #define REG_AWB_G_GAIN_L 0x3403
71*4882a593Smuzhiyun #define REG_AWB_B_GAIN_H 0x3404
72*4882a593Smuzhiyun #define REG_AWB_B_GAIN_L 0x3405
73*4882a593Smuzhiyun #define REG_AWB_MANUAL_CONTROL 0x3406
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun #define REG_TIMING_HS_H 0x3800
76*4882a593Smuzhiyun #define REG_TIMING_HS_L 0x3801
77*4882a593Smuzhiyun #define REG_TIMING_VS_H 0x3802
78*4882a593Smuzhiyun #define REG_TIMING_VS_L 0x3803
79*4882a593Smuzhiyun #define REG_TIMING_HW_H 0x3804
80*4882a593Smuzhiyun #define REG_TIMING_HW_L 0x3805
81*4882a593Smuzhiyun #define REG_TIMING_VH_H 0x3806
82*4882a593Smuzhiyun #define REG_TIMING_VH_L 0x3807
83*4882a593Smuzhiyun #define REG_TIMING_DVPHO_H 0x3808
84*4882a593Smuzhiyun #define REG_TIMING_DVPHO_L 0x3809
85*4882a593Smuzhiyun #define REG_TIMING_DVPVO_H 0x380a
86*4882a593Smuzhiyun #define REG_TIMING_DVPVO_L 0x380b
87*4882a593Smuzhiyun #define REG_TIMING_HTS_H 0x380c
88*4882a593Smuzhiyun #define REG_TIMING_HTS_L 0x380d
89*4882a593Smuzhiyun #define REG_TIMING_VTS_H 0x380e
90*4882a593Smuzhiyun #define REG_TIMING_VTS_L 0x380f
91*4882a593Smuzhiyun #define REG_TIMING_HOFFS_H 0x3810
92*4882a593Smuzhiyun #define REG_TIMING_HOFFS_L 0x3811
93*4882a593Smuzhiyun #define REG_TIMING_VOFFS_H 0x3812
94*4882a593Smuzhiyun #define REG_TIMING_VOFFS_L 0x3813
95*4882a593Smuzhiyun #define REG_TIMING_XINC 0x3814
96*4882a593Smuzhiyun #define REG_TIMING_YINC 0x3815
97*4882a593Smuzhiyun #define REG_TIMING_VERT_FORMAT 0x3820
98*4882a593Smuzhiyun #define REG_TIMING_HORIZ_FORMAT 0x3821
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #define REG_FORMAT_CTRL00 0x4300
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #define REG_VFIFO_READ_START_H 0x4608
103*4882a593Smuzhiyun #define REG_VFIFO_READ_START_L 0x4609
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun #define REG_DVP_CTRL02 0x4708
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun #define REG_ISP_CTRL00 0x5000
108*4882a593Smuzhiyun #define REG_ISP_CTRL01 0x5001
109*4882a593Smuzhiyun #define REG_ISP_CTRL02 0x5002
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun #define REG_LENC_RED_X0_H 0x500c
112*4882a593Smuzhiyun #define REG_LENC_RED_X0_L 0x500d
113*4882a593Smuzhiyun #define REG_LENC_RED_Y0_H 0x500e
114*4882a593Smuzhiyun #define REG_LENC_RED_Y0_L 0x500f
115*4882a593Smuzhiyun #define REG_LENC_RED_A1 0x5010
116*4882a593Smuzhiyun #define REG_LENC_RED_B1 0x5011
117*4882a593Smuzhiyun #define REG_LENC_RED_A2_B2 0x5012
118*4882a593Smuzhiyun #define REG_LENC_GREEN_X0_H 0x5013
119*4882a593Smuzhiyun #define REG_LENC_GREEN_X0_L 0x5014
120*4882a593Smuzhiyun #define REG_LENC_GREEN_Y0_H 0x5015
121*4882a593Smuzhiyun #define REG_LENC_GREEN_Y0_L 0x5016
122*4882a593Smuzhiyun #define REG_LENC_GREEN_A1 0x5017
123*4882a593Smuzhiyun #define REG_LENC_GREEN_B1 0x5018
124*4882a593Smuzhiyun #define REG_LENC_GREEN_A2_B2 0x5019
125*4882a593Smuzhiyun #define REG_LENC_BLUE_X0_H 0x501a
126*4882a593Smuzhiyun #define REG_LENC_BLUE_X0_L 0x501b
127*4882a593Smuzhiyun #define REG_LENC_BLUE_Y0_H 0x501c
128*4882a593Smuzhiyun #define REG_LENC_BLUE_Y0_L 0x501d
129*4882a593Smuzhiyun #define REG_LENC_BLUE_A1 0x501e
130*4882a593Smuzhiyun #define REG_LENC_BLUE_B1 0x501f
131*4882a593Smuzhiyun #define REG_LENC_BLUE_A2_B2 0x5020
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun #define REG_AWB_CTRL00 0x5035
134*4882a593Smuzhiyun #define REG_AWB_CTRL01 0x5036
135*4882a593Smuzhiyun #define REG_AWB_CTRL02 0x5037
136*4882a593Smuzhiyun #define REG_AWB_CTRL03 0x5038
137*4882a593Smuzhiyun #define REG_AWB_CTRL04 0x5039
138*4882a593Smuzhiyun #define REG_AWB_LOCAL_LIMIT 0x503a
139*4882a593Smuzhiyun #define REG_AWB_CTRL12 0x5049
140*4882a593Smuzhiyun #define REG_AWB_CTRL13 0x504a
141*4882a593Smuzhiyun #define REG_AWB_CTRL14 0x504b
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun #define REG_SHARPENMT_THRESH1 0x5064
144*4882a593Smuzhiyun #define REG_SHARPENMT_THRESH2 0x5065
145*4882a593Smuzhiyun #define REG_SHARPENMT_OFFSET1 0x5066
146*4882a593Smuzhiyun #define REG_SHARPENMT_OFFSET2 0x5067
147*4882a593Smuzhiyun #define REG_DENOISE_THRESH1 0x5068
148*4882a593Smuzhiyun #define REG_DENOISE_THRESH2 0x5069
149*4882a593Smuzhiyun #define REG_DENOISE_OFFSET1 0x506a
150*4882a593Smuzhiyun #define REG_DENOISE_OFFSET2 0x506b
151*4882a593Smuzhiyun #define REG_SHARPEN_THRESH1 0x506c
152*4882a593Smuzhiyun #define REG_SHARPEN_THRESH2 0x506d
153*4882a593Smuzhiyun #define REG_CIP_CTRL00 0x506e
154*4882a593Smuzhiyun #define REG_CIP_CTRL01 0x506f
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun #define REG_CMX_SIGN 0x5079
157*4882a593Smuzhiyun #define REG_CMX_MISC_CTRL 0x507a
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun #define REG_PRE_ISP_CTRL00 0x50a0
160*4882a593Smuzhiyun #define TEST_PATTERN_ENABLE BIT(7)
161*4882a593Smuzhiyun #define VERTICAL_COLOR_BAR_MASK 0x53
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun #define REG_NULL 0x0000 /* Array end token */
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun #define OV265X_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
166*4882a593Smuzhiyun #define OV2659_ID 0x2656
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun struct sensor_register {
169*4882a593Smuzhiyun u16 addr;
170*4882a593Smuzhiyun u8 value;
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun struct ov2659_framesize {
174*4882a593Smuzhiyun u16 width;
175*4882a593Smuzhiyun u16 height;
176*4882a593Smuzhiyun u16 max_exp_lines;
177*4882a593Smuzhiyun const struct sensor_register *regs;
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun struct ov2659_pll_ctrl {
181*4882a593Smuzhiyun u8 ctrl1;
182*4882a593Smuzhiyun u8 ctrl2;
183*4882a593Smuzhiyun u8 ctrl3;
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun struct ov2659_pixfmt {
187*4882a593Smuzhiyun u32 code;
188*4882a593Smuzhiyun /* Output format Register Value (REG_FORMAT_CTRL00) */
189*4882a593Smuzhiyun struct sensor_register *format_ctrl_regs;
190*4882a593Smuzhiyun };
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun struct pll_ctrl_reg {
193*4882a593Smuzhiyun unsigned int div;
194*4882a593Smuzhiyun unsigned char reg;
195*4882a593Smuzhiyun };
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun struct ov2659 {
198*4882a593Smuzhiyun struct v4l2_subdev sd;
199*4882a593Smuzhiyun struct media_pad pad;
200*4882a593Smuzhiyun struct v4l2_mbus_framefmt format;
201*4882a593Smuzhiyun unsigned int xvclk_frequency;
202*4882a593Smuzhiyun const struct ov2659_platform_data *pdata;
203*4882a593Smuzhiyun struct mutex lock;
204*4882a593Smuzhiyun struct i2c_client *client;
205*4882a593Smuzhiyun struct v4l2_ctrl_handler ctrls;
206*4882a593Smuzhiyun struct v4l2_ctrl *link_frequency;
207*4882a593Smuzhiyun struct clk *clk;
208*4882a593Smuzhiyun const struct ov2659_framesize *frame_size;
209*4882a593Smuzhiyun struct sensor_register *format_ctrl_regs;
210*4882a593Smuzhiyun struct ov2659_pll_ctrl pll;
211*4882a593Smuzhiyun int streaming;
212*4882a593Smuzhiyun /* used to control the sensor PWDN pin */
213*4882a593Smuzhiyun struct gpio_desc *pwdn_gpio;
214*4882a593Smuzhiyun /* used to control the sensor RESETB pin */
215*4882a593Smuzhiyun struct gpio_desc *resetb_gpio;
216*4882a593Smuzhiyun };
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun static const struct sensor_register ov2659_init_regs[] = {
219*4882a593Smuzhiyun { REG_IO_CTRL00, 0x03 },
220*4882a593Smuzhiyun { REG_IO_CTRL01, 0xff },
221*4882a593Smuzhiyun { REG_IO_CTRL02, 0xe0 },
222*4882a593Smuzhiyun { 0x3633, 0x3d },
223*4882a593Smuzhiyun { 0x3620, 0x02 },
224*4882a593Smuzhiyun { 0x3631, 0x11 },
225*4882a593Smuzhiyun { 0x3612, 0x04 },
226*4882a593Smuzhiyun { 0x3630, 0x20 },
227*4882a593Smuzhiyun { 0x4702, 0x02 },
228*4882a593Smuzhiyun { 0x370c, 0x34 },
229*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
230*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
231*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
232*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
233*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
234*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
235*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
236*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
237*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x03 },
238*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x20 },
239*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x02 },
240*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0x58 },
241*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x05 },
242*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x14 },
243*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x02 },
244*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0x68 },
245*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x08 },
246*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x02 },
247*4882a593Smuzhiyun { REG_TIMING_XINC, 0x31 },
248*4882a593Smuzhiyun { REG_TIMING_YINC, 0x31 },
249*4882a593Smuzhiyun { 0x3a02, 0x02 },
250*4882a593Smuzhiyun { 0x3a03, 0x68 },
251*4882a593Smuzhiyun { 0x3a08, 0x00 },
252*4882a593Smuzhiyun { 0x3a09, 0x5c },
253*4882a593Smuzhiyun { 0x3a0a, 0x00 },
254*4882a593Smuzhiyun { 0x3a0b, 0x4d },
255*4882a593Smuzhiyun { 0x3a0d, 0x08 },
256*4882a593Smuzhiyun { 0x3a0e, 0x06 },
257*4882a593Smuzhiyun { 0x3a14, 0x02 },
258*4882a593Smuzhiyun { 0x3a15, 0x28 },
259*4882a593Smuzhiyun { REG_DVP_CTRL02, 0x01 },
260*4882a593Smuzhiyun { 0x3623, 0x00 },
261*4882a593Smuzhiyun { 0x3634, 0x76 },
262*4882a593Smuzhiyun { 0x3701, 0x44 },
263*4882a593Smuzhiyun { 0x3702, 0x18 },
264*4882a593Smuzhiyun { 0x3703, 0x24 },
265*4882a593Smuzhiyun { 0x3704, 0x24 },
266*4882a593Smuzhiyun { 0x3705, 0x0c },
267*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x81 },
268*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x01 },
269*4882a593Smuzhiyun { 0x370a, 0x52 },
270*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
271*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
272*4882a593Smuzhiyun { REG_FORMAT_CTRL00, 0x30 },
273*4882a593Smuzhiyun { 0x5086, 0x02 },
274*4882a593Smuzhiyun { REG_ISP_CTRL00, 0xfb },
275*4882a593Smuzhiyun { REG_ISP_CTRL01, 0x1f },
276*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
277*4882a593Smuzhiyun { 0x5025, 0x0e },
278*4882a593Smuzhiyun { 0x5026, 0x18 },
279*4882a593Smuzhiyun { 0x5027, 0x34 },
280*4882a593Smuzhiyun { 0x5028, 0x4c },
281*4882a593Smuzhiyun { 0x5029, 0x62 },
282*4882a593Smuzhiyun { 0x502a, 0x74 },
283*4882a593Smuzhiyun { 0x502b, 0x85 },
284*4882a593Smuzhiyun { 0x502c, 0x92 },
285*4882a593Smuzhiyun { 0x502d, 0x9e },
286*4882a593Smuzhiyun { 0x502e, 0xb2 },
287*4882a593Smuzhiyun { 0x502f, 0xc0 },
288*4882a593Smuzhiyun { 0x5030, 0xcc },
289*4882a593Smuzhiyun { 0x5031, 0xe0 },
290*4882a593Smuzhiyun { 0x5032, 0xee },
291*4882a593Smuzhiyun { 0x5033, 0xf6 },
292*4882a593Smuzhiyun { 0x5034, 0x11 },
293*4882a593Smuzhiyun { 0x5070, 0x1c },
294*4882a593Smuzhiyun { 0x5071, 0x5b },
295*4882a593Smuzhiyun { 0x5072, 0x05 },
296*4882a593Smuzhiyun { 0x5073, 0x20 },
297*4882a593Smuzhiyun { 0x5074, 0x94 },
298*4882a593Smuzhiyun { 0x5075, 0xb4 },
299*4882a593Smuzhiyun { 0x5076, 0xb4 },
300*4882a593Smuzhiyun { 0x5077, 0xaf },
301*4882a593Smuzhiyun { 0x5078, 0x05 },
302*4882a593Smuzhiyun { REG_CMX_SIGN, 0x98 },
303*4882a593Smuzhiyun { REG_CMX_MISC_CTRL, 0x21 },
304*4882a593Smuzhiyun { REG_AWB_CTRL00, 0x6a },
305*4882a593Smuzhiyun { REG_AWB_CTRL01, 0x11 },
306*4882a593Smuzhiyun { REG_AWB_CTRL02, 0x92 },
307*4882a593Smuzhiyun { REG_AWB_CTRL03, 0x21 },
308*4882a593Smuzhiyun { REG_AWB_CTRL04, 0xe1 },
309*4882a593Smuzhiyun { REG_AWB_LOCAL_LIMIT, 0x01 },
310*4882a593Smuzhiyun { 0x503c, 0x05 },
311*4882a593Smuzhiyun { 0x503d, 0x08 },
312*4882a593Smuzhiyun { 0x503e, 0x08 },
313*4882a593Smuzhiyun { 0x503f, 0x64 },
314*4882a593Smuzhiyun { 0x5040, 0x58 },
315*4882a593Smuzhiyun { 0x5041, 0x2a },
316*4882a593Smuzhiyun { 0x5042, 0xc5 },
317*4882a593Smuzhiyun { 0x5043, 0x2e },
318*4882a593Smuzhiyun { 0x5044, 0x3a },
319*4882a593Smuzhiyun { 0x5045, 0x3c },
320*4882a593Smuzhiyun { 0x5046, 0x44 },
321*4882a593Smuzhiyun { 0x5047, 0xf8 },
322*4882a593Smuzhiyun { 0x5048, 0x08 },
323*4882a593Smuzhiyun { REG_AWB_CTRL12, 0x70 },
324*4882a593Smuzhiyun { REG_AWB_CTRL13, 0xf0 },
325*4882a593Smuzhiyun { REG_AWB_CTRL14, 0xf0 },
326*4882a593Smuzhiyun { REG_LENC_RED_X0_H, 0x03 },
327*4882a593Smuzhiyun { REG_LENC_RED_X0_L, 0x20 },
328*4882a593Smuzhiyun { REG_LENC_RED_Y0_H, 0x02 },
329*4882a593Smuzhiyun { REG_LENC_RED_Y0_L, 0x5c },
330*4882a593Smuzhiyun { REG_LENC_RED_A1, 0x48 },
331*4882a593Smuzhiyun { REG_LENC_RED_B1, 0x00 },
332*4882a593Smuzhiyun { REG_LENC_RED_A2_B2, 0x66 },
333*4882a593Smuzhiyun { REG_LENC_GREEN_X0_H, 0x03 },
334*4882a593Smuzhiyun { REG_LENC_GREEN_X0_L, 0x30 },
335*4882a593Smuzhiyun { REG_LENC_GREEN_Y0_H, 0x02 },
336*4882a593Smuzhiyun { REG_LENC_GREEN_Y0_L, 0x7c },
337*4882a593Smuzhiyun { REG_LENC_GREEN_A1, 0x40 },
338*4882a593Smuzhiyun { REG_LENC_GREEN_B1, 0x00 },
339*4882a593Smuzhiyun { REG_LENC_GREEN_A2_B2, 0x66 },
340*4882a593Smuzhiyun { REG_LENC_BLUE_X0_H, 0x03 },
341*4882a593Smuzhiyun { REG_LENC_BLUE_X0_L, 0x10 },
342*4882a593Smuzhiyun { REG_LENC_BLUE_Y0_H, 0x02 },
343*4882a593Smuzhiyun { REG_LENC_BLUE_Y0_L, 0x7c },
344*4882a593Smuzhiyun { REG_LENC_BLUE_A1, 0x3a },
345*4882a593Smuzhiyun { REG_LENC_BLUE_B1, 0x00 },
346*4882a593Smuzhiyun { REG_LENC_BLUE_A2_B2, 0x66 },
347*4882a593Smuzhiyun { REG_CIP_CTRL00, 0x44 },
348*4882a593Smuzhiyun { REG_SHARPENMT_THRESH1, 0x08 },
349*4882a593Smuzhiyun { REG_SHARPENMT_THRESH2, 0x10 },
350*4882a593Smuzhiyun { REG_SHARPENMT_OFFSET1, 0x12 },
351*4882a593Smuzhiyun { REG_SHARPENMT_OFFSET2, 0x02 },
352*4882a593Smuzhiyun { REG_SHARPEN_THRESH1, 0x08 },
353*4882a593Smuzhiyun { REG_SHARPEN_THRESH2, 0x10 },
354*4882a593Smuzhiyun { REG_CIP_CTRL01, 0xa6 },
355*4882a593Smuzhiyun { REG_DENOISE_THRESH1, 0x08 },
356*4882a593Smuzhiyun { REG_DENOISE_THRESH2, 0x10 },
357*4882a593Smuzhiyun { REG_DENOISE_OFFSET1, 0x04 },
358*4882a593Smuzhiyun { REG_DENOISE_OFFSET2, 0x12 },
359*4882a593Smuzhiyun { 0x507e, 0x40 },
360*4882a593Smuzhiyun { 0x507f, 0x20 },
361*4882a593Smuzhiyun { 0x507b, 0x02 },
362*4882a593Smuzhiyun { REG_CMX_MISC_CTRL, 0x01 },
363*4882a593Smuzhiyun { 0x5084, 0x0c },
364*4882a593Smuzhiyun { 0x5085, 0x3e },
365*4882a593Smuzhiyun { 0x5005, 0x80 },
366*4882a593Smuzhiyun { 0x3a0f, 0x30 },
367*4882a593Smuzhiyun { 0x3a10, 0x28 },
368*4882a593Smuzhiyun { 0x3a1b, 0x32 },
369*4882a593Smuzhiyun { 0x3a1e, 0x26 },
370*4882a593Smuzhiyun { 0x3a11, 0x60 },
371*4882a593Smuzhiyun { 0x3a1f, 0x14 },
372*4882a593Smuzhiyun { 0x5060, 0x69 },
373*4882a593Smuzhiyun { 0x5061, 0x7d },
374*4882a593Smuzhiyun { 0x5062, 0x7d },
375*4882a593Smuzhiyun { 0x5063, 0x69 },
376*4882a593Smuzhiyun { REG_NULL, 0x00 },
377*4882a593Smuzhiyun };
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /* 1280X720 720p */
380*4882a593Smuzhiyun static struct sensor_register ov2659_720p[] = {
381*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
382*4882a593Smuzhiyun { REG_TIMING_HS_L, 0xa0 },
383*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
384*4882a593Smuzhiyun { REG_TIMING_VS_L, 0xf0 },
385*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x05 },
386*4882a593Smuzhiyun { REG_TIMING_HW_L, 0xbf },
387*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x03 },
388*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xcb },
389*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x05 },
390*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x00 },
391*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x02 },
392*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0xd0 },
393*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x06 },
394*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x4c },
395*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x02 },
396*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0xe8 },
397*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x10 },
398*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x06 },
399*4882a593Smuzhiyun { REG_TIMING_XINC, 0x11 },
400*4882a593Smuzhiyun { REG_TIMING_YINC, 0x11 },
401*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x80 },
402*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x00 },
403*4882a593Smuzhiyun { 0x370a, 0x12 },
404*4882a593Smuzhiyun { 0x3a03, 0xe8 },
405*4882a593Smuzhiyun { 0x3a09, 0x6f },
406*4882a593Smuzhiyun { 0x3a0b, 0x5d },
407*4882a593Smuzhiyun { 0x3a15, 0x9a },
408*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
409*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
410*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
411*4882a593Smuzhiyun { REG_NULL, 0x00 },
412*4882a593Smuzhiyun };
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /* 1600X1200 UXGA */
415*4882a593Smuzhiyun static struct sensor_register ov2659_uxga[] = {
416*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
417*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
418*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
419*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
420*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
421*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
422*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
423*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xbb },
424*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x06 },
425*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x40 },
426*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x04 },
427*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0xb0 },
428*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x07 },
429*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x9f },
430*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x04 },
431*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0xd0 },
432*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x10 },
433*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x06 },
434*4882a593Smuzhiyun { REG_TIMING_XINC, 0x11 },
435*4882a593Smuzhiyun { REG_TIMING_YINC, 0x11 },
436*4882a593Smuzhiyun { 0x3a02, 0x04 },
437*4882a593Smuzhiyun { 0x3a03, 0xd0 },
438*4882a593Smuzhiyun { 0x3a08, 0x00 },
439*4882a593Smuzhiyun { 0x3a09, 0xb8 },
440*4882a593Smuzhiyun { 0x3a0a, 0x00 },
441*4882a593Smuzhiyun { 0x3a0b, 0x9a },
442*4882a593Smuzhiyun { 0x3a0d, 0x08 },
443*4882a593Smuzhiyun { 0x3a0e, 0x06 },
444*4882a593Smuzhiyun { 0x3a14, 0x04 },
445*4882a593Smuzhiyun { 0x3a15, 0x50 },
446*4882a593Smuzhiyun { 0x3623, 0x00 },
447*4882a593Smuzhiyun { 0x3634, 0x44 },
448*4882a593Smuzhiyun { 0x3701, 0x44 },
449*4882a593Smuzhiyun { 0x3702, 0x30 },
450*4882a593Smuzhiyun { 0x3703, 0x48 },
451*4882a593Smuzhiyun { 0x3704, 0x48 },
452*4882a593Smuzhiyun { 0x3705, 0x18 },
453*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x80 },
454*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x00 },
455*4882a593Smuzhiyun { 0x370a, 0x12 },
456*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
457*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
458*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
459*4882a593Smuzhiyun { REG_NULL, 0x00 },
460*4882a593Smuzhiyun };
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun /* 1280X1024 SXGA */
463*4882a593Smuzhiyun static struct sensor_register ov2659_sxga[] = {
464*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
465*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
466*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
467*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
468*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
469*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
470*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
471*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
472*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x05 },
473*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x00 },
474*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x04 },
475*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0x00 },
476*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x07 },
477*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x9c },
478*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x04 },
479*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0xd0 },
480*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x10 },
481*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x06 },
482*4882a593Smuzhiyun { REG_TIMING_XINC, 0x11 },
483*4882a593Smuzhiyun { REG_TIMING_YINC, 0x11 },
484*4882a593Smuzhiyun { 0x3a02, 0x02 },
485*4882a593Smuzhiyun { 0x3a03, 0x68 },
486*4882a593Smuzhiyun { 0x3a08, 0x00 },
487*4882a593Smuzhiyun { 0x3a09, 0x5c },
488*4882a593Smuzhiyun { 0x3a0a, 0x00 },
489*4882a593Smuzhiyun { 0x3a0b, 0x4d },
490*4882a593Smuzhiyun { 0x3a0d, 0x08 },
491*4882a593Smuzhiyun { 0x3a0e, 0x06 },
492*4882a593Smuzhiyun { 0x3a14, 0x02 },
493*4882a593Smuzhiyun { 0x3a15, 0x28 },
494*4882a593Smuzhiyun { 0x3623, 0x00 },
495*4882a593Smuzhiyun { 0x3634, 0x76 },
496*4882a593Smuzhiyun { 0x3701, 0x44 },
497*4882a593Smuzhiyun { 0x3702, 0x18 },
498*4882a593Smuzhiyun { 0x3703, 0x24 },
499*4882a593Smuzhiyun { 0x3704, 0x24 },
500*4882a593Smuzhiyun { 0x3705, 0x0c },
501*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x80 },
502*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x00 },
503*4882a593Smuzhiyun { 0x370a, 0x52 },
504*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
505*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
506*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
507*4882a593Smuzhiyun { REG_NULL, 0x00 },
508*4882a593Smuzhiyun };
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun /* 1024X768 SXGA */
511*4882a593Smuzhiyun static struct sensor_register ov2659_xga[] = {
512*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
513*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
514*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
515*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
516*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
517*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
518*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
519*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
520*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x04 },
521*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x00 },
522*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x03 },
523*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0x00 },
524*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x07 },
525*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x9c },
526*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x04 },
527*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0xd0 },
528*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x10 },
529*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x06 },
530*4882a593Smuzhiyun { REG_TIMING_XINC, 0x11 },
531*4882a593Smuzhiyun { REG_TIMING_YINC, 0x11 },
532*4882a593Smuzhiyun { 0x3a02, 0x02 },
533*4882a593Smuzhiyun { 0x3a03, 0x68 },
534*4882a593Smuzhiyun { 0x3a08, 0x00 },
535*4882a593Smuzhiyun { 0x3a09, 0x5c },
536*4882a593Smuzhiyun { 0x3a0a, 0x00 },
537*4882a593Smuzhiyun { 0x3a0b, 0x4d },
538*4882a593Smuzhiyun { 0x3a0d, 0x08 },
539*4882a593Smuzhiyun { 0x3a0e, 0x06 },
540*4882a593Smuzhiyun { 0x3a14, 0x02 },
541*4882a593Smuzhiyun { 0x3a15, 0x28 },
542*4882a593Smuzhiyun { 0x3623, 0x00 },
543*4882a593Smuzhiyun { 0x3634, 0x76 },
544*4882a593Smuzhiyun { 0x3701, 0x44 },
545*4882a593Smuzhiyun { 0x3702, 0x18 },
546*4882a593Smuzhiyun { 0x3703, 0x24 },
547*4882a593Smuzhiyun { 0x3704, 0x24 },
548*4882a593Smuzhiyun { 0x3705, 0x0c },
549*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x80 },
550*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x00 },
551*4882a593Smuzhiyun { 0x370a, 0x52 },
552*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
553*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
554*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
555*4882a593Smuzhiyun { REG_NULL, 0x00 },
556*4882a593Smuzhiyun };
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun /* 800X600 SVGA */
559*4882a593Smuzhiyun static struct sensor_register ov2659_svga[] = {
560*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
561*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
562*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
563*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
564*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
565*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
566*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
567*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
568*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x03 },
569*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x20 },
570*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x02 },
571*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0x58 },
572*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x05 },
573*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x14 },
574*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x02 },
575*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0x68 },
576*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x08 },
577*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x02 },
578*4882a593Smuzhiyun { REG_TIMING_XINC, 0x31 },
579*4882a593Smuzhiyun { REG_TIMING_YINC, 0x31 },
580*4882a593Smuzhiyun { 0x3a02, 0x02 },
581*4882a593Smuzhiyun { 0x3a03, 0x68 },
582*4882a593Smuzhiyun { 0x3a08, 0x00 },
583*4882a593Smuzhiyun { 0x3a09, 0x5c },
584*4882a593Smuzhiyun { 0x3a0a, 0x00 },
585*4882a593Smuzhiyun { 0x3a0b, 0x4d },
586*4882a593Smuzhiyun { 0x3a0d, 0x08 },
587*4882a593Smuzhiyun { 0x3a0e, 0x06 },
588*4882a593Smuzhiyun { 0x3a14, 0x02 },
589*4882a593Smuzhiyun { 0x3a15, 0x28 },
590*4882a593Smuzhiyun { 0x3623, 0x00 },
591*4882a593Smuzhiyun { 0x3634, 0x76 },
592*4882a593Smuzhiyun { 0x3701, 0x44 },
593*4882a593Smuzhiyun { 0x3702, 0x18 },
594*4882a593Smuzhiyun { 0x3703, 0x24 },
595*4882a593Smuzhiyun { 0x3704, 0x24 },
596*4882a593Smuzhiyun { 0x3705, 0x0c },
597*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x81 },
598*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x01 },
599*4882a593Smuzhiyun { 0x370a, 0x52 },
600*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
601*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0x80 },
602*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x00 },
603*4882a593Smuzhiyun { REG_NULL, 0x00 },
604*4882a593Smuzhiyun };
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun /* 640X480 VGA */
607*4882a593Smuzhiyun static struct sensor_register ov2659_vga[] = {
608*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
609*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
610*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
611*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
612*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
613*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
614*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
615*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
616*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x02 },
617*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x80 },
618*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x01 },
619*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0xe0 },
620*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x05 },
621*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x14 },
622*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x02 },
623*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0x68 },
624*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x08 },
625*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x02 },
626*4882a593Smuzhiyun { REG_TIMING_XINC, 0x31 },
627*4882a593Smuzhiyun { REG_TIMING_YINC, 0x31 },
628*4882a593Smuzhiyun { 0x3a02, 0x02 },
629*4882a593Smuzhiyun { 0x3a03, 0x68 },
630*4882a593Smuzhiyun { 0x3a08, 0x00 },
631*4882a593Smuzhiyun { 0x3a09, 0x5c },
632*4882a593Smuzhiyun { 0x3a0a, 0x00 },
633*4882a593Smuzhiyun { 0x3a0b, 0x4d },
634*4882a593Smuzhiyun { 0x3a0d, 0x08 },
635*4882a593Smuzhiyun { 0x3a0e, 0x06 },
636*4882a593Smuzhiyun { 0x3a14, 0x02 },
637*4882a593Smuzhiyun { 0x3a15, 0x28 },
638*4882a593Smuzhiyun { 0x3623, 0x00 },
639*4882a593Smuzhiyun { 0x3634, 0x76 },
640*4882a593Smuzhiyun { 0x3701, 0x44 },
641*4882a593Smuzhiyun { 0x3702, 0x18 },
642*4882a593Smuzhiyun { 0x3703, 0x24 },
643*4882a593Smuzhiyun { 0x3704, 0x24 },
644*4882a593Smuzhiyun { 0x3705, 0x0c },
645*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x81 },
646*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x01 },
647*4882a593Smuzhiyun { 0x370a, 0x52 },
648*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
649*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0xa0 },
650*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x10 },
651*4882a593Smuzhiyun { REG_NULL, 0x00 },
652*4882a593Smuzhiyun };
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun /* 320X240 QVGA */
655*4882a593Smuzhiyun static struct sensor_register ov2659_qvga[] = {
656*4882a593Smuzhiyun { REG_TIMING_HS_H, 0x00 },
657*4882a593Smuzhiyun { REG_TIMING_HS_L, 0x00 },
658*4882a593Smuzhiyun { REG_TIMING_VS_H, 0x00 },
659*4882a593Smuzhiyun { REG_TIMING_VS_L, 0x00 },
660*4882a593Smuzhiyun { REG_TIMING_HW_H, 0x06 },
661*4882a593Smuzhiyun { REG_TIMING_HW_L, 0x5f },
662*4882a593Smuzhiyun { REG_TIMING_VH_H, 0x04 },
663*4882a593Smuzhiyun { REG_TIMING_VH_L, 0xb7 },
664*4882a593Smuzhiyun { REG_TIMING_DVPHO_H, 0x01 },
665*4882a593Smuzhiyun { REG_TIMING_DVPHO_L, 0x40 },
666*4882a593Smuzhiyun { REG_TIMING_DVPVO_H, 0x00 },
667*4882a593Smuzhiyun { REG_TIMING_DVPVO_L, 0xf0 },
668*4882a593Smuzhiyun { REG_TIMING_HTS_H, 0x05 },
669*4882a593Smuzhiyun { REG_TIMING_HTS_L, 0x14 },
670*4882a593Smuzhiyun { REG_TIMING_VTS_H, 0x02 },
671*4882a593Smuzhiyun { REG_TIMING_VTS_L, 0x68 },
672*4882a593Smuzhiyun { REG_TIMING_HOFFS_L, 0x08 },
673*4882a593Smuzhiyun { REG_TIMING_VOFFS_L, 0x02 },
674*4882a593Smuzhiyun { REG_TIMING_XINC, 0x31 },
675*4882a593Smuzhiyun { REG_TIMING_YINC, 0x31 },
676*4882a593Smuzhiyun { 0x3a02, 0x02 },
677*4882a593Smuzhiyun { 0x3a03, 0x68 },
678*4882a593Smuzhiyun { 0x3a08, 0x00 },
679*4882a593Smuzhiyun { 0x3a09, 0x5c },
680*4882a593Smuzhiyun { 0x3a0a, 0x00 },
681*4882a593Smuzhiyun { 0x3a0b, 0x4d },
682*4882a593Smuzhiyun { 0x3a0d, 0x08 },
683*4882a593Smuzhiyun { 0x3a0e, 0x06 },
684*4882a593Smuzhiyun { 0x3a14, 0x02 },
685*4882a593Smuzhiyun { 0x3a15, 0x28 },
686*4882a593Smuzhiyun { 0x3623, 0x00 },
687*4882a593Smuzhiyun { 0x3634, 0x76 },
688*4882a593Smuzhiyun { 0x3701, 0x44 },
689*4882a593Smuzhiyun { 0x3702, 0x18 },
690*4882a593Smuzhiyun { 0x3703, 0x24 },
691*4882a593Smuzhiyun { 0x3704, 0x24 },
692*4882a593Smuzhiyun { 0x3705, 0x0c },
693*4882a593Smuzhiyun { REG_TIMING_VERT_FORMAT, 0x81 },
694*4882a593Smuzhiyun { REG_TIMING_HORIZ_FORMAT, 0x01 },
695*4882a593Smuzhiyun { 0x370a, 0x52 },
696*4882a593Smuzhiyun { REG_VFIFO_READ_START_H, 0x00 },
697*4882a593Smuzhiyun { REG_VFIFO_READ_START_L, 0xa0 },
698*4882a593Smuzhiyun { REG_ISP_CTRL02, 0x10 },
699*4882a593Smuzhiyun { REG_NULL, 0x00 },
700*4882a593Smuzhiyun };
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun static const struct pll_ctrl_reg ctrl3[] = {
703*4882a593Smuzhiyun { 1, 0x00 },
704*4882a593Smuzhiyun { 2, 0x02 },
705*4882a593Smuzhiyun { 3, 0x03 },
706*4882a593Smuzhiyun { 4, 0x06 },
707*4882a593Smuzhiyun { 6, 0x0d },
708*4882a593Smuzhiyun { 8, 0x0e },
709*4882a593Smuzhiyun { 12, 0x0f },
710*4882a593Smuzhiyun { 16, 0x12 },
711*4882a593Smuzhiyun { 24, 0x13 },
712*4882a593Smuzhiyun { 32, 0x16 },
713*4882a593Smuzhiyun { 48, 0x1b },
714*4882a593Smuzhiyun { 64, 0x1e },
715*4882a593Smuzhiyun { 96, 0x1f },
716*4882a593Smuzhiyun { 0, 0x00 },
717*4882a593Smuzhiyun };
718*4882a593Smuzhiyun
719*4882a593Smuzhiyun static const struct pll_ctrl_reg ctrl1[] = {
720*4882a593Smuzhiyun { 2, 0x10 },
721*4882a593Smuzhiyun { 4, 0x20 },
722*4882a593Smuzhiyun { 6, 0x30 },
723*4882a593Smuzhiyun { 8, 0x40 },
724*4882a593Smuzhiyun { 10, 0x50 },
725*4882a593Smuzhiyun { 12, 0x60 },
726*4882a593Smuzhiyun { 14, 0x70 },
727*4882a593Smuzhiyun { 16, 0x80 },
728*4882a593Smuzhiyun { 18, 0x90 },
729*4882a593Smuzhiyun { 20, 0xa0 },
730*4882a593Smuzhiyun { 22, 0xb0 },
731*4882a593Smuzhiyun { 24, 0xc0 },
732*4882a593Smuzhiyun { 26, 0xd0 },
733*4882a593Smuzhiyun { 28, 0xe0 },
734*4882a593Smuzhiyun { 30, 0xf0 },
735*4882a593Smuzhiyun { 0, 0x00 },
736*4882a593Smuzhiyun };
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun static const struct ov2659_framesize ov2659_framesizes[] = {
739*4882a593Smuzhiyun { /* QVGA */
740*4882a593Smuzhiyun .width = 320,
741*4882a593Smuzhiyun .height = 240,
742*4882a593Smuzhiyun .regs = ov2659_qvga,
743*4882a593Smuzhiyun .max_exp_lines = 248,
744*4882a593Smuzhiyun }, { /* VGA */
745*4882a593Smuzhiyun .width = 640,
746*4882a593Smuzhiyun .height = 480,
747*4882a593Smuzhiyun .regs = ov2659_vga,
748*4882a593Smuzhiyun .max_exp_lines = 498,
749*4882a593Smuzhiyun }, { /* SVGA */
750*4882a593Smuzhiyun .width = 800,
751*4882a593Smuzhiyun .height = 600,
752*4882a593Smuzhiyun .regs = ov2659_svga,
753*4882a593Smuzhiyun .max_exp_lines = 498,
754*4882a593Smuzhiyun }, { /* XGA */
755*4882a593Smuzhiyun .width = 1024,
756*4882a593Smuzhiyun .height = 768,
757*4882a593Smuzhiyun .regs = ov2659_xga,
758*4882a593Smuzhiyun .max_exp_lines = 498,
759*4882a593Smuzhiyun }, { /* 720P */
760*4882a593Smuzhiyun .width = 1280,
761*4882a593Smuzhiyun .height = 720,
762*4882a593Smuzhiyun .regs = ov2659_720p,
763*4882a593Smuzhiyun .max_exp_lines = 498,
764*4882a593Smuzhiyun }, { /* SXGA */
765*4882a593Smuzhiyun .width = 1280,
766*4882a593Smuzhiyun .height = 1024,
767*4882a593Smuzhiyun .regs = ov2659_sxga,
768*4882a593Smuzhiyun .max_exp_lines = 1048,
769*4882a593Smuzhiyun }, { /* UXGA */
770*4882a593Smuzhiyun .width = 1600,
771*4882a593Smuzhiyun .height = 1200,
772*4882a593Smuzhiyun .regs = ov2659_uxga,
773*4882a593Smuzhiyun .max_exp_lines = 498,
774*4882a593Smuzhiyun },
775*4882a593Smuzhiyun };
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun /* YUV422 YUYV*/
778*4882a593Smuzhiyun static struct sensor_register ov2659_format_yuyv[] = {
779*4882a593Smuzhiyun { REG_FORMAT_CTRL00, 0x30 },
780*4882a593Smuzhiyun { REG_NULL, 0x0 },
781*4882a593Smuzhiyun };
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun /* YUV422 UYVY */
784*4882a593Smuzhiyun static struct sensor_register ov2659_format_uyvy[] = {
785*4882a593Smuzhiyun { REG_FORMAT_CTRL00, 0x32 },
786*4882a593Smuzhiyun { REG_NULL, 0x0 },
787*4882a593Smuzhiyun };
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun /* Raw Bayer BGGR */
790*4882a593Smuzhiyun static struct sensor_register ov2659_format_bggr[] = {
791*4882a593Smuzhiyun { REG_FORMAT_CTRL00, 0x00 },
792*4882a593Smuzhiyun { REG_NULL, 0x0 },
793*4882a593Smuzhiyun };
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun /* RGB565 */
796*4882a593Smuzhiyun static struct sensor_register ov2659_format_rgb565[] = {
797*4882a593Smuzhiyun { REG_FORMAT_CTRL00, 0x60 },
798*4882a593Smuzhiyun { REG_NULL, 0x0 },
799*4882a593Smuzhiyun };
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun static const struct ov2659_pixfmt ov2659_formats[] = {
802*4882a593Smuzhiyun {
803*4882a593Smuzhiyun .code = MEDIA_BUS_FMT_YUYV8_2X8,
804*4882a593Smuzhiyun .format_ctrl_regs = ov2659_format_yuyv,
805*4882a593Smuzhiyun }, {
806*4882a593Smuzhiyun .code = MEDIA_BUS_FMT_UYVY8_2X8,
807*4882a593Smuzhiyun .format_ctrl_regs = ov2659_format_uyvy,
808*4882a593Smuzhiyun }, {
809*4882a593Smuzhiyun .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
810*4882a593Smuzhiyun .format_ctrl_regs = ov2659_format_rgb565,
811*4882a593Smuzhiyun }, {
812*4882a593Smuzhiyun .code = MEDIA_BUS_FMT_SBGGR8_1X8,
813*4882a593Smuzhiyun .format_ctrl_regs = ov2659_format_bggr,
814*4882a593Smuzhiyun },
815*4882a593Smuzhiyun };
816*4882a593Smuzhiyun
to_ov2659(struct v4l2_subdev * sd)817*4882a593Smuzhiyun static inline struct ov2659 *to_ov2659(struct v4l2_subdev *sd)
818*4882a593Smuzhiyun {
819*4882a593Smuzhiyun return container_of(sd, struct ov2659, sd);
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun /* sensor register write */
ov2659_write(struct i2c_client * client,u16 reg,u8 val)823*4882a593Smuzhiyun static int ov2659_write(struct i2c_client *client, u16 reg, u8 val)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun struct i2c_msg msg;
826*4882a593Smuzhiyun u8 buf[3];
827*4882a593Smuzhiyun int ret;
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun buf[0] = reg >> 8;
830*4882a593Smuzhiyun buf[1] = reg & 0xFF;
831*4882a593Smuzhiyun buf[2] = val;
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun msg.addr = client->addr;
834*4882a593Smuzhiyun msg.flags = client->flags;
835*4882a593Smuzhiyun msg.buf = buf;
836*4882a593Smuzhiyun msg.len = sizeof(buf);
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun ret = i2c_transfer(client->adapter, &msg, 1);
839*4882a593Smuzhiyun if (ret >= 0)
840*4882a593Smuzhiyun return 0;
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun dev_dbg(&client->dev,
843*4882a593Smuzhiyun "ov2659 write reg(0x%x val:0x%x) failed !\n", reg, val);
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun return ret;
846*4882a593Smuzhiyun }
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun /* sensor register read */
ov2659_read(struct i2c_client * client,u16 reg,u8 * val)849*4882a593Smuzhiyun static int ov2659_read(struct i2c_client *client, u16 reg, u8 *val)
850*4882a593Smuzhiyun {
851*4882a593Smuzhiyun struct i2c_msg msg[2];
852*4882a593Smuzhiyun u8 buf[2];
853*4882a593Smuzhiyun int ret;
854*4882a593Smuzhiyun
855*4882a593Smuzhiyun buf[0] = reg >> 8;
856*4882a593Smuzhiyun buf[1] = reg & 0xFF;
857*4882a593Smuzhiyun
858*4882a593Smuzhiyun msg[0].addr = client->addr;
859*4882a593Smuzhiyun msg[0].flags = client->flags;
860*4882a593Smuzhiyun msg[0].buf = buf;
861*4882a593Smuzhiyun msg[0].len = sizeof(buf);
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun msg[1].addr = client->addr;
864*4882a593Smuzhiyun msg[1].flags = client->flags | I2C_M_RD;
865*4882a593Smuzhiyun msg[1].buf = buf;
866*4882a593Smuzhiyun msg[1].len = 1;
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun ret = i2c_transfer(client->adapter, msg, 2);
869*4882a593Smuzhiyun if (ret >= 0) {
870*4882a593Smuzhiyun *val = buf[0];
871*4882a593Smuzhiyun return 0;
872*4882a593Smuzhiyun }
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun dev_dbg(&client->dev,
875*4882a593Smuzhiyun "ov2659 read reg(0x%x val:0x%x) failed !\n", reg, *val);
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun return ret;
878*4882a593Smuzhiyun }
879*4882a593Smuzhiyun
ov2659_write_array(struct i2c_client * client,const struct sensor_register * regs)880*4882a593Smuzhiyun static int ov2659_write_array(struct i2c_client *client,
881*4882a593Smuzhiyun const struct sensor_register *regs)
882*4882a593Smuzhiyun {
883*4882a593Smuzhiyun int i, ret = 0;
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun for (i = 0; ret == 0 && regs[i].addr; i++)
886*4882a593Smuzhiyun ret = ov2659_write(client, regs[i].addr, regs[i].value);
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun return ret;
889*4882a593Smuzhiyun }
890*4882a593Smuzhiyun
ov2659_pll_calc_params(struct ov2659 * ov2659)891*4882a593Smuzhiyun static void ov2659_pll_calc_params(struct ov2659 *ov2659)
892*4882a593Smuzhiyun {
893*4882a593Smuzhiyun const struct ov2659_platform_data *pdata = ov2659->pdata;
894*4882a593Smuzhiyun u8 ctrl1_reg = 0, ctrl2_reg = 0, ctrl3_reg = 0;
895*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
896*4882a593Smuzhiyun unsigned int desired = pdata->link_frequency;
897*4882a593Smuzhiyun u32 prediv, postdiv, mult;
898*4882a593Smuzhiyun u32 bestdelta = -1;
899*4882a593Smuzhiyun u32 delta, actual;
900*4882a593Smuzhiyun int i, j;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun for (i = 0; ctrl1[i].div != 0; i++) {
903*4882a593Smuzhiyun postdiv = ctrl1[i].div;
904*4882a593Smuzhiyun for (j = 0; ctrl3[j].div != 0; j++) {
905*4882a593Smuzhiyun prediv = ctrl3[j].div;
906*4882a593Smuzhiyun for (mult = 1; mult <= 63; mult++) {
907*4882a593Smuzhiyun actual = ov2659->xvclk_frequency;
908*4882a593Smuzhiyun actual *= mult;
909*4882a593Smuzhiyun actual /= prediv;
910*4882a593Smuzhiyun actual /= postdiv;
911*4882a593Smuzhiyun delta = actual - desired;
912*4882a593Smuzhiyun delta = abs(delta);
913*4882a593Smuzhiyun
914*4882a593Smuzhiyun if ((delta < bestdelta) || (bestdelta == -1)) {
915*4882a593Smuzhiyun bestdelta = delta;
916*4882a593Smuzhiyun ctrl1_reg = ctrl1[i].reg;
917*4882a593Smuzhiyun ctrl2_reg = mult;
918*4882a593Smuzhiyun ctrl3_reg = ctrl3[j].reg;
919*4882a593Smuzhiyun }
920*4882a593Smuzhiyun }
921*4882a593Smuzhiyun }
922*4882a593Smuzhiyun }
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun ov2659->pll.ctrl1 = ctrl1_reg;
925*4882a593Smuzhiyun ov2659->pll.ctrl2 = ctrl2_reg;
926*4882a593Smuzhiyun ov2659->pll.ctrl3 = ctrl3_reg;
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun dev_dbg(&client->dev,
929*4882a593Smuzhiyun "Actual reg config: ctrl1_reg: %02x ctrl2_reg: %02x ctrl3_reg: %02x\n",
930*4882a593Smuzhiyun ctrl1_reg, ctrl2_reg, ctrl3_reg);
931*4882a593Smuzhiyun }
932*4882a593Smuzhiyun
ov2659_set_pixel_clock(struct ov2659 * ov2659)933*4882a593Smuzhiyun static int ov2659_set_pixel_clock(struct ov2659 *ov2659)
934*4882a593Smuzhiyun {
935*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
936*4882a593Smuzhiyun struct sensor_register pll_regs[] = {
937*4882a593Smuzhiyun {REG_SC_PLL_CTRL1, ov2659->pll.ctrl1},
938*4882a593Smuzhiyun {REG_SC_PLL_CTRL2, ov2659->pll.ctrl2},
939*4882a593Smuzhiyun {REG_SC_PLL_CTRL3, ov2659->pll.ctrl3},
940*4882a593Smuzhiyun {REG_NULL, 0x00},
941*4882a593Smuzhiyun };
942*4882a593Smuzhiyun
943*4882a593Smuzhiyun dev_dbg(&client->dev, "%s\n", __func__);
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun return ov2659_write_array(client, pll_regs);
946*4882a593Smuzhiyun };
947*4882a593Smuzhiyun
ov2659_get_default_format(struct v4l2_mbus_framefmt * format)948*4882a593Smuzhiyun static void ov2659_get_default_format(struct v4l2_mbus_framefmt *format)
949*4882a593Smuzhiyun {
950*4882a593Smuzhiyun format->width = ov2659_framesizes[2].width;
951*4882a593Smuzhiyun format->height = ov2659_framesizes[2].height;
952*4882a593Smuzhiyun format->colorspace = V4L2_COLORSPACE_SRGB;
953*4882a593Smuzhiyun format->code = ov2659_formats[0].code;
954*4882a593Smuzhiyun format->field = V4L2_FIELD_NONE;
955*4882a593Smuzhiyun }
956*4882a593Smuzhiyun
ov2659_set_streaming(struct ov2659 * ov2659,int on)957*4882a593Smuzhiyun static void ov2659_set_streaming(struct ov2659 *ov2659, int on)
958*4882a593Smuzhiyun {
959*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
960*4882a593Smuzhiyun int ret;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun on = !!on;
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun dev_dbg(&client->dev, "%s: on: %d\n", __func__, on);
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun ret = ov2659_write(client, REG_SOFTWARE_STANDBY, on);
967*4882a593Smuzhiyun if (ret)
968*4882a593Smuzhiyun dev_err(&client->dev, "ov2659 soft standby failed\n");
969*4882a593Smuzhiyun }
970*4882a593Smuzhiyun
ov2659_init(struct v4l2_subdev * sd,u32 val)971*4882a593Smuzhiyun static int ov2659_init(struct v4l2_subdev *sd, u32 val)
972*4882a593Smuzhiyun {
973*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun return ov2659_write_array(client, ov2659_init_regs);
976*4882a593Smuzhiyun }
977*4882a593Smuzhiyun
978*4882a593Smuzhiyun /*
979*4882a593Smuzhiyun * V4L2 subdev video and pad level operations
980*4882a593Smuzhiyun */
981*4882a593Smuzhiyun
ov2659_enum_mbus_code(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_mbus_code_enum * code)982*4882a593Smuzhiyun static int ov2659_enum_mbus_code(struct v4l2_subdev *sd,
983*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
984*4882a593Smuzhiyun struct v4l2_subdev_mbus_code_enum *code)
985*4882a593Smuzhiyun {
986*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
987*4882a593Smuzhiyun
988*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun if (code->index >= ARRAY_SIZE(ov2659_formats))
991*4882a593Smuzhiyun return -EINVAL;
992*4882a593Smuzhiyun
993*4882a593Smuzhiyun code->code = ov2659_formats[code->index].code;
994*4882a593Smuzhiyun
995*4882a593Smuzhiyun return 0;
996*4882a593Smuzhiyun }
997*4882a593Smuzhiyun
ov2659_enum_frame_sizes(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_frame_size_enum * fse)998*4882a593Smuzhiyun static int ov2659_enum_frame_sizes(struct v4l2_subdev *sd,
999*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1000*4882a593Smuzhiyun struct v4l2_subdev_frame_size_enum *fse)
1001*4882a593Smuzhiyun {
1002*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1003*4882a593Smuzhiyun int i = ARRAY_SIZE(ov2659_formats);
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun if (fse->index >= ARRAY_SIZE(ov2659_framesizes))
1008*4882a593Smuzhiyun return -EINVAL;
1009*4882a593Smuzhiyun
1010*4882a593Smuzhiyun while (--i)
1011*4882a593Smuzhiyun if (fse->code == ov2659_formats[i].code)
1012*4882a593Smuzhiyun break;
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun fse->code = ov2659_formats[i].code;
1015*4882a593Smuzhiyun
1016*4882a593Smuzhiyun fse->min_width = ov2659_framesizes[fse->index].width;
1017*4882a593Smuzhiyun fse->max_width = fse->min_width;
1018*4882a593Smuzhiyun fse->max_height = ov2659_framesizes[fse->index].height;
1019*4882a593Smuzhiyun fse->min_height = fse->max_height;
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun return 0;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun
ov2659_get_fmt(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_format * fmt)1024*4882a593Smuzhiyun static int ov2659_get_fmt(struct v4l2_subdev *sd,
1025*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1026*4882a593Smuzhiyun struct v4l2_subdev_format *fmt)
1027*4882a593Smuzhiyun {
1028*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1029*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1030*4882a593Smuzhiyun
1031*4882a593Smuzhiyun dev_dbg(&client->dev, "ov2659_get_fmt\n");
1032*4882a593Smuzhiyun
1033*4882a593Smuzhiyun if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1034*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1035*4882a593Smuzhiyun struct v4l2_mbus_framefmt *mf;
1036*4882a593Smuzhiyun
1037*4882a593Smuzhiyun mf = v4l2_subdev_get_try_format(sd, cfg, 0);
1038*4882a593Smuzhiyun mutex_lock(&ov2659->lock);
1039*4882a593Smuzhiyun fmt->format = *mf;
1040*4882a593Smuzhiyun mutex_unlock(&ov2659->lock);
1041*4882a593Smuzhiyun return 0;
1042*4882a593Smuzhiyun #else
1043*4882a593Smuzhiyun return -EINVAL;
1044*4882a593Smuzhiyun #endif
1045*4882a593Smuzhiyun }
1046*4882a593Smuzhiyun
1047*4882a593Smuzhiyun mutex_lock(&ov2659->lock);
1048*4882a593Smuzhiyun fmt->format = ov2659->format;
1049*4882a593Smuzhiyun mutex_unlock(&ov2659->lock);
1050*4882a593Smuzhiyun
1051*4882a593Smuzhiyun dev_dbg(&client->dev, "ov2659_get_fmt: %x %dx%d\n",
1052*4882a593Smuzhiyun ov2659->format.code, ov2659->format.width,
1053*4882a593Smuzhiyun ov2659->format.height);
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun return 0;
1056*4882a593Smuzhiyun }
1057*4882a593Smuzhiyun
__ov2659_try_frame_size(struct v4l2_mbus_framefmt * mf,const struct ov2659_framesize ** size)1058*4882a593Smuzhiyun static void __ov2659_try_frame_size(struct v4l2_mbus_framefmt *mf,
1059*4882a593Smuzhiyun const struct ov2659_framesize **size)
1060*4882a593Smuzhiyun {
1061*4882a593Smuzhiyun const struct ov2659_framesize *fsize = &ov2659_framesizes[0];
1062*4882a593Smuzhiyun const struct ov2659_framesize *match = NULL;
1063*4882a593Smuzhiyun int i = ARRAY_SIZE(ov2659_framesizes);
1064*4882a593Smuzhiyun unsigned int min_err = UINT_MAX;
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun while (i--) {
1067*4882a593Smuzhiyun int err = abs(fsize->width - mf->width)
1068*4882a593Smuzhiyun + abs(fsize->height - mf->height);
1069*4882a593Smuzhiyun if ((err < min_err) && (fsize->regs[0].addr)) {
1070*4882a593Smuzhiyun min_err = err;
1071*4882a593Smuzhiyun match = fsize;
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun fsize++;
1074*4882a593Smuzhiyun }
1075*4882a593Smuzhiyun
1076*4882a593Smuzhiyun if (!match)
1077*4882a593Smuzhiyun match = &ov2659_framesizes[2];
1078*4882a593Smuzhiyun
1079*4882a593Smuzhiyun mf->width = match->width;
1080*4882a593Smuzhiyun mf->height = match->height;
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun if (size)
1083*4882a593Smuzhiyun *size = match;
1084*4882a593Smuzhiyun }
1085*4882a593Smuzhiyun
ov2659_set_fmt(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_format * fmt)1086*4882a593Smuzhiyun static int ov2659_set_fmt(struct v4l2_subdev *sd,
1087*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1088*4882a593Smuzhiyun struct v4l2_subdev_format *fmt)
1089*4882a593Smuzhiyun {
1090*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1091*4882a593Smuzhiyun int index = ARRAY_SIZE(ov2659_formats);
1092*4882a593Smuzhiyun struct v4l2_mbus_framefmt *mf = &fmt->format;
1093*4882a593Smuzhiyun const struct ov2659_framesize *size = NULL;
1094*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1095*4882a593Smuzhiyun int ret = 0;
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun dev_dbg(&client->dev, "ov2659_set_fmt\n");
1098*4882a593Smuzhiyun
1099*4882a593Smuzhiyun __ov2659_try_frame_size(mf, &size);
1100*4882a593Smuzhiyun
1101*4882a593Smuzhiyun while (--index >= 0)
1102*4882a593Smuzhiyun if (ov2659_formats[index].code == mf->code)
1103*4882a593Smuzhiyun break;
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun if (index < 0) {
1106*4882a593Smuzhiyun index = 0;
1107*4882a593Smuzhiyun mf->code = ov2659_formats[index].code;
1108*4882a593Smuzhiyun }
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun mf->colorspace = V4L2_COLORSPACE_SRGB;
1111*4882a593Smuzhiyun mf->field = V4L2_FIELD_NONE;
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun mutex_lock(&ov2659->lock);
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1116*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1117*4882a593Smuzhiyun mf = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
1118*4882a593Smuzhiyun *mf = fmt->format;
1119*4882a593Smuzhiyun #endif
1120*4882a593Smuzhiyun } else {
1121*4882a593Smuzhiyun s64 val;
1122*4882a593Smuzhiyun
1123*4882a593Smuzhiyun if (ov2659->streaming) {
1124*4882a593Smuzhiyun mutex_unlock(&ov2659->lock);
1125*4882a593Smuzhiyun return -EBUSY;
1126*4882a593Smuzhiyun }
1127*4882a593Smuzhiyun
1128*4882a593Smuzhiyun ov2659->frame_size = size;
1129*4882a593Smuzhiyun ov2659->format = fmt->format;
1130*4882a593Smuzhiyun ov2659->format_ctrl_regs =
1131*4882a593Smuzhiyun ov2659_formats[index].format_ctrl_regs;
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun if (ov2659->format.code != MEDIA_BUS_FMT_SBGGR8_1X8)
1134*4882a593Smuzhiyun val = ov2659->pdata->link_frequency / 2;
1135*4882a593Smuzhiyun else
1136*4882a593Smuzhiyun val = ov2659->pdata->link_frequency;
1137*4882a593Smuzhiyun
1138*4882a593Smuzhiyun ret = v4l2_ctrl_s_ctrl_int64(ov2659->link_frequency, val);
1139*4882a593Smuzhiyun if (ret < 0)
1140*4882a593Smuzhiyun dev_warn(&client->dev,
1141*4882a593Smuzhiyun "failed to set link_frequency rate (%d)\n",
1142*4882a593Smuzhiyun ret);
1143*4882a593Smuzhiyun }
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun mutex_unlock(&ov2659->lock);
1146*4882a593Smuzhiyun return ret;
1147*4882a593Smuzhiyun }
1148*4882a593Smuzhiyun
ov2659_set_frame_size(struct ov2659 * ov2659)1149*4882a593Smuzhiyun static int ov2659_set_frame_size(struct ov2659 *ov2659)
1150*4882a593Smuzhiyun {
1151*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun dev_dbg(&client->dev, "%s\n", __func__);
1154*4882a593Smuzhiyun
1155*4882a593Smuzhiyun return ov2659_write_array(ov2659->client, ov2659->frame_size->regs);
1156*4882a593Smuzhiyun }
1157*4882a593Smuzhiyun
ov2659_set_format(struct ov2659 * ov2659)1158*4882a593Smuzhiyun static int ov2659_set_format(struct ov2659 *ov2659)
1159*4882a593Smuzhiyun {
1160*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
1161*4882a593Smuzhiyun
1162*4882a593Smuzhiyun dev_dbg(&client->dev, "%s\n", __func__);
1163*4882a593Smuzhiyun
1164*4882a593Smuzhiyun return ov2659_write_array(ov2659->client, ov2659->format_ctrl_regs);
1165*4882a593Smuzhiyun }
1166*4882a593Smuzhiyun
ov2659_s_stream(struct v4l2_subdev * sd,int on)1167*4882a593Smuzhiyun static int ov2659_s_stream(struct v4l2_subdev *sd, int on)
1168*4882a593Smuzhiyun {
1169*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1170*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1171*4882a593Smuzhiyun int ret = 0;
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun dev_dbg(&client->dev, "%s: on: %d\n", __func__, on);
1174*4882a593Smuzhiyun
1175*4882a593Smuzhiyun mutex_lock(&ov2659->lock);
1176*4882a593Smuzhiyun
1177*4882a593Smuzhiyun on = !!on;
1178*4882a593Smuzhiyun
1179*4882a593Smuzhiyun if (ov2659->streaming == on)
1180*4882a593Smuzhiyun goto unlock;
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun if (!on) {
1183*4882a593Smuzhiyun /* Stop Streaming Sequence */
1184*4882a593Smuzhiyun ov2659_set_streaming(ov2659, 0);
1185*4882a593Smuzhiyun ov2659->streaming = on;
1186*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1187*4882a593Smuzhiyun goto unlock;
1188*4882a593Smuzhiyun }
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun ret = pm_runtime_get_sync(&client->dev);
1191*4882a593Smuzhiyun if (ret < 0) {
1192*4882a593Smuzhiyun pm_runtime_put_noidle(&client->dev);
1193*4882a593Smuzhiyun goto unlock;
1194*4882a593Smuzhiyun }
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun ret = ov2659_init(sd, 0);
1197*4882a593Smuzhiyun if (!ret)
1198*4882a593Smuzhiyun ret = ov2659_set_pixel_clock(ov2659);
1199*4882a593Smuzhiyun if (!ret)
1200*4882a593Smuzhiyun ret = ov2659_set_frame_size(ov2659);
1201*4882a593Smuzhiyun if (!ret)
1202*4882a593Smuzhiyun ret = ov2659_set_format(ov2659);
1203*4882a593Smuzhiyun if (!ret) {
1204*4882a593Smuzhiyun ov2659_set_streaming(ov2659, 1);
1205*4882a593Smuzhiyun ov2659->streaming = on;
1206*4882a593Smuzhiyun }
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun unlock:
1209*4882a593Smuzhiyun mutex_unlock(&ov2659->lock);
1210*4882a593Smuzhiyun return ret;
1211*4882a593Smuzhiyun }
1212*4882a593Smuzhiyun
ov2659_set_test_pattern(struct ov2659 * ov2659,int value)1213*4882a593Smuzhiyun static int ov2659_set_test_pattern(struct ov2659 *ov2659, int value)
1214*4882a593Smuzhiyun {
1215*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(&ov2659->sd);
1216*4882a593Smuzhiyun int ret;
1217*4882a593Smuzhiyun u8 val;
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun ret = ov2659_read(client, REG_PRE_ISP_CTRL00, &val);
1220*4882a593Smuzhiyun if (ret < 0)
1221*4882a593Smuzhiyun return ret;
1222*4882a593Smuzhiyun
1223*4882a593Smuzhiyun switch (value) {
1224*4882a593Smuzhiyun case 0:
1225*4882a593Smuzhiyun val &= ~TEST_PATTERN_ENABLE;
1226*4882a593Smuzhiyun break;
1227*4882a593Smuzhiyun case 1:
1228*4882a593Smuzhiyun val &= VERTICAL_COLOR_BAR_MASK;
1229*4882a593Smuzhiyun val |= TEST_PATTERN_ENABLE;
1230*4882a593Smuzhiyun break;
1231*4882a593Smuzhiyun }
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun return ov2659_write(client, REG_PRE_ISP_CTRL00, val);
1234*4882a593Smuzhiyun }
1235*4882a593Smuzhiyun
ov2659_s_ctrl(struct v4l2_ctrl * ctrl)1236*4882a593Smuzhiyun static int ov2659_s_ctrl(struct v4l2_ctrl *ctrl)
1237*4882a593Smuzhiyun {
1238*4882a593Smuzhiyun struct ov2659 *ov2659 =
1239*4882a593Smuzhiyun container_of(ctrl->handler, struct ov2659, ctrls);
1240*4882a593Smuzhiyun struct i2c_client *client = ov2659->client;
1241*4882a593Smuzhiyun
1242*4882a593Smuzhiyun /* V4L2 controls values will be applied only when power is already up */
1243*4882a593Smuzhiyun if (!pm_runtime_get_if_in_use(&client->dev))
1244*4882a593Smuzhiyun return 0;
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun switch (ctrl->id) {
1247*4882a593Smuzhiyun case V4L2_CID_TEST_PATTERN:
1248*4882a593Smuzhiyun return ov2659_set_test_pattern(ov2659, ctrl->val);
1249*4882a593Smuzhiyun }
1250*4882a593Smuzhiyun
1251*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1252*4882a593Smuzhiyun return 0;
1253*4882a593Smuzhiyun }
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun static const struct v4l2_ctrl_ops ov2659_ctrl_ops = {
1256*4882a593Smuzhiyun .s_ctrl = ov2659_s_ctrl,
1257*4882a593Smuzhiyun };
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun static const char * const ov2659_test_pattern_menu[] = {
1260*4882a593Smuzhiyun "Disabled",
1261*4882a593Smuzhiyun "Vertical Color Bars",
1262*4882a593Smuzhiyun };
1263*4882a593Smuzhiyun
ov2659_power_off(struct device * dev)1264*4882a593Smuzhiyun static int ov2659_power_off(struct device *dev)
1265*4882a593Smuzhiyun {
1266*4882a593Smuzhiyun struct i2c_client *client = to_i2c_client(dev);
1267*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
1268*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
1271*4882a593Smuzhiyun
1272*4882a593Smuzhiyun gpiod_set_value(ov2659->pwdn_gpio, 1);
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun clk_disable_unprepare(ov2659->clk);
1275*4882a593Smuzhiyun
1276*4882a593Smuzhiyun return 0;
1277*4882a593Smuzhiyun }
1278*4882a593Smuzhiyun
ov2659_power_on(struct device * dev)1279*4882a593Smuzhiyun static int ov2659_power_on(struct device *dev)
1280*4882a593Smuzhiyun {
1281*4882a593Smuzhiyun struct i2c_client *client = to_i2c_client(dev);
1282*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
1283*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1284*4882a593Smuzhiyun int ret;
1285*4882a593Smuzhiyun
1286*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
1287*4882a593Smuzhiyun
1288*4882a593Smuzhiyun ret = clk_prepare_enable(ov2659->clk);
1289*4882a593Smuzhiyun if (ret) {
1290*4882a593Smuzhiyun dev_err(&client->dev, "%s: failed to enable clock\n",
1291*4882a593Smuzhiyun __func__);
1292*4882a593Smuzhiyun return ret;
1293*4882a593Smuzhiyun }
1294*4882a593Smuzhiyun
1295*4882a593Smuzhiyun gpiod_set_value(ov2659->pwdn_gpio, 0);
1296*4882a593Smuzhiyun
1297*4882a593Smuzhiyun if (ov2659->resetb_gpio) {
1298*4882a593Smuzhiyun gpiod_set_value(ov2659->resetb_gpio, 1);
1299*4882a593Smuzhiyun usleep_range(500, 1000);
1300*4882a593Smuzhiyun gpiod_set_value(ov2659->resetb_gpio, 0);
1301*4882a593Smuzhiyun usleep_range(3000, 5000);
1302*4882a593Smuzhiyun }
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun return 0;
1305*4882a593Smuzhiyun }
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun /* -----------------------------------------------------------------------------
1308*4882a593Smuzhiyun * V4L2 subdev internal operations
1309*4882a593Smuzhiyun */
1310*4882a593Smuzhiyun
1311*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
ov2659_open(struct v4l2_subdev * sd,struct v4l2_subdev_fh * fh)1312*4882a593Smuzhiyun static int ov2659_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1313*4882a593Smuzhiyun {
1314*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1315*4882a593Smuzhiyun struct v4l2_mbus_framefmt *format =
1316*4882a593Smuzhiyun v4l2_subdev_get_try_format(sd, fh->pad, 0);
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
1319*4882a593Smuzhiyun
1320*4882a593Smuzhiyun ov2659_get_default_format(format);
1321*4882a593Smuzhiyun
1322*4882a593Smuzhiyun return 0;
1323*4882a593Smuzhiyun }
1324*4882a593Smuzhiyun #endif
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun static const struct v4l2_subdev_core_ops ov2659_subdev_core_ops = {
1327*4882a593Smuzhiyun .log_status = v4l2_ctrl_subdev_log_status,
1328*4882a593Smuzhiyun .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1329*4882a593Smuzhiyun .unsubscribe_event = v4l2_event_subdev_unsubscribe,
1330*4882a593Smuzhiyun };
1331*4882a593Smuzhiyun
1332*4882a593Smuzhiyun static const struct v4l2_subdev_video_ops ov2659_subdev_video_ops = {
1333*4882a593Smuzhiyun .s_stream = ov2659_s_stream,
1334*4882a593Smuzhiyun };
1335*4882a593Smuzhiyun
1336*4882a593Smuzhiyun static const struct v4l2_subdev_pad_ops ov2659_subdev_pad_ops = {
1337*4882a593Smuzhiyun .enum_mbus_code = ov2659_enum_mbus_code,
1338*4882a593Smuzhiyun .enum_frame_size = ov2659_enum_frame_sizes,
1339*4882a593Smuzhiyun .get_fmt = ov2659_get_fmt,
1340*4882a593Smuzhiyun .set_fmt = ov2659_set_fmt,
1341*4882a593Smuzhiyun };
1342*4882a593Smuzhiyun
1343*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1344*4882a593Smuzhiyun static const struct v4l2_subdev_ops ov2659_subdev_ops = {
1345*4882a593Smuzhiyun .core = &ov2659_subdev_core_ops,
1346*4882a593Smuzhiyun .video = &ov2659_subdev_video_ops,
1347*4882a593Smuzhiyun .pad = &ov2659_subdev_pad_ops,
1348*4882a593Smuzhiyun };
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun static const struct v4l2_subdev_internal_ops ov2659_subdev_internal_ops = {
1351*4882a593Smuzhiyun .open = ov2659_open,
1352*4882a593Smuzhiyun };
1353*4882a593Smuzhiyun #endif
1354*4882a593Smuzhiyun
ov2659_detect(struct v4l2_subdev * sd)1355*4882a593Smuzhiyun static int ov2659_detect(struct v4l2_subdev *sd)
1356*4882a593Smuzhiyun {
1357*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
1358*4882a593Smuzhiyun u8 pid = 0;
1359*4882a593Smuzhiyun u8 ver = 0;
1360*4882a593Smuzhiyun int ret;
1361*4882a593Smuzhiyun
1362*4882a593Smuzhiyun dev_dbg(&client->dev, "%s:\n", __func__);
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun ret = ov2659_write(client, REG_SOFTWARE_RESET, 0x01);
1365*4882a593Smuzhiyun if (ret != 0) {
1366*4882a593Smuzhiyun dev_err(&client->dev, "Sensor soft reset failed\n");
1367*4882a593Smuzhiyun return -ENODEV;
1368*4882a593Smuzhiyun }
1369*4882a593Smuzhiyun usleep_range(1000, 2000);
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun /* Check sensor revision */
1372*4882a593Smuzhiyun ret = ov2659_read(client, REG_SC_CHIP_ID_H, &pid);
1373*4882a593Smuzhiyun if (!ret)
1374*4882a593Smuzhiyun ret = ov2659_read(client, REG_SC_CHIP_ID_L, &ver);
1375*4882a593Smuzhiyun
1376*4882a593Smuzhiyun if (!ret) {
1377*4882a593Smuzhiyun unsigned short id;
1378*4882a593Smuzhiyun
1379*4882a593Smuzhiyun id = OV265X_ID(pid, ver);
1380*4882a593Smuzhiyun if (id != OV2659_ID) {
1381*4882a593Smuzhiyun dev_err(&client->dev,
1382*4882a593Smuzhiyun "Sensor detection failed (%04X, %d)\n",
1383*4882a593Smuzhiyun id, ret);
1384*4882a593Smuzhiyun ret = -ENODEV;
1385*4882a593Smuzhiyun } else {
1386*4882a593Smuzhiyun dev_info(&client->dev, "Found OV%04X sensor\n", id);
1387*4882a593Smuzhiyun }
1388*4882a593Smuzhiyun }
1389*4882a593Smuzhiyun
1390*4882a593Smuzhiyun return ret;
1391*4882a593Smuzhiyun }
1392*4882a593Smuzhiyun
1393*4882a593Smuzhiyun static struct ov2659_platform_data *
ov2659_get_pdata(struct i2c_client * client)1394*4882a593Smuzhiyun ov2659_get_pdata(struct i2c_client *client)
1395*4882a593Smuzhiyun {
1396*4882a593Smuzhiyun struct ov2659_platform_data *pdata;
1397*4882a593Smuzhiyun struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
1398*4882a593Smuzhiyun struct device_node *endpoint;
1399*4882a593Smuzhiyun int ret;
1400*4882a593Smuzhiyun
1401*4882a593Smuzhiyun if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
1402*4882a593Smuzhiyun return client->dev.platform_data;
1403*4882a593Smuzhiyun
1404*4882a593Smuzhiyun endpoint = of_graph_get_next_endpoint(client->dev.of_node, NULL);
1405*4882a593Smuzhiyun if (!endpoint)
1406*4882a593Smuzhiyun return NULL;
1407*4882a593Smuzhiyun
1408*4882a593Smuzhiyun ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(endpoint),
1409*4882a593Smuzhiyun &bus_cfg);
1410*4882a593Smuzhiyun if (ret) {
1411*4882a593Smuzhiyun pdata = NULL;
1412*4882a593Smuzhiyun goto done;
1413*4882a593Smuzhiyun }
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1416*4882a593Smuzhiyun if (!pdata)
1417*4882a593Smuzhiyun goto done;
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun if (!bus_cfg.nr_of_link_frequencies) {
1420*4882a593Smuzhiyun dev_err(&client->dev,
1421*4882a593Smuzhiyun "link-frequencies property not found or too many\n");
1422*4882a593Smuzhiyun pdata = NULL;
1423*4882a593Smuzhiyun goto done;
1424*4882a593Smuzhiyun }
1425*4882a593Smuzhiyun
1426*4882a593Smuzhiyun pdata->link_frequency = bus_cfg.link_frequencies[0];
1427*4882a593Smuzhiyun
1428*4882a593Smuzhiyun done:
1429*4882a593Smuzhiyun v4l2_fwnode_endpoint_free(&bus_cfg);
1430*4882a593Smuzhiyun of_node_put(endpoint);
1431*4882a593Smuzhiyun return pdata;
1432*4882a593Smuzhiyun }
1433*4882a593Smuzhiyun
ov2659_probe(struct i2c_client * client)1434*4882a593Smuzhiyun static int ov2659_probe(struct i2c_client *client)
1435*4882a593Smuzhiyun {
1436*4882a593Smuzhiyun const struct ov2659_platform_data *pdata = ov2659_get_pdata(client);
1437*4882a593Smuzhiyun struct v4l2_subdev *sd;
1438*4882a593Smuzhiyun struct ov2659 *ov2659;
1439*4882a593Smuzhiyun int ret;
1440*4882a593Smuzhiyun
1441*4882a593Smuzhiyun if (!pdata) {
1442*4882a593Smuzhiyun dev_err(&client->dev, "platform data not specified\n");
1443*4882a593Smuzhiyun return -EINVAL;
1444*4882a593Smuzhiyun }
1445*4882a593Smuzhiyun
1446*4882a593Smuzhiyun ov2659 = devm_kzalloc(&client->dev, sizeof(*ov2659), GFP_KERNEL);
1447*4882a593Smuzhiyun if (!ov2659)
1448*4882a593Smuzhiyun return -ENOMEM;
1449*4882a593Smuzhiyun
1450*4882a593Smuzhiyun ov2659->pdata = pdata;
1451*4882a593Smuzhiyun ov2659->client = client;
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun ov2659->clk = devm_clk_get(&client->dev, "xvclk");
1454*4882a593Smuzhiyun if (IS_ERR(ov2659->clk))
1455*4882a593Smuzhiyun return PTR_ERR(ov2659->clk);
1456*4882a593Smuzhiyun
1457*4882a593Smuzhiyun ov2659->xvclk_frequency = clk_get_rate(ov2659->clk);
1458*4882a593Smuzhiyun if (ov2659->xvclk_frequency < 6000000 ||
1459*4882a593Smuzhiyun ov2659->xvclk_frequency > 27000000)
1460*4882a593Smuzhiyun return -EINVAL;
1461*4882a593Smuzhiyun
1462*4882a593Smuzhiyun /* Optional gpio don't fail if not present */
1463*4882a593Smuzhiyun ov2659->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
1464*4882a593Smuzhiyun GPIOD_OUT_LOW);
1465*4882a593Smuzhiyun if (IS_ERR(ov2659->pwdn_gpio))
1466*4882a593Smuzhiyun return PTR_ERR(ov2659->pwdn_gpio);
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun /* Optional gpio don't fail if not present */
1469*4882a593Smuzhiyun ov2659->resetb_gpio = devm_gpiod_get_optional(&client->dev, "reset",
1470*4882a593Smuzhiyun GPIOD_OUT_HIGH);
1471*4882a593Smuzhiyun if (IS_ERR(ov2659->resetb_gpio))
1472*4882a593Smuzhiyun return PTR_ERR(ov2659->resetb_gpio);
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun v4l2_ctrl_handler_init(&ov2659->ctrls, 2);
1475*4882a593Smuzhiyun ov2659->link_frequency =
1476*4882a593Smuzhiyun v4l2_ctrl_new_std(&ov2659->ctrls, &ov2659_ctrl_ops,
1477*4882a593Smuzhiyun V4L2_CID_PIXEL_RATE,
1478*4882a593Smuzhiyun pdata->link_frequency / 2,
1479*4882a593Smuzhiyun pdata->link_frequency, 1,
1480*4882a593Smuzhiyun pdata->link_frequency);
1481*4882a593Smuzhiyun v4l2_ctrl_new_std_menu_items(&ov2659->ctrls, &ov2659_ctrl_ops,
1482*4882a593Smuzhiyun V4L2_CID_TEST_PATTERN,
1483*4882a593Smuzhiyun ARRAY_SIZE(ov2659_test_pattern_menu) - 1,
1484*4882a593Smuzhiyun 0, 0, ov2659_test_pattern_menu);
1485*4882a593Smuzhiyun ov2659->sd.ctrl_handler = &ov2659->ctrls;
1486*4882a593Smuzhiyun
1487*4882a593Smuzhiyun if (ov2659->ctrls.error) {
1488*4882a593Smuzhiyun dev_err(&client->dev, "%s: control initialization error %d\n",
1489*4882a593Smuzhiyun __func__, ov2659->ctrls.error);
1490*4882a593Smuzhiyun return ov2659->ctrls.error;
1491*4882a593Smuzhiyun }
1492*4882a593Smuzhiyun
1493*4882a593Smuzhiyun sd = &ov2659->sd;
1494*4882a593Smuzhiyun client->flags |= I2C_CLIENT_SCCB;
1495*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1496*4882a593Smuzhiyun v4l2_i2c_subdev_init(sd, client, &ov2659_subdev_ops);
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun sd->internal_ops = &ov2659_subdev_internal_ops;
1499*4882a593Smuzhiyun sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
1500*4882a593Smuzhiyun V4L2_SUBDEV_FL_HAS_EVENTS;
1501*4882a593Smuzhiyun #endif
1502*4882a593Smuzhiyun
1503*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER)
1504*4882a593Smuzhiyun ov2659->pad.flags = MEDIA_PAD_FL_SOURCE;
1505*4882a593Smuzhiyun sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
1506*4882a593Smuzhiyun ret = media_entity_pads_init(&sd->entity, 1, &ov2659->pad);
1507*4882a593Smuzhiyun if (ret < 0) {
1508*4882a593Smuzhiyun v4l2_ctrl_handler_free(&ov2659->ctrls);
1509*4882a593Smuzhiyun return ret;
1510*4882a593Smuzhiyun }
1511*4882a593Smuzhiyun #endif
1512*4882a593Smuzhiyun
1513*4882a593Smuzhiyun mutex_init(&ov2659->lock);
1514*4882a593Smuzhiyun
1515*4882a593Smuzhiyun ov2659_get_default_format(&ov2659->format);
1516*4882a593Smuzhiyun ov2659->frame_size = &ov2659_framesizes[2];
1517*4882a593Smuzhiyun ov2659->format_ctrl_regs = ov2659_formats[0].format_ctrl_regs;
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun ret = ov2659_power_on(&client->dev);
1520*4882a593Smuzhiyun if (ret < 0)
1521*4882a593Smuzhiyun goto error;
1522*4882a593Smuzhiyun
1523*4882a593Smuzhiyun ret = ov2659_detect(sd);
1524*4882a593Smuzhiyun if (ret < 0)
1525*4882a593Smuzhiyun goto error;
1526*4882a593Smuzhiyun
1527*4882a593Smuzhiyun /* Calculate the PLL register value needed */
1528*4882a593Smuzhiyun ov2659_pll_calc_params(ov2659);
1529*4882a593Smuzhiyun
1530*4882a593Smuzhiyun ret = v4l2_async_register_subdev(&ov2659->sd);
1531*4882a593Smuzhiyun if (ret)
1532*4882a593Smuzhiyun goto error;
1533*4882a593Smuzhiyun
1534*4882a593Smuzhiyun dev_info(&client->dev, "%s sensor driver registered !!\n", sd->name);
1535*4882a593Smuzhiyun
1536*4882a593Smuzhiyun pm_runtime_set_active(&client->dev);
1537*4882a593Smuzhiyun pm_runtime_enable(&client->dev);
1538*4882a593Smuzhiyun pm_runtime_idle(&client->dev);
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun return 0;
1541*4882a593Smuzhiyun
1542*4882a593Smuzhiyun error:
1543*4882a593Smuzhiyun v4l2_ctrl_handler_free(&ov2659->ctrls);
1544*4882a593Smuzhiyun ov2659_power_off(&client->dev);
1545*4882a593Smuzhiyun media_entity_cleanup(&sd->entity);
1546*4882a593Smuzhiyun mutex_destroy(&ov2659->lock);
1547*4882a593Smuzhiyun return ret;
1548*4882a593Smuzhiyun }
1549*4882a593Smuzhiyun
ov2659_remove(struct i2c_client * client)1550*4882a593Smuzhiyun static int ov2659_remove(struct i2c_client *client)
1551*4882a593Smuzhiyun {
1552*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
1553*4882a593Smuzhiyun struct ov2659 *ov2659 = to_ov2659(sd);
1554*4882a593Smuzhiyun
1555*4882a593Smuzhiyun v4l2_ctrl_handler_free(&ov2659->ctrls);
1556*4882a593Smuzhiyun v4l2_async_unregister_subdev(sd);
1557*4882a593Smuzhiyun media_entity_cleanup(&sd->entity);
1558*4882a593Smuzhiyun mutex_destroy(&ov2659->lock);
1559*4882a593Smuzhiyun
1560*4882a593Smuzhiyun pm_runtime_disable(&client->dev);
1561*4882a593Smuzhiyun if (!pm_runtime_status_suspended(&client->dev))
1562*4882a593Smuzhiyun ov2659_power_off(&client->dev);
1563*4882a593Smuzhiyun pm_runtime_set_suspended(&client->dev);
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun return 0;
1566*4882a593Smuzhiyun }
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun static const struct dev_pm_ops ov2659_pm_ops = {
1569*4882a593Smuzhiyun SET_RUNTIME_PM_OPS(ov2659_power_off, ov2659_power_on, NULL)
1570*4882a593Smuzhiyun };
1571*4882a593Smuzhiyun
1572*4882a593Smuzhiyun static const struct i2c_device_id ov2659_id[] = {
1573*4882a593Smuzhiyun { "ov2659", 0 },
1574*4882a593Smuzhiyun { /* sentinel */ },
1575*4882a593Smuzhiyun };
1576*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, ov2659_id);
1577*4882a593Smuzhiyun
1578*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_OF)
1579*4882a593Smuzhiyun static const struct of_device_id ov2659_of_match[] = {
1580*4882a593Smuzhiyun { .compatible = "ovti,ov2659", },
1581*4882a593Smuzhiyun { /* sentinel */ },
1582*4882a593Smuzhiyun };
1583*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, ov2659_of_match);
1584*4882a593Smuzhiyun #endif
1585*4882a593Smuzhiyun
1586*4882a593Smuzhiyun static struct i2c_driver ov2659_i2c_driver = {
1587*4882a593Smuzhiyun .driver = {
1588*4882a593Smuzhiyun .name = DRIVER_NAME,
1589*4882a593Smuzhiyun .pm = &ov2659_pm_ops,
1590*4882a593Smuzhiyun .of_match_table = of_match_ptr(ov2659_of_match),
1591*4882a593Smuzhiyun },
1592*4882a593Smuzhiyun .probe_new = ov2659_probe,
1593*4882a593Smuzhiyun .remove = ov2659_remove,
1594*4882a593Smuzhiyun .id_table = ov2659_id,
1595*4882a593Smuzhiyun };
1596*4882a593Smuzhiyun
1597*4882a593Smuzhiyun module_i2c_driver(ov2659_i2c_driver);
1598*4882a593Smuzhiyun
1599*4882a593Smuzhiyun MODULE_AUTHOR("Benoit Parrot <bparrot@ti.com>");
1600*4882a593Smuzhiyun MODULE_DESCRIPTION("OV2659 CMOS Image Sensor driver");
1601*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
1602