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