1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for GalaxyCore GC2235 2M camera sensor.
4  *
5  * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
6  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.
18  *
19  */
20 
21 #ifndef __GC2235_H__
22 #define __GC2235_H__
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/i2c.h>
26 #include <linux/delay.h>
27 #include <linux/videodev2.h>
28 #include <linux/spinlock.h>
29 #include <media/v4l2-subdev.h>
30 #include <media/v4l2-device.h>
31 #include <media/v4l2-ctrls.h>
32 #include <linux/v4l2-mediabus.h>
33 #include <media/media-entity.h>
34 
35 #include "../include/linux/atomisp_platform.h"
36 
37 /*
38  * FIXME: non-preview resolutions are currently broken
39  */
40 #define ENABLE_NON_PREVIEW     0
41 
42 /* Defines for register writes and register array processing */
43 #define I2C_MSG_LENGTH		0x2
44 #define I2C_RETRY_COUNT		5
45 
46 #define GC2235_FOCAL_LENGTH_NUM	278	/*2.78mm*/
47 
48 #define MAX_FMTS		1
49 
50 /*
51  * focal length bits definition:
52  * bits 31-16: numerator, bits 15-0: denominator
53  */
54 #define GC2235_FOCAL_LENGTH_DEFAULT 0x1160064
55 
56 /*
57  * current f-number bits definition:
58  * bits 31-16: numerator, bits 15-0: denominator
59  */
60 #define GC2235_F_NUMBER_DEFAULT 0x1a000a
61 
62 /*
63  * f-number range bits definition:
64  * bits 31-24: max f-number numerator
65  * bits 23-16: max f-number denominator
66  * bits 15-8: min f-number numerator
67  * bits 7-0: min f-number denominator
68  */
69 #define GC2235_F_NUMBER_RANGE 0x1a0a1a0a
70 #define GC2235_ID	0x2235
71 
72 #define GC2235_FINE_INTG_TIME_MIN 0
73 #define GC2235_FINE_INTG_TIME_MAX_MARGIN 0
74 #define GC2235_COARSE_INTG_TIME_MIN 1
75 #define GC2235_COARSE_INTG_TIME_MAX_MARGIN 6
76 
77 /*
78  * GC2235 System control registers
79  */
80 /*
81  * GC2235 System control registers
82  */
83 #define GC2235_SENSOR_ID_H		0xF0
84 #define GC2235_SENSOR_ID_L		0xF1
85 #define GC2235_RESET_RELATED		0xFE
86 #define GC2235_SW_RESET			0x8
87 #define GC2235_MIPI_RESET		0x3
88 #define GC2235_RESET_BIT		0x4
89 #define GC2235_REGISTER_PAGE_0		0x0
90 #define GC2235_REGISTER_PAGE_3		0x3
91 
92 #define GC2235_V_CROP_START_H		0x91
93 #define GC2235_V_CROP_START_L		0x92
94 #define GC2235_H_CROP_START_H		0x93
95 #define GC2235_H_CROP_START_L		0x94
96 #define GC2235_V_OUTSIZE_H		0x95
97 #define GC2235_V_OUTSIZE_L		0x96
98 #define GC2235_H_OUTSIZE_H		0x97
99 #define GC2235_H_OUTSIZE_L		0x98
100 
101 #define GC2235_HB_H			0x5
102 #define GC2235_HB_L			0x6
103 #define GC2235_VB_H			0x7
104 #define GC2235_VB_L			0x8
105 #define GC2235_SH_DELAY_H		0x11
106 #define GC2235_SH_DELAY_L		0x12
107 
108 #define GC2235_CSI2_MODE		0x10
109 
110 #define GC2235_EXPOSURE_H		0x3
111 #define GC2235_EXPOSURE_L		0x4
112 #define GC2235_GLOBAL_GAIN		0xB0
113 #define GC2235_PRE_GAIN			0xB1
114 #define GC2235_AWB_R_GAIN		0xB3
115 #define GC2235_AWB_G_GAIN		0xB4
116 #define GC2235_AWB_B_GAIN		0xB5
117 
118 #define GC2235_START_STREAMING		0x91
119 #define GC2235_STOP_STREAMING		0x0
120 
121 struct regval_list {
122 	u16 reg_num;
123 	u8 value;
124 };
125 
126 struct gc2235_resolution {
127 	u8 *desc;
128 	const struct gc2235_reg *regs;
129 	int res;
130 	int width;
131 	int height;
132 	int fps;
133 	int pix_clk_freq;
134 	u32 skip_frames;
135 	u16 pixels_per_line;
136 	u16 lines_per_frame;
137 	bool used;
138 };
139 
140 struct gc2235_format {
141 	u8 *desc;
142 	u32 pixelformat;
143 	struct gc2235_reg *regs;
144 };
145 
146 /*
147  * gc2235 device structure.
148  */
149 struct gc2235_device {
150 	struct v4l2_subdev sd;
151 	struct media_pad pad;
152 	struct v4l2_mbus_framefmt format;
153 	struct mutex input_lock;
154 	struct v4l2_ctrl_handler ctrl_handler;
155 	struct gc2235_resolution *res;
156 
157 	struct camera_sensor_platform_data *platform_data;
158 	u8 type;
159 };
160 
161 enum gc2235_tok_type {
162 	GC2235_8BIT  = 0x0001,
163 	GC2235_16BIT = 0x0002,
164 	GC2235_32BIT = 0x0004,
165 	GC2235_TOK_TERM   = 0xf000,	/* terminating token for reg list */
166 	GC2235_TOK_DELAY  = 0xfe00,	/* delay token for reg list */
167 	GC2235_TOK_MASK = 0xfff0
168 };
169 
170 /**
171  * struct gc2235_reg - MI sensor  register format
172  * @type: type of the register
173  * @reg: 8-bit offset to register
174  * @val: 8/16/32-bit register value
175  *
176  * Define a structure for sensor register initialization values
177  */
178 struct gc2235_reg {
179 	enum gc2235_tok_type type;
180 	u8 reg;
181 	u32 val;	/* @set value for read/mod/write, @mask */
182 };
183 
184 #define to_gc2235_sensor(x) container_of(x, struct gc2235_device, sd)
185 
186 #define GC2235_MAX_WRITE_BUF_SIZE	30
187 
188 struct gc2235_write_buffer {
189 	u8 addr;
190 	u8 data[GC2235_MAX_WRITE_BUF_SIZE];
191 };
192 
193 struct gc2235_write_ctrl {
194 	int index;
195 	struct gc2235_write_buffer buffer;
196 };
197 
198 static struct gc2235_reg const gc2235_stream_on[] = {
199 	{ GC2235_8BIT, 0xfe, 0x03}, /* switch to P3 */
200 	{ GC2235_8BIT, 0x10, 0x91}, /* start mipi */
201 	{ GC2235_8BIT, 0xfe, 0x00}, /* switch to P0 */
202 	{ GC2235_TOK_TERM, 0, 0 }
203 };
204 
205 static struct gc2235_reg const gc2235_stream_off[] = {
206 	{ GC2235_8BIT, 0xfe, 0x03}, /* switch to P3 */
207 	{ GC2235_8BIT, 0x10, 0x01}, /* stop mipi */
208 	{ GC2235_8BIT, 0xfe, 0x00}, /* switch to P0 */
209 	{ GC2235_TOK_TERM, 0, 0 }
210 };
211 
212 static struct gc2235_reg const gc2235_init_settings[] = {
213 	/* System */
214 	{ GC2235_8BIT, 0xfe, 0x80 },
215 	{ GC2235_8BIT, 0xfe, 0x80 },
216 	{ GC2235_8BIT, 0xfe, 0x80 },
217 	{ GC2235_8BIT, 0xf2, 0x00 },
218 	{ GC2235_8BIT, 0xf6, 0x00 },
219 	{ GC2235_8BIT, 0xfc, 0x06 },
220 	{ GC2235_8BIT, 0xf7, 0x15 },
221 	{ GC2235_8BIT, 0xf8, 0x84 },
222 	{ GC2235_8BIT, 0xf9, 0xfe },
223 	{ GC2235_8BIT, 0xfa, 0x00 },
224 	{ GC2235_8BIT, 0xfe, 0x00 },
225 	/* Analog & cisctl */
226 	{ GC2235_8BIT, 0x03, 0x04 },
227 	{ GC2235_8BIT, 0x04, 0x9E },
228 	{ GC2235_8BIT, 0x05, 0x00 },
229 	{ GC2235_8BIT, 0x06, 0xfd },
230 	{ GC2235_8BIT, 0x07, 0x00 },
231 	{ GC2235_8BIT, 0x08, 0x14 },
232 	{ GC2235_8BIT, 0x0a, 0x02 }, /* row start */
233 	{ GC2235_8BIT, 0x0c, 0x00 }, /* col start */
234 	{ GC2235_8BIT, 0x0d, 0x04 }, /* win height 1232 */
235 	{ GC2235_8BIT, 0x0e, 0xd0 },
236 	{ GC2235_8BIT, 0x0f, 0x06 }, /* win width: 1616 */
237 	{ GC2235_8BIT, 0x10, 0x60 },
238 	{ GC2235_8BIT, 0x17, 0x15 }, /* mirror flip */
239 	{ GC2235_8BIT, 0x18, 0x1a },
240 	{ GC2235_8BIT, 0x19, 0x06 },
241 	{ GC2235_8BIT, 0x1a, 0x01 },
242 	{ GC2235_8BIT, 0x1b, 0x4d },
243 	{ GC2235_8BIT, 0x1e, 0x88 },
244 	{ GC2235_8BIT, 0x1f, 0x48 },
245 	{ GC2235_8BIT, 0x20, 0x03 },
246 	{ GC2235_8BIT, 0x21, 0x7f },
247 	{ GC2235_8BIT, 0x22, 0x83 },
248 	{ GC2235_8BIT, 0x23, 0x42 },
249 	{ GC2235_8BIT, 0x24, 0x16 },
250 	{ GC2235_8BIT, 0x26, 0x01 }, /*analog gain*/
251 	{ GC2235_8BIT, 0x27, 0x30 },
252 	{ GC2235_8BIT, 0x3f, 0x00 }, /* PRC */
253 	/* blk */
254 	{ GC2235_8BIT, 0x40, 0xa3 },
255 	{ GC2235_8BIT, 0x41, 0x82 },
256 	{ GC2235_8BIT, 0x43, 0x20 },
257 	{ GC2235_8BIT, 0x5e, 0x18 },
258 	{ GC2235_8BIT, 0x5f, 0x18 },
259 	{ GC2235_8BIT, 0x60, 0x18 },
260 	{ GC2235_8BIT, 0x61, 0x18 },
261 	{ GC2235_8BIT, 0x62, 0x18 },
262 	{ GC2235_8BIT, 0x63, 0x18 },
263 	{ GC2235_8BIT, 0x64, 0x18 },
264 	{ GC2235_8BIT, 0x65, 0x18 },
265 	{ GC2235_8BIT, 0x66, 0x20 },
266 	{ GC2235_8BIT, 0x67, 0x20 },
267 	{ GC2235_8BIT, 0x68, 0x20 },
268 	{ GC2235_8BIT, 0x69, 0x20 },
269 	/* Gain */
270 	{ GC2235_8BIT, 0xb2, 0x00 },
271 	{ GC2235_8BIT, 0xb3, 0x40 },
272 	{ GC2235_8BIT, 0xb4, 0x40 },
273 	{ GC2235_8BIT, 0xb5, 0x40 },
274 	/* Dark sun */
275 	{ GC2235_8BIT, 0xbc, 0x00 },
276 
277 	{ GC2235_8BIT, 0xfe, 0x03 },
278 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
279 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
280 	{ GC2235_TOK_TERM, 0, 0 }
281 };
282 
283 /*
284  * Register settings for various resolution
285  */
286 #if ENABLE_NON_PREVIEW
287 static struct gc2235_reg const gc2235_1296_736_30fps[] = {
288 	{ GC2235_8BIT, 0x8b, 0xa0 },
289 	{ GC2235_8BIT, 0x8c, 0x02 },
290 
291 	{ GC2235_8BIT, 0x07, 0x01 }, /* VBI */
292 	{ GC2235_8BIT, 0x08, 0x44 },
293 	{ GC2235_8BIT, 0x09, 0x00 }, /* row start */
294 	{ GC2235_8BIT, 0x0a, 0xf0 },
295 	{ GC2235_8BIT, 0x0b, 0x00 }, /* col start */
296 	{ GC2235_8BIT, 0x0c, 0xa0 },
297 	{ GC2235_8BIT, 0x0d, 0x02 }, /* win height 736 */
298 	{ GC2235_8BIT, 0x0e, 0xf0 },
299 	{ GC2235_8BIT, 0x0f, 0x05 }, /* win width: 1296 */
300 	{ GC2235_8BIT, 0x10, 0x20 },
301 
302 	{ GC2235_8BIT, 0x90, 0x01 },
303 	{ GC2235_8BIT, 0x92, 0x08 },
304 	{ GC2235_8BIT, 0x94, 0x08 },
305 	{ GC2235_8BIT, 0x95, 0x02 }, /* crop win height 736 */
306 	{ GC2235_8BIT, 0x96, 0xe0 },
307 	{ GC2235_8BIT, 0x97, 0x05 }, /* crop win width 1296 */
308 	{ GC2235_8BIT, 0x98, 0x10 },
309 	/* mimi init */
310 	{ GC2235_8BIT, 0xfe, 0x03 }, /* switch to P3 */
311 	{ GC2235_8BIT, 0x01, 0x07 },
312 	{ GC2235_8BIT, 0x02, 0x11 },
313 	{ GC2235_8BIT, 0x03, 0x11 },
314 	{ GC2235_8BIT, 0x06, 0x80 },
315 	{ GC2235_8BIT, 0x11, 0x2b },
316 	/* set mipi buffer */
317 	{ GC2235_8BIT, 0x12, 0x54 }, /* val_low = (width * 10 / 8) & 0xFF */
318 	{ GC2235_8BIT, 0x13, 0x06 }, /* val_high = (width * 10 / 8) >> 8 */
319 
320 	{ GC2235_8BIT, 0x15, 0x12 }, /* DPHY mode*/
321 	{ GC2235_8BIT, 0x04, 0x10 },
322 	{ GC2235_8BIT, 0x05, 0x00 },
323 	{ GC2235_8BIT, 0x17, 0x01 },
324 
325 	{ GC2235_8BIT, 0x22, 0x01 },
326 	{ GC2235_8BIT, 0x23, 0x05 },
327 	{ GC2235_8BIT, 0x24, 0x10 },
328 	{ GC2235_8BIT, 0x25, 0x10 },
329 	{ GC2235_8BIT, 0x26, 0x02 },
330 	{ GC2235_8BIT, 0x21, 0x10 },
331 	{ GC2235_8BIT, 0x29, 0x01 },
332 	{ GC2235_8BIT, 0x2a, 0x02 },
333 	{ GC2235_8BIT, 0x2b, 0x02 },
334 
335 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
336 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
337 	{ GC2235_TOK_TERM, 0, 0 }
338 };
339 
340 static struct gc2235_reg const gc2235_960_640_30fps[] = {
341 	{ GC2235_8BIT, 0x8b, 0xa0 },
342 	{ GC2235_8BIT, 0x8c, 0x02 },
343 
344 	{ GC2235_8BIT, 0x07, 0x02 }, /* VBI */
345 	{ GC2235_8BIT, 0x08, 0xA4 },
346 	{ GC2235_8BIT, 0x09, 0x01 }, /* row start */
347 	{ GC2235_8BIT, 0x0a, 0x18 },
348 	{ GC2235_8BIT, 0x0b, 0x01 }, /* col start */
349 	{ GC2235_8BIT, 0x0c, 0x40 },
350 	{ GC2235_8BIT, 0x0d, 0x02 }, /* win height 656 */
351 	{ GC2235_8BIT, 0x0e, 0x90 },
352 	{ GC2235_8BIT, 0x0f, 0x03 }, /* win width: 976 */
353 	{ GC2235_8BIT, 0x10, 0xd0 },
354 
355 	{ GC2235_8BIT, 0x90, 0x01 },
356 	{ GC2235_8BIT, 0x92, 0x02 },
357 	{ GC2235_8BIT, 0x94, 0x06 },
358 	{ GC2235_8BIT, 0x95, 0x02 }, /* crop win height 640 */
359 	{ GC2235_8BIT, 0x96, 0x80 },
360 	{ GC2235_8BIT, 0x97, 0x03 }, /* crop win width 960 */
361 	{ GC2235_8BIT, 0x98, 0xc0 },
362 	/* mimp init */
363 	{ GC2235_8BIT, 0xfe, 0x03 }, /* switch to P3 */
364 	{ GC2235_8BIT, 0x01, 0x07 },
365 	{ GC2235_8BIT, 0x02, 0x11 },
366 	{ GC2235_8BIT, 0x03, 0x11 },
367 	{ GC2235_8BIT, 0x06, 0x80 },
368 	{ GC2235_8BIT, 0x11, 0x2b },
369 	/* set mipi buffer */
370 	{ GC2235_8BIT, 0x12, 0xb0 }, /* val_low = (width * 10 / 8) & 0xFF */
371 	{ GC2235_8BIT, 0x13, 0x04 }, /* val_high = (width * 10 / 8) >> 8 */
372 
373 	{ GC2235_8BIT, 0x15, 0x12 }, /* DPHY mode*/
374 	{ GC2235_8BIT, 0x04, 0x10 },
375 	{ GC2235_8BIT, 0x05, 0x00 },
376 	{ GC2235_8BIT, 0x17, 0x01 },
377 	{ GC2235_8BIT, 0x22, 0x01 },
378 	{ GC2235_8BIT, 0x23, 0x05 },
379 	{ GC2235_8BIT, 0x24, 0x10 },
380 	{ GC2235_8BIT, 0x25, 0x10 },
381 	{ GC2235_8BIT, 0x26, 0x02 },
382 	{ GC2235_8BIT, 0x21, 0x10 },
383 	{ GC2235_8BIT, 0x29, 0x01 },
384 	{ GC2235_8BIT, 0x2a, 0x02 },
385 	{ GC2235_8BIT, 0x2b, 0x02 },
386 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
387 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
388 	{ GC2235_TOK_TERM, 0, 0 }
389 };
390 #endif
391 
392 static struct gc2235_reg const gc2235_1600_900_30fps[] = {
393 	{ GC2235_8BIT, 0x8b, 0xa0 },
394 	{ GC2235_8BIT, 0x8c, 0x02 },
395 
396 	{ GC2235_8BIT, 0x0d, 0x03 }, /* win height 932 */
397 	{ GC2235_8BIT, 0x0e, 0xa4 },
398 	{ GC2235_8BIT, 0x0f, 0x06 }, /* win width: 1632 */
399 	{ GC2235_8BIT, 0x10, 0x50 },
400 
401 	{ GC2235_8BIT, 0x90, 0x01 },
402 	{ GC2235_8BIT, 0x92, 0x02 },
403 	{ GC2235_8BIT, 0x94, 0x06 },
404 	{ GC2235_8BIT, 0x95, 0x03 }, /* crop win height 900 */
405 	{ GC2235_8BIT, 0x96, 0x84 },
406 	{ GC2235_8BIT, 0x97, 0x06 }, /* crop win width 1600 */
407 	{ GC2235_8BIT, 0x98, 0x40 },
408 	/* mimi init */
409 	{ GC2235_8BIT, 0xfe, 0x03 }, /* switch to P3 */
410 	{ GC2235_8BIT, 0x01, 0x07 },
411 	{ GC2235_8BIT, 0x02, 0x11 },
412 	{ GC2235_8BIT, 0x03, 0x11 },
413 	{ GC2235_8BIT, 0x06, 0x80 },
414 	{ GC2235_8BIT, 0x11, 0x2b },
415 	/* set mipi buffer */
416 	{ GC2235_8BIT, 0x12, 0xd0 }, /* val_low = (width * 10 / 8) & 0xFF */
417 	{ GC2235_8BIT, 0x13, 0x07 }, /* val_high = (width * 10 / 8) >> 8 */
418 
419 	{ GC2235_8BIT, 0x15, 0x12 }, /* DPHY mode*/
420 	{ GC2235_8BIT, 0x04, 0x10 },
421 	{ GC2235_8BIT, 0x05, 0x00 },
422 	{ GC2235_8BIT, 0x17, 0x01 },
423 	{ GC2235_8BIT, 0x22, 0x01 },
424 	{ GC2235_8BIT, 0x23, 0x05 },
425 	{ GC2235_8BIT, 0x24, 0x10 },
426 	{ GC2235_8BIT, 0x25, 0x10 },
427 	{ GC2235_8BIT, 0x26, 0x02 },
428 	{ GC2235_8BIT, 0x21, 0x10 },
429 	{ GC2235_8BIT, 0x29, 0x01 },
430 	{ GC2235_8BIT, 0x2a, 0x02 },
431 	{ GC2235_8BIT, 0x2b, 0x02 },
432 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
433 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
434 	{ GC2235_TOK_TERM, 0, 0 }
435 };
436 
437 static struct gc2235_reg const gc2235_1616_1082_30fps[] = {
438 	{ GC2235_8BIT, 0x8b, 0xa0 },
439 	{ GC2235_8BIT, 0x8c, 0x02 },
440 
441 	{ GC2235_8BIT, 0x0d, 0x04 }, /* win height 1232 */
442 	{ GC2235_8BIT, 0x0e, 0xd0 },
443 	{ GC2235_8BIT, 0x0f, 0x06 }, /* win width: 1616 */
444 	{ GC2235_8BIT, 0x10, 0x50 },
445 
446 	{ GC2235_8BIT, 0x90, 0x01 },
447 	{ GC2235_8BIT, 0x92, 0x4a },
448 	{ GC2235_8BIT, 0x94, 0x00 },
449 	{ GC2235_8BIT, 0x95, 0x04 }, /* crop win height 1082 */
450 	{ GC2235_8BIT, 0x96, 0x3a },
451 	{ GC2235_8BIT, 0x97, 0x06 }, /* crop win width 1616 */
452 	{ GC2235_8BIT, 0x98, 0x50 },
453 	/* mimp init */
454 	{ GC2235_8BIT, 0xfe, 0x03 }, /* switch to P3 */
455 	{ GC2235_8BIT, 0x01, 0x07 },
456 	{ GC2235_8BIT, 0x02, 0x11 },
457 	{ GC2235_8BIT, 0x03, 0x11 },
458 	{ GC2235_8BIT, 0x06, 0x80 },
459 	{ GC2235_8BIT, 0x11, 0x2b },
460 	/* set mipi buffer */
461 	{ GC2235_8BIT, 0x12, 0xe4 }, /* val_low = (width * 10 / 8) & 0xFF */
462 	{ GC2235_8BIT, 0x13, 0x07 }, /* val_high = (width * 10 / 8) >> 8 */
463 
464 	{ GC2235_8BIT, 0x15, 0x12 }, /* DPHY mode*/
465 	{ GC2235_8BIT, 0x04, 0x10 },
466 	{ GC2235_8BIT, 0x05, 0x00 },
467 	{ GC2235_8BIT, 0x17, 0x01 },
468 	{ GC2235_8BIT, 0x22, 0x01 },
469 	{ GC2235_8BIT, 0x23, 0x05 },
470 	{ GC2235_8BIT, 0x24, 0x10 },
471 	{ GC2235_8BIT, 0x25, 0x10 },
472 	{ GC2235_8BIT, 0x26, 0x02 },
473 	{ GC2235_8BIT, 0x21, 0x10 },
474 	{ GC2235_8BIT, 0x29, 0x01 },
475 	{ GC2235_8BIT, 0x2a, 0x02 },
476 	{ GC2235_8BIT, 0x2b, 0x02 },
477 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
478 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
479 	{ GC2235_TOK_TERM, 0, 0 }
480 };
481 
482 static struct gc2235_reg const gc2235_1616_1216_30fps[] = {
483 	{ GC2235_8BIT, 0x8b, 0xa0 },
484 	{ GC2235_8BIT, 0x8c, 0x02 },
485 
486 	{ GC2235_8BIT, 0x0d, 0x04 }, /* win height 1232 */
487 	{ GC2235_8BIT, 0x0e, 0xd0 },
488 	{ GC2235_8BIT, 0x0f, 0x06 }, /* win width: 1616 */
489 	{ GC2235_8BIT, 0x10, 0x50 },
490 
491 	{ GC2235_8BIT, 0x90, 0x01 },
492 	{ GC2235_8BIT, 0x92, 0x02 },
493 	{ GC2235_8BIT, 0x94, 0x00 },
494 	{ GC2235_8BIT, 0x95, 0x04 }, /* crop win height 1216 */
495 	{ GC2235_8BIT, 0x96, 0xc0 },
496 	{ GC2235_8BIT, 0x97, 0x06 }, /* crop win width 1616 */
497 	{ GC2235_8BIT, 0x98, 0x50 },
498 	/* mimi init */
499 	{ GC2235_8BIT, 0xfe, 0x03 }, /* switch to P3 */
500 	{ GC2235_8BIT, 0x01, 0x07 },
501 	{ GC2235_8BIT, 0x02, 0x11 },
502 	{ GC2235_8BIT, 0x03, 0x11 },
503 	{ GC2235_8BIT, 0x06, 0x80 },
504 	{ GC2235_8BIT, 0x11, 0x2b },
505 	/* set mipi buffer */
506 	{ GC2235_8BIT, 0x12, 0xe4 }, /* val_low = (width * 10 / 8) & 0xFF */
507 	{ GC2235_8BIT, 0x13, 0x07 }, /* val_high = (width * 10 / 8) >> 8 */
508 	{ GC2235_8BIT, 0x15, 0x12 }, /* DPHY mode*/
509 	{ GC2235_8BIT, 0x04, 0x10 },
510 	{ GC2235_8BIT, 0x05, 0x00 },
511 	{ GC2235_8BIT, 0x17, 0x01 },
512 	{ GC2235_8BIT, 0x22, 0x01 },
513 	{ GC2235_8BIT, 0x23, 0x05 },
514 	{ GC2235_8BIT, 0x24, 0x10 },
515 	{ GC2235_8BIT, 0x25, 0x10 },
516 	{ GC2235_8BIT, 0x26, 0x02 },
517 	{ GC2235_8BIT, 0x21, 0x10 },
518 	{ GC2235_8BIT, 0x29, 0x01 },
519 	{ GC2235_8BIT, 0x2a, 0x02 },
520 	{ GC2235_8BIT, 0x2b, 0x02 },
521 	{ GC2235_8BIT, 0x10, 0x01 }, /* disable mipi */
522 	{ GC2235_8BIT, 0xfe, 0x00 }, /* switch to P0 */
523 	{ GC2235_TOK_TERM, 0, 0 }
524 };
525 
526 static struct gc2235_resolution gc2235_res_preview[] = {
527 	{
528 		.desc = "gc2235_1600_900_30fps",
529 		.width = 1600,
530 		.height = 900,
531 		.pix_clk_freq = 30,
532 		.fps = 30,
533 		.used = 0,
534 		.pixels_per_line = 2132,
535 		.lines_per_frame = 1068,
536 		.skip_frames = 3,
537 		.regs = gc2235_1600_900_30fps,
538 	},
539 
540 	{
541 		.desc = "gc2235_1600_1066_30fps",
542 		.width = 1616,
543 		.height = 1082,
544 		.pix_clk_freq = 30,
545 		.fps = 30,
546 		.used = 0,
547 		.pixels_per_line = 2132,
548 		.lines_per_frame = 1368,
549 		.skip_frames = 3,
550 		.regs = gc2235_1616_1082_30fps,
551 	},
552 	{
553 		.desc = "gc2235_1600_1200_30fps",
554 		.width = 1616,
555 		.height = 1216,
556 		.pix_clk_freq = 30,
557 		.fps = 30,
558 		.used = 0,
559 		.pixels_per_line = 2132,
560 		.lines_per_frame = 1368,
561 		.skip_frames = 3,
562 		.regs = gc2235_1616_1216_30fps,
563 	},
564 
565 };
566 
567 #define N_RES_PREVIEW (ARRAY_SIZE(gc2235_res_preview))
568 
569 /*
570  * Disable non-preview configurations until the configuration selection is
571  * improved.
572  */
573 #if ENABLE_NON_PREVIEW
574 static struct gc2235_resolution gc2235_res_still[] = {
575 	{
576 		.desc = "gc2235_1600_900_30fps",
577 		.width = 1600,
578 		.height = 900,
579 		.pix_clk_freq = 30,
580 		.fps = 30,
581 		.used = 0,
582 		.pixels_per_line = 2132,
583 		.lines_per_frame = 1068,
584 		.skip_frames = 3,
585 		.regs = gc2235_1600_900_30fps,
586 	},
587 	{
588 		.desc = "gc2235_1600_1066_30fps",
589 		.width = 1616,
590 		.height = 1082,
591 		.pix_clk_freq = 30,
592 		.fps = 30,
593 		.used = 0,
594 		.pixels_per_line = 2132,
595 		.lines_per_frame = 1368,
596 		.skip_frames = 3,
597 		.regs = gc2235_1616_1082_30fps,
598 	},
599 	{
600 		.desc = "gc2235_1600_1200_30fps",
601 		.width = 1616,
602 		.height = 1216,
603 		.pix_clk_freq = 30,
604 		.fps = 30,
605 		.used = 0,
606 		.pixels_per_line = 2132,
607 		.lines_per_frame = 1368,
608 		.skip_frames = 3,
609 		.regs = gc2235_1616_1216_30fps,
610 	},
611 
612 };
613 
614 #define N_RES_STILL (ARRAY_SIZE(gc2235_res_still))
615 
616 static struct gc2235_resolution gc2235_res_video[] = {
617 	{
618 		.desc = "gc2235_1296_736_30fps",
619 		.width = 1296,
620 		.height = 736,
621 		.pix_clk_freq = 30,
622 		.fps = 30,
623 		.used = 0,
624 		.pixels_per_line = 1828,
625 		.lines_per_frame = 888,
626 		.skip_frames = 3,
627 		.regs = gc2235_1296_736_30fps,
628 	},
629 	{
630 		.desc = "gc2235_960_640_30fps",
631 		.width = 960,
632 		.height = 640,
633 		.pix_clk_freq = 30,
634 		.fps = 30,
635 		.used = 0,
636 		.pixels_per_line = 1492,
637 		.lines_per_frame = 792,
638 		.skip_frames = 3,
639 		.regs = gc2235_960_640_30fps,
640 	},
641 
642 };
643 
644 #define N_RES_VIDEO (ARRAY_SIZE(gc2235_res_video))
645 #endif
646 
647 static struct gc2235_resolution *gc2235_res = gc2235_res_preview;
648 static unsigned long N_RES = N_RES_PREVIEW;
649 #endif
650