forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/drivers/media/i2c/gc8034.c
....@@ -13,8 +13,13 @@
1313 * 1. add 2lane support.
1414 * 2. add some debug info.
1515 * 3. adjust gc8034_g_mbus_config function.
16
+ * V0.0X01.0X07 support get channel info
17
+ * V0.0X01.0X08
18
+ * 1. default support 2lane full 30fps.
19
+ * 2. default support rk otp spec.
20
+ * V0.0X01.0X09 adjust supply sequence to suit spec
1621 */
17
-
22
+//#define DEBUG
1823 #include <linux/clk.h>
1924 #include <linux/device.h>
2025 #include <linux/delay.h>
....@@ -39,8 +44,10 @@
3944 #include <media/v4l2-subdev.h>
4045 #include <linux/pinctrl/consumer.h>
4146 #include <linux/slab.h>
47
+#include <linux/of_graph.h>
48
+#include "otp_eeprom.h"
4249
43
-#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x06)
50
+#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x09)
4451
4552 #ifndef V4L2_CID_DIGITAL_GAIN
4653 #define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
....@@ -49,6 +56,7 @@
4956 #define GC8034_LANES 4
5057 #define GC8034_BITS_PER_SAMPLE 10
5158 #define GC8034_MIPI_FREQ_336MHZ 336000000U
59
+#define GC8034_MIPI_FREQ_634MHZ 634000000U
5260
5361 /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
5462 #define GC8034_PIXEL_RATE 288000000
....@@ -92,15 +100,20 @@
92100 #define GC8034_NAME "gc8034"
93101 #define GC8034_MEDIA_BUS_FMT MEDIA_BUS_FMT_SRGGB10_1X10
94102
103
+/* use RK_OTP or old mode */
104
+#define RK_OTP
105
+/* choose 2lane support full 30fps or 15fps */
106
+#define GC8034_2LANE_30FPS
107
+
95108 static const char * const gc8034_supply_names[] = {
96
- "avdd", /* Analog power */
97109 "dovdd", /* Digital I/O power */
98110 "dvdd", /* Digital core power */
111
+ "avdd", /* Analog power */
99112 };
100113
101
-static const struct regval *gc8034_global_regs;
102114 #define GC8034_NUM_SUPPLIES ARRAY_SIZE(gc8034_supply_names)
103115
116
+#ifndef RK_OTP
104117 struct gc8034_dd {
105118 u16 x;
106119 u16 y;
....@@ -145,6 +158,7 @@
145158 {0xd0, "CK8401"},
146159 {0x00, "Unknown"}
147160 };
161
+#endif
148162
149163 struct regval {
150164 u8 addr;
....@@ -158,7 +172,10 @@
158172 u32 hts_def;
159173 u32 vts_def;
160174 u32 exp_def;
175
+ u32 mipi_freq_idx;
176
+ const struct regval *global_reg_list;
161177 const struct regval *reg_list;
178
+ u32 vc[PAD_MAX];
162179 };
163180
164181 struct gc8034 {
....@@ -192,7 +209,11 @@
192209 const char *module_name;
193210 const char *len_name;
194211 u32 Dgain_ratio;
212
+#ifdef RK_OTP
213
+ struct otp_info *otp;
214
+#else
195215 struct gc8034_otp_info *otp;
216
+#endif
196217 struct rkmodule_inf module_inf;
197218 struct rkmodule_awb_cfg awb_cfg;
198219 };
....@@ -244,6 +265,217 @@
244265 * Xclk 24Mhz
245266 */
246267 static const struct regval gc8034_global_regs_2lane[] = {
268
+#ifdef GC8034_2LANE_30FPS
269
+ /* SYS */
270
+ {0xf2, 0x00},
271
+ {0xf4, 0x90},
272
+ {0xf5, 0x3d},
273
+ {0xf6, 0x44},
274
+ {0xf8, 0x63},
275
+ {0xfa, 0x42},
276
+ {0xf9, 0x00},
277
+ {0xf7, 0x95},
278
+ {0xfc, 0x00},
279
+ {0xfc, 0x00},
280
+ {0xfc, 0xea},
281
+ {0xfe, 0x03},
282
+ {0x03, 0x9a},
283
+ {0xfc, 0xee},
284
+ {0xfe, 0x00},
285
+ {0x88, 0x03},
286
+
287
+ /*Cisctl&Analog*/
288
+ {0xfe, 0x00},
289
+ {0x03, 0x08},
290
+ {0x04, 0xc6},
291
+ {0x05, 0x02},
292
+ {0x06, 0x16},
293
+ {0x07, 0x00},
294
+ {0x08, 0x10},
295
+ {0x0a, 0x3a}, //row start
296
+ {0x0b, 0x00},
297
+ {0x0c, 0x04}, //col start
298
+ {0x0d, 0x09},
299
+ {0x0e, 0xa0}, //win_height 2464
300
+ {0x0f, 0x0c},
301
+ {0x10, 0xd4}, //win_width 3284
302
+ {0x17, GC8034_MIRROR},
303
+ {0x18, 0x02},
304
+ {0x19, 0x17},
305
+ {0x1e, 0x50},
306
+ {0x1f, 0x80},
307
+ {0x21, 0x4c},
308
+ {0x25, 0x00},
309
+ {0x28, 0x4a},
310
+ {0x2d, 0x89},
311
+ {0xca, 0x02},
312
+ {0xcb, 0x00},
313
+ {0xcc, 0x39},
314
+ {0xce, 0xd0},
315
+ {0xcf, 0x93},
316
+ {0xd0, 0x1b},
317
+ {0xd1, 0xaa},
318
+ {0xd2, 0xcb},
319
+ {0xd8, 0x40},
320
+ {0xd9, 0xff},
321
+ {0xda, 0x0e},
322
+ {0xdb, 0xb0},
323
+ {0xdc, 0x0e},
324
+ {0xde, 0x08},
325
+ {0xe4, 0xc6},
326
+ {0xe5, 0x08},
327
+ {0xe6, 0x10},
328
+ {0xed, 0x2a},
329
+ {0xfe, 0x02},
330
+ {0x59, 0x02},
331
+ {0x5a, 0x04},
332
+ {0x5b, 0x08},
333
+ {0x5c, 0x20},
334
+ {0xfe, 0x00},
335
+ {0x1a, 0x09},
336
+ {0x1d, 0x13},
337
+ {0xfe, 0x10},
338
+ {0xfe, 0x00},
339
+ {0xfe, 0x10},
340
+ {0xfe, 0x00},
341
+
342
+ /* Gamma */
343
+ {0xfe, 0x00},
344
+ {0x20, 0x54},
345
+ {0x33, 0x82},
346
+ {0xfe, 0x01},
347
+ {0xdf, 0x06},
348
+ {0xe7, 0x18},
349
+ {0xe8, 0x20},
350
+ {0xe9, 0x16},
351
+ {0xea, 0x17},
352
+ {0xeb, 0x50},
353
+ {0xec, 0x6c},
354
+ {0xed, 0x9b},
355
+ {0xee, 0xd8},
356
+
357
+ /*ISP*/
358
+ {0xfe, 0x00},
359
+ {0x80, 0x13},
360
+ {0x84, 0x01},
361
+ {0x89, 0x03},
362
+ {0x8d, 0x03},
363
+ {0x8f, 0x14},
364
+ {0xad, 0x00},
365
+ {0x66, 0x0c},
366
+ {0xbc, 0x09},
367
+ {0xc2, 0x7f},
368
+ {0xc3, 0xff},
369
+
370
+ /*Crop window*/
371
+ {0x90, 0x01},
372
+ {0x92, FULL_STARTY},
373
+ {0x94, FULL_STARTX},
374
+ {0x95, 0x09},
375
+ {0x96, 0x90},
376
+ {0x97, 0x0c},
377
+ {0x98, 0xc0},
378
+
379
+ /*Gain*/
380
+ {0xb0, 0x90},
381
+ {0xb1, 0x01},
382
+ {0xb2, 0x00},
383
+ {0xb6, 0x00},
384
+
385
+ /*BLK*/
386
+ {0xfe, 0x00},
387
+ {0x40, 0x22},
388
+ {0x41, 0x20},
389
+ {0x42, 0x02},
390
+ {0x43, 0x08},
391
+ {0x4e, 0x0f},
392
+ {0x4f, 0xf0},
393
+ {0x58, 0x80},
394
+ {0x59, 0x80},
395
+ {0x5a, 0x80},
396
+ {0x5b, 0x80},
397
+ {0x5c, 0x00},
398
+ {0x5d, 0x00},
399
+ {0x5e, 0x00},
400
+ {0x5f, 0x00},
401
+ {0x6b, 0x01},
402
+ {0x6c, 0x00},
403
+ {0x6d, 0x0c},
404
+
405
+ /*WB offset*/
406
+ {0xfe, 0x01},
407
+ {0xbf, 0x40},
408
+
409
+ /*Dark Sun*/
410
+ {0xfe, 0x01},
411
+ {0x68, 0x77},
412
+
413
+ /*DPC*/
414
+ {0xfe, 0x01},
415
+ {0x60, 0x00},
416
+ {0x61, 0x10},
417
+ {0x62, 0x60},
418
+ {0x63, 0x30},
419
+ {0x64, 0x00},
420
+
421
+ /* LSC */
422
+ {0xfe, 0x01},
423
+ {0xa8, 0x60},
424
+ {0xa2, 0xd1},
425
+ {0xc8, 0x57},
426
+ {0xa1, 0xb8},
427
+ {0xa3, 0x91},
428
+ {0xc0, 0x50},
429
+ {0xd0, 0x05},
430
+ {0xd1, 0xb2},
431
+ {0xd2, 0x1f},
432
+ {0xd3, 0x00},
433
+ {0xd4, 0x00},
434
+ {0xd5, 0x00},
435
+ {0xd6, 0x00},
436
+ {0xd7, 0x00},
437
+ {0xd8, 0x00},
438
+ {0xd9, 0x00},
439
+ {0xa4, 0x10},
440
+ {0xa5, 0x20},
441
+ {0xa6, 0x60},
442
+ {0xa7, 0x80},
443
+ {0xab, 0x18},
444
+ {0xc7, 0xc0},
445
+
446
+ /*ABB*/
447
+ {0xfe, 0x01},
448
+ {0x20, 0x02},
449
+ {0x21, 0x02},
450
+ {0x23, 0x42},
451
+
452
+ /*MIPI*/
453
+ {0xfe, 0x03},
454
+ {0x01, 0x07},
455
+ {0x02, 0x04},
456
+ {0x04, 0x80},
457
+ {0x11, 0x2b},
458
+ {0x12, 0xf0}, //lwc 3264*5/4
459
+ {0x13, 0x0f},
460
+ {0x15, 0x10}, //LP
461
+ {0x16, 0x29},
462
+ {0x17, 0xff},
463
+ {0x18, 0x01},
464
+ {0x19, 0xaa},
465
+ {0x1a, 0x02},
466
+ {0x21, 0x0c},
467
+ {0x22, 0x0e},
468
+ {0x23, 0x45},
469
+ {0x24, 0x01},
470
+ {0x25, 0x1c},
471
+ {0x26, 0x0b},
472
+ {0x29, 0x0e},
473
+ {0x2a, 0x1d},
474
+ {0x2b, 0x0b},
475
+ {0xfe, 0x00},
476
+ //{0x3f, 0x91},
477
+ {0x3f, 0x00},
478
+#else
247479 /*SYS*/
248480 {0xf2, 0x00},
249481 {0xf4, 0x80},
....@@ -433,10 +665,11 @@
433665 {0xfe, 0x00},
434666 //{0x3f, 0x91},
435667 {0x3f, 0x00},
436
-
668
+#endif
437669 {REG_NULL, 0x00},
438670 };
439671
672
+#ifndef GC8034_2LANE_30FPS
440673 /*
441674 * Xclk 24Mhz
442675 * max_framerate 30fps
....@@ -507,6 +740,7 @@
507740
508741 {REG_NULL, 0x00},
509742 };
743
+#endif
510744
511745 /*
512746 * Xclk 24Mhz
....@@ -514,6 +748,72 @@
514748 * mipi_datarate per lane 672Mbps
515749 */
516750 static const struct regval gc8034_3264x2448_regs_2lane[] = {
751
+#ifdef GC8034_2LANE_30FPS
752
+ /* SYS */
753
+ {0xf2, 0x00},
754
+ {0xf4, 0x90},
755
+ {0xf5, 0x3d},
756
+ {0xf6, 0x44},
757
+ {0xf8, 0x63},
758
+ {0xfa, 0x42},
759
+ {0xf9, 0x00},
760
+ {0xf7, 0x95},
761
+ {0xfc, 0x00},
762
+ {0xfc, 0x00},
763
+ {0xfc, 0xea},
764
+ {0xfe, 0x03},
765
+ {0x03, 0x9a},
766
+ {0xfc, 0xee},
767
+ {0xfe, 0x00},
768
+ {0x3f, 0x00},
769
+ {0xfe, 0x10},
770
+ {0xfe, 0x00},
771
+ {0xfe, 0x10},
772
+ {0xfe, 0x00},
773
+
774
+ /* ISP */
775
+ {0xfe, 0x00},
776
+ {0x80, 0x13},
777
+ {0xad, 0x00},
778
+ {0x66, 0x0c},
779
+ {0xbc, 0x06},
780
+
781
+ /* Crop window */
782
+ {0x90, 0x01},
783
+ {0x92, FULL_STARTY},
784
+ {0x94, FULL_STARTX},
785
+ {0x95, 0x09},
786
+ {0x96, 0x90},
787
+ {0x97, 0x0c},
788
+ {0x98, 0xc0},
789
+
790
+ /* MIPI */
791
+ {0xfe, 0x03},
792
+ {0x01, 0x07},
793
+ {0x02, 0x04},
794
+ {0x04, 0x80},
795
+ {0x11, 0x2b},
796
+ {0x12, 0xf0}, //lwc 3264*5/4
797
+ {0x13, 0x0f},
798
+ {0x15, 0x10}, //LP
799
+ {0x16, 0x29},
800
+ {0x17, 0xff},
801
+ {0x18, 0x01},
802
+ {0x19, 0xaa},
803
+ {0x1a, 0x02},
804
+ {0x21, 0x0c},
805
+ {0x22, 0x0c},
806
+ {0x23, 0x56},
807
+ {0x24, 0x00},
808
+ {0x25, 0x1c},
809
+ {0x26, 0x0b},
810
+ {0x29, 0x0e},
811
+ {0x2a, 0x1d},
812
+ {0x2b, 0x0b},
813
+ {0xfe, 0x00},
814
+ //{0x3f, 0x91},
815
+ {0x3f, 0x00},
816
+#else
517817 /*SYS*/
518818 {0xf2, 0x00},
519819 {0xf4, 0x80},
....@@ -570,6 +870,7 @@
570870 {0xfe, 0x00},
571871 //{0x3f, 0x91},
572872 {0x3f, 0x00},
873
+#endif
573874 {REG_NULL, 0x00},
574875 };
575876
....@@ -843,6 +1144,23 @@
8431144 };
8441145
8451146 static const struct gc8034_mode supported_modes_2lane[] = {
1147
+#ifdef GC8034_2LANE_30FPS
1148
+ {
1149
+ .width = 3264,
1150
+ .height = 2448,
1151
+ .max_fps = {
1152
+ .numerator = 10000,
1153
+ .denominator = 300000,
1154
+ },
1155
+ .exp_def = 0x0900,
1156
+ .hts_def = 0x0858 * 2,
1157
+ .vts_def = 0x09c0,
1158
+ .mipi_freq_idx = 1,
1159
+ .global_reg_list = gc8034_global_regs_2lane,
1160
+ .reg_list = gc8034_3264x2448_regs_2lane,
1161
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
1162
+ },
1163
+#else
8461164 {
8471165 .width = 3264,
8481166 .height = 2448,
....@@ -853,7 +1171,10 @@
8531171 .exp_def = 0x09a0,
8541172 .hts_def = 0x0858 * 2,
8551173 .vts_def = 0x09c4,
1174
+ .mipi_freq_idx = 0,
1175
+ .global_reg_list = gc8034_global_regs_2lane,
8561176 .reg_list = gc8034_3264x2448_regs_2lane,
1177
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
8571178 },
8581179 {
8591180 .width = 1632,
....@@ -865,8 +1186,12 @@
8651186 .exp_def = 0x09a0,
8661187 .hts_def = 0x0858 * 2,
8671188 .vts_def = 0x09c4,
1189
+ .mipi_freq_idx = 0,
1190
+ .global_reg_list = gc8034_global_regs_2lane,
8681191 .reg_list = gc8034_1632x1224_regs_2lane,
1192
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
8691193 },
1194
+#endif
8701195 };
8711196
8721197 static const struct gc8034_mode supported_modes_4lane[] = {
....@@ -880,7 +1205,10 @@
8801205 .exp_def = 0x08c6,
8811206 .hts_def = 0x10b0,
8821207 .vts_def = 0x09c0,
1208
+ .mipi_freq_idx = 0,
1209
+ .global_reg_list = gc8034_global_regs_4lane,
8831210 .reg_list = gc8034_3264x2448_regs_4lane,
1211
+ .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
8841212 },
8851213 };
8861214
....@@ -888,6 +1216,7 @@
8881216
8891217 static const s64 link_freq_menu_items[] = {
8901218 GC8034_MIPI_FREQ_336MHZ,
1219
+ GC8034_MIPI_FREQ_634MHZ
8911220 };
8921221
8931222 /* Write registers up to 4 at a time */
....@@ -1017,8 +1346,8 @@
10171346 __v4l2_ctrl_modify_range(gc8034->vblank, vblank_def,
10181347 GC8034_VTS_MAX - mode->height,
10191348 1, vblank_def);
1020
- __v4l2_ctrl_s_ctrl(gc8034->link_freq,
1021
- link_freq_menu_items[0]);
1349
+ __v4l2_ctrl_s_ctrl(gc8034->vblank, vblank_def);
1350
+ __v4l2_ctrl_s_ctrl(gc8034->link_freq, mode->mipi_freq_idx);
10221351 }
10231352
10241353 mutex_unlock(&gc8034->mutex);
....@@ -1089,13 +1418,91 @@
10891418 struct gc8034 *gc8034 = to_gc8034(sd);
10901419 const struct gc8034_mode *mode = gc8034->cur_mode;
10911420
1092
- mutex_lock(&gc8034->mutex);
10931421 fi->interval = mode->max_fps;
1094
- mutex_unlock(&gc8034->mutex);
10951422
10961423 return 0;
10971424 }
10981425
1426
+#ifdef RK_OTP
1427
+static void gc8034_get_otp(struct otp_info *otp,
1428
+ struct rkmodule_inf *inf)
1429
+{
1430
+ u32 i, j;
1431
+ u32 w, h;
1432
+
1433
+ /* awb */
1434
+ if (otp->awb_data.flag) {
1435
+ inf->awb.flag = 1;
1436
+ inf->awb.r_value = otp->awb_data.r_ratio;
1437
+ inf->awb.b_value = otp->awb_data.b_ratio;
1438
+ inf->awb.gr_value = otp->awb_data.g_ratio;
1439
+ inf->awb.gb_value = 0x0;
1440
+
1441
+ inf->awb.golden_r_value = otp->awb_data.r_golden;
1442
+ inf->awb.golden_b_value = otp->awb_data.b_golden;
1443
+ inf->awb.golden_gr_value = otp->awb_data.g_golden;
1444
+ inf->awb.golden_gb_value = 0x0;
1445
+ }
1446
+
1447
+ /* lsc */
1448
+ if (otp->lsc_data.flag) {
1449
+ inf->lsc.flag = 1;
1450
+ inf->lsc.width = otp->basic_data.size.width;
1451
+ inf->lsc.height = otp->basic_data.size.height;
1452
+ inf->lsc.table_size = otp->lsc_data.table_size;
1453
+
1454
+ for (i = 0; i < 289; i++) {
1455
+ inf->lsc.lsc_r[i] = (otp->lsc_data.data[i * 2] << 8) |
1456
+ otp->lsc_data.data[i * 2 + 1];
1457
+ inf->lsc.lsc_gr[i] = (otp->lsc_data.data[i * 2 + 578] << 8) |
1458
+ otp->lsc_data.data[i * 2 + 579];
1459
+ inf->lsc.lsc_gb[i] = (otp->lsc_data.data[i * 2 + 1156] << 8) |
1460
+ otp->lsc_data.data[i * 2 + 1157];
1461
+ inf->lsc.lsc_b[i] = (otp->lsc_data.data[i * 2 + 1734] << 8) |
1462
+ otp->lsc_data.data[i * 2 + 1735];
1463
+ }
1464
+ }
1465
+
1466
+ /* pdaf */
1467
+ if (otp->pdaf_data.flag) {
1468
+ inf->pdaf.flag = 1;
1469
+ inf->pdaf.gainmap_width = otp->pdaf_data.gainmap_width;
1470
+ inf->pdaf.gainmap_height = otp->pdaf_data.gainmap_height;
1471
+ inf->pdaf.dcc_mode = otp->pdaf_data.dcc_mode;
1472
+ inf->pdaf.dcc_dir = otp->pdaf_data.dcc_dir;
1473
+ inf->pdaf.dccmap_width = otp->pdaf_data.dccmap_width;
1474
+ inf->pdaf.dccmap_height = otp->pdaf_data.dccmap_height;
1475
+ w = otp->pdaf_data.gainmap_width;
1476
+ h = otp->pdaf_data.gainmap_height;
1477
+ for (i = 0; i < h; i++) {
1478
+ for (j = 0; j < w; j++) {
1479
+ inf->pdaf.gainmap[i * w + j] =
1480
+ (otp->pdaf_data.gainmap[(i * w + j) * 2] << 8) |
1481
+ otp->pdaf_data.gainmap[(i * w + j) * 2 + 1];
1482
+ }
1483
+ }
1484
+ w = otp->pdaf_data.dccmap_width;
1485
+ h = otp->pdaf_data.dccmap_height;
1486
+ for (i = 0; i < h; i++) {
1487
+ for (j = 0; j < w; j++) {
1488
+ inf->pdaf.dccmap[i * w + j] =
1489
+ (otp->pdaf_data.dccmap[(i * w + j) * 2] << 8) |
1490
+ otp->pdaf_data.dccmap[(i * w + j) * 2 + 1];
1491
+ }
1492
+ }
1493
+ }
1494
+
1495
+ /* af */
1496
+ if (otp->af_data.flag) {
1497
+ inf->af.flag = 1;
1498
+ inf->af.dir_cnt = 1;
1499
+ inf->af.af_otp[0].vcm_start = otp->af_data.af_inf;
1500
+ inf->af.af_otp[0].vcm_end = otp->af_data.af_macro;
1501
+ inf->af.af_otp[0].vcm_dir = 0;
1502
+ }
1503
+
1504
+}
1505
+#else
10991506 #define DD_WIDTH 3284
11001507 #define DD_HEIGHT 2464
11011508
....@@ -1605,11 +2012,16 @@
16052012 inf->af.af_otp[0].vcm_dir = otp->vcm_dir;
16062013 }
16072014 }
2015
+#endif
16082016
16092017 static void gc8034_get_module_inf(struct gc8034 *gc8034,
16102018 struct rkmodule_inf *inf)
16112019 {
2020
+#ifdef RK_OTP
2021
+ struct otp_info *otp = gc8034->otp;
2022
+#else
16122023 struct gc8034_otp_info *otp = gc8034->otp;
2024
+#endif
16132025
16142026 strlcpy(inf->base.sensor,
16152027 GC8034_NAME,
....@@ -1632,11 +2044,23 @@
16322044 mutex_unlock(&gc8034->mutex);
16332045 }
16342046
2047
+static int gc8034_get_channel_info(struct gc8034 *gc8034, struct rkmodule_channel_info *ch_info)
2048
+{
2049
+ if (ch_info->index < PAD0 || ch_info->index >= PAD_MAX)
2050
+ return -EINVAL;
2051
+ ch_info->vc = gc8034->cur_mode->vc[ch_info->index];
2052
+ ch_info->width = gc8034->cur_mode->width;
2053
+ ch_info->height = gc8034->cur_mode->height;
2054
+ ch_info->bus_fmt = GC8034_MEDIA_BUS_FMT;
2055
+ return 0;
2056
+}
2057
+
16352058 static long gc8034_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
16362059 {
16372060 struct gc8034 *gc8034 = to_gc8034(sd);
16382061 long ret = 0;
16392062 u32 stream = 0;
2063
+ struct rkmodule_channel_info *ch_info;
16402064
16412065 switch (cmd) {
16422066 case RKMODULE_GET_MODULE_INFO:
....@@ -1671,6 +2095,10 @@
16712095 GC8034_MODE_SW_STANDBY);
16722096 }
16732097 break;
2098
+ case RKMODULE_GET_CHANNEL_INFO:
2099
+ ch_info = (struct rkmodule_channel_info *)arg;
2100
+ ret = gc8034_get_channel_info(gc8034, ch_info);
2101
+ break;
16742102 default:
16752103 ret = -ENOTTY;
16762104 break;
....@@ -1688,6 +2116,7 @@
16882116 struct rkmodule_awb_cfg *cfg;
16892117 long ret = 0;
16902118 u32 stream = 0;
2119
+ struct rkmodule_channel_info *ch_info;
16912120
16922121 switch (cmd) {
16932122 case RKMODULE_GET_MODULE_INFO:
....@@ -1698,8 +2127,11 @@
16982127 }
16992128
17002129 ret = gc8034_ioctl(sd, cmd, inf);
1701
- if (!ret)
2130
+ if (!ret) {
17022131 ret = copy_to_user(up, inf, sizeof(*inf));
2132
+ if (ret)
2133
+ ret = -EFAULT;
2134
+ }
17032135 kfree(inf);
17042136 break;
17052137 case RKMODULE_AWB_CFG:
....@@ -1712,12 +2144,31 @@
17122144 ret = copy_from_user(cfg, up, sizeof(*cfg));
17132145 if (!ret)
17142146 ret = gc8034_ioctl(sd, cmd, cfg);
2147
+ else
2148
+ ret = -EFAULT;
17152149 kfree(cfg);
17162150 break;
17172151 case RKMODULE_SET_QUICK_STREAM:
17182152 ret = copy_from_user(&stream, up, sizeof(u32));
17192153 if (!ret)
17202154 ret = gc8034_ioctl(sd, cmd, &stream);
2155
+ else
2156
+ ret = -EFAULT;
2157
+ break;
2158
+ case RKMODULE_GET_CHANNEL_INFO:
2159
+ ch_info = kzalloc(sizeof(*ch_info), GFP_KERNEL);
2160
+ if (!ch_info) {
2161
+ ret = -ENOMEM;
2162
+ return ret;
2163
+ }
2164
+
2165
+ ret = gc8034_ioctl(sd, cmd, ch_info);
2166
+ if (!ret) {
2167
+ ret = copy_to_user(up, ch_info, sizeof(*ch_info));
2168
+ if (ret)
2169
+ ret = -EFAULT;
2170
+ }
2171
+ kfree(ch_info);
17212172 break;
17222173 default:
17232174 ret = -ENOTTY;
....@@ -1728,6 +2179,7 @@
17282179 }
17292180 #endif
17302181
2182
+#ifndef RK_OTP
17312183 /*--------------------------------------------------------------------------*/
17322184 static int gc8034_apply_otp(struct gc8034 *gc8034)
17332185 {
....@@ -1908,11 +2360,12 @@
19082360 }
19092361 return 0;
19102362 }
2363
+#endif
19112364
19122365 static int __gc8034_start_stream(struct gc8034 *gc8034)
19132366 {
19142367 int ret;
1915
-
2368
+#ifndef RK_OTP
19162369 if (gc8034->otp) {
19172370 ret = gc8034_otp_enable(gc8034);
19182371 gc8034_check_prsel(gc8034);
....@@ -1922,6 +2375,7 @@
19222375 if (ret)
19232376 return ret;
19242377 }
2378
+#endif
19252379 ret = gc8034_write_array(gc8034->client, gc8034->cur_mode->reg_list);
19262380 if (ret)
19272381 return ret;
....@@ -2006,6 +2460,7 @@
20062460 {
20072461 struct gc8034 *gc8034 = to_gc8034(sd);
20082462 struct i2c_client *client = gc8034->client;
2463
+ const struct gc8034_mode *mode = gc8034->cur_mode;
20092464 int ret = 0;
20102465
20112466 dev_info(&client->dev, "%s(%d) on(%d)\n", __func__, __LINE__, on);
....@@ -2022,7 +2477,7 @@
20222477 goto unlock_and_return;
20232478 }
20242479
2025
- ret = gc8034_write_array(gc8034->client, gc8034_global_regs);
2480
+ ret = gc8034_write_array(gc8034->client, mode->global_reg_list);
20262481 if (ret) {
20272482 v4l2_err(sd, "could not set init registers\n");
20282483 pm_runtime_put_noidle(&client->dev);
....@@ -2047,6 +2502,31 @@
20472502 return DIV_ROUND_UP(cycles, GC8034_XVCLK_FREQ / 1000 / 1000);
20482503 }
20492504
2505
+static int gc8034_enable_regulators(struct gc8034 *gc8034,
2506
+ struct regulator_bulk_data *consumers)
2507
+{
2508
+ int i, j;
2509
+ int ret = 0;
2510
+ struct device *dev = &gc8034->client->dev;
2511
+ int num_consumers = GC8034_NUM_SUPPLIES;
2512
+
2513
+ for (i = 0; i < num_consumers; i++) {
2514
+
2515
+ ret = regulator_enable(consumers[i].consumer);
2516
+ if (ret < 0) {
2517
+ dev_err(dev, "Failed to enable regulator: %s\n",
2518
+ consumers[i].supply);
2519
+ goto err;
2520
+ }
2521
+ }
2522
+ return 0;
2523
+err:
2524
+ for (j = 0; j < i; j++)
2525
+ regulator_disable(consumers[j].consumer);
2526
+
2527
+ return ret;
2528
+}
2529
+
20502530 static int __gc8034_power_on(struct gc8034 *gc8034)
20512531 {
20522532 int ret;
....@@ -2069,27 +2549,30 @@
20692549 dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
20702550 if (clk_get_rate(gc8034->xvclk) != GC8034_XVCLK_FREQ)
20712551 dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
2072
- ret = clk_prepare_enable(gc8034->xvclk);
2073
- if (ret < 0) {
2074
- dev_err(dev, "Failed to enable xvclk\n");
2075
- return ret;
2076
- }
2552
+
20772553 if (!IS_ERR(gc8034->reset_gpio))
20782554 gpiod_set_value_cansleep(gc8034->reset_gpio, 1);
20792555
2080
- ret = regulator_bulk_enable(GC8034_NUM_SUPPLIES, gc8034->supplies);
2556
+ ret = gc8034_enable_regulators(gc8034, gc8034->supplies);
20812557 if (ret < 0) {
20822558 dev_err(dev, "Failed to enable regulators\n");
20832559 goto disable_clk;
20842560 }
20852561
2086
- usleep_range(1000, 1100);
2087
- if (!IS_ERR(gc8034->reset_gpio))
2088
- gpiod_set_value_cansleep(gc8034->reset_gpio, 0);
2562
+ usleep_range(100, 200);
2563
+ ret = clk_prepare_enable(gc8034->xvclk);
2564
+ if (ret < 0) {
2565
+ dev_err(dev, "Failed to enable xvclk\n");
2566
+ return ret;
2567
+ }
20892568
2090
- usleep_range(500, 1000);
2569
+ usleep_range(1000, 1100);
20912570 if (!IS_ERR(gc8034->pwdn_gpio))
20922571 gpiod_set_value_cansleep(gc8034->pwdn_gpio, 0);
2572
+
2573
+ usleep_range(500, 1000);
2574
+ if (!IS_ERR(gc8034->reset_gpio))
2575
+ gpiod_set_value_cansleep(gc8034->reset_gpio, 0);
20932576
20942577 /* 8192 cycles prior to first SCCB transaction */
20952578 delay_us = gc8034_cal_delay(8192);
....@@ -2109,9 +2592,11 @@
21092592
21102593 if (!IS_ERR(gc8034->pwdn_gpio))
21112594 gpiod_set_value_cansleep(gc8034->pwdn_gpio, 1);
2112
- clk_disable_unprepare(gc8034->xvclk);
2595
+
21132596 if (!IS_ERR(gc8034->reset_gpio))
21142597 gpiod_set_value_cansleep(gc8034->reset_gpio, 1);
2598
+
2599
+ clk_disable_unprepare(gc8034->xvclk);
21152600 if (!IS_ERR_OR_NULL(gc8034->pins_sleep)) {
21162601 ret = pinctrl_select_state(gc8034->pinctrl,
21172602 gc8034->pins_sleep);
....@@ -2124,7 +2609,7 @@
21242609 regulator_bulk_disable(GC8034_NUM_SUPPLIES, gc8034->supplies);
21252610 }
21262611
2127
-static int gc8034_runtime_resume(struct device *dev)
2612
+static int __maybe_unused gc8034_runtime_resume(struct device *dev)
21282613 {
21292614 struct i2c_client *client = to_i2c_client(dev);
21302615 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -2133,7 +2618,7 @@
21332618 return __gc8034_power_on(gc8034);
21342619 }
21352620
2136
-static int gc8034_runtime_suspend(struct device *dev)
2621
+static int __maybe_unused gc8034_runtime_suspend(struct device *dev)
21372622 {
21382623 struct i2c_client *client = to_i2c_client(dev);
21392624 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -2175,16 +2660,14 @@
21752660 if (fie->index >= gc8034->cfg_num)
21762661 return -EINVAL;
21772662
2178
- if (fie->code != GC8034_MEDIA_BUS_FMT)
2179
- return -EINVAL;
2180
-
2663
+ fie->code = GC8034_MEDIA_BUS_FMT;
21812664 fie->width = supported_modes[fie->index].width;
21822665 fie->height = supported_modes[fie->index].height;
21832666 fie->interval = supported_modes[fie->index].max_fps;
21842667 return 0;
21852668 }
21862669
2187
-static int gc8034_g_mbus_config(struct v4l2_subdev *sd,
2670
+static int gc8034_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
21882671 struct v4l2_mbus_config *config)
21892672 {
21902673 struct gc8034 *sensor = to_gc8034(sd);
....@@ -2193,12 +2676,12 @@
21932676 dev_info(dev, "%s(%d) enter!\n", __func__, __LINE__);
21942677
21952678 if (2 == sensor->lane_num) {
2196
- config->type = V4L2_MBUS_CSI2;
2679
+ config->type = V4L2_MBUS_CSI2_DPHY;
21972680 config->flags = V4L2_MBUS_CSI2_2_LANE |
21982681 V4L2_MBUS_CSI2_CHANNEL_0 |
21992682 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
22002683 } else if (4 == sensor->lane_num) {
2201
- config->type = V4L2_MBUS_CSI2;
2684
+ config->type = V4L2_MBUS_CSI2_DPHY;
22022685 config->flags = V4L2_MBUS_CSI2_4_LANE |
22032686 V4L2_MBUS_CSI2_CHANNEL_0 |
22042687 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
....@@ -2231,7 +2714,6 @@
22312714 static const struct v4l2_subdev_video_ops gc8034_video_ops = {
22322715 .s_stream = gc8034_s_stream,
22332716 .g_frame_interval = gc8034_g_frame_interval,
2234
- .g_mbus_config = gc8034_g_mbus_config,
22352717 };
22362718
22372719 static const struct v4l2_subdev_pad_ops gc8034_pad_ops = {
....@@ -2240,6 +2722,7 @@
22402722 .enum_frame_interval = gc8034_enum_frame_interval,
22412723 .get_fmt = gc8034_get_fmt,
22422724 .set_fmt = gc8034_set_fmt,
2725
+ .get_mbus_config = gc8034_g_mbus_config,
22432726 };
22442727
22452728 static const struct v4l2_subdev_ops gc8034_subdev_ops = {
....@@ -2388,15 +2871,15 @@
23882871 switch (ctrl->id) {
23892872 case V4L2_CID_EXPOSURE:
23902873 /* 4 least significant bits of expsoure are fractional part */
2391
- dev_info(&client->dev, "set exposure value 0x%x\n", ctrl->val);
2874
+ dev_dbg(&client->dev, "set exposure value 0x%x\n", ctrl->val);
23922875 ret = gc8034_set_exposure_reg(gc8034, ctrl->val);
23932876 break;
23942877 case V4L2_CID_ANALOGUE_GAIN:
2395
- dev_info(&client->dev, "set analog gain value 0x%x\n", ctrl->val);
2878
+ dev_dbg(&client->dev, "set analog gain value 0x%x\n", ctrl->val);
23962879 ret = gc8034_set_gain_reg(gc8034, ctrl->val);
23972880 break;
23982881 case V4L2_CID_VBLANK:
2399
- dev_info(&client->dev, "set vb value 0x%x\n", ctrl->val);
2882
+ dev_dbg(&client->dev, "set vb value 0x%x\n", ctrl->val);
24002883 /* VB = VTS - 2448 -36, according android8.1 driver */
24012884 temp = ctrl->val + gc8034->cur_mode->height - 2448 - 36;
24022885 ret = gc8034_write_reg(gc8034->client,
....@@ -2440,8 +2923,10 @@
24402923 handler->lock = &gc8034->mutex;
24412924
24422925 gc8034->link_freq = v4l2_ctrl_new_int_menu(handler, NULL,
2443
- V4L2_CID_LINK_FREQ, 0, 0,
2926
+ V4L2_CID_LINK_FREQ,
2927
+ ARRAY_SIZE(link_freq_menu_items) - 1, 0,
24442928 link_freq_menu_items);
2929
+ v4l2_ctrl_s_ctrl(gc8034->link_freq, mode->mipi_freq_idx);
24452930
24462931 v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE,
24472932 0, gc8034->pixel_rate, 1, gc8034->pixel_rate);
....@@ -2542,7 +3027,6 @@
25423027 gc8034->cur_mode = &supported_modes_4lane[0];
25433028 supported_modes = supported_modes_4lane;
25443029 gc8034->cfg_num = ARRAY_SIZE(supported_modes_4lane);
2545
- gc8034_global_regs = gc8034_global_regs_4lane;
25463030 /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
25473031 fps = DIV_ROUND_CLOSEST(gc8034->cur_mode->max_fps.denominator,
25483032 gc8034->cur_mode->max_fps.numerator);
....@@ -2555,7 +3039,6 @@
25553039 gc8034->cur_mode = &supported_modes_2lane[0];
25563040 supported_modes = supported_modes_2lane;
25573041 gc8034->cfg_num = ARRAY_SIZE(supported_modes_2lane);
2558
- gc8034_global_regs = gc8034_global_regs_2lane;
25593042 /*pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
25603043 fps = DIV_ROUND_CLOSEST(gc8034->cur_mode->max_fps.denominator,
25613044 gc8034->cur_mode->max_fps.numerator);
....@@ -2580,6 +3063,10 @@
25803063 struct v4l2_subdev *sd;
25813064 char facing[2];
25823065 int ret;
3066
+ struct device_node *eeprom_ctrl_node;
3067
+ struct i2c_client *eeprom_ctrl_client;
3068
+ struct v4l2_subdev *eeprom_ctrl;
3069
+ struct otp_info *otp_ptr;
25833070
25843071 dev_info(dev, "driver version: %02x.%02x.%02x",
25853072 DRIVER_VERSION >> 16,
....@@ -2661,10 +3148,40 @@
26613148 ret = gc8034_check_sensor_id(gc8034, client);
26623149 if (ret)
26633150 goto err_power_off;
2664
-
3151
+#ifdef RK_OTP
3152
+ eeprom_ctrl_node = of_parse_phandle(node, "eeprom-ctrl", 0);
3153
+ if (eeprom_ctrl_node) {
3154
+ eeprom_ctrl_client =
3155
+ of_find_i2c_device_by_node(eeprom_ctrl_node);
3156
+ of_node_put(eeprom_ctrl_node);
3157
+ if (IS_ERR_OR_NULL(eeprom_ctrl_client)) {
3158
+ dev_err(dev, "can not get node\n");
3159
+ goto continue_probe;
3160
+ }
3161
+ eeprom_ctrl = i2c_get_clientdata(eeprom_ctrl_client);
3162
+ if (IS_ERR_OR_NULL(eeprom_ctrl)) {
3163
+ dev_err(dev, "can not get eeprom i2c client\n");
3164
+ } else {
3165
+ otp_ptr = devm_kzalloc(dev, sizeof(*otp_ptr), GFP_KERNEL);
3166
+ if (!otp_ptr)
3167
+ return -ENOMEM;
3168
+ ret = v4l2_subdev_call(eeprom_ctrl,
3169
+ core, ioctl, 0, otp_ptr);
3170
+ if (!ret) {
3171
+ gc8034->otp = otp_ptr;
3172
+ } else {
3173
+ gc8034->otp = NULL;
3174
+ devm_kfree(dev, otp_ptr);
3175
+ dev_warn(dev, "can not get otp info, skip!\n");
3176
+ }
3177
+ }
3178
+ }
3179
+continue_probe:
3180
+#else
26653181 gc8034_otp_enable(gc8034);
26663182 gc8034_otp_read(gc8034);
26673183 gc8034_otp_disable(gc8034);
3184
+#endif
26683185
26693186 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
26703187 sd->internal_ops = &gc8034_internal_ops;