1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
|
/* drivers/media/video/s5k4ecgx.c
*
* Driver for s5k4ecgx (5MP Camera) from SEC
*
* Copyright (C) 2010, SAMSUNG ELECTRONICS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/version.h>
#include <linux/vmalloc.h>
#include <linux/completion.h>
#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>
#include <media/s5k4ecgx.h>
#include <linux/videodev2_samsung.h>
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_0
#include "s5k4ecgx_regs_1_0.h"
#define S5K4ECGX_VERSION_1_0 0x00
#endif
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_1
#include "s5k4ecgx_regs_1_1.h"
#define S5K4ECGX_VERSION_1_1 0x11
#endif
#define FORMAT_FLAGS_COMPRESSED 0x3
#define SENSOR_JPEG_SNAPSHOT_MEMSIZE 0x410580
#define DEFAULT_PIX_FMT V4L2_PIX_FMT_UYVY /* YUV422 */
#define DEFAULT_MCLK 24000000
#define POLL_TIME_MS 10
#define CAPTURE_POLL_TIME_MS 1000
/* maximum time for one frame at minimum fps (15fps) in normal mode */
#define NORMAL_MODE_MAX_ONE_FRAME_DELAY_MS 67
/* maximum time for one frame at minimum fps (4fps) in night mode */
#define NIGHT_MODE_MAX_ONE_FRAME_DELAY_MS 250
/* time to move lens to target position before last af mode register write */
#define LENS_MOVE_TIME_MS 100
/* level at or below which we need to enable flash when in auto mode */
#define LOW_LIGHT_LEVEL 0x1D
/* level at or below which we need to use low light capture mode */
#define HIGH_LIGHT_LEVEL 0x80
#define FIRST_AF_SEARCH_COUNT 80
#define SECOND_AF_SEARCH_COUNT 80
#define AE_STABLE_SEARCH_COUNT 4
#define FIRST_SETTING_FOCUS_MODE_DELAY_MS 100
#define SECOND_SETTING_FOCUS_MODE_DELAY_MS 200
#ifdef CONFIG_VIDEO_S5K4ECGX_DEBUG
enum {
S5K4ECGX_DEBUG_I2C = 1U << 0,
S5K4ECGX_DEBUG_I2C_BURSTS = 1U << 1,
};
static uint32_t s5k4ecgx_debug_mask = S5K4ECGX_DEBUG_I2C_BURSTS;
module_param_named(debug_mask, s5k4ecgx_debug_mask, uint, S_IWUSR | S_IRUGO);
#define s5k4ecgx_debug(mask, x...) \
do { \
if (s5k4ecgx_debug_mask & mask) \
pr_info(x); \
} while (0)
#else
#define s5k4ecgx_debug(mask, x...)
#endif
#define S5K4ECGX_VERSION_1_1 0x11
/* result values returned to HAL */
enum {
AUTO_FOCUS_FAILED,
AUTO_FOCUS_DONE,
AUTO_FOCUS_CANCELLED,
};
enum af_operation_status {
AF_NONE = 0,
AF_START,
AF_CANCEL,
AF_INITIAL,
};
enum s5k4ecgx_oprmode {
S5K4ECGX_OPRMODE_VIDEO = 0,
S5K4ECGX_OPRMODE_IMAGE = 1,
};
enum s5k4ecgx_preview_frame_size {
S5K4ECGX_PREVIEW_QCIF = 0, /* 176x144 */
S5K4ECGX_PREVIEW_CIF, /* 352x288 */
S5K4ECGX_PREVIEW_VGA, /* 640x480 */
S5K4ECGX_PREVIEW_D1, /* 720x480 */
S5K4ECGX_PREVIEW_WVGA, /* 800x480 */
S5K4ECGX_PREVIEW_SVGA, /* 800x600 */
S5K4ECGX_PREVIEW_WSVGA, /* 1024x600*/
S5K4ECGX_PREVIEW_MAX,
};
enum s5k4ecgx_capture_frame_size {
S5K4ECGX_CAPTURE_VGA = 0, /* 640x480 */
S5K4ECGX_CAPTURE_WVGA, /* 800x480 */
S5K4ECGX_CAPTURE_SVGA, /* 800x600 */
S5K4ECGX_CAPTURE_WSVGA, /* 1024x600 */
S5K4ECGX_CAPTURE_1MP, /* 1280x960 */
S5K4ECGX_CAPTURE_W1MP, /* 1600x960 */
S5K4ECGX_CAPTURE_2MP, /* UXGA - 1600x1200 */
S5K4ECGX_CAPTURE_W2MP, /* 35mm Academy Offset Standard 1.66 */
/* 2048x1232, 2.4MP */
S5K4ECGX_CAPTURE_3MP, /* QXGA - 2048x1536 */
S5K4ECGX_CAPTURE_W4MP, /* WQXGA - 2560x1536 */
S5K4ECGX_CAPTURE_5MP, /* 2560x1920 */
S5K4ECGX_CAPTURE_MAX,
};
struct s5k4ecgx_framesize {
u32 index;
u32 width;
u32 height;
};
static const struct s5k4ecgx_framesize s5k4ecgx_preview_framesize_list[] = {
{ S5K4ECGX_PREVIEW_QCIF, 176, 144 },
{ S5K4ECGX_PREVIEW_CIF, 352, 288 },
{ S5K4ECGX_PREVIEW_VGA, 640, 480 },
{ S5K4ECGX_PREVIEW_D1, 720, 480 },
};
static const struct s5k4ecgx_framesize s5k4ecgx_capture_framesize_list[] = {
{ S5K4ECGX_CAPTURE_VGA, 640, 480 },
{ S5K4ECGX_CAPTURE_1MP, 1280, 960 },
{ S5K4ECGX_CAPTURE_2MP, 1600, 1200 },
{ S5K4ECGX_CAPTURE_3MP, 2048, 1536 },
{ S5K4ECGX_CAPTURE_5MP, 2560, 1920 },
};
struct s5k4ecgx_version {
u32 major;
u32 minor;
};
struct s5k4ecgx_date_info {
u32 year;
u32 month;
u32 date;
};
enum s5k4ecgx_runmode {
S5K4ECGX_RUNMODE_NOTREADY,
S5K4ECGX_RUNMODE_IDLE,
S5K4ECGX_RUNMODE_RUNNING,
S5K4ECGX_RUNMODE_CAPTURE,
};
struct s5k4ecgx_firmware {
u32 addr;
u32 size;
};
struct s5k4ecgx_jpeg_param {
u32 enable;
u32 quality;
u32 main_size; /* Main JPEG file size */
u32 thumb_size; /* Thumbnail file size */
u32 main_offset;
u32 thumb_offset;
u32 postview_offset;
};
struct s5k4ecgx_position {
int x;
int y;
};
struct gps_info_common {
u32 direction;
u32 dgree;
u32 minute;
u32 second;
};
struct s5k4ecgx_gps_info {
unsigned char gps_buf[8];
unsigned char altitude_buf[4];
int gps_timeStamp;
};
struct s5k4ecgx_regset {
u32 size;
u8 *data;
};
struct s5k4ecgx_regset_table {
const u32 *reg;
int array_size;
};
#define S5K4ECGX_REGSET(x, y) \
[(x)] = { \
.reg = (y), \
.array_size = ARRAY_SIZE((y)), \
}
#define S5K4ECGX_REGSET_TABLE(y) \
{ \
.reg = (y), \
.array_size = ARRAY_SIZE((y)), \
}
struct s5k4ecgx_regs {
struct s5k4ecgx_regset_table ev[EV_MAX];
struct s5k4ecgx_regset_table metering[METERING_MAX];
struct s5k4ecgx_regset_table iso[ISO_MAX];
struct s5k4ecgx_regset_table effect[IMAGE_EFFECT_MAX];
struct s5k4ecgx_regset_table white_balance[WHITE_BALANCE_MAX];
struct s5k4ecgx_regset_table preview_size[S5K4ECGX_PREVIEW_MAX];
struct s5k4ecgx_regset_table capture_size[S5K4ECGX_CAPTURE_MAX];
struct s5k4ecgx_regset_table scene_mode[SCENE_MODE_MAX];
struct s5k4ecgx_regset_table saturation[SATURATION_MAX];
struct s5k4ecgx_regset_table contrast[CONTRAST_MAX];
struct s5k4ecgx_regset_table sharpness[SHARPNESS_MAX];
struct s5k4ecgx_regset_table fps[FRAME_RATE_MAX];
struct s5k4ecgx_regset_table preview_return;
struct s5k4ecgx_regset_table jpeg_quality_high;
struct s5k4ecgx_regset_table jpeg_quality_normal;
struct s5k4ecgx_regset_table jpeg_quality_low;
struct s5k4ecgx_regset_table flash_start;
struct s5k4ecgx_regset_table flash_end;
struct s5k4ecgx_regset_table af_assist_flash_start;
struct s5k4ecgx_regset_table af_assist_flash_end;
struct s5k4ecgx_regset_table af_low_light_mode_on;
struct s5k4ecgx_regset_table af_low_light_mode_off;
struct s5k4ecgx_regset_table ae_awb_lock_on;
struct s5k4ecgx_regset_table ae_awb_lock_off;
struct s5k4ecgx_regset_table low_cap_on;
struct s5k4ecgx_regset_table low_cap_off;
struct s5k4ecgx_regset_table wdr_on;
struct s5k4ecgx_regset_table wdr_off;
struct s5k4ecgx_regset_table face_detection_on;
struct s5k4ecgx_regset_table face_detection_off;
struct s5k4ecgx_regset_table capture_start;
struct s5k4ecgx_regset_table af_macro_mode_1;
struct s5k4ecgx_regset_table af_macro_mode_2;
struct s5k4ecgx_regset_table af_macro_mode_3;
struct s5k4ecgx_regset_table af_normal_mode_1;
struct s5k4ecgx_regset_table af_normal_mode_2;
struct s5k4ecgx_regset_table af_normal_mode_3;
struct s5k4ecgx_regset_table af_return_macro_position;
struct s5k4ecgx_regset_table single_af_start;
struct s5k4ecgx_regset_table single_af_off_1;
struct s5k4ecgx_regset_table single_af_off_2;
struct s5k4ecgx_regset_table dtp_start;
struct s5k4ecgx_regset_table dtp_stop;
struct s5k4ecgx_regset_table init_reg_1;
struct s5k4ecgx_regset_table init_reg_2;
struct s5k4ecgx_regset_table flash_init;
struct s5k4ecgx_regset_table reset_crop;
struct s5k4ecgx_regset_table get_ae_stable_status;
struct s5k4ecgx_regset_table get_light_level;
struct s5k4ecgx_regset_table get_1st_af_search_status;
struct s5k4ecgx_regset_table get_2nd_af_search_status;
struct s5k4ecgx_regset_table get_capture_status;
struct s5k4ecgx_regset_table get_esd_status;
struct s5k4ecgx_regset_table get_iso;
struct s5k4ecgx_regset_table get_shutterspeed;
};
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_0
static const struct s5k4ecgx_regs regs_for_fw_version_1_0 = {
.ev = {
S5K4ECGX_REGSET(EV_MINUS_4, s5k4ecgx_EV_Minus_4_v1),
S5K4ECGX_REGSET(EV_MINUS_3, s5k4ecgx_EV_Minus_3_v1),
S5K4ECGX_REGSET(EV_MINUS_2, s5k4ecgx_EV_Minus_2_v1),
S5K4ECGX_REGSET(EV_MINUS_1, s5k4ecgx_EV_Minus_1_v1),
S5K4ECGX_REGSET(EV_DEFAULT, s5k4ecgx_EV_Default_v1),
S5K4ECGX_REGSET(EV_PLUS_1, s5k4ecgx_EV_Plus_1_v1),
S5K4ECGX_REGSET(EV_PLUS_2, s5k4ecgx_EV_Plus_2_v1),
S5K4ECGX_REGSET(EV_PLUS_3, s5k4ecgx_EV_Plus_3_v1),
S5K4ECGX_REGSET(EV_PLUS_4, s5k4ecgx_EV_Plus_4_v1),
},
.metering = {
S5K4ECGX_REGSET(METERING_MATRIX, s5k4ecgx_Metering_Matrix_v1),
S5K4ECGX_REGSET(METERING_CENTER, s5k4ecgx_Metering_Center_v1),
S5K4ECGX_REGSET(METERING_SPOT, s5k4ecgx_Metering_Spot_v1),
},
.iso = {
S5K4ECGX_REGSET(ISO_AUTO, s5k4ecgx_ISO_Auto_v1),
S5K4ECGX_REGSET(ISO_50, s5k4ecgx_ISO_100_v1), /* use 100 */
S5K4ECGX_REGSET(ISO_100, s5k4ecgx_ISO_100_v1),
S5K4ECGX_REGSET(ISO_200, s5k4ecgx_ISO_200_v1),
S5K4ECGX_REGSET(ISO_400, s5k4ecgx_ISO_400_v1),
S5K4ECGX_REGSET(ISO_800, s5k4ecgx_ISO_400_v1), /* use 400 */
S5K4ECGX_REGSET(ISO_1600, s5k4ecgx_ISO_400_v1), /* use 400 */
S5K4ECGX_REGSET(ISO_SPORTS, s5k4ecgx_ISO_Auto_v1),/* use auto */
S5K4ECGX_REGSET(ISO_NIGHT, s5k4ecgx_ISO_Auto_v1), /* use auto */
S5K4ECGX_REGSET(ISO_MOVIE, s5k4ecgx_ISO_Auto_v1), /* use auto */
},
.effect = {
S5K4ECGX_REGSET(IMAGE_EFFECT_NONE, s5k4ecgx_Effect_Normal_v1),
S5K4ECGX_REGSET(IMAGE_EFFECT_BNW,
s5k4ecgx_Effect_Black_White_v1),
S5K4ECGX_REGSET(IMAGE_EFFECT_SEPIA, s5k4ecgx_Effect_Sepia_v1),
S5K4ECGX_REGSET(IMAGE_EFFECT_NEGATIVE,
s5k4ecgx_Effect_Negative_v1),
},
.white_balance = {
S5K4ECGX_REGSET(WHITE_BALANCE_AUTO, s5k4ecgx_WB_Auto_v1),
S5K4ECGX_REGSET(WHITE_BALANCE_SUNNY, s5k4ecgx_WB_Sunny_v1),
S5K4ECGX_REGSET(WHITE_BALANCE_CLOUDY, s5k4ecgx_WB_Cloudy_v1),
S5K4ECGX_REGSET(WHITE_BALANCE_TUNGSTEN,
s5k4ecgx_WB_Tungsten_v1),
S5K4ECGX_REGSET(WHITE_BALANCE_FLUORESCENT,
s5k4ecgx_WB_Fluorescent_v1),
},
.preview_size = {
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_QCIF, s5k4ecgx_176_Preview_v1),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_CIF, s5k4ecgx_352_Preview_v1),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_VGA, s5k4ecgx_640_Preview_v1),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_D1, s5k4ecgx_720_Preview_v1),
},
.capture_size = {
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_VGA, s5k4ecgx_VGA_Capture_v1),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_1MP, s5k4ecgx_1M_Capture_v1),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_2MP, s5k4ecgx_2M_Capture_v1),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_3MP, s5k4ecgx_3M_Capture_v1),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_5MP, s5k4ecgx_5M_Capture_v1),
},
.scene_mode = {
S5K4ECGX_REGSET(SCENE_MODE_NONE, s5k4ecgx_Scene_Default_v1),
S5K4ECGX_REGSET(SCENE_MODE_PORTRAIT,
s5k4ecgx_Scene_Portrait_v1),
S5K4ECGX_REGSET(SCENE_MODE_NIGHTSHOT,
s5k4ecgx_Scene_Nightshot_v1),
S5K4ECGX_REGSET(SCENE_MODE_LANDSCAPE,
s5k4ecgx_Scene_Landscape_v1),
S5K4ECGX_REGSET(SCENE_MODE_SPORTS, s5k4ecgx_Scene_Sports_v1),
S5K4ECGX_REGSET(SCENE_MODE_PARTY_INDOOR,
s5k4ecgx_Scene_Party_Indoor_v1),
S5K4ECGX_REGSET(SCENE_MODE_BEACH_SNOW,
s5k4ecgx_Scene_Beach_Snow_v1),
S5K4ECGX_REGSET(SCENE_MODE_SUNSET, s5k4ecgx_Scene_Sunset_v1),
S5K4ECGX_REGSET(SCENE_MODE_FIREWORKS,
s5k4ecgx_Scene_Fireworks_v1),
S5K4ECGX_REGSET(SCENE_MODE_CANDLE_LIGHT,
s5k4ecgx_Scene_Candle_Light_v1),
},
.saturation = {
S5K4ECGX_REGSET(SATURATION_MINUS_2,
s5k4ecgx_Saturation_Minus_2_v1),
S5K4ECGX_REGSET(SATURATION_MINUS_1,
s5k4ecgx_Saturation_Minus_1_v1),
S5K4ECGX_REGSET(SATURATION_DEFAULT,
s5k4ecgx_Saturation_Default_v1),
S5K4ECGX_REGSET(SATURATION_PLUS_1,
s5k4ecgx_Saturation_Plus_1_v1),
S5K4ECGX_REGSET(SATURATION_PLUS_2,
s5k4ecgx_Saturation_Plus_2_v1),
},
.contrast = {
S5K4ECGX_REGSET(CONTRAST_MINUS_2, s5k4ecgx_Contrast_Minus_2_v1),
S5K4ECGX_REGSET(CONTRAST_MINUS_1, s5k4ecgx_Contrast_Minus_1_v1),
S5K4ECGX_REGSET(CONTRAST_DEFAULT, s5k4ecgx_Contrast_Default_v1),
S5K4ECGX_REGSET(CONTRAST_PLUS_1, s5k4ecgx_Contrast_Plus_1_v1),
S5K4ECGX_REGSET(CONTRAST_PLUS_2, s5k4ecgx_Contrast_Plus_2_v1),
},
.sharpness = {
S5K4ECGX_REGSET(SHARPNESS_MINUS_2,
s5k4ecgx_Sharpness_Minus_2_v1),
S5K4ECGX_REGSET(SHARPNESS_MINUS_1,
s5k4ecgx_Sharpness_Minus_1_v1),
S5K4ECGX_REGSET(SHARPNESS_DEFAULT,
s5k4ecgx_Sharpness_Default_v1),
S5K4ECGX_REGSET(SHARPNESS_PLUS_1, s5k4ecgx_Sharpness_Plus_1_v1),
S5K4ECGX_REGSET(SHARPNESS_PLUS_2, s5k4ecgx_Sharpness_Plus_2_v1),
},
.preview_return = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Preview_Return_v1),
.jpeg_quality_high =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_High_v1),
.jpeg_quality_normal =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_Normal_v1),
.jpeg_quality_low = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_Low_v1),
.flash_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_Start_v1),
.flash_end = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_End_v1),
.af_assist_flash_start =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Pre_Flash_Start_v1),
.af_assist_flash_end =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Pre_Flash_End_v1),
.af_low_light_mode_on =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Low_Light_Mode_On_v1),
.af_low_light_mode_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Low_Light_Mode_Off_v1),
.ae_awb_lock_on =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AE_AWB_Lock_On_v1),
.ae_awb_lock_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AE_AWB_Lock_Off_v1),
.low_cap_on = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Low_Cap_On_v1),
.low_cap_off = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Low_Cap_Off_v1),
.wdr_on = S5K4ECGX_REGSET_TABLE(s5k4ecgx_WDR_on_v1),
.wdr_off = S5K4ECGX_REGSET_TABLE(s5k4ecgx_WDR_off_v1),
.face_detection_on =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Face_Detection_On_v1),
.face_detection_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Face_Detection_Off_v1),
.capture_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Capture_Start_v1),
.af_macro_mode_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_1_v1),
.af_macro_mode_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_2_v1),
.af_macro_mode_3 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_3_v1),
.af_normal_mode_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_1_v1),
.af_normal_mode_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_2_v1),
.af_normal_mode_3 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_3_v1),
.af_return_macro_position =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Return_Macro_pos_v1),
.single_af_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Start_v1),
.single_af_off_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Off_1_v1),
.single_af_off_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Off_2_v1),
.dtp_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_DTP_init_v1),
.dtp_stop = S5K4ECGX_REGSET_TABLE(s5k4ecgx_DTP_stop_v1),
.init_reg_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_init_reg1_v1),
.init_reg_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_init_reg2_v1),
.flash_init = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_init_v1),
.reset_crop = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Reset_Crop_v1),
.get_ae_stable_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Get_AE_Stable_Status_v1),
.get_light_level = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Get_Light_Level_v1),
.get_1st_af_search_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_1st_af_search_status_v1),
.get_2nd_af_search_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_2nd_af_search_status_v1),
.get_capture_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_capture_status_v1),
.get_esd_status = S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_esd_status_v1),
.get_iso = S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_iso_reg_v1),
.get_shutterspeed =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_shutterspeed_reg_v1),
};
#endif
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_1
static const struct s5k4ecgx_regs regs_for_fw_version_1_1 = {
.ev = {
S5K4ECGX_REGSET(EV_MINUS_4, s5k4ecgx_EV_Minus_4),
S5K4ECGX_REGSET(EV_MINUS_3, s5k4ecgx_EV_Minus_3),
S5K4ECGX_REGSET(EV_MINUS_2, s5k4ecgx_EV_Minus_2),
S5K4ECGX_REGSET(EV_MINUS_1, s5k4ecgx_EV_Minus_1),
S5K4ECGX_REGSET(EV_DEFAULT, s5k4ecgx_EV_Default),
S5K4ECGX_REGSET(EV_PLUS_1, s5k4ecgx_EV_Plus_1),
S5K4ECGX_REGSET(EV_PLUS_2, s5k4ecgx_EV_Plus_2),
S5K4ECGX_REGSET(EV_PLUS_3, s5k4ecgx_EV_Plus_3),
S5K4ECGX_REGSET(EV_PLUS_4, s5k4ecgx_EV_Plus_4),
},
.metering = {
S5K4ECGX_REGSET(METERING_MATRIX, s5k4ecgx_Metering_Matrix),
S5K4ECGX_REGSET(METERING_CENTER, s5k4ecgx_Metering_Center),
S5K4ECGX_REGSET(METERING_SPOT, s5k4ecgx_Metering_Spot),
},
.iso = {
S5K4ECGX_REGSET(ISO_AUTO, s5k4ecgx_ISO_Auto),
S5K4ECGX_REGSET(ISO_50, s5k4ecgx_ISO_100), /* map to 100 */
S5K4ECGX_REGSET(ISO_100, s5k4ecgx_ISO_100),
S5K4ECGX_REGSET(ISO_200, s5k4ecgx_ISO_200),
S5K4ECGX_REGSET(ISO_400, s5k4ecgx_ISO_400),
S5K4ECGX_REGSET(ISO_800, s5k4ecgx_ISO_400), /* map to 400 */
S5K4ECGX_REGSET(ISO_1600, s5k4ecgx_ISO_400), /* map to 400 */
S5K4ECGX_REGSET(ISO_SPORTS, s5k4ecgx_ISO_Auto),/* map to auto */
S5K4ECGX_REGSET(ISO_NIGHT, s5k4ecgx_ISO_Auto), /* map to auto */
S5K4ECGX_REGSET(ISO_MOVIE, s5k4ecgx_ISO_Auto), /* map to auto */
},
.effect = {
S5K4ECGX_REGSET(IMAGE_EFFECT_NONE, s5k4ecgx_Effect_Normal),
S5K4ECGX_REGSET(IMAGE_EFFECT_BNW, s5k4ecgx_Effect_Black_White),
S5K4ECGX_REGSET(IMAGE_EFFECT_SEPIA, s5k4ecgx_Effect_Sepia),
S5K4ECGX_REGSET(IMAGE_EFFECT_NEGATIVE,
s5k4ecgx_Effect_Negative),
},
.white_balance = {
S5K4ECGX_REGSET(WHITE_BALANCE_AUTO, s5k4ecgx_WB_Auto),
S5K4ECGX_REGSET(WHITE_BALANCE_SUNNY, s5k4ecgx_WB_Sunny),
S5K4ECGX_REGSET(WHITE_BALANCE_CLOUDY, s5k4ecgx_WB_Cloudy),
S5K4ECGX_REGSET(WHITE_BALANCE_TUNGSTEN, s5k4ecgx_WB_Tungsten),
S5K4ECGX_REGSET(WHITE_BALANCE_FLUORESCENT,
s5k4ecgx_WB_Fluorescent),
},
.preview_size = {
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_QCIF, s5k4ecgx_176_Preview),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_CIF, s5k4ecgx_352_Preview),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_VGA, s5k4ecgx_640_Preview),
S5K4ECGX_REGSET(S5K4ECGX_PREVIEW_D1, s5k4ecgx_720_Preview),
},
.capture_size = {
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_VGA, s5k4ecgx_VGA_Capture),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_1MP, s5k4ecgx_1M_Capture),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_2MP, s5k4ecgx_2M_Capture),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_3MP, s5k4ecgx_3M_Capture),
S5K4ECGX_REGSET(S5K4ECGX_CAPTURE_5MP, s5k4ecgx_5M_Capture),
},
.scene_mode = {
S5K4ECGX_REGSET(SCENE_MODE_NONE, s5k4ecgx_Scene_Default),
S5K4ECGX_REGSET(SCENE_MODE_PORTRAIT, s5k4ecgx_Scene_Portrait),
S5K4ECGX_REGSET(SCENE_MODE_NIGHTSHOT, s5k4ecgx_Scene_Nightshot),
S5K4ECGX_REGSET(SCENE_MODE_LANDSCAPE, s5k4ecgx_Scene_Landscape),
S5K4ECGX_REGSET(SCENE_MODE_SPORTS, s5k4ecgx_Scene_Sports),
S5K4ECGX_REGSET(SCENE_MODE_PARTY_INDOOR,
s5k4ecgx_Scene_Party_Indoor),
S5K4ECGX_REGSET(SCENE_MODE_BEACH_SNOW,
s5k4ecgx_Scene_Beach_Snow),
S5K4ECGX_REGSET(SCENE_MODE_SUNSET, s5k4ecgx_Scene_Sunset),
S5K4ECGX_REGSET(SCENE_MODE_FIREWORKS, s5k4ecgx_Scene_Fireworks),
S5K4ECGX_REGSET(SCENE_MODE_CANDLE_LIGHT,
s5k4ecgx_Scene_Candle_Light),
},
.saturation = {
S5K4ECGX_REGSET(SATURATION_MINUS_2,
s5k4ecgx_Saturation_Minus_2),
S5K4ECGX_REGSET(SATURATION_MINUS_1,
s5k4ecgx_Saturation_Minus_1),
S5K4ECGX_REGSET(SATURATION_DEFAULT,
s5k4ecgx_Saturation_Default),
S5K4ECGX_REGSET(SATURATION_PLUS_1, s5k4ecgx_Saturation_Plus_1),
S5K4ECGX_REGSET(SATURATION_PLUS_2, s5k4ecgx_Saturation_Plus_2),
},
.contrast = {
S5K4ECGX_REGSET(CONTRAST_MINUS_2, s5k4ecgx_Contrast_Minus_2),
S5K4ECGX_REGSET(CONTRAST_MINUS_1, s5k4ecgx_Contrast_Minus_1),
S5K4ECGX_REGSET(CONTRAST_DEFAULT, s5k4ecgx_Contrast_Default),
S5K4ECGX_REGSET(CONTRAST_PLUS_1, s5k4ecgx_Contrast_Plus_1),
S5K4ECGX_REGSET(CONTRAST_PLUS_2, s5k4ecgx_Contrast_Plus_2),
},
.sharpness = {
S5K4ECGX_REGSET(SHARPNESS_MINUS_2, s5k4ecgx_Sharpness_Minus_2),
S5K4ECGX_REGSET(SHARPNESS_MINUS_1, s5k4ecgx_Sharpness_Minus_1),
S5K4ECGX_REGSET(SHARPNESS_DEFAULT, s5k4ecgx_Sharpness_Default),
S5K4ECGX_REGSET(SHARPNESS_PLUS_1, s5k4ecgx_Sharpness_Plus_1),
S5K4ECGX_REGSET(SHARPNESS_PLUS_2, s5k4ecgx_Sharpness_Plus_2),
},
.fps = {
S5K4ECGX_REGSET(FRAME_RATE_AUTO, s5k4ecgx_FPS_Auto),
S5K4ECGX_REGSET(FRAME_RATE_7, s5k4ecgx_FPS_7),
S5K4ECGX_REGSET(FRAME_RATE_15, s5k4ecgx_FPS_15),
S5K4ECGX_REGSET(FRAME_RATE_30, s5k4ecgx_FPS_30),
},
.preview_return = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Preview_Return),
.jpeg_quality_high = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_High),
.jpeg_quality_normal =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_Normal),
.jpeg_quality_low = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Jpeg_Quality_Low),
.flash_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_Start),
.flash_end = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_End),
.af_assist_flash_start =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Pre_Flash_Start),
.af_assist_flash_end =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Pre_Flash_End),
.af_low_light_mode_on =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Low_Light_Mode_On),
.af_low_light_mode_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Low_Light_Mode_Off),
.ae_awb_lock_on =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AE_AWB_Lock_On),
.ae_awb_lock_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AE_AWB_Lock_Off),
.low_cap_on = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Low_Cap_On),
.low_cap_off = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Low_Cap_Off),
.wdr_on = S5K4ECGX_REGSET_TABLE(s5k4ecgx_WDR_on),
.wdr_off = S5K4ECGX_REGSET_TABLE(s5k4ecgx_WDR_off),
.face_detection_on = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Face_Detection_On),
.face_detection_off =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Face_Detection_Off),
.capture_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Capture_Start),
.af_macro_mode_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_1),
.af_macro_mode_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_2),
.af_macro_mode_3 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Macro_mode_3),
.af_normal_mode_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_1),
.af_normal_mode_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_2),
.af_normal_mode_3 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Normal_mode_3),
.af_return_macro_position =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_AF_Return_Macro_pos),
.single_af_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Start),
.single_af_off_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Off_1),
.single_af_off_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Single_AF_Off_2),
.dtp_start = S5K4ECGX_REGSET_TABLE(s5k4ecgx_DTP_init),
.dtp_stop = S5K4ECGX_REGSET_TABLE(s5k4ecgx_DTP_stop),
.init_reg_1 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_init_reg1),
.init_reg_2 = S5K4ECGX_REGSET_TABLE(s5k4ecgx_init_reg2),
.flash_init = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Flash_init),
.reset_crop = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Reset_Crop),
.get_ae_stable_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_Get_AE_Stable_Status),
.get_light_level = S5K4ECGX_REGSET_TABLE(s5k4ecgx_Get_Light_Level),
.get_1st_af_search_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_1st_af_search_status),
.get_2nd_af_search_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_2nd_af_search_status),
.get_capture_status =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_capture_status),
.get_esd_status = S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_esd_status),
.get_iso = S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_iso_reg),
.get_shutterspeed =
S5K4ECGX_REGSET_TABLE(s5k4ecgx_get_shutterspeed_reg),
};
#endif
struct s5k4ecgx_state {
struct s5k4ecgx_platform_data *pdata;
struct v4l2_subdev sd;
struct v4l2_pix_format pix;
struct v4l2_fract timeperframe;
struct s5k4ecgx_jpeg_param jpeg;
struct s5k4ecgx_version fw;
struct s5k4ecgx_version prm;
struct s5k4ecgx_date_info dateinfo;
struct s5k4ecgx_position position;
struct v4l2_streamparm strm;
struct s5k4ecgx_gps_info gps_info;
struct mutex ctrl_lock;
enum s5k4ecgx_runmode runmode;
enum s5k4ecgx_oprmode oprmode;
enum af_operation_status af_status;
int preview_framesize_index;
int capture_framesize_index;
int sensor_version;
int freq; /* MCLK in Hz */
int check_dataline;
int check_previewdata;
bool flash_on;
bool torch_on;
bool sensor_af_in_low_light_mode;
bool flash_state_on_previous_capture;
bool initialized;
bool restore_preview_size_needed;
int one_frame_delay_ms;
const struct s5k4ecgx_regs *regs;
};
static const struct v4l2_mbus_framefmt capture_fmts[] = {
{
.code = V4L2_MBUS_FMT_FIXED,
.colorspace = V4L2_COLORSPACE_JPEG,
},
};
/**
* s5k4ecgx_i2c_read_twobyte: Read 2 bytes from sensor
*/
static int s5k4ecgx_i2c_read_twobyte(struct i2c_client *client,
u16 subaddr, u16 *data)
{
int err;
unsigned char buf[2];
struct i2c_msg msg[2];
cpu_to_be16s(&subaddr);
msg[0].addr = client->addr;
msg[0].flags = 0;
msg[0].len = 2;
msg[0].buf = (u8 *)&subaddr;
msg[1].addr = client->addr;
msg[1].flags = I2C_M_RD;
msg[1].len = 2;
msg[1].buf = buf;
err = i2c_transfer(client->adapter, msg, 2);
if (unlikely(err != 2)) {
dev_err(&client->dev,
"%s: register read fail\n", __func__);
return -EIO;
}
*data = ((buf[0] << 8) | buf[1]);
return 0;
}
/**
* s5k4ecgx_i2c_write_twobyte: Write (I2C) multiple bytes to the camera sensor
* @client: pointer to i2c_client
* @cmd: command register
* @w_data: data to be written
* @w_len: length of data to be written
*
* Returns 0 on success, <0 on error
*/
static int s5k4ecgx_i2c_write_twobyte(struct i2c_client *client,
u16 addr, u16 w_data)
{
int retry_count = 5;
unsigned char buf[4];
struct i2c_msg msg = {client->addr, 0, 4, buf};
int ret = 0;
buf[0] = addr >> 8;
buf[1] = addr;
buf[2] = w_data >> 8;
buf[3] = w_data & 0xff;
s5k4ecgx_debug(S5K4ECGX_DEBUG_I2C, "%s : W(0x%02X%02X%02X%02X)\n",
__func__, buf[0], buf[1], buf[2], buf[3]);
do {
ret = i2c_transfer(client->adapter, &msg, 1);
if (likely(ret == 1))
break;
msleep(POLL_TIME_MS);
dev_err(&client->dev, "%s: I2C err %d, retry %d.\n",
__func__, ret, retry_count);
} while (retry_count-- > 0);
if (ret != 1) {
dev_err(&client->dev, "%s: I2C is not working.\n", __func__);
return -EIO;
}
return 0;
}
static int s5k4ecgx_write_regs(struct v4l2_subdev *sd, const u32 regs[],
int size)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
int i, err;
for (i = 0; i < size; i++) {
err = s5k4ecgx_i2c_write_twobyte(client,
(regs[i] >> 16), regs[i]);
if (unlikely(err != 0)) {
dev_err(&client->dev,
"%s: register write failed\n", __func__);
return err;
}
}
return 0;
}
static int s5k4ecgx_set_from_table(struct v4l2_subdev *sd,
const char *setting_name,
const struct s5k4ecgx_regset_table *table,
int table_size, int index)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
dev_dbg(&client->dev, "%s: set %s index %d\n",
__func__, setting_name, index);
if ((index < 0) || (index >= table_size)) {
dev_err(&client->dev,
"%s: index(%d) out of range[0:%d] for table for %s\n",
__func__, index, table_size, setting_name);
return -EINVAL;
}
table += index;
if (table->reg == NULL)
return -EINVAL;
return s5k4ecgx_write_regs(sd, table->reg, table->array_size);
}
static int s5k4ecgx_set_parameter(struct v4l2_subdev *sd,
int *current_value_ptr,
int new_value,
const char *setting_name,
const struct s5k4ecgx_regset_table *table,
int table_size)
{
int err;
if (*current_value_ptr == new_value)
return 0;
err = s5k4ecgx_set_from_table(sd, setting_name, table,
table_size, new_value);
if (!err)
*current_value_ptr = new_value;
return err;
}
static int s5k4ecgx_set_preview_stop(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING)
state->runmode = S5K4ECGX_RUNMODE_IDLE;
dev_dbg(&client->dev, "%s:\n", __func__);
return 0;
}
static int s5k4ecgx_set_preview_start(struct v4l2_subdev *sd)
{
int err;
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
bool set_size = true;
dev_dbg(&client->dev, "%s: runmode = %d\n",
__func__, state->runmode);
if (!state->pix.width || !state->pix.height ||
!state->strm.parm.capture.timeperframe.denominator)
return -EINVAL;
if (state->runmode == S5K4ECGX_RUNMODE_CAPTURE) {
dev_dbg(&client->dev, "%s: sending Preview_Return cmd\n",
__func__);
err = s5k4ecgx_set_from_table(sd, "preview return",
&state->regs->preview_return, 1, 0);
if (err < 0) {
dev_err(&client->dev,
"%s: failed: s5k4ecgx_Preview_Return\n",
__func__);
return -EIO;
}
set_size = state->restore_preview_size_needed;
}
if (set_size) {
err = s5k4ecgx_set_from_table(sd, "preview_size",
state->regs->preview_size,
ARRAY_SIZE(state->regs->preview_size),
state->preview_framesize_index);
if (err < 0) {
dev_err(&client->dev,
"%s: failed: Could not set preview size\n",
__func__);
return -EIO;
}
}
dev_dbg(&client->dev, "%s: runmode now RUNNING\n", __func__);
state->runmode = S5K4ECGX_RUNMODE_RUNNING;
return 0;
}
static int s5k4ecgx_set_capture_size(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
int err;
dev_dbg(&client->dev, "%s: index:%d\n", __func__,
state->capture_framesize_index);
err = s5k4ecgx_set_from_table(sd, "capture_size",
state->regs->capture_size,
ARRAY_SIZE(state->regs->capture_size),
state->capture_framesize_index);
if (err < 0) {
dev_err(&client->dev,
"%s: failed: i2c_write for capture_size index %d\n",
__func__, state->capture_framesize_index);
}
state->runmode = S5K4ECGX_RUNMODE_CAPTURE;
return err;
}
static int s5k4ecgx_set_jpeg_quality(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
dev_dbg(&client->dev,
"%s: jpeg.quality %d\n", __func__, state->jpeg.quality);
if (state->jpeg.quality < 0)
state->jpeg.quality = 0;
if (state->jpeg.quality > 100)
state->jpeg.quality = 100;
switch (state->jpeg.quality) {
case 90 ... 100:
dev_dbg(&client->dev,
"%s: setting to high jpeg quality\n", __func__);
return s5k4ecgx_set_from_table(sd, "jpeg quality high",
&state->regs->jpeg_quality_high, 1, 0);
case 80 ... 89:
dev_dbg(&client->dev,
"%s: setting to normal jpeg quality\n", __func__);
return s5k4ecgx_set_from_table(sd, "jpeg quality normal",
&state->regs->jpeg_quality_normal, 1, 0);
default:
dev_dbg(&client->dev,
"%s: setting to low jpeg quality\n", __func__);
return s5k4ecgx_set_from_table(sd, "jpeg quality low",
&state->regs->jpeg_quality_low, 1, 0);
}
}
static u16 s5k4ecgx_get_light_level(struct v4l2_subdev *sd)
{
int err;
u16 read_value = 0;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
err = s5k4ecgx_set_from_table(sd, "get light level",
&state->regs->get_light_level, 1, 0);
if (err) {
dev_err(&client->dev,
"%s: write cmd failed, returning 0\n", __func__);
goto out;
}
err = s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
if (err) {
dev_err(&client->dev,
"%s: read cmd failed, returning 0\n", __func__);
goto out;
}
dev_dbg(&client->dev, "%s: read_value = %d (0x%X)\n",
__func__, read_value, read_value);
out:
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
return read_value;
}
static int s5k4ecgx_start_capture(struct v4l2_subdev *sd)
{
int err;
u16 read_value;
u16 light_level;
int poll_time_ms;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
struct s5k4ecgx_platform_data *pdata = client->dev.platform_data;
/* reset cropping if our current preview is not 640x480,
* otherwise the capture will be wrong because of the cropping
*/
if (state->preview_framesize_index != S5K4ECGX_PREVIEW_VGA) {
int err = s5k4ecgx_set_from_table(sd, "reset crop",
&state->regs->reset_crop, 1, 0);
if (err < 0) {
dev_err(&client->dev,
"%s: failed: Could not set preview size\n",
__func__);
return -EIO;
}
state->restore_preview_size_needed = true;
} else
state->restore_preview_size_needed = false;
msleep(50);
light_level = s5k4ecgx_get_light_level(sd);
dev_dbg(&client->dev, "%s: light_level = %d\n", __func__,
light_level);
state->flash_state_on_previous_capture = false;
if (parms->scene_mode != SCENE_MODE_NIGHTSHOT) {
switch (parms->flash_mode) {
case FLASH_MODE_AUTO:
if (light_level > LOW_LIGHT_LEVEL) {
/* light level bright enough
* that we don't need flash
*/
break;
}
/* fall through to flash start */
case FLASH_MODE_ON:
if (parms->focus_mode == FOCUS_MODE_INFINITY) {
s5k4ecgx_set_from_table(sd,
"AF assist flash start",
&state->regs->af_assist_flash_start,
1, 0);
s5k4ecgx_set_from_table(sd,
"AF assist flash end",
&state->regs->af_assist_flash_end,
1, 0);
msleep(10);
}
s5k4ecgx_set_from_table(sd, "flash start",
&state->regs->flash_start, 1, 0);
state->flash_on = true;
state->flash_state_on_previous_capture = true;
pdata->flash_onoff(1);
break;
default:
break;
}
}
/* if light is low, use low light capture settings, EXCEPT
* if scene mode set to NIGHTSHOT or SPORTS because they
* have their own settings (though a low light sport setting
* could be useful)
*/
if ((light_level <= HIGH_LIGHT_LEVEL) &&
(parms->scene_mode != SCENE_MODE_NIGHTSHOT) &&
(parms->scene_mode != SCENE_MODE_SPORTS)) {
s5k4ecgx_set_from_table(sd, "low cap on",
&state->regs->low_cap_on, 1, 0);
}
err = s5k4ecgx_set_capture_size(sd);
if (err < 0) {
dev_err(&client->dev,
"%s: failed: i2c_write for capture_resolution\n",
__func__);
return -EIO;
}
dev_dbg(&client->dev, "%s: send Capture_Start cmd\n", __func__);
s5k4ecgx_set_from_table(sd, "capture start",
&state->regs->capture_start, 1, 0);
/* a shot takes takes at least 50ms so sleep that amount first
* and then start polling for completion.
*/
msleep(50);
/* Enter read mode */
s5k4ecgx_i2c_write_twobyte(client, 0x002C, 0x7000);
poll_time_ms = 50;
do {
s5k4ecgx_set_from_table(sd, "get capture status",
&state->regs->get_capture_status, 1, 0);
s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
dev_dbg(&client->dev,
"%s: s5k4ecgx_Capture_Start check = %#x\n",
__func__, read_value);
if (read_value != 0x00)
break;
msleep(POLL_TIME_MS);
poll_time_ms += POLL_TIME_MS;
} while (poll_time_ms < CAPTURE_POLL_TIME_MS);
dev_dbg(&client->dev, "%s: capture done check finished after %d ms\n",
__func__, poll_time_ms);
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
s5k4ecgx_set_from_table(sd, "ae awb lock off",
&state->regs->ae_awb_lock_off, 1, 0);
if ((light_level <= HIGH_LIGHT_LEVEL) &&
(parms->scene_mode != SCENE_MODE_NIGHTSHOT) &&
(parms->scene_mode != SCENE_MODE_SPORTS)) {
s5k4ecgx_set_from_table(sd, "low cap off",
&state->regs->low_cap_off, 1, 0);
}
if ((parms->scene_mode != SCENE_MODE_NIGHTSHOT) && (state->flash_on)) {
state->flash_on = false;
pdata->flash_onoff(0);
s5k4ecgx_set_from_table(sd, "flash end",
&state->regs->flash_end, 1, 0);
}
return 0;
}
/* wide dynamic range support */
static int s5k4ecgx_set_wdr(struct v4l2_subdev *sd, int value)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
if (value == WDR_ON)
return s5k4ecgx_set_from_table(sd, "wdr on",
&state->regs->wdr_on, 1, 0);
return s5k4ecgx_set_from_table(sd, "wdr off",
&state->regs->wdr_off, 1, 0);
}
static int s5k4ecgx_set_face_detection(struct v4l2_subdev *sd, int value)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
if (value == FACE_DETECTION_ON)
return s5k4ecgx_set_from_table(sd, "face detection on",
&state->regs->face_detection_on, 1, 0);
return s5k4ecgx_set_from_table(sd, "face detection off",
&state->regs->face_detection_off, 1, 0);
}
static int s5k4ecgx_return_focus(struct v4l2_subdev *sd)
{
int err;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
err = s5k4ecgx_set_from_table(sd,
"af normal mode 1",
&state->regs->af_normal_mode_1, 1, 0);
if (err < 0)
goto fail;
msleep(FIRST_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd,
"af normal mode 2",
&state->regs->af_normal_mode_2, 1, 0);
if (err < 0)
goto fail;
msleep(SECOND_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd,
"af normal mode 3",
&state->regs->af_normal_mode_3, 1, 0);
if (err < 0)
goto fail;
return 0;
fail:
dev_err(&client->dev,
"%s: i2c_write failed\n", __func__);
return -EIO;
}
static int s5k4ecgx_set_focus_mode(struct v4l2_subdev *sd, int value)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
int err;
if (parms->focus_mode == value)
return 0;
dev_dbg(&client->dev, "%s value(%d)\n", __func__, value);
switch (value) {
case FOCUS_MODE_MACRO:
dev_dbg(&client->dev,
"%s: FOCUS_MODE_MACRO\n", __func__);
err = s5k4ecgx_set_from_table(sd, "af macro mode 1",
&state->regs->af_macro_mode_1, 1, 0);
if (err < 0)
goto fail;
msleep(FIRST_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd, "af macro mode 2",
&state->regs->af_macro_mode_2, 1, 0);
if (err < 0)
goto fail;
msleep(SECOND_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd, "af macro mode 3",
&state->regs->af_macro_mode_3, 1, 0);
if (err < 0)
goto fail;
parms->focus_mode = FOCUS_MODE_MACRO;
break;
case FOCUS_MODE_INFINITY:
case FOCUS_MODE_AUTO:
err = s5k4ecgx_set_from_table(sd,
"af normal mode 1",
&state->regs->af_normal_mode_1, 1, 0);
if (err < 0)
goto fail;
msleep(FIRST_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd,
"af normal mode 2",
&state->regs->af_normal_mode_2, 1, 0);
if (err < 0)
goto fail;
msleep(SECOND_SETTING_FOCUS_MODE_DELAY_MS);
err = s5k4ecgx_set_from_table(sd,
"af normal mode 3",
&state->regs->af_normal_mode_3, 1, 0);
if (err < 0)
goto fail;
parms->focus_mode = value;
break;
default:
return -EINVAL;
break;
}
return 0;
fail:
dev_err(&client->dev,
"%s: i2c_write failed\n", __func__);
return -EIO;
}
static void s5k4ecgx_auto_focus_flash_start(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct s5k4ecgx_platform_data *pdata = client->dev.platform_data;
int count;
u16 read_value;
s5k4ecgx_set_from_table(sd, "AF assist flash start",
&state->regs->af_assist_flash_start, 1, 0);
state->flash_on = true;
pdata->af_assist_onoff(1);
/* delay 200ms (SLSI value) and then poll to see if AE is stable.
* once it is stable, lock it and then return to do AF
*/
msleep(200);
/* enter read mode */
s5k4ecgx_i2c_write_twobyte(client, 0x002C, 0x7000);
for (count = 0; count < AE_STABLE_SEARCH_COUNT; count++) {
if (state->af_status == AF_CANCEL)
break;
s5k4ecgx_set_from_table(sd, "get ae stable status",
&state->regs->get_ae_stable_status, 1, 0);
s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
dev_dbg(&client->dev, "%s: ae stable status = %#x\n",
__func__, read_value);
if (read_value == 0x1)
break;
msleep(state->one_frame_delay_ms);
}
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
/* if we were cancelled, turn off flash */
if (state->af_status == AF_CANCEL) {
dev_dbg(&client->dev,
"%s: AF cancelled\n", __func__);
s5k4ecgx_set_from_table(sd, "AF assist flash end",
&state->regs->af_assist_flash_end, 1, 0);
state->flash_on = false;
pdata->af_assist_onoff(0);
}
}
static int s5k4ecgx_start_auto_focus(struct v4l2_subdev *sd)
{
int light_level;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
dev_dbg(&client->dev, "%s: start SINGLE AF operation, flash mode %d\n",
__func__, parms->flash_mode);
/* in case user calls auto_focus repeatedly without a cancel
* or a capture, we need to cancel here to allow ae_awb
* to work again, or else we could be locked forever while
* that app is running, which is not the expected behavior.
*/
s5k4ecgx_set_from_table(sd, "ae awb lock off",
&state->regs->ae_awb_lock_off, 1, 0);
if (parms->scene_mode == SCENE_MODE_NIGHTSHOT) {
/* user selected night shot mode, assume we need low light
* af mode. flash is always off in night shot mode
*/
goto enable_af_low_light_mode;
}
light_level = s5k4ecgx_get_light_level(sd);
switch (parms->flash_mode) {
case FLASH_MODE_AUTO:
if (light_level > LOW_LIGHT_LEVEL) {
/* flash not needed */
break;
}
/* fall through to turn on flash for AF assist */
case FLASH_MODE_ON:
s5k4ecgx_auto_focus_flash_start(sd);
if (state->af_status == AF_CANCEL)
return 0;
break;
case FLASH_MODE_OFF:
break;
default:
dev_err(&client->dev,
"%s: Unknown Flash mode 0x%x\n",
__func__, parms->flash_mode);
break;
}
if (light_level > LOW_LIGHT_LEVEL) {
if (state->sensor_af_in_low_light_mode) {
state->sensor_af_in_low_light_mode = false;
s5k4ecgx_set_from_table(sd, "af low light mode off",
&state->regs->af_low_light_mode_off, 1, 0);
}
} else {
enable_af_low_light_mode:
if (!state->sensor_af_in_low_light_mode) {
state->sensor_af_in_low_light_mode = true;
s5k4ecgx_set_from_table(sd, "af low light mode on",
&state->regs->af_low_light_mode_on, 1, 0);
}
}
s5k4ecgx_set_from_table(sd, "single af start",
&state->regs->single_af_start, 1, 0);
state->af_status = AF_INITIAL;
dev_dbg(&client->dev, "%s: af_status set to start\n", __func__);
return 0;
}
/* called by HAL after auto focus was finished.
* it might off the assist flash
*/
static int s5k4ecgx_finish_auto_focus(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
if (state->flash_on) {
struct s5k4ecgx_platform_data *pd = client->dev.platform_data;
s5k4ecgx_set_from_table(sd, "AF assist flash end",
&state->regs->af_assist_flash_end, 1, 0);
state->flash_on = false;
pd->af_assist_onoff(0);
}
dev_dbg(&client->dev, "%s: single AF finished\n", __func__);
state->af_status = AF_NONE;
return 0;
}
static int s5k4ecgx_stop_auto_focus(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
int focus_mode = parms->focus_mode;
dev_dbg(&client->dev, "%s: single AF Off command Setting\n", __func__);
/* always cancel ae_awb, in case AF already finished before
* we got called.
*/
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
s5k4ecgx_set_from_table(sd, "ae awb lock off",
&state->regs->ae_awb_lock_off, 1, 0);
if (state->flash_on)
s5k4ecgx_finish_auto_focus(sd);
if (state->af_status != AF_START) {
/* we weren't in the middle auto focus operation, we're done */
dev_dbg(&client->dev,
"%s: auto focus not in progress, done\n", __func__);
if (focus_mode == FOCUS_MODE_MACRO) {
/* for change focus mode forcely */
parms->focus_mode = -1;
s5k4ecgx_set_focus_mode(sd, FOCUS_MODE_MACRO);
} else if (focus_mode == FOCUS_MODE_AUTO) {
/* for change focus mode forcely */
parms->focus_mode = -1;
s5k4ecgx_set_focus_mode(sd, FOCUS_MODE_AUTO);
}
return 0;
}
/* auto focus was in progress. the other thread
* is either in the middle of s5k4ecgx_get_auto_focus_result_first(),
* s5k4ecgx_get_auto_focus_result_second()
* or will call it shortly. set a flag to have
* it abort it's polling. that thread will
* also do cleanup like restore focus position.
*
* it might be enough to just send sensor commands
* to abort auto focus and the other thread would get
* that state from it's polling calls, but I'm not sure.
*/
state->af_status = AF_CANCEL;
dev_dbg(&client->dev,
"%s: sending Single_AF_Off commands to sensor\n", __func__);
s5k4ecgx_set_from_table(sd, "single af off 1",
&state->regs->single_af_off_1, 1, 0);
msleep(state->one_frame_delay_ms);
s5k4ecgx_set_from_table(sd, "single af off 2",
&state->regs->single_af_off_2, 1, 0);
return 0;
}
/* called by HAL after auto focus was started to get the first search result*/
static int s5k4ecgx_get_auto_focus_result_first(struct v4l2_subdev *sd,
struct v4l2_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
u16 read_value;
if (state->af_status == AF_INITIAL) {
dev_dbg(&client->dev, "%s: Check AF Result\n", __func__);
if (state->af_status == AF_NONE) {
dev_dbg(&client->dev,
"%s: auto focus never started, returning 0x2\n",
__func__);
ctrl->value = AUTO_FOCUS_CANCELLED;
return 0;
}
/* must delay 2 frame times before checking result of 1st phase */
mutex_unlock(&state->ctrl_lock);
msleep(state->one_frame_delay_ms*2);
mutex_lock(&state->ctrl_lock);
/* lock AE and AWB after first AF search */
s5k4ecgx_set_from_table(sd, "ae awb lock on",
&state->regs->ae_awb_lock_on, 1, 0);
dev_dbg(&client->dev, "%s: 1st AF search\n", __func__);
/* enter read mode */
s5k4ecgx_i2c_write_twobyte(client, 0x002C, 0x7000);
state->af_status = AF_START;
} else if (state->af_status == AF_CANCEL) {
dev_dbg(&client->dev,
"%s: AF is cancelled while doing\n", __func__);
ctrl->value = AUTO_FOCUS_CANCELLED;
s5k4ecgx_finish_auto_focus(sd);
return 0;
}
s5k4ecgx_set_from_table(sd, "get 1st af search status",
&state->regs->get_1st_af_search_status,
1, 0);
s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
dev_dbg(&client->dev,
"%s: 1st i2c_read --- read_value == 0x%x\n",
__func__, read_value);
ctrl->value = read_value;
return 0;
}
/* called by HAL after first search was succeed to get the second search result*/
static int s5k4ecgx_get_auto_focus_result_second(struct v4l2_subdev *sd,
struct v4l2_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
u16 read_value;
if (state->af_status == AF_CANCEL) {
dev_dbg(&client->dev,
"%s: AF is cancelled while doing\n", __func__);
ctrl->value = AUTO_FOCUS_CANCELLED;
s5k4ecgx_finish_auto_focus(sd);
return 0;
}
s5k4ecgx_set_from_table(sd, "get 2nd af search status",
&state->regs->get_2nd_af_search_status,
1, 0);
s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
dev_dbg(&client->dev,
"%s: 2nd i2c_read --- read_value == 0x%x\n",
__func__, read_value);
ctrl->value = read_value;
return 0;
}
static void s5k4ecgx_init_parameters(struct v4l2_subdev *sd)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
state->strm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
parms->capture.capturemode = 0;
parms->capture.timeperframe.numerator = 1;
parms->capture.timeperframe.denominator = 30;
parms->contrast = CONTRAST_DEFAULT;
parms->effects = IMAGE_EFFECT_NONE;
parms->brightness = EV_DEFAULT;
parms->flash_mode = FLASH_MODE_AUTO;
parms->focus_mode = FOCUS_MODE_AUTO;
parms->iso = ISO_AUTO;
parms->metering = METERING_CENTER;
parms->saturation = SATURATION_DEFAULT;
parms->scene_mode = SCENE_MODE_NONE;
parms->sharpness = SHARPNESS_DEFAULT;
parms->white_balance = WHITE_BALANCE_AUTO;
state->jpeg.enable = 0;
state->jpeg.quality = 100;
state->jpeg.main_offset = 0;
state->jpeg.main_size = 0;
state->jpeg.thumb_offset = 0;
state->jpeg.thumb_size = 0;
state->jpeg.postview_offset = 0;
state->fw.major = 1;
state->one_frame_delay_ms = NORMAL_MODE_MAX_ONE_FRAME_DELAY_MS;
}
static void s5k4ecgx_set_framesize(struct v4l2_subdev *sd,
const struct s5k4ecgx_framesize *frmsize,
int frmsize_count, bool exact_match);
static int s5k4ecgx_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
dev_dbg(&client->dev, "%s: code = 0x%x, field = 0x%x,"
" colorspace = 0x%x, width = %d, height = %d\n",
__func__, fmt->code, fmt->field,
fmt->colorspace,
fmt->width, fmt->height);
if (fmt->code == V4L2_MBUS_FMT_FIXED &&
fmt->colorspace != V4L2_COLORSPACE_JPEG) {
dev_err(&client->dev,
"%s: mismatch in pixelformat and colorspace\n",
__func__);
return -EINVAL;
}
state->pix.width = fmt->width;
state->pix.height = fmt->height;
if (fmt->colorspace == V4L2_COLORSPACE_JPEG)
state->pix.pixelformat = V4L2_PIX_FMT_JPEG;
else
state->pix.pixelformat = 0; /* is this used anywhere? */
if (fmt->colorspace == V4L2_COLORSPACE_JPEG) {
state->oprmode = S5K4ECGX_OPRMODE_IMAGE;
/*
* In case of image capture mode,
* if the given image resolution is not supported,
* use the next higher image resolution. */
s5k4ecgx_set_framesize(sd, s5k4ecgx_capture_framesize_list,
ARRAY_SIZE(s5k4ecgx_capture_framesize_list),
false);
} else {
state->oprmode = S5K4ECGX_OPRMODE_VIDEO;
/*
* In case of video mode,
* if the given video resolution is not matching, use
* the default rate (currently S5K4ECGX_PREVIEW_WVGA).
*/
s5k4ecgx_set_framesize(sd, s5k4ecgx_preview_framesize_list,
ARRAY_SIZE(s5k4ecgx_preview_framesize_list),
true);
}
state->jpeg.enable = state->pix.pixelformat == V4L2_PIX_FMT_JPEG;
return 0;
}
static int s5k4ecgx_enum_framesizes(struct v4l2_subdev *sd,
struct v4l2_frmsizeenum *fsize)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
/* The camera interface should read this value, this is the resolution
* at which the sensor would provide framedata to the camera i/f
*
* In case of image capture,
* this returns the default camera resolution (SVGA)
*/
fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
fsize->discrete.width = state->pix.width;
fsize->discrete.height = state->pix.height;
return 0;
}
static int s5k4ecgx_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
enum v4l2_mbus_pixelcode *code)
{
pr_debug("%s: index = %d\n", __func__, index);
if (index >= ARRAY_SIZE(capture_fmts))
return -EINVAL;
*code = capture_fmts[index].code;
return 0;
}
static int s5k4ecgx_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt)
{
int num_entries;
int i;
num_entries = ARRAY_SIZE(capture_fmts);
pr_debug("%s: code = 0x%x, colorspace = 0x%x, num_entries = %d\n",
__func__, fmt->code, fmt->colorspace, num_entries);
for (i = 0; i < num_entries; i++) {
if (capture_fmts[i].code == fmt->code &&
capture_fmts[i].colorspace == fmt->colorspace) {
pr_debug("%s: match found, returning 0\n", __func__);
return 0;
}
}
pr_debug("%s: no match found, returning -EINVAL\n", __func__);
return -EINVAL;
}
static void s5k4ecgx_enable_torch(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct s5k4ecgx_platform_data *pdata = client->dev.platform_data;
s5k4ecgx_set_from_table(sd, "torch start",
&state->regs->flash_start, 1, 0);
state->torch_on = true;
pdata->torch_onoff(1);
}
static void s5k4ecgx_disable_torch(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct s5k4ecgx_platform_data *pdata = client->dev.platform_data;
if (state->torch_on) {
state->torch_on = false;
pdata->torch_onoff(0);
s5k4ecgx_set_from_table(sd, "torch end",
&state->regs->flash_end, 1, 0);
}
}
static int s5k4ecgx_set_flash_mode(struct v4l2_subdev *sd, int value)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
if (parms->flash_mode == value)
return 0;
if ((value >= FLASH_MODE_OFF) && (value <= FLASH_MODE_TORCH)) {
pr_debug("%s: setting flash mode to %d\n",
__func__, value);
parms->flash_mode = value;
if (parms->flash_mode == FLASH_MODE_TORCH)
s5k4ecgx_enable_torch(sd);
else
s5k4ecgx_disable_torch(sd);
return 0;
}
pr_debug("%s: trying to set invalid flash mode %d\n",
__func__, value);
return -EINVAL;
}
static int s5k4ecgx_g_parm(struct v4l2_subdev *sd,
struct v4l2_streamparm *param)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
memcpy(param, &state->strm, sizeof(param));
return 0;
}
static int s5k4ecgx_s_parm(struct v4l2_subdev *sd,
struct v4l2_streamparm *param)
{
int err = 0;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *new_parms =
(struct sec_cam_parm *)¶m->parm.raw_data;
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
dev_dbg(&client->dev, "%s: start\n", __func__);
if (param->parm.capture.timeperframe.numerator !=
parms->capture.timeperframe.numerator ||
param->parm.capture.timeperframe.denominator !=
parms->capture.timeperframe.denominator) {
int fps = 0;
int fps_max = 30;
if (param->parm.capture.timeperframe.numerator &&
param->parm.capture.timeperframe.denominator)
fps =
(int)(param->parm.capture.timeperframe.denominator /
param->parm.capture.timeperframe.numerator);
else
fps = 0;
if (fps <= 0 || fps > fps_max) {
dev_err(&client->dev,
"%s: Framerate %d not supported,"
" setting it to %d fps.\n",
__func__, fps, fps_max);
fps = fps_max;
}
/*
* Don't set the fps value, just update it in the state
* We will set the resolution and
* fps in the start operation (preview/capture) call
*/
parms->capture.timeperframe.numerator = 1;
parms->capture.timeperframe.denominator = fps;
}
/* we return an error if one happened but don't stop trying to
* set all parameters passed
*/
err = s5k4ecgx_set_parameter(sd, &parms->contrast, new_parms->contrast,
"contrast", state->regs->contrast,
ARRAY_SIZE(state->regs->contrast));
err |= s5k4ecgx_set_parameter(sd, &parms->effects, new_parms->effects,
"effect", state->regs->effect,
ARRAY_SIZE(state->regs->effect));
err |= s5k4ecgx_set_parameter(sd, &parms->brightness,
new_parms->brightness, "brightness",
state->regs->ev, ARRAY_SIZE(state->regs->ev));
err |= s5k4ecgx_set_flash_mode(sd, new_parms->flash_mode);
/* Must delay 150ms before setting macro mode due to a camera
* sensor requirement */
if ((new_parms->focus_mode == FOCUS_MODE_MACRO) &&
(parms->focus_mode != FOCUS_MODE_MACRO))
msleep(150);
err |= s5k4ecgx_set_focus_mode(sd, new_parms->focus_mode);
err |= s5k4ecgx_set_parameter(sd, &parms->iso, new_parms->iso,
"iso", state->regs->iso,
ARRAY_SIZE(state->regs->iso));
err |= s5k4ecgx_set_parameter(sd, &parms->metering, new_parms->metering,
"metering", state->regs->metering,
ARRAY_SIZE(state->regs->metering));
err |= s5k4ecgx_set_parameter(sd, &parms->saturation,
new_parms->saturation, "saturation",
state->regs->saturation,
ARRAY_SIZE(state->regs->saturation));
err |= s5k4ecgx_set_parameter(sd, &parms->scene_mode,
new_parms->scene_mode, "scene_mode",
state->regs->scene_mode,
ARRAY_SIZE(state->regs->scene_mode));
err |= s5k4ecgx_set_parameter(sd, &parms->sharpness,
new_parms->sharpness, "sharpness",
state->regs->sharpness,
ARRAY_SIZE(state->regs->sharpness));
err |= s5k4ecgx_set_parameter(sd, &parms->white_balance,
new_parms->white_balance, "white balance",
state->regs->white_balance,
ARRAY_SIZE(state->regs->white_balance));
err |= s5k4ecgx_set_parameter(sd, &parms->fps,
new_parms->fps, "fps",
state->regs->fps,
ARRAY_SIZE(state->regs->fps));
if (parms->scene_mode == SCENE_MODE_NIGHTSHOT)
state->one_frame_delay_ms = NIGHT_MODE_MAX_ONE_FRAME_DELAY_MS;
else
state->one_frame_delay_ms = NORMAL_MODE_MAX_ONE_FRAME_DELAY_MS;
dev_dbg(&client->dev, "%s: returning %d\n", __func__, err);
return err;
}
/* This function is called from the g_ctrl api
*
* This function should be called only after the s_fmt call,
* which sets the required width/height value.
*
* It checks a list of available frame sizes and sets the
* most appropriate frame size.
*
* The list is stored in an increasing order (as far as possible).
* Hence the first entry (searching from the beginning) where both the
* width and height is more than the required value is returned.
* In case of no perfect match, we set the last entry (which is supposed
* to be the largest resolution supported.)
*/
static void s5k4ecgx_set_framesize(struct v4l2_subdev *sd,
const struct s5k4ecgx_framesize *frmsize,
int frmsize_count, bool preview)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
const struct s5k4ecgx_framesize *last_frmsize =
&frmsize[frmsize_count - 1];
dev_dbg(&client->dev, "%s: Requested Res: %dx%d\n", __func__,
state->pix.width, state->pix.height);
do {
/*
* In case of image capture mode,
* if the given image resolution is not supported,
* return the next higher image resolution. */
if (preview) {
if (frmsize->width == state->pix.width &&
frmsize->height == state->pix.height) {
break;
}
} else {
dev_dbg(&client->dev,
"%s: compare frmsize %dx%d to %dx%d\n",
__func__,
frmsize->width, frmsize->height,
state->pix.width, state->pix.height);
if (frmsize->width >= state->pix.width &&
frmsize->height >= state->pix.height) {
dev_dbg(&client->dev,
"%s: select frmsize %dx%d, index=%d\n",
__func__,
frmsize->width, frmsize->height,
frmsize->index);
break;
}
}
frmsize++;
} while (frmsize <= last_frmsize);
if (frmsize > last_frmsize)
frmsize = last_frmsize;
state->pix.width = frmsize->width;
state->pix.height = frmsize->height;
if (preview) {
state->preview_framesize_index = frmsize->index;
dev_dbg(&client->dev, "%s: Preview Res Set: %dx%d, index %d\n",
__func__, state->pix.width, state->pix.height,
state->preview_framesize_index);
} else {
state->capture_framesize_index = frmsize->index;
dev_dbg(&client->dev, "%s: Capture Res Set: %dx%d, index %d\n",
__func__, state->pix.width, state->pix.height,
state->capture_framesize_index);
}
}
static int s5k4ecgx_check_dataline_stop(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
int err;
dev_dbg(&client->dev, "%s\n", __func__);
err = s5k4ecgx_set_from_table(sd, "DTP stop",
&state->regs->dtp_stop, 1, 0);
if (err < 0) {
v4l_info(client, "%s: register set failed\n", __func__);
return -EIO;
}
state->check_dataline = 0;
return err;
}
static void s5k4ecgx_get_esd_int(struct v4l2_subdev *sd,
struct v4l2_control *ctrl)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
u16 read_value;
int err;
if ((S5K4ECGX_RUNMODE_RUNNING == state->runmode) &&
(state->af_status != AF_START)) {
err = s5k4ecgx_set_from_table(sd, "get esd status",
&state->regs->get_esd_status,
1, 0);
err |= s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
dev_dbg(&client->dev,
"%s: read_value == 0x%x\n", __func__, read_value);
/* return to write mode */
err |= s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
if (err < 0) {
v4l_info(client,
"Failed I2C for getting ESD information\n");
ctrl->value = 0x01;
} else {
if (read_value != 0x0000) {
v4l_info(client, "ESD interrupt happened!!\n");
ctrl->value = 0x01;
} else {
dev_dbg(&client->dev,
"%s: No ESD interrupt!!\n", __func__);
ctrl->value = 0x00;
}
}
} else
ctrl->value = 0x00;
}
/* returns the real iso currently used by sensor due to lighting
* conditions, not the requested iso we sent using s_ctrl.
*/
static int s5k4ecgx_get_iso(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
int err;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
u16 read_value1 = 0;
u16 read_value2 = 0;
int read_value;
err = s5k4ecgx_set_from_table(sd, "get iso",
&state->regs->get_iso, 1, 0);
err |= s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value1);
err |= s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value2);
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
read_value = read_value1 * read_value2 / 384;
if (read_value > 0x400)
ctrl->value = ISO_400;
else if (read_value > 0x200)
ctrl->value = ISO_200;
else if (read_value > 0x100)
ctrl->value = ISO_100;
else
ctrl->value = ISO_50;
dev_dbg(&client->dev, "%s: get iso == %d (0x%x, 0x%x)\n",
__func__, ctrl->value, read_value1, read_value2);
return err;
}
static int s5k4ecgx_get_shutterspeed(struct v4l2_subdev *sd,
struct v4l2_control *ctrl)
{
int err;
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
u16 read_value_1;
u16 read_value_2;
u32 read_value;
err = s5k4ecgx_set_from_table(sd, "get shutterspeed",
&state->regs->get_shutterspeed, 1, 0);
err |= s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value_1);
err |= s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value_2);
read_value = (read_value_2 << 16) | (read_value_1 & 0xffff);
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
ctrl->value = read_value * 1000 / 400;
dev_dbg(&client->dev,
"%s: get shutterspeed == %d\n", __func__, ctrl->value);
return err;
}
static int s5k4ecgx_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
int err = 0;
if (!state->initialized) {
dev_err(&client->dev,
"%s: return error because uninitialized\n", __func__);
return -ENODEV;
}
mutex_lock(&state->ctrl_lock);
switch (ctrl->id) {
case V4L2_CID_CAMERA_WHITE_BALANCE:
ctrl->value = parms->white_balance;
break;
case V4L2_CID_CAMERA_EFFECT:
ctrl->value = parms->effects;
break;
case V4L2_CID_CAMERA_CONTRAST:
ctrl->value = parms->contrast;
break;
case V4L2_CID_CAMERA_SATURATION:
ctrl->value = parms->saturation;
break;
case V4L2_CID_CAMERA_SHARPNESS:
ctrl->value = parms->sharpness;
break;
case V4L2_CID_CAM_JPEG_MAIN_SIZE:
ctrl->value = state->jpeg.main_size;
break;
case V4L2_CID_CAM_JPEG_MAIN_OFFSET:
ctrl->value = state->jpeg.main_offset;
break;
case V4L2_CID_CAM_JPEG_THUMB_SIZE:
ctrl->value = state->jpeg.thumb_size;
break;
case V4L2_CID_CAM_JPEG_THUMB_OFFSET:
ctrl->value = state->jpeg.thumb_offset;
break;
case V4L2_CID_CAM_JPEG_POSTVIEW_OFFSET:
ctrl->value = state->jpeg.postview_offset;
break;
case V4L2_CID_CAM_JPEG_MEMSIZE:
ctrl->value = SENSOR_JPEG_SNAPSHOT_MEMSIZE;
break;
case V4L2_CID_CAM_JPEG_QUALITY:
ctrl->value = state->jpeg.quality;
break;
case V4L2_CID_CAMERA_AUTO_FOCUS_RESULT_FIRST:
err = s5k4ecgx_get_auto_focus_result_first(sd, ctrl);
break;
case V4L2_CID_CAMERA_AUTO_FOCUS_RESULT_SECOND:
err = s5k4ecgx_get_auto_focus_result_second(sd, ctrl);
break;
case V4L2_CID_CAM_DATE_INFO_YEAR:
ctrl->value = 2010;
break;
case V4L2_CID_CAM_DATE_INFO_MONTH:
ctrl->value = 2;
break;
case V4L2_CID_CAM_DATE_INFO_DATE:
ctrl->value = 25;
break;
case V4L2_CID_CAM_SENSOR_VER:
ctrl->value = 1;
break;
case V4L2_CID_CAM_FW_MINOR_VER:
ctrl->value = state->fw.minor;
break;
case V4L2_CID_CAM_FW_MAJOR_VER:
ctrl->value = state->fw.major;
break;
case V4L2_CID_CAM_PRM_MINOR_VER:
ctrl->value = state->prm.minor;
break;
case V4L2_CID_CAM_PRM_MAJOR_VER:
ctrl->value = state->prm.major;
break;
case V4L2_CID_ESD_INT:
s5k4ecgx_get_esd_int(sd, ctrl);
break;
case V4L2_CID_CAMERA_GET_ISO:
err = s5k4ecgx_get_iso(sd, ctrl);
break;
case V4L2_CID_CAMERA_GET_SHT_TIME:
err = s5k4ecgx_get_shutterspeed(sd, ctrl);
break;
case V4L2_CID_CAMERA_GET_FLASH_ONOFF:
ctrl->value = state->flash_state_on_previous_capture;
break;
case V4L2_CID_CAMERA_OBJ_TRACKING_STATUS:
case V4L2_CID_CAMERA_SMART_AUTO_STATUS:
break;
default:
err = -ENOIOCTLCMD;
dev_err(&client->dev, "%s: unknown ctrl id 0x%x\n",
__func__, ctrl->id);
break;
}
mutex_unlock(&state->ctrl_lock);
return err;
}
static int s5k4ecgx_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct sec_cam_parm *parms =
(struct sec_cam_parm *)&state->strm.parm.raw_data;
int err = 0;
int value = ctrl->value;
if (!state->initialized &&
(ctrl->id != V4L2_CID_CAMERA_CHECK_DATALINE)) {
dev_err(&client->dev,
"%s: return error because uninitialized\n", __func__);
return -ENODEV;
}
dev_dbg(&client->dev, "%s: V4l2 control ID =%d, val = %d\n",
__func__, ctrl->id - V4L2_CID_PRIVATE_BASE, value);
mutex_lock(&state->ctrl_lock);
switch (ctrl->id) {
case V4L2_CID_CAMERA_FLASH_MODE:
err = s5k4ecgx_set_flash_mode(sd, value);
break;
case V4L2_CID_CAMERA_BRIGHTNESS:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
err = s5k4ecgx_set_parameter(sd, &parms->brightness,
value, "brightness",
state->regs->ev,
ARRAY_SIZE(state->regs->ev));
} else {
dev_err(&client->dev,
"%s: trying to set brightness when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_WHITE_BALANCE:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
err = s5k4ecgx_set_parameter(sd, &parms->white_balance,
value, "white balance",
state->regs->white_balance,
ARRAY_SIZE(state->regs->white_balance));
} else {
dev_err(&client->dev,
"%s: trying to set white balance when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_EFFECT:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
err = s5k4ecgx_set_parameter(sd, &parms->effects,
value, "effects", state->regs->effect,
ARRAY_SIZE(state->regs->effect));
} else {
dev_err(&client->dev,
"%s: trying to set effect when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_ISO:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
err = s5k4ecgx_set_parameter(sd, &parms->iso,
value, "iso",
state->regs->iso,
ARRAY_SIZE(state->regs->iso));
} else {
dev_err(&client->dev,
"%s: trying to set iso when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_METERING:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
err = s5k4ecgx_set_parameter(sd, &parms->metering,
value, "metering",
state->regs->metering,
ARRAY_SIZE(state->regs->metering));
} else {
dev_err(&client->dev,
"%s: trying to set metering when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_CONTRAST:
err = s5k4ecgx_set_parameter(sd, &parms->contrast,
value, "contrast",
state->regs->contrast,
ARRAY_SIZE(state->regs->contrast));
break;
case V4L2_CID_CAMERA_SATURATION:
err = s5k4ecgx_set_parameter(sd, &parms->saturation,
value, "saturation",
state->regs->saturation,
ARRAY_SIZE(state->regs->saturation));
break;
case V4L2_CID_CAMERA_SHARPNESS:
err = s5k4ecgx_set_parameter(sd, &parms->sharpness,
value, "sharpness",
state->regs->sharpness,
ARRAY_SIZE(state->regs->sharpness));
break;
case V4L2_CID_CAMERA_WDR:
err = s5k4ecgx_set_wdr(sd, value);
break;
case V4L2_CID_CAMERA_FACE_DETECTION:
err = s5k4ecgx_set_face_detection(sd, value);
break;
case V4L2_CID_CAMERA_FOCUS_MODE:
err = s5k4ecgx_set_focus_mode(sd, value);
break;
case V4L2_CID_CAM_JPEG_QUALITY:
if (state->runmode == S5K4ECGX_RUNMODE_RUNNING) {
state->jpeg.quality = value;
err = s5k4ecgx_set_jpeg_quality(sd);
} else {
dev_err(&client->dev,
"%s: trying to set jpeg quality when not "
"in preview mode\n",
__func__);
err = -EINVAL;
}
break;
case V4L2_CID_CAMERA_SCENE_MODE:
err = s5k4ecgx_set_parameter(sd, &parms->scene_mode,
SCENE_MODE_NONE, "scene_mode",
state->regs->scene_mode,
ARRAY_SIZE(state->regs->scene_mode));
if (err < 0) {
dev_err(&client->dev,
"%s: failed to set scene-mode default value\n",
__func__);
break;
}
if (value != SCENE_MODE_NONE) {
err = s5k4ecgx_set_parameter(sd, &parms->scene_mode,
value, "scene_mode",
state->regs->scene_mode,
ARRAY_SIZE(state->regs->scene_mode));
}
if (parms->scene_mode == SCENE_MODE_NIGHTSHOT) {
state->one_frame_delay_ms =
NIGHT_MODE_MAX_ONE_FRAME_DELAY_MS;
} else {
state->one_frame_delay_ms =
NORMAL_MODE_MAX_ONE_FRAME_DELAY_MS;
}
break;
case V4L2_CID_CAMERA_GPS_LATITUDE:
dev_err(&client->dev,
"%s: V4L2_CID_CAMERA_GPS_LATITUDE: not implemented\n",
__func__);
break;
case V4L2_CID_CAMERA_GPS_LONGITUDE:
dev_err(&client->dev,
"%s: V4L2_CID_CAMERA_GPS_LONGITUDE: not implemented\n",
__func__);
break;
case V4L2_CID_CAMERA_GPS_TIMESTAMP:
dev_err(&client->dev,
"%s: V4L2_CID_CAMERA_GPS_TIMESTAMP: not implemented\n",
__func__);
break;
case V4L2_CID_CAMERA_GPS_ALTITUDE:
dev_err(&client->dev,
"%s: V4L2_CID_CAMERA_GPS_ALTITUDE: not implemented\n",
__func__);
break;
case V4L2_CID_CAMERA_OBJECT_POSITION_X:
state->position.x = value;
break;
case V4L2_CID_CAMERA_OBJECT_POSITION_Y:
state->position.y = value;
break;
case V4L2_CID_CAMERA_SET_AUTO_FOCUS:
if (value == AUTO_FOCUS_ON)
err = s5k4ecgx_start_auto_focus(sd);
else if (value == AUTO_FOCUS_OFF)
err = s5k4ecgx_stop_auto_focus(sd);
else {
err = -EINVAL;
dev_err(&client->dev,
"%s: bad focus value requestion %d\n",
__func__, value);
}
break;
case V4L2_CID_CAMERA_FRAME_RATE:
dev_dbg(&client->dev,
"%s: camera frame rate request for %d fps\n",
__func__, value);
err = s5k4ecgx_set_parameter(sd, &parms->fps,
value, "fps",
state->regs->fps,
ARRAY_SIZE(state->regs->fps));
break;
case V4L2_CID_CAM_CAPTURE:
err = s5k4ecgx_start_capture(sd);
break;
/* Used to start / stop preview operation.
* This call can be modified to START/STOP operation,
* which can be used in image capture also
*/
case V4L2_CID_CAM_PREVIEW_ONOFF:
if (value)
err = s5k4ecgx_set_preview_start(sd);
else
err = s5k4ecgx_set_preview_stop(sd);
break;
case V4L2_CID_CAMERA_CHECK_DATALINE:
dev_dbg(&client->dev, "%s: check_dataline set to %d\n",
__func__, value);
state->check_dataline = value;
break;
case V4L2_CID_CAMERA_CHECK_DATALINE_STOP:
err = s5k4ecgx_check_dataline_stop(sd);
break;
case V4L2_CID_CAMERA_RETURN_FOCUS:
if (parms->focus_mode != FOCUS_MODE_MACRO)
err = s5k4ecgx_return_focus(sd);
break;
case V4L2_CID_CAMERA_FINISH_AUTO_FOCUS:
err = s5k4ecgx_finish_auto_focus(sd);
break;
default:
dev_err(&client->dev, "%s: unknown set ctrl id 0x%x\n",
__func__, ctrl->id);
err = -ENOIOCTLCMD;
break;
}
if (err < 0)
dev_err(&client->dev, "%s: videoc_s_ctrl failed %d\n", __func__,
err);
mutex_unlock(&state->ctrl_lock);
dev_dbg(&client->dev, "%s: videoc_s_ctrl returning %d\n",
__func__, err);
return err;
}
static int s5k4ecgx_s_ext_ctrl(struct v4l2_subdev *sd,
struct v4l2_ext_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
int err = 0;
struct gps_info_common *tempGPSType = NULL;
switch (ctrl->id) {
case V4L2_CID_CAMERA_GPS_LATITUDE:
tempGPSType = (struct gps_info_common *)ctrl->reserved2[1];
state->gps_info.gps_buf[0] = tempGPSType->direction;
state->gps_info.gps_buf[1] = tempGPSType->dgree;
state->gps_info.gps_buf[2] = tempGPSType->minute;
state->gps_info.gps_buf[3] = tempGPSType->second;
break;
case V4L2_CID_CAMERA_GPS_LONGITUDE:
tempGPSType = (struct gps_info_common *)ctrl->reserved2[1];
state->gps_info.gps_buf[4] = tempGPSType->direction;
state->gps_info.gps_buf[5] = tempGPSType->dgree;
state->gps_info.gps_buf[6] = tempGPSType->minute;
state->gps_info.gps_buf[7] = tempGPSType->second;
break;
case V4L2_CID_CAMERA_GPS_ALTITUDE:
tempGPSType = (struct gps_info_common *)ctrl->reserved2[1];
state->gps_info.altitude_buf[0] = tempGPSType->direction;
state->gps_info.altitude_buf[1] =
(tempGPSType->dgree) & 0x00ff;
state->gps_info.altitude_buf[2] =
((tempGPSType->dgree) & 0xff00) >> 8;
state->gps_info.altitude_buf[3] = tempGPSType->minute;
break;
case V4L2_CID_CAMERA_GPS_TIMESTAMP:
state->gps_info.gps_timeStamp = *((int *)ctrl->reserved2[1]);
err = 0;
break;
default:
dev_err(&client->dev, "%s: unknown ctrl->id %d\n",
__func__, ctrl->id);
err = -ENOIOCTLCMD;
break;
}
if (err < 0)
dev_err(&client->dev, "%s: vidioc_s_ext_ctrl failed %d\n",
__func__, err);
return err;
}
static int s5k4ecgx_s_ext_ctrls(struct v4l2_subdev *sd,
struct v4l2_ext_controls *ctrls)
{
struct v4l2_ext_control *ctrl = ctrls->controls;
int ret;
int i;
for (i = 0; i < ctrls->count; i++, ctrl++) {
ret = s5k4ecgx_s_ext_ctrl(sd, ctrl);
if (ret) {
ctrls->error_idx = i;
break;
}
}
return ret;
}
#ifdef CONFIG_VIDEO_S5K4ECGX_DEBUG
static void s5k4ecgx_dump_regset(struct s5k4ecgx_regset *regset)
{
if ((regset->data[0] == 0x00) && (regset->data[1] == 0x2A)) {
if (regset->size <= 6)
pr_err("odd regset size %d\n", regset->size);
pr_info("regset: addr = 0x%02X%02X, data[0,1] = 0x%02X%02X,"
" total data size = %d\n",
regset->data[2], regset->data[3],
regset->data[6], regset->data[7],
regset->size-6);
} else {
pr_info("regset: 0x%02X%02X%02X%02X\n",
regset->data[0], regset->data[1],
regset->data[2], regset->data[3]);
if (regset->size != 4)
pr_err("odd regset size %d\n", regset->size);
}
}
#endif
static int s5k4ecgx_i2c_write_block(struct v4l2_subdev *sd, u8 *buf, int size)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
int retry_count = 5;
int ret;
struct i2c_msg msg = {client->addr, 0, size, buf};
#ifdef CONFIG_VIDEO_S5K4ECGX_DEBUG
if (s5k4ecgx_debug_mask & S5K4ECGX_DEBUG_I2C_BURSTS) {
if ((buf[0] == 0x0F) && (buf[1] == 0x12))
pr_info("%s : data[0,1] = 0x%02X%02X,"
" total data size = %d\n",
__func__, buf[2], buf[3], size-2);
else
pr_info("%s : 0x%02X%02X%02X%02X\n",
__func__, buf[0], buf[1], buf[2], buf[3]);
}
#endif
do {
ret = i2c_transfer(client->adapter, &msg, 1);
if (likely(ret == 1))
break;
msleep(POLL_TIME_MS);
} while (retry_count-- > 0);
if (ret != 1) {
dev_err(&client->dev, "%s: I2C is not working.\n", __func__);
return -EIO;
}
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_0
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
if (state->fw.minor == 0) {
/* v1.0 sensor have problems sometimes if we write
* too much data too fast, so add a sleep. I've
* tried various combinations of size/delay. Checking
* for a larger size doesn't seem to work reliably, and
* a delay of 1ms sometimes isn't enough either.
*/
if (size > 16)
msleep(2);
}
}
#endif
return 0;
}
/*
* Parse the init_reg2 array into a number of register sets that
* we can send over as i2c burst writes instead of writing each
* entry of init_reg2 as a single 4 byte write. Write the
* new data structures and then free them.
*/
static int s5k4ecgx_write_init_reg2_burst(struct v4l2_subdev *sd)
{
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
struct s5k4ecgx_regset *regset_table;
struct s5k4ecgx_regset *regset;
struct s5k4ecgx_regset *end_regset;
u8 *regset_data;
u8 *dst_ptr;
const u32 *end_src_ptr;
bool flag_copied;
int init_reg_2_array_size = state->regs->init_reg_2.array_size;
int init_reg_2_size = init_reg_2_array_size * sizeof(u32);
const u32 *src_ptr = state->regs->init_reg_2.reg;
u32 src_value;
int err;
pr_debug("%s : start\n", __func__);
regset_data = vmalloc(init_reg_2_size);
if (regset_data == NULL)
return -ENOMEM;
regset_table = vmalloc(sizeof(struct s5k4ecgx_regset) *
init_reg_2_size);
if (regset_table == NULL) {
kfree(regset_data);
return -ENOMEM;
}
dst_ptr = regset_data;
regset = regset_table;
end_src_ptr = &state->regs->init_reg_2.reg[init_reg_2_array_size];
src_value = *src_ptr++;
while (src_ptr <= end_src_ptr) {
/* initial value for a regset */
regset->data = dst_ptr;
flag_copied = false;
*dst_ptr++ = src_value >> 24;
*dst_ptr++ = src_value >> 16;
*dst_ptr++ = src_value >> 8;
*dst_ptr++ = src_value;
/* check subsequent values for a data flag (starts with
0x0F12) or something else */
do {
src_value = *src_ptr++;
if ((src_value & 0xFFFF0000) != 0x0F120000) {
/* src_value is start of next regset */
regset->size = dst_ptr - regset->data;
regset++;
break;
}
/* copy the 0x0F12 flag if not done already */
if (!flag_copied) {
*dst_ptr++ = src_value >> 24;
*dst_ptr++ = src_value >> 16;
flag_copied = true;
}
/* copy the data part */
*dst_ptr++ = src_value >> 8;
*dst_ptr++ = src_value;
} while (src_ptr < end_src_ptr);
}
pr_debug("%s : finished creating table\n", __func__);
end_regset = regset;
pr_debug("%s : first regset = %p, last regset = %p, count = %d\n",
__func__, regset_table, regset, end_regset - regset_table);
pr_debug("%s : regset_data = %p, end = %p, dst_ptr = %p\n", __func__,
regset_data, regset_data + (init_reg_2_size * sizeof(u32)),
dst_ptr);
#ifdef CONFIG_VIDEO_S5K4ECGX_DEBUG
if (s5k4ecgx_debug_mask & S5K4ECGX_DEBUG_I2C_BURSTS) {
int last_regset_end_addr = 0;
regset = regset_table;
do {
s5k4ecgx_dump_regset(regset);
if (regset->size > 4) {
int regset_addr = (regset->data[2] << 8 |
regset->data[3]);
if (last_regset_end_addr == regset_addr)
pr_info("%s : this regset can be"
" combined with previous\n",
__func__);
last_regset_end_addr = (regset_addr +
regset->size - 6);
}
regset++;
} while (regset < end_regset);
}
#endif
regset = regset_table;
pr_debug("%s : start writing init reg 2 bursts\n", __func__);
do {
if (regset->size > 4) {
/* write the address packet */
err = s5k4ecgx_i2c_write_block(sd, regset->data, 4);
if (err)
break;
/* write the data in a burst */
err = s5k4ecgx_i2c_write_block(sd, regset->data+4,
regset->size-4);
} else
err = s5k4ecgx_i2c_write_block(sd, regset->data,
regset->size);
if (err)
break;
regset++;
} while (regset < end_regset);
pr_debug("%s : finished writing init reg 2 bursts\n", __func__);
vfree(regset_data);
vfree(regset_table);
return err;
}
static int s5k4ecgx_init_regs(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
u16 read_value;
/* we'd prefer to do this in probe, but the framework hasn't
* turned on the camera yet so our i2c operations would fail
* if we tried to do it in probe, so we have to do it here
* and keep track if we succeeded or not.
*/
/* enter read mode */
s5k4ecgx_i2c_write_twobyte(client, 0x002C, 0x7000);
s5k4ecgx_i2c_write_twobyte(client, 0x002E, 0x01A6);
s5k4ecgx_i2c_read_twobyte(client, 0x0F12, &read_value);
pr_info("%s : revision %08X\n", __func__, read_value);
/* restore write mode */
s5k4ecgx_i2c_write_twobyte(client, 0x0028, 0x7000);
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_0
if (read_value == S5K4ECGX_VERSION_1_0) {
state->regs = ®s_for_fw_version_1_0;
state->initialized = true;
return 0;
}
#endif
#ifdef CONFIG_VIDEO_S5K4ECGX_V_1_1
if (read_value == S5K4ECGX_VERSION_1_1) {
state->fw.minor = 1;
state->regs = ®s_for_fw_version_1_1;
state->initialized = true;
return 0;
}
#endif
dev_err(&client->dev, "%s: unknown fw version 0x%x\n",
__func__, read_value);
return -ENODEV;
}
static int s5k4ecgx_init(struct v4l2_subdev *sd, u32 val)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
dev_dbg(&client->dev, "%s: start\n", __func__);
s5k4ecgx_init_parameters(sd);
if (s5k4ecgx_init_regs(&state->sd) < 0)
return -ENODEV;
dev_dbg(&client->dev, "%s: state->check_dataline : %d\n",
__func__, state->check_dataline);
if (s5k4ecgx_set_from_table(sd, "init reg 1",
&state->regs->init_reg_1, 1, 0) < 0)
return -EIO;
/* delay 10ms after wakeup of SOC processor */
msleep(10);
if (s5k4ecgx_write_init_reg2_burst(sd) < 0)
return -EIO;
if (s5k4ecgx_set_from_table(sd, "flash init",
&state->regs->flash_init, 1, 0) < 0)
return -EIO;
if (state->check_dataline) {
if (s5k4ecgx_set_from_table(sd, "dtp start",
&state->regs->dtp_start, 1, 0) < 0)
return -EIO;
}
dev_dbg(&client->dev, "%s: end\n", __func__);
return 0;
}
static const struct v4l2_subdev_core_ops s5k4ecgx_core_ops = {
.init = s5k4ecgx_init, /* initializing API */
.g_ctrl = s5k4ecgx_g_ctrl,
.s_ctrl = s5k4ecgx_s_ctrl,
.s_ext_ctrls = s5k4ecgx_s_ext_ctrls,
};
static const struct v4l2_subdev_video_ops s5k4ecgx_video_ops = {
.s_mbus_fmt = s5k4ecgx_s_mbus_fmt,
.enum_framesizes = s5k4ecgx_enum_framesizes,
.enum_mbus_fmt = s5k4ecgx_enum_mbus_fmt,
.try_mbus_fmt = s5k4ecgx_try_mbus_fmt,
.g_parm = s5k4ecgx_g_parm,
.s_parm = s5k4ecgx_s_parm,
};
static const struct v4l2_subdev_ops s5k4ecgx_ops = {
.core = &s5k4ecgx_core_ops,
.video = &s5k4ecgx_video_ops,
};
/*
* s5k4ecgx_probe
* Fetching platform data is being done with s_config subdev call.
* In probe routine, we just register subdev device
*/
static int s5k4ecgx_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct v4l2_subdev *sd;
struct s5k4ecgx_state *state;
struct s5k4ecgx_platform_data *pdata = client->dev.platform_data;
if ((pdata == NULL) || (pdata->flash_onoff == NULL)) {
dev_err(&client->dev, "%s: bad platform data\n", __func__);
return -ENODEV;
}
state = kzalloc(sizeof(struct s5k4ecgx_state), GFP_KERNEL);
if (state == NULL)
return -ENOMEM;
mutex_init(&state->ctrl_lock);
state->runmode = S5K4ECGX_RUNMODE_NOTREADY;
sd = &state->sd;
strcpy(sd->name, S5K4ECGX_DRIVER_NAME);
/*
* Assign default format and resolution
* Use configured default information in platform data
* or without them, use default information in driver
*/
state->pix.width = pdata->default_width;
state->pix.height = pdata->default_height;
if (!pdata->pixelformat)
state->pix.pixelformat = DEFAULT_PIX_FMT;
else
state->pix.pixelformat = pdata->pixelformat;
if (!pdata->freq)
state->freq = DEFAULT_MCLK; /* 24MHz default */
else
state->freq = pdata->freq;
/* Registering subdev */
v4l2_i2c_subdev_init(sd, client, &s5k4ecgx_ops);
dev_dbg(&client->dev, "5MP camera S5K4ECGX loaded.\n");
return 0;
}
static int s5k4ecgx_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct s5k4ecgx_state *state =
container_of(sd, struct s5k4ecgx_state, sd);
v4l2_device_unregister_subdev(sd);
mutex_destroy(&state->ctrl_lock);
kfree(state);
dev_dbg(&client->dev, "Unloaded camera sensor S5K4ECGX.\n");
return 0;
}
static const struct i2c_device_id s5k4ecgx_id[] = {
{ S5K4ECGX_DRIVER_NAME, 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, s5k4ecgx_id);
static struct i2c_driver v4l2_i2c_driver = {
.driver.name = S5K4ECGX_DRIVER_NAME,
.probe = s5k4ecgx_probe,
.remove = s5k4ecgx_remove,
.id_table = s5k4ecgx_id,
};
static int __init v4l2_i2c_drv_init(void)
{
return i2c_add_driver(&v4l2_i2c_driver);
}
static void __exit v4l2_i2c_drv_cleanup(void)
{
i2c_del_driver(&v4l2_i2c_driver);
}
module_init(v4l2_i2c_drv_init);
module_exit(v4l2_i2c_drv_cleanup);
MODULE_DESCRIPTION("LSI S5K4ECGX 5MP SOC camera driver");
MODULE_AUTHOR("Seok-Young Jang <quartz.jang@samsung.com>");
MODULE_LICENSE("GPL");
|