• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * A V4L2 driver for gc2145 YUV cameras.
4  *
5  * Copyright (c) 2017 by Allwinnertech Co., Ltd.  http://www.allwinnertech.com
6  *
7  * Authors:  Zhao Wei <zhaowei@allwinnertech.com>
8  *    Yang Feng <yangfeng@allwinnertech.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14 
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/i2c.h>
19 #include <linux/delay.h>
20 #include <linux/videodev2.h>
21 #include <linux/clk.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-mediabus.h>
24 #include <linux/io.h>
25 #include "camera.h"
26 #include "sensor_helper.h"
27 
28 MODULE_AUTHOR("raymonxiu");
29 MODULE_DESCRIPTION("A low-level driver for GalaxyCore gc2145 sensors");
30 MODULE_LICENSE("GPL");
31 
32 #define MCLK              (24*1000*1000)
33 #define VREF_POL          V4L2_MBUS_VSYNC_ACTIVE_HIGH
34 #define HREF_POL          V4L2_MBUS_HSYNC_ACTIVE_HIGH
35 #define CLK_POL           V4L2_MBUS_PCLK_SAMPLE_RISING
36 #define V4L2_IDENT_SENSOR 0x2145
37 
38 /*
39  * Our nominal (default) frame rate.
40  */
41 #define SENSOR_FRAME_RATE 8
42 
43 /*
44  * The gc2145 sits on i2c with ID 0x78
45  */
46 #define I2C_ADDR   0x78
47 #define SENSOR_NAME "gc2145"
48 
49 struct cfg_array {		/* coming later */
50 	struct regval_list *regs;
51 	int size;
52 };
53 
54 
55 /*
56  * The default register settings
57  *
58  */
59 
60 static struct regval_list sensor_default_regs[] = {
61 	{0xfe, 0xf0},
62 	{0xfe, 0xf0},
63 	{0xfe, 0xf0},
64 	{0xfc, 0x06},
65 	{0xf6, 0x00},
66 	{0xf7, 0x1d},
67 	{0xf8, 0x84},
68 	{0xfa, 0x00},
69 	{0xf9, 0xfe},
70 	{0xf2, 0x00},
71 	{0xfe, 0x00},
72 	{0x03, 0x04},
73 	{0x04, 0x00},
74 	{0x09, 0x00},
75 	{0x0a, 0x00},
76 	{0x0b, 0x00},
77 	{0x0c, 0x00},
78 	{0x0d, 0x04},
79 	{0x0e, 0xc0},
80 	{0x0f, 0x06},
81 	{0x10, 0x52},
82 	{0x12, 0x2e},
83 	{0x17, 0x14},
84 	{0x18, 0x22},
85 	{0x19, 0x0f},
86 	{0x1a, 0x01},
87 	{0x1b, 0x4b},
88 	{0x1c, 0x07},
89 	{0x1d, 0x10},
90 	{0x1e, 0x88},
91 	{0x1f, 0x78},
92 	{0x20, 0x03},
93 	{0x21, 0x40},
94 	{0x22, 0xf0},
95 	{0x24, 0x16},
96 	{0x25, 0x01},
97 	{0x26, 0x10},
98 	{0x2d, 0x60},
99 	{0x30, 0x01},
100 	{0x31, 0x90},
101 	{0x33, 0x06},
102 	{0x34, 0x01},
103 	{0x80, 0xff},
104 	{0x81, 0x24},
105 	{0x82, 0xfa},
106 	{0x83, 0x00},
107 	{0x84, 0x02},
108 	{0x86, 0x07},
109 	{0x88, 0x03},
110 	{0x89, 0x03},
111 	{0x85, 0x30},
112 	{0x8a, 0x00},
113 	{0x8b, 0x00},
114 	{0xb0, 0x55},
115 	{0xc3, 0x00},
116 	{0xc4, 0x80},
117 	{0xc5, 0x90},
118 	{0xc6, 0x38},
119 	{0xc7, 0x40},
120 	{0xec, 0x06},
121 	{0xed, 0x04},
122 	{0xee, 0x60},
123 	{0xef, 0x90},
124 	{0xb6, 0x01},
125 	{0x90, 0x01},
126 	{0x91, 0x00},
127 	{0x92, 0x00},
128 	{0x93, 0x00},
129 	{0x94, 0x00},
130 	{0x95, 0x04},
131 	{0x96, 0xb0},
132 	{0x97, 0x06},
133 	{0x98, 0x40},
134 	{0x18, 0x02},
135 	{0x40, 0x42},
136 	{0x41, 0x00},
137 	{0x43, 0x54},
138 	{0x5e, 0x00},
139 	{0x5f, 0x00},
140 	{0x60, 0x00},
141 	{0x61, 0x00},
142 	{0x62, 0x00},
143 	{0x63, 0x00},
144 	{0x64, 0x00},
145 	{0x65, 0x00},
146 	{0x66, 0x20},
147 	{0x67, 0x20},
148 	{0x68, 0x20},
149 	{0x69, 0x20},
150 	{0x76, 0x00},
151 	{0x6a, 0x02},
152 	{0x6b, 0x02},
153 	{0x6c, 0x02},
154 	{0x6d, 0x02},
155 	{0x6e, 0x02},
156 	{0x6f, 0x02},
157 	{0x70, 0x02},
158 	{0x71, 0x02},
159 	{0x76, 0x00},
160 	{0x72, 0xf0},
161 	{0x7e, 0x3c},
162 	{0x7f, 0x00},
163 	{0xfe, 0x02},
164 	{0x48, 0x15},
165 	{0x49, 0x00},
166 	{0x4b, 0x0b},
167 	{0xfe, 0x00},
168 	{0xfe, 0x01},
169 	{0x01, 0x04},
170 	{0x02, 0xc0},
171 	{0x03, 0x04},
172 	{0x04, 0x90},
173 	{0x05, 0x30},
174 	{0x06, 0x90},
175 	{0x07, 0x20},
176 	{0x08, 0x70},
177 	{0x09, 0x00},
178 	{0x0a, 0xc2},
179 	{0x0b, 0x11},
180 	{0x0c, 0x10},
181 	{0x13, 0x30},
182 	{0x17, 0x00},
183 	{0x1c, 0x11},
184 	{0x1e, 0x61},
185 	{0x1f, 0x30},
186 	{0x20, 0x40},
187 	{0x22, 0x80},
188 	{0x23, 0x20},
189 	{0xfe, 0x02},
190 	{0x0f, 0x04},
191 	{0xfe, 0x01},
192 	{0x12, 0x00},
193 	{0x15, 0x50},
194 	{0x10, 0x31},
195 	{0x3e, 0x28},
196 	{0x3f, 0xe0},
197 	{0x40, 0xe0},
198 	{0x41, 0x0f},
199 	{0xfe, 0x02},
200 	{0x90, 0x6c},
201 	{0x91, 0x03},
202 	{0x92, 0xc8},
203 	{0x94, 0x66},
204 	{0x95, 0xb5},
205 	{0x97, 0x64},
206 	{0xa2, 0x11},
207 	{0xfe, 0x00},
208 	{0xfe, 0x02},
209 	{0x80, 0xc1},
210 	{0x81, 0x08},
211 	{0x82, 0x08},
212 	{0x83, 0x05},
213 	{0x84, 0x0a},
214 	{0x86, 0x50},
215 	{0x87, 0x30},
216 	{0x88, 0x15},
217 	{0x89, 0x80},
218 	{0x8a, 0x60},
219 	{0x8b, 0x30},
220 	{0xfe, 0x01},
221 	{0x21, 0x14},
222 	{0xfe, 0x02},
223 	{0xa3, 0x40},
224 	{0xa4, 0x20},
225 	{0xa5, 0x40},
226 	{0xa6, 0x80},
227 	{0xab, 0x40},
228 	{0xae, 0x0c},
229 	{0xb3, 0x34},
230 	{0xb4, 0x44},
231 	{0xb6, 0x38},
232 	{0xb7, 0x02},
233 	{0xb9, 0x30},
234 	{0x3c, 0x08},
235 	{0x3d, 0x30},
236 	{0x4b, 0x0d},
237 	{0x4c, 0x20},
238 	{0xfe, 0x00},
239 	{0xfe, 0x02},
240 	{0x10, 0x10},
241 	{0x11, 0x15},
242 	{0x12, 0x1a},
243 	{0x13, 0x1f},
244 	{0x14, 0x2c},
245 	{0x15, 0x39},
246 	{0x16, 0x45},
247 	{0x17, 0x54},
248 	{0x18, 0x69},
249 	{0x19, 0x7d},
250 	{0x1a, 0x8f},
251 	{0x1b, 0x9d},
252 	{0x1c, 0xa9},
253 	{0x1d, 0xbd},
254 	{0x1e, 0xcd},
255 	{0x1f, 0xd9},
256 	{0x20, 0xe3},
257 	{0x21, 0xea},
258 	{0x22, 0xef},
259 	{0x23, 0xf5},
260 	{0x24, 0xf9},
261 	{0x25, 0xff},
262 	{0xfe, 0x02},
263 	{0x26, 0x0f},
264 	{0x27, 0x14},
265 	{0x28, 0x19},
266 	{0x29, 0x1e},
267 	{0x2a, 0x27},
268 	{0x2b, 0x33},
269 	{0x2c, 0x3b},
270 	{0x2d, 0x45},
271 	{0x2e, 0x59},
272 	{0x2f, 0x69},
273 	{0x30, 0x7c},
274 	{0x31, 0x89},
275 	{0x32, 0x98},
276 	{0x33, 0xae},
277 	{0x34, 0xc0},
278 	{0x35, 0xcf},
279 	{0x36, 0xda},
280 	{0x37, 0xe2},
281 	{0x38, 0xe9},
282 	{0x39, 0xf3},
283 	{0x3a, 0xf9},
284 	{0x3b, 0xff},
285 	{0xfe, 0x02},
286 	{0xd1, 0x30},
287 	{0xd2, 0x30},
288 	{0xd3, 0x45},
289 	{0xdd, 0x14},
290 	{0xde, 0x86},
291 	{0xed, 0x01},
292 	{0xee, 0x28},
293 	{0xef, 0x30},
294 	{0xd8, 0xd8},
295 	{0xfe, 0x01},
296 	{0xc2, 0x1a},
297 	{0xc3, 0x0b},
298 	{0xc4, 0x0e},
299 	{0xc8, 0x20},
300 	{0xc9, 0x0c},
301 	{0xca, 0x12},
302 	{0xbc, 0x41},
303 	{0xbd, 0x1f},
304 	{0xbe, 0x29},
305 	{0xb6, 0x48},
306 	{0xb7, 0x22},
307 	{0xb8, 0x28},
308 	{0xc5, 0x04},
309 	{0xc6, 0x00},
310 	{0xc7, 0x00},
311 	{0xcb, 0x12},
312 	{0xcc, 0x00},
313 	{0xcd, 0x08},
314 	{0xbf, 0x14},
315 	{0xc0, 0x00},
316 	{0xc1, 0x10},
317 	{0xb9, 0x0f},
318 	{0xba, 0x00},
319 	{0xbb, 0x00},
320 	{0xaa, 0x0a},
321 	{0xab, 0x00},
322 	{0xac, 0x00},
323 	{0xad, 0x09},
324 	{0xae, 0x00},
325 	{0xaf, 0x02},
326 	{0xb0, 0x04},
327 	{0xb1, 0x00},
328 	{0xb2, 0x00},
329 	{0xb3, 0x03},
330 	{0xb4, 0x00},
331 	{0xb5, 0x02},
332 	{0xd0, 0x42},
333 	{0xd1, 0x00},
334 	{0xd2, 0x00},
335 	{0xd6, 0x47},
336 	{0xd7, 0x07},
337 	{0xd8, 0x00},
338 	{0xd9, 0x34},
339 	{0xda, 0x13},
340 	{0xdb, 0x00},
341 	{0xd3, 0x2b},
342 	{0xd4, 0x18},
343 	{0xd5, 0x10},
344 	{0xa4, 0x00},
345 	{0xa5, 0x00},
346 	{0xa6, 0x77},
347 	{0xa7, 0x77},
348 	{0xa8, 0x77},
349 	{0xa9, 0x77},
350 	{0xa1, 0x80},
351 	{0xa2, 0x80},
352 
353 	{0xfe, 0x01},
354 	{0xdf, 0x00},
355 	{0xdc, 0x80},
356 	{0xdd, 0x30},
357 	{0xe0, 0x6b},
358 	{0xe1, 0x70},
359 	{0xe2, 0x6b},
360 	{0xe3, 0x70},
361 	{0xe6, 0xa0},
362 	{0xe7, 0x60},
363 	{0xe8, 0xa0},
364 	{0xe9, 0x60},
365 	{0xfe, 0x00},
366 	{0xfe, 0x01},
367 	{0x4f, 0x00},
368 	{0x4f, 0x00},
369 	{0x4b, 0x01},
370 	{0x4f, 0x00},
371 	{0x4c, 0x01},
372 	{0x4d, 0x71},
373 	{0x4e, 0x01},
374 	{0x4c, 0x01},
375 	{0x4d, 0x91},
376 	{0x4e, 0x01},
377 	{0x4c, 0x01},
378 	{0x4d, 0x70},
379 	{0x4e, 0x01},
380 	{0x4c, 0x01},
381 	{0x4d, 0x90},
382 	{0x4e, 0x02},
383 	{0x4c, 0x01},
384 	{0x4d, 0xb0},
385 	{0x4e, 0x02},
386 	{0x4c, 0x01},
387 	{0x4d, 0x8f},
388 	{0x4e, 0x02},
389 	{0x4c, 0x01},
390 	{0x4d, 0x6f},
391 	{0x4e, 0x02},
392 	{0x4c, 0x01},
393 	{0x4d, 0xaf},
394 	{0x4e, 0x02},
395 	{0x4c, 0x01},
396 	{0x4d, 0xd0},
397 	{0x4e, 0x02},
398 	{0x4c, 0x01},
399 	{0x4d, 0xf0},
400 	{0x4e, 0x02},
401 	{0x4c, 0x01},
402 	{0x4d, 0xcf},
403 	{0x4e, 0x02},
404 	{0x4c, 0x01},
405 	{0x4d, 0xef},
406 	{0x4e, 0x02},
407 	{0x4c, 0x01},
408 	{0x4d, 0x6e},
409 	{0x4e, 0x03},
410 	{0x4c, 0x01},
411 	{0x4d, 0x8e},
412 	{0x4e, 0x03},
413 	{0x4c, 0x01},
414 	{0x4d, 0xae},
415 	{0x4e, 0x03},
416 	{0x4c, 0x01},
417 	{0x4d, 0xce},
418 	{0x4e, 0x03},
419 	{0x4c, 0x01},
420 	{0x4d, 0xee},
421 	{0x4e, 0x03},
422 	{0x4c, 0x01},
423 	{0x4d, 0x6d},
424 	{0x4e, 0x03},
425 	{0x4c, 0x01},
426 	{0x4d, 0x8d},
427 	{0x4e, 0x03},
428 	{0x4c, 0x01},
429 	{0x4d, 0xad},
430 	{0x4e, 0x03},
431 	{0x4c, 0x01},
432 	{0x4d, 0xcd},
433 	{0x4e, 0x03},
434 	{0x4c, 0x01},
435 	{0x4d, 0xed},
436 	{0x4e, 0x03},
437 	{0x4c, 0x01},
438 	{0x4d, 0x6c},
439 	{0x4e, 0x03},
440 	{0x4c, 0x01},
441 	{0x4d, 0x8c},
442 	{0x4e, 0x03},
443 	{0x4c, 0x01},
444 	{0x4d, 0xac},
445 	{0x4e, 0x03},
446 	{0x4c, 0x01},
447 	{0x4d, 0xcc},
448 	{0x4e, 0x03},
449 	{0x4c, 0x01},
450 	{0x4d, 0xec},
451 	{0x4e, 0x03},
452 	{0x4c, 0x01},
453 	{0x4d, 0x6b},
454 	{0x4e, 0x03},
455 	{0x4c, 0x01},
456 	{0x4d, 0x8b},
457 	{0x4e, 0x03},
458 	{0x4c, 0x01},
459 	{0x4d, 0x8a},
460 	{0x4e, 0x03},
461 	{0x4c, 0x01},
462 	{0x4d, 0xaa},
463 	{0x4e, 0x04},
464 	{0x4c, 0x01},
465 	{0x4d, 0xab},
466 	{0x4e, 0x04},
467 	{0x4c, 0x01},
468 	{0x4d, 0xcb},
469 	{0x4e, 0x04},
470 	{0x4c, 0x01},
471 	{0x4d, 0xa9},
472 	{0x4e, 0x04},
473 	{0x4c, 0x01},
474 	{0x4d, 0xca},
475 	{0x4e, 0x04},
476 	{0x4c, 0x01},
477 	{0x4d, 0xc9},
478 	{0x4e, 0x04},
479 	{0x4c, 0x01},
480 	{0x4d, 0x8a},
481 	{0x4e, 0x04},
482 	{0x4c, 0x01},
483 	{0x4d, 0x89},
484 	{0x4e, 0x04},
485 	{0x4c, 0x01},
486 	{0x4d, 0xeb},
487 	{0x4e, 0x05},
488 	{0x4c, 0x02},
489 	{0x4d, 0x0b},
490 	{0x4e, 0x05},
491 	{0x4c, 0x02},
492 	{0x4d, 0x0c},
493 	{0x4e, 0x05},
494 	{0x4c, 0x02},
495 	{0x4d, 0x2c},
496 	{0x4e, 0x05},
497 	{0x4c, 0x02},
498 	{0x4d, 0x2b},
499 	{0x4e, 0x05},
500 	{0x4c, 0x01},
501 	{0x4d, 0xea},
502 	{0x4e, 0x05},
503 	{0x4c, 0x02},
504 	{0x4d, 0x0a},
505 	{0x4e, 0x05},
506 	{0x4c, 0x02},
507 	{0x4d, 0x8b},
508 	{0x4e, 0x06},
509 	{0x4c, 0x02},
510 	{0x4d, 0x2a},
511 	{0x4e, 0x06},
512 	{0x4c, 0x02},
513 	{0x4d, 0x4a},
514 	{0x4e, 0x06},
515 	{0x4c, 0x02},
516 	{0x4d, 0x6a},
517 	{0x4e, 0x06},
518 	{0x4c, 0x02},
519 	{0x4d, 0x8a},
520 	{0x4e, 0x06},
521 	{0x4c, 0x02},
522 	{0x4d, 0xaa},
523 	{0x4e, 0x06},
524 	{0x4c, 0x02},
525 	{0x4d, 0x09},
526 	{0x4e, 0x06},
527 	{0x4c, 0x02},
528 	{0x4d, 0x29},
529 	{0x4e, 0x06},
530 	{0x4c, 0x02},
531 	{0x4d, 0x49},
532 	{0x4e, 0x06},
533 	{0x4c, 0x02},
534 	{0x4d, 0x69},
535 	{0x4e, 0x06},
536 	{0x4c, 0x02},
537 	{0x4d, 0xcc},
538 	{0x4e, 0x07},
539 	{0x4c, 0x02},
540 	{0x4d, 0xca},
541 	{0x4e, 0x07},
542 	{0x4c, 0x02},
543 	{0x4d, 0xa9},
544 	{0x4e, 0x07},
545 	{0x4c, 0x02},
546 	{0x4d, 0xc9},
547 	{0x4e, 0x07},
548 	{0x4c, 0x02},
549 	{0x4d, 0xe9},
550 	{0x4e, 0x07},
551 
552 	{0x4f, 0x01},
553 	{0x50, 0x80},
554 	{0x51, 0xa8},
555 	{0x52, 0x47},
556 	{0x53, 0x38},
557 	{0x54, 0xc7},
558 	{0x56, 0x0e},
559 	{0x58, 0x08},
560 	{0x5b, 0x00},
561 	{0x5c, 0x74},
562 	{0x5d, 0x8b},
563 	{0x61, 0xdb},
564 	{0x62, 0xb8},
565 	{0x63, 0x86},
566 	{0x64, 0xc0},
567 	{0x65, 0x04},
568 	{0x67, 0xa8},
569 	{0x68, 0xb0},
570 	{0x69, 0x00},
571 	{0x6a, 0xa8},
572 	{0x6b, 0xb0},
573 	{0x6c, 0xaf},
574 	{0x6d, 0x8b},
575 	{0x6e, 0x50},
576 	{0x6f, 0x18},
577 	{0x73, 0xe0},
578 	{0x70, 0x0d},
579 	{0x71, 0x68},
580 	{0x72, 0x81},
581 	{0x74, 0x01},
582 	{0x75, 0x01},
583 	{0x7f, 0x0c},
584 	{0x76, 0x70},
585 	{0x77, 0x58},
586 	{0x78, 0xa0},
587 	{0x79, 0x5e},
588 	{0x7a, 0x54},
589 	{0x7b, 0x55},
590 	{0xfe, 0x00},
591 	{0xfe, 0x02},
592 	{0xc0, 0x01},
593 	{0xC1, 0x44},
594 	{0xc2, 0xF4},
595 	{0xc3, 0x02},
596 	{0xc4, 0xf2},
597 	{0xc5, 0x44},
598 	{0xc6, 0xf8},
599 	{0xC7, 0x50},
600 	{0xc8, 0xf2},
601 	{0xc9, 0x00},
602 	{0xcA, 0xE0},
603 	{0xcB, 0x45},
604 	{0xcC, 0xec},
605 	{0xCd, 0x45},
606 	{0xce, 0xf0},
607 	{0xcf, 0x00},
608 	{0xe3, 0xf0},
609 	{0xe4, 0x45},
610 	{0xe5, 0xe8},
611 	{0xfe, 0x00},
612 	{0x05, 0x01},
613 	{0x06, 0x56},
614 	{0x07, 0x00},
615 	{0x08, 0x32},
616 	{0xfe, 0x01},
617 	{0x25, 0x00},
618 	{0x26, 0xfa},
619 	{0x27, 0x04},
620 	{0x28, 0xe2},
621 	{0x29, 0x05},
622 	{0x2a, 0xdc},
623 	{0x2b, 0x06},
624 	{0x2c, 0xd6},
625 	{0x2d, 0x0b},
626 	{0x2e, 0xb8},
627 	{0xfe, 0x00},
628 	{0xfe, 0x00},
629 	{0xfa, 0x00},
630 	{0xfd, 0x01},
631 	{0xfe, 0x00},
632 	{0x99, 0x11},
633 	{0x9a, 0x06},
634 	{0x9b, 0x00},
635 	{0x9c, 0x00},
636 	{0x9d, 0x00},
637 	{0x9e, 0x00},
638 	{0x9f, 0x00},
639 	{0xa0, 0x00},
640 	{0xa1, 0x00},
641 	{0xa2, 0x00},
642 	{0x90, 0x01},
643 	{0x91, 0x00},
644 	{0x92, 0x00},
645 	{0x93, 0x00},
646 	{0x94, 0x00},
647 	{0x95, 0x02},
648 	{0x96, 0x58},
649 	{0x97, 0x03},
650 	{0x98, 0x20},
651 	{0xfe, 0x00},
652 	{0xec, 0x01},
653 	{0xed, 0x02},
654 	{0xee, 0x30},
655 	{0xef, 0x48},
656 	{0xfe, 0x01},
657 	{0x74, 0x00},
658 	{0xfe, 0x01},
659 	{0x01, 0x04},
660 	{0x02, 0x60},
661 	{0x03, 0x02},
662 	{0x04, 0x48},
663 	{0x05, 0x18},
664 	{0x06, 0x4c},
665 	{0x07, 0x14},
666 	{0x08, 0x36},
667 	{0x0a, 0xc0},
668 	{0x21, 0x14},
669 	{0xfe, 0x00},
670 	{0xfe, 0x00},
671 	{0xf2, 0x0f},
672 	{0x18, 0x22},
673 	{0xfe, 0x02},
674 	{0x40, 0xbf},
675 	{0x46, 0xcf},
676 	{0xfe, 0x00},
677 };
678 
679 /* 1600X1200 UXGA capture */
680 static struct regval_list sensor_uxga_regs[] = {
681 	{0xfe, 0x00},
682 	{0xb6, 0x00},
683 	{0xfa, 0x11},
684 	{0xfd, 0x00},
685 	{0xfe, 0x00},
686 	{0xb6, 0x00},
687 	{0x99, 0x11},
688 	{0x9a, 0x06},
689 	{0x9b, 0x00},
690 	{0x9c, 0x00},
691 	{0x9d, 0x00},
692 	{0x9e, 0x00},
693 	{0x9f, 0x00},
694 	{0xa0, 0x00},
695 	{0xa1, 0x00},
696 	{0xa2, 0x00},
697 	{0x90, 0x01},
698 	{0x91, 0x00},
699 	{0x92, 0x00},
700 	{0x93, 0x00},
701 	{0x94, 0x00},
702 	{0x95, 0x04},
703 	{0x96, 0xb0},
704 	{0x97, 0x06},
705 	{0x98, 0x40},
706 	{0xfe, 0x00},
707 	{0xec, 0x02},
708 	{0xed, 0x04},
709 	{0xee, 0x60},
710 	{0xef, 0x90},
711 	{0xfe, 0x01},
712 	{0x74, 0x01},
713 	{0xfe, 0x01},
714 	{0x01, 0x08},
715 	{0x02, 0xc0},
716 	{0x03, 0x04},
717 	{0x04, 0x90},
718 	{0x05, 0x30},
719 	{0x06, 0x98},
720 	{0x07, 0x28},
721 	{0x08, 0x6c},
722 	{0x0a, 0xc2},
723 	{0x21, 0x15},
724 	{0xfe, 0x00},
725 };
726 
727 /* 800X600 SVGA,30fps*/
728 static struct regval_list sensor_svga_regs[] = {
729 	{0xfe, 0x00},
730 	{0xfa, 0x00},
731 	{0xfd, 0x01},
732 	{0xb6, 0x01},
733 	{0xfe, 0x00},
734 	{0x99, 0x11},
735 	{0x9a, 0x06},
736 	{0x9b, 0x00},
737 	{0x9c, 0x00},
738 	{0x9d, 0x00},
739 	{0x9e, 0x00},
740 	{0x9f, 0x00},
741 	{0xa0, 0x00},
742 	{0xa1, 0x00},
743 	{0xa2, 0x00},
744 	{0x90, 0x01},
745 	{0x91, 0x00},
746 	{0x92, 0x00},
747 	{0x93, 0x00},
748 	{0x94, 0x00},
749 	{0x95, 0x02},
750 	{0x96, 0x58},
751 	{0x97, 0x03},
752 	{0x98, 0x20},
753 
754 	{0xfe, 0x00},
755 	{0xec, 0x01},
756 	{0xed, 0x02},
757 	{0xee, 0x30},
758 	{0xef, 0x48},
759 	{0xfe, 0x01},
760 	{0x74, 0x00},
761 
762 	{0xfe, 0x01},
763 	{0x01, 0x04},
764 	{0x02, 0x60},
765 	{0x03, 0x02},
766 	{0x04, 0x48},
767 	{0x05, 0x18},
768 	{0x06, 0x4c},
769 	{0x07, 0x14},
770 	{0x08, 0x36},
771 	{0x0a, 0xc0},
772 	{0x21, 0x14},
773 	{0xfe, 0x00},
774 
775 };
776 
777 /*
778  * The white balance settings
779  * Here only tune the R G B channel gain.
780  * The white balance enalbe bit is modified in sensor_s_autowb and sensor_s_wb
781  */
782 static struct regval_list sensor_wb_manual[] = {
783 };
784 
785 static struct regval_list sensor_wb_auto_regs[] = {
786 	{0xfe, 0x00},
787 	{0xb3, 0x61},
788 	{0xb4, 0x40},
789 	{0xb5, 0x61},
790 	{0x82, 0xfe},
791 };
792 
793 static struct regval_list sensor_wb_incandescence_regs[] = {
794 	{0xfe, 0x00},
795 	{0x82, 0xfc},
796 	{0xb3, 0x50},
797 	{0xb4, 0x40},
798 	{0xb5, 0xa8},
799 };
800 
801 static struct regval_list sensor_wb_fluorescent_regs[] = {
802 	{0xfe, 0x00},
803 	{0x82, 0xfc},
804 	{0xb3, 0x72},
805 	{0xb4, 0x40},
806 	{0xb5, 0x5b},
807 };
808 
809 static struct regval_list sensor_wb_tungsten_regs[] = {
810 	{0xfe, 0x00},
811 	{0x82, 0xfc},
812 	{0xb3, 0xa0},
813 	{0xb4, 0x45},
814 	{0xb5, 0x40},
815 };
816 
817 static struct regval_list sensor_wb_horizon[] = {
818 
819 };
820 static struct regval_list sensor_wb_daylight_regs[] = {
821 	{0xfe, 0x00},
822 	{0x82, 0xfc},
823 	{0xb3, 0x70},
824 	{0xb4, 0x40},
825 	{0xb5, 0x50},
826 };
827 
828 static struct regval_list sensor_wb_flash[] = {
829 
830 };
831 
832 static struct regval_list sensor_wb_cloud_regs[] = {
833 	{0xfe, 0x00},
834 	{0x82, 0xfc},
835 	{0xb3, 0x58},
836 	{0xb4, 0x40},
837 	{0xb5, 0x50},
838 };
839 
840 static struct regval_list sensor_wb_shade[] = {
841 };
842 
843 static struct cfg_array sensor_wb[] = {
844 	{
845 	 .regs = sensor_wb_manual,
846 	 .size = ARRAY_SIZE(sensor_wb_manual),
847 	 },
848 	{
849 	 .regs = sensor_wb_auto_regs,
850 	 .size = ARRAY_SIZE(sensor_wb_auto_regs),
851 	 },
852 	{
853 	 .regs = sensor_wb_incandescence_regs,
854 	 .size = ARRAY_SIZE(sensor_wb_incandescence_regs),
855 	 },
856 	{
857 	 .regs = sensor_wb_fluorescent_regs,
858 	 .size = ARRAY_SIZE(sensor_wb_fluorescent_regs),
859 	 },
860 	{
861 	 .regs = sensor_wb_tungsten_regs,
862 	 .size = ARRAY_SIZE(sensor_wb_tungsten_regs),
863 	 },
864 	{
865 	 .regs = sensor_wb_horizon,
866 	 .size = ARRAY_SIZE(sensor_wb_horizon),
867 	 },
868 	{
869 	 .regs = sensor_wb_daylight_regs,
870 	 .size = ARRAY_SIZE(sensor_wb_daylight_regs),
871 	 },
872 	{
873 	 .regs = sensor_wb_flash,
874 	 .size = ARRAY_SIZE(sensor_wb_flash),
875 	 },
876 	{
877 	 .regs = sensor_wb_cloud_regs,
878 	 .size = ARRAY_SIZE(sensor_wb_cloud_regs),
879 	 },
880 	{
881 	 .regs = sensor_wb_shade,
882 	 .size = ARRAY_SIZE(sensor_wb_shade),
883 	 },
884 };
885 
886 /*
887  * The color effect settings
888  */
889 static struct regval_list sensor_colorfx_none_regs[] = {
890 	{0xfe, 0x00},
891 	{0x83, 0xe0},
892 };
893 
894 static struct regval_list sensor_colorfx_bw_regs[] = {
895 
896 };
897 
898 static struct regval_list sensor_colorfx_sepia_regs[] = {
899 	{0xfe, 0x00},
900 	{0x83, 0x82},
901 };
902 
903 static struct regval_list sensor_colorfx_negative_regs[] = {
904 	{0xfe, 0x00},
905 	{0x83, 0x01},
906 };
907 
908 static struct regval_list sensor_colorfx_emboss_regs[] = {
909 	{0xfe, 0x00},
910 	{0x83, 0x12},
911 };
912 
913 static struct regval_list sensor_colorfx_sketch_regs[] = {
914 
915 };
916 
917 static struct regval_list sensor_colorfx_sky_blue_regs[] = {
918 	{0xfe, 0x00},
919 	{0x83, 0x62},
920 };
921 
922 static struct regval_list sensor_colorfx_grass_green_regs[] = {
923 	{0xfe, 0x00},
924 	{0x83, 0x52},
925 };
926 
927 static struct regval_list sensor_colorfx_skin_whiten_regs[] = {
928 };
929 
930 static struct regval_list sensor_colorfx_vivid_regs[] = {
931 };
932 
933 static struct regval_list sensor_colorfx_aqua_regs[] = {
934 };
935 
936 static struct regval_list sensor_colorfx_art_freeze_regs[] = {
937 };
938 
939 static struct regval_list sensor_colorfx_silhouette_regs[] = {
940 };
941 
942 static struct regval_list sensor_colorfx_solarization_regs[] = {
943 };
944 
945 static struct regval_list sensor_colorfx_antique_regs[] = {
946 };
947 
948 static struct regval_list sensor_colorfx_set_cbcr_regs[] = {
949 };
950 
951 static struct cfg_array sensor_colorfx[] = {
952 	{
953 	 .regs = sensor_colorfx_none_regs,
954 	 .size = ARRAY_SIZE(sensor_colorfx_none_regs),
955 	 },
956 	{
957 	 .regs = sensor_colorfx_bw_regs,
958 	 .size = ARRAY_SIZE(sensor_colorfx_bw_regs),
959 	 },
960 	{
961 	 .regs = sensor_colorfx_sepia_regs,
962 	 .size = ARRAY_SIZE(sensor_colorfx_sepia_regs),
963 	 },
964 	{
965 	 .regs = sensor_colorfx_negative_regs,
966 	 .size = ARRAY_SIZE(sensor_colorfx_negative_regs),
967 	 },
968 	{
969 	 .regs = sensor_colorfx_emboss_regs,
970 	 .size = ARRAY_SIZE(sensor_colorfx_emboss_regs),
971 	 },
972 	{
973 	 .regs = sensor_colorfx_sketch_regs,
974 	 .size = ARRAY_SIZE(sensor_colorfx_sketch_regs),
975 	 },
976 	{
977 	 .regs = sensor_colorfx_sky_blue_regs,
978 	 .size = ARRAY_SIZE(sensor_colorfx_sky_blue_regs),
979 	 },
980 	{
981 	 .regs = sensor_colorfx_grass_green_regs,
982 	 .size = ARRAY_SIZE(sensor_colorfx_grass_green_regs),
983 	 },
984 	{
985 	 .regs = sensor_colorfx_skin_whiten_regs,
986 	 .size = ARRAY_SIZE(sensor_colorfx_skin_whiten_regs),
987 	 },
988 	{
989 	 .regs = sensor_colorfx_vivid_regs,
990 	 .size = ARRAY_SIZE(sensor_colorfx_vivid_regs),
991 	 },
992 	{
993 	 .regs = sensor_colorfx_aqua_regs,
994 	 .size = ARRAY_SIZE(sensor_colorfx_aqua_regs),
995 	 },
996 	{
997 	 .regs = sensor_colorfx_art_freeze_regs,
998 	 .size = ARRAY_SIZE(sensor_colorfx_art_freeze_regs),
999 	 },
1000 	{
1001 	 .regs = sensor_colorfx_silhouette_regs,
1002 	 .size = ARRAY_SIZE(sensor_colorfx_silhouette_regs),
1003 	 },
1004 	{
1005 	 .regs = sensor_colorfx_solarization_regs,
1006 	 .size = ARRAY_SIZE(sensor_colorfx_solarization_regs),
1007 	 },
1008 	{
1009 	 .regs = sensor_colorfx_antique_regs,
1010 	 .size = ARRAY_SIZE(sensor_colorfx_antique_regs),
1011 	 },
1012 	{
1013 	 .regs = sensor_colorfx_set_cbcr_regs,
1014 	 .size = ARRAY_SIZE(sensor_colorfx_set_cbcr_regs),
1015 	 },
1016 };
1017 
1018 /*
1019  * The brightness setttings
1020  */
1021 static struct regval_list sensor_brightness_neg4_regs[] = {
1022 };
1023 
1024 static struct regval_list sensor_brightness_neg3_regs[] = {
1025 };
1026 
1027 static struct regval_list sensor_brightness_neg2_regs[] = {
1028 };
1029 
1030 static struct regval_list sensor_brightness_neg1_regs[] = {
1031 };
1032 
1033 static struct regval_list sensor_brightness_zero_regs[] = {
1034 };
1035 
1036 static struct regval_list sensor_brightness_pos1_regs[] = {
1037 };
1038 
1039 static struct regval_list sensor_brightness_pos2_regs[] = {
1040 };
1041 
1042 static struct regval_list sensor_brightness_pos3_regs[] = {
1043 };
1044 
1045 static struct regval_list sensor_brightness_pos4_regs[] = {
1046 };
1047 
1048 static struct cfg_array sensor_brightness[] = {
1049 	{
1050 	 .regs = sensor_brightness_neg4_regs,
1051 	 .size = ARRAY_SIZE(sensor_brightness_neg4_regs),
1052 	 },
1053 	{
1054 	 .regs = sensor_brightness_neg3_regs,
1055 	 .size = ARRAY_SIZE(sensor_brightness_neg3_regs),
1056 	 },
1057 	{
1058 	 .regs = sensor_brightness_neg2_regs,
1059 	 .size = ARRAY_SIZE(sensor_brightness_neg2_regs),
1060 	 },
1061 	{
1062 	 .regs = sensor_brightness_neg1_regs,
1063 	 .size = ARRAY_SIZE(sensor_brightness_neg1_regs),
1064 	 },
1065 	{
1066 	 .regs = sensor_brightness_zero_regs,
1067 	 .size = ARRAY_SIZE(sensor_brightness_zero_regs),
1068 	 },
1069 	{
1070 	 .regs = sensor_brightness_pos1_regs,
1071 	 .size = ARRAY_SIZE(sensor_brightness_pos1_regs),
1072 	 },
1073 	{
1074 	 .regs = sensor_brightness_pos2_regs,
1075 	 .size = ARRAY_SIZE(sensor_brightness_pos2_regs),
1076 	 },
1077 	{
1078 	 .regs = sensor_brightness_pos3_regs,
1079 	 .size = ARRAY_SIZE(sensor_brightness_pos3_regs),
1080 	 },
1081 	{
1082 	 .regs = sensor_brightness_pos4_regs,
1083 	 .size = ARRAY_SIZE(sensor_brightness_pos4_regs),
1084 	 },
1085 };
1086 
1087 /*
1088  * The contrast setttings
1089  */
1090 static struct regval_list sensor_contrast_neg4_regs[] = {
1091 };
1092 
1093 static struct regval_list sensor_contrast_neg3_regs[] = {
1094 };
1095 
1096 static struct regval_list sensor_contrast_neg2_regs[] = {
1097 };
1098 
1099 static struct regval_list sensor_contrast_neg1_regs[] = {
1100 };
1101 
1102 static struct regval_list sensor_contrast_zero_regs[] = {
1103 };
1104 
1105 static struct regval_list sensor_contrast_pos1_regs[] = {
1106 };
1107 
1108 static struct regval_list sensor_contrast_pos2_regs[] = {
1109 };
1110 
1111 static struct regval_list sensor_contrast_pos3_regs[] = {
1112 };
1113 
1114 static struct regval_list sensor_contrast_pos4_regs[] = {
1115 };
1116 
1117 static struct cfg_array sensor_contrast[] = {
1118 	{
1119 	 .regs = sensor_contrast_neg4_regs,
1120 	 .size = ARRAY_SIZE(sensor_contrast_neg4_regs),
1121 	 },
1122 	{
1123 	 .regs = sensor_contrast_neg3_regs,
1124 	 .size = ARRAY_SIZE(sensor_contrast_neg3_regs),
1125 	 },
1126 	{
1127 	 .regs = sensor_contrast_neg2_regs,
1128 	 .size = ARRAY_SIZE(sensor_contrast_neg2_regs),
1129 	 },
1130 	{
1131 	 .regs = sensor_contrast_neg1_regs,
1132 	 .size = ARRAY_SIZE(sensor_contrast_neg1_regs),
1133 	 },
1134 	{
1135 	 .regs = sensor_contrast_zero_regs,
1136 	 .size = ARRAY_SIZE(sensor_contrast_zero_regs),
1137 	 },
1138 	{
1139 	 .regs = sensor_contrast_pos1_regs,
1140 	 .size = ARRAY_SIZE(sensor_contrast_pos1_regs),
1141 	 },
1142 	{
1143 	 .regs = sensor_contrast_pos2_regs,
1144 	 .size = ARRAY_SIZE(sensor_contrast_pos2_regs),
1145 	 },
1146 	{
1147 	 .regs = sensor_contrast_pos3_regs,
1148 	 .size = ARRAY_SIZE(sensor_contrast_pos3_regs),
1149 	 },
1150 	{
1151 	 .regs = sensor_contrast_pos4_regs,
1152 	 .size = ARRAY_SIZE(sensor_contrast_pos4_regs),
1153 	 },
1154 };
1155 
1156 /*
1157  * The saturation setttings
1158  */
1159 static struct regval_list sensor_saturation_neg4_regs[] = {
1160 };
1161 
1162 static struct regval_list sensor_saturation_neg3_regs[] = {
1163 };
1164 
1165 static struct regval_list sensor_saturation_neg2_regs[] = {
1166 };
1167 
1168 static struct regval_list sensor_saturation_neg1_regs[] = {
1169 };
1170 
1171 static struct regval_list sensor_saturation_zero_regs[] = {
1172 };
1173 
1174 static struct regval_list sensor_saturation_pos1_regs[] = {
1175 };
1176 
1177 static struct regval_list sensor_saturation_pos2_regs[] = {
1178 };
1179 
1180 static struct regval_list sensor_saturation_pos3_regs[] = {
1181 };
1182 
1183 static struct regval_list sensor_saturation_pos4_regs[] = {
1184 };
1185 
1186 static struct cfg_array sensor_saturation[] = {
1187 	{
1188 	 .regs = sensor_saturation_neg4_regs,
1189 	 .size = ARRAY_SIZE(sensor_saturation_neg4_regs),
1190 	 },
1191 	{
1192 	 .regs = sensor_saturation_neg3_regs,
1193 	 .size = ARRAY_SIZE(sensor_saturation_neg3_regs),
1194 	 },
1195 	{
1196 	 .regs = sensor_saturation_neg2_regs,
1197 	 .size = ARRAY_SIZE(sensor_saturation_neg2_regs),
1198 	 },
1199 	{
1200 	 .regs = sensor_saturation_neg1_regs,
1201 	 .size = ARRAY_SIZE(sensor_saturation_neg1_regs),
1202 	 },
1203 	{
1204 	 .regs = sensor_saturation_zero_regs,
1205 	 .size = ARRAY_SIZE(sensor_saturation_zero_regs),
1206 	 },
1207 	{
1208 	 .regs = sensor_saturation_pos1_regs,
1209 	 .size = ARRAY_SIZE(sensor_saturation_pos1_regs),
1210 	 },
1211 	{
1212 	 .regs = sensor_saturation_pos2_regs,
1213 	 .size = ARRAY_SIZE(sensor_saturation_pos2_regs),
1214 	 },
1215 	{
1216 	 .regs = sensor_saturation_pos3_regs,
1217 	 .size = ARRAY_SIZE(sensor_saturation_pos3_regs),
1218 	 },
1219 	{
1220 	 .regs = sensor_saturation_pos4_regs,
1221 	 .size = ARRAY_SIZE(sensor_saturation_pos4_regs),
1222 	 },
1223 };
1224 
1225 /*
1226  * The exposure target setttings
1227  */
1228 static struct regval_list sensor_ev_neg4_regs[] = {
1229 	{0xfe, 0x01},
1230 	{0x13, 0x40},
1231 	{0xfe, 0x02},
1232 	{0xd5, 0xc0},
1233 	{0xfe, 0x00},
1234 };
1235 
1236 static struct regval_list sensor_ev_neg3_regs[] = {
1237 	{0xfe, 0x01},
1238 	{0x13, 0x50},
1239 	{0xfe, 0x02},
1240 	{0xd5, 0xd0},
1241 	{0xfe, 0x00},
1242 };
1243 
1244 static struct regval_list sensor_ev_neg2_regs[] = {
1245 	{0xfe, 0x01},
1246 	{0x13, 0x60},
1247 	{0xfe, 0x02},
1248 	{0xd5, 0xe0},
1249 	{0xfe, 0x00},
1250 };
1251 
1252 static struct regval_list sensor_ev_neg1_regs[] = {
1253 	{0xfe, 0x01},
1254 	{0x13, 0x70},
1255 	{0xfe, 0x02},
1256 	{0xd5, 0xf0},
1257 	{0xfe, 0x00},
1258 };
1259 
1260 static struct regval_list sensor_ev_zero_regs[] = {
1261 	{0xfe, 0x01},
1262 	{0x13, 0x80},
1263 	{0xfe, 0x02},
1264 	{0xd5, 0x00},
1265 	{0xfe, 0x00},
1266 };
1267 
1268 static struct regval_list sensor_ev_pos1_regs[] = {
1269 	{0xfe, 0x01},
1270 	{0x13, 0x98},
1271 	{0xfe, 0x02},
1272 	{0xd5, 0x10},
1273 	{0xfe, 0x00},
1274 };
1275 
1276 static struct regval_list sensor_ev_pos2_regs[] = {
1277 	{0xfe, 0x01},
1278 	{0x13, 0xb0},
1279 	{0xfe, 0x02},
1280 	{0xd5, 0x20},
1281 	{0xfe, 0x00},
1282 };
1283 
1284 static struct regval_list sensor_ev_pos3_regs[] = {
1285 	{0xfe, 0x01},
1286 	{0x13, 0xc0},
1287 	{0xfe, 0x02},
1288 	{0xd5, 0x30},
1289 	{0xfe, 0x00},
1290 };
1291 
1292 static struct regval_list sensor_ev_pos4_regs[] = {
1293 	{0xfe, 0x01},
1294 	{0x13, 0xd0},
1295 	{0xfe, 0x02},
1296 	{0xd5, 0x50},
1297 	{0xfe, 0x00},
1298 };
1299 
1300 static struct cfg_array sensor_ev[] = {
1301 	{
1302 	 .regs = sensor_ev_neg4_regs,
1303 	 .size = ARRAY_SIZE(sensor_ev_neg4_regs),
1304 	 },
1305 	{
1306 	 .regs = sensor_ev_neg3_regs,
1307 	 .size = ARRAY_SIZE(sensor_ev_neg3_regs),
1308 	 },
1309 	{
1310 	 .regs = sensor_ev_neg2_regs,
1311 	 .size = ARRAY_SIZE(sensor_ev_neg2_regs),
1312 	 },
1313 	{
1314 	 .regs = sensor_ev_neg1_regs,
1315 	 .size = ARRAY_SIZE(sensor_ev_neg1_regs),
1316 	 },
1317 	{
1318 	 .regs = sensor_ev_zero_regs,
1319 	 .size = ARRAY_SIZE(sensor_ev_zero_regs),
1320 	 },
1321 	{
1322 	 .regs = sensor_ev_pos1_regs,
1323 	 .size = ARRAY_SIZE(sensor_ev_pos1_regs),
1324 	 },
1325 	{
1326 	 .regs = sensor_ev_pos2_regs,
1327 	 .size = ARRAY_SIZE(sensor_ev_pos2_regs),
1328 	 },
1329 	{
1330 	 .regs = sensor_ev_pos3_regs,
1331 	 .size = ARRAY_SIZE(sensor_ev_pos3_regs),
1332 	 },
1333 	{
1334 	 .regs = sensor_ev_pos4_regs,
1335 	 .size = ARRAY_SIZE(sensor_ev_pos4_regs),
1336 	 },
1337 };
1338 
1339 /*
1340  * Here we'll try to encapsulate the changes for just the output
1341  * video format.
1342  *
1343  */
1344 
1345 static struct regval_list sensor_fmt_yuv422_yuyv[] = {
1346 	{0x84, 0x02},
1347 };
1348 
1349 static struct regval_list sensor_fmt_yuv422_yvyu[] = {
1350 	{0x84, 0x03},
1351 };
1352 
1353 static struct regval_list sensor_fmt_yuv422_vyuy[] = {
1354 	{0x84, 0x01},
1355 };
1356 
1357 static struct regval_list sensor_fmt_yuv422_uyvy[] = {
1358 	{0x84, 0x00},
1359 };
1360 
1361 static struct regval_list sensor_fmt_raw[] = {
1362 	{0x84, 0x18},
1363 };
1364 
1365 static struct regval_list sensor_oe_disable_regs[] = {
1366 };
1367 
1368 static struct regval_list sensor_oe_enable_regs[] = {
1369 };
1370 
sensor_g_hflip(struct v4l2_subdev * sd,__s32 * value)1371 static int sensor_g_hflip(struct v4l2_subdev *sd, __s32 *value)
1372 {
1373 	int ret;
1374 	struct sensor_info *info = to_state(sd);
1375 	data_type val;
1376 
1377 	ret = sensor_write(sd, 0xfe, 0x00);
1378 	if (ret < 0) {
1379 		sensor_err("sensor_write err at sensor_g_hflip!\n");
1380 		return ret;
1381 	}
1382 
1383 	ret = sensor_read(sd, 0x17, &val);
1384 	if (ret < 0) {
1385 		sensor_err("sensor_read err at sensor_g_hflip!\n");
1386 		return ret;
1387 	}
1388 
1389 	val &= (1 << 0);
1390 	val = val >> 0;
1391 
1392 	*value = val;
1393 
1394 	info->hflip = *value;
1395 	return 0;
1396 }
1397 
sensor_s_hflip(struct v4l2_subdev * sd,int value)1398 static int sensor_s_hflip(struct v4l2_subdev *sd, int value)
1399 {
1400 	int ret;
1401 	struct sensor_info *info = to_state(sd);
1402 	data_type val;
1403 
1404 	ret = sensor_write(sd, 0xfe, 0);
1405 	if (ret < 0) {
1406 		sensor_err("sensor_write err at sensor_s_hflip!\n");
1407 		return ret;
1408 	}
1409 	ret = sensor_read(sd, 0x17, &val);
1410 	if (ret < 0) {
1411 		sensor_err("sensor_read err at sensor_s_hflip!\n");
1412 		return ret;
1413 	}
1414 
1415 	switch (value) {
1416 	case 0:
1417 		val &= 0xfe;
1418 		break;
1419 	case 1:
1420 		val |= 0x01;
1421 		break;
1422 	default:
1423 		return -EINVAL;
1424 	}
1425 	ret = sensor_write(sd, 0x17, val);
1426 	if (ret < 0) {
1427 		sensor_err("sensor_write err at sensor_s_hflip!\n");
1428 		return ret;
1429 	}
1430 
1431 	usleep_range(20000, 22000);
1432 
1433 	info->hflip = value;
1434 	return 0;
1435 }
1436 
sensor_g_vflip(struct v4l2_subdev * sd,__s32 * value)1437 static int sensor_g_vflip(struct v4l2_subdev *sd, __s32 *value)
1438 {
1439 	int ret;
1440 	struct sensor_info *info = to_state(sd);
1441 	data_type val;
1442 
1443 	ret = sensor_write(sd, 0xfe, 0x00);
1444 	if (ret < 0) {
1445 		sensor_err("sensor_write err at sensor_g_vflip!\n");
1446 		return ret;
1447 	}
1448 
1449 	ret = sensor_read(sd, 0x17, &val);
1450 	if (ret < 0) {
1451 		sensor_err("sensor_read err at sensor_g_vflip!\n");
1452 		return ret;
1453 	}
1454 
1455 	val &= (1 << 1);
1456 	val = val >> 1;
1457 
1458 	*value = val;
1459 
1460 	info->vflip = *value;
1461 	return 0;
1462 }
1463 
sensor_s_vflip(struct v4l2_subdev * sd,int value)1464 static int sensor_s_vflip(struct v4l2_subdev *sd, int value)
1465 {
1466 	int ret;
1467 	struct sensor_info *info = to_state(sd);
1468 	data_type val;
1469 
1470 	ret = sensor_write(sd, 0xfe, 0x00);
1471 	if (ret < 0) {
1472 		sensor_err("sensor_write err at sensor_s_vflip!\n");
1473 		return ret;
1474 	}
1475 
1476 	ret = sensor_read(sd, 0x17, &val);
1477 	if (ret < 0) {
1478 		sensor_err("sensor_read err at sensor_s_vflip!\n");
1479 		return ret;
1480 	}
1481 
1482 	switch (value) {
1483 	case 0:
1484 		val &= 0xfd;
1485 		break;
1486 	case 1:
1487 		val |= 0x02;
1488 		break;
1489 	default:
1490 		return -EINVAL;
1491 	}
1492 	ret = sensor_write(sd, 0x17, val);
1493 	if (ret < 0) {
1494 		sensor_err("sensor_write err at sensor_s_vflip!\n");
1495 		return ret;
1496 	}
1497 
1498 	usleep_range(20000, 22000);
1499 
1500 	info->vflip = value;
1501 	return 0;
1502 }
1503 
sensor_g_autogain(struct v4l2_subdev * sd,__s32 * value)1504 static int sensor_g_autogain(struct v4l2_subdev *sd, __s32 *value)
1505 {
1506 	return -EINVAL;
1507 }
1508 
sensor_s_autogain(struct v4l2_subdev * sd,int value)1509 static int sensor_s_autogain(struct v4l2_subdev *sd, int value)
1510 {
1511 	return -EINVAL;
1512 }
1513 
sensor_g_autoexp(struct v4l2_subdev * sd,__s32 * value)1514 static int sensor_g_autoexp(struct v4l2_subdev *sd, __s32 *value)
1515 {
1516 	int ret;
1517 	struct sensor_info *info = to_state(sd);
1518 	data_type val;
1519 
1520 	ret = sensor_write(sd, 0xfe, 0x00);
1521 	if (ret < 0) {
1522 		sensor_err("sensor_write err at sensor_g_autoexp!\n");
1523 		return ret;
1524 	}
1525 
1526 	ret = sensor_read(sd, 0xb6, &val);
1527 	if (ret < 0) {
1528 		sensor_err("sensor_read err at sensor_g_autoexp!\n");
1529 		return ret;
1530 	}
1531 
1532 	val &= 0x01;
1533 	if (val == 0x01)
1534 		*value = V4L2_EXPOSURE_AUTO;
1535 	else
1536 		*value = V4L2_EXPOSURE_MANUAL;
1537 
1538 	info->autoexp = *value;
1539 	return 0;
1540 }
1541 
sensor_s_autoexp(struct v4l2_subdev * sd,enum v4l2_exposure_auto_type value)1542 static int sensor_s_autoexp(struct v4l2_subdev *sd,
1543 			    enum v4l2_exposure_auto_type value)
1544 {
1545 	int ret;
1546 	struct sensor_info *info = to_state(sd);
1547 	data_type val;
1548 
1549 	ret = sensor_write(sd, 0xfe, 0x00);
1550 	if (ret < 0) {
1551 		sensor_err("sensor_write err at sensor_s_autoexp!\n");
1552 		return ret;
1553 	}
1554 
1555 	ret = sensor_read(sd, 0xb6, &val);
1556 	if (ret < 0) {
1557 		sensor_err("sensor_read err at sensor_s_autoexp!\n");
1558 		return ret;
1559 	}
1560 
1561 	switch (value) {
1562 	case V4L2_EXPOSURE_AUTO:
1563 		val |= 0x01;
1564 		break;
1565 	case V4L2_EXPOSURE_MANUAL:
1566 		val &= 0xfe;
1567 		break;
1568 	case V4L2_EXPOSURE_SHUTTER_PRIORITY:
1569 		return -EINVAL;
1570 	case V4L2_EXPOSURE_APERTURE_PRIORITY:
1571 		return -EINVAL;
1572 	default:
1573 		return -EINVAL;
1574 	}
1575 	if (ret < 0) {
1576 		sensor_err("sensor_write err at sensor_s_autoexp!\n");
1577 		return ret;
1578 	}
1579 	usleep_range(10000, 12000);
1580 	info->autoexp = value;
1581 	return 0;
1582 }
1583 
sensor_g_autowb(struct v4l2_subdev * sd,int * value)1584 static int sensor_g_autowb(struct v4l2_subdev *sd, int *value)
1585 {
1586 	int ret;
1587 	struct sensor_info *info = to_state(sd);
1588 	data_type val;
1589 
1590 	ret = sensor_write(sd, 0xfe, 0x00);
1591 	if (ret < 0) {
1592 		sensor_err("sensor_write err at sensor_g_autowb!\n");
1593 		return ret;
1594 	}
1595 
1596 	ret = sensor_read(sd, 0x82, &val);
1597 	if (ret < 0) {
1598 		sensor_err("sensor_read err at sensor_g_autowb!\n");
1599 		return ret;
1600 	}
1601 
1602 	val &= (1 << 1);
1603 	val = val >> 1;
1604 	*value = val;
1605 	info->autowb = *value;
1606 	return 0;
1607 }
1608 
sensor_s_autowb(struct v4l2_subdev * sd,int value)1609 static int sensor_s_autowb(struct v4l2_subdev *sd, int value)
1610 {
1611 	int ret;
1612 	struct sensor_info *info = to_state(sd);
1613 	data_type val;
1614 
1615 	ret =
1616 	    sensor_write_array(sd, sensor_wb_auto_regs,
1617 			       ARRAY_SIZE(sensor_wb_auto_regs));
1618 	if (ret < 0) {
1619 		sensor_err("sensor_write_array err at sensor_s_autowb!\n");
1620 		return ret;
1621 	}
1622 
1623 	ret = sensor_read(sd, 0x82, &val);
1624 	if (ret < 0) {
1625 		sensor_err("sensor_read err at sensor_s_autowb!\n");
1626 		return ret;
1627 	}
1628 
1629 	switch (value) {
1630 	case 0:
1631 		val &= 0xfd;
1632 		break;
1633 	case 1:
1634 		val |= 0x02;
1635 		break;
1636 	default:
1637 		break;
1638 	}
1639 	ret = sensor_write(sd, 0x82, val);
1640 	if (ret < 0) {
1641 		sensor_err("sensor_write err at sensor_s_autowb!\n");
1642 		return ret;
1643 	}
1644 
1645 	usleep_range(10000, 12000);
1646 
1647 	info->autowb = value;
1648 	return 0;
1649 }
1650 
sensor_g_hue(struct v4l2_subdev * sd,__s32 * value)1651 static int sensor_g_hue(struct v4l2_subdev *sd, __s32 *value)
1652 {
1653 	return -EINVAL;
1654 }
1655 
sensor_s_hue(struct v4l2_subdev * sd,int value)1656 static int sensor_s_hue(struct v4l2_subdev *sd, int value)
1657 {
1658 	return -EINVAL;
1659 }
1660 
sensor_g_gain(struct v4l2_subdev * sd,__s32 * value)1661 static int sensor_g_gain(struct v4l2_subdev *sd, __s32 *value)
1662 {
1663 	return -EINVAL;
1664 }
1665 
sensor_s_gain(struct v4l2_subdev * sd,int value)1666 static int sensor_s_gain(struct v4l2_subdev *sd, int value)
1667 {
1668 	return -EINVAL;
1669 }
1670 
1671 /* ****************end of ********************** */
1672 
sensor_g_brightness(struct v4l2_subdev * sd,__s32 * value)1673 static int sensor_g_brightness(struct v4l2_subdev *sd, __s32 *value)
1674 {
1675 	struct sensor_info *info = to_state(sd);
1676 
1677 	*value = info->brightness;
1678 	return 0;
1679 }
1680 
sensor_s_brightness(struct v4l2_subdev * sd,int value)1681 static int sensor_s_brightness(struct v4l2_subdev *sd, int value)
1682 {
1683 	struct sensor_info *info = to_state(sd);
1684 
1685 	if (info->brightness == value)
1686 		return 0;
1687 
1688 	if (value < 0 || value > 8)
1689 		return -ERANGE;
1690 
1691 	sensor_write_array(sd, sensor_brightness[value].regs,
1692 			sensor_brightness[value].size);
1693 
1694 	info->brightness = value;
1695 	return 0;
1696 }
1697 
sensor_g_contrast(struct v4l2_subdev * sd,__s32 * value)1698 static int sensor_g_contrast(struct v4l2_subdev *sd, __s32 *value)
1699 {
1700 	struct sensor_info *info = to_state(sd);
1701 
1702 	*value = info->contrast;
1703 	return 0;
1704 }
1705 
sensor_s_contrast(struct v4l2_subdev * sd,int value)1706 static int sensor_s_contrast(struct v4l2_subdev *sd, int value)
1707 {
1708 	struct sensor_info *info = to_state(sd);
1709 
1710 	if (info->contrast == value)
1711 		return 0;
1712 
1713 	if (value < 0 || value > 8)
1714 		return -ERANGE;
1715 
1716 	sensor_write_array(sd, sensor_contrast[value].regs,
1717 			sensor_contrast[value].size);
1718 
1719 	info->contrast = value;
1720 	return 0;
1721 }
1722 
sensor_g_saturation(struct v4l2_subdev * sd,__s32 * value)1723 static int sensor_g_saturation(struct v4l2_subdev *sd, __s32 *value)
1724 {
1725 	struct sensor_info *info = to_state(sd);
1726 
1727 	*value = info->saturation;
1728 	return 0;
1729 }
1730 
sensor_s_saturation(struct v4l2_subdev * sd,int value)1731 static int sensor_s_saturation(struct v4l2_subdev *sd, int value)
1732 {
1733 	struct sensor_info *info = to_state(sd);
1734 
1735 	if (info->saturation == value)
1736 		return 0;
1737 
1738 	if (value < 0 || value > 8)
1739 		return -ERANGE;
1740 
1741 	sensor_write_array(sd, sensor_saturation[value].regs,
1742 			sensor_saturation[value].size);
1743 
1744 	info->saturation = value;
1745 	return 0;
1746 }
1747 
sensor_g_exp_bias(struct v4l2_subdev * sd,__s32 * value)1748 static int sensor_g_exp_bias(struct v4l2_subdev *sd, __s32 *value)
1749 {
1750 	struct sensor_info *info = to_state(sd);
1751 
1752 	*value = info->exp_bias;
1753 	return 0;
1754 }
1755 
sensor_s_exp_bias(struct v4l2_subdev * sd,int value)1756 static int sensor_s_exp_bias(struct v4l2_subdev *sd, int value)
1757 {
1758 	struct sensor_info *info = to_state(sd);
1759 
1760 	if (info->exp_bias == value)
1761 		return 0;
1762 
1763 	if (value < 0 || value > 8)
1764 		return -ERANGE;
1765 
1766 	sensor_write_array(sd, sensor_ev[value].regs,
1767 			sensor_ev[value].size);
1768 
1769 	info->exp_bias = value;
1770 	return 0;
1771 }
1772 
sensor_g_wb(struct v4l2_subdev * sd,int * value)1773 static int sensor_g_wb(struct v4l2_subdev *sd, int *value)
1774 {
1775 	struct sensor_info *info = to_state(sd);
1776 	enum v4l2_auto_n_preset_white_balance *wb_type =
1777 	    (enum v4l2_auto_n_preset_white_balance *)value;
1778 
1779 	*wb_type = info->wb;
1780 
1781 	return 0;
1782 }
1783 
sensor_s_wb(struct v4l2_subdev * sd,enum v4l2_auto_n_preset_white_balance value)1784 static int sensor_s_wb(struct v4l2_subdev *sd,
1785 		       enum v4l2_auto_n_preset_white_balance value)
1786 {
1787 	struct sensor_info *info = to_state(sd);
1788 
1789 	if (info->capture_mode == V4L2_MODE_IMAGE)
1790 		return 0;
1791 
1792 	sensor_write_array(sd, sensor_wb[value].regs, sensor_wb[value].size);
1793 
1794 	if (value == V4L2_WHITE_BALANCE_AUTO)
1795 		info->autowb = 1;
1796 	else
1797 		info->autowb = 0;
1798 
1799 	info->wb = value;
1800 	return 0;
1801 }
1802 
sensor_g_colorfx(struct v4l2_subdev * sd,__s32 * value)1803 static int sensor_g_colorfx(struct v4l2_subdev *sd, __s32 *value)
1804 {
1805 	struct sensor_info *info = to_state(sd);
1806 	enum v4l2_colorfx *clrfx_type = (enum v4l2_colorfx *)value;
1807 
1808 	*clrfx_type = info->clrfx;
1809 	return 0;
1810 }
1811 
sensor_s_colorfx(struct v4l2_subdev * sd,enum v4l2_colorfx value)1812 static int sensor_s_colorfx(struct v4l2_subdev *sd, enum v4l2_colorfx value)
1813 {
1814 	struct sensor_info *info = to_state(sd);
1815 
1816 	if (info->clrfx == value)
1817 		return 0;
1818 
1819 	sensor_write_array(sd, sensor_colorfx[value].regs,
1820 			sensor_colorfx[value].size);
1821 
1822 	info->clrfx = value;
1823 	return 0;
1824 }
1825 
sensor_g_flash_mode(struct v4l2_subdev * sd,__s32 * value)1826 static int sensor_g_flash_mode(struct v4l2_subdev *sd, __s32 *value)
1827 {
1828 	struct sensor_info *info = to_state(sd);
1829 	enum v4l2_flash_led_mode *flash_mode =
1830 	    (enum v4l2_flash_led_mode *)value;
1831 
1832 	*flash_mode = info->flash_mode;
1833 	return 0;
1834 }
1835 
sensor_s_flash_mode(struct v4l2_subdev * sd,enum v4l2_flash_led_mode value)1836 static int sensor_s_flash_mode(struct v4l2_subdev *sd,
1837 			       enum v4l2_flash_led_mode value)
1838 {
1839 	struct sensor_info *info = to_state(sd);
1840 
1841 	info->flash_mode = value;
1842 	return 0;
1843 }
1844 
sensor_s_sw_stby(struct v4l2_subdev * sd,int on_off)1845 static int sensor_s_sw_stby(struct v4l2_subdev *sd, int on_off)
1846 {
1847 	int ret = 0;
1848 	return ret;
1849 }
1850 
1851 /*
1852  * Stuff that knows about the sensor.
1853  */
sensor_power(struct v4l2_subdev * sd,int on)1854 static int sensor_power(struct v4l2_subdev *sd, int on)
1855 {
1856 	int ret;
1857 
1858 	cci_lock(sd);
1859 	switch (on) {
1860 	case STBY_ON:
1861 		sensor_print("STBY_ON\n");
1862 		ret = sensor_write_array(sd, sensor_oe_disable_regs,
1863 			       ARRAY_SIZE(sensor_oe_disable_regs));
1864 		if (ret < 0)
1865 			sensor_err("disalbe oe falied!\n");
1866 		ret = sensor_s_sw_stby(sd, CSI_GPIO_HIGH);
1867 		if (ret < 0)
1868 			sensor_err("soft stby falied!\n");
1869 		vin_gpio_write(sd, PWDN, CSI_GPIO_HIGH);
1870 		usleep_range(10000, 12000);
1871 		vin_set_mclk(sd, OFF);
1872 		break;
1873 	case STBY_OFF:
1874 		sensor_print("STBY_OFF\n");
1875 		ret = sensor_s_sw_stby(sd, CSI_GPIO_LOW);
1876 		if (ret < 0)
1877 			sensor_err("soft stby off falied!\n");
1878 		usleep_range(10000, 12000);
1879 		vin_gpio_write(sd, PWDN, CSI_GPIO_LOW);
1880 		usleep_range(10000, 12000);
1881 		vin_set_mclk_freq(sd, MCLK);
1882 		vin_set_mclk(sd, ON);
1883 		usleep_range(10000, 12000);
1884 		ret = sensor_write_array(sd, sensor_oe_enable_regs,
1885 			       ARRAY_SIZE(sensor_oe_enable_regs));
1886 		if (ret < 0)
1887 			sensor_err("enable oe falied!\n");
1888 		break;
1889 	case PWR_ON:
1890 		sensor_print("PWR_ON\n");
1891 		vin_set_pmu_channel(sd, CAMERAVDD, ON);
1892 		vin_gpio_set_status(sd, PWDN, 1);
1893 		vin_gpio_set_status(sd, RESET, 1);
1894 		vin_set_mclk_freq(sd, MCLK);
1895 		vin_set_mclk(sd, ON);
1896 		vin_gpio_write(sd, PWDN, CSI_GPIO_HIGH);
1897 		vin_gpio_write(sd, RESET, CSI_GPIO_LOW);
1898 		vin_gpio_write(sd, POWER_EN, CSI_GPIO_HIGH);
1899 		vin_set_pmu_channel(sd, IOVDD, ON);
1900 		vin_set_pmu_channel(sd, AVDD, ON);
1901 		vin_set_pmu_channel(sd, DVDD, ON);
1902 		vin_set_pmu_channel(sd, AFVDD, ON);
1903 		usleep_range(10000, 12000);
1904 		break;
1905 	case PWR_OFF:
1906 		sensor_print("PWR_OFF\n");
1907 		vin_gpio_write(sd, POWER_EN, CSI_GPIO_LOW);
1908 		vin_set_pmu_channel(sd, AFVDD, OFF);
1909 		vin_set_pmu_channel(sd, DVDD, OFF);
1910 		vin_set_pmu_channel(sd, AVDD, OFF);
1911 		vin_set_pmu_channel(sd, IOVDD, OFF);
1912 		vin_set_pmu_channel(sd, CAMERAVDD, OFF);
1913 		usleep_range(10000, 12000);
1914 		vin_set_mclk(sd, OFF);
1915 		vin_gpio_write(sd, RESET, CSI_GPIO_HIGH);
1916 		usleep_range(10000, 12000);
1917 		vin_gpio_write(sd, PWDN, CSI_GPIO_LOW);
1918 		vin_gpio_set_status(sd, RESET, 0);
1919 		vin_gpio_set_status(sd, PWDN, 0);
1920 		break;
1921 	default:
1922 		return -EINVAL;
1923 	}
1924 	cci_unlock(sd);
1925 	return 0;
1926 }
1927 
sensor_reset(struct v4l2_subdev * sd,u32 val)1928 static int sensor_reset(struct v4l2_subdev *sd, u32 val)
1929 {
1930 	switch (val) {
1931 	case 0:
1932 		vin_gpio_write(sd, RESET, CSI_GPIO_HIGH);
1933 		usleep_range(10000, 12000);
1934 		break;
1935 	case 1:
1936 		vin_gpio_write(sd, RESET, CSI_GPIO_LOW);
1937 		usleep_range(10000, 12000);
1938 		break;
1939 	default:
1940 		return -EINVAL;
1941 	}
1942 	return 0;
1943 }
1944 
sensor_detect(struct v4l2_subdev * sd)1945 static int sensor_detect(struct v4l2_subdev *sd)
1946 {
1947 	unsigned int SENSOR_ID = 0;
1948 	data_type val;
1949 	int cnt = 0;
1950 
1951 	sensor_read(sd, 0xf0, &val);
1952 	SENSOR_ID |= (val << 8);
1953 	sensor_read(sd, 0xf1, &val);
1954 	SENSOR_ID |= (val);
1955 	sensor_print("V4L2_IDENT_SENSOR = %x\n", SENSOR_ID);
1956 
1957 	while ((SENSOR_ID != V4L2_IDENT_SENSOR) && (cnt < 5)) {
1958 		sensor_read(sd, 0xf0, &val);
1959 		SENSOR_ID |= (val << 8);
1960 		sensor_read(sd, 0xf1, &val);
1961 		SENSOR_ID |= (val);
1962 		sensor_print("retry = %d, V4L2_IDENT_SENSOR = %x\n", cnt, SENSOR_ID);
1963 		cnt++;
1964 	}
1965 
1966 	if (SENSOR_ID != V4L2_IDENT_SENSOR)
1967 		return -ENODEV;
1968 
1969 	return 0;
1970 }
1971 
sensor_init(struct v4l2_subdev * sd,u32 val)1972 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1973 {
1974 	int ret;
1975 
1976 	sensor_dbg("sensor_init\n");
1977 	/*Make sure it is a target sensor */
1978 	ret = sensor_detect(sd);
1979 	if (ret) {
1980 		sensor_err("chip found is not an target chip.\n");
1981 		return ret;
1982 	}
1983 	ret =
1984 	    sensor_write_array(sd, sensor_default_regs,
1985 			       ARRAY_SIZE(sensor_default_regs));
1986 	return 0;
1987 }
1988 
sensor_ioctl(struct v4l2_subdev * sd,unsigned int cmd,void * arg)1989 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1990 {
1991 	int ret = 0;
1992 	struct sensor_info *info = to_state(sd);
1993 
1994 	switch (cmd) {
1995 	case GET_CURRENT_WIN_CFG:
1996 		if (info->current_wins != NULL) {
1997 			memcpy(arg,
1998 					info->current_wins,
1999 					sizeof(struct sensor_win_size));
2000 			ret = 0;
2001 		} else {
2002 			sensor_err("empty wins!\n");
2003 			ret = -1;
2004 		}
2005 		break;
2006 	default:
2007 		return -EINVAL;
2008 	}
2009 	return ret;
2010 }
2011 
2012 /*
2013  * Store information about the video data format.
2014  */
2015 static struct sensor_format_struct sensor_formats[] = {
2016 	{
2017 		.desc = "YUYV 4:2:2",
2018 		.mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
2019 		.regs = sensor_fmt_yuv422_yuyv,
2020 		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yuyv),
2021 		.bpp = 2,
2022 	}, {
2023 		.desc = "YVYU 4:2:2",
2024 		.mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
2025 		.regs = sensor_fmt_yuv422_yvyu,
2026 		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yvyu),
2027 		.bpp = 2,
2028 	}, {
2029 		.desc = "UYVY 4:2:2",
2030 		.mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
2031 		.regs = sensor_fmt_yuv422_uyvy,
2032 		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_uyvy),
2033 		.bpp = 2,
2034 	}, {
2035 		.desc = "VYUY 4:2:2",
2036 		.mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
2037 		.regs = sensor_fmt_yuv422_vyuy,
2038 		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_vyuy),
2039 		.bpp = 2,
2040 	}, {
2041 		.desc = "Raw RGB Bayer",
2042 		.mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
2043 		.regs = sensor_fmt_raw,
2044 		.regs_size = ARRAY_SIZE(sensor_fmt_raw),
2045 		.bpp = 1
2046 	},
2047 };
2048 
2049 #define N_FMTS ARRAY_SIZE(sensor_formats)
2050 
2051 /*
2052  * Then there is the issue of window sizes.  Try to capture the info here.
2053  */
2054 
2055 static struct sensor_win_size sensor_win_sizes[] = {
2056 	/* UXGA */
2057 	{
2058 	 .width = UXGA_WIDTH,
2059 	 .height = UXGA_HEIGHT,
2060 	 .hoffset = 0,
2061 	 .voffset = 0,
2062 	 .regs = sensor_uxga_regs,
2063 	 .regs_size = ARRAY_SIZE(sensor_uxga_regs),
2064 	 .set_size = NULL,
2065 	 },
2066 	/* 720p */
2067 	{
2068 	 .width = HD720_WIDTH,
2069 	 .height = HD720_HEIGHT,
2070 	 .hoffset = (UXGA_WIDTH-HD720_WIDTH)/2,
2071 	 .voffset = (UXGA_HEIGHT-HD720_HEIGHT)/2,
2072 	 .regs = sensor_uxga_regs,
2073 	 .regs_size	= ARRAY_SIZE(sensor_uxga_regs),
2074 	 .set_size = NULL,
2075 	 },
2076 	/* SVGA */
2077 	{
2078 	 .width = SVGA_WIDTH,
2079 	 .height = SVGA_HEIGHT,
2080 	 .hoffset = 0,
2081 	 .voffset = 0,
2082 	 .regs = sensor_svga_regs,
2083 	 .regs_size = ARRAY_SIZE(sensor_svga_regs),
2084 	 .set_size = NULL,
2085 	 },
2086 };
2087 
2088 #define N_WIN_SIZES (ARRAY_SIZE(sensor_win_sizes))
2089 
sensor_reg_init(struct sensor_info * info)2090 static int sensor_reg_init(struct sensor_info *info)
2091 {
2092 
2093 	int ret = 0;
2094 	unsigned int temp = 0, shutter = 0;
2095 	data_type val;
2096 	struct v4l2_subdev *sd = &info->sd;
2097 	struct sensor_format_struct *sensor_fmt = info->fmt;
2098 	struct sensor_win_size *wsize = info->current_wins;
2099 
2100 	if ((wsize->width == 1600) && (wsize->height == 1200)) {
2101 
2102 		sensor_write(sd, 0xfe, 0x00);
2103 		sensor_write(sd, 0xb6, 0x00);
2104 		/*read shutter */
2105 		sensor_read(sd, 0x03, &val);
2106 		temp |= (val << 8);
2107 		sensor_read(sd, 0x04, &val);
2108 		temp |= (val & 0xff);
2109 		shutter = temp;
2110 	}
2111 
2112 	sensor_write_array(sd, sensor_fmt->regs, sensor_fmt->regs_size);
2113 
2114 	if (wsize->regs) {
2115 		ret = sensor_write_array(sd, wsize->regs, wsize->regs_size);
2116 		if (ret < 0)
2117 			return ret;
2118 	}
2119 
2120 	if (wsize->set_size) {
2121 		ret = wsize->set_size(sd);
2122 		if (ret < 0)
2123 			return ret;
2124 	}
2125 
2126 	if ((wsize->width == 1600) && (wsize->height == 1200)) {
2127 		sensor_write(sd, 0xfe, 0x00);
2128 		shutter = shutter / 2;
2129 		if (shutter < 1)
2130 			shutter = 1;
2131 		sensor_write(sd, 0x03, ((shutter >> 8) & 0xff));
2132 		sensor_write(sd, 0x04, (shutter & 0xff));
2133 		msleep(200);
2134 	}
2135 
2136 	sensor_s_hflip(sd, info->hflip);
2137 	sensor_s_vflip(sd, info->vflip);
2138 
2139 	info->width = wsize->width;
2140 	info->height = wsize->height;
2141 
2142 	return 0;
2143 }
2144 
sensor_s_stream(struct v4l2_subdev * sd,int enable)2145 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2146 {
2147 	struct sensor_info *info = to_state(sd);
2148 
2149 	sensor_print("%s on = %d, %d*%d %x\n", __func__, enable,
2150 		  info->current_wins->width,
2151 		  info->current_wins->height, info->fmt->mbus_code);
2152 
2153 	if (!enable)
2154 		return 0;
2155 	return sensor_reg_init(info);
2156 }
2157 
sensor_g_mbus_config(struct v4l2_subdev * sd,unsigned int pad,struct v4l2_mbus_config * cfg)2158 static int sensor_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
2159 				struct v4l2_mbus_config *cfg)
2160 {
2161 	cfg->type = V4L2_MBUS_PARALLEL;
2162 	cfg->flags = V4L2_MBUS_MASTER | VREF_POL | HREF_POL | CLK_POL;
2163 
2164 	return 0;
2165 }
2166 
2167 /*
2168  * Code for dealing with controls.
2169  * fill with different sensor module
2170  * different sensor module has different settings here
2171  * if not support the follow function ,retrun -EINVAL
2172  */
2173 
2174 /* *********************begin of ***************************** */
2175 
sensor_g_ctrl(struct v4l2_ctrl * ctrl)2176 static int sensor_g_ctrl(struct v4l2_ctrl *ctrl)
2177 {
2178 	struct sensor_info *info =
2179 			container_of(ctrl->handler, struct sensor_info, handler);
2180 	struct v4l2_subdev *sd = &info->sd;
2181 
2182 	switch (ctrl->id) {
2183 	case V4L2_CID_BRIGHTNESS:
2184 		return sensor_g_brightness(sd, &ctrl->val);
2185 	case V4L2_CID_CONTRAST:
2186 		return sensor_g_contrast(sd, &ctrl->val);
2187 	case V4L2_CID_SATURATION:
2188 		return sensor_g_saturation(sd, &ctrl->val);
2189 	case V4L2_CID_HUE:
2190 		return sensor_g_hue(sd, &ctrl->val);
2191 	case V4L2_CID_VFLIP:
2192 		return sensor_g_vflip(sd, &ctrl->val);
2193 	case V4L2_CID_HFLIP:
2194 		return sensor_g_hflip(sd, &ctrl->val);
2195 	case V4L2_CID_GAIN:
2196 		return sensor_g_gain(sd, &ctrl->val);
2197 	case V4L2_CID_AUTOGAIN:
2198 		return sensor_g_autogain(sd, &ctrl->val);
2199 	case V4L2_CID_EXPOSURE:
2200 	case V4L2_CID_AUTO_EXPOSURE_BIAS:
2201 		return sensor_g_exp_bias(sd, &ctrl->val);
2202 	case V4L2_CID_EXPOSURE_AUTO:
2203 		return sensor_g_autoexp(sd, &ctrl->val);
2204 	case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2205 		return sensor_g_wb(sd, &ctrl->val);
2206 	case V4L2_CID_AUTO_WHITE_BALANCE:
2207 		return sensor_g_autowb(sd, &ctrl->val);
2208 	case V4L2_CID_COLORFX:
2209 		return sensor_g_colorfx(sd, &ctrl->val);
2210 	case V4L2_CID_FLASH_LED_MODE:
2211 		return sensor_g_flash_mode(sd, &ctrl->val);
2212 	}
2213 	return -EINVAL;
2214 }
2215 
sensor_s_ctrl(struct v4l2_ctrl * ctrl)2216 static int sensor_s_ctrl(struct v4l2_ctrl *ctrl)
2217 {
2218 	struct sensor_info *info =
2219 			container_of(ctrl->handler, struct sensor_info, handler);
2220 	struct v4l2_subdev *sd = &info->sd;
2221 
2222 	switch (ctrl->id) {
2223 	case V4L2_CID_BRIGHTNESS:
2224 		return sensor_s_brightness(sd, ctrl->val);
2225 	case V4L2_CID_CONTRAST:
2226 		return sensor_s_contrast(sd, ctrl->val);
2227 	case V4L2_CID_SATURATION:
2228 		return sensor_s_saturation(sd, ctrl->val);
2229 	case V4L2_CID_HUE:
2230 		return sensor_s_hue(sd, ctrl->val);
2231 	case V4L2_CID_VFLIP:
2232 		return sensor_s_vflip(sd, ctrl->val);
2233 	case V4L2_CID_HFLIP:
2234 		return sensor_s_hflip(sd, ctrl->val);
2235 	case V4L2_CID_GAIN:
2236 		return sensor_s_gain(sd, ctrl->val);
2237 	case V4L2_CID_AUTOGAIN:
2238 		return sensor_s_autogain(sd, ctrl->val);
2239 	case V4L2_CID_EXPOSURE:
2240 	case V4L2_CID_AUTO_EXPOSURE_BIAS:
2241 		return sensor_s_exp_bias(sd, ctrl->val);
2242 	case V4L2_CID_EXPOSURE_AUTO:
2243 		return sensor_s_autoexp(sd,
2244 				(enum v4l2_exposure_auto_type)ctrl->val);
2245 	case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2246 		return sensor_s_wb(sd,
2247 			(enum v4l2_auto_n_preset_white_balance)ctrl->val);
2248 	case V4L2_CID_AUTO_WHITE_BALANCE:
2249 		return sensor_s_autowb(sd, ctrl->val);
2250 	case V4L2_CID_COLORFX:
2251 		return sensor_s_colorfx(sd, (enum v4l2_colorfx)ctrl->val);
2252 	case V4L2_CID_FLASH_LED_MODE:
2253 		return sensor_s_flash_mode(sd,
2254 				(enum v4l2_flash_led_mode)ctrl->val);
2255 	}
2256 	return -EINVAL;
2257 }
2258 
2259 /* ----------------------------------------------------------------------- */
2260 
2261 static const struct v4l2_ctrl_ops sensor_ctrl_ops = {
2262 	.g_volatile_ctrl = sensor_g_ctrl,
2263 	.s_ctrl = sensor_s_ctrl,
2264 };
2265 
2266 static const s64 sensor_exp_bias_qmenu[] = {
2267 	-4, -3, -2, -1, 0, 1, 2, 3, 4,
2268 };
2269 
2270 static const struct v4l2_subdev_core_ops sensor_core_ops = {
2271 	.reset = sensor_reset,
2272 	.init = sensor_init,
2273 	.s_power = sensor_power,
2274 	.ioctl = sensor_ioctl,
2275 #ifdef CONFIG_COMPAT
2276 	.compat_ioctl32 = sensor_compat_ioctl32,
2277 #endif
2278 };
2279 
2280 static const struct v4l2_subdev_video_ops sensor_video_ops = {
2281 	.s_stream = sensor_s_stream,
2282 };
2283 
2284 static const struct v4l2_subdev_pad_ops sensor_pad_ops = {
2285 	.enum_mbus_code = sensor_enum_mbus_code,
2286 	.enum_frame_size = sensor_enum_frame_size,
2287 	.get_fmt = sensor_get_fmt,
2288 	.set_fmt = sensor_set_fmt,
2289 	.get_mbus_config = sensor_g_mbus_config,
2290 };
2291 
2292 static const struct v4l2_subdev_ops sensor_ops = {
2293 	.core = &sensor_core_ops,
2294 	.video = &sensor_video_ops,
2295 	.pad = &sensor_pad_ops,
2296 };
2297 
2298 /* ----------------------------------------------------------------------- */
2299 static struct cci_driver cci_drv = {
2300 	.name = SENSOR_NAME,
2301 	.addr_width = CCI_BITS_8,
2302 	.data_width = CCI_BITS_8,
2303 };
2304 
sensor_init_controls(struct v4l2_subdev * sd,const struct v4l2_ctrl_ops * ops)2305 static int sensor_init_controls(struct v4l2_subdev *sd, const struct v4l2_ctrl_ops *ops)
2306 {
2307 	struct sensor_info *info = to_state(sd);
2308 	struct v4l2_ctrl_handler *handler = &info->handler;
2309 	struct v4l2_ctrl *ctrl;
2310 	int ret = 0;
2311 
2312 	v4l2_ctrl_handler_init(handler, 9);
2313 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
2314 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
2315 	ctrl = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 0,
2316 			      65536 * 16, 1, 0);
2317 	if (ctrl != NULL)
2318 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
2319 	v4l2_ctrl_new_int_menu(handler, ops, V4L2_CID_AUTO_EXPOSURE_BIAS,
2320 				ARRAY_SIZE(sensor_exp_bias_qmenu) - 1,
2321 				ARRAY_SIZE(sensor_exp_bias_qmenu) / 2, sensor_exp_bias_qmenu);
2322 	v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_EXPOSURE_AUTO,
2323 				V4L2_EXPOSURE_APERTURE_PRIORITY, 0,
2324 				V4L2_EXPOSURE_AUTO);
2325 	v4l2_ctrl_new_std_menu(handler, ops,
2326 				V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
2327 				V4L2_WHITE_BALANCE_SHADE, 0,
2328 				V4L2_WHITE_BALANCE_AUTO);
2329 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_AUTO_WHITE_BALANCE,
2330 				0, 1, 1, 1);
2331 	v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_COLORFX,
2332 				V4L2_COLORFX_SET_CBCR, 0, V4L2_COLORFX_NONE);
2333 	v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_FLASH_LED_MODE,
2334 			       V4L2_FLASH_LED_MODE_RED_EYE, 0,
2335 			       V4L2_FLASH_LED_MODE_NONE);
2336 
2337 	if (handler->error) {
2338 		ret = handler->error;
2339 		v4l2_ctrl_handler_free(handler);
2340 	}
2341 
2342 	sd->ctrl_handler = handler;
2343 
2344 	return ret;
2345 }
2346 
sensor_probe(struct i2c_client * client,const struct i2c_device_id * id)2347 static int sensor_probe(struct i2c_client *client,
2348 			const struct i2c_device_id *id)
2349 {
2350 	struct v4l2_subdev *sd;
2351 	struct sensor_info *info;
2352 
2353 	info = kzalloc(sizeof(struct sensor_info), GFP_KERNEL);
2354 	if (info == NULL)
2355 		return -ENOMEM;
2356 	mutex_init(&info->lock);
2357 
2358 	sd = &info->sd;
2359 	cci_dev_probe_helper(sd, client, &sensor_ops, &cci_drv);
2360 	sensor_init_controls(sd, &sensor_ctrl_ops);
2361 
2362 	if (client)
2363 		client->addr = 0x78 >> 1;
2364 
2365 #ifdef CONFIG_SAME_I2C
2366 	info->sensor_i2c_addr = I2C_ADDR >> 1;
2367 #endif
2368 	info->fmt = &sensor_formats[0];
2369 	info->fmt_pt = &sensor_formats[0];
2370 	info->win_pt = &sensor_win_sizes[0];
2371 	info->fmt_num = N_FMTS;
2372 	info->win_size_num = N_WIN_SIZES;
2373 	info->sensor_field = V4L2_FIELD_NONE;
2374 	info->brightness = 0;
2375 	info->contrast = 0;
2376 	info->saturation = 0;
2377 	info->hue = 0;
2378 	info->hflip = 0;
2379 	info->vflip = 0;
2380 	info->gain = 0;
2381 	info->autogain = 1;
2382 	info->exp = 0;
2383 	info->autoexp = 0;
2384 	info->autowb = 1;
2385 	info->wb = 0;
2386 	info->clrfx = 0;
2387 
2388 	return 0;
2389 }
2390 
sensor_remove(struct i2c_client * client)2391 static int sensor_remove(struct i2c_client *client)
2392 {
2393 	struct v4l2_subdev *sd;
2394 
2395 	sd = cci_dev_remove_helper(client, &cci_drv);
2396 	kfree(to_state(sd));
2397 	return 0;
2398 }
2399 
2400 static const struct i2c_device_id sensor_id[] = {
2401 	{SENSOR_NAME, 0},
2402 	{}
2403 };
2404 
2405 MODULE_DEVICE_TABLE(i2c, sensor_id);
2406 static struct i2c_driver sensor_driver = {
2407 	.driver = {
2408 		   .owner = THIS_MODULE,
2409 		   .name = SENSOR_NAME,
2410 		   },
2411 	.probe = sensor_probe,
2412 	.remove = sensor_remove,
2413 	.id_table = sensor_id,
2414 };
2415 
init_sensor(void)2416 static __init int init_sensor(void)
2417 {
2418 	return cci_dev_init_helper(&sensor_driver);
2419 }
2420 
exit_sensor(void)2421 static __exit void exit_sensor(void)
2422 {
2423 	cci_dev_exit_helper(&sensor_driver);
2424 }
2425 
2426 module_init(init_sensor);
2427 module_exit(exit_sensor);
2428