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