summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx/ezx_camera.patch
blob: bec5687e0f0f4528946e9de8a01b3f673af9056f (plain)
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
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
EZX phone platform device drivers for camera

diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/Kconfig linux-2.6.16.5-exz/drivers/i2c/chips/Kconfig
--- linux-2.6.16.5/drivers/i2c/chips/Kconfig	2006-04-12 22:27:57.000000000 +0200
+++ linux-2.6.16.5-exz/drivers/i2c/chips/Kconfig	2006-04-16 18:49:29.000000000 +0200
@@ -135,4 +135,25 @@
 	  This driver can also be built as a module. If so, the module
 	  will be called x1205.
 
+config I2C_ADCM2700
+	tristate "ADCM2700 support"
+	depends on I2C_PXA
+
+config I2C_A780_CAMERA 
+	tristate "A780 camera support"
+	depends on I2C_PXA
+
+config I2C_OV9640
+	depends on I2C_A780_CAMERA
+	bool "OV9640 support"
+config I2C_OV9650
+	depends on I2C_A780_CAMERA
+	bool "OV9650 support"
+config I2C_MT9M111
+	depends on I2C_A780_CAMERA
+	bool "MT9M111 support"
+config I2C_ADCM3800
+	depends on I2C_A780_CAMERA
+	bool "ADCM3800 support"
+
 endmenu
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/Makefile linux-2.6.16.5-exz/drivers/i2c/chips/Makefile
--- linux-2.6.16.5/drivers/i2c/chips/Makefile	2006-04-12 22:27:57.000000000 +0200
+++ linux-2.6.16.5-exz/drivers/i2c/chips/Makefile	2006-04-16 18:49:29.000000000 +0200
@@ -15,6 +15,10 @@
 obj-$(CONFIG_TPS65010)		+= tps65010.o
 obj-$(CONFIG_RTC_X1205_I2C)	+= x1205.o
 
+obj-$(CONFIG_I2C_ADCM2700)	+= e680_camera.o
+obj-$(CONFIG_I2C_A780_CAMERA)	+= a780_camera.o
+obj-$(CONFIG_PXA_EZX_E680)	+= boomer.o
+
 ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
 endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/a780_camera.c linux-2.6.16.5-exz/drivers/i2c/chips/a780_camera.c
--- linux-2.6.16.5/drivers/i2c/chips/a780_camera.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/a780_camera.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,905 @@
+/*
+ *  linux/drivers/i2c/a780_camera.c
+ *
+ *  Support for the Motorola Ezx A780 Development Platform.
+ *  
+ *  Author:	    Jay Jia
+ *  Created:	Nov 25, 2003
+ *  Copyright:	Motorola Inc.
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *
+ */
+#include <linux/miscdevice.h>
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/videodev.h>
+#include <linux/pxa_camera.h>
+#include <linux/init.h>
+#include <linux/kdev_t.h>
+#include <asm/semaphore.h>
+
+#include <linux/sound.h>
+#include <linux/soundcard.h>
+#include <asm/uaccess.h>
+#include <asm/irq.h>
+
+/* Major 10, Minor 244, /dev/camerai2c */
+#define CAM_NAME        "cami2c"
+#define CAM_MINOR       244
+
+#define TESTCODE
+#undef  TESTCODE
+#define I2C_A780_CAMERA 0x86
+
+//#define DEBUG 2
+
+/*-----------------------------------------------------------*/
+#define err_print(fmt, args...) printk(KERN_ERR "I2C-CAMERA in fun:%s "fmt"\n", __FUNCTION__, ##args)
+
+#ifndef NDEBUG
+#define dbg_print(fmt, args...) printk(KERN_INFO "I2C-CAMERA in fun:%s "fmt"\n", __FUNCTION__, ##args)
+#if      DEBUG > 1
+#define ddbg_print(fmt, args...) dbg_print(fmt, ##args)
+#else
+#define ddbg_print(fmt, args...) ;
+#endif
+#else
+#define dbg_print(fmt, args...) ;
+#define ddbg_print(fmt, args...) ;
+#endif
+/*-----------------------------------------------------------*/
+
+#define I2C_CLIENT_NONE         100
+#define I2C_CLIENT_MT9M111      101
+#define I2C_CLIENT_OV9640       102
+#define I2C_CLIENT_OV9650       103
+#define I2C_CLIENT_ADCM3800     104
+static int i2c_camera_client_type = I2C_CLIENT_NONE;
+static unsigned long i2c_camera_chipid = 0;
+
+
+static int a780_camera_adapter_attach(struct i2c_adapter *adap);
+static int a780_camera_detach(struct i2c_client *client);
+static int a780_camera_client_register(struct i2c_client *client);
+static int a780_camera_client_unregister(struct i2c_client *client);
+/* ----------------------------------------------------------------------- */
+static struct i2c_driver driver = {
+	.name		= "a780 camera driver",
+	.id		= I2C_A780_CAMERA,
+	//flags:           I2C_DF_DUMMY,
+	.attach_adapter	= a780_camera_adapter_attach,        
+	.detach_client	= a780_camera_detach,
+	.owner		= THIS_MODULE,
+};
+
+static struct i2c_adapter a780_camera_adapter = {
+        name:                   "a780 camera adapter",
+        id:                     I2C_A780_CAMERA,
+        client_register:        a780_camera_client_register,
+        client_unregister:      a780_camera_client_unregister,
+};
+
+static struct i2c_client client_template =
+{
+    name:   "(unset)",        
+    adapter:&a780_camera_adapter,
+};
+
+struct i2c_client *a780_camera_client;
+unsigned int a780_camera_minor;
+	
+static int a780_camera_open(void)
+{
+	//MOD_INC_USE_COUNT;
+	
+	return 0;
+}
+
+static int a780_camera_release(void)
+{
+	//MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+
+int a780_camera_read(char *buf, size_t count)
+{
+    int ret;
+    unsigned int flags;
+ 
+	a780_camera_open();	
+    local_irq_save(flags);
+    enable_irq(IRQ_I2C);
+        ret = i2c_master_recv(a780_camera_client, buf, count);
+    local_irq_restore(flags);
+	a780_camera_release();
+	return ret;
+			
+}
+	
+int a780_camera_write(const char *buf, size_t count)
+{
+	int ret;
+    unsigned int flags;
+
+	a780_camera_open();	
+    local_irq_save(flags);
+    enable_irq(IRQ_I2C);
+	ret = i2c_master_send(a780_camera_client, buf, count);
+    local_irq_restore(flags);
+	a780_camera_release();
+	return ret;
+}
+
+static int a780_camera_client_register(struct i2c_client *client)
+{
+	
+	return 0;
+}
+
+static int a780_camera_client_unregister(struct i2c_client *client)
+{
+	
+	return 0;	
+}
+/* ----------------------------------------------------------------------- */
+
+static int a780_camera_adapter_attach(struct i2c_adapter *adap)
+{
+	if(! (a780_camera_client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
+		return -ENOMEM;
+	memcpy(a780_camera_client,&client_template,sizeof(struct i2c_client));
+	a780_camera_client->adapter = adap;
+        
+	a780_camera_client->addr = 0x5D;
+	
+	i2c_attach_client(a780_camera_client);
+	return 0;
+}	
+
+static int a780_camera_detach(struct i2c_client *client)
+{	
+	i2c_detach_client(a780_camera_client);
+	return 0;
+}
+/* ----------------------------------------------------------------------- */
+static int cam_open(struct inode *inode, struct file *file)
+{
+        if(i2c_camera_client_type == I2C_CLIENT_NONE)
+            return -EINVAL;
+
+        //MOD_INC_USE_COUNT;
+        return 0;
+}
+
+static int i2c_camera_readw(unsigned short addr, unsigned short *pvalue);
+static int i2c_camera_readb(unsigned short addr, unsigned char *pvalue);
+static int i2c_camera_writew(unsigned short addr, unsigned short value);
+static int i2c_camera_writeb(unsigned short addr, unsigned char value);
+
+static int cam_close(struct inode * inode, struct file *file)
+{
+        //MOD_DEC_USE_COUNT;
+        return 0;
+}
+
+#define DETECT_BUFLEN 256
+static int cam_ioctl_detectid (void * arg)
+{
+    int    buflen, idlen;
+    char*  id;
+    struct camera_i2c_detectid * param = arg;
+    if(copy_from_user(&buflen, &(param->buflen), sizeof(buflen)))
+    {
+        return -EFAULT;
+    }
+    if(buflen > DETECT_BUFLEN)
+    {
+        return -ENOMEM;
+    }
+    id = kmalloc(DETECT_BUFLEN, GFP_KERNEL);
+    if(id == NULL)
+    {
+        return -ENOMEM;
+    }
+
+    idlen = 0;
+    switch(i2c_camera_client_type)
+    {
+#ifdef CONFIG_I2C_MT9M111
+        case I2C_CLIENT_MT9M111:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "MICRON", "MT9M111", i2c_camera_chipid);
+            break;
+#endif
+#ifdef CONFIG_I2C_ADCM3800
+        case I2C_CLIENT_ADCM3800:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "AGILENT", "ADCM3800", i2c_camera_chipid);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9640
+        case I2C_CLIENT_OV9640:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "OMNIVISION", "OV9640", i2c_camera_chipid);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9650
+        case I2C_CLIENT_OV9650:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "OMNIVISION", "OV9650", i2c_camera_chipid);
+            break;
+#endif
+        default:
+            break;
+    }
+    id[DETECT_BUFLEN-1] = 0;
+    idlen = strlen(id)+1;
+    if(buflen < idlen)
+    {
+        kfree(id);
+        return -ENOMEM;
+    }
+    if(copy_to_user(param->data, id, idlen))
+    {
+        kfree(id);
+        return -EFAULT;
+    }
+    kfree(id);
+    return 0;
+}
+
+static int cam_ioctl_register_rw (unsigned int cmd, void * arg)
+{
+    int ret = -ENOTSUPP;
+    struct camera_i2c_register reg;
+    if(copy_from_user(&reg, arg, sizeof(reg)))
+    {
+        return -EFAULT;
+    }
+    switch(cmd)
+    {
+        case CAMERA_I2C_WRITEW:
+            ret=i2c_camera_writew(reg.addr, reg.value.w);
+            break;
+        case CAMERA_I2C_WRITEB:
+            ret=i2c_camera_writeb(reg.addr, reg.value.b);
+            break;
+        case CAMERA_I2C_READW:
+            if((ret=i2c_camera_readw(reg.addr, &(reg.value.w)))>=0)
+            {
+                if(copy_to_user(arg, &reg, sizeof(reg)))
+                    ret = -EFAULT;
+            }
+            break;
+        case CAMERA_I2C_READB:
+            if((ret=i2c_camera_readb(reg.addr, &(reg.value.b)))>=0)
+            {
+                if(copy_to_user(arg, &reg, sizeof(reg)))
+                    ret = -EFAULT;
+            }
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int cam_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+    int ret = -ENOTSUPP;
+    switch (cmd)
+    {
+        case CAMERA_I2C_WRITEW:
+        case CAMERA_I2C_WRITEB:
+        case CAMERA_I2C_READW:
+        case CAMERA_I2C_READB:
+            ret = cam_ioctl_register_rw(cmd, (void *)arg);
+            break;
+        case CAMERA_I2C_DETECTID:
+            ret = cam_ioctl_detectid((void *)arg);
+            break;
+        default:
+            ret = -EINVAL;
+            break;
+    }
+    return ret;
+}
+
+static struct file_operations cam_fops = {
+        ioctl:          cam_ioctl,
+        open:           cam_open,
+        release:        cam_close,
+};
+
+static struct miscdevice cam_misc_device = {
+        CAM_MINOR,
+        CAM_NAME,
+        &cam_fops,
+};
+
+/* ----------------------------------------------------------------------- */
+static int a780_camera_init_module(void)
+{
+	int res;
+	
+	res = i2c_add_driver(&driver);
+	if( res < 0 )
+	{
+		printk("error in add i2c driver\n");
+		return res;
+	}
+    if (misc_register (&cam_misc_device))
+    {
+        printk(KERN_ERR "Couldn't register cam driver\n");
+        return -EIO;
+    }
+
+	return 0;
+}
+
+static void a780_camera_cleanup_module(void)
+{	
+	i2c_del_driver(&driver);
+    misc_deregister(&cam_misc_device);
+}
+
+
+#ifdef  CONFIG_I2C_MT9M111
+
+/*-----------------------------------------------------------*/
+#define MT9M111_PAGE(a)    ((u8)(((a) >> 8) & 0xFF))
+#define MT9M111_OFFSET(a)   ((u8)((a) & 0xFF))
+
+//#define MT9M111_LOG
+
+#ifdef  MT9M111_LOG
+#define mt9m111_dbg_print(fmt, args...) dbg_print(fmt, ##args)
+#else
+#define mt9m111_dbg_print(fmt, args...) ;
+#endif
+
+static int mt9m111_ChangePage(unsigned char page)
+{
+    static unsigned char old_page = 0xFF;
+    int res;
+    char tmp[3]={0xF0, 0, page};
+    
+    if(page == old_page)
+    {
+	return 0;
+    }
+    
+    res = a780_camera_write(tmp, 3);
+    if(res < 0)
+    {
+	return  res;
+    }
+    old_page = page;
+    
+    return 0; 
+}
+
+int mt9m111_read(unsigned short addr, unsigned short *pvalue)
+{
+	unsigned char	pageaddr = MT9M111_PAGE(addr);
+	unsigned char	offset    = MT9M111_OFFSET(addr);
+	unsigned short value;
+        int     ret;
+
+	if((ret = mt9m111_ChangePage(pageaddr)) != 0)  
+	{
+	    mt9m111_dbg_print("Change block address failed. block = 0x%2x", pageaddr);
+            mt9m111_dbg_print("Error code = 0x%x", ret);
+	    return ret;
+	}
+        if(a780_camera_write(&offset, 1) < 0)
+        {
+            mt9m111_dbg_print("read error!");
+            return ret;
+        }
+        
+        ret = a780_camera_read((char *)&value, 2); 
+        if(ret < 0)
+        {
+           mt9m111_dbg_print("read error");
+           return ret;
+        } 
+
+	*pvalue = (value >> 8) | (value << 8);
+        mt9m111_dbg_print("addr = 0x%04x, value = 0x%04x", addr, *pvalue);
+	return  0;
+}	
+
+int mt9m111_write(unsigned short addr, unsigned short value)
+{
+	unsigned char	pageaddr = MT9M111_PAGE(addr);
+	unsigned char	offset    = MT9M111_OFFSET(addr);
+        char    tmp[3]={offset, (char)(value>>8), (char)(value&0xFF)};
+        int     ret;
+		
+	if((ret = mt9m111_ChangePage(pageaddr)) != 0)  
+	{
+	   mt9m111_dbg_print("Change block address failed. block = 0x%2x", pageaddr);
+           mt9m111_dbg_print("error code = 0x%x", ret);
+	   return ret;
+	}
+	ret = a780_camera_write(tmp, 3);
+        if(ret < 0)
+        {
+          return ret;
+        }
+        mt9m111_dbg_print("addr = 0x%04x, value = 0x%04x", addr,value);
+        return 0;
+}
+
+int i2c_mt9m111_cleanup(void)
+{
+  i2c_camera_client_type = I2C_CLIENT_NONE;
+  return 0;
+} 
+int i2c_mt9m111_init(void)
+{
+  //unsigned short chipid;
+  a780_camera_client->addr = 0x5D;
+
+  //mt9m111_read(0, &chipid);
+  //mt9m111_dbg_print("mt9m111 chip id is 0x%x", chipid);
+
+  i2c_camera_client_type = I2C_CLIENT_MT9M111;
+  return 0;
+}
+
+#endif  // CONFIG_I2C_MT9M111
+
+#ifdef CONFIG_I2C_OV9650
+
+#define OV_REG_PID  0x0a
+#define OV_REG_VER  0x0b
+#define OV9650_CHIPID_M    0x96
+#define OV9650_CHIPID_L_0  0x51
+#define OV9650_CHIPID_L    0x52
+
+int i2c_ov9650_read(u8 addr, u8 *pvalue)
+{
+    int     ret;
+
+    if((ret = a780_camera_write(&addr, 1)) < 0)
+    {
+        err_print("i2c write error code =%d", ret);
+        return -EIO;
+    }
+        
+    ret = a780_camera_read((char *)pvalue, 1); 
+    if(ret < 0)
+    {
+        err_print("i2c read error code =%d", ret);
+        return -EIO;
+    } 
+
+    ddbg_print("addr = 0x%02x, value = 0x%02x", addr, *pvalue);
+	return  0;
+}	
+
+int i2c_ov9650_write(u8 addr, u8 value)
+{
+    char    tmp[2]={addr, value};
+    int     ret;
+		
+	ret = a780_camera_write(tmp, 2);
+    if(ret < 0)
+    {
+        err_print("i2c write error code =%d", ret);
+        return -EIO;
+    }
+
+    ddbg_print("addr = 0x%02x, value = 0x%02x", addr,value);
+    return 0;
+}
+
+int i2c_ov9650_cleanup(void)
+{
+    i2c_camera_client_type = I2C_CLIENT_NONE;
+    return 0;
+}
+
+int i2c_ov9650_init(void)
+{
+    unsigned char chipid;
+    unsigned char ver;
+    // setup i2c address
+    a780_camera_client->addr = 0x30;    //0x60;
+
+    if( i2c_ov9650_read(OV_REG_PID, &chipid) < 0 )
+    {
+        err_print("error: failed to read chipid");
+        return -EIO;
+    }
+    if( chipid != OV9650_CHIPID_M )
+    {
+        err_print("chip is not Omnivision");
+        return -EIO;
+    }
+
+    i2c_ov9650_read(OV_REG_VER, &ver);
+    dbg_print("ov chip id is 0x%x:0x%x", chipid, ver);
+
+    if( ver != OV9650_CHIPID_L && ver != OV9650_CHIPID_L_0 )
+    {
+        err_print("chip is not OV9650");
+        return -EIO;
+    }
+    i2c_camera_client_type = I2C_CLIENT_OV9650;
+    i2c_camera_chipid = (chipid<<8) | ver;
+    
+    return 0;
+}
+
+#ifdef  CONFIG_I2C_OV9640
+int ov9640_read(u8 addr, u8 *pvalue)
+{
+    return i2c_ov9650_read(addr, pvalue);
+}
+
+int ov9640_write(u8 addr, u8 value)
+{
+    return i2c_ov9650_write(addr, value);
+}
+
+int i2c_ov9640_cleanup(void)
+{
+    i2c_camera_client_type = I2C_CLIENT_NONE;
+    return 0;
+}
+
+#define OV9640_CHIPID_M  0x96
+#define OV9640_CHIPID_L  0x49
+#define OV9640_CHIPID_L_V2  0x48
+
+int i2c_ov9640_init(void)
+{
+    unsigned char chipid;
+    unsigned char ver;
+    // setup i2c address
+    a780_camera_client->addr = 0x30;    //0x60;
+
+    if( ov9640_read(OV_REG_PID, &chipid) < 0 )
+    {
+        err_print("error: failed to read chipid");
+        return -EIO;
+    }
+    if( chipid != OV9640_CHIPID_M )
+    {
+        err_print("chip is not Omnivision");
+        return -EIO;
+    }
+
+    ov9640_read(OV_REG_VER, &ver);
+    dbg_print("ov chip id is 0x%x:0x%x", chipid, ver);
+
+    if( ver != OV9640_CHIPID_L && ver != OV9640_CHIPID_L_V2 )
+    {
+        err_print("chip is not OV9640");
+        return -EIO;
+    }
+    i2c_camera_client_type = I2C_CLIENT_OV9640;
+    i2c_camera_chipid = (chipid<<8) | ver;
+    
+    return 0;
+}
+#endif  // CONFIG_I2C_OV9640
+
+#endif  // CONFIG_I2C_OV9650
+
+#ifdef CONFIG_I2C_ADCM3800
+
+#define ADCM3800_I2C_ADDR           0x56
+#define ADCM3800_BLOCK_SWITCH_CMD   0xFE
+
+/* Calculating the Module Block Number */
+#define ADCM3800_BLOCK(a)    ((u8)(((a) >> 7) & 0xFF))     /* register's module block address. */
+#define ADCM3800_OFFSET(a)   ((u8)(((a) << 1) & 0xFF))     /* register's offset to this block. */
+#define ADCM3800_OFFSET_R(a) (ADCM3800_OFFSET(a)|1)                 /* register's offset ot this block to read*/     
+
+static int adcm3800_ChgBlock(unsigned char block)
+{
+    static unsigned char old_blk = 0xFF;
+    int res;
+    char tmp[2]={ADCM3800_BLOCK_SWITCH_CMD, block};
+    
+    if(block == old_blk)
+    {
+	    return 0;
+    }
+    
+    res = a780_camera_write(tmp, 2);
+    if(res < 0)
+    {
+        err_print("error code = %d", res);
+	    return  -EIO;
+    }
+    old_blk = block;
+    
+    return 0; 
+}
+
+int i2c_adcm3800_read_byte(unsigned short addr, unsigned char *pvalue)
+{
+	unsigned char	blockaddr = ADCM3800_BLOCK(addr);
+	unsigned char	offset    = ADCM3800_OFFSET_R(addr);
+    int     ret;
+
+	if((ret = adcm3800_ChgBlock(blockaddr)) != 0)  
+	{
+	    err_print("Change block address failed. block = 0x%2x", blockaddr);
+	    return -EIO;
+	}
+    if((ret = a780_camera_write(&offset, 1)) < 0)
+    {
+        err_print("i2c write error code =%d", ret);
+        return -EIO;
+    }
+
+    ret = a780_camera_read((char *)pvalue, 1); 
+    if(ret < 0)
+    {
+        err_print("i2c read error code = %d", ret);
+        return -EIO;
+    } 
+    ddbg_print("read b: addr(0x%x) value(0x%x)", addr, *pvalue);
+	
+	return  *pvalue;
+}
+
+int i2c_adcm3800_read(unsigned short addr, unsigned short *pvalue)
+{
+	unsigned char	blockaddr = ADCM3800_BLOCK(addr);
+	unsigned char	offset    = ADCM3800_OFFSET_R(addr);
+    int     ret;
+
+	if((ret = adcm3800_ChgBlock(blockaddr)) != 0)  
+	{
+	    err_print("Change block address failed. block = 0x%2x", blockaddr);
+	    return -EIO;
+	}
+    if((ret = a780_camera_write(&offset, 1)) < 0)
+    {
+        err_print("i2c write error code =%d", ret);
+        return -EIO;
+    }
+        
+    ret = a780_camera_read((char *)pvalue, 2); 
+    if(ret < 0)
+    {
+        err_print("i2c read error code = %d", ret);
+        return -EIO;
+    } 
+    ddbg_print("read: addr(0x%x) value(0x%x)", addr, *pvalue);
+	
+	return  *pvalue;
+}
+
+int i2c_adcm3800_write_byte(unsigned short addr, unsigned char value)
+{
+	unsigned char	blockaddr = ADCM3800_BLOCK(addr);
+	unsigned char 	offset    = ADCM3800_OFFSET(addr);;
+    char    tmp[3]={offset, value};
+    int     ret;
+
+    ddbg_print("write b: addr(0x%x) value(0x%x)", addr, value);
+	if((ret = adcm3800_ChgBlock(blockaddr)) != 0)  
+	{
+	    err_print("Change block address failed. block = 0x%2x", blockaddr);
+	    return -EIO;
+	}
+	ret = a780_camera_write(tmp, 2);
+    if(ret < 0)
+    {
+        err_print("i2c write error code = %d", ret);
+        return -EIO;
+    }
+    return 0;
+ 
+}
+int i2c_adcm3800_write(unsigned short addr, unsigned short value)
+{
+	unsigned char	blockaddr = ADCM3800_BLOCK(addr);
+	unsigned char 	offset    = ADCM3800_OFFSET(addr);;
+    char    tmp[3]={offset, (char)(value&0xFF), (char)(value>>8)};
+    int     ret;
+
+    ddbg_print("write: addr(0x%x) value(0x%x)", addr, value);
+	if((ret = adcm3800_ChgBlock(blockaddr)) != 0)  
+	{
+	    err_print("Change block address failed. block = 0x%2x", blockaddr);
+	    return -EIO;
+	}
+	ret = a780_camera_write(tmp, 3);
+    if(ret < 0)
+    {
+        err_print("i2c write error code = %d", ret);
+        return -EIO;
+    }
+    return 0;
+}
+
+int i2c_adcm3800_cleanup(void)
+{
+    i2c_camera_client_type = I2C_CLIENT_NONE;
+    return 0;
+}
+
+#define ADCM_SREG_PID  0x0000
+#define ADCM_EREG_PID  0x0800
+
+#define ADCM3800_PIPE_REV       0x0068
+#define ADCM3800_SENSOR_REV     0x68
+
+int i2c_adcm3800_init(void)
+{
+    unsigned short pid_pipe;
+    unsigned char pid_sensor;
+    a780_camera_client->addr = ADCM3800_I2C_ADDR;
+ 
+    if(i2c_adcm3800_read(ADCM_SREG_PID, &pid_pipe) < 0)
+    {
+        return -EIO;
+    }
+    if(i2c_adcm3800_read_byte(ADCM_EREG_PID, &pid_sensor) < 0)
+    {
+        return -EIO;
+    }
+
+    dbg_print("pipe id is 0x%x, sensor id is 0x%x", pid_pipe, pid_sensor);
+    if(pid_pipe != ADCM3800_PIPE_REV && pid_sensor != ADCM3800_SENSOR_REV)
+    {
+        err_print("sensor is not Agilent ADCM3800");
+        return -EIO;
+    } 
+    i2c_camera_client_type = I2C_CLIENT_ADCM3800;
+    i2c_camera_chipid = (pid_pipe<<8) | pid_sensor;
+
+    return 0;
+}
+#endif // CONFIG_I2C_ADCM3800
+
+static int i2c_camera_readw(unsigned short addr, unsigned short *pvalue)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+#ifdef CONFIG_I2C_MT9M111
+        case I2C_CLIENT_MT9M111:
+            ret = mt9m111_read(addr, pvalue);
+            break;
+#endif
+#ifdef CONFIG_I2C_ADCM3800
+        case I2C_CLIENT_ADCM3800:
+            ret = i2c_adcm3800_read(addr, pvalue);
+            break;
+#endif
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_readb(unsigned short addr, unsigned char *pvalue)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+#ifdef CONFIG_I2C_ADCM3800
+        case I2C_CLIENT_ADCM3800:
+            ret = i2c_adcm3800_read_byte(addr, pvalue);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9640
+        case I2C_CLIENT_OV9640:
+            ret = ov9640_read(addr, pvalue);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9650
+        case I2C_CLIENT_OV9650:
+            ret = i2c_ov9650_read(addr, pvalue);
+            break;
+#endif
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_writew(unsigned short addr, unsigned short value)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+#ifdef CONFIG_I2C_MT9M111
+        case I2C_CLIENT_MT9M111:
+            ret = mt9m111_write(addr, value);
+            break;
+#endif
+#ifdef CONFIG_I2C_ADCM3800
+        case I2C_CLIENT_ADCM3800:
+            ret = i2c_adcm3800_write(addr, value);
+            break;
+#endif
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_writeb(unsigned short addr, unsigned char value)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+#ifdef CONFIG_I2C_ADCM3800
+        case I2C_CLIENT_ADCM3800:
+            ret = i2c_adcm3800_write_byte(addr, value);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9640
+        case I2C_CLIENT_OV9640:
+            ret = ov9640_write(addr, value);
+            break;
+#endif
+#ifdef CONFIG_I2C_OV9650
+        case I2C_CLIENT_OV9650:
+            ret = i2c_ov9650_write(addr, value);
+            break;
+#endif
+        default:
+            break;
+    }
+    return ret;
+}
+
+#ifdef CONFIG_I2C_MT9M111
+EXPORT_SYMBOL(i2c_mt9m111_init);
+EXPORT_SYMBOL(mt9m111_write);
+EXPORT_SYMBOL(mt9m111_read);
+EXPORT_SYMBOL(i2c_mt9m111_cleanup);
+#endif
+
+#ifdef CONFIG_I2C_OV9650
+EXPORT_SYMBOL(i2c_ov9650_init);
+EXPORT_SYMBOL(i2c_ov9650_write);
+EXPORT_SYMBOL(i2c_ov9650_read);
+EXPORT_SYMBOL(i2c_ov9650_cleanup);
+#endif
+
+#ifdef CONFIG_I2C_OV9640
+EXPORT_SYMBOL(i2c_ov9640_init);
+EXPORT_SYMBOL(ov9640_write);
+EXPORT_SYMBOL(ov9640_read);
+EXPORT_SYMBOL(i2c_ov9640_cleanup);
+#endif
+
+#ifdef CONFIG_I2C_ADCM3800
+EXPORT_SYMBOL(i2c_adcm3800_init);
+EXPORT_SYMBOL(i2c_adcm3800_write);
+EXPORT_SYMBOL(i2c_adcm3800_read);
+EXPORT_SYMBOL(i2c_adcm3800_write_byte);
+EXPORT_SYMBOL(i2c_adcm3800_read_byte);
+EXPORT_SYMBOL(i2c_adcm3800_cleanup);
+#endif
+
+module_init(a780_camera_init_module);
+module_exit(a780_camera_cleanup_module);
+MODULE_AUTHOR("Jay Jia");
+MODULE_LICENSE("GPL");
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/boomer.c linux-2.6.16.5-exz/drivers/i2c/chips/boomer.c
--- linux-2.6.16.5/drivers/i2c/chips/boomer.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/boomer.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,175 @@
+/*
+ *  linux/drivers/i2c/boomer.c
+ *
+ *  Support for the Motorola Ezx A780 Development Platform.
+ *  
+ *  Author:	    Jay Jia
+ *  Created:	Nov 25, 2003
+ *  Copyright:	Motorola Inc.
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  History:
+ *  Jin Lihong(w20076),Motorola  Jan 13,2004,LIBdd68327  Make the e680 louder speaker work.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/videodev.h>
+#include <linux/init.h>
+#include <linux/kdev_t.h>
+#include <asm/semaphore.h>
+
+#include <linux/sound.h>
+#include <linux/soundcard.h>
+#include <asm/uaccess.h>
+#include <asm/irq.h>
+
+
+#define TESTCODE
+#undef  TESTCODE
+#define I2C_MIXER 0x80
+
+static int mixer_adapter_attach(struct i2c_adapter *adap);
+static int mixer_detach(struct i2c_client *client);
+static int mixer_client_register(struct i2c_client *client);
+static int mixer_client_unregister(struct i2c_client *client);
+extern struct i2c_client *fmradio_client;
+/* ----------------------------------------------------------------------- */
+static struct i2c_driver driver = {
+	.name			= "mixer driver",
+	.id			= I2C_MIXER,
+	//.flags		= I2C_DF_DUMMY,
+	.attach_adapter		= mixer_adapter_attach,        
+	.detach_client		= mixer_detach,
+	.owner			= THIS_MODULE,
+};
+
+static struct i2c_adapter mixer_adapter = {
+        name:                   "Mixer adapter",
+        id:                     I2C_MIXER,
+        client_register:        mixer_client_register,
+        client_unregister:      mixer_client_unregister,
+};
+
+static struct i2c_client client_template =
+{
+    name:   "(unset)",        
+    adapter:&mixer_adapter,
+};
+
+struct i2c_client *mixer_client;
+unsigned int mixer_minor;
+	
+int mixer_write(const char *buf, size_t count);
+int mixer_open(void)
+{
+	//MOD_INC_USE_COUNT;
+	
+
+#ifdef TESTCODE
+	char data[4]={0x18,0x7d,0xbd,0xcd};
+        char freq[5]={0x2e,0x56,0x41,0x11,0x40};
+	unsigned char s[5]={0, 0, 0, 0, 0};
+	
+	mixer_write(data,4);
+//	i2c_master_send(fmradio_client,freq,5);	
+//	printk("fmradio test code\n");
+//        mdelay(300);		
+//	i2c_master_recv(fmradio_client, s, 5);
+//	printk("s0=%02x   s1=%02x   s2=%02x    s3=%02x   s4=%02x \n",s[0],s[1],s[2],s[3],s[4]);
+#endif
+
+
+	return 0;
+}
+
+int mixer_release(void)
+{
+	//MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+int mixer_write(const char *buf, size_t count)
+{
+	int ret;
+	unsigned long flags;	
+
+	mixer_open();
+	local_irq_save(flags);
+	enable_irq(IRQ_I2C);
+	ret = i2c_master_send(mixer_client, buf, count);
+	local_irq_restore(flags);
+//	printk("i2c-%d writing %d bytes.\n", mixer_minor, ret);
+	mixer_release();
+	return ret;
+}
+
+static int mixer_client_register(struct i2c_client *client)
+{
+	return 0;
+}
+
+static int mixer_client_unregister(struct i2c_client *client)
+{
+	
+	return 0;	
+}
+/* ----------------------------------------------------------------------- */
+
+static int mixer_adapter_attach(struct i2c_adapter *adap)
+{
+	if(! (mixer_client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
+		return -ENOMEM;
+	memcpy(mixer_client,&client_template,sizeof(struct i2c_client));
+	mixer_client->adapter = adap;
+        
+	mixer_client->addr = 0x7c;
+	
+	printk("adapter %s\n",adap->name);
+	i2c_attach_client(mixer_client);
+#ifdef TESTCODE
+	mixer_open();
+#endif
+	return 0;
+}
+
+static int mixer_detach(struct i2c_client *client)
+{	
+	i2c_detach_client(mixer_client);
+	return 0;
+}
+/* ----------------------------------------------------------------------- */
+
+static int mixer_init_module(void)
+{
+	int res;
+	
+	res = i2c_add_driver(&driver);
+	if( res < 0 )
+	{
+		printk("error in add i2c driver\n");
+		return res;
+	}
+	return 0;
+}
+
+static void mixer_cleanup_module(void)
+{	
+	i2c_del_driver(&driver);
+}
+
+module_init(mixer_init_module);
+module_exit(mixer_cleanup_module);
+MODULE_AUTHOR("Jay Jia");
+MODULE_LICENSE("GPL");
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/e680_camera.c linux-2.6.16.5-exz/drivers/i2c/chips/e680_camera.c
--- linux-2.6.16.5/drivers/i2c/chips/e680_camera.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/e680_camera.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,668 @@
+/*
+ *  linux/drivers/i2c/e680_camera.c
+ *
+ *  Support for the Motorola Ezx A780 Development Platform.
+ *  
+ *  Author:	    Jay Jia
+ *  Created:	Nov 25, 2003
+ *  Copyright:	Motorola Inc.
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  History:
+ *  Jin Lihong(w20076),Motorola  Jan 13,2004,LIBdd68327  Make the e680 louder speaker work.
+ *
+ */
+#include <linux/miscdevice.h>
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/videodev.h>
+#include <linux/pxa_camera.h>
+#include <linux/init.h>
+#include <linux/kdev_t.h>
+#include <asm/semaphore.h>
+
+
+#include <linux/sound.h>
+#include <linux/soundcard.h>
+#include <asm/uaccess.h>
+#include <asm/irq.h>
+#include <asm/arch/hardware.h>
+#include "i2c-adcm2700.h"
+
+/* Major 10, Minor 244, /dev/camerai2c */
+#define CAM_NAME        "cami2c"
+#define CAM_MINOR       244
+
+#define TESTCODE
+#undef  TESTCODE
+#define I2C_E680_CAMERA 0x86
+
+#define I2C_CLIENT_NONE      0
+#define I2C_CLIENT_ADCM2700  1
+#define I2C_CLIENT_MT9V111   2
+static int i2c_camera_client_type = I2C_CLIENT_NONE;
+static unsigned long i2c_camera_chipid = 0;
+#define REG_ADDRSELECT       (0x01)
+#undef BLOCK(a)
+#define BLOCK(a) ((u8)(((a)>>7)&0xFF))
+
+static int e680_camera_adapter_attach(struct i2c_adapter *adap);
+static int e680_camera_detach(struct i2c_client *client);
+static int e680_camera_client_register(struct i2c_client *client);
+static int e680_camera_client_unregister(struct i2c_client *client);
+
+typedef struct 
+{
+  u16 addr;
+  union {u16 word; u8 byte;}value;
+}i2c_camera_reg;
+/* ----------------------------------------------------------------------- */
+static struct i2c_driver driver = {
+	.name		= "e680 camera driver",
+	.id		= I2C_E680_CAMERA,
+	//.flags	= I2C_DF_DUMMY,
+	.attach_adapter	= e680_camera_adapter_attach,        
+	.detach_client	= e680_camera_detach,
+	.owner		= THIS_MODULE,
+};
+
+static struct i2c_adapter e680_camera_adapter = {
+        .name			= "e680 camera adapter",
+        .id			= I2C_E680_CAMERA,
+        .client_register	= e680_camera_client_register,
+        .client_unregister	= e680_camera_client_unregister,
+	.owner			= THIS_MODULE,
+};
+
+static struct i2c_client client_template =
+{
+    name:   "(unset)",        
+    adapter:&e680_camera_adapter,
+};
+
+struct i2c_client *e680_camera_client;
+unsigned int e680_camera_minor;
+
+static int e680_camera_open(void)
+{
+	//MOD_INC_USE_COUNT;
+	
+	return 0;
+}
+
+static int e680_camera_release(void)
+{
+	//MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+
+int e680_camera_read(char *buf, size_t count)
+{
+    int ret;        
+    unsigned int flags;
+    
+	e680_camera_open();	
+    local_irq_save(flags);
+    enable_irq(IRQ_I2C);
+    ret = i2c_master_recv(e680_camera_client, buf, count);
+    local_irq_restore(flags);
+	e680_camera_release();
+	return ret;
+			
+}
+	
+int e680_camera_write(const char *buf, size_t count)
+{
+	int ret;
+    unsigned int flags;
+    
+	e680_camera_open();
+    local_irq_save(flags);
+ 	enable_irq(IRQ_I2C);
+	ret = i2c_master_send(e680_camera_client, buf, count);
+    local_irq_restore(flags);
+	e680_camera_release();
+	return ret;
+}
+
+static int e680_camera_client_register(struct i2c_client *client)
+{
+	
+	return 0;
+}
+
+static int e680_camera_client_unregister(struct i2c_client *client)
+{
+	
+	return 0;	
+}
+/* ----------------------------------------------------------------------- */
+
+static int e680_camera_adapter_attach(struct i2c_adapter *adap)
+{
+	if(! (e680_camera_client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
+		return -ENOMEM;
+        
+	memcpy(e680_camera_client,&client_template,sizeof(struct i2c_client));
+	e680_camera_client->adapter = adap;
+        
+    /*adcm2700 i2c client address*/    
+	e680_camera_client->addr = 0x53;
+	i2c_attach_client(e680_camera_client);
+	return 0;
+}	
+
+static int e680_camera_detach(struct i2c_client *client)
+{	
+	i2c_detach_client(e680_camera_client);
+	return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+static int cam_open(struct inode *inode, struct file *file)
+{
+        if(i2c_camera_client_type == I2C_CLIENT_NONE)
+            return -EINVAL;
+
+        //MOD_INC_USE_COUNT;
+        return 0;
+}
+
+static int i2c_camera_readw(unsigned short addr, unsigned short *pvalue);
+static int i2c_camera_readb(unsigned short addr, unsigned char *pvalue);
+static int i2c_camera_writew(unsigned short addr, unsigned short value);
+static int i2c_camera_writeb(unsigned short addr, unsigned char value);
+
+static int cam_close(struct inode * inode, struct file *file)
+{
+        //MOD_DEC_USE_COUNT;
+        return 0;
+}
+
+#define DETECT_BUFLEN 256
+static int cam_ioctl_detectid (void * arg)
+{
+    int    buflen, idlen;
+    char*  id;
+    struct camera_i2c_detectid * param = arg;
+    if(copy_from_user(&buflen, &(param->buflen), sizeof(buflen)))
+    {
+        return -EFAULT;
+    }
+    if(buflen > DETECT_BUFLEN)
+    {
+        return -ENOMEM;
+    }
+    id = kmalloc(DETECT_BUFLEN, GFP_KERNEL);
+    if(id == NULL)
+    {
+        return -ENOMEM;
+    }
+
+    idlen = 0;
+    switch(i2c_camera_client_type)
+    {
+        case I2C_CLIENT_MT9V111:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "MICRON", "MT9V111", i2c_camera_chipid);
+            break;
+        case I2C_CLIENT_ADCM2700:
+            idlen = snprintf(id, DETECT_BUFLEN-1, "%s %s %lx", 
+                            "AGILENT", "ADCM2700", i2c_camera_chipid);
+            break;
+        default:
+            break;
+    }
+    id[DETECT_BUFLEN-1] = 0;
+    idlen = strlen(id)+1;
+    if(buflen < idlen)
+    {
+        kfree(id);
+        return -ENOMEM;
+    }
+    if(copy_to_user(param->data, id, idlen))
+    {
+        kfree(id);
+        return -EFAULT;
+    }
+    kfree(id);
+    return 0;
+}
+
+static int cam_ioctl_register_rw (unsigned int cmd, void * arg)
+{
+    int ret = -ENOTSUPP;
+    struct camera_i2c_register reg;
+    if(copy_from_user(&reg, arg, sizeof(reg)))
+    {
+        return -EFAULT;
+    }
+    switch(cmd)
+    {
+        case CAMERA_I2C_WRITEW:
+            ret=i2c_camera_writew(reg.addr, reg.value.w);
+            break;
+        case CAMERA_I2C_WRITEB:
+            ret=i2c_camera_writeb(reg.addr, reg.value.b);
+            break;
+        case CAMERA_I2C_READW:
+            if((ret=i2c_camera_readw(reg.addr, &(reg.value.w)))>=0)
+            {
+                if(copy_to_user(arg, &reg, sizeof(reg)))
+                    ret = -EFAULT;
+            }
+            break;
+        case CAMERA_I2C_READB:
+            if((ret=i2c_camera_readb(reg.addr, &(reg.value.b)))>=0)
+            {
+                if(copy_to_user(arg, &reg, sizeof(reg)))
+                    ret = -EFAULT;
+            }
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int cam_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+    int ret = -ENOTSUPP;
+    switch (cmd)
+    {
+        case CAMERA_I2C_WRITEW:
+        case CAMERA_I2C_WRITEB:
+        case CAMERA_I2C_READW:
+        case CAMERA_I2C_READB:
+            ret = cam_ioctl_register_rw(cmd, (void *)arg);
+            break;
+        case CAMERA_I2C_DETECTID:
+            ret = cam_ioctl_detectid((void *)arg);
+            break;
+        default:
+            ret = -EINVAL;
+            break;
+    }
+    return ret;
+}
+
+static struct file_operations cam_fops = {
+        ioctl:          cam_ioctl,
+        open:           cam_open,
+        release:        cam_close,
+};
+
+static struct miscdevice cam_misc_device = {
+        CAM_MINOR,
+        CAM_NAME,
+        &cam_fops,
+};
+
+/* ----------------------------------------------------------------------- */
+static int e680_camera_init_module(void)
+{
+	int res;
+	
+	res = i2c_add_driver(&driver);
+	if( res < 0 )
+	{
+		printk("error in add i2c driver\n");
+		return res;
+	}
+    if (misc_register (&cam_misc_device))
+    {
+        printk(KERN_ERR "Couldn't register cam driver\n");
+        return -EIO;
+    }
+
+	return 0;
+}
+
+static void e680_camera_cleanup_module(void)
+{	
+	i2c_del_driver(&driver);
+    misc_deregister(&cam_misc_device);
+}
+/*-----------------------------------------------------------*/
+static int ChgBlockAddr(unsigned char block)
+{
+    static unsigned char old_blk = 0xFF;
+    int res;
+    char tmp[2]={BLOCK_SWITCH_CMD, block};
+    
+    if(block == old_blk)
+    {
+	return 0;
+    }
+    
+    res = e680_camera_write(tmp, 2);
+    if(res < 0)
+    {
+        dbg_print("error code = %d", res);
+	return  -1;
+    }
+    old_blk = block;
+    
+    return 0; 
+}
+
+int adcm2700_read(unsigned short addr, unsigned short *pvalue)
+{
+	unsigned char	blockaddr = BLOCK(addr);
+	unsigned char	offset    = OFFSET_R(addr);
+        int     ret;
+
+	if((ret = ChgBlockAddr(blockaddr)) != 0)  
+	{
+	    dbg_print("Change block address failed. block = 0x%2x", blockaddr);
+	    return -1;
+	}
+        if((ret = e680_camera_write(&offset, 1)) < 0)
+        {
+            dbg_print("i2c write error code =%d", ret);
+            return -1;
+        }
+        
+        ret = e680_camera_read((char *)pvalue, 2); 
+        if(ret < 0)
+        {
+           dbg_print("i2c read error oce = %d", ret);
+           return -1;
+        } 
+	
+	return  *pvalue;
+}	
+int adcm2700_write_byte(unsigned short addr, unsigned char value)
+{
+	unsigned char	blockaddr = BLOCK(addr);
+	unsigned char 	offset    = OFFSET(addr);;
+    char    tmp[3]={offset, value};
+    int     ret;
+		
+	if((ret = ChgBlockAddr(blockaddr)) != 0)  
+	{
+	   dbg_print("Change block address failed. block = 0x%2x", blockaddr);
+	   return -1;
+	}
+	ret = e680_camera_write(tmp, 2);
+        if(ret < 0)
+        {
+          dbg_print("i2c write error code = %d", ret);
+          return -1;
+        }
+    return 0;
+ 
+}
+int adcm2700_read_byte(unsigned short addr, unsigned char * pvalue)
+{
+  	unsigned char	blockaddr = BLOCK(addr);
+	unsigned char 	offset    = OFFSET_R(addr);;
+    int     ret;
+		
+	if((ret = ChgBlockAddr(blockaddr)) != 0)  
+	{
+	   dbg_print("Change block address failed. block = 0x%2x", blockaddr);
+	   return -1;
+	}
+    if((ret = e680_camera_write(&offset, 1)) < 0)
+        {
+            dbg_print("i2c write error code =%d", ret);
+            return -1;
+        }
+        
+        ret = e680_camera_read((char *)pvalue, 1); 
+        if(ret < 0)
+        {
+           dbg_print("i2c read error oce = %d", ret);
+           return -1;
+        } 
+    return 0;
+
+}
+int adcm2700_write(unsigned short addr, unsigned short value)
+{
+	unsigned char	blockaddr = BLOCK(addr);
+	unsigned char 	offset    = OFFSET(addr);;
+        char    tmp[3]={offset, (char)(value&0xFF), (char)(value>>8)};
+        int     ret;
+		
+	if((ret = ChgBlockAddr(blockaddr)) != 0)  
+	{
+	   dbg_print("Change block address failed. block = 0x%2x", blockaddr);
+	   return -1;
+	}
+	ret = e680_camera_write(tmp, 3);
+        if(ret < 0)
+        {
+          dbg_print("i2c write error code = %d", ret);
+          return -1;
+        }
+        return 0;
+}
+
+int i2c_adcm2700_cleanup(void)
+{
+  i2c_camera_client_type = I2C_CLIENT_NONE;
+  return 0;
+} 
+int i2c_adcm2700_init(void)
+{
+    unsigned short chipid;
+    unsigned short adcm_chipids[] = {ADCM2700_CHIP_ID, ADCM2700_CHIP_ID_NEW, 0x62};
+    int i;
+    e680_camera_client->addr = 0x53;
+ 
+    if(adcm2700_read(0, &chipid) < 0)
+    {
+       return -1;
+    }
+
+    dbg_print("CHIP ID IS %x", chipid);
+    
+    for(i = 0; i < sizeof(adcm_chipids)/sizeof(adcm_chipids[0]); i++)
+    {
+       if(chipid == adcm_chipids[i])
+          break;	       
+    }
+    
+    if(i >= sizeof(adcm_chipids)/sizeof(adcm_chipids[0]))
+    {
+       return -1;
+    } 
+
+   i2c_camera_client_type = I2C_CLIENT_ADCM2700;
+   i2c_camera_chipid = chipid;
+    
+   return 0;
+}
+//=======================================================================
+static int  mt9v111_addr_select(unsigned char addrSpace)
+{
+  int    ret;
+  static u8 curSpace = 0;
+  char   buf[3] = {REG_ADDRSELECT, 0, addrSpace};
+
+  if(curSpace != addrSpace)
+  {
+    if((ret = e680_camera_write(buf, 3)) < 0)
+    {
+       dbg_print("i2c write error code = %d", ret);
+       return  ret;
+    }
+    curSpace = addrSpace;
+  }
+  return 0;
+}
+
+int mt9v111_read(unsigned char addrSpace, unsigned short addr)
+{
+    unsigned short value;
+    unsigned char  reg_addr = (unsigned char)addr;
+    
+    if(addr != REG_ADDRSELECT)
+    {
+      if(mt9v111_addr_select(addrSpace) != 0)
+      {
+        dbg_print("Address space select  failed. addrSpace = 0x%2x", addrSpace);
+        return -1;
+      }
+    }
+    if(e680_camera_write(&reg_addr, 1) < 0)
+    {
+       return -1;
+    }
+
+	if(e680_camera_read((char *)&value, 2) < 0)
+    {
+        return -1;
+    }
+    
+    value = (value << 8 | value >> 8);
+    return value;
+}	
+
+int mt9v111_write(unsigned char addrSpace, unsigned short addr, unsigned short value)
+{
+    int  ret;
+    char buf[3] = {(char)addr, (char)(value>>8), (char)value};
+    
+    if(addr != REG_ADDRSELECT)
+    {
+      if(mt9v111_addr_select(addrSpace) != 0)
+      {
+       dbg_print("Address space select  failed. addrSpace = 0x%2x", addrSpace);
+       return -1;
+      }
+    }
+    
+    if((ret = e680_camera_write(buf, 3)) < 0)
+    {
+      dbg_print("write error code = %d", ret);
+    }
+    
+	return ret;
+}	
+int i2c_mt9v111_cleanup(void)
+{
+  i2c_camera_client_type = I2C_CLIENT_NONE;
+  return 0;
+} 
+int i2c_mt9v111_init(void)
+{
+    int chipid;
+    e680_camera_client->addr = 0x5C;
+ 
+    if((chipid = mt9v111_read(0x04, 0x36)) < 0)
+    {
+       return -1;
+    }
+    
+    if((chipid & 0xFF00) != 0x8200)
+    {
+       return -1;
+    } 
+
+   i2c_camera_client_type = I2C_CLIENT_MT9V111;
+   i2c_camera_chipid = chipid;
+    
+   return 0;
+
+}
+
+static int i2c_camera_readw(unsigned short addr, unsigned short *pvalue)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+        case I2C_CLIENT_MT9V111:
+            ret = mt9v111_read((addr>>8), (addr&0xFF));
+            if(ret > 0)
+            {
+               *pvalue = (u16)ret;
+            }
+            break;
+        case I2C_CLIENT_ADCM2700:
+            ret = adcm2700_read(addr, pvalue);
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_readb(unsigned short addr, unsigned char *pvalue)
+{
+    int ret = -ENOTSUPP;
+    unsigned short value;
+    switch(i2c_camera_client_type)
+    {
+        case I2C_CLIENT_ADCM2700:
+            ret = adcm2700_read(addr, &value);
+            *pvalue = (value>>8);
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_writew(unsigned short addr, unsigned short value)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+        case I2C_CLIENT_MT9V111:
+            ret = mt9v111_write((addr>>8), (addr&0xFF), value);
+            break;
+        case I2C_CLIENT_ADCM2700:
+            ret = adcm2700_write(addr, value);
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+static int i2c_camera_writeb(unsigned short addr, unsigned char value)
+{
+    int ret = -ENOTSUPP;
+    switch(i2c_camera_client_type)
+    {
+        case I2C_CLIENT_ADCM2700:
+            ret = adcm2700_write_byte(addr, value);
+            break;
+        default:
+            break;
+    }
+    return ret;
+}
+
+
+EXPORT_SYMBOL(i2c_adcm2700_init);
+EXPORT_SYMBOL(adcm2700_write);
+EXPORT_SYMBOL(adcm2700_write_byte);
+EXPORT_SYMBOL(adcm2700_read_byte);
+EXPORT_SYMBOL(adcm2700_read);
+EXPORT_SYMBOL(i2c_adcm2700_cleanup);
+
+EXPORT_SYMBOL(i2c_mt9v111_init);
+EXPORT_SYMBOL(mt9v111_write);
+EXPORT_SYMBOL(mt9v111_read);
+EXPORT_SYMBOL(i2c_mt9v111_cleanup);
+
+module_init(e680_camera_init_module);
+module_exit(e680_camera_cleanup_module);
+MODULE_AUTHOR("Jay Jia");
+MODULE_LICENSE("GPL");
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/i2c-adcm2700.h linux-2.6.16.5-exz/drivers/i2c/chips/i2c-adcm2700.h
--- linux-2.6.16.5/drivers/i2c/chips/i2c-adcm2700.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/i2c-adcm2700.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,65 @@
+
+/*================================================================================
+                                                                               
+                      Header Name: i2c-adcm2700.h
+
+General Description: Camera module adcm2700 I2C interface head file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      12/15/2003     LIBdd35749    Created   
+wangfei(w20239)      02/26/2004     LIBdd81055    New chip id support
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef  __I2C_ADCM2700_H__
+#define  __I2C_ADCM2700_H__
+
+#define DEBUG
+
+/* Calculating the Module Block Number */
+#define BLOCK(a)    ((u8)(((a) >> 7) & 0x7F))     /* register's module block address. */
+#define OFFSET(a)   ((u8)(((a) << 1) & 0xFF))     /* register's offset to this block. */
+#define OFFSET_R(a) (OFFSET(a)|1)                 /* register's offset ot this block to read*/     
+
+#define BLOCK_SWITCH_CMD        0xFE
+#define ADCM2700_I2C_ADDR       0x53
+#define I2C_DRIVERID_ADCM2700   I2C_DRIVERID_EXP1
+#define ADCM2700_CHIP_ID        0x0060
+#define ADCM2700_CHIP_ID_NEW    0x0061
+#define REV_ID                  0x0               /* Register definitions in ADCM2700's chip. */
+
+
+struct adcm2700_data {
+    /*
+     *  Because the i2c bus is slow, it is often useful to cache the read
+     *  information of a chip for some time (for example, 1 or 2 seconds).
+     *  It depends of course on the device whether this is really worthwhile
+     *  or even sensible.
+     */
+    struct semaphore update_lock; /* When we are reading lots of information,
+                                     another process should not update the
+                                     below information */
+
+    char valid;                   /* != 0 if the following fields are valid. */
+    int  blockaddr;               /* current using block address.    */
+    unsigned long last_updated;   /* In jiffies */
+};
+
+#ifdef DEBUG
+#define dbg_print(fmt, args...) printk(KERN_INFO "I2C-ADCM2700 in fun:%s "fmt"\n", __FUNCTION__, ##args)
+#else
+#define dbg_print(fmt, args...) ;
+#endif
+
+#endif  /* __I2C_ADCM2700_H__ */
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/i2c-ov9640.c linux-2.6.16.5-exz/drivers/i2c/chips/i2c-ov9640.c
--- linux-2.6.16.5/drivers/i2c/chips/i2c-ov9640.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/i2c-ov9640.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,303 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <asm/hardware.h>
+#include <asm/types.h>
+#include <linux/delay.h>
+
+#include "i2c-ov9640.h"
+
+#define DEBUG 1
+#define DPRINTK(fmt,args...)	do { if (DEBUG) printk("in function %s "fmt,__FUNCTION__,##args);} while(0)
+extern int i2c_adapter_id(struct i2c_adapter *adap);
+
+int  i2c_ov9640_cleanup(void);
+void i2c_ov9640_inc_use (struct i2c_client *client);
+void i2c_ov9640_dec_use (struct i2c_client *client);
+int  i2c_ov9640_attach_adapter(struct i2c_adapter *adapter);
+int  i2c_ov9640_detect_client(struct i2c_adapter *, int, unsigned short, int);
+int  i2c_ov9640_detach_client(struct i2c_client *client);
+
+struct i2c_driver ov9640_driver  = 
+{
+	name:			"ov9640 driver",	            /* name           */
+	id:			I2C_DRIVERID_OV9640,         	    /* id             */
+	flags:			I2C_DF_NOTIFY,        		    /* flags          */
+	attach_adapter:		&i2c_ov9640_attach_adapter,       /* attach_adapter */
+	detach_client:		&i2c_ov9640_detach_client,        /* detach_client  */
+	command:		NULL,
+	inc_use:		&i2c_ov9640_inc_use,
+	dec_use:		&i2c_ov9640_dec_use
+};
+
+extern  struct i2c_adapter *i2cdev_adaps[];
+/* Unique ID allocation */
+static int ov9640_id = 0;
+struct i2c_client *g_client = NULL;
+static unsigned short normal_i2c[] = {OV9640_SLAVE_ADDR ,I2C_CLIENT_END };
+static unsigned short normal_i2c_range[] = { I2C_CLIENT_END }; 
+I2C_CLIENT_INSMOD;
+
+/* 
+ * This call returns a unique low identifier for each registered adapter,
+ * or -1 if the adapter was not registered.
+ */
+void i2c_ov9640_inc_use (struct i2c_client *client)
+{
+	MOD_INC_USE_COUNT;
+#ifdef MODULE
+#endif
+}
+
+void i2c_ov9640_dec_use (struct i2c_client *client)
+{
+	MOD_DEC_USE_COUNT;
+#ifdef MODULE
+#endif
+}
+
+char ov9640_read(u8 addr, u8 *pvalue)
+{
+	int	res=0;
+	char 	buf=0;
+	struct i2c_msg msgs[2] = {
+		{ 0, I2C_M_WR, 1, &addr },
+		{ 0, I2C_M_RD, 1, &buf }};
+	
+	if( g_client == NULL )	
+		return -1;
+	i2c_ov9640_inc_use(g_client);
+	msgs[0].addr=msgs[1].addr=g_client->addr;
+	res=i2c_transfer(g_client->adapter,&msgs[0],1);
+	if (res<=0) 
+		goto out;
+	res=i2c_transfer(g_client->adapter,&msgs[1],1);
+	if (res<=0) 
+		goto out;
+	*pvalue = buf;
+	i2c_ov9640_dec_use(g_client);
+out:
+	DPRINTK(KERN_INFO "In funtion %s addr:%x,value=%x\n", __FUNCTION__, addr,*pvalue);
+	if (res<=0) DPRINTK("res = %d \n",res);
+	return res;
+}	
+
+int ov9640_write(u8 addr, u8 value)
+{
+	int	res=0;
+	if( g_client == NULL )
+		return -1;
+	/*
+	char 	buf=0;
+	struct i2c_msg msgs[2] = {
+		{ 0, I2C_M_WR, 1, &addr },
+		{ 0, I2C_M_WR, 1, &value }};
+	msgs[0].addr=msgs[1].addr=g_client->addr;
+	res=i2c_transfer(g_client->adapter,&msgs[0],1);
+	if (res<=0) return res;
+	res=i2c_transfer(g_client->adapter,&msgs[1],1);
+	if (res<=0) return res;
+
+
+	res=i2c_smbus_write_byte_data(g_client, addr, value );
+	*/
+	char 	buf[2]={addr,value};
+	i2c_ov9640_inc_use(g_client);
+	res = i2c_master_send(g_client, buf, 2);
+	i2c_ov9640_dec_use(g_client);
+	if (res >0) res =0;
+	else res =-1;
+	DPRINTK(KERN_INFO "In funtion %s addr:%x value:%xreturn %d \n", __FUNCTION__, addr,value,res);
+	return res;
+}	
+
+
+int i2c_ov9640_read(struct i2c_client *client, u8 reg)
+{
+	unsigned char msgbuf=0;
+	DPRINTK("in function %s\n",__FUNCTION__);
+	i2c_master_recv(client,&msgbuf,1);
+	return msgbuf;
+	/*
+	*/
+//    return i2c_smbus_read_word_data(client,reg);
+//  return i2c_smbus_read_byte_data(client,reg);
+}
+
+int i2c_ov9640_write(struct i2c_client *client, u8 reg, u16 value)
+{
+    return i2c_smbus_write_word_data(client,reg,value);
+}
+
+
+int i2c_ov9640_attach_adapter(struct i2c_adapter *adap)
+{
+	DPRINTK("In function %s.\n", __FUNCTION__);
+	return i2c_probe(adap,&addr_data,i2c_ov9640_detect_client);
+}
+
+
+int i2c_ov9640_detect_client(struct i2c_adapter *adapter, int address, unsigned short flags, int kind)
+{
+    struct i2c_client *new_client;
+    int err = 0;
+    struct ov9640_data *data;
+    
+    /*check if */
+    if(g_client != NULL) {
+      err = -ENXIO;
+      goto ERROR0;
+    }
+ 
+
+	DPRINTK(KERN_INFO "In funtion %s. address=0X%X\n", __FUNCTION__, address);
+    /* Let's see whether this adapter can support what we need.
+       Please substitute the things you need here!  */
+	if ( !i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA) ) {
+		DPRINTK(KERN_INFO "Word op is not permited.\n");
+		goto ERROR0;
+	}
+
+    /* OK. For now, we presume we have a valid client. We now create the
+       client structure, even though we cannot fill it completely yet.
+       But it allows us to access several i2c functions safely */
+    
+    /* Note that we reserve some space for ov9640_data too. If you don't
+       need it, remove it. We do it here to help to lessen memory
+       fragmentation. */
+
+    new_client=kmalloc(sizeof(struct i2c_client)+sizeof(struct ov9640_data),
+		  				GFP_KERNEL );
+
+    if ( !new_client )  {
+      err = -ENOMEM;
+      goto ERROR0;
+    }
+
+	data = (struct ov9640_data *) (new_client + 1);
+
+	new_client->addr = address;	
+	new_client->data = data;
+	new_client->adapter = adapter;
+	new_client->driver = &ov9640_driver;
+	new_client->flags = 0;
+
+    g_client = new_client;
+
+    /* Now, we do the remaining detection. If no `force' parameter is used. */
+
+    /* First, the generic detection (if any), that is skipped if any force
+       parameter was used. */
+
+	if (kind <= 0) {
+                 char res = -1;
+		mdelay(2000);
+		 ov9640_read(REV,&res);
+		/* The below is of course bogus */
+		DPRINTK("I2C: Probe ov9640 chip..addr=0x%x, REV=%d, res=0x%x\n", address, REV, res);
+                /*ov9640 chip id is 0x9648
+                 if(res != OV9640_CHIP_ID) {
+			DPRINTK(KERN_WARNING "Failed.product id =%d \n",res);
+			goto ERROR1;
+		 }		 
+		else {
+                       DPRINTK("OV9640 chip id is 0X%04X\n", OV9640_CHIP_ID);
+			if ( ov9640_id == 0 )
+				DPRINTK(" detected.\n");
+		}*/
+	}
+
+	strcpy(new_client->name, "ov9640");
+    /* Automatically unique */
+    new_client->id = ov9640_id++; 
+
+    /* Only if you use this field */
+	data->valid = 0; 
+
+    /* Only if you use this field */
+	init_MUTEX(&data->update_lock); 
+
+    /* Tell the i2c layer a new client has arrived */
+    if ((err = i2c_attach_client(new_client)))
+      goto ERROR3;
+
+    /* This function can write default values to the client registers, if
+       needed. */
+	/*	ov9640_init_client(new_client);	*/
+    return 0;
+
+    /* OK, this is not exactly good programming practice, usually. But it is
+       very code-efficient in this case. */
+
+ERROR3:
+ERROR1:
+      kfree(new_client);
+      g_client = NULL;
+ERROR0:
+      return err;
+}
+
+int i2c_ov9640_detach_client(struct i2c_client *client)
+{
+	int err;
+
+    /* Try to detach the client from i2c space */
+    if ((err = i2c_detach_client(client))) {
+      DPRINTK("ov9640.o: Client deregistration failed, client not detached.\n");
+      return err;
+    }
+
+    kfree(client); /* Frees client data too, if allocated at the same time */
+    g_client = NULL;
+    return 0;
+}
+
+/* 	Keep track of how far we got in the initialization process. If several
+	things have to initialized, and we fail halfway, only those things
+	have to be cleaned up! */
+static int ov9640_initialized = 0;
+
+int i2c_ov9640_init(void)
+{
+	int res;
+
+	if (ov9640_initialized) 
+		return 0;
+	DPRINTK("I2C: driver for device ov9640.\n");
+	if ( (res = i2c_add_driver(&ov9640_driver)) ) {
+		DPRINTK("ov9640: Driver registration failed, module not inserted.\n");
+		i2c_ov9640_cleanup();
+		return res;
+	}
+	ov9640_initialized ++;
+        if(g_client != NULL)
+   	   DPRINTK("I2C: driver for device %s registed!.\n", g_client->name);
+        else 
+           DPRINTK("I2C: driver for device unregisted!.\n");
+	return 0;
+}
+
+int i2c_ov9640_cleanup(void)
+{
+	int res;
+
+	if (ov9640_initialized == 1) {
+		if ((res = i2c_del_driver(&ov9640_driver))) {
+			DPRINTK("ov9640: Driver registration failed, module not removed.\n");
+			return res;
+		}
+		ov9640_initialized --;
+	}
+	return 0;
+}
+
+EXPORT_SYMBOL(i2c_ov9640_init);
+EXPORT_SYMBOL(ov9640_write);
+EXPORT_SYMBOL(ov9640_read);
+EXPORT_SYMBOL(i2c_ov9640_cleanup);
+//module_init(i2c_ov9640_init);
+//module_exit(i2c_ov9640_cleanup);
+MODULE_LICENSE("GPL");
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/i2c/chips/i2c-ov9640.h linux-2.6.16.5-exz/drivers/i2c/chips/i2c-ov9640.h
--- linux-2.6.16.5/drivers/i2c/chips/i2c-ov9640.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/i2c/chips/i2c-ov9640.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,42 @@
+#ifndef  __I2C_OV9640_H__
+#define  __I2C_OV9640_H__
+
+#define DEBUG
+
+/* Calculating the Module Block Number */
+#define BLOCK(a)    (u8)((a) >> 7)      /* register's module block address. */
+#define OFFSET(a)   (u8)((a) & 0x7F )   /* register's offset to this block. */
+
+/*  Update the block address.*/
+#define BLOCK_SWITCH_CMD    0xFE
+
+#define OV9640_SLAVE_ADDR (0x60>>1)	/* 60 for write , 61 for read */
+// #define SENSOR_SLAVE_ADDR   0x0055      /* tbd: */
+
+
+#define I2C_DRIVERID_OV9640   I2C_DRIVERID_EXP2
+
+/*ov9640 chip id*/
+#define OV9640_CHIP_ID  0x9648
+
+/* Register definitions in OV9640's chip. */
+#define PID	0xA
+#define REV     0xA
+
+struct ov9640_data {
+    /*
+     *  Because the i2c bus is slow, it is often useful to cache the read
+     *  information of a chip for some time (for example, 1 or 2 seconds).
+     *  It depends of course on the device whether this is really worthwhile
+     *  or even sensible.
+     */
+    struct semaphore update_lock; /* When we are reading lots of information,
+                                     another process should not update the
+                                     below information */
+
+    char valid;                   /* != 0 if the following fields are valid. */
+    int  blockaddr;               /* current using block address.    */
+    unsigned long last_updated;   /* In jiffies */
+};
+#endif
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/Kconfig linux-2.6.16.5-exz/drivers/media/video/Kconfig
--- linux-2.6.16.5/drivers/media/video/Kconfig	2006-04-12 22:27:57.000000000 +0200
+++ linux-2.6.16.5-exz/drivers/media/video/Kconfig	2006-04-16 18:49:29.000000000 +0200
@@ -354,4 +354,35 @@
 	  Say Y here to compile drivers for SAA7115, SAA7127 and CX25840
 	  video decoders.
 
+config PXA_CAMERA
+	depends on VIDEO_DEV
+	tristate "Camera Interface for PXA27x"
+
+choice
+	prompt "PXA27x Camera Type"
+	depends on PXA_CAMERA
+
+config CAMERA_ADCM2700
+	select I2C_ADCM2700
+	bool "ADCM2700"
+
+config CAMERA_MT9M111
+	select I2C_A780_CAMERA
+	bool "Mt9m111"
+
+config CAMERA_OV9640
+	select I2C_A780_CAMERA
+	bool "Omnivision 9640"
+
+config CAMERA_OV9650
+	select I2C_A780_CAMERA
+	bool "Omnivision 9650"
+
+config CAMERA_ADCM3800
+	select I2C_A780_CAMERA
+	bool "ADCM3900"
+
+endchoice
+	
+
 endmenu
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/Makefile linux-2.6.16.5-exz/drivers/media/video/Makefile
--- linux-2.6.16.5/drivers/media/video/Makefile	2006-04-12 22:27:57.000000000 +0200
+++ linux-2.6.16.5-exz/drivers/media/video/Makefile	2006-04-16 18:49:29.000000000 +0200
@@ -19,6 +19,14 @@
 	tda7432.o tda9875.o ir-kbd-i2c.o
 obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
 
+obj-$(CONFIG_PXA_CAMERA) += pxa_camera.o
+
+obj-$(CONFIG_CAMERA_ADCM2700) += adcm2700.o adcm2700_hw.o
+obj-$(CONFIG_CAMERA_OV9640) += ov9640.o ov9640_hw.o
+obj-$(CONFIG_CAMERA_OV9650) += ov9650.o ov9650_hw.o
+obj-$(CONFIG_CAMERA_MT9M111) += mt9m111.o mt9m111_hw.o
+obj-$(CONFIG_CAMERA_ADCM3800) += adcm3800.o adcm3800_hw.o
+
 obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
 obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o
 obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm2700.c linux-2.6.16.5-exz/drivers/media/video/adcm2700.c
--- linux-2.6.16.5/drivers/media/video/adcm2700.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm2700.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,644 @@
+ 
+/*================================================================================
+                                                                               
+                      Header Name: adcm2700.c
+
+General Description: Camera module adcm2700 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      12/15/2003     LIBdd35749   Created   
+wangfei(w20239)      02/05/2004     LIBdd74309   Set frame rate in video mode
+wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
+                                                 Update algorithm for DMA transfer
+                                                 Update strategy for memory management
+                                                 Fix still picture capture failed sometime
+                                                 New Agilent sensor chip ID support
+                                                 Make output height in an even multiple of 8
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+
+#include <asm/pgtable.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include <asm/arch/pxa-regs.h>
+
+#include "camera.h"
+#include "adcm2700.h"
+#include "adcm2700_hw.h"
+
+
+/***********************************************************************
+ *
+ * ADCM2700  and MT9v111 common functions
+ *
+ ***********************************************************************/
+#define MAX_WIDTH          640
+#define MAX_HEIGHT         480
+#define MIN_WIDTH          64
+#define MIN_HEIGHT         64
+#define WIDTH_DEFT         240
+#define HEIGHT_DEFT        320
+#define FRAMERATE_DEFT	   15
+#define MCLK_DEFT          6             /* Default Master clock*/
+#define BUF_SIZE_DEFT      ((PAGE_ALIGN(MAX_WIDTH * MAX_HEIGHT) + (PAGE_ALIGN(MAX_WIDTH*MAX_HEIGHT/2)*2)))
+
+extern int i2c_adcm2700_init(void);
+extern int i2c_mt9v111_init(void);
+
+//////////////////////////////////////////////////////////////////////////////////////
+//adcm2700 functions
+//
+int camera_func_adcm2700_init(p_camera_context_t);
+int camera_func_adcm2700_deinit(p_camera_context_t);
+int camera_func_adcm2700_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+int camera_func_adcm2700_set_capture_format(p_camera_context_t);
+int camera_func_adcm2700_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_adcm2700_stop_capture(p_camera_context_t);
+
+int camera_func_adcm2700_pm_management(p_camera_context_t, int);
+
+//////////////////////////////////////////////////////////////////////////////////////
+//mt9v111 functions
+//
+int camera_func_mt9v111_init(p_camera_context_t);
+int camera_func_mt9v111_deinit(p_camera_context_t);
+int camera_func_mt9v111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+int camera_func_mt9v111_set_capture_format(p_camera_context_t);
+int camera_func_mt9v111_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_mt9v111_stop_capture(p_camera_context_t);
+
+int camera_func_mt9v111_pm_management(p_camera_context_t, int);
+
+int camera_func_init(p_camera_context_t cam_ctx);
+
+
+camera_function_t  e680_camera_func = 
+{
+   init:                camera_func_init,
+};
+
+int camera_func_init(p_camera_context_t cam_ctx)
+{
+    int ret = 0;
+    // init context status
+    cam_ctx->dma_channels[0] = 0xFF;
+    cam_ctx->dma_channels[1] = 0xFF;
+    cam_ctx->dma_channels[2] = 0xFF;
+    
+    cam_ctx->capture_width  = WIDTH_DEFT;
+    cam_ctx->capture_height = HEIGHT_DEFT;
+    
+    cam_ctx->capture_input_format  = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    
+    cam_ctx->frame_rate = cam_ctx->fps = FRAMERATE_DEFT;
+    
+    cam_ctx->mini_fps = FRAMERATE_DEFT-5;
+    
+    cam_ctx->mclk = MCLK_DEFT;
+    cam_ctx->flicker_freq = 50;
+    
+    cam_ctx->buf_size     = BUF_SIZE_DEFT;
+    cam_ctx->dma_descriptors_size = (cam_ctx->buf_size/PAGE_SIZE + 10);
+    cam_ctx->vc.maxwidth  = MAX_WIDTH;
+    cam_ctx->vc.maxheight = MAX_HEIGHT;
+    cam_ctx->vc.minwidth  = MIN_WIDTH; 
+    cam_ctx->vc.minheight = MIN_HEIGHT;
+       
+    camera_gpio_init();
+    ci_init();
+    
+    // Configure CI according to hardware
+  	// master parallel with 8 data pins
+   	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8); 
+
+  	// enable pixel clock(sensor will provide pclock)
+   	ci_set_clock(cam_ctx->clk_reg_base, 1, 1, cam_ctx->mclk);
+
+   	// data sample on rising and h,vsync active high
+   	ci_set_polarity(0, 0, 0);
+	
+   	// fifo control
+   	ci_set_fifo(0, CI_FIFO_THL_32, 1, 1); // quality
+
+   	// Turn on M_CLK using xx MHz and wait for 150 ms.
+    ci_enable(1);
+    
+    mdelay(150);
+    
+    if(i2c_adcm2700_init() == 0)
+    {
+        cam_ctx->sensor_type = CAMERA_TYPE_ADCM_2700;
+        e680_camera_func.deinit             = camera_func_adcm2700_deinit;
+        e680_camera_func.command            = camera_func_adcm2700_docommand;
+        e680_camera_func.set_capture_format = camera_func_adcm2700_set_capture_format;
+        e680_camera_func.start_capture      = camera_func_adcm2700_start_capture; 
+        e680_camera_func.stop_capture       = camera_func_adcm2700_stop_capture;
+        e680_camera_func.pm_management      = camera_func_adcm2700_pm_management;
+
+        if((ret =  camera_func_adcm2700_init(cam_ctx)) < 0)
+        {
+         dbg_print("adcm2700 init error! capture format!");
+         return -1;
+        }
+        ddbg_print("Agilent ADCM2700 camera module detected!");
+    }
+    else if(i2c_mt9v111_init() == 0)
+    {
+        cam_ctx->sensor_type = CAMERA_TYPE_MT9V111;
+
+        e680_camera_func.deinit             = camera_func_mt9v111_deinit;
+        e680_camera_func.command            = camera_func_mt9v111_docommand;
+        e680_camera_func.set_capture_format = camera_func_mt9v111_set_capture_format;
+        e680_camera_func.start_capture      = camera_func_mt9v111_start_capture; 
+        e680_camera_func.stop_capture       = camera_func_mt9v111_stop_capture;
+        e680_camera_func.pm_management      = camera_func_mt9v111_pm_management;
+        if((ret =  camera_func_mt9v111_init(cam_ctx)) < 0)
+        {
+         dbg_print("mt9v111 init error! capture format!");
+         return -1;
+        }
+        ddbg_print("Micro MT9V111 camera module detected!");
+    }
+    else
+    {
+       dbg_print("no camera sensor detected!!!\n");
+       return -1;
+    }
+
+    return 0;
+}
+
+/***********************************************************************
+ *
+ * ADCM2700 Functions
+ *
+ ***********************************************************************/
+int camera_func_adcm2700_init(  p_camera_context_t camera_context )
+{
+    u16 sensor_rev, cm_rev;
+    int i;
+    adcm2700_power_on(camera_context->mclk);
+    //read out version
+    //adcm2700_version_revision(&cm_rev, &sensor_rev);
+    return 0;
+}
+
+int camera_func_adcm2700_deinit(  p_camera_context_t camera_context )
+{
+    /* power off the external module */
+    camera_func_adcm2700_stop_capture(camera_context);
+    /* disable CI */
+    ci_disable(1);
+	
+    i2c_adcm2700_cleanup();
+   	camera_gpio_deinit();
+    return 0;
+}
+
+int camera_func_adcm2700_set_capture_format(p_camera_context_t camera_context)
+{
+    u16 adcm_format;
+    adcm_window_size size;
+
+	   //set sensor format
+    switch(camera_context->capture_input_format)
+    {
+        case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+        case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+ 	          adcm_format = O_FORMAT_422_B_YCbYCr;
+        break;
+        case CAMERA_IMAGE_FORMAT_RGB565:
+            adcm_format = O_FORMAT_565_RGB;
+        break;
+        case CAMERA_IMAGE_FORMAT_RGB888_PACKED:
+        case CAMERA_IMAGE_FORMAT_RGB888_PLANAR:
+   	        adcm_format = O_FORMAT_888RGB;
+        break;
+        default:
+  		        adcm_format = O_FORMAT_422_B_YCbYCr;
+        break;
+    }
+    size.width  = camera_context->capture_width;
+    size.height = camera_context->capture_height;
+    //adcm2700_output_size(&size);
+  	//adcm2700_viewfinder_cfg_output(adcm_format);
+   return 0;
+}
+
+int camera_func_adcm2700_start_capture(p_camera_context_t cam_ctx, unsigned int frames)
+{   
+    int   cisr;
+    int   wait_count;
+    int   error_count = 0;
+    static int error_times = 0;
+ 
+start:    
+  
+    // frames=0 means video mode capture	
+    if(frames == 0) 
+    {
+       // ddbg_print("video capture!"); 
+       wait_count = 1;
+       adcm2700_restore_property(cam_ctx, frames);
+       adcm2700_viewfinder_on();
+       ci_disable(1);
+       ci_enable(1);       
+ 
+    }
+    else 
+    {
+       // ddbg_print("still capture");
+       
+        wait_count = 1;
+        adcm2700_restore_property(cam_ctx, frames);
+        adcm2700_snapshot_trigger();
+        ci_disable(1);
+        ci_enable(1);       
+
+    }
+
+    dbg_print("wait for EOF %d time", wait_count);
+    unsigned int start_time = 0xFFFFF * 20 * wait_count;
+    unsigned int flags;
+    
+  //  local_irq_save(flags);
+    CISR |= CI_CISR_EOF;       
+    CISR |= CI_CISR_SOF;       
+    cisr=CISR;
+    while(wait_count)
+    {
+       if(cisr & CI_CISR_EOF)
+       {
+          //wait_count -- ;
+          CISR |= CI_CISR_EOF;
+       }   
+       
+       if(cisr & CI_CISR_SOF)
+       {
+          wait_count -- ;
+          CISR |= CI_CISR_SOF;
+       }   
+              
+       cisr=CISR;
+       if(!(--start_time))
+       {
+          goto wait_EOF_error;
+       }
+
+    }
+    ci_disable(1);
+    ci_enable(1);
+    ci_reset_fifo();
+    ci_clear_int_status(0xFFFFFFFF);
+    mdelay(1);
+    start_dma_transfer(cam_ctx, cam_ctx->block_header);
+//    local_irq_restore(flags);
+    dbg_print("wait ok..%d", start_time);
+    return 0;
+    
+wait_EOF_error:
+   // local_irq_restore(flags);
+    error_times++;
+    if(error_count++ >= 3)
+    {
+      return -1;
+    }
+    dbg_print("wait EOF error! error_count = %d", error_count);
+    dbg_print("wait EOF error! error_times = %d", error_times);    
+    dbg_print("Reset CIF and camera...");
+    ci_disable(1);
+   // master parallel with 8 data pins
+    ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8); 
+  	 // enable pixel clock(sensor will provide pclock)
+    ci_set_clock(cam_ctx->clk_reg_base, 1, 1, cam_ctx->mclk);
+  	 // data sample on rising and h,vsync active high
+    ci_set_polarity(0, 0, 0);
+    // fifo control
+    ci_set_fifo(0, CI_FIFO_THL_32, 1, 1); // quality
+    // Turn on M_CLK using xx MHz and wait for 150 ms.
+    ci_enable(1);
+    mdelay(10);
+    adcm2700_power_on(cam_ctx->mclk);
+    goto start;
+}
+
+int camera_func_adcm2700_stop_capture(p_camera_context_t cam_ctx)
+{
+    adcm2700_viewfinder_off();
+    stop_dma_transfer(cam_ctx);
+    return 0;
+}
+
+int camera_func_adcm2700_pm_management(p_camera_context_t cam_ctx, int suspend)
+{
+    static int resume_dma = 0;
+    if(suspend)
+    {
+        if(cam_ctx != NULL )
+        {
+            if(cam_ctx->dma_started) 
+            {
+                ddbg_print("camera running, suspended");
+                stop_dma_transfer(cam_ctx);
+                resume_dma = 1;
+            }
+        }
+
+        disable_irq(IRQ_CAMERA);
+        pxa_set_cken(CKEN24_CAMERA, 0);
+    }
+    else
+    {
+        pxa_set_cken(CKEN24_CAMERA, 1);
+        enable_irq(IRQ_CAMERA);
+
+        if(cam_ctx != NULL)
+        {  
+            ddbg_print("camera running, resumed");
+            camera_init(cam_ctx);
+            if(resume_dma == 1)
+            {
+                camera_start_video_capture(cam_ctx, 0);
+                resume_dma = 0;
+            }
+        }
+    }
+   return 0;
+}
+
+/*set picture brightness*/
+static int pxa_cam_WCAM_VIDIOCSBRIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   ddbg_print("WCAM_VIDIOCSBRIGHT");
+   int ret = 0;
+   if(cam_ctx->capture_bright != (int)param)
+   {
+     cam_ctx->capture_bright = (int)param;
+     ret = adcm2700_set_bright(cam_ctx->capture_bright);
+   }
+   return ret;
+}
+
+/*set picture style*/  
+static int pxa_cam_WCAM_VIDIOCSSTYLE(p_camera_context_t cam_ctx, void * param)
+{
+  ddbg_print("WCAM_VIDIOCSSTYLE");
+  int ret = 0;
+  if(cam_ctx->capture_style != (V4l_PIC_STYLE)param)
+  {
+     cam_ctx->capture_style = (V4l_PIC_STYLE)param;
+     if(cam_ctx->dma_started == 1)
+      {
+         camera_func_adcm2700_stop_capture(cam_ctx);
+         ret = camera_func_adcm2700_start_capture(cam_ctx, 0);
+      } 
+
+  }
+  
+  return ret;
+}
+
+        
+/*set picture light*/     
+static int pxa_cam_WCAM_VIDIOCSLIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   
+   dbg_print("WCAM_VIDIOCSLIGHT");
+   int ret = 0;
+   if(cam_ctx->capture_light != (V4l_PIC_WB)param)
+   {
+      cam_ctx->capture_light = (V4l_PIC_WB)param;
+      if(cam_ctx->dma_started == 1)
+      {
+         camera_func_adcm2700_stop_capture(cam_ctx);
+         ret = camera_func_adcm2700_start_capture(cam_ctx, 0);
+      }
+ 
+   }
+   return ret;
+}
+
+
+//set  output size
+static int pxa_cam_WCAM_VIDIOCSOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+
+   //ddbg_print("WCAM_VIDIOCSOSIZE");
+   
+   adcm_window_size size;
+   CI_MP_TIMING     timing;
+   int ret = 0;
+ 
+   if(copy_from_user(&size, param, sizeof(adcm_window_size))) 
+   {
+        return  -EFAULT;
+   }
+   if(cam_ctx->dma_started == 1)
+   {
+        return -EFAULT;
+   }
+   //make it in an even of multiple of 8
+   size.width  = (size.width +7)/8 * 8;
+   size.height = (size.height+7)/8 * 8;
+   dbg_print("w=%d h=%d", size.width, size.height);
+   if(cam_ctx->capture_width != size.width || cam_ctx->capture_height != size.height)
+   {
+     cam_ctx->capture_width  = size.width;
+     cam_ctx->capture_height = size.height;
+     ret = adcm2700_output_size(&size);
+   
+     timing.BFW = timing.BLW = 0;
+
+     ci_configure_mp(cam_ctx->capture_width-1, cam_ctx->capture_height-1, &timing);
+     camera_ring_buf_init(cam_ctx);
+   }
+   
+   return ret;
+}
+
+/*Set  sensor size*/  
+static int pxa_cam_WCAM_VIDIOCSSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+  //ddbg_print("WCAM_VIDIOCSSSIZE");
+  adcm_window_size size;
+  int ret = 0;
+  
+  if(copy_from_user(&size, param, sizeof(adcm_window_size))) 
+  {
+        return  -EFAULT;
+  }
+  if(cam_ctx->dma_started == 1)
+  {
+        return -EFAULT;
+  }
+  //make it in an even of multiple of 8
+  size.width  = (size.width +7)/8 * 8;
+  size.height = (size.height+7)/8 * 8;
+  
+  if(cam_ctx->sensor_width != size.width ||  cam_ctx->sensor_height != size.height)
+  {
+    cam_ctx->sensor_width = size.width;
+    cam_ctx->sensor_height = size.height;
+    ret = adcm2700_input_size(&size);
+    dbg_print("w = %d h = %d", size.width, size.height);
+  }
+  return ret;
+}
+
+static int pxa_cam_WCAM_VIDIOCSFPS(p_camera_context_t cam_ctx, void * param)
+{
+    //ddbg_print("WCAM_VIDIOCSFPS");
+    
+    struct {int fps, minfps;} cam_fps;
+    int ret = 0;
+    
+    if(copy_from_user(&cam_fps, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    if(cam_fps.fps < 12)
+    {
+       cam_fps.fps = 12;
+    }
+     
+    if(cam_ctx->fps != cam_fps.fps || cam_ctx->mini_fps != cam_fps.minfps)
+    {
+        cam_ctx->fps = cam_fps.fps;
+        cam_ctx->mini_fps = cam_fps.minfps;
+        if(cam_ctx->dma_started == 1)
+        {
+          camera_func_adcm2700_stop_capture(cam_ctx);
+          ret = camera_func_adcm2700_start_capture(cam_ctx, 0);
+        }    
+    }
+    return ret;
+}
+
+static int pxa_camera_WCAM_VIDIOCGCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    int reg_value, offset;
+    //ddbg_print("WCAM_VIDIOCGCAMREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return -EFAULT;
+    }
+    reg_value = (int)adcm2700_reg_read((u16)offset);
+
+    if(copy_to_user(param, &reg_value, sizeof(int))) 
+    {
+        return -EFAULT;
+    } 
+
+    return 0;
+}
+/*set flicker frequency*/
+static int pxa_cam_WCAM_VIDIOCSFLICKER(p_camera_context_t cam_ctx, void * param)
+{
+   dbg_print("WCAM_VIDIOCSFLICKER");
+   cam_ctx->flicker_freq = (int)param;
+
+   return adcm2700_set_flicker(cam_ctx->flicker_freq);
+}
+
+
+static int pxa_camera_WCAM_VIDIOCSCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    struct reg_set_s{int val1, val2} reg_s;
+    //ddbg_print("WCAM_VIDIOCSCAMREG");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    adcm2700_write((u16)reg_s.val1, (u16)reg_s.val2);
+    return 0;
+} 
+
+int camera_func_adcm2700_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+   switch(cmd)
+   {
+     /*read adcm2700 registers*/
+    case WCAM_VIDIOCGCAMREG:
+         return pxa_camera_WCAM_VIDIOCGCAMREG(cam_ctx, param);
+
+    /*write adcm2700 registers*/
+    case WCAM_VIDIOCSCAMREG:
+          return pxa_camera_WCAM_VIDIOCSCAMREG(cam_ctx, param);
+        
+    /*set sensor size */  
+    case WCAM_VIDIOCSSSIZE:
+         return pxa_cam_WCAM_VIDIOCSSSIZE(cam_ctx, param);
+
+    /*set output size*/
+    case WCAM_VIDIOCSOSIZE:
+         return pxa_cam_WCAM_VIDIOCSOSIZE(cam_ctx, param);
+         
+          
+    /*set video mode fps*/
+    case WCAM_VIDIOCSFPS:
+         return pxa_cam_WCAM_VIDIOCSFPS(cam_ctx, param);
+            
+    /*set picture style*/  
+    case WCAM_VIDIOCSSTYLE:
+         return pxa_cam_WCAM_VIDIOCSSTYLE(cam_ctx, param);
+         
+    /*set picture light*/     
+    case WCAM_VIDIOCSLIGHT:
+         return pxa_cam_WCAM_VIDIOCSLIGHT(cam_ctx, param);
+    
+    /*set picture brightness*/
+    case WCAM_VIDIOCSBRIGHT:
+         return pxa_cam_WCAM_VIDIOCSBRIGHT(cam_ctx, param);
+         
+    /*set flicker frequency*/
+    case WCAM_VIDIOCSFLICKER:
+         return pxa_cam_WCAM_VIDIOCSFLICKER(cam_ctx, param);
+
+    default:
+         {
+           dbg_print("Error cmd=0x%x", cmd);
+           return -1;
+         }
+  }
+  return 0;
+ 
+ }
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm2700.h linux-2.6.16.5-exz/drivers/media/video/adcm2700.h
--- linux-2.6.16.5/drivers/media/video/adcm2700.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm2700.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,42 @@
+
+/*================================================================================
+                                                                               
+                      Header Name: adcm2700.h
+
+General Description: Camera module adcm2700  interface head file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      12/15/2003     LIBdd35749    Created   
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _ADCM2700_H_
+#define _ADCM2700_H_
+
+#include "camera.h"
+
+//////////////////////////////////////////////////////////////////////////////////////
+//
+//          Prototypes
+//
+//////////////////////////////////////////////////////////////////////////////////////
+
+int camera_func_adcm2700_init(p_camera_context_t);
+int camera_func_adcm2700_deinit(p_camera_context_t);
+int camera_func_adcm2700_set_capture_format(p_camera_context_t);
+int camera_func_adcm2700_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_adcm2700_stop_capture(p_camera_context_t);
+
+#endif /* _ADCM2700_H_ */
+
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm2700_hw.c linux-2.6.16.5-exz/drivers/media/video/adcm2700_hw.c
--- linux-2.6.16.5/drivers/media/video/adcm2700_hw.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm2700_hw.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,936 @@
+/*================================================================================
+                                                                               
+                      Header Name: adcm2700_hw.c
+
+General Description: Camera module adcm2700 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)     12/15/2003      LIBdd35749    Created   
+
+wangfei(w20239)     02/05/2004      LIBdd74309    Set frame rate in video mode
+
+wangfei(w20239)     02/26/2004      LIBdd81055    New chip id support
+                                                  Update algorithm for DMA transfer
+                                                  Update strategy for memory management
+                                                  Fix still picture capture failed sometime
+                                                  New Agilent sensor chip ID support
+                                                  Make output height in an even multiple of 8
+                                                 
+wangfei(w20239)     03/08/2004      LIBdd84578    Photo effects setting
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/wrapper.h>
+#include <linux/delay.h>
+#include <linux/i2c.h> 
+
+#define  MAX_FPS  20
+
+#include "adcm2700_hw.h"
+#include "camera.h"
+
+
+extern int adcm2700_read(u16 addr, u16 *pvalue);
+extern int adcm2700_write(u16 addr, u16 value);
+extern int adcm2700_read_byte(unsigned short addr, unsigned char * value);
+
+
+ 
+#define wait_sreg_update()  { int   retry = adcm2700__TIMEOUT<<2;                   \
+			      dbg_print("wait for sensor update simple registers"); \
+                              adcm2700_write(SREG_CONTROL,   0x05);                 \
+                              while(--retry)                                        \
+                              {                                                     \
+                                u16 v = adcm2700_reg_read(SREG_CONTROL);            \
+                                mdelay(1);                                          \
+                                if(v == 0xFF)  break;                               \
+                                if(!(v & 0x04)) break;                              \
+                              }                                                     \
+                              dbg_print("retry = %d", retry);                       \
+                            }
+ 
+void adcm2700_wait(u32 ms)
+{
+    if(ms > 10)
+    {
+     set_current_state(TASK_INTERRUPTIBLE);
+     schedule_timeout(ms/10);
+    }
+}
+
+/****************************************************************************
+*									                                        *
+*        I2C Management		 					                            *
+*									                                        *
+*****************************************************************************/
+u16 adcm2700_reg_read(u16 reg_addr)
+{
+    u16 value;
+    int ret = adcm2700_read(reg_addr, &value);
+    if(ret < 0)
+    {
+      return 0xFF;
+    }
+    return value;
+}
+
+void adcm2700_reg_write(u16 reg_addr, u16 reg_value)
+{
+ 
+    /*experts registers or SREG_CONTROL write directly*/
+    if(reg_addr > 0x26 || reg_addr == SREG_CONTROL)
+    {
+      adcm2700_write(reg_addr, reg_value);
+      return; 
+    }
+
+    /* write sample control register step:
+    1 Stop the camera ¨C write 0x0000 to the CONTROL register.
+    2 Change the relevant register. 
+    3 Set the CONFIG bit in the CONTROL register, write 0x0004.
+    4 Wait for the CONFIG bit in CONTROL to clear. */
+    adcm2700_write(SREG_CONTROL, 0);
+    adcm2700_write(reg_addr, reg_value);
+    wait_sreg_update();
+    adcm2700_write(SREG_CONTROL, 0x01);
+  
+}
+ 
+/*restore capture property*/
+int adcm2700_restore_property(p_camera_context_t cam_ctx, int frames)
+{
+	u16 awb_gain_grn1, awb_gain_grn2, awb_gain_red, awb_gain_blue;
+    	u8 ae_gain1, ae_gain2, ae_gain3, ae_gain4;
+    	u8 r813, r814, r815, r80e;
+    	u16 r80, r84, rp;
+	u16 clk_div, sen_clk_div;
+	u32 texp;
+
+    dbg_print("sensor width %d", cam_ctx->sensor_width);
+    dbg_print("sensor height %d", cam_ctx->sensor_height);
+    dbg_print("capture_width %d", cam_ctx->capture_width);
+    dbg_print("capture_height %d", cam_ctx->capture_height);
+    ddbg_print("fps %d mini fps %d", cam_ctx->fps, cam_ctx->mini_fps);
+    ddbg_print("light %d", cam_ctx->capture_light);
+    ddbg_print("capture_bright %d", cam_ctx->capture_bright);
+    ddbg_print("capture_style %d", cam_ctx->capture_style);
+
+
+    awb_gain_grn1 = adcm2700_reg_read(EREG_APS_COEF_GRN1);
+    awb_gain_grn2 = adcm2700_reg_read(EREG_APS_COEF_GRN2);
+    awb_gain_red  = adcm2700_reg_read(EREG_APS_COEF_RED);
+    awb_gain_blue = adcm2700_reg_read(EREG_APS_COEF_BLUE);
+   
+    adcm2700_read_byte(0x080F, &ae_gain1);
+    adcm2700_read_byte(0x0810, &ae_gain2);
+    adcm2700_read_byte(0x0811, &ae_gain3);
+    adcm2700_read_byte(0x0812, &ae_gain4);
+    
+    adcm2700_read_byte(0x813, &r813);
+    adcm2700_read_byte(0x814, &r814);
+    adcm2700_read_byte(0x815, &r815);
+    adcm2700_read_byte(0x80e, &r80e);
+    dbg_print("r813= %x, r814=%x r815 = %x", r813, r814, r815);
+    
+    adcm2700_read(0x80, &r80);
+    adcm2700_read(0x84, &r84);
+    adcm2700_read(0x114, &rp);
+
+    clk_div = r80+1;
+    sen_clk_div = (r84 == 0) ? 1 : (r84<<1);
+    texp = ((((u32)r814)<<8) + r813) * rp + 4 * r815;
+    texp *= clk_div * sen_clk_div * r80e;
+    dbg_print("before rp = 0x%x r80 = 0x%x r84 = 0x%x", rp, r80, r84);
+    dbg_print("before clk_div = 0x%x sen_clk_div = 0x%x r80e = 0x%x", clk_div, sen_clk_div, r80e);
+       //update simple registers
+    adcm2700_write(SREG_CONTROL, 0);
+    //sensor width and sensor height
+    adcm2700_write(SREG_SIZE, 0x707);  
+    adcm2700_write(SREG_SENSOR_WID_V, (u16)(cam_ctx->sensor_width));
+    adcm2700_write(SREG_SENSOR_HGT_V, (u16)(cam_ctx->sensor_height));
+
+    //output width and output height
+    adcm2700_write(SREG_OUTPUT_WID_V, (u16)(cam_ctx->capture_width));
+    adcm2700_write(SREG_OUTPUT_HGT_V, (u16)(cam_ctx->capture_height));
+
+    //default fps
+    adcm2700_write(SREG_FRAME_RATE, cam_ctx->fps*10);
+    wait_sreg_update();
+    adcm2700_set_light(cam_ctx->capture_light);
+    adcm2700_write(EREG_AE_ETIME_MAX, 100000/(cam_ctx->mini_fps));
+       
+      //still mode and not night mode
+    if(frames == 1)
+    {
+        adcm2700_write(EREG_AF_CTRL1, 0x10);
+        adcm2700_read_byte(0x80e, &r80e);
+        adcm2700_read(0x80, &r80);
+        adcm2700_read(0x84, &r84);
+        adcm2700_read(0x114, &rp);
+        clk_div = r80+1;
+        sen_clk_div = (r84 == 0) ? 1 : (r84<<1);
+        texp /= (clk_div * sen_clk_div * r80e);
+        u16 ttexp = (texp/rp);
+        r815 = (u8)((texp - ttexp * rp)>>2);
+        r813 = (u8)(ttexp & 0xFF);
+        r814 = (u8)(ttexp >> 8);
+        dbg_print("after r813= %x, r814=%x r815 = %x", r813, r814, r815);
+        adcm2700_write_byte(0x813, r813);
+        adcm2700_write_byte(0x814, r814);
+        adcm2700_write_byte(0x815, r815);
+        dbg_print("after rp = 0x%x r80 = 0x%x r84 = 0x%x", rp, r80, r84);
+        dbg_print("after clk_div = 0x%x sen_clk_div = 0x%x r80e = 0x%x", clk_div, sen_clk_div, r80e);
+
+        
+        adcm2700_write_byte(0x080F, ae_gain1);
+        adcm2700_write_byte(0x0810, ae_gain2);
+        adcm2700_write_byte(0x0811, ae_gain3);
+        adcm2700_write_byte(0x0812, ae_gain4);
+ 
+        adcm2700_write(EREG_APS_COEF_GRN1, awb_gain_grn1);
+        adcm2700_write(EREG_APS_COEF_GRN2, awb_gain_grn2);
+        adcm2700_write(EREG_APS_COEF_RED,  awb_gain_red);
+        adcm2700_write(EREG_APS_COEF_BLUE, awb_gain_blue);
+        
+    }
+    else
+    {
+
+    }
+   
+           
+    //expert registers
+    adcm2700_set_bright(cam_ctx->capture_bright);
+
+    if(cam_ctx->capture_style == V4l_STYLE_NORMAL && frames == 1)
+    {
+         adcm2700_set_gamma(3);
+    }
+    else
+    {
+        adcm2700_set_style(cam_ctx->capture_style);
+    }
+
+    adcm2700_write(SREG_CONTROL, 0x01);
+    return ADCM_ERR_NONE;
+
+}
+
+
+///////////////////////////////////////////////////////////////
+//
+//   Programming Guide Chapter 1: Basic Programming
+//
+///////////////////////////////////////////////////////////////
+
+void adcm2700_color_init(void);
+
+int adcm2700_power_on( u8 clk )
+{
+    /*Follow these steps to correctly power on the ADCM-2700:
+    1 Turn on VCC voltage (2.8 volts) and wait 20 milliseconds.
+    2 Turn on MCLK (13 MHz is the default value) and wait 150 milliseconds.
+    3 Read register 0x0004; if the return value equals 0x0001, power-up is complete. */
+    int   retry = adcm2700__TIMEOUT<<2;
+    while(--retry)
+    {
+        if(adcm2700_reg_read(SREG_STATUS) == 0x0001)
+        {
+             dbg_print("adcm2700 Power-up complete!!"); 
+             break;
+        }
+        adcm2700_wait(2);
+    }
+    
+ 
+    
+    /* Program the mafster clock */
+    adcm2700_master_clock(clk);
+
+    /* Configure  anti-vignetting */
+    adcm2700_color_init();
+    
+    return ADCM_ERR_NONE;
+}
+
+
+int adcm2700_power_off()
+{
+	/*stop camera*/
+	adcm2700_write(SREG_CONTROL, 0);
+	return ADCM_ERR_NONE;   
+}
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+//   
+//  Programming Guide Chapter 2: Configuration Methods 
+//
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+int adcm2700_version_revision(u16 * cm_revision, u16 *sensor_revision)
+{
+    //Camera module version is 0x060
+    *cm_revision = adcm2700_reg_read(SREG_ID);
+    dbg_print("adcm2700 SREG_ID is 0x%x", *cm_revision);
+     
+    //Image sensor version is 0x60
+    *sensor_revision = adcm2700_reg_read(EREG_IDENT);
+    dbg_print("adcm2700 EREG_IDENT is 0x%x", *sensor_revision);       
+    return ADCM_ERR_NONE;
+}
+
+int adcm2700_viewfinder_on()
+{
+    //adcm2700_write(SREG_CONTROL, 0x01);
+    ddbg_print("camera video mode start!"); 
+    return ADCM_ERR_NONE;
+}
+
+
+
+int adcm2700_viewfinder_off()
+{
+    //adcm2700_write(SREG_CONTROL, 0);
+    ddbg_print("camera video mode stop!");
+      // adcm2700_store_af_regs();
+    return ADCM_ERR_NONE;
+}
+
+
+int adcm2700_snapshot_trigger()
+{
+ /*   
+    u16 status = adcm2700_reg_read(EREG_AF_STATUS);
+    int   retry = adcm2700__TIMEOUT<<1;
+    while(--retry)
+    {
+      if(status & 0x08)
+         break;
+      status = adcm2700_reg_read(EREG_AF_STATUS);   
+    }
+    dbg_print("retry = %d", retry);
+ 
+   */
+	return ADCM_ERR_NONE;
+}
+
+int adcm2700_master_clock(u8 clk)
+{
+  
+    //0x2712  2X
+    //0x1D09  3X   //default
+    //0x2709  4X
+    //0xFC53
+    u16 div = 0x1D09;
+
+    clk *= (((div>>8) + 1)/((div&0xFF) + 1));
+    
+    
+    //adcm2700_reg_write(EREG_SEN_CLK_DIV, 1);
+
+    /*enable pll*/
+    adcm2700_write(SREG_CONTROL, 0);
+
+    adcm2700_write(SREG_CLK_FREQ, (u16)clk * 1000);
+    adcm2700_write(EREG_PLL_DIV_L, div);
+    adcm2700_write(EREG_PLL_DIV_S, div);
+    adcm2700_write(EREG_PLL_CTRL,  0x0025);  //0x002D
+    
+    wait_sreg_update();
+    //adcm2700_reg_write(EREG_I_CLK_DIV, 0);
+    adcm2700_write(SREG_CONTROL, 1);
+
+    return ADCM_ERR_NONE;
+}
+
+
+int adcm2700_input_size(adcm_window_size * window)
+{
+  
+   /* write sample control register step:
+    1 Stop the camera ¨C write 0x0000 to the CONTROL register.
+    2 Change the relevant register. 
+    3 Set the CONFIG bit in the CONTROL register, write 0x0004.
+    4 Wait for the CONFIG bit in CONTROL to clear.  */
+ /*
+   adcm2700_write(SREG_CONTROL, 0);
+
+      adcm2700_write(SREG_SIZE, 0x707);  
+      adcm2700_write(SREG_SENSOR_WID_V, window->width);
+      adcm2700_write(SREG_SENSOR_HGT_V, window->height);
+      
+      //adcm2700_write(SREG_SENSOR_WID_S, window->width);
+      //adcm2700_write(SREG_SENSOR_HGT_S, window->height);
+      
+   wait_sreg_update();
+ */
+   return ADCM_ERR_NONE;
+ }
+int adcm2700_output_size(adcm_window_size * window)
+{
+   
+   /* write sample control register step:
+    1 Stop the camera ¨C write 0x0000 to the CONTROL register.
+    2 Change the relevant register. 
+    3 Set the CONFIG bit in the CONTROL register, write 0x0004.
+    4 Wait for the CONFIG bit in CONTROL to clear.  */
+/*
+   adcm2700_write(SREG_CONTROL, 0);
+  
+       adcm2700_write(SREG_SIZE, 0x707);  
+       adcm2700_write(SREG_OUTPUT_WID_V, window->width);
+       adcm2700_write(SREG_OUTPUT_HGT_V, window->height);
+//     adcm2700_write(SREG_OUTPUT_WID_S, window->width);
+//     adcm2700_write(SREG_OUTPUT_HGT_S, window->height);
+
+   wait_sreg_update();
+ */
+   return ADCM_ERR_NONE;
+}
+
+
+int adcm2700_set_fps(u16 fps, u16 minfps)
+{
+    if(fps > MAX_FPS  || minfps > fps)
+    {
+        return ADCM_ERR_PARAMETER;
+    }
+    
+    adcm2700_reg_write(SREG_FRAME_RATE, fps*10);
+    adcm2700_reg_write(EREG_AE_ETIME_MAX, 100000/(minfps));
+    
+    return ADCM_ERR_NONE;
+}
+
+
+int adcm2700_stillframe_cfg_output(u16 format)
+{
+
+    u16   oldcfg =   adcm2700_reg_read(SREG_OUTPUT_FORMAT);
+    
+    oldcfg = (oldcfg & 0xF0FF) | ((format & 0x000F) << 8);
+    adcm2700_reg_write( SREG_OUTPUT_FORMAT, oldcfg);
+    
+    return ADCM_ERR_NONE;
+}
+
+int adcm2700_viewfinder_cfg_output(u16 format)
+{
+
+      u16   oldcfg = adcm2700_reg_read( SREG_OUTPUT_FORMAT);
+      
+      oldcfg = (oldcfg & 0xFFF0) | (format & 0x000F);
+      adcm2700_reg_write( SREG_OUTPUT_FORMAT, oldcfg );
+      return ADCM_ERR_NONE;
+}
+
+
+
+void adcm2700_dump_register(u16 startRegAddr, u16 endRegAddr, u16* buffer)
+{
+	u16 addr;
+	
+	for(addr = startRegAddr; addr <= endRegAddr; addr+=2)
+	{
+	   adcm2700_read(addr, buffer++);
+	}
+}
+
+int adcm2700_set_gamma(int table)
+{
+  const u16 regs[] = 
+  { 
+    0x1400, 0x1402, 0x1404, 0x1406, 0x1408, 0x140a, 0x140c, 0x140e, 0x1410, 0x1412, 0x1414,  
+    0x1416, 0x1418, 0x141a, 0x141c, 0x141e, 0x1420, 0x1422, 0x1424, 0x1426, 0x1428, 0x142a,  
+    0x142c, 0x142e, 0x1430, 0x1432, 0x1434, 0x1436, 0x1438, 0x143a, 0x143c, 0x143e, 0x1440
+  };
+  
+
+  const u16 regsv[] = 
+  {
+  EREG_TM_COEF_00_V, EREG_TM_COEF_01_V, EREG_TM_COEF_02_V, EREG_TM_COEF_03_V, 
+  EREG_TM_COEF_04_V, EREG_TM_COEF_05_V, EREG_TM_COEF_06_V, EREG_TM_COEF_07_V, 
+  EREG_TM_COEF_08_V, EREG_TM_COEF_09_V, EREG_TM_COEF_10_V, EREG_TM_COEF_11_V, 
+  EREG_TM_COEF_12_V, EREG_TM_COEF_13_V, EREG_TM_COEF_14_V, EREG_TM_COEF_15_V,
+  EREG_TM_COEF_16_V, EREG_TM_COEF_17_V, EREG_TM_COEF_18_V, EREG_TM_COEF_19_V,
+  EREG_TM_COEF_20_V, EREG_TM_COEF_21_V, EREG_TM_COEF_22_V, EREG_TM_COEF_23_V,
+  EREG_TM_COEF_24_V, EREG_TM_COEF_25_V, EREG_TM_COEF_26_V, EREG_TM_COEF_27_V,
+  EREG_TM_COEF_28_V, EREG_TM_COEF_29_V, EREG_TM_COEF_30_V, EREG_TM_COEF_31_V,
+  EREG_TM_COEF_32_V
+  };
+  const u16 regss[] = 
+  {
+  EREG_TM_COEF_00_S, EREG_TM_COEF_01_S, EREG_TM_COEF_02_S, EREG_TM_COEF_03_S, 
+  EREG_TM_COEF_04_S, EREG_TM_COEF_05_S, EREG_TM_COEF_06_S, EREG_TM_COEF_07_S, 
+  EREG_TM_COEF_08_S, EREG_TM_COEF_09_S, EREG_TM_COEF_10_S, EREG_TM_COEF_11_S, 
+  EREG_TM_COEF_12_S, EREG_TM_COEF_13_S, EREG_TM_COEF_14_S, EREG_TM_COEF_15_S,
+  EREG_TM_COEF_16_S, EREG_TM_COEF_17_S, EREG_TM_COEF_18_S, EREG_TM_COEF_19_S,
+  EREG_TM_COEF_20_S, EREG_TM_COEF_21_S, EREG_TM_COEF_22_S, EREG_TM_COEF_23_S,
+  EREG_TM_COEF_24_S, EREG_TM_COEF_25_S, EREG_TM_COEF_26_S, EREG_TM_COEF_27_S,
+  EREG_TM_COEF_28_S, EREG_TM_COEF_29_S, EREG_TM_COEF_30_S, EREG_TM_COEF_31_S,
+  EREG_TM_COEF_32_S
+  };
+
+  const u16 value[][33] =   
+  {
+  //default
+    0x0000, 0x003c, 0x0052, 0x0063, 0x0070, 0x007c, 0x0087, 0x0091, 0x0094, 0x00ab, 0x00b9, 
+    0x00c7, 0x00d3, 0x00ea, 0x00fe, 0x0111, 0x0122, 0x0141, 0x015d, 0x0176, 0x018d, 0x01b8,
+    0x01de, 0x0201, 0x0221, 0x025b, 0x028f, 0x02bf, 0x02eb, 0x033b, 0x0382, 0x03c3, 0x0400,
+    /*
+    0x0000, 0x004C, 0x0065, 0x0078, 0x0087, 0x0094, 0x00A0, 0x00ab, 0x00b5, 0x00c6, 0x00d6, 
+    0x00e4, 0x00f1, 0x0109, 0x011E, 0x0131, 0x0142, 0x0161, 0x017D, 0x0197, 0x01AE, 0x01d8,
+    0x01fd, 0x021F, 0x023E, 0x0276, 0x02a8, 0x02d5, 0x02ff, 0x0349, 0x038C, 0x03C8, 0x0400, 
+    */   
+  
+   
+   //solarize
+     0x0400, 0x03e9, 0x03a9, 0x0344, 0x02c3, 0x0232, 0x019c, 0x010e, 0x0095, 0x003c, 0x0009,
+     0x0002, 0x0026, 0x0074, 0x00e3, 0x016b, 0x01ff, 0x0294, 0x031c, 0x038b, 0x03d9, 0x03fd,
+     0x03f6, 0x03c3, 0x036a, 0x02f1, 0x0263, 0x01cd, 0x013c, 0x00bb, 0x0056, 0x0016, 0x0000,
+     
+   //neg.art
+     0x03ff, 0x03e8, 0x03cd, 0x03b9, 0x03a9, 0x039b, 0x038e, 0x0383, 0x0379, 0x0366, 0x0356, 
+     0x0347, 0x0339, 0x0320, 0x030a, 0x02f6, 0x02e4, 0x02c2, 0x02a5, 0x028a, 0x0272, 0x0245,
+     0x021e, 0x01fa, 0x01da, 0x019e, 0x016a, 0x013a, 0x010e, 0x00c0, 0x007a, 0x003a, 0x0000,
+    
+   
+   /*
+    //2.6
+    0x0000, 0x005C, 0x0079, 0x008d, 0x009e, 0x00ac, 0x00b9, 0x00c4, 0x00ce, 0x00e1, 0x00f1, 
+    0x0100, 0x010e, 0x0126, 0x013b, 0x014e, 0x0160, 0x0180, 0x019c, 0x01b5, 0x01cc, 0x01f5,
+    0x0219, 0x023a, 0x0258, 0x028e, 0x02be, 0x02e9, 0x0310, 0x0356, 0x0394, 0x03cc, 0x0400, 
+   
+    //2.4
+    0x0000, 0x004C, 0x0065, 0x0078, 0x0087, 0x0094, 0x00A0, 0x00ab, 0x00b5, 0x00c6, 0x00d6, 
+    0x00e4, 0x00f1, 0x0109, 0x011E, 0x0131, 0x0142, 0x0161, 0x017D, 0x0197, 0x01AE, 0x01d8,
+    0x01fd, 0x021F, 0x023E, 0x0276, 0x02a8, 0x02d5, 0x02ff, 0x0349, 0x038C, 0x03C8, 0x0400, 
+    
+    //2.3
+    0x0000, 0x0043, 0x005b, 0x006d, 0x007c, 0x0088, 0x0094, 0x009e, 0x00a7, 0x00b8, 0x00c8,
+    0x00d6, 0x00e2, 0x00fa, 0x010e, 0x0121, 0x0132, 0x0151, 0x016d, 0x0187, 0x019e, 0x01c8,
+    0x01ee, 0x0210, 0x0230, 0x0269, 0x029c, 0x02ca, 0x02f5, 0x0342, 0x0387, 0x03c6, 0x0400,
+     */
+    //2.2
+    0x0000, 0x003c, 0x0052, 0x0063, 0x0070, 0x007c, 0x0087, 0x0091, 0x0094, 0x00ab, 0x00b9, 
+    0x00c7, 0x00d3, 0x00ea, 0x00fe, 0x0111, 0x0122, 0x0141, 0x015d, 0x0176, 0x018d, 0x01b8,
+    0x01de, 0x0201, 0x0221, 0x025b, 0x028f, 0x02bf, 0x02eb, 0x033b, 0x0382, 0x03c3, 0x0400,
+     
+    //2.1
+    0x0000, 0x0034, 0x0049, 0x0058, 0x0065, 0x0070, 0x007b, 0x0084, 0x008d, 0x009d, 0x00ab, 
+    0x00b8, 0x00c4, 0x00da, 0x00ee, 0x0100, 0x0111, 0x0130, 0x014b, 0x0164, 0x017c, 0x01a7,
+    0x01cd, 0x01f0, 0x0211, 0x024c, 0x0281, 0x02b2, 0x02e0, 0x0332, 0x037c, 0x03c0, 0x0400,
+    
+    //2.0
+    0x0000, 0x002d, 0x0040, 0x004e, 0x005a, 0x0065, 0x006e, 0x0077, 0x0080, 0x008f, 0x009c,
+    0x00a9, 0x00b5, 0x00ca, 0x00dd, 0x00ef, 0x0100, 0x011e, 0x0139, 0x0152, 0x016a, 0x0194,
+    0x01bb, 0x01de, 0x0200, 0x023c, 0x0273, 0x02a5, 0x02d4, 0x0329, 0x0376, 0x03bd, 0x0400,
+   
+    //1.9
+    0x0000, 0x0026, 0x0037, 0x0044, 0x004f, 0x0059, 0x0062, 0x006a, 0x0072, 0x0081, 0x008e, 
+    0x009a, 0x00a5, 0x00b9, 0x00cc, 0x00dd, 0x00ed, 0x010b, 0x0126, 0x013f, 0x0156, 0x0181, 
+    0x01a8, 0x01cc, 0x01ed, 0x022b, 0x0263, 0x0296, 0x02c6, 0x031f, 0x0370, 0x03ba, 0x0400,
+    
+    //1.8 ap30
+    0x0000, 0x0020, 0x002f, 0x003a, 0x0045, 0x004e, 0x0056, 0x005e, 0x0065, 0x0073, 0x007f, 
+    0x008a, 0x0095, 0x00a9, 0x00bb, 0x00cb, 0x00db, 0x00f8, 0x0112, 0x012b, 0x0142, 0x016d, 
+    0x0194, 0x01b8, 0x01da, 0x0218, 0x0251, 0x0286, 0x02b8, 0x0314, 0x0368, 0x03b6, 0x0400,
+    //default
+ 
+    0x0000, 0x0017, 0x0032, 0x0046, 0x0056, 0x0064, 0x0071, 0x007c, 0x0086, 0x0099, 0x00a9,
+    0x00b8, 0x00c6, 0x00df, 0x00f5, 0x0109, 0x011b, 0x013d, 0x015a, 0x0175, 0x018d, 0x01ba,
+    0x01e1, 0x0205, 0x0225, 0x0261, 0x0295, 0x02c5, 0x02f1, 0x033f, 0x0385, 0x03c5, 0x0400
+   
+  };
+  
+  int i, ret;
+  /*
+  for(i = 0; i < 33; i++)
+  {
+     ret = adcm2700_write(regss[i], value[table][i]);
+     if(ret < 0)
+     {
+       dbg_print("adcm2700 write error!");
+       return -1;
+     }
+  }
+  */
+  
+  for(i = 0; i < 33; i++)
+  {
+     ret = adcm2700_write(regsv[i], value[table][i]);
+     if(ret < 0)
+     {
+       dbg_print("adcm2700 write error!");
+       return -1;
+     }
+  }
+  
+  for(i = 0; i < 33; i++)
+  {
+     ret = adcm2700_write(regs[i],  value[table][i]);
+     if(ret < 0)
+     {
+       dbg_print("adcm2700 write error!");
+       return -1;
+     }
+  }
+  return ADCM_ERR_NONE;
+}
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+int adcm2700_set_style(V4l_PIC_STYLE style)
+{
+  const u16 regs1[] = {EREG_CC_COEF_00, EREG_CC_COEF_01, EREG_CC_COEF_02,
+                       EREG_CC_COEF_10, EREG_CC_COEF_11, EREG_CC_COEF_12,
+                       EREG_CC_COEF_20, EREG_CC_COEF_21, EREG_CC_COEF_22};
+                       
+  // 0 - normal    1 - black white   2 - sepia
+  const u16 value1[][9] = 
+  {
+   //{0x02f9, 0x0f03, 0x0f02, 0x0f4f, 0x025c, 0x0f54, 0x0fe0, 0x0e4a, 0x02d5}, //normal settings
+   
+   {0x01f0, 0x0f88, 0x0f88,
+    0x0f88, 0x01f0, 0x0f88,
+    0x0f88, 0x0f88, 0x01f0},
+   
+   {0x003b, 0x00c8, 0x0fcf, 0x003b, 0x00c8, 0x0fcf, 0x003b, 0x00c8, 0x0fcf}, //black white
+   {0x005c, 0x0131, 0x0fb6, 0x0030, 0x00a2, 0x0fd9, 0x001a, 0x0058, 0x0feb}, //sepia   
+  }; 
+   
+
+  u16 * reg_value;
+  u16 reg_count;
+  int i;
+
+  switch(style)
+  {
+  case V4l_STYLE_BLACK_WHITE:
+       adcm2700_set_gamma(0);
+       reg_value = value1[1];
+       reg_count = 9;
+       break;
+  case V4l_STYLE_SEPIA:
+       adcm2700_set_gamma(0);
+       reg_value = value1[2];
+       reg_count = 9;
+       break;
+  case V4l_STYLE_SOLARIZE:
+       adcm2700_set_gamma(1);
+       return ADCM_ERR_NONE; 
+  case V4l_STYLE_NEG_ART:
+       adcm2700_set_gamma(2);
+       return ADCM_ERR_NONE; 
+  default:
+       adcm2700_set_gamma(0);
+     //  adcm2700_reg_write(SREG_ILLUM, illum);
+       return ADCM_ERR_NONE;
+  }
+
+  for(i = 0; i < reg_count; i++)
+  {
+    adcm2700_write(regs1[i], reg_value[i]);
+  }
+  return ADCM_ERR_NONE;
+}
+
+/*set picture light(auto/direct sun/incandescent/fluorescent)*/     
+u16 adcm2700_get_light_v(V4l_PIC_WB light)
+{ /*
+  const u16 regs1[] = {EREG_CC_COEF_00, EREG_CC_COEF_01, EREG_CC_COEF_02,
+                       EREG_CC_COEF_10, EREG_CC_COEF_11, EREG_CC_COEF_12,
+                       EREG_CC_COEF_20, EREG_CC_COEF_21, EREG_CC_COEF_22};
+                       
+  const u16 value1[][9] = 
+  {
+   {0x02f9, 0x0f03, 0x0f02, 0x0f4f, 0x025c, 0x0f54, 0x0fe0, 0x0e4a, 0x02d5}, //default
+   {0x0235, 0x0f8f, 0x0f3b, 0x0f63, 0x01f0, 0x0fad, 0x000d, 0x0eb2, 0x0241}, //day
+   {0x0235, 0x0f46, 0x0f85, 0x0f64, 0x01fc, 0x0f9f, 0x0008, 0x0e8d, 0x026b}, //fluorescent
+   {0x023a, 0x0f34, 0x0f92, 0x0f5a, 0x0218, 0x0f8e, 0x0ffa, 0x0deb, 0x031b}, //tungsten   
+  }; 
+  int i, index;
+  switch(light)
+  {
+   case V4l_WB_DIRECT_SUN:
+       index = 1;
+       break;       
+   case V4l_WB_INCANDESCENT:
+       index = 3;
+       break;       
+   case V4l_WB_FLUORESCENT:
+       index = 2;
+       break;       
+   default:
+       index = 0;
+       break;
+  }
+  for(i = 0; i< 9; i++)
+  {
+      adcm2700_write(regs1[i], value1[index][i]);
+  }
+
+  */
+
+  u16 value = adcm2700_reg_read(SREG_ILLUM);
+  value &= ~0x0007;
+  switch(light)
+  {
+  case V4l_WB_DIRECT_SUN:
+       value |= 0x0002;
+       break;       
+  case V4l_WB_INCANDESCENT:
+       value |= 0x0006;
+       break;       
+  case V4l_WB_FLUORESCENT:
+       value |= 0x0004;
+       break;       
+  default:
+       break;
+   }
+   return value;
+}
+/* Sunny - 5500K daylight */
+const u16 agilent_sunny_color[] =
+{0x0214, 0x0F6E, 0x0F7C,
+ 0x0F58, 0x022D, 0x0F79,
+ 0x0FF4, 0x0EB3, 0x0257};
+
+/* Cloudy - 7500K daylight */
+const u16 agilent_cloudy_color[] =
+{0x021B, 0x0F8D, 0x0F56,
+ 0x0F5C, 0x0226, 0x0F7D,
+ 0x0FF5, 0x0EE7, 0x0223};
+
+/* Indoor - home tungsten */
+const u16 agilent_home_tungsten_color[] =
+{0x0243, 0x0EDD, 0x0FDF,
+ 0x0F3B, 0x0273, 0x0F50,
+ 0x0FA4, 0x0D9F, 0x03BB};
+
+/* Indoor - office cool white fluorescent */
+const u16 agilent_office_cool_white_fluorescent_color[] =
+{0x01CF, 0x0F6E, 0x0FC1,
+ 0x0F72, 0x020D, 0x0F7F,
+ 0x0FEF, 0x0E5A, 0x02B6};
+
+/* Night tungsten */
+const u16 agilent_night_tungsten_color[] =
+{0x0243, 0x0EDD, 0x0FDF,
+ 0x0F3B, 0x0273, 0x0F50,
+ 0x0FA4, 0x0D9F, 0x03BB};
+
+/* Automatic (generic default setting) 6500K daylight */
+const u16 agilent_automatic_color[] =
+{0x02F4, 0x0F27, 0x0F30,
+ 0x0F0C, 0x02F2, 0x0F4E,
+ 0x0FE8, 0x0E2E, 0x0335};
+ 
+int adcm2700_set_light(V4l_PIC_WB light)
+{
+  // u16 value = adcm2700_get_light_v(light);
+  // adcm2700_reg_write(SREG_ILLUM, value);
+  
+  const u16 regs1[] = {EREG_CC_COEF_00, EREG_CC_COEF_01, EREG_CC_COEF_02,
+                       EREG_CC_COEF_10, EREG_CC_COEF_11, EREG_CC_COEF_12,
+                       EREG_CC_COEF_20, EREG_CC_COEF_21, EREG_CC_COEF_22};
+  const u16 agilent_default[] = {0x02f9, 0x0f03, 0x0f02, 0x0f4f, 0x025c, 0x0f54, 0x0fe0, 0x0e4a, 0x02d5};
+     /*                  
+  const u16 value1[][9] = 
+  {
+   {0x02f9, 0x0f03, 0x0f02, 0x0f4f, 0x025c, 0x0f54, 0x0fe0, 0x0e4a, 0x02d5}, //default
+   {0x0235, 0x0f8f, 0x0f3b, 0x0f63, 0x01f0, 0x0fad, 0x000d, 0x0eb2, 0x0241}, //day
+   {0x0235, 0x0f46, 0x0f85, 0x0f64, 0x01fc, 0x0f9f, 0x0008, 0x0e8d, 0x026b}, //fluorescent
+   {0x023a, 0x0f34, 0x0f92, 0x0f5a, 0x0218, 0x0f8e, 0x0ffa, 0x0deb, 0x031b}, //tungsten   
+  }; 
+  */
+  int i;
+  const u16 * values = NULL;
+  u16 v = adcm2700_reg_read(EREG_AF_CTRL1);
+  switch(light)
+  {
+   case V4l_WB_DIRECT_SUN:
+       values = agilent_sunny_color;
+       adcm2700_write(EREG_AF_CTRL1, v&(~0x0002)); 
+       break;       
+   case V4l_WB_INCANDESCENT:
+       values = agilent_night_tungsten_color;
+       adcm2700_write(EREG_AF_CTRL1, v&(~0x0002)); 
+       break;       
+   case V4l_WB_FLUORESCENT:
+       values = agilent_office_cool_white_fluorescent_color;
+       adcm2700_write(EREG_AF_CTRL1, v&(~0x0002)); 
+       break;       
+   default:
+       values = agilent_automatic_color;
+       adcm2700_write(EREG_AF_CTRL1, v|0x0002);
+       break;
+  }
+  if(values != agilent_automatic_color)
+  {
+   for(i = 0; i < 9; i++)
+   {
+      adcm2700_write(regs1[i], values[i]);
+   }
+  }
+  return 0;
+}
+        
+/*set picture brightness*/
+int adcm2700_set_bright(int bright)
+{
+  const u16 target[] = 
+   { 
+       0x0010,      // -2.0 EV
+       0x0015,      // -1.5 EV
+       0x0020,      // -1.0 EV
+       0x0030,      // -0.5 EV
+       0x0040,      //  0.0 EV
+       0x0060,      // +0.5 EV
+       0x0080,      // +1.0 EV
+       0x00C0,      // +1.5 EV
+       0x00FF       // +2.0 EV
+   };
+
+  if(bright < -4 || bright > 4)
+  {
+    return ADCM_ERR_PARAMETER;
+  }
+  adcm2700_write(EREG_AE_TARGET, target[bright+4]);
+  return ADCM_ERR_NONE;
+}
+
+#define ADCM2700_PROC_CTRL_V_REG        0x0112
+#define ADCM2700_PROC_CTRL_S_REG        0x0132
+
+#define ADCM2700_AV_CENTER_COL_REG      0x106e
+#define ADCM2700_AV_CENTER_ROW_REG      0x1070
+#define ADCM2700_AV_OVAL_FACT_REG       0x1094
+
+
+#define ADCM2700_PROC_CTRL_V_REG        0x0112
+#define ADCM2700_PROC_CTRL_S_REG        0x0132
+
+#define ADCM2700_AV_LEFT_TOP_REG        0x106a
+#define ADCM2700_AV_RIGHT_BOT_REG       0x106c
+#define ADCM2700_AV_CENTER_COL_REG      0x106e
+#define ADCM2700_AV_CENTER_ROW_REG      0x1070
+#define ADCM2700_AV_OVAL_FACT_REG       0x1094
+
+#define ADCM2700_AV_RED_RAM_REG         0x1800
+#define ADCM2700_AV_GREEN_RAM_REG       0x1840
+#define ADCM2700_AV_BLUE_RAM_REG        0x1880
+
+unsigned short AV_BLUE_2700[32] =
+{
+    0x47, 0x49, 0x4b, 0x4d, 0x50, 0x52, 0x55, 0x58,
+    0x5a, 0x5d, 0x60, 0x63, 0x66, 0x69, 0x6d, 0x71,
+    0x75, 0x79, 0x7d, 0x82, 0x87, 0x8d, 0x93, 0x9a,
+    0xa1, 0xa9, 0xb2, 0xbd, 0xc8, 0xd6, 0xe5, 0xf7
+};
+
+unsigned short AV_GREEN_2700[32] =
+{
+    0x44, 0x48, 0x4b, 0x4f, 0x52, 0x56,  0x5a,  0x5e,
+    0x63, 0x67, 0x6c, 0x70, 0x75, 0x7b,  0x80,  0x86,
+    0x8c, 0x92, 0x98, 0x9f, 0xa6, 0xae,  0xb5,  0xbd,
+    0xc6, 0xcf, 0xd8, 0xe2, 0xed, 0xf8,  0x103, 0x10f
+};
+
+unsigned short AV_RED_2700[32] =
+{
+    0x43, 0x47, 0x4b, 0x50, 0x54,  0x59,  0x5e,  0x63,
+    0x69, 0x6f, 0x75, 0x7b, 0x82,  0x89,  0x90,  0x97,
+    0x9e, 0xa6, 0xae, 0xb6, 0xbe,  0xc6,  0xce,  0xd6,
+    0xde, 0xe6, 0xee, 0xf6, 0xfe,  0x103, 0x104, 0x103
+};
+
+
+void adcm2700_color_init(void)
+{
+    u16  regdata;
+    int  count;
+
+    adcm2700_reg_write(ADCM2700_AV_CENTER_COL_REG, 0x0146);
+    adcm2700_reg_write(ADCM2700_AV_CENTER_ROW_REG, 0x00fc);
+    adcm2700_reg_write(ADCM2700_AV_OVAL_FACT_REG,  0x10e);
+
+    for(count = 0; count < 32; count++)
+    {
+        adcm2700_reg_write(ADCM2700_AV_RED_RAM_REG+count*2,   AV_RED_2700[count]);
+    }
+
+    for(count = 0; count < 32; count++)
+    {    
+        adcm2700_reg_write(ADCM2700_AV_GREEN_RAM_REG+count*2, AV_GREEN_2700[count]);
+    }
+    
+    for(count = 0; count < 32; count++)
+    {
+        adcm2700_reg_write(ADCM2700_AV_BLUE_RAM_REG+count*2,  AV_BLUE_2700[count]);
+    }
+
+
+    /* video mode sharpening enable*/
+    regdata = adcm2700_reg_read(ADCM2700_PROC_CTRL_V_REG);
+    adcm2700_reg_write(ADCM2700_PROC_CTRL_V_REG, regdata|0x4800);
+
+    /* still mode sharpening enable*/
+    regdata = adcm2700_reg_read(ADCM2700_PROC_CTRL_S_REG);
+    adcm2700_reg_write(ADCM2700_PROC_CTRL_S_REG, regdata|0x4800);
+
+
+    /* disable automatic dark*/
+    regdata = 0x64;
+    adcm2700_reg_write(0x081C, regdata);
+}
+
+int adcm2700_set_flicker(int flicker)
+{
+   
+    u16 old = adcm2700_reg_read(EREG_AF_CTRL2);
+    u16 old1 = adcm2700_reg_read(SREG_ILLUM);
+    old1 &= ~(0x18);
+    dbg_print("set flicker to %d", flicker);
+    if(flicker == 50)
+    {
+        adcm2700_reg_write(SREG_ILLUM, old1|0x08);
+        adcm2700_write(EREG_AF_CTRL2, old&(~0x02));
+        //1000 = 100000/50/2
+        adcm2700_write(EREG_AE_ETIME_DFLT, 1000);
+    }
+    else if(flicker == 60)
+    {
+         adcm2700_reg_write(SREG_ILLUM, old1|0x10);
+         adcm2700_write(EREG_AF_CTRL2, old|0x02);
+         // 833 = 100000/60/2 
+         adcm2700_write(EREG_AE_ETIME_DFLT, 833);  
+    }
+    else
+    {
+        return ADCM_ERR_PARAMETER;
+    }
+    return 0;
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm2700_hw.h linux-2.6.16.5-exz/drivers/media/video/adcm2700_hw.h
--- linux-2.6.16.5/drivers/media/video/adcm2700_hw.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm2700_hw.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,533 @@
+/*================================================================================
+                                                                               
+                      Header Name: adcm2700_hw.h
+
+General Description: Camera module adcm2700 interface header file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)     12/15/2003      LIBdd35749   Created   
+wangfei(w20239)     02/05/2004      LIBdd74309   Set frame rate in video mode
+wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
+wangfei(w20239)     03/08/2004      LIBdd84578   Photo effects setting
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _PXA_ADCM_2700_HW_H__
+#define _PXA_ADCM_2700_HW_H__
+
+#include "camera.h"
+/***********************************************************************
+ * 
+ * Constants & Structures
+ *
+ ***********************************************************************/
+ 
+/* ADCM_WINDOWSIZE */
+typedef struct {
+    u16 width;
+    u16 height;
+} adcm_window_size;
+
+
+// Revision constants
+#define PIPE_REV            0x60
+#define PIPE_REV_NEW        0x61
+#define SENSOR_REV          0x60
+
+// Calculating the Module Block Number
+#define BLOCK(a)            (u8)((a) >> 7)        // register's module block address.
+#define OFFSET(a)           (u8)((a) & 0x7F ) // register's offset to this block.
+
+// Return codes
+#define ADCM_ERR_NONE       0x00
+#define ADCM_ERR_TIMEOUT    -1
+#define ADCM_ERR_PARAMETER  -2  
+
+// Auto Exposure Frequency
+#define AEF_50HZ    0x20
+#define AEF_60HZ    0x40
+
+// Non JEPG Output Format
+#define O_FORMAT_888RGB         0   //0b0000    // 888 RGB (1 pixel in 3 bytes )
+#define O_FORMAT_666_A_RGB      1   //0b0001    // 666 A RGB (tight pack, 4 pixels in 9 bytes)
+#define O_FORMAT_666_B_RGB      2   //0b0010    // 666 B RGB (loose pack, 1 pixel in 3 bytes,left or right justified)
+#define O_FORMAT_565_RGB        3   //0b0011    // 565 RGB (1 pixel in 2 bytes)
+#define O_FORMAT_444_A_RGB      4   //0b0100    // 444 A RGB (tight pack, 2 pixels per 3 bytes, RG BR GB)
+#define O_FORMAT_444_B_RGB      5   //0b0101    // 444 B RGB (loose pack, 1 pixel per 2 bytes,RG B0 or 0R GB)
+#define O_FORMAT_444_C_RGV      6   //0b0110    // 444 C RGB (sparse pack, 1 pixel per three bytes,R0 G0 B0 or 0R 0G 0B)
+#define O_FORMAT_332_RGB        7   //0b0111    // 332 RGB (1 pixel in 1 byte)
+#define O_FORMAT_422_A_YCbYCr   8   //0b1000    // 4:2:2 A YCbYCr (Y1 Cb12 Y2 CRL2 order)
+#define O_FORMAT_422_B_YCbYCr   9   //0b1001    // 4:2:2 B YCbYCr (Cb12 Y1 CRL2 Y2 order)
+#define O_FORMAT_422_C_YCbYCr   10  //0b1010    // 4:2:2 C YCbYCr (Y1 CRL2 Y2 Cb12 order)
+#define O_FORMAT_422_D_YCbYCr   11  //0b1011    // 4:2:2 D YCbYCr (CRL2 Y1 Cb12 Y2 order)
+#define O_FORMAT_444_YCbYCr     12  //0b1100    // 4:4:4 YCbCr (1 pixels per 3 bytes)
+#define O_FORMAT_400_B_YCbYCr   13  //0b1101    // 4:0:0 YCbCr (Greyscale, 1 pixel per 1 byte)
+#define O_FORMAT_RAWBPA         14  //0b1110    // RAWBPA (with AWB and BPA)
+#define O_FORMAT_RAW            15  //0b1111    // RAW (without AWB and BPA)
+
+// Camera Mode
+#define VIEWFINDER_MODE     0x10
+#define STILLFRAME_MODE     0x20
+
+// Others
+#define adcm2700__TIMEOUT   100              // ms to timeout.
+#define BLOCK_SWITCH_CMD    ((u8)0xFE)        // Block Switch Code: 0x7F, CMD = Code << 1
+#define VOLTS_28            0x28
+
+
+/*************************************************************************************
+ *
+ * Simple Control Registers Address
+ *
+ *************************************************************************************/
+//      name                addr    description                        default   page
+#define SREG_ID             0x0000  //Chip ID                           0x0060   139
+#define SREG_CONTROL        0x0002  //Camera control                    0x0001   140
+#define SREG_STATUS         0x0004  //Camera status                     0x0004   142
+#define SREG_CLK_FREQ       0x0006  //Input clock frequency             0x32c8   144
+#define SREG_SIZE           0x0008  //Image size and orientation        0x0605   145
+#define SREG_OUTPUT_FORMAT  0x000a  //Output format                     0x0909   147
+#define SREG_EXPOSURE       0x000c  //Exposure                          0x03e8   149
+#define SREG_EXP_ADJ        0x000e  //Exposure adjustment               0x0000   150
+#define SREG_ILLUM          0x0010  //Illumination                      0x0000   151
+#define SREG_FRAME_RATE     0x0012  //Requested frame rate              0x0096   152
+#define SREG_A_FRAME_RATE   0x0016  //Actual frame rate                 0x0096   154
+#define SREG_SENSOR_WID_V   0x0018  //Sensor window width, video mode   0x0000   155
+#define SREG_SENSOR_HGT_V   0x001a  //Sensor window height, video mode  0x0000   156
+#define SREG_OUTPUT_WID_V   0x001c  //Output window width, video mode   0x0000   157
+#define SREG_OUTPUT_HGT_V   0x001e  //Output window height, video mode  0x0000   158
+#define SREG_SENSOR_WID_S   0x0020  //Sensor window width, still mode   0x0000   159
+#define SREG_SENSOR_HGT_S   0x0022  //Sensor window height, still mode  0x0000   160
+#define SREG_OUTPUT_WID_S   0x0024  //Output window width, still mode   0x0000   161
+#define SREG_OUTPUT_HGT_S   0x0026  //Output window height, still mode  0x0000   162
+
+/*************************************************************************************
+ *
+ * Expert Hardware Registers
+ *
+ *************************************************************************************/
+//      name                addr       description                        default   page
+#define  EREG_I_CLK_DIV      0x0080    //Initial clock divider              0x0001  166
+#define  EREG_CTL_CLK_DIV    0x0082    //Clock dividers for control 
+                                       //and serial interfaces              0x4000  167
+#define  EREG_SEN_CLK_DIV    0x0084    //Sensor clock dividers              0x0000  168
+#define  EREG_IP_CLK_DIV     0x0086    //Clock dividers for image pipeline  0x0000  169
+#define  EREG_TST_MODE       0x0088    //Latched test mode                  0x0000  170
+#define  EREG_SER_ADDR       0x008a    //Serial interface device address    0x0053  171
+#define  EREG_SER_PARM       0x008c    //Serial Interface parameters        0x0000  172
+#define  EREG_OUT_CTRL       0x008e    //Output control                     0x0000  173
+#define  EREG_PLL_CTRL       0x0090    //PLL control                        0x0024  174
+#define  EREG_PLL_DIV_L      0x0092    //PLL divisors, large values         0x1d09  175
+#define  EREG_PLL_DIV_S      0x0094    //PLL divisors, small values         0x0200  176
+
+/*************************************************************************************
+ *
+ * Expert Control Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                             default  page
+#define  EREG_SZR_IN_WID_V    0x0100   //Sizer input width, video mode           0x0280  184
+#define  EREG_SZR_IN_HGT_V    0x0102   //Sizer input height, video mode          0x01e0  185
+#define  EREG_SZR_OUT_WID_V   0x0104   //Sizer output width, video mode          0x0140  186
+#define  EREG_SZR_OUT_HGT_V   0x0106   //Sizer output height, video mode         0x00f0  187
+#define  EREG_CPP_V           0x0108   //Clocks per pixel, video mode            0x0002  188
+#define  EREG_HBLANK_V        0x010a   //Horizontal blanking period, video mode  0x0000  189
+#define  EREG_VBLANK_V        0x010c   //Vertical blanking period, video mode    0x0000  190
+#define  EREG_MIN_MAX_F_V     0x010e   //Frame convergence rates, video mode     0x0000  191
+#define  EREG_OUTPUT_CTRL_V   0x0110   //Output control, video mode              0x9019  192
+#define  EREG_PROC_CTRL_V     0x0112   //Processing control, video mode          0x0280  194
+#define  EREG_RPT_V           0x0114   //Row processing time, video mode         0x0546  196
+#define  EREG_HYSNC_PER_V     0x0116   //HSYNC period, video mode                0x0a8b  197
+#define  EREG_CLK_DIV_V       0x0118   //Clock divisors, video mode              0x0000  198
+#define  EREG_PARALLEL_CTRL_V 0x011a   //Parallel output control, video mode     0x0003  199
+#define  EREG_SEN_CTRL_V      0x011c   //Sensor control, video mode              0x0000  200
+
+#define  EREG_SZR_IN_WID_S    0x0120   //Sizer input width, still mode           0x0280  202
+#define  EREG_SZR_IN_HGT_S    0x0122   //Sizer input height, still mode          0x01e0  203
+#define  EREG_SZR_OUT_WID_S   0x0124   //Sizer output width, still mode          0x0280  204
+#define  EREG_SZR_OUT_HGT_S   0x0126   //Sizer output height, still mode         0x01e0  205
+#define  EREG_CPP_S           0x0128   //Clocks per pixel, still mode            0x0002  206
+#define  EREG_HBLANK_S        0x012a   //Horizontal blanking period, still mode  0x0000  207
+#define  EREG_VBLANK_S        0x012c   //Vertical blanking period, still mode    0x0000  208
+#define  EREG_MIN_MAX_F_S     0x012e   //Frame convergence rates, still mode     0x0002  209
+#define  EREG_OUTPUT_CTRL_S   0x0130   //Output control, still mode              0x8019  210
+#define  EREG_PROC_CTRL_S     0x0132   //Processing control, still mode          0x0280  212
+#define  EREG_RPT_S           0x0134   //Row processing time, still mode         0x0546  214
+#define  EREG_HYSNC_PER_S     0x0136   //HSYNC period, still mode                0x0545  215
+#define  EREG_CLK_DIV_S       0x0138   //Clock divisors, still mode              0x0000  216
+#define  EREG_PARALLEL_CTRL_S 0x013a   //Parallel output control, still mode     0x0000  217
+#define  EREG_SEN_CTRL_S      0x013c   //Sensor control, still mode              0x0000  218
+
+#define  EREG_AF_CTRL1        0x0140   //Auto functions control 1                0x0013  220
+#define  EREG_AF_CTRL2        0x0142   //Auto functions control 2                0x0001  221
+#define  EREG_AF_STATUS       0x0144   //Auto functions status                   0x0000  222
+#define  EREG_SOF_CODES       0x0146   //Start of frame codes                    0xfeff  223
+#define  EREG_EOF_CODES       0x0148   //End of frame codes                      0x0100  224
+#define  EREG_ABL_TARGET      0x014a   //Auto black level target                 0x0005  225
+#define  EREG_ABL_MAX_BIN     0x014c   //Auto black level maximum bin            0x0003  226
+#define  EREG_ABL_MAX_BLACK   0x014e   //Auto black level maximum black          0x0010  227
+#define  EREG_AE_GAIN_MIN     0x0150   //Auto exposure gain minimum              0x01c0  228
+#define  EREG_AE_GAIN_MIN_P   0x0152   //Auto exposure gain minimum, preferred   0x0200  229
+#define  EREG_AE_GAIN_MAX     0x0154   //Auto exposure gain maximum              0x0500  230
+#define  EREG_AE_GAIN_DFLT    0x0156   //Auto exposure gain default              0x0200  231
+#define  EREG_AE_ETIME_MIN    0x0158   //Auto exposure time minimum              0x0005  232
+#define  EREG_AE_ETIME_MAX    0x015a   //Auto exposure time maximum              0x4e20  233
+#define  EREG_AE_ETIME_DFLT   0x015c   //Auto exposure time default              0x03e8  234
+#define  EREG_AE_TARGET       0x015e   //Auto exposure target                    0x0040  235
+#define  EREG_AE_TOL_ACQ      0x0160   //Auto exposure tolerance acquire         0x0118  236
+#define  EREG_AE_TOL_MON      0x0162   //Auto exposure tolerance monitor         0x0118  237
+#define  EREG_AE_MARGIN       0x0164   //Auto exposure margin                    0x0120  238
+#define  EREG_AE_DOE_FACTOR   0x0166   //AE deliberate overexposure factor       0x014e  239
+#define  EREG_AE_DOE_MARGIN   0x0168   //AE deliberate overexposure margin       0x0140  240
+
+#define  EREG_AWB_RED_MIN     0x0170   //AWB minimum red/green ratio             0x00c0  242
+#define  EREG_AWB_RED_MAX     0x0172   //AWB maximum red/green ratio             0x01a6  243
+#define  EREG_AWB_RED_DFLT    0x0174   //AWB default red/green ratio             0x0134  244
+#define  EREG_AWB_BLUE_MIN    0x0176   //AWB minimum blue/green ratio            0x00c0  245
+#define  EREG_AWB_BLUE_MAX    0x0178   //AWB maximum blue/green ratio            0x02a4  246
+#define  EREG_AWB_BLUE_DFLT   0x017a   //AWB default blue/green ratio            0x01e4  247
+#define  EREG_AWB_TOL_ACQ     0x017c   //Auto white balance tolerance acquire    0x0110  248
+#define  EREG_AWB_TOL_MON     0x017e   //Auto white balance tolerance monitor    0x0120  249
+#define  EREG_FIRMWARE_REV    0x0180   //Current firmware revision               0x0152  250
+#define  EREG_FLICK_CFG_1     0x0182   //Flicker configuration 1                 0x2aeb  251
+#define  EREG_FLICK_CFG_2     0x0184   //Flicker configuration 2                 0x0005  252
+
+#define  EREG_MAX_SCLK        0x018a   //Maximum sensor clock                    0x1964  254
+
+#define  EREG_CSC_00_V        0x0190   //Color conversion coefficient 00, video  0x0026  256
+#define  EREG_CSC_01_V        0x0192   //Color conversion coefficient 01, video  0x004b  256
+#define  EREG_CSC_02_V        0x0194   //Color conversion coefficient 02, video  0x000f  256
+#define  EREG_CSC_10_V        0x0196   //Color conversion coefficient 10, video  0x01ed  256
+#define  EREG_CSC_11_V        0x0198   //Color conversion coefficient 11, video  0x01db  256
+#define  EREG_CSC_12_V        0x019a   //Color conversion coefficient 12, video  0x0038  256
+#define  EREG_CSC_20_V        0x019c   //Color conversion coefficient 20, video  0x004f  256
+#define  EREG_CSC_21_V        0x019e   //Color conversion coefficient 21, video  0x01be  256
+#define  EREG_CSC_22_V        0x01a0   //Color conversion coefficient 22, video  0x01f3  256
+
+#define  EREG_CSC_OS0_V       0x01a2   //Color space conversion offset 0, video  0x0000  257
+#define  EREG_CSC_OS1_V       0x01a4   //Color space conversion offset 1, video  0x0080  257
+#define  EREG_CSC_OS2_V       0x01a6   //Color space conversion offset 2, video  0x0080  257
+
+#define  EREG_CSC_00_S        0x01a8   //Color conversion coefficient 00, still  0x0026  258
+#define  EREG_CSC_01_S        0x01aa   //Color conversion coefficient 01, still  0x004b  258
+#define  EREG_CSC_02_S        0x01ac   //Color conversion coefficient 02, still  0x000f  258
+#define  EREG_CSC_10_S        0x01ae   //Color conversion coefficient 10, still  0x01ed  258
+#define  EREG_CSC_11_S        0x01b0   //Color conversion coefficient 11, still  0x01db  258
+#define  EREG_CSC_12_S        0x01b2   //Color conversion coefficient 12, still  0x0038  258
+#define  EREG_CSC_20_S        0x01b4   //Color conversion coefficient 20, still  0x004f  258
+#define  EREG_CSC_21_S        0x01b6   //Color conversion coefficient 21, still  0x01be  258
+#define  EREG_CSC_22_S        0x01b8   //Color conversion coefficient 22, still  0x01f3  258
+                                                                                       
+#define  EREG_CSC_OS0_S       0x01ba   //Color space conversion offset 0, still  0x0000  259
+#define  EREG_CSC_OS1_S       0x01bc   //Color space conversion offset 1, still  0x0080  259
+#define  EREG_CSC_OS2_S       0x01be   //Color space conversion offset 2, still  0x0080  259
+
+
+#define  EREG_TM_COEF_00_V    0x01c0   //Tonemap coefficient 00, video           0x0000  261
+#define  EREG_TM_COEF_01_V    0x01c2   //Tonemap coefficient 01, video           0x0017  261
+#define  EREG_TM_COEF_02_V    0x01c4   //Tonemap coefficient 02, video           0x0032  261
+#define  EREG_TM_COEF_03_V    0x01c6   //Tonemap coefficient 03, video           0x0046  261
+#define  EREG_TM_COEF_04_V    0x01c8   //Tonemap coefficient 04, video           0x0056  261
+#define  EREG_TM_COEF_05_V    0x01ca   //Tonemap coefficient 05, video           0x0064  261
+#define  EREG_TM_COEF_06_V    0x01cc   //Tonemap coefficient 06, video           0x0071  261
+#define  EREG_TM_COEF_07_V    0x01ce   //Tonemap coefficient 07, video           0x007c  261
+#define  EREG_TM_COEF_08_V    0x01d0   //Tonemap coefficient 08, video           0x0086  261
+#define  EREG_TM_COEF_09_V    0x01d2   //Tonemap coefficient 09, video           0x0099  261
+#define  EREG_TM_COEF_10_V    0x01d4   //Tonemap coefficient 10, video           0x00a9  261
+#define  EREG_TM_COEF_11_V    0x01d6   //Tonemap coefficient 11, video           0x00b8  261
+#define  EREG_TM_COEF_12_V    0x01d8   //Tonemap coefficient 12, video           0x00c6  261
+#define  EREG_TM_COEF_13_V    0x01da   //Tonemap coefficient 13, video           0x00df  261
+#define  EREG_TM_COEF_14_V    0x01dc   //Tonemap coefficient 14, video           0x00f5  261
+#define  EREG_TM_COEF_15_V    0x01de   //Tonemap coefficient 15, video           0x0109  261
+#define  EREG_TM_COEF_16_V    0x01e0   //Tonemap coefficient 16, video           0x011b  261
+#define  EREG_TM_COEF_17_V    0x01e2   //Tonemap coefficient 17, video           0x013d  261
+#define  EREG_TM_COEF_18_V    0x01e4   //Tonemap coefficient 18, video           0x015a  261
+#define  EREG_TM_COEF_19_V    0x01e6   //Tonemap coefficient 19, video           0x0175  261
+#define  EREG_TM_COEF_20_V    0x01e8   //Tonemap coefficient 20, video           0x018d  261
+#define  EREG_TM_COEF_21_V    0x01ea   //Tonemap coefficient 21, video           0x01ba  261
+#define  EREG_TM_COEF_22_V    0x01ec   //Tonemap coefficient 22, video           0x01e1  261
+#define  EREG_TM_COEF_23_V    0x01ee   //Tonemap coefficient 23, video           0x0205  261
+#define  EREG_TM_COEF_24_V    0x01f0   //Tonemap coefficient 24, video           0x0225  261
+#define  EREG_TM_COEF_25_V    0x01f2   //Tonemap coefficient 25, video           0x0261  261
+#define  EREG_TM_COEF_26_V    0x01f4   //Tonemap coefficient 26, video           0x0295  261
+#define  EREG_TM_COEF_27_V    0x01f6   //Tonemap coefficient 27, video           0x02c5  261
+#define  EREG_TM_COEF_28_V    0x01f8   //Tonemap coefficient 28, video           0x02f1  261
+#define  EREG_TM_COEF_29_V    0x01fa   //Tonemap coefficient 29, video           0x033f  261
+#define  EREG_TM_COEF_30_V    0x01fc   //Tonemap coefficient 30, video           0x0385  261
+#define  EREG_TM_COEF_31_V    0x01fe   //Tonemap coefficient 31, video           0x03c5  261
+#define  EREG_TM_COEF_32_V    0x0200   //Tonemap coefficient 32, video           0x0400  261
+
+#define  EREG_TM_COEF_00_S    0x0202   //Tonemap coefficient 00, still           0x0000  262
+#define  EREG_TM_COEF_01_S    0x0204   //Tonemap coefficient 01, still           0x0017  262
+#define  EREG_TM_COEF_02_S    0x0206   //Tonemap coefficient 02, still           0x0032  262
+#define  EREG_TM_COEF_03_S    0x0208   //Tonemap coefficient 03, still           0x0046  262
+#define  EREG_TM_COEF_04_S    0x020a   //Tonemap coefficient 04, still           0x0056  262
+#define  EREG_TM_COEF_05_S    0x020c   //Tonemap coefficient 05, still           0x0064  262
+#define  EREG_TM_COEF_06_S    0x020e   //Tonemap coefficient 06, still           0x0071  262
+#define  EREG_TM_COEF_07_S    0x0210   //Tonemap coefficient 07, still           0x007c  262
+#define  EREG_TM_COEF_08_S    0x0212   //Tonemap coefficient 08, still           0x0086  262
+#define  EREG_TM_COEF_09_S    0x0214   //Tonemap coefficient 09, still           0x0099  262
+#define  EREG_TM_COEF_10_S    0x0216   //Tonemap coefficient 10, still           0x00a9  262
+#define  EREG_TM_COEF_11_S    0x0218   //Tonemap coefficient 11, still           0x00b8  262
+#define  EREG_TM_COEF_12_S    0x021a   //Tonemap coefficient 12, still           0x00c6  262
+#define  EREG_TM_COEF_13_S    0x021c   //Tonemap coefficient 13, still           0x00df  262
+#define  EREG_TM_COEF_14_S    0x021e   //Tonemap coefficient 14, still           0x00f5  262
+#define  EREG_TM_COEF_15_S    0x0220   //Tonemap coefficient 15, still           0x0109  262
+#define  EREG_TM_COEF_16_S    0x0222   //Tonemap coefficient 16, still           0x011b  262
+#define  EREG_TM_COEF_17_S    0x0224   //Tonemap coefficient 17, still           0x013d  262
+#define  EREG_TM_COEF_18_S    0x0226   //Tonemap coefficient 18, still           0x015a  262
+#define  EREG_TM_COEF_19_S    0x0228   //Tonemap coefficient 19, still           0x0175  262
+#define  EREG_TM_COEF_20_S    0x022a   //Tonemap coefficient 20, still           0x018d  262
+#define  EREG_TM_COEF_21_S    0x022c   //Tonemap coefficient 21, still           0x01ba  262
+#define  EREG_TM_COEF_22_S    0x022e   //Tonemap coefficient 22, still           0x01e1  262
+#define  EREG_TM_COEF_23_S    0x0230   //Tonemap coefficient 23, still           0x0205  262
+#define  EREG_TM_COEF_24_S    0x0232   //Tonemap coefficient 24, still           0x0225  262
+#define  EREG_TM_COEF_25_S    0x0234   //Tonemap coefficient 25, still           0x0261  262
+#define  EREG_TM_COEF_26_S    0x0236   //Tonemap coefficient 26, still           0x0295  262
+#define  EREG_TM_COEF_27_S    0x0238   //Tonemap coefficient 27, still           0x02c5  262
+#define  EREG_TM_COEF_28_S    0x023a   //Tonemap coefficient 28, still           0x02f1  262
+#define  EREG_TM_COEF_29_S    0x023c   //Tonemap coefficient 29, still           0x033f  262
+#define  EREG_TM_COEF_30_S    0x023e   //Tonemap coefficient 30, still           0x0385  262
+#define  EREG_TM_COEF_31_S    0x0240   //Tonemap coefficient 31, still           0x03c5  262
+#define  EREG_TM_COEF_32_S    0x0242   //Tonemap coefficient 32, still           0x0400  262
+
+#define  EREG_NACC_EGP_1      0x0250   //NACC EGP 1                              0x05dc  265
+#define  EREG_NACC_SAT_1      0x0252   //NACC saturation 1                       0x0000  265
+#define  EREG_NACC_EGP_2      0x0254   //NACC EGP 2                              0x0465  265
+#define  EREG_NACC_SAT_2      0x0256   //NACC saturation 2                       0x0040  265
+#define  EREG_NACC_EGP_3      0x0258   //NACC EGP 3                              0x02ee  265
+#define  EREG_NACC_SAT_3      0x025a   //NACC saturation 3                       0x0080  265
+#define  EREG_NACC_EGP_4      0x025c   //NACC EGP 4                              0x0177  265
+#define  EREG_NACC_SAT_4      0x025e   //NACC saturation 4                       0x00c0  265
+#define  EREG_NACC_EGP_5      0x0260   //NACC EGP 5                              0x0000  265
+#define  EREG_NACC_SAT_5      0x0262   //NACC saturation 5                       0x0100  265
+#define  EREG_NACC_EGP_6      0x0264   //NACC EGP 6                              0x0000  265
+#define  EREG_NACC_SAT_6      0x0266   //NACC saturation 6                       0x0000  265
+#define  EREG_NACC_EGP_7      0x0268   //NACC EGP 7                              0x0000  265
+#define  EREG_NACC_SAT_7      0x026a   //NACC saturation 7                       0x0000  265
+#define  EREG_NACC_EGP_8      0x026c   //NACC EGP 8                              0x0000  265
+#define  EREG_NACC_SAT_8      0x026e   //NACC saturation 8                       0x0000  265
+#define  EREG_NACC_BC_00      0x0270   //NACC NACC bright coefficients 00        0x0235  266
+#define  EREG_NACC_BC_01      0x0272   //NACC NACC bright coefficients 01        0xff46  266
+#define  EREG_NACC_BC_02      0x0274   //NACC bright coefficients 02             0xff85  266
+#define  EREG_NACC_BC_10      0x0276   //NACC bright coefficients 10             0xff64  266
+#define  EREG_NACC_BC_11      0x0278   //NACC bright coefficients 11             0x01fc  266
+#define  EREG_NACC_BC_12      0x027a   //NACC bright coefficients 12             0xff9f  266
+#define  EREG_NACC_BC_20      0x027c   //NACC bright coefficients 20             0x0008  266
+#define  EREG_NACC_BC_21      0x027e   //NACC bright coefficients 21             0xfe8d  266
+#define  EREG_NACC_BC_22      0x0280   //NACC bright coefficients 22             0x026b  266
+#define  EREG_NACC_DC_00      0x0282   //NACC dark coefficients 00               0x0048  266
+#define  EREG_NACC_DC_01      0x0284   //NACC dark coefficients 01               0x010b  266
+#define  EREG_NACC_DC_02      0x0286   //NACC dark coefficients 02               0xffaa  266
+#define  EREG_NACC_DC_10      0x0288   //NACC dark coefficients 10               0x0048  266
+#define  EREG_NACC_DC_11      0x028a   //NACC dark coefficients 11               0x010b  266
+#define  EREG_NACC_DC_12      0x028c   //NACC dark coefficients 12               0xffaa  266
+#define  EREG_NACC_DC_20      0x028e   //NACC dark coefficients 20               0x0048  266
+#define  EREG_NACC_DC_21      0x0290   //NACC dark coefficients 21               0x010b  266
+#define  EREG_NACC_DC_22      0x0292   //NACC dark coefficients 22               0xffaa  266
+                         
+/*************************************************************************************
+ *
+ * Expert Sensor Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                             default  page
+#define  EREG_IDENT          0x0800    //Image sensor identification             0x60     272
+#define  EREG_IS_STATUS      0x0801    //Image sensor status                     0x00     273
+#define  EREG_ICTRL          0x0805    //Interface control                       0x00     275
+
+#define  EREG_ADC_CTRL       0x0809    //ADC control                             0x01     277
+#define  EREG_FWROW          0x080a    //Window first row address                0x01     278
+#define  EREG_FWCOL          0x080b    //Window first column address             0x01     279
+#define  EREG_LWROW          0x080c    //Window last row address                 0x7a     280
+#define  EREG_LWCOL          0x080d    //Window last column address              0xa2     281
+#define  EREG_CLK_PIXEL      0x080e    //Clocks per pixel                        0x02     282
+#define  EREG_EREC_PGA       0x080f    //Even row, even column(green 1)PGA gain  0x00     283
+#define  EREG_EROC_PGA       0x0810    //Even row, odd column (red) PGA gain     0x00     284
+#define  EREG_OREC_PGA       0x0811    //Odd row, even column (blue) PGA gain    0x00     285
+#define  EREG_OROC_PGA       0x0812    //Odd row, odd column (green 2) PGA gain  0x00     286
+#define  EREG_ROWEXP_L       0x0813    //Row exposure low                        0x54     287
+#define  EREG_ROWEXP_H       0x0814    //Row exposure high                       0x00     288
+#define  EREG_SROWEXP        0x0815    //Sub row exposure                        0x31     289
+#define  EREG_ERROR          0x0816    //Error control                           0x00     290
+
+#define  EREG_HBLANK         0x0819    //Horizontal blank                        0x00     292
+#define  EREG_VBLANK         0x081a    //Vertical blank                          0x00     293
+#define  EREG_CONFIG_1       0x081b    //Image sensor configuration 1            0x0e     294
+#define  EREG_CONTROL_1      0x081c    //Image sensor control 1                  0x24     295
+
+#define  EREG_CONFIG_2       0x0827    //Image sensor configuration 2            0x00     298
+#define  EREG_GRR_CTRL       0x0828    //Ground reset reference control          0x00     299
+
+#define  EREG_BIAS_TRM       0x0837    //Bias trim                               0x00     301
+#define  EREG_SMP_GR_E2      0x08d7    //Sample ground reference edge 2          0x00     303
+#define  EREG_SMP_GR_E1      0x08d8    //Sample ground reference edge 1          0x10     304
+#define  EREG_SMP_GR_E0      0x08d9    //Sample ground reference edge 0          0x0a     305
+
+#define  EREG_EXP_GR_E1      0x08dc    //Exposure, ground reference edge 1       0x10     307
+#define  EREG_EXP_GR_E0      0x08dd    //Exposure, ground reference edge 0       0x06     308
+#define  EREG_GR_POL         0x08df    //Ground reference polarity               0xd3     310
+
+#define  EREG_SMP_RST_E2     0x08eb    //Sample, reset edge 2                    0x04     312
+#define  EREG_SMP_RST_E1     0x08ec    //Sample, reset edge 1                    0x10     313
+#define  EREG_SMP_RST_E0     0x08ed    //Sample, reset edge 0                    0x07     314
+
+#define  EREG_EXP_RST_E1     0x08f0    //Exposure, reset edge 1                  0x10     316
+#define  EREG_EXP_RST_E0     0x08f1    //Exposure, reset edge 1                  0x03     317
+#define  EREG_RESET_POL      0x08f3    //Reset polarity enable                   0xd3     319
+
+#define  EREG_SMP_PRST_E2    0x08f5    //Sample, preset edge 2                   0x00     321
+#define  EREG_SMP_PRST_E1    0x08f6    //Sample, preset edge 1                   0x02     322
+#define  EREG_SMP_PRST_E0    0x08f7    //Sample, preset edge 0                   0x0a     323
+
+#define  EREG_EXP_PRST_E1    0x08fa    //Exposure, preset edge 1                 0x02     325
+#define  EREG_EXP_PRST_E0    0x08fb    //Exposure, preset edge 1                 0x06     326
+#define  EREG_PRESET_POL     0x08fd    //Preset polarity enable                  0xd3     328
+
+/*************************************************************************************
+ *
+ * Expert Image Pipeline Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                               default  page
+                                    
+#define  EREG_CMD_1           0x1002    //Main command 1                           0x0000  335
+#define  EREG_CMD_2           0x1004    //Main command 2 (write 1¡¯s only)         0x0002  336
+#define  EREG_OUTPUT_CTRL     0x1008    //Output control, working                  0x9019  338
+#define  EREG_PARALLEL_CTRL   0x100a    //Parallel output control working copy     0x0000  340
+#define  EREG_SOF_CODE_W      0x100c    //Start of frame code working copy         0x00ff  341
+#define  EREG_PEOF_CODES      0x100e    //End of frame codes working copy          0x0100  342
+#define  EREG_CCIR_TIMING     0x1010    //CCIR interface timing                    0x0000  343
+#define  EREG_R_Y_MAX_MIN     0x1012    //Luminance, Y (or red) maximum/minimum    0xff00  344
+#define  EREG_G_CB_MAX_MIN    0x1014    //Chrominance,Cb(or green)maximum/minimum  0xff00  345
+#define  EREG_B_CR_MAX_MIN    0x1016    //Chrominance,Cr(or blue)maximum/minimum   0xff00  346
+#define  EREG_PROCESS_CTRL    0x1018    //Processing control working copy          0x0280  347
+#define  EREG_BPA_SF_GTHRESH  0x101a    //BPA scale factor,green filter threshold  0x0220  349
+#define  EREG_BPA_OUTL_PED    0x101c    //BPA outlier, pedestal                    0x4008  350
+#define  EREG_BPA_BADPIX_CNT  0x101e    //BPA bad pixel count (read only)          0x0000  351
+#define  EREG_SZR_IN_W        0x1020    //Sizer input width                        0x0280  352
+#define  EREG_SZR_IN_H        0x1022    //Sizer input height                       0x01e0  353
+#define  EREG_SZR_OUT_W       0x1024    //Sizer output width                       0x0140  354
+#define  EREG_SZR_OUT_H       0x1026    //Sizer output height                      0x00f0  355
+
+
+#define  EREG_CC_COEF_00      0x1028    //Color correction coefficient 00          0x02f9  358
+#define  EREG_CC_COEF_01      0x102a    //Color correction coefficient 01          0x0f03  358
+#define  EREG_CC_COEF_02      0x102c    //Color correction coefficient 02          0x0f02  358
+#define  EREG_CC_COEF_10      0x102e    //Color correction coefficient 10          0x0f4f  358
+#define  EREG_CC_COEF_11      0x1030    //Color correction coefficient 11          0x025c  358
+#define  EREG_CC_COEF_12      0x1032    //Color correction coefficient 12          0x0f54  358
+#define  EREG_CC_COEF_20      0x1034    //Color correction coefficient 20          0x0fe0  358
+#define  EREG_CC_COEF_21      0x1036    //Color correction coefficient 21          0x0e4a  358
+#define  EREG_CC_COEF_22      0x1038    //Color correction coefficient 22          0x02d5  358
+                                                                                         
+#define  EREG_CC_PRE_OS_0     0x103a    //Color correction pre-offset 0            0x01f8  360
+#define  EREG_CC_PRE_OS_1     0x103c    //Color correction pre-offset 1            0x01f8  360
+#define  EREG_CC_PRE_OS_2     0x103e    //Color correction pre-offset 2            0x01f8  360
+#define  EREG_CC_POST_OS_0    0x1040    //Color correction post-offset 0           0x0000  360
+#define  EREG_CC_POST_OS_1    0x1042    //Color correction post-offset 1           0x0000  360
+#define  EREG_CC_POST_OS_2    0x1044    //Color correction post-offset 2           0x0000  360
+
+#define  EREG_CSC_COEF_00     0x1046    //Color space conversion coefficient 00    0x0026  363
+#define  EREG_CSC_COEF_01     0x1048    //Color space conversion coefficient 01    0x004b  363
+#define  EREG_CSC_COEF_02     0x104a    //Color space conversion coefficient 02    0x000f  363
+#define  EREG_CSC_COEF_10     0x104c    //Color space conversion coefficient 10    0x01ed  363
+#define  EREG_CSC_COEF_11     0x104e    //Color space conversion coefficient 11    0x01db  363
+#define  EREG_CSC_COEF_12     0x1050    //Color space conversion coefficient 12    0x0038  363
+#define  EREG_CSC_COEF_20     0x1052    //Color space conversion coefficient 20    0x004f  363
+#define  EREG_CSC_COEF_21     0x1054    //Color space conversion coefficient 21    0x01be  363
+#define  EREG_CSC_COEF_22     0x1056    //Color space conversion coefficient 22    0x01f3  363
+#define  EREG_CSC_OS_0        0x1058    //Color space conversion offset 0          0x0000  364
+#define  EREG_CSC_OS_1        0x105a    //Color space conversion offset 1          0x0080  364
+#define  EREG_CSC_OS_2        0x105c    //Color space conversion offset 2          0x0080  364
+#define  EREG_DATA_GEN        0x105e    //Test data generator                      0x0000  365
+#define  EREG_HSYNC_PER       0x1060    //Horizontal synchronization period        0x0a8b  366
+#define  EREG_APS_COEF_GRN1   0x1062    //Green 1 AWB gain                         0x0080  368
+#define  EREG_APS_COEF_RED    0x1064    //Red AWB gain                             0x0080  368
+
+
+#define  EREG_APS_COEF_BLUE     0x1066  //Blue AWB gain                            0x0080  368
+#define  EREG_APS_COEF_GRN2     0x1068  //Green 2 AWB gain                         0x0080  368
+#define  EREG_AV_LEFT_TOP       0x106a  //Anti-v,sensor first row and column       0x0101  369
+#define  EREG_AV_RIGHT_BOT      0x106c  //Anti-v, sensor last row and column       0xa27a  370
+#define  EREG_AV_CENTER_COL     0x106e  //Anti-v, sensor center column             0x0148  371
+#define  EREG_AV_CENTER_ROW     0x1070  //Anti-v, sensor center row                0x00f8  372
+#define  EREG_STAT_CAP_CTRL     0x1072  //Image statistics capture control         0x0021  373
+#define  EREG_STAT_MODE_CTRL    0x1074  //Image statistics mode control            0x0000  374
+#define  EREG_GREEN_1_SUM       0x1076  //Green 1 pixel sum                        0x0000  375
+#define  EREG_RED_SUM           0x1078  //Red pixel sum                            0x0000  375
+#define  EREG_BLUE_SUM          0x107a  //Blue pixel sum                           0x0000  375
+#define  EREG_GREEN_2_SUM       0x107c  //Green 2 pixel sum                        0x0000  375
+#define  EREG_I_WIDTH           0x107e  //Current image width                      0x0000  376
+#define  EREG_I_HEIGHT          0x1080  //Current image height                     0x0000  377
+#define  EREG_STATUS_FLAGS      0x1082  //Status flags (read only)                 0x0000  378
+#define  EREG_CLK_GATE_DIS      0x1084  //Clock gate disable                       0x0000  379
+#define  EREG_CCIR_TIMING2      0x1086  //CCIR interface timing 2                  0x0000  381
+#define  EREG_CCIR_TIMING3      0x1088  //CCIR interface timing 3                  0x0010  382
+#define  EREG_G1G2_DIAG_THRESH  0x108a  //Green 1/green 2 diagonal threshold       0x0040  383
+#define  EREG_BPA_D2_THRESH     0x108c  //BPA second derivative threshold          0x0100  384
+#define  EREG_SERIAL_CTRL       0x108e  //Serial control                           0x0000  385
+#define  EREG_INTP_CTRL_1       0x1090  //Interpolation control 1(demosaic)        0x0188  387
+#define  EREG_INTP_CTRL_2       0x1092  //Interpolation control 2(demosaic)        0x00c8  388
+#define  EREG_AV_OVAL_FACT      0x1094  //Anti-vignetting oval factor              0x0100  389
+#define  EREG_AV_OS_GREEN1      0x1096  //Anti-vignetting green 1 offset           0x0000  391
+#define  EREG_AV_OS_RED         0x1098  //Anti-vignetting red offset               0x0000  391
+#define  EREG_AV_OS_BLUE        0x109a  //Anti-vignetting blue offset              0x0000  391
+#define  EREG_AV_OS_GREEN2      0x109c  //Anti-vignetting green 2 offset           0x0000  391
+                                    
+
+                                                                            
+/***********************************************************************                   
+ *                                                                                         
+ * Function Prototype                 
+ *                                    
+ ***********************************************************************/
+
+u16  adcm2700_reg_read(u16 reg_addr);
+void adcm2700_reg_write(u16 reg_addr, u16 reg_value);
+
+
+// Configuration Procedures
+int adcm2700_power_on(u8);
+int adcm2700_power_off(void );
+int adcm2700_change_viewfinder_mode(adcm_window_size * input_win, adcm_window_size *vf_output_win, adcm_window_size *sf_output_win );
+int adcm2700_firmware_upgrade( void );
+int adcm2700_version_revision(u16 * cm_revision, u16 *sensor_revision);
+int adcm2700_viewfinder_on( void );
+int adcm2700_viewfinder_off( void );
+int adcm2700_master_clock(u8 clk);
+int adcm2700_viewfinder_input_size(adcm_window_size * win );
+int adcm2700_stillframe_input_size(adcm_window_size * win );
+int adcm2700_viewfinder_output_size(adcm_window_size * win);
+int adcm2700_stillframe_output_size(adcm_window_size * win);
+int adcm2700_stillframe_cfg_output(u16 format);
+int adcm2700_viewfinder_cfg_output(u16 format);
+int adcm2700_gamma_correction(void);
+int adcm2700_get_output_frame_rate(u16 * fps);
+int adcm2700_detect_camera_mode(u16 *mode);
+
+int adcm2700_set_fps(u16 fps, u16 minfps);
+
+int adcm2700_input_size(adcm_window_size * win);
+int adcm2700_output_size(adcm_window_size * win);
+int adcm2700_get_input_size(adcm_window_size * win);
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+int adcm2700_set_style(V4l_PIC_STYLE style);
+/*set picture light(direct sun/incandescent/fluorescent)*/     
+int adcm2700_set_light(V4l_PIC_WB light);
+/*set picture brightness*/
+int adcm2700_set_bright(int bright);
+
+int adcm2700_restore_property(p_camera_context_t cam_ctx, int frames);
+
+#endif /* _PXA_ADCM_2700_HW_H__ */
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm3800.c linux-2.6.16.5-exz/drivers/media/video/adcm3800.c
--- linux-2.6.16.5/drivers/media/video/adcm3800.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm3800.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,619 @@
+ 
+/*================================================================================
+                                                                               
+                      Header Name: adcm3800.c
+
+General Description: Camera module adcm3800 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      12/15/2003     LIBdd35749   Created   
+wangfei(w20239)      02/05/2004     LIBdd74309   Set frame rate in video mode
+wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
+                                                 Update algorithm for DMA transfer
+                                                 Update strategy for memory management
+                                                 Fix still picture capture failed sometime
+                                                 New Agilent sensor chip ID support
+                                                 Make output height in an even multiple of 8
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+
+#include <asm/irq.h>
+#include <asm/hardware.h>
+
+#include <asm/arch/pxa-regs.h>
+
+#include "camera.h"
+#include "adcm3800.h"
+#include "adcm3800_hw.h"
+
+
+/***********************************************************************
+ *
+ * ADCM3800  common functions
+ *
+ ***********************************************************************/
+#define MAX_WIDTH          1280
+#define MAX_HEIGHT         1024
+#define MIN_WIDTH          64
+#define MIN_HEIGHT         56
+#define WIDTH_DEFT         320
+#define HEIGHT_DEFT        240
+#define S_WIDTH_DEFT       1280
+#define S_HEIGHT_DEFT      960
+#define FRAMERATE_DEFT	   15
+#define MCLK_DEFT          48             /* Default Master clock*/
+#define BUF_SIZE_DEFT      ((PAGE_ALIGN(MAX_WIDTH * MAX_HEIGHT) + (PAGE_ALIGN(MAX_WIDTH*MAX_HEIGHT/2)*2)))
+
+extern int i2c_adcm3800_init(void);
+extern int i2c_adcm3800_cleanup(void);
+
+//////////////////////////////////////////////////////////////////////////////////////
+//adcm3800 functions
+//
+static int camera_func_adcm3800_init(p_camera_context_t);
+static int camera_func_adcm3800_deinit(p_camera_context_t);
+static int camera_func_adcm3800_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+static int camera_func_adcm3800_set_capture_format(p_camera_context_t);
+static int camera_func_adcm3800_start_capture(p_camera_context_t, unsigned int frames);
+static int camera_func_adcm3800_stop_capture(p_camera_context_t);
+
+static int camera_func_adcm3800_pm_management(p_camera_context_t, int);
+
+static int adcm3800_sensor_init(p_camera_context_t cam_ctx);
+
+
+camera_function_t  camera_adcm3800_func = 
+{
+    init:                camera_func_adcm3800_init,
+    deinit:              camera_func_adcm3800_deinit,
+    command:             camera_func_adcm3800_docommand,
+    set_capture_format:  camera_func_adcm3800_set_capture_format,
+    start_capture:       camera_func_adcm3800_start_capture,
+    stop_capture:        camera_func_adcm3800_stop_capture,
+    pm_management:       camera_func_adcm3800_pm_management
+};
+
+static int camera_func_adcm3800_init(p_camera_context_t cam_ctx)
+{
+    int ret = 0;
+    // init context status
+    cam_ctx->dma_channels[0] = 0xFF;
+    cam_ctx->dma_channels[1] = 0xFF;
+    cam_ctx->dma_channels[2] = 0xFF;
+    
+    cam_ctx->capture_width  = WIDTH_DEFT;
+    cam_ctx->capture_height = HEIGHT_DEFT;
+    cam_ctx->sensor_width  = S_WIDTH_DEFT;
+    cam_ctx->sensor_height = S_HEIGHT_DEFT;
+    
+    cam_ctx->capture_input_format  = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    
+    cam_ctx->frame_rate = cam_ctx->fps = FRAMERATE_DEFT;
+    
+    cam_ctx->mini_fps = FRAMERATE_DEFT-5;
+    
+    cam_ctx->mclk = MCLK_DEFT;
+    cam_ctx->flicker_freq = 50;
+    
+    cam_ctx->buf_size     = BUF_SIZE_DEFT;
+    cam_ctx->dma_descriptors_size = (cam_ctx->buf_size/PAGE_SIZE + 10);
+    cam_ctx->vc.maxwidth  = MAX_WIDTH;
+    cam_ctx->vc.maxheight = MAX_HEIGHT;
+    cam_ctx->vc.minwidth  = MIN_WIDTH; 
+    cam_ctx->vc.minheight = MIN_HEIGHT;
+       
+    camera_gpio_init();
+    ci_init();
+    
+    // Configure CI according to hardware
+  	// master parallel with 8 data pins
+   	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8); 
+
+  	// enable pixel clock(sensor will provide pclock)
+   	ci_set_clock(cam_ctx->clk_reg_base, 1, 1, cam_ctx->mclk);
+
+   	// data sample on rising and h,vsync active high
+   	ci_set_polarity(0, 0, 0);
+	
+   	// fifo control
+   	ci_set_fifo(0, CI_FIFO_THL_32, 1, 1); // quality
+
+   	// Turn on M_CLK using xx MHz and wait for 150 ms.
+    ci_enable(1);
+    
+    mdelay(10);    // TODO: reduce it
+    
+    if(i2c_adcm3800_init() == 0)
+    {
+        cam_ctx->sensor_type = CAMERA_TYPE_ADCM3800;
+
+        //mdelay(100);
+    
+        if((ret =  adcm3800_sensor_init(cam_ctx)) < 0)
+        {
+            dbg_print("adcm3800 hardware init error!");
+            return -1;
+        }
+        ddbg_print("Agilent ADCM3800 camera module detected!");
+    }
+    else
+        return -1;
+
+    return 0;
+}
+
+/***********************************************************************
+ *
+ * ADCM3800 Functions
+ *
+ ***********************************************************************/
+static int adcm3800_sensor_init(  p_camera_context_t camera_context )
+{
+    //u32 adcm_mclk = camera_context->mclk * 195000 / 192;   // SYS_CLK is 195Mhz
+    u32 adcm_mclk = camera_context->mclk * 1000;
+    adcm3800_power_on(adcm_mclk);
+    return 0;
+}
+
+static int camera_func_adcm3800_deinit(  p_camera_context_t camera_context )
+{
+    dbg_print("adcm3800 off!");
+
+    /* power off the external module */
+    camera_func_adcm3800_stop_capture(camera_context);
+
+    adcm3800_power_off();
+    i2c_adcm3800_cleanup();
+
+    /* disable CI */
+    ci_disable(1);
+	
+   	camera_gpio_deinit();
+    return 0;
+}
+
+static int camera_func_adcm3800_set_capture_format(p_camera_context_t camera_context)
+{
+    u16 adcm_format;
+    window_size size;
+
+    //set sensor format
+    switch(camera_context->capture_input_format)
+    {
+        case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+        case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+            adcm_format = O_FORMAT_422_B_YCbYCr;
+        break;
+        case CAMERA_IMAGE_FORMAT_RGB565:
+            adcm_format = O_FORMAT_565_RGB;
+        break;
+        case CAMERA_IMAGE_FORMAT_RGB888_PACKED:
+        case CAMERA_IMAGE_FORMAT_RGB888_PLANAR:
+   	        adcm_format = O_FORMAT_888RGB;
+        break;
+        default:
+            adcm_format = O_FORMAT_422_B_YCbYCr;
+        break;
+    }
+    adcm3800_set_output_format(adcm_format);
+
+    size.width  = camera_context->capture_width;
+    size.height = camera_context->capture_height;
+    adcm3800_set_output_size(size.width, size.height);
+
+    return 0;
+}
+
+static int camera_func_adcm3800_start_capture(p_camera_context_t cam_ctx, unsigned int frames)
+{
+    int   ret;
+    int   cisr;
+    int   wait_count;
+    static int error_times = 0;
+    unsigned int start_time;
+ 
+    // frames=0 means video mode capture	
+    if(frames == 0) 
+    {
+        // ddbg_print("video capture!"); 
+        wait_count = 1;
+    }
+    else 
+    {
+        // ddbg_print("still capture");
+        wait_count = 1;
+    }
+    ret = adcm3800_reconfigure(cam_ctx, frames);
+    if(ret<0)
+        return ret;
+    adcm3800_viewfinder_on();
+
+    ci_disable(1);
+    ci_enable(1);
+
+    dbg_print("wait for SOF %d time", wait_count);
+    start_time = 0xFFFFF * 20 * wait_count;
+
+    CISR |= CI_CISR_SOF;
+    CISR |= CI_CISR_EOF;
+    cisr=CISR;
+    while(wait_count)
+    {
+       if(cisr & CI_CISR_EOF)
+       {
+          dbg_print("get EOF %d:%d", wait_count, start_time);
+          CISR |= CI_CISR_EOF;
+       }          
+       if(cisr & CI_CISR_SOF)
+       {
+          dbg_print("get SOF %d:%d", wait_count, start_time);
+          wait_count -- ;
+          CISR |= CI_CISR_SOF;
+       }          
+       cisr=CISR;
+       if(!(--start_time))
+       {
+          goto wait_SOF_error;
+       }
+
+    }
+    //mdelay(1);
+    ci_disable(1);
+    ci_enable(1);
+    ci_reset_fifo();
+    //ci_clear_int_status(0xFFFFFFFF);
+    start_dma_transfer(cam_ctx, cam_ctx->block_header);
+    dbg_print("wait ok..%d", start_time);
+    return 0;
+    
+wait_SOF_error:
+    error_times++;
+    dbg_print("wait SOF error! error_times = %d", error_times);    
+    return -EIO;
+}
+
+static int camera_func_adcm3800_stop_capture(p_camera_context_t cam_ctx)
+{
+    adcm3800_viewfinder_off();
+    stop_dma_transfer(cam_ctx);
+    return 0;
+}
+
+static int camera_func_adcm3800_pm_management(p_camera_context_t cam_ctx, int suspend)
+{
+    static int resume_dma = 0;
+    if(suspend)
+    {
+        if(cam_ctx != NULL )
+        {
+            if(cam_ctx->dma_started) 
+            {
+                ddbg_print("camera running, suspended");
+                stop_dma_transfer(cam_ctx);
+                resume_dma = 1;
+            }
+        }
+
+        disable_irq(IRQ_CAMERA);
+        pxa_set_cken(CKEN24_CAMERA, 0);
+    }
+    else
+    {
+        pxa_set_cken(CKEN24_CAMERA, 1);
+        enable_irq(IRQ_CAMERA);
+
+        if(cam_ctx != NULL)
+        {  
+            ddbg_print("camera running, resumed");
+            camera_init(cam_ctx);
+            if(resume_dma == 1)
+            {
+                camera_start_video_capture(cam_ctx, 0);
+                resume_dma = 0;
+            }
+        }
+    }
+   return 0;
+}
+
+/*set picture brightness*/
+static int pxa_cam_WCAM_VIDIOCSBRIGHT(p_camera_context_t cam_ctx, void * param)
+{
+    int ret = 0;
+    int bright;
+    bright = (int)param;
+    ddbg_print("WCAM_VIDIOCSBRIGHT %d", bright);
+
+    cam_ctx->capture_bright = bright;
+    ret = adcm3800_set_bright(bright);
+
+    if(cam_ctx->dma_started == 1 && ret>0)
+    {
+        camera_func_adcm3800_stop_capture(cam_ctx);
+        ret = camera_func_adcm3800_start_capture(cam_ctx, 0);
+        return ret;
+    }
+    return 0;
+}
+
+/*set picture style*/  
+static int pxa_cam_WCAM_VIDIOCSSTYLE(p_camera_context_t cam_ctx, void * param)
+{
+    int ret = 0;
+    V4l_PIC_STYLE style;
+    style = (V4l_PIC_STYLE)param;
+    ddbg_print("WCAM_VIDIOCSSTYLE %d", style);
+
+    cam_ctx->capture_style = style;
+    ret = adcm3800_set_style(style);
+    if(cam_ctx->dma_started == 1 && ret>0)
+    {
+        camera_func_adcm3800_stop_capture(cam_ctx);
+        ret = camera_func_adcm3800_start_capture(cam_ctx, 0);
+        return ret;
+    } 
+    return 0;
+}
+
+        
+/*set picture light*/     
+static int pxa_cam_WCAM_VIDIOCSLIGHT(p_camera_context_t cam_ctx, void * param)
+{
+    int ret = 0;
+    V4l_PIC_WB light;
+    light = (V4l_PIC_WB)param;
+    dbg_print("WCAM_VIDIOCSLIGHT %d", light);
+
+    cam_ctx->capture_light = light;
+    ret = adcm3800_set_light(light);
+    if(cam_ctx->dma_started == 1)
+    {
+        camera_func_adcm3800_stop_capture(cam_ctx);
+        ret = camera_func_adcm3800_start_capture(cam_ctx, 0);
+        return ret;
+    }
+    return 0;
+}
+
+
+//set  output size
+static int pxa_cam_WCAM_VIDIOCSOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+   //ddbg_print("WCAM_VIDIOCSOSIZE");
+   
+   window_size size;
+ 
+   if(copy_from_user(&size, param, sizeof(window_size))) 
+   {
+        return  -EFAULT;
+   }
+   if(cam_ctx->dma_started == 1)
+   {
+        return -EFAULT;
+   }
+
+   //make it in an even of multiple of 8
+   size.width  = (size.width +7)/8 * 8;
+   size.height = (size.height+7)/8 * 8;
+   
+   dbg_print("w=%d h=%d", size.width, size.height);
+
+   if(cam_ctx->capture_width != size.width || cam_ctx->capture_height != size.height)
+   {
+       dbg_print("error: the camera output size should match CSWIN size");
+       return -EINVAL;
+   }
+   
+   return 0;
+}
+
+/*Set  sensor size*/  
+static int pxa_cam_WCAM_VIDIOCSSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+    //ddbg_print("WCAM_VIDIOCSSSIZE");
+    window_size size;
+    int ret;
+  
+    if(copy_from_user(&size, param, sizeof(window_size))) 
+    {
+        return  -EFAULT;
+    }
+    if(cam_ctx->dma_started == 1)
+    {
+        return -EFAULT;
+    }
+
+    //make it in an even of multiple of 8
+    size.width  = (size.width +7)/8 * 8;
+    size.height = (size.height+7)/8 * 8;
+  
+    cam_ctx->sensor_width = size.width;
+    cam_ctx->sensor_height = size.height;
+    dbg_print("w = %d h = %d", size.width, size.height);
+
+    ret = adcm3800_set_sensor_size(size.width, size.height);
+    if(ret<0)
+        return ret;
+
+    return 0;
+}
+
+static int pxa_cam_WCAM_VIDIOCSFPS(p_camera_context_t cam_ctx, void * param)
+{
+    //ddbg_print("WCAM_VIDIOCSFPS");
+    
+    struct {int fps, minfps;} cam_fps;
+    int ret = 0;
+    
+    if(copy_from_user(&cam_fps, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    if(cam_fps.fps < 5)
+    {
+       cam_fps.fps = 5;
+    }
+     
+    ddbg_print("WCAM_VIDIOCSFPS %d:%d", cam_ctx->fps, cam_fps.fps);
+    if(cam_ctx->fps != cam_fps.fps || cam_ctx->mini_fps != cam_fps.minfps)
+    {
+        cam_ctx->fps = cam_fps.fps;
+        cam_ctx->mini_fps = cam_fps.minfps;
+
+        ret = adcm3800_set_fps(cam_ctx->fps * 10);
+        if(ret<0)
+            return ret;
+
+        if(cam_ctx->dma_started == 1 && ret>1)
+        {
+            camera_func_adcm3800_stop_capture(cam_ctx);
+            ret = camera_func_adcm3800_start_capture(cam_ctx, 0);
+            return ret;
+        }
+    }
+    return 0;
+}
+
+static int pxa_cam_WCAM_VIDIOCSNIGHTMODE(p_camera_context_t cam_ctx, void * param)
+{
+    int ret;
+    struct {
+        V4l_NM mode;
+        int maxtime;
+    } expo_mode;
+    if (copy_from_user(&expo_mode, param, sizeof(expo_mode))) {
+        return -EFAULT;
+    }
+    ddbg_print("WCAM_VIDIOCSNIGHTMODE %d:%d", expo_mode.mode, expo_mode.maxtime);
+
+    ret = adcm3800_set_exposure_mode(expo_mode.mode, expo_mode.maxtime);
+    if(cam_ctx->dma_started == 1 && ret>0)
+    {
+        camera_func_adcm3800_stop_capture(cam_ctx);
+        ret = camera_func_adcm3800_start_capture(cam_ctx, 0);
+        return ret;
+    }
+    return 0;
+}
+
+/*set flicker frequency*/
+static int pxa_cam_WCAM_VIDIOCSFLICKER(p_camera_context_t cam_ctx, void * param)
+{
+    int ret;
+    dbg_print("WCAM_VIDIOCSFLICKER");
+    cam_ctx->flicker_freq = (int)param;
+
+    if(cam_ctx->dma_started == 1)
+        return -EPERM;
+
+    ret = adcm3800_set_flicker(cam_ctx->flicker_freq);
+    if(ret<0)
+        return ret;
+
+    return 0;
+}
+
+static int pxa_camera_WCAM_VIDIOCGCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    int ret, offset;
+    u16 value;
+    //ddbg_print("WCAM_VIDIOCGCAMREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return -EFAULT;
+    }
+    ret = i2c_adcm3800_read((u16)offset, &value);
+    if(ret<0)
+        return ret;
+
+    if(copy_to_user(param, &value, sizeof(int))) 
+    {
+        return -EFAULT;
+    } 
+
+    return 0;
+}
+
+static int pxa_camera_WCAM_VIDIOCSCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    struct reg_set_s{int val1, val2;} reg_s;
+    //ddbg_print("WCAM_VIDIOCSCAMREG");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    i2c_adcm3800_write((u16)reg_s.val1, (u16)reg_s.val2);
+    return 0;
+} 
+
+static int camera_func_adcm3800_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+   switch(cmd)
+   {
+     /*read adcm3800 registers*/
+    case WCAM_VIDIOCGCAMREG:
+         return pxa_camera_WCAM_VIDIOCGCAMREG(cam_ctx, param);
+
+    /*write adcm3800 registers*/
+    case WCAM_VIDIOCSCAMREG:
+          return pxa_camera_WCAM_VIDIOCSCAMREG(cam_ctx, param);
+        
+    /*set sensor size */  
+    case WCAM_VIDIOCSSSIZE:
+         return pxa_cam_WCAM_VIDIOCSSSIZE(cam_ctx, param);
+
+    /*set output size*/
+    case WCAM_VIDIOCSOSIZE:
+         return pxa_cam_WCAM_VIDIOCSOSIZE(cam_ctx, param);
+         
+          
+    /*set video mode fps*/
+    case WCAM_VIDIOCSFPS:
+         return pxa_cam_WCAM_VIDIOCSFPS(cam_ctx, param);
+            
+    case WCAM_VIDIOCSNIGHTMODE:
+         return pxa_cam_WCAM_VIDIOCSNIGHTMODE(cam_ctx, param);
+            
+    /*set picture style*/  
+    case WCAM_VIDIOCSSTYLE:
+         return pxa_cam_WCAM_VIDIOCSSTYLE(cam_ctx, param);
+         
+    /*set picture light*/     
+    case WCAM_VIDIOCSLIGHT:
+         return pxa_cam_WCAM_VIDIOCSLIGHT(cam_ctx, param);
+    
+    /*set picture brightness*/
+    case WCAM_VIDIOCSBRIGHT:
+         return pxa_cam_WCAM_VIDIOCSBRIGHT(cam_ctx, param);
+         
+    /*set flicker frequency*/
+    case WCAM_VIDIOCSFLICKER:
+         return pxa_cam_WCAM_VIDIOCSFLICKER(cam_ctx, param);
+
+    default:
+         {
+           dbg_print("Error cmd=0x%x", cmd);
+           return -1;
+         }
+  }
+  return 0;
+ 
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm3800.h linux-2.6.16.5-exz/drivers/media/video/adcm3800.h
--- linux-2.6.16.5/drivers/media/video/adcm3800.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm3800.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,41 @@
+
+/*================================================================================
+                                                                               
+                      Header Name: adcm3800.h
+
+General Description: Camera module adcm3800  interface head file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      12/15/2003     LIBdd35749    Created   
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _ADCM3800_H_
+#define _ADCM3800_H_
+
+#include "camera.h"
+
+//////////////////////////////////////////////////////////////////////////////////////
+//
+//          Prototypes
+//
+//////////////////////////////////////////////////////////////////////////////////////
+
+/* WINDOW SIZE */
+typedef struct {
+    u16 width;
+    u16 height;
+} window_size;
+
+#endif /* _ADCM3800_H_ */
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm3800_hw.c linux-2.6.16.5-exz/drivers/media/video/adcm3800_hw.c
--- linux-2.6.16.5/drivers/media/video/adcm3800_hw.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm3800_hw.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,1828 @@
+/*================================================================================
+                                                                               
+                      Header Name: adcm3800_hw.c
+
+General Description: Camera module adcm3800 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)     12/15/2003      LIBdd35749    Created   
+
+wangfei(w20239)     02/05/2004      LIBdd74309    Set frame rate in video mode
+
+wangfei(w20239)     02/26/2004      LIBdd81055    New chip id support
+                                                  Update algorithm for DMA transfer
+                                                  Update strategy for memory management
+                                                  Fix still picture capture failed sometime
+                                                  New Agilent sensor chip ID support
+                                                  Make output height in an even multiple of 8
+                                                 
+wangfei(w20239)     03/08/2004      LIBdd84578    Photo effects setting
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/delay.h>
+
+#include "camera.h"
+#include "adcm3800_hw.h"
+
+#define  MAX_FPS  300   // 30 fps
+
+static adcm3800_context_t  adcm3800_context;
+
+#define adcm3800_read(addr, pvalue)             \
+    i2c_adcm3800_read(addr, pvalue);            \
+    ddbg_print("i2c read: a(0x%04x) v(0x%04x)", addr, *(pvalue));
+ 
+#define adcm3800_write(addr, value)             \
+    i2c_adcm3800_write(addr, value);            \
+    ddbg_print("i2c write: a(0x%04x) v(0x%04x)", addr, value);
+ 
+#define adcm3800_read_byte(addr, pvalue)        \
+    i2c_adcm3800_read_byte(addr, pvalue);       \
+    ddbg_print("i2c read b: a(0x%04x) v(0x%02x)", addr, *(pvalue));
+ 
+#define adcm3800_write_byte(addr, value)        \
+    i2c_adcm3800_write_byte(addr, value);       \
+    ddbg_print("i2c write b: a(0x%04x) v(0x%02x)", addr, value);
+ 
+static int adcm3800_reg_read(u16 reg_addr)
+{
+    u16 value;
+    int ret = adcm3800_read(reg_addr, &value);
+    if(ret < 0)
+    {
+        return ret;
+    }
+    return value;
+}
+
+// These routine writes to consectutive 16 bit registers
+// with addresses that increment by 2.
+static int adcm3800_write_regs (u16 regAddr, u16 *regData, u16 nRegs)
+{
+    int i, ret;
+    for(i = 0; i < nRegs; i++)
+    {
+        ret = adcm3800_write(regAddr+i*2, regData[i]);
+        if(ret < 0)
+        {
+            dbg_print("adcm3800 write error %d:%04x!", i, regAddr+i*2);
+            return -1;
+        }
+    }
+    return i;
+}
+
+static int adcm3800_writeb_regs (u16 regAddr, u8 *regData, u16 nRegs)
+{
+    int i, ret;
+    for(i = 0; i < nRegs; i++)
+    {
+        ret = adcm3800_write_byte(regAddr+i, regData[i]);
+        if(ret < 0)
+        {
+            dbg_print("adcm3800 write error %d:%04x!", i, regAddr+i*2);
+            return -1;
+        }
+    }
+    return i;
+}
+     
+void adcm3800_dump_awb_regs(void)
+{
+#ifdef DEBUG
+    int i;
+    unsigned short value;
+    unsigned char valueb;
+
+    // read some PI/AWB registers
+    adcm3800_read(0x003e, &value);  // current CC matrix for PI
+    dbg_print("003e: %04x (PI index)", value);
+    adcm3800_read(0x1064, &value);  // current red gains
+    dbg_print("1064: %04x (red gain)", value);
+    adcm3800_read(0x1066, &value);  // current blue gains
+    dbg_print("1066: %04x (blue gain)", value);
+
+    // read only current registers
+    adcm3800_read(0x0244, &value);  // C_GAIN,  current gain
+    dbg_print("0244: %04x (current gain)", value);
+    adcm3800_read(0x0246, &value);  // C_ETIME, current exposure time
+    dbg_print("0246: %04x (current exposure time)", value);
+    adcm3800_read(0x024a, &value);  // C_RG_RATIO,  current red/green ratio
+    dbg_print("024a: %04x (current red/green ratio)", value);
+    adcm3800_read(0x024c, &value);  // C_BG_RATIO,  current blue/green ratio
+    dbg_print("024c: %04x (current blue/green ratio)", value);
+#endif
+}
+
+static int adcm3800_print_status(void)
+{
+    adcm3800_dump_awb_regs();
+
+#if DEBUG > 1
+    int i;
+    unsigned short value;
+    unsigned char valueb;
+
+    adcm3800_read(0x0002, &value);
+    ddbg_print("control: %04x", value);
+    adcm3800_read(0x0004, &value);
+    ddbg_print("status: %04x", value);
+    adcm3800_read(0x000c, &value);
+    ddbg_print("exposure time: %d ms", value/100);
+    adcm3800_read(0x0016, &value);
+    ddbg_print("frame rate: %d/10 fps", value);
+
+    // read only current registers
+    adcm3800_read(0x0248, &value);  // C_BNF_TIME,  current flicker time
+
+    // PLL & clock registers
+    adcm3800_read(0x100a, &value);
+    adcm3800_read(0x3000, &value);
+    adcm3800_read(0x3004, &value);
+    adcm3800_read(0x3006, &value);
+
+    adcm3800_read(0x114, &value);
+
+    // Auto function registers
+    adcm3800_read(EREG_AE_TARGET, &value);
+    adcm3800_read(0x017c, &value);
+    adcm3800_read(0x017e, &value);
+
+    adcm3800_read(EREG_AF_CTRL1, &value);
+    adcm3800_read(EREG_AF_CTRL2, &value);
+    adcm3800_read(EREG_APS_COEF_GRN1, &value);
+    adcm3800_read(EREG_APS_COEF_GRN2, &value);
+    adcm3800_read(EREG_APS_COEF_RED, &value);
+    adcm3800_read(EREG_APS_COEF_BLUE, &value);
+
+    // statistics registers
+    //adcm3800_read(0x1076, &value);
+    //adcm3800_read(0x1074, &value);
+
+    // Sensor exposure registers
+    adcm3800_read_byte(0x080F, &valueb);
+    adcm3800_read_byte(0x0810, &valueb);
+    adcm3800_read_byte(0x0811, &valueb);
+    adcm3800_read_byte(0x0812, &valueb);
+    
+    adcm3800_read_byte(0x0813, &valueb);
+    adcm3800_read_byte(0x0814, &valueb);
+    adcm3800_read_byte(0x0815, &valueb);
+    adcm3800_read_byte(0x080e, &valueb);
+    
+    // read CC_COEF
+    for(i=0; i<9; i++)
+    {    adcm3800_read(0x1028+i*2, &value); }
+    // read NACC Bright CC
+    for(i=0; i<9; i++)
+    {    adcm3800_read(0x0270+i*2, &value); }
+    // read gamma
+    for(i=0; i<33; i++)
+    {    adcm3800_read(0x1400+i*2, &value); }
+    // read CSC
+    for(i=0; i<10; i++)
+    {    adcm3800_read(0x0190+i*2, &value); }
+    for(i=0; i<10; i++)
+    {    adcm3800_read(0x1046+i*2, &value); }
+#endif
+    return 0;
+}
+
+static void adcm3800_wait(u32 ms)
+{
+    if(ms > 10)
+    {
+        set_current_state(TASK_INTERRUPTIBLE);
+        schedule_timeout(ms/10);
+    }
+}
+
+static int wait_sreg_update(void)
+{
+    dbg_print("wait for sensor update simple registers");
+    adcm3800_write(SREG_CONTROL, 0x04);
+    adcm3800_wait(10);
+    int retry = adcm3800__TIMEOUT*4;
+    while(--retry)
+    {
+        u16 v;
+        int ret;
+        ret = adcm3800_read(SREG_CONTROL, &v);
+        if(ret<0)
+            return ret;
+
+        if(!(v & 0x04))
+        { 
+            dbg_print("retry = %d", retry);
+            return 0;
+        }
+        adcm3800_wait(2);
+    }
+    dbg_print("error:timeout to SCL, retry = %d", retry);
+    return -EIO;
+}
+ 
+static int adcm3800_firmware_upgrade(void);
+static int adcm3800_init_regs(void);
+
+static void adcm3800_init_context(void)
+{
+    memset(&adcm3800_context, 0, sizeof(adcm3800_context));
+
+    adcm3800_context.SCL_restart = 1;        // force restart at first time
+    adcm3800_context.format = O_FORMAT_NONE;
+    adcm3800_context.max_expotime = 100000;  // 100ms
+}
+
+///////////////////////////////////////////////////////////////
+//
+//   Programming Guide Chapter 1: Basic Programming
+//
+///////////////////////////////////////////////////////////////
+
+int adcm3800_master_clock(u32 clk)
+{
+#if 1
+    int i;
+    unsigned short value;
+    unsigned int   clock;
+    //0x5017  3.375X    // 24M*3.375 = 81M
+    //0x502f  1.6875X   // 48M*1.6875 = 81M
+    //0x4f2f            // 48.75*80/48 = 81.25M
+    //u16 div = 0x4f2f;   // 48.75*80/48 = 81.25M
+    u16 div = 0x502f;   // 48.75*81/48 = 82.265625M
+
+    clock = clk*((div>>8) + 1) / ((div&0xFF) + 1);
+    
+    adcm3800_read(EREG_PLL_CTRL,  &value);
+    dbg_print("1 clk %d, clock %d, PLL CTRL : %04x", clk, clock, value);
+    /*enable pll*/
+    adcm3800_write(0x300a, clock/4000-1);
+    adcm3800_write(EREG_PLL_DIV_L, div);
+    adcm3800_write(EREG_PLL_DIV_S, div);
+    adcm3800_write(EREG_PLL_CTRL,  0x0015);  //0x002D
+    adcm3800_write(0x3040, 0x0100);
+    
+    adcm3800_write(0x010c, 0x0006);
+    adcm3800_write(SREG_CLK_FREQ, (u16)(clock / 10));
+
+    for(i=0; i<1000; i++)
+    {
+        adcm3800_read(EREG_PLL_CTRL,  &value);
+        dbg_print("2 PLL CTRL : %04x", value);
+        if(value&0x80)
+            break;
+        mdelay(2);
+    }
+    dbg_print("3 wait %d ms : ", i*2);
+
+#else
+    adcm3800_write(SREG_CLK_FREQ, (u16)(clk / 10));
+#endif
+
+    return 0;
+}
+
+int adcm3800_power_on( u32 clk )
+{
+    adcm3800_init_context();
+
+    //read out version
+    //u16 sensor_rev, cm_rev;
+    //adcm3800_version_revision(&cm_rev, &sensor_rev);
+
+    /*Follow these steps to correctly power on the ADCM-2700:
+    1 Turn on VCC voltage (2.8 volts) and wait 20 milliseconds.
+    2 Turn on MCLK (13 MHz is the default value) and wait 150 milliseconds.
+    3 Read register 0x0004; if the return value equals 0x0001, power-up is complete. */
+    int   retry = adcm3800__TIMEOUT/2;
+    int   timeout = 0;
+    while(--retry)
+    {
+        int ret;
+        u16 value;
+        ret = adcm3800_read(SREG_STATUS, &value);
+        if(value == 0x0001)
+        {
+             dbg_print("adcm3800 Power-up complete!! time %dms", timeout); 
+             break;
+        }
+        adcm3800_wait(2);
+        timeout += 2;
+    }
+    if(retry==0)
+    {
+        dbg_print("error: timeout! Power-up failed!");
+        return -EIO;
+    }
+
+    // turn off camera
+    adcm3800_write(SREG_CONTROL, 0x0);
+
+    // Load the firmware upgrade
+    adcm3800_firmware_upgrade();
+
+    // initialize registers
+    adcm3800_init_regs();
+
+    /* Program the mafster clock */
+    adcm3800_master_clock(clk);
+
+    return 0;
+}
+
+
+int adcm3800_power_off()
+{
+	/*stop camera*/
+	adcm3800_write(SREG_CONTROL, 0);
+	return 0;   
+}
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+//   
+//  Programming Guide Chapter 2: Configuration Methods 
+//
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+static int adcm3800_version_revision(u16 * cm_revision, u16 *sensor_revision)
+{
+    u8 bvalue;
+
+    //Camera module version is 0x060
+    adcm3800_read(SREG_ID, cm_revision);
+    dbg_print("adcm3800 SREG_ID is 0x%x", *cm_revision);
+     
+    //Image sensor version is 0x60
+    adcm3800_read_byte(EREG_IDENT, &bvalue);
+    *sensor_revision = bvalue;
+    dbg_print("adcm3800 EREG_IDENT is 0x%x", *sensor_revision);
+
+    return 0;
+}
+
+int adcm3800_viewfinder_on()
+{
+    ddbg_print("camera video mode start!"); 
+    adcm3800_print_status();
+    return 0;
+}
+
+int adcm3800_viewfinder_off()
+{
+    adcm3800_print_status();
+
+    ddbg_print("camera video mode stop!");
+    return 0;
+}
+
+static int adcm3800_register_sensor_size(u16 width, u16 height)
+{
+    adcm3800_write(SREG_SENSOR_WID_V, width);
+    adcm3800_write(SREG_SENSOR_HGT_V, height);
+    return 0;
+}
+
+int adcm3800_set_sensor_size(u16 width, u16 height)
+{
+    if( width!=adcm3800_context.sensor_w ||
+        height!=adcm3800_context.sensor_h )
+    {
+        adcm3800_context.sensor_w = width;
+        adcm3800_context.sensor_h = height;
+        adcm3800_context.SCL_partial = 1;
+        return 1;
+    }
+    return 0;
+}
+
+static int adcm3800_register_output_size(u16 width, u16 height)
+{
+    adcm3800_write(SREG_OUTPUT_WID_V, width);
+    adcm3800_write(SREG_OUTPUT_HGT_V, height);
+
+    return 0;
+}
+
+int adcm3800_set_output_size(u16 width, u16 height)
+{
+    if( width!=adcm3800_context.output_w || 
+        height!=adcm3800_context.output_h )
+    {
+        adcm3800_context.output_w = width;
+        adcm3800_context.output_h = height;
+        adcm3800_context.SCL_partial = 1;
+        return 1;
+    }
+    return 0;
+}
+
+
+static int adcm3800_register_output_format(u16 format)
+{
+    u16   newcfg;
+    u16   oldcfg;
+    adcm3800_read(SREG_OUTPUT_FORMAT, &oldcfg);
+      
+    newcfg = (oldcfg & 0xFFF0) | (format & 0x000F);
+    if(newcfg!=oldcfg)
+    {
+        adcm3800_write( SREG_OUTPUT_FORMAT, newcfg );
+    }
+
+    return 0;
+}
+
+int adcm3800_set_output_format(u16 format)
+{
+    if( format!=adcm3800_context.format )
+    {
+        adcm3800_context.format = format;
+        adcm3800_context.SCL_partial = 1;   // TODO: not confirmed
+        return 1;
+    }
+    return 0;
+}
+
+static int adcm3800_register_fps(p_adcm3800_context_t adcm_ctx)
+{
+    if( (adcm_ctx->fps>70) && (adcm_ctx->output_w > 640 || adcm_ctx->output_h > 480) )
+    {
+        //if capture size > VGA, the frame rate shall be low
+        // this is limit of CIF PCLK < 24.25Mhz
+        adcm3800_write(SREG_FRAME_RATE, 75);  // 7.5 fps
+    }
+    else
+    {
+        //normal fps
+        adcm3800_write(SREG_FRAME_RATE, adcm_ctx->fps);
+    }
+    return 0;
+}
+
+int adcm3800_set_fps(u16 fps)
+{
+    if(fps > MAX_FPS)
+    {
+        return -EINVAL;
+    }
+    
+    if( fps!=adcm3800_context.fps )
+    {
+        adcm3800_context.fps = fps;
+        adcm3800_context.SCL_partial = 1;   // TODO: not confirmed
+        return 1;
+    }
+    return 0;
+}
+
+static int adcm3800_register_gamma(int table)
+{
+  dbg_print("set gamma table %d", table);
+
+  const u16 value[][33] =   
+  {
+    //0 default sRGB
+    {
+    0x0000, 0x0017, 0x0032, 0x0046, 0x0056, 0x0064, 0x0071, 0x007c, 0x0086, 0x0099, 0x00a9,
+    0x00b8, 0x00c6, 0x00df, 0x00f5, 0x0109, 0x011b, 0x013d, 0x015a, 0x0175, 0x018d, 0x01ba,
+    0x01e1, 0x0205, 0x0225, 0x0261, 0x0295, 0x02c5, 0x02f1, 0x033f, 0x0385, 0x03c5, 0x0400},
+     
+    //1 2.6
+    {
+    0x0000, 0x005c, 0x0079, 0x008d, 0x009e, 0x00ac, 0x00b9, 0x00c4, 0x00ce, 0x00e1, 0x00f1, 
+    0x0100, 0x010e, 0x0126, 0x013b, 0x014e, 0x0160, 0x0180, 0x019c, 0x01b5, 0x01cc, 0x01f5,
+    0x0219, 0x023a, 0x0258, 0x028e, 0x02be, 0x02e9, 0x0310, 0x0356, 0x0394, 0x03cc, 0x0400}, 
+    
+    //2 2.5
+    {
+    0x0000, 0x0054, 0x006f, 0x0083, 0x0093, 0x00a0, 0x00ac, 0x00b7, 0x00c2, 0x00d4, 0x00e4, 
+    0x00f2, 0x00ff, 0x0117, 0x012d, 0x0140, 0x0151, 0x0171, 0x018d, 0x01a6, 0x01bd, 0x01e7,
+    0x020c, 0x022d, 0x024c, 0x0283, 0x02b3, 0x02df, 0x0308, 0x0350, 0x0390, 0x03ca, 0x0400}, 
+    
+    //3 2.4
+    {
+    0x0000, 0x004C, 0x0065, 0x0078, 0x0087, 0x0094, 0x00A0, 0x00ab, 0x00b5, 0x00c6, 0x00d6, 
+    0x00e4, 0x00f1, 0x0109, 0x011E, 0x0131, 0x0142, 0x0161, 0x017D, 0x0197, 0x01AE, 0x01d8,
+    0x01fd, 0x021F, 0x023E, 0x0276, 0x02a8, 0x02d5, 0x02ff, 0x0349, 0x038C, 0x03C8, 0x0400}, 
+    
+    //4 2.3
+    {
+    0x0000, 0x0043, 0x005b, 0x006d, 0x007c, 0x0088, 0x0094, 0x009e, 0x00a7, 0x00b8, 0x00c8,
+    0x00d6, 0x00e2, 0x00fa, 0x010e, 0x0121, 0x0132, 0x0151, 0x016d, 0x0187, 0x019e, 0x01c8,
+    0x01ee, 0x0210, 0x0230, 0x0269, 0x029c, 0x02ca, 0x02f5, 0x0342, 0x0387, 0x03c6, 0x0400},
+
+    //5 2.2
+    {
+    0x0000, 0x003c, 0x0052, 0x0063, 0x0070, 0x007c, 0x0087, 0x0091, 0x0094, 0x00ab, 0x00b9, 
+    0x00c7, 0x00d3, 0x00ea, 0x00fe, 0x0111, 0x0122, 0x0141, 0x015d, 0x0176, 0x018d, 0x01b8,
+    0x01de, 0x0201, 0x0221, 0x025b, 0x028f, 0x02bf, 0x02eb, 0x033b, 0x0382, 0x03c3, 0x0400},
+  
+    //6 2.1
+    {
+    0x0000, 0x0034, 0x0049, 0x0058, 0x0065, 0x0070, 0x007b, 0x0084, 0x008d, 0x009d, 0x00ab, 
+    0x00b8, 0x00c4, 0x00da, 0x00ee, 0x0100, 0x0111, 0x0130, 0x014b, 0x0164, 0x017c, 0x01a7,
+    0x01cd, 0x01f0, 0x0211, 0x024c, 0x0281, 0x02b2, 0x02e0, 0x0332, 0x037c, 0x03c0, 0x0400},
+     
+    //7 2.0
+    {
+    0x0000, 0x002d, 0x0040, 0x004e, 0x005a, 0x0065, 0x006e, 0x0077, 0x0080, 0x008f, 0x009c,
+    0x00a9, 0x00b5, 0x00ca, 0x00dd, 0x00ef, 0x0100, 0x011e, 0x0139, 0x0152, 0x016a, 0x0194,
+    0x01bb, 0x01de, 0x0200, 0x023c, 0x0273, 0x02a5, 0x02d4, 0x0329, 0x0376, 0x03bd, 0x0400},
+   
+    //8 1.9
+    {
+    0x0000, 0x0026, 0x0037, 0x0044, 0x004f, 0x0059, 0x0062, 0x006a, 0x0072, 0x0081, 0x008e, 
+    0x009a, 0x00a5, 0x00b9, 0x00cc, 0x00dd, 0x00ed, 0x010b, 0x0126, 0x013f, 0x0156, 0x0181, 
+    0x01a8, 0x01cc, 0x01ed, 0x022b, 0x0263, 0x0296, 0x02c6, 0x031f, 0x0370, 0x03ba, 0x0400},
+    
+    //9 1.8
+    {
+    0x0000, 0x0020, 0x002f, 0x003a, 0x0045, 0x004e, 0x0056, 0x005e, 0x0065, 0x0073, 0x007f, 
+    0x008a, 0x0095, 0x00a9, 0x00bb, 0x00cb, 0x00db, 0x00f8, 0x0112, 0x012b, 0x0142, 0x016d, 
+    0x0194, 0x01b8, 0x01da, 0x0218, 0x0251, 0x0286, 0x02b8, 0x0314, 0x0368, 0x03b6, 0x0400},
+   
+    //10 1.6
+    {
+    0x0000, 0x0014, 0x0020, 0x0029, 0x0031, 0x0038, 0x003f, 0x0046, 0x004c, 0x0057, 0x0062,
+    0x006b, 0x0075, 0x0086, 0x0097, 0x00a6, 0x00b5, 0x00d0, 0x00e9, 0x0100, 0x0117, 0x0140,
+    0x0167, 0x018c, 0x01ae, 0x01ee, 0x022a, 0x0262, 0x0297, 0x02fb, 0x0357, 0x03ae, 0x0400}
+
+  };
+  
+  int i, ret;
+  /*
+  for(i = 0; i < 33; i++)
+  {
+     adcm3800_write(0x1400+i*2, value[table][i]);
+  }
+  */
+  
+  for(i = 0; i < 33; i++)
+  {
+     ret = adcm3800_write(EREG_TM_COEF_00_V+i*2, value[table][i]);
+  }
+
+  return 0;
+}
+
+static int adcm3800_register_gamma_solarize(void)
+{
+  const u16 value[33] =   
+  {
+   //solarize
+     0x0400, 0x03e9, 0x03a9, 0x0344, 0x02c3, 0x0232, 0x019c, 0x010e, 0x0095, 0x003c, 0x0009,
+     0x0002, 0x0026, 0x0074, 0x00e3, 0x016b, 0x01ff, 0x0294, 0x031c, 0x038b, 0x03d9, 0x03fd,
+     0x03f6, 0x03c3, 0x036a, 0x02f1, 0x0263, 0x01cd, 0x013c, 0x00bb, 0x0056, 0x0016, 0x0000
+  };
+
+  int i, ret;
+  /*
+  for(i = 0; i < 33; i++)
+  {
+     adcm3800_write(0x1400+i*2, value[i]);
+  }
+  */
+  
+  for(i = 0; i < 33; i++)
+  {
+     ret = adcm3800_write(EREG_TM_COEF_00_V+i*2, value[i]);
+  }
+
+  return 0;
+}
+
+/***************** Image Styles ************************/
+/* No special effect */
+static const u16 agilent_adcm3800_normal_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01ED, 0x01DB, 0x0038,
+ 0x004F, 0x01BE, 0x01F3,
+ 0x0000};
+
+/* Antique effect */
+static const u16 agilent_adcm3800_antique_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01F8, 0x01F8, 0x01F8,
+ 0x0008, 0x0008, 0x0008, 
+ 0x0000};
+
+/* Black and White effect */
+static const u16 agilent_adcm3800_black_and_white_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000,
+ 0x0000};
+
+/* Color Negative effect */
+static const u16 agilent_adcm3800_color_negative_effect[] =
+{0x01da, 0x01bf, 0x01f1,
+ 0x0013, 0x0025, 0x01c8,
+ 0x01b1, 0x0042, 0x000d,
+ 0x00ff};
+
+#if 0
+/* saturation 50% effect */
+static const u16 agilent_adcm3800_saturation_50_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01e4, 0x01c9, 0x0054,
+ 0x0076, 0x019d, 0x01ed,
+ 0x0000};
+
+/* saturation 100% effect */
+static const u16 agilent_adcm3800_saturation_100_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01da, 0x01b6, 0x0070,
+ 0x009d, 0x017c, 0x01e6,
+ 0x0000};
+
+/* Reddish effect */
+static const u16 agilent_adcm3800_red_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01e4, 0x01db, 0x0038,
+ 0x0076, 0x01be, 0x01f3,
+ 0x0000};
+
+/* Greenish effect */
+static const u16 agilent_adcm3800_green_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01ed, 0x01c9, 0x0038,
+ 0x004f, 0x019d, 0x01F3,
+ 0x0000};
+
+/* Bluish effect */
+static const u16 agilent_adcm3800_blue_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01ed, 0x01db, 0x0054,
+ 0x004f, 0x01be, 0x01ed,
+ 0x0000};
+
+/* Cyan effect */
+static const u16 agilent_adcm3800_cyan_effect[] =
+{0x0026, 0x004B, 0x000F,
+ 0x01f7, 0x01db, 0x0038,
+ 0x0027, 0x01be, 0x01f3,
+ 0x0000};
+#endif
+
+/* End additional matrices */
+/*******************************************************/
+
+
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+static int adcm3800_register_style(V4l_PIC_STYLE style)
+{
+    u16 * reg_value;
+    u16 reg_count = 10;
+    reg_value = (u16 *)agilent_adcm3800_normal_effect;
+    switch(style)
+    {
+        case V4l_STYLE_BLACK_WHITE:
+            reg_value = (u16 *)agilent_adcm3800_black_and_white_effect;
+            break;
+        case V4l_STYLE_SEPIA:
+            reg_value = (u16 *)agilent_adcm3800_antique_effect;
+            break;
+        case V4l_STYLE_SOLARIZE:
+            break;
+        case V4l_STYLE_NEG_ART:
+            reg_value = (u16 *)agilent_adcm3800_color_negative_effect;
+            break;
+        default:
+            break;
+    }
+
+    int i;
+    for(i = 0; i < reg_count; i++)
+    {
+        adcm3800_write(EREG_CSC_00_V+i*2, reg_value[i]);
+    }
+    return 0;
+}
+
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+int adcm3800_set_style(V4l_PIC_STYLE style)
+{
+    if( style!=adcm3800_context.style )
+    {
+        adcm3800_context.style = style;
+        adcm3800_context.SCL_restart = 1;
+        return 1;
+    }
+    return 0;
+}
+
+/******* Agilent Color Matrices ***************************/
+
+/*
+White Balance gains are located in registers 0x1064 (Red Gain) and 0x1066 (Blue Gains)
+
+Color Correction Coeffecients are located in registers 0x1028-0x1038
+
+* To force write White Balance coeffecients, make sure AWB is off (bit 1 in 0x140)
+
+* To force write Color Correction coeffiecients, make sure NACC is off (bit 3 in 0x140)
+
+
+The following are the register writes for various iluminants:
+
+*************************************************
+Illuminant D50
+*************************************************
+w 1064 12B
+w 1066 143
+w 1028 23E EDF FE3 F3E 2A8 F1A FBC E23 321
+------------------------ 
+*************************************************
+Illuminant D55
+*************************************************
+w 1064 134
+w 1066 13B
+w 1028 233 EF7 FD7 F3F 29B F26 FC1 E40 2FF
+------------------------ 
+*************************************************
+Illuminant D65
+*************************************************
+w 1064 141
+w 1066 12D
+w 1028 223 F17 FC6 F41 289 F36 FC6 E6A 2D0
+------------------------ 
+*************************************************
+Illuminant D75
+*************************************************
+w 1064 14B
+w 1066 123
+w 1028 21A F2C FBA F42 27D F40 FC7 E86 2B3
+------------------------ 
+*************************************************
+Illuminant D90
+*************************************************
+w 1064 155
+w 1066 118
+w 1028 212 F40 FAF F44 272 F4A FC7 EA2 298
+------------------------ 
+*************************************************
+Illuminant FluorTriphosphor_4000K
+*************************************************
+w 1064 111
+w 1066 16A
+w 1028 251 E44 06B F63 281 F1B FB7 E12 338
+------------------------ 
+*************************************************
+Illuminant Fluor_PhilipsUltraLume
+*************************************************
+w 1064 F3
+w 1066 190
+w 1028 212 DCA 125 F81 23D F42 F8E D81 3F1
+------------------------ 
+*************************************************
+Illuminant blackbody2600	
+*************************************************
+w 1064 E4
+w 1066 176
+w 1028 240 DDC 0E4 F49 2BC EFC F44 D57 465
+------------------------ 
+*************************************************
+Illuminant blackbody3200
+*************************************************
+w 1064 FA
+w 1066 166
+w 1028 217 E74 075 F50 27D F33 F8C DEA 38A
+------------------------ 
+*************************************************
+Illuminant blackbody3500
+*************************************************
+w 1064 104
+w 1066 15E
+w 1028 20A EA2 055 F53 26C F41 F9E E19 349
+------------------------ 
+*************************************************
+Illuminant blackbody3800
+*************************************************
+w 1064 10E
+w 1066 157
+w 1028 1FF EC5 03D F55 25F F4C FAB E3D 318
+------------------------ 
+*************************************************
+Illuminant blackbody4200
+*************************************************
+w 1064 118
+w 1066 14E
+w 1028 1F4 EE7 025 F57 252 F56 FB7 E63 2E7
+------------------------ 
+*************************************************
+Illuminant blackbody4600
+*************************************************
+w 1064 121
+w 1066 146
+w 1028 1EB F02 013 F59 249 F5E FBE E80 2C2
+------------------------ 
+*************************************************
+Illuminant boothCool_4070K
+*************************************************
+w 1064 126
+w 1066 16C
+w 1028 201 ED8 027 F6D 274 F1F FAE E0F 343
+------------------------ 
+*************************************************
+Illuminant boothHorizon
+*************************************************
+w 1064 D5
+w 1066 17D
+w 1028 264 D43 159 F47 313 EA6 EF5 CD9 531
+------------------------ 
+*************************************************
+Illuminant boothInca
+*************************************************
+w 1064 ED
+w 1066 170
+w 1028 22C E29 0AB F4C 29A F1A F69 DA0 3F7
+------------------------ 
+*************************************************
+Illuminant fluorescent_3335K
+*************************************************
+w 1064 109
+w 1066 186
+w 1028 1DB E6A 0BB F83 229 F54 FA2 DE4 37A
+------------------------ 
+*************************************************
+Illuminant halogen_2250K
+*************************************************
+w 1064 D5
+w 1066 184
+w 1028 213 D7F 16E F5C 2C2 EE2 F01 D43 4BC
+------------------------ 
+*/
+
+/* Sunlight 
+*************************************************
+Illuminant D65
+*************************************************
+w 1064 141
+w 1066 12D
+w 1028 223 F17 FC6 F41 289 F36 FC6 E6A 2D0
+*/
+static const u16 agilent_adcm3800_sunny_color_gain[] =
+{0x0141, 0x012D};
+static const u16 agilent_adcm3800_sunny_color[] =
+{0x0223, 0x0F17, 0x0FC6,
+ 0x0F41, 0x0289, 0x0F36,
+ 0x0FC6, 0x0E6A, 0x02D0};
+
+/* Cloudy 
+*************************************************
+Illuminant D75
+*************************************************
+w 1064 14B
+w 1066 123
+w 1028 21A F2C FBA F42 27D F40 FC7 E86 2B3
+*/
+static const u16 agilent_adcm3800_cloudy_color_gain[] =
+{0x014B, 0x0123};
+static const u16 agilent_adcm3800_cloudy_color[] =
+{0x021A, 0x0F2C, 0x0FBA, 
+ 0x0F42, 0x027D, 0x0F40, 
+ 0x0FC7, 0x0E86, 0x02B3};
+
+
+/* Indoor - home tungsten
+*************************************************
+Illuminant blackbody3200
+*************************************************
+w 1064 FA
+w 1066 166
+w 1028 217 E74 075 F50 27D F33 F8C DEA 38A
+*/
+static const u16 agilent_adcm3800_home_tungsten_color_gain[] =
+{0x0FA, 0x0166};
+static const u16 agilent_adcm3800_home_tungsten_color[] =
+{0x0217, 0x0E74, 0x0075, 
+ 0x0F50, 0x027D, 0x0F33, 
+ 0x0F8C, 0x0DEA, 0x038A};
+
+
+/* Indoor - office cool white fluorescent 
+*************************************************
+Illuminant fluorescent_3335K
+*************************************************
+w 1064 109
+w 1066 186
+w 1028 1DB E6A 0BB F83 229 F54 FA2 DE4 37A
+ * */
+static const u16 agilent_adcm3800_office_fluorescent_color_gain[] =
+{0x0109, 0x0186};
+static const u16 agilent_adcm3800_office_fluorescent_color[] =
+{0x01DB, 0x0E6A, 0x00BB, 
+ 0x0F83, 0x0229, 0x0F54, 
+ 0x0FA2, 0x0DE4, 0x037A};
+
+/* Night tungsten
+static const u16 agilent_adcm3800_night_tungsten_color[] =
+{0x034f, 0x0cdd, 0x00d3, 
+ 0x0f47, 0x033c, 0x0e73, 
+ 0x0f31, 0x0b2a, 0x06a3};
+*/
+
+/* Automatic (generic default setting) 5500K sun-light
+*************************************************
+Illuminant D55
+*************************************************
+w 1064 134
+w 1066 13B
+w 1028 233 EF7 FD7 F3F 29B F26 FC1 E40 2FF
+*/
+static const u16 agilent_adcm3800_automatic_color_gain[] =
+{0x0134, 0x013B};
+static const u16 agilent_adcm3800_automatic_color[] =
+{0x0233, 0x0EF7, 0x0FD7,
+ 0x0F3F, 0x029B, 0x0F26,
+ 0x0FC1, 0x0E40, 0x02FF};
+/*******************************************************/
+
+
+static int adcm3800_register_light(V4l_PIC_WB light)
+{
+    int i;
+    int awb = 0;
+    u16* color_cc;
+    u16* color_gain;
+    switch(light)
+    {
+      case V4l_WB_DIRECT_SUN:
+        awb = 0;
+        color_cc = (u16 *)agilent_adcm3800_sunny_color;
+        color_gain = (u16 *)agilent_adcm3800_sunny_color_gain;
+        break;       
+      case V4l_WB_INCANDESCENT:
+        awb = 0;
+        color_cc = (u16 *)agilent_adcm3800_home_tungsten_color;
+        color_gain = (u16 *)agilent_adcm3800_home_tungsten_color_gain;
+        break;       
+      case V4l_WB_FLUORESCENT:
+        awb = 1;
+        color_cc = (u16 *)agilent_adcm3800_office_fluorescent_color;
+        color_gain = (u16 *)agilent_adcm3800_office_fluorescent_color_gain;
+        break;       
+      default:
+        awb = 1;
+        color_cc = (u16 *)agilent_adcm3800_automatic_color;
+        color_gain = (u16 *)agilent_adcm3800_automatic_color_gain;
+        break;
+    }
+
+    u16 value_r140;
+    adcm3800_read(EREG_AF_CTRL1, &value_r140);
+    // disable AWB NACC
+    adcm3800_write(EREG_AF_CTRL1, value_r140&(~0x02)&(~0x08));
+
+    for(i = 0; i< 9; i++)
+    {
+        adcm3800_write(EREG_CC_COEF_00+i*2, color_cc[i]);
+    }
+#if 1
+    for(i = 0; i< 9; i++)
+    {
+        u16 value;
+        adcm3800_read(0x0270+i*2, &value);
+        adcm3800_write(0x0270+i*2, (value&0xf000)|color_cc[i]);
+    }
+#endif
+
+    for(i = 0; i< 2; i++)
+    {
+        adcm3800_write(0x1064+i*2, color_gain[i]);
+    }
+
+    // tighter awb tolerances ???
+    // w 17c 108 110
+    //adcm3800_write(EREG_AWB_TOL_ACQ, 0x0108);
+    //adcm3800_write(EREG_AWB_TOL_MON, 0x0110);
+
+    if(awb) {
+        adcm3800_write(EREG_AF_CTRL1, value_r140|0x02);   // enable AWB
+    }
+    else {
+        adcm3800_write(EREG_AF_CTRL1, value_r140&(~0x02));   // disable AWB
+    }
+    return 0;
+}
+        
+int adcm3800_set_light(V4l_PIC_WB light)
+{
+    if( light!=adcm3800_context.light )
+    {
+        adcm3800_context.light = light;
+        adcm3800_context.SCL_restart = 1;
+        return 1;
+    }
+    return 0;
+}
+
+/*set exposure compensation */
+static int adcm3800_register_exp_comp(int bright)
+{
+    const u16 exp_adj[] = 
+    { 
+        0x0108,      // -2.0 EV
+        0x0106,      // -1.5 EV
+        0x0104,      // -1.0 EV
+        0x0102,      // -0.5 EV
+        0x0000,      //  0.0 EV
+        0x0002,      // +0.5 EV
+        0x0004,      // +1.0 EV
+        0x0006,      // +1.5 EV
+        0x0008       // +2.0 EV
+    };
+
+    if(bright < -4 || bright > 4)
+    {
+        return -EINVAL;
+    }
+
+    int value = exp_adj[bright+4];
+    value |= 0x0200;    // set center zone exposure
+    adcm3800_write(SREG_EXP_ADJ, value);
+    return 0;
+}
+
+/*set picture brightness*/
+static int adcm3800_register_bright(int bright)
+{
+    const u16 target[] = 
+    { 
+        16,  //0x0010,      // -2.0 EV
+        23,  //0x0017,      // -1.5 EV
+        32,  //0x0020,      // -1.0 EV
+        45,  //0x002d,      // -0.5 EV
+        64,  //0x0040,      //  0.0 EV
+        90,  //0x005a,      // +0.5 EV
+        128, //0x0080,      // +1.0 EV
+        181, //0x00b5,      // +1.5 EV
+        240  //0x00f0       // +2.0 EV
+    };
+
+    if(bright < -4 || bright > 4)
+    {
+        return -EINVAL;
+    }
+    adcm3800_write(EREG_AE_TARGET, target[bright+4]);
+    return 0;
+}
+
+/*set picture brightness*/
+int adcm3800_set_bright(int bright)
+{
+    adcm3800_context.bright = bright;
+    adcm3800_register_bright(bright);
+    return 0;
+}
+
+static int adcm3800_register_exposure_mode(V4l_NM mode, int maxexpotime)
+{
+    adcm3800_write(EREG_AE_ETIME_MAX, maxexpotime/10);
+    return 0;
+}
+
+/*set exposure mode: normal/night */
+int adcm3800_set_exposure_mode(V4l_NM mode, int maxexpotime)
+{
+    if(maxexpotime<10 && maxexpotime>500000) // 500ms > time > 10us
+        return -EINVAL;
+
+    if(adcm3800_context.max_expotime != maxexpotime)
+    {
+        adcm3800_context.max_expotime = maxexpotime;
+        adcm3800_context.SCL_restart = 1;
+        return 1;
+    }
+    return 0;
+}
+
+int adcm3800_set_flicker(int flicker)
+{
+    adcm3800_context.flicker_freq = flicker;
+    u16 old;
+    u16 old1;
+    adcm3800_read(EREG_AF_CTRL2, &old);
+    adcm3800_read(SREG_ILLUM, &old1);
+    old1 &= ~(0x18);
+    dbg_print("set flicker to %d", flicker);
+    if(flicker == 50)
+    {
+        adcm3800_write(SREG_ILLUM, old1|0x08);
+        adcm3800_write(EREG_AF_CTRL2, old&(~0x02));
+        //1000 = 100000/50/2
+        adcm3800_write(EREG_AE_ETIME_DFLT, 1000);
+    }
+    else if(flicker == 60)
+    {
+        adcm3800_write(SREG_ILLUM, old1|0x10);
+        adcm3800_write(EREG_AF_CTRL2, old|0x02);
+        // 833 = 100000/60/2 
+        adcm3800_write(EREG_AE_ETIME_DFLT, 833);  
+    }
+    else
+    {
+        return -EINVAL;
+    }
+    return 0;
+}
+
+// SCL restart
+static int adcm3800_SCL_restart(p_camera_context_t cam_ctx, int frames)
+{
+    int ret;
+
+    /*stop camera*/
+    adcm3800_write(SREG_CONTROL, 0);
+
+    //update simple registers
+    adcm3800_register_fps(&adcm3800_context);
+
+    adcm3800_register_output_format(adcm3800_context.format);
+
+    adcm3800_write(SREG_SIZE, 0x0f0f);  // perfer image quality, disallow subsampling
+    //sensor width and sensor height
+    adcm3800_register_sensor_size(adcm3800_context.sensor_w, adcm3800_context.sensor_h);
+    //output width and output height
+    adcm3800_register_output_size(adcm3800_context.output_w, adcm3800_context.output_h);
+
+    if(adcm3800_context.style == V4l_STYLE_SOLARIZE ) {
+        adcm3800_register_gamma_solarize();
+    }
+    else if(frames == 1) {
+        adcm3800_register_gamma(0);  // gamma sRGB, still mode
+    }
+    else {
+        adcm3800_register_gamma(5);  // gamma 2.0, video mode
+    }
+
+    //adcm3800_print_status();
+
+    // SCL
+    ret = wait_sreg_update();
+    if(ret<0)
+        return ret;
+
+    //adcm3800_print_status();
+
+    // set AE_GAIN to improve pink at center issue
+    // w 150 240 280 500 280
+#if 1
+    adcm3800_write(EREG_AE_GAIN_MIN,    0x0240);
+    adcm3800_write(EREG_AE_GAIN_MIN_P,  0x0280);
+    adcm3800_write(EREG_AE_GAIN_MAX,    0x0500);
+    adcm3800_write(EREG_AE_GAIN_DFLT,   0x0280);
+#endif
+
+    adcm3800_register_style(adcm3800_context.style);
+
+    // re-initialize auto functions
+    u16 v_ctrl2;
+    adcm3800_read(EREG_AF_CTRL2, &v_ctrl2);
+    adcm3800_write(EREG_AF_CTRL2, v_ctrl2|0x0040);
+
+    //adcm3800_print_status();
+
+    // set max exposure time
+    adcm3800_register_exposure_mode(adcm3800_context.expo_mode,
+                                    adcm3800_context.max_expotime);
+
+    // set brightness
+    adcm3800_register_bright(adcm3800_context.bright);
+
+    // set white balance
+    adcm3800_register_light(adcm3800_context.light);
+
+    // start video mode
+    adcm3800_write(SREG_CONTROL, 0x01);
+
+    //adcm3800_print_status();
+
+    adcm3800_write(EREG_AF_CTRL2, v_ctrl2);
+
+    return 0;
+}
+
+// SCL partial
+int adcm3800_SCL_partial(p_camera_context_t cam_ctx, int frames)
+{
+    //update simple registers
+    adcm3800_register_fps(&adcm3800_context);
+
+    adcm3800_write(SREG_SIZE, 0x0f0f);  // perfer image quality, disallow subsampling
+    //sensor width and sensor height
+    adcm3800_register_sensor_size(adcm3800_context.sensor_w, adcm3800_context.sensor_h);
+
+    //output width and output height
+    adcm3800_register_output_size(adcm3800_context.output_w, adcm3800_context.output_h);
+
+    if(adcm3800_context.style == V4l_STYLE_SOLARIZE ) {
+        adcm3800_register_gamma_solarize();
+    }
+    else if(frames == 1) {
+        adcm3800_register_gamma(0);  // gamma sRGB, still mode
+    }
+    else {
+        adcm3800_register_gamma(5);  // gamma 2.0, video mode
+    }
+
+    // partial simple control
+    // still mode
+
+    //adcm3800_print_status();
+
+    // partial config
+    adcm3800_write(SREG_CONTROL, 0x21);
+
+    //adcm3800_print_status();
+
+    return 0;
+}
+
+int adcm3800_reconfigure(p_camera_context_t cam_ctx, int frames)
+{
+    dbg_print("sensor width %d", cam_ctx->sensor_width);
+    dbg_print("sensor height %d", cam_ctx->sensor_height);
+    dbg_print("capture_width %d", cam_ctx->capture_width);
+    dbg_print("capture_height %d", cam_ctx->capture_height);
+    ddbg_print("fps %d", cam_ctx->fps);
+    ddbg_print("light %d", cam_ctx->capture_light);
+    ddbg_print("capture_bright %d", cam_ctx->capture_bright);
+    ddbg_print("capture_style %d", cam_ctx->capture_style);
+
+    int ret = 0;
+    if(adcm3800_context.SCL_restart != 0)
+    {
+        ret = adcm3800_SCL_restart(cam_ctx, frames);
+        adcm3800_context.SCL_restart = 0;
+    }
+    else if(adcm3800_context.SCL_partial != 0)
+    {
+        ret = adcm3800_SCL_partial(cam_ctx, frames);
+        adcm3800_context.SCL_partial = 0;
+    }
+
+    return ret;
+}
+
+//
+// This is an example of how to implement a firmware patch table.
+// The patch data contained here is the ADCM-3800 patch version 3.
+//
+// The first array is the starting register address of each contiguous block
+// of data to write.  The second array is the number of words to write for
+// each block.  These arrays are terminated with a zero entry.  Some other
+// method could also be used to know how many patch blocks there are,
+// such as using the sizeof() operator, or a separate defined constant.
+//
+// The third array contains the patch data to be written, formatted according
+// to the length of each block.  The length of the third array should equal
+// the sum of the entries in the second array.
+//
+
+// patch code ver.7, 10/20/2004
+static unsigned short patch3800addr[] = {
+    0x0186, 0x484c, 0x488c, 0x4838, 0x4818, 0x4898,
+    0x4980, 0x002c, 0x0034, 0x4820, 0x486C,
+	0x4860, 0x4804, 0x4854, 0x487C, 0x4894, 0x482C, 0x4834, 0x4800,
+	0x4868, 0x4C80, 0x0062, 0x006A, 0x0186,
+    0};
+static unsigned short patch3800len [] = {
+    3,      2,      2,      2,      2,      2,
+    352,    4,      4,      2,	    2,
+	2,	    2,      2,      2,      2,      2,      2,      2,
+	2,	    1104,   4,      2,      2,
+    0};
+static unsigned short patch3800data[] =
+{
+    // #Load patch 
+    // 0x0186, 3
+    0x0000, 0x0000, 0x0000,
+    // 484C, 2
+    0x0002, 0x0012,
+    // 488C, 2
+    0x0002, 0x437e,
+    // 4838, 2
+    0x0002, 0x4385,
+    // 4818, 2
+    0x0002, 0x0564,
+    // 4898, 2
+    0x0002, 0x43a0,
+
+    // #PI patch 
+    // 0x4980, 352
+    0x0000, 0x00C0, 0x0000, 0x00EA, 0x0000, 0x0212, 0x0000, 0xFF40,
+	0x0000, 0xFFAF, 0x0000, 0xFF44, 0x0000, 0x0272, 0x0000, 0xFF4A,
+	0x0000, 0xFFC7, 0x0000, 0xFEA2, 0x0000, 0x0298, 0x0000, 0x00C6,
+	0x0000, 0x00E1, 0x0000, 0x021A, 0x0000, 0xFF2C, 0x0000, 0xFFBA,
+	0x0000, 0xFF42, 0x0000, 0x027D, 0x0000, 0xFF40, 0x0000, 0xFFC7,
+	0x0000, 0xFE86, 0x0000, 0x02B3, 0x0000, 0x00CC, 0x0000, 0x00DA,
+	0x0000, 0x0223, 0x0000, 0xFF17, 0x0000, 0xFFC6, 0x0000, 0xFF41,
+	0x0000, 0x0289, 0x0000, 0xFF36, 0x0000, 0xFFC6, 0x0000, 0xFE6A,
+	0x0000, 0x02D0, 0x0000, 0x00D5, 0x0000, 0x00D0, 0x0000, 0x0233,
+	0x0000, 0xFEF7, 0x0000, 0xFFD7, 0x0000, 0xFF3F, 0x0000, 0x029B,
+	0x0000, 0xFF26, 0x0000, 0xFFC1, 0x0000, 0xFE40, 0x0000, 0x02FF,
+	0x0000, 0x00DB, 0x0000, 0x00CB, 0x0000, 0x023E, 0x0000, 0xFEDF,
+	0x0000, 0xFFE3, 0x0000, 0xFF3E, 0x0000, 0x02A8, 0x0000, 0xFF1A,
+	0x0000, 0xFFBC, 0x0000, 0xFE23, 0x0000, 0x0321, 0x0000, 0x00E3,
+	0x0000, 0x00C9, 0x0000, 0x01EB, 0x0000, 0xFF02, 0x0000, 0x0013,
+	0x0000, 0xFF59, 0x0000, 0x0249, 0x0000, 0xFF5E, 0x0000, 0xFFBE,
+	0x0000, 0xFE80, 0x0000, 0x02C2, 0x0000, 0x00EA, 0x0000, 0x00C4,
+	0x0000, 0x01F4, 0x0000, 0xFEE7, 0x0000, 0x0025, 0x0000, 0xFF57,
+	0x0000, 0x0252, 0x0000, 0xFF56, 0x0000, 0xFFB7, 0x0000, 0xFE63,
+	0x0000, 0x02E7, 0x0000, 0x00F3, 0x0000, 0x00BF, 0x0000, 0x01FF,
+	0x0000, 0xFEC5, 0x0000, 0x003D, 0x0000, 0xFF55, 0x0000, 0x025F,
+	0x0000, 0xFF4C, 0x0000, 0xFFAB, 0x0000, 0xFE3D, 0x0000, 0x0318,
+	0x0000, 0x00DF, 0x0000, 0x00B4, 0x0000, 0x0201, 0x0000, 0xFED8,
+	0x0000, 0x0027, 0x0000, 0xFF6D, 0x0000, 0x0274, 0x0000, 0xFF1F,
+	0x0000, 0xFFAE, 0x0000, 0xFE0F, 0x0000, 0x0343, 0x0000, 0x00FC,
+	0x0000, 0x00BB, 0x0000, 0x020A, 0x0000, 0xFEA2, 0x0000, 0x0055,
+	0x0000, 0xFF53, 0x0000, 0x026C, 0x0000, 0xFF41, 0x0000, 0xFF9E,
+	0x0000, 0xFE19, 0x0000, 0x0349, 0x0000, 0x0106, 0x0000, 0x00B7,
+	0x0000, 0x0217, 0x0000, 0xFE74, 0x0000, 0x0075, 0x0000, 0xFF50,
+	0x0000, 0x027D, 0x0000, 0xFF33, 0x0000, 0xFF8C, 0x0000, 0xFDEA,
+	0x0000, 0x038A, 0x0000, 0x00F7, 0x0000, 0x00A8, 0x0000, 0x01DB,
+	0x0000, 0xFE6A, 0x0000, 0x00BB, 0x0000, 0xFF83, 0x0000, 0x0229,
+	0x0000, 0xFF54, 0x0000, 0xFFA2, 0x0000, 0xFDE4, 0x0000, 0x037A,
+	0x0000, 0x0114, 0x0000, 0x00B2, 0x0000, 0x022C, 0x0000, 0xFE29,
+	0x0000, 0x00AB, 0x0000, 0xFF4C, 0x0000, 0x029A, 0x0000, 0xFF1A,
+	0x0000, 0xFF69, 0x0000, 0xFDA0, 0x0000, 0x03F7, 0x0000, 0x010E,
+	0x0000, 0x00A4, 0x0000, 0x0212, 0x0000, 0xFDCA, 0x0000, 0x0125,
+	0x0000, 0xFF81, 0x0000, 0x023D, 0x0000, 0xFF42, 0x0000, 0xFF8E,
+	0x0000, 0xFD81, 0x0000, 0x03F1, 0x0000, 0x0120, 0x0000, 0x00AF,
+	0x0000, 0x0240, 0x0000, 0xFDDC, 0x0000, 0x00E4, 0x0000, 0xFF49,
+	0x0000, 0x02BC, 0x0000, 0xFEFC, 0x0000, 0xFF44, 0x0000, 0xFD57,
+	0x0000, 0x0465, 0x0000, 0x0134, 0x0000, 0x00AC, 0x0000, 0x0264,
+	0x0000, 0xFD43, 0x0000, 0x0159, 0x0000, 0xFF47, 0x0000, 0x0313,
+	0x0000, 0xFEA6, 0x0000, 0xFEF5, 0x0000, 0xFCD9, 0x0000, 0x0531,
+    // 002c, 4
+	0x0080, 0x001A, 0x0034, 0x1388,
+    // 0034, 4
+	0x03E8, 0x0000, 0x07D0, 0x0001,
+	// 4820, 2, 
+    0x0002, 0x4320,
+	// 486C, 2
+    0x0002, 0x432F,
+	// 4860, 2
+    0x0002, 0x44C0,
+	// 4804, 2
+    0x0002, 0x44DF,
+	// 4854, 2
+    0x0002, 0x1D8B,
+	// 487C, 2
+    0x0002, 0x4510,
+	// 4894, 2
+    0x0002, 0x4516,
+	// 482C, 2
+    0x0002, 0x451E,
+	// 4834, 2
+    0x0002, 0x4522,
+	// 4800, 2
+    0x0002, 0x4536,
+	// 4868, 2
+    0x0002, 0x4538,
+	// 4C80, 1104
+    0x0003, 0x1DB3, 0x0000, 0x0632, 0x0009, 0x0006, 0x0000, 0x661F,
+	0x0009, 0x0004, 0x0000, 0x6620, 0x0009, 0x0118, 0x0000, 0x6725,
+	0x0009, 0x014e, 0x0000, 0x6726, 0x0009, 0x0118, 0x0000, 0x6532,
+	0x0009, 0x014e, 0x0000, 0x6533, 0x0000, 0x01FF, 0x0000, 0x0958,
+	0x0000, 0x0960, 0x0000, 0x0968, 0x0000, 0x0970, 0x0000, 0x0978,
+	0x0000, 0x4F23, 0x0000, 0x4722, 0x0000, 0x024B, 0x0000, 0x01A3,
+	0x0000, 0x091E, 0x000B, 0xFE26, 0x0009, 0x8480, 0x0000, 0x08CB,
+	0x000B, 0xFE27, 0x0009, 0x001E, 0x0000, 0x08CB, 0x0009, 0xFE26,
+    // 4D00
+	0x0000, 0x6621, 0x0000, 0x7A22, 0x0009, 0xFE26, 0x0000, 0x6623,
+	0x0003, 0x449B, 0x000B, 0xFE27, 0x0000, 0x085B, 0x000A, 0x0000,
+	0x0000, 0x0153, 0x0006, 0x434B, 0x0002, 0x434E, 0x000B, 0xFE26,
+	0x0009, 0xFFFF, 0x0000, 0x08CB, 0x0009, 0x0010, 0x0000, 0x662A,
+	0x000B, 0xFE26, 0x0000, 0x0873, 0x0000, 0x5620, 0x000B, 0x0000,
+	0x0000, 0x4A19, 0x0000, 0x0156, 0x0007, 0x435B, 0x000A, 0x0001,
+	0x0000, 0x0155, 0x0004, 0x435B, 0x0002, 0x4363, 0x0000, 0x5219,
+	0x0000, 0x042C, 0x0000, 0x4A19, 0x0000, 0x0054, 0x0000, 0x0166,
+	0x0007, 0x4362, 0x0002, 0x4363, 0x0002, 0x4364, 0x0000, 0x0183,
+	0x0000, 0x031B, 0x0005, 0x436A, 0x0009, 0x0205, 0x0000, 0x662A,
+	0x000D, 0x0001, 0x0002, 0x43AE, 0x000B, 0x0000, 0x0000, 0x4A1A,
+	0x0000, 0x0156, 0x0007, 0x4372, 0x000A, 0x0002, 0x0000, 0x0155,
+	0x0004, 0x4372, 0x0002, 0x437A, 0x0000, 0x521A, 0x0000, 0x042C,
+	0x0000, 0x4A1A, 0x0000, 0x0054, 0x0000, 0x0166, 0x0007, 0x4379,
+	0x0002, 0x437A, 0x0002, 0x437B, 0x0000, 0x0183, 0x0000, 0x031B,
+	0x0005, 0x4381, 0x0009, 0x0003, 0x0000, 0x662A, 0x000D, 0x0002,
+    // 4E00
+	0x0002, 0x43AE, 0x000B, 0x0000, 0x0000, 0x4A1B, 0x0000, 0x0156,
+	0x0007, 0x4389, 0x000A, 0x0003, 0x0000, 0x0155, 0x0004, 0x4389,
+	0x0002, 0x4391, 0x0000, 0x521B, 0x0000, 0x042C, 0x0000, 0x4A1B,
+	0x0000, 0x0054, 0x0000, 0x0166, 0x0007, 0x4390, 0x0002, 0x4391,
+	0x0002, 0x4392, 0x0000, 0x0183, 0x0000, 0x031B, 0x0005, 0x4396,
+	0x000D, 0x0003, 0x0002, 0x43AE, 0x000B, 0x0000, 0x0000, 0x4A1C,
+	0x0000, 0x0156, 0x0007, 0x439E, 0x000A, 0x0004, 0x0000, 0x0155,
+	0x0004, 0x439E, 0x0002, 0x43A6, 0x0000, 0x521C, 0x0000, 0x042C,
+	0x0000, 0x4A1C, 0x0000, 0x0054, 0x0000, 0x0166, 0x0007, 0x43A5,
+	0x0002, 0x43A6, 0x0002, 0x43A7, 0x0000, 0x0183, 0x0000, 0x031B,
+	0x0005, 0x43AD, 0x000D, 0x0004, 0x0009, 0x0010, 0x0000, 0x662A,
+	0x0002, 0x43AE, 0x000D, 0x0005, 0x0000, 0x7620, 0x0000, 0x4F4D,
+	0x0000, 0x474C, 0x0000, 0x028B, 0x0000, 0x4725, 0x0000, 0x028B,
+	0x0000, 0x091F, 0x0000, 0x4F4E, 0x0000, 0x474C, 0x0000, 0x028B,
+	0x0000, 0x4726, 0x0000, 0x028B, 0x0000, 0x6E25, 0x0000, 0x462A,
+	0x0000, 0x0439, 0x0000, 0x6629, 0x0000, 0x4629, 0x000A, 0x000B,
+    // 4F00
+    0x0000, 0x0251, 0x0000, 0x01D3, 0x000A, 0x4260, 0x0000, 0x005A,
+	0x0000, 0x6A2B, 0x0000, 0x4E2B, 0x0000, 0x0853, 0x0000, 0x6A21,
+	0x0000, 0x7E22, 0x0000, 0x4E2B, 0x0000, 0x0183, 0x0000, 0x0853,
+	0x0000, 0x6A23, 0x0000, 0x4625, 0x0000, 0x6624, 0x0003, 0x4485,
+	0x0000, 0x6628, 0x0000, 0x5629, 0x0000, 0x0185, 0x0000, 0x4E2A,
+	0x0000, 0x2CFF, 0x0000, 0x015D, 0x0007, 0x43D8, 0x0002, 0x43F0,
+	0x0000, 0x462B, 0x000A, 0x000B, 0x0000, 0x0051, 0x0000, 0x662B,
+	0x0000, 0x4E2B, 0x0000, 0x0853, 0x0000, 0x6A21, 0x0000, 0x7E22,
+	0x0000, 0x4E2B, 0x0000, 0x0183, 0x0000, 0x0853, 0x0000, 0x6A23,
+	0x0000, 0x4625, 0x0000, 0x6624, 0x0003, 0x4485, 0x0000, 0x090E,
+	0x0000, 0x4A28, 0x0000, 0x0156, 0x0007, 0x43EC, 0x0002, 0x43EE,
+	0x0000, 0x7A28, 0x0000, 0x7629, 0x0000, 0x0185, 0x0002, 0x43D3,
+	0x0000, 0x461F, 0x000A, 0x000B, 0x0000, 0x0251, 0x0000, 0x01D3,
+	0x000A, 0x4260, 0x0000, 0x005A, 0x0000, 0x6A2B, 0x0000, 0x4E2B,
+	0x0000, 0x0853, 0x0000, 0x6A21, 0x0000, 0x7E22, 0x0000, 0x4E2B,
+	0x0000, 0x0183, 0x0000, 0x0853, 0x0000, 0x6A23, 0x0000, 0x4625,
+	// 5000
+    0x0000, 0x6624, 0x0003, 0x4485, 0x0000, 0x090E, 0x0000, 0x4629,
+	0x0000, 0x4A1F, 0x0000, 0x0151, 0x0004, 0x4409, 0x0000, 0x0602,
+	0x0002, 0x4416, 0x0000, 0x4A28, 0x0000, 0x02B2, 0x0000, 0x0913,
+	0x0000, 0x4A16, 0x0000, 0x0153, 0x0006, 0x4410, 0x0002, 0x4415,
+	0x0000, 0x461F, 0x0000, 0x6629, 0x0000, 0x7A28, 0x0000, 0x0602,
+	0x0002, 0x4416, 0x0000, 0x0622, 0x0000, 0x0652, 0x0005, 0x4422,
+	0x0000, 0x4628, 0x0000, 0x4A17, 0x0000, 0x0151, 0x0007, 0x441D,
+	0x0002, 0x4421, 0x0000, 0x0612, 0x0009, 0x0000, 0x0000, 0x661E,
+	0x0000, 0x0622, 0x0002, 0x442B, 0x0000, 0x4628, 0x0000, 0x4A18,
+	0x0000, 0x0151, 0x0006, 0x4427, 0x0002, 0x442B, 0x0000, 0x0632,
+	0x0009, 0x0001, 0x0000, 0x661E, 0x0000, 0x0622, 0x000B, 0x0000,
+	0x0000, 0x4629, 0x000A, 0x0005, 0x0000, 0x0151, 0x0007, 0x4435,
+	0x0000, 0x4620, 0x000A, 0x0002, 0x0000, 0x0151, 0x0006, 0x4435,
+	0x0000, 0x0183, 0x0000, 0x031B, 0x0005, 0x443B, 0x0000, 0x0632,
+	0x0000, 0x0622, 0x0009, 0x0002, 0x0000, 0x6629, 0x0000, 0x0642,
+	0x0005, 0x447B, 0x0000, 0x0605, 0x0000, 0x0606, 0x0000, 0x4629,
+	// 5100
+    0x000A, 0x000B, 0x0000, 0x0251, 0x0000, 0x01D3, 0x000A, 0x4260,
+	0x0000, 0x0053, 0x000A, 0x000A, 0x0000, 0x0053, 0x0000, 0x6E2B,
+	0x0000, 0x8EA0, 0x0005, 0x444D, 0x0009, 0xFF40, 0x0000, 0x662C,
+	0x0002, 0x444F, 0x0009, 0xFD1C, 0x0000, 0x662C, 0x000D, 0x0001,
+	0x000A, 0x000A, 0x0000, 0x0155, 0x0007, 0x4454, 0x0002, 0x4460,
+	0x0000, 0x4E2C, 0x0000, 0x0193, 0x0000, 0x6E2C, 0x0000, 0x0183,
+	0x0000, 0x522B, 0x0000, 0x0194, 0x0000, 0x722B, 0x0000, 0x0184,
+	0x0000, 0x0864, 0x0000, 0x08E3, 0x0000, 0x0185, 0x0002, 0x4450,
+	0x0000, 0x0652, 0x0005, 0x4472, 0x0000, 0x4E2B, 0x0000, 0x0193,
+	0x0000, 0x6E2B, 0x0000, 0x0183, 0x0000, 0x085B, 0x000A, 0x0100,
+	0x0000, 0x029A, 0x0000, 0x0913, 0x0000, 0x6F26, 0x0000, 0x4E2B,
+	0x0000, 0x085B, 0x000A, 0x0100, 0x0000, 0x029A, 0x0000, 0x0913,
+	0x0000, 0x6F25, 0x0002, 0x447A, 0x000A, 0x0100, 0x0000, 0x02BA,
+	0x0000, 0x0913, 0x0000, 0x6F25, 0x000B, 0x0100, 0x0000, 0x4625,
+	0x0000, 0x028B, 0x0000, 0x6F26, 0x0002, 0x447D, 0x0000, 0x0625,
+	0x0000, 0x0626, 0x0000, 0x4629, 0x0000, 0x661F, 0x0000, 0x0838,
+    // 5200
+    0x0000, 0x0830, 0x0000, 0x0828, 0x0000, 0x0820, 0x0000, 0x0818,
+	0x0000, 0x01FF, 0x0000, 0x0958, 0x0000, 0x4621, 0x0000, 0x4A22,
+	0x0003, 0x4493, 0x0000, 0x090B, 0x0000, 0x4623, 0x0000, 0x4A24,
+	0x0003, 0x4493, 0x0000, 0x0059, 0x0000, 0x01FB, 0x0005, 0x4491,
+	0x0009, 0xFFFF, 0x0000, 0x0818, 0x0000, 0x01FF, 0x0000, 0x008A,
+	0x0000, 0x0212, 0x0000, 0x01D1, 0x0000, 0x01C2, 0x0000, 0x0352,
+	0x0005, 0x449A, 0x0009, 0xFFFF, 0x0000, 0x01FF, 0x0000, 0x0958,
+	0x0000, 0x0960, 0x0000, 0x0978, 0x0000, 0x4A21, 0x0000, 0x080A,
+	0x0000, 0x0852, 0x0000, 0x4E22, 0x000C, 0x0000, 0x000F, 0x0020,
+	0x0000, 0x060A, 0x0000, 0x0404, 0x0000, 0x01FB, 0x0005, 0x44A9,
+	0x0000, 0x062A, 0x0000, 0x05AF, 0x0005, 0x44AC, 0x0000, 0x0540,
+	0x0000, 0x0402, 0x0000, 0x059F, 0x0005, 0x44B0, 0x0000, 0x0520,
+	0x0000, 0x0401, 0x0000, 0x064A, 0x0004, 0x44B5, 0x0000, 0x015C,
+	0x0007, 0x44B7, 0x0000, 0x00DC, 0x0000, 0x0510, 0x0000, 0x0197,
+	0x0004, 0x44A4, 0x0000, 0x4E23, 0x0000, 0x088B, 0x0000, 0x08D3,
+	0x0000, 0x0838, 0x0000, 0x0820, 0x0000, 0x0818, 0x0000, 0x01FF,
+	// 5300
+    0x0000, 0x060D, 0x0000, 0x513F, 0x000F, 0x0008, 0x0000, 0x00FC,
+	0x0000, 0x5540, 0x0000, 0x00FD, 0x0000, 0x026C, 0x0000, 0x01A7,
+	0x0000, 0x52A5, 0x0000, 0x0414, 0x0000, 0x0267, 0x0000, 0x01A7,
+	0x0000, 0x7E50, 0x000F, 0x0000, 0x0000, 0x7E51, 0x0000, 0x7E53,
+	0x0000, 0x7E55, 0x000B, 0x0000, 0x0002, 0x44D4, 0x0000, 0x0183,
+	0x0000, 0x5EA6, 0x0000, 0x017B, 0x0006, 0x21A8, 0x000F, 0x4230,
+	0x0000, 0x001F, 0x0000, 0x0877, 0x0000, 0x5253, 0x0000, 0x0074,
+	0x0000, 0x7254, 0x000F, 0xFE31, 0x0002, 0x218D, 0x0000, 0x5E01,
+	0x0000, 0x05F5, 0x0005, 0x004C, 0x0000, 0x04F5, 0x0000, 0x7E01,
+	0x0003, 0x0213, 0x0000, 0x46AF, 0x0000, 0x0948, 0x0000, 0x4722,
+	0x0000, 0x0948, 0x0000, 0x4723, 0x0000, 0x0948, 0x0000, 0x060A,
+	0x0003, 0x05DC, 0x0000, 0x062A, 0x0003, 0x05DC, 0x0000, 0x060A,
+	0x0003, 0x06EC, 0x0000, 0x675E, 0x0000, 0x062A, 0x0003, 0x06EC,
+	0x0000, 0x675F, 0x0009, 0x44FA, 0x0000, 0x0948, 0x0009, 0xFFFB,
+	0x0000, 0x0048, 0x0002, 0x0564, 0x0000, 0x0808, 0x0000, 0x6723,
+	0x0000, 0x0808, 0x0000, 0x6722, 0x0000, 0x0808, 0x0000, 0x66AF,
+	// 5400
+    0x0003, 0x02BC, 0x0000, 0x7E67, 0x0000, 0x7A68, 0x0000, 0x7269,
+	0x0003, 0x1C3B, 0x0000, 0x7E8A, 0x0003, 0x1C55, 0x0000, 0x7E8B,
+	0x0000, 0x5EA4, 0x0000, 0x7D07, 0x0000, 0x5F23, 0x0003, 0x1CD1,
+	0x0003, 0x01AF, 0x0003, 0x1B8A, 0x0003, 0x1B90, 0x0002, 0x004C,
+	0x0000, 0x0640, 0x0004, 0x4514, 0x0000, 0x0641, 0x0005, 0x4515,
+	0x0000, 0x0634, 0x0002, 0x225D, 0x0000, 0x0654, 0x0005, 0x451A,
+	0x0000, 0x8EA2, 0x0004, 0x451C, 0x0000, 0x060D, 0x0000, 0x01FF,
+	0x0000, 0x0614, 0x0002, 0x2163, 0x0003, 0x021E, 0x0000, 0x5E98,
+	0x0000, 0x7D04, 0x0000, 0x01FF, 0x0000, 0x466E, 0x0000, 0x240F,
+	0x000A, 0x0001, 0x0000, 0x014A, 0x0004, 0x010A, 0x0000, 0x4601,
+	0x0000, 0x0591, 0x0004, 0x4531, 0x0000, 0x0590, 0x0004, 0x012C,
+	0x0003, 0x0213, 0x0000, 0x4602, 0x0000, 0x0490, 0x0000, 0x6602,
+	0x0002, 0x0017, 0x0000, 0xBAA1, 0x0004, 0x4535, 0x0000, 0x8EA2,
+	0x0005, 0x012C, 0x0002, 0x0082, 0x0008, 0x4570, 0x0002, 0x001E,
+	0x0000, 0x4723, 0x0000, 0x4AAD, 0x0000, 0x0151, 0x0007, 0x1E8F,
+	0x0006, 0x4545, 0x0000, 0x4722, 0x0000, 0x4AAA, 0x0000, 0x0151,
+	// 5500
+    0x0007, 0x1E8F, 0x0009, 0x0100, 0x0000, 0x010C, 0x0007, 0x1E8F,
+	0x0000, 0x01FF, 0x0000, 0x6B23, 0x0000, 0x0620, 0x0000, 0x01FF,
+	// 0062, 4
+    0x0200, 0x0600, 0x0C00, 0x1800,
+	// 006A, 2
+    0x2800, 0x3800,
+	// 0186, 2
+    0x2903, 0x8D20
+};
+
+
+static int adcm3800Patch(void)
+{
+    int err;
+    int ipatch, idata;
+    for (ipatch = 0, idata = 0; patch3800addr[ipatch] != 0; ipatch++)
+    {
+        int addr = patch3800addr[ipatch];
+        int len = patch3800len[ipatch];
+        ddbg_print("write %d length to addr %x", len, addr);
+        err = adcm3800_write_regs (addr, &patch3800data[idata], len);
+        if (err < 0) 
+        {
+            dbg_print("error: fail to upgrade patch code");
+            return (err);
+        }
+        idata += len;
+    }
+    dbg_print("ok: write %d patch code", idata);
+    if(idata*2 != sizeof(patch3800data))
+    {
+        dbg_print("error: patch len wrong! %d:%d", idata, sizeof(patch3800data)/2);
+        return -1;
+    }
+    return 0;
+}
+
+
+static int adcm3800_firmware_upgrade(void)
+{
+    u8  valueb;
+    u16 valuew;
+
+    //adcm3800_write(0x3040, 0x0100);
+
+    int to = 200;
+    while(to>0)
+    {
+        adcm3800_read(0x0004, &valuew);
+        if(valuew==0x0000)
+            break;
+        mdelay(5);
+        to -= 1;
+    }
+
+    dbg_print("start patch");
+    adcm3800Patch();
+    dbg_print("end patch");
+    adcm3800_read_byte(0x084b, &valueb);
+
+    return 0;
+}
+    
+static int adcm3800_init_regs(void)
+{
+    u16 valuew;
+/*
+#Setting pixel ram and sensor registers
+#set block 14
+w  0a04 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0005 0005 0805 0005 0007 0007 0007 0007 0107 0107 0187 0187 0187 0183 0183 0183
+
+#set block 15
+w  0a80 0183 0183 0183 0183 0183 0183 0183 0183
+w  0a90 0181 0001 0000 0000 0000 0000 0008 0008
+w  0aa0 0008 0008 0079 0079 0079 0079 0079 0079
+w  0ab0 0079 0079 0079 0079 0079 0079 0079 0079
+
+#set block 16
+w  0b00 0079 0079 0079 0079 0079 0071 0035 0035
+w  0b10 0035 0035 0037 0837 0037 0037 0137 0137
+w  0b20 01b7 01b7 01b3 01b3 01b3 01b3 01b3 01b3
+w  0b30 01b3 01b3 01b3 01b3 01b3 01b3 01b1 0071
+
+#set block 17
+w  0b80 0071 0071 0071 0071 0071 0071 0061 0021 0020 0000 0000 0000 0000 0000
+*/
+    static u16 reg_0a04[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0005, 0x0005, 0x0805, 0x0005, 0x0007, 0x0007, 0x0007, 0x0007, 0x0107, 0x0107, 0x0187, 0x0187, 0x0187, 0x0183, 0x0183, 0x0183};
+    adcm3800_write_regs (0x0a04, reg_0a04, 30);
+
+    static u16 reg_0a80[] = {
+        0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183,
+        0x0181, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008,
+        0x0008, 0x0008, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
+        0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079};
+    adcm3800_write_regs (0x0a80, reg_0a80, 32);
+
+    static u16 reg_0b00[] = {
+        0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0071, 0x0035, 0x0035,
+        0x0035, 0x0035, 0x0037, 0x0837, 0x0037, 0x0037, 0x0137, 0x0137,
+        0x01b7, 0x01b7, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3,
+        0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b1, 0x0071};
+    adcm3800_write_regs (0x0b00, reg_0b00, 32);
+
+    static u16 reg_0b80[] = {
+        0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0061, 0x0021, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
+    adcm3800_write_regs (0x0b80, reg_0b80, 14);
+
+/*
+# Sensor settings
+w8 081e 00
+w8 081f 00
+w8 0820 00
+w8 0821 00
+w8 0822 00
+w8 0823 00
+w8 0824 00
+w8 0825 00
+w8 0828 02
+w8 0845 b0
+w8 0848 06
+w8 0849 03
+w8 084d 20
+*/
+    adcm3800_write_byte(0x081e, 0x00);
+    adcm3800_write_byte(0x081f, 0x00);
+    adcm3800_write_byte(0x0820, 0x00);
+    adcm3800_write_byte(0x0821, 0x00);
+    adcm3800_write_byte(0x0822, 0x00);
+    adcm3800_write_byte(0x0823, 0x00);
+    adcm3800_write_byte(0x0824, 0x00);
+    adcm3800_write_byte(0x0825, 0x00);
+    adcm3800_write_byte(0x0828, 0x02);
+    adcm3800_write_byte(0x0845, 0xb0);
+    adcm3800_write_byte(0x0848, 0x06);
+    adcm3800_write_byte(0x0849, 0x03);
+    adcm3800_write_byte(0x084D, 0x20);
+/*
+# Purple sky fix
+w8 84f F8
+*/
+    adcm3800_write_byte(0x084f, 0xF8);
+
+/*
+#r  0112 1	# Return:8280
+w  0112 c680	# PROC_CTRL_V
+#r  0132 1	# Return:0280
+w  0132 4680	# PROC_CTRL_S
+w  014a 0015	# Auto Black Level Target
+#r  0008 1	# Return:0b84
+// delete w  0008 0b04	# Image Size and Orientation, still: SXGA, Video: QQVGA
+*/
+    // turn on AV
+    // sharpness
+    //adcm3800_write(0x0112, 0x4e80);   // high sharpness
+    //adcm3800_write(0x0132, 0x4e80);
+    adcm3800_write(0x0112, 0x4a80);   // medium sharpness
+    adcm3800_write(0x0132, 0x4a80);
+    //adcm3800_write(0x0112, 0x4680);   // low sharpness
+    //adcm3800_write(0x0132, 0x4680);
+    //adcm3800_write(0x0112, 0x4280);     // no sharpness
+    //adcm3800_write(0x0132, 0x4280);
+    adcm3800_write(0x014a, 0x0015);
+
+/*
+# AWB setting
+w  0174 010d	# AWB Default Red/Green Ratio
+w  017a 0185	# AWB Default Blue/Green Ratio
+w  017c 0108	# AWB Tolerance Acquire
+w  017e 0110	# AWB Tolerance Monitor
+*/
+    // AWB
+    adcm3800_write(0x0174, 0x010d);
+    adcm3800_write(0x017a, 0x0185);
+    adcm3800_write(0x017c, 0x0108);
+    adcm3800_write(0x017e, 0x0110);
+
+    // 0x00e0, 6
+    static u16 reg_00e0[] = {
+        0x003c, 0x00c8, 0x0200, 0x0130, 0x0180, 0x003c
+    };
+    adcm3800_write_regs (0x00e0, reg_00e0, 6);
+
+/*
+#set block 00, AWB setting
+w  0028 028f 0333 a3d7 001a 0021 c350 0bb8 01f4 0064 0001 0001
+#set block 00
+w  0062 0200 0600 0c00 1800 2800 3800
+*/
+#if 0
+    static u16 reg_0028[] = {
+        0x028f, 0x0333, 0xa3d7, 0x001a, 0x0021, 0xc350, 0x0bb8, 0x01f4, 0x0064, 0x0001, 0x0001};
+    adcm3800_write_regs (0x0028, reg_0028, 11);
+    static u16 reg_0062[] = {
+        0x0200, 0x0600, 0x0c00, 0x1800, 0x2800, 0x3800};
+    adcm3800_write_regs (0x0062, reg_0062, 6);
+#endif
+
+/*
+# 70% Vignetting Correction (7/27/04 - BB)
+w 10a6 248 1d0 248 1d0 260 160 0f6 0f6 0f2
+
+w 1800 0F1 102 111 120 12F 13F 14B 157 165 171 17E 18A 197 1A3 1AB 1B4 1BB 1C3 1C6 1CB 1CA 1C6 1C2 1BB 1B4 1AE 1A9 1A3 19E 198 193 18D
+w 1840 0E0 0EF 0FC 108 113 11F 12A 136 141 14D 158 161 16D 176 17E 186 18D 191 196 198 198 197 195 191 18A 183 17A 170 165 159 14C 13F
+w 1880 0F8 106 110 11A 124 12D 136 140 14B 154 15D 167 16F 178 180 188 18F 196 19C 1A0 1A4 1A6 1A8 1A7 1A6 1A4 1A0 19C 195 18E 186 17C
+*/
+    static u16 reg_10a6[] = {
+        0x0248, 0x01d0, 0x0248, 0x01d0, 0x0260, 0x0160, 0x00f6, 0x00f6, 0x00f2
+    };
+    adcm3800_write_regs (0x10a6, reg_10a6, 9);
+    // Red vignetting data
+    static u16 reg_1800[] = {
+        0x00F1, 0x0102, 0x0111, 0x0120, 0x012F, 0x013F, 0x014B, 0x0157,
+        0x0165, 0x0171, 0x017E, 0x018A, 0x0197, 0x01A3, 0x01AB, 0x01B4,
+        0x01BB, 0x01C3, 0x01C6, 0x01CB, 0x01CA, 0x01C6, 0x01C2, 0x01BB,
+        0x01B4, 0x01AE, 0x01A9, 0x01A3, 0x019E, 0x0198, 0x0193, 0x018D
+    };
+    adcm3800_write_regs (0x1800, reg_1800, 32);
+    // Green vignetting data
+    static u16 reg_1840[] = {
+        0x00E0, 0x00EF, 0x00FC, 0x0108, 0x0113, 0x011F, 0x012A, 0x0136,
+        0x0141, 0x014D, 0x0158, 0x0161, 0x016D, 0x0176, 0x017E, 0x0186,
+        0x018D, 0x0191, 0x0196, 0x0198, 0x0198, 0x0197, 0x0195, 0x0191,
+        0x018A, 0x0183, 0x017A, 0x0170, 0x0165, 0x0159, 0x014C, 0x013F
+    };
+    adcm3800_write_regs (0x1840, reg_1840, 32);
+    // Blue vignetting data
+    static u16 reg_1880[] = {
+        0x00F8, 0x0106, 0x0110, 0x011A, 0x0124, 0x012D, 0x0136, 0x0140,
+        0x014B, 0x0154, 0x015D, 0x0167, 0x016F, 0x0178, 0x0180, 0x0188,
+        0x018F, 0x0196, 0x019C, 0x01A0, 0x01A4, 0x01A6, 0x01A8, 0x01A7,
+        0x01A6, 0x01A4, 0x01A0, 0x019C, 0x0195, 0x018E, 0x0186, 0x017C
+    };
+    adcm3800_write_regs (0x1880, reg_1880, 32);
+
+    // BPA
+    // BPA 5 Line Threshold, default to 0x0020 
+    adcm3800_write(0x1094, 0x0010);
+
+/*
+#G1/G2 Threshold
+w 101a 23f
+*/
+    adcm3800_write(0x101a, 0x023f);
+/*
+#NACC Settings - Dark Table
+w 282 2B3 FE0B 41 FF69 2B1 FEE4 FF6D FC69 528
+*/
+    static u16 reg_0282[] = {
+        0x2B3, 0xFE0B, 0x41, 0xFF69, 0x2B1, 0xFEE4, 0xFF6D, 0xFC69, 0x528
+    };
+    adcm3800_write_regs (0x0282, reg_0282, 9);
+/*
+#NACC Settings - NACC Table
+w 250 96 0 0 100
+*/
+    static u16 reg_0250[] = {
+        0x0096, 0x0000, 0x0000, 0x0100, 0x0ea6, 0x0060, 0x09c4, 0x0080,
+        0x04e2, 0x00a0, 0x0271, 0x00c0, 0x0000, 0x0100
+    };
+    adcm3800_write_regs (0x0250, reg_0250, 14);
+/*
+#PI control
+w 2e A4 EC
+*/
+    adcm3800_write(0x002e, 0x00A4);
+    adcm3800_write(0x0030, 0x00EC);
+
+/*
+#Sunlight oscillation
+#Set bit 4 of 0x142
+# auto function control, select Xenon flash mode and enabled auto exposure deliberate overexposure
+w 142 1011
+
+#Turn NACC on
+w 140 1B
+*/
+    //adcm3800_write(0x0142, 0x1011);
+    adcm3800_write(EREG_AF_CTRL2, 0x1011);
+    //adcm3800_write(0x0140, 0x001B);
+    adcm3800_write(EREG_AF_CTRL1, 0x001b);   // enable AE AWB NACC ABL
+
+    dbg_print("end");
+    return 0;
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/adcm3800_hw.h linux-2.6.16.5-exz/drivers/media/video/adcm3800_hw.h
--- linux-2.6.16.5/drivers/media/video/adcm3800_hw.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/adcm3800_hw.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,534 @@
+/*================================================================================
+                                                                               
+                      Header Name: adcm3800_hw.h
+
+General Description: Camera module adcm3800 interface header file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)     12/15/2003      LIBdd35749   Created   
+wangfei(w20239)     02/05/2004      LIBdd74309   Set frame rate in video mode
+wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
+wangfei(w20239)     03/08/2004      LIBdd84578   Photo effects setting
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _PXA_ADCM3800_HW_H__
+#define _PXA_ADCM3800_HW_H__
+
+#include "camera.h"
+
+/***********************************************************************
+ * 
+ * Constants
+ *
+ ***********************************************************************/
+ 
+// Revision constants
+#define PIPE_REV            0x68
+//#define PIPE_REV_NEW        0x68
+#define SENSOR_REV          0x68
+
+// Others
+#define adcm3800__TIMEOUT   400               // times to timeout.
+
+// Non JEPG Output Format
+#define O_FORMAT_888RGB         0   //0b0000    // 888 RGB (1 pixel in 3 bytes )
+#define O_FORMAT_666_A_RGB      1   //0b0001    // 666 A RGB (tight pack, 4 pixels in 9 bytes)
+#define O_FORMAT_666_B_RGB      2   //0b0010    // 666 B RGB (loose pack, 1 pixel in 3 bytes,left or right justified)
+#define O_FORMAT_565_RGB        3   //0b0011    // 565 RGB (1 pixel in 2 bytes)
+#define O_FORMAT_444_A_RGB      4   //0b0100    // 444 A RGB (tight pack, 2 pixels per 3 bytes, RG BR GB)
+#define O_FORMAT_444_B_RGB      5   //0b0101    // 444 B RGB (loose pack, 1 pixel per 2 bytes,RG B0 or 0R GB)
+#define O_FORMAT_444_C_RGV      6   //0b0110    // 444 C RGB (sparse pack, 1 pixel per three bytes,R0 G0 B0 or 0R 0G 0B)
+#define O_FORMAT_332_RGB        7   //0b0111    // 332 RGB (1 pixel in 1 byte)
+#define O_FORMAT_422_A_YCbYCr   8   //0b1000    // 4:2:2 A YCbYCr (Y1 Cb12 Y2 CRL2 order)
+#define O_FORMAT_422_B_YCbYCr   9   //0b1001    // 4:2:2 B YCbYCr (Cb12 Y1 CRL2 Y2 order)
+#define O_FORMAT_422_C_YCbYCr   10  //0b1010    // 4:2:2 C YCbYCr (Y1 CRL2 Y2 Cb12 order)
+#define O_FORMAT_422_D_YCbYCr   11  //0b1011    // 4:2:2 D YCbYCr (CRL2 Y1 Cb12 Y2 order)
+#define O_FORMAT_444_YCbYCr     12  //0b1100    // 4:4:4 YCbCr (1 pixels per 3 bytes)
+#define O_FORMAT_400_B_YCbYCr   13  //0b1101    // 4:0:0 YCbCr (Greyscale, 1 pixel per 1 byte)
+#define O_FORMAT_RAWBPA         14  //0b1110    // RAWBPA (with AWB and BPA)
+#define O_FORMAT_RAW            15  //0b1111    // RAW (without AWB and BPA)
+
+#define O_FORMAT_NONE        65535  //
+
+/*************************************************************************************
+ *
+ * Simple Control Registers Address
+ *
+ *************************************************************************************/
+//      name                addr    description                        default   page
+#define SREG_ID             0x0000  //Chip ID                           0x0060   139
+#define SREG_CONTROL        0x0002  //Camera control                    0x0001   140
+#define SREG_STATUS         0x0004  //Camera status                     0x0004   142
+#define SREG_CLK_FREQ       0x0006  //Input clock frequency             0x32c8   144
+#define SREG_SIZE           0x0008  //Image size and orientation        0x0605   145
+#define SREG_OUTPUT_FORMAT  0x000a  //Output format                     0x0909   147
+#define SREG_EXPOSURE       0x000c  //Exposure                          0x03e8   149
+#define SREG_EXP_ADJ        0x000e  //Exposure adjustment               0x0000   150
+#define SREG_ILLUM          0x0010  //Illumination                      0x0000   151
+#define SREG_FRAME_RATE     0x0012  //Requested frame rate              0x0096   152
+#define SREG_A_FRAME_RATE   0x0016  //Actual frame rate                 0x0096   154
+#define SREG_SENSOR_WID_V   0x0018  //Sensor window width, video mode   0x0000   155
+#define SREG_SENSOR_HGT_V   0x001a  //Sensor window height, video mode  0x0000   156
+#define SREG_OUTPUT_WID_V   0x001c  //Output window width, video mode   0x0000   157
+#define SREG_OUTPUT_HGT_V   0x001e  //Output window height, video mode  0x0000   158
+#define SREG_SENSOR_WID_S   0x0020  //Sensor window width, still mode   0x0000   159
+#define SREG_SENSOR_HGT_S   0x0022  //Sensor window height, still mode  0x0000   160
+#define SREG_OUTPUT_WID_S   0x0024  //Output window width, still mode   0x0000   161
+#define SREG_OUTPUT_HGT_S   0x0026  //Output window height, still mode  0x0000   162
+
+/*************************************************************************************
+ *
+ * Expert Hardware Registers
+ *
+ *************************************************************************************/
+//      name                addr       description                        default   page
+#define  EREG_I_CLK_DIV      0x3000    //Initial clock divider              0x0001  166
+#define  EREG_CTL_CLK_DIV    0x3002    //Clock dividers for control 
+                                       //and serial interfaces              0x4000  167
+#define  EREG_SEN_CLK_DIV    0x3004    //Sensor clock dividers              0x0000  168
+#define  EREG_IP_CLK_DIV     0x3006    //Clock dividers for image pipeline  0x0000  169
+#define  EREG_TST_MODE       0x3008    //Latched test mode                  0x0000  170
+#define  EREG_SER_ADDR       0x300a    //Serial interface device address    0x0053  171
+#define  EREG_SER_PARM       0x300c    //Serial Interface parameters        0x0000  172
+#define  EREG_OUT_CTRL       0x300e    //Output control                     0x0000  173
+#define  EREG_PLL_CTRL       0x3010    //PLL control                        0x0014  470
+#define  EREG_PLL_DIV_L      0x3012    //PLL divisors, large values         0x500C  471
+#define  EREG_PLL_DIV_S      0x3014    //PLL divisors, small values         0x500C  472
+
+/*************************************************************************************
+ *
+ * Expert Control Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                             default  page
+#define  EREG_SZR_IN_WID_V    0x0100   //Sizer input width, video mode           0x0280  184
+#define  EREG_SZR_IN_HGT_V    0x0102   //Sizer input height, video mode          0x01e0  185
+#define  EREG_SZR_OUT_WID_V   0x0104   //Sizer output width, video mode          0x0140  186
+#define  EREG_SZR_OUT_HGT_V   0x0106   //Sizer output height, video mode         0x00f0  187
+#define  EREG_CPP_V           0x0108   //Clocks per pixel, video mode            0x0002  188
+#define  EREG_HBLANK_V        0x010a   //Horizontal blanking period, video mode  0x0000  189
+#define  EREG_VBLANK_V        0x010c   //Vertical blanking period, video mode    0x0000  190
+#define  EREG_MIN_MAX_F_V     0x010e   //Frame convergence rates, video mode     0x0000  191
+#define  EREG_OUTPUT_CTRL_V   0x0110   //Output control, video mode              0x9019  192
+#define  EREG_PROC_CTRL_V     0x0112   //Processing control, video mode          0x0280  194
+#define  EREG_RPT_V           0x0114   //Row processing time, video mode         0x0546  196
+#define  EREG_HYSNC_PER_V     0x0116   //HSYNC period, video mode                0x0a8b  197
+#define  EREG_CLK_DIV_V       0x0118   //Clock divisors, video mode              0x0000  198
+#define  EREG_PARALLEL_CTRL_V 0x011a   //Parallel output control, video mode     0x0003  199
+#define  EREG_SEN_CTRL_V      0x011c   //Sensor control, video mode              0x0000  200
+
+#define  EREG_SZR_IN_WID_S    0x0120   //Sizer input width, still mode           0x0280  202
+#define  EREG_SZR_IN_HGT_S    0x0122   //Sizer input height, still mode          0x01e0  203
+#define  EREG_SZR_OUT_WID_S   0x0124   //Sizer output width, still mode          0x0280  204
+#define  EREG_SZR_OUT_HGT_S   0x0126   //Sizer output height, still mode         0x01e0  205
+#define  EREG_CPP_S           0x0128   //Clocks per pixel, still mode            0x0002  206
+#define  EREG_HBLANK_S        0x012a   //Horizontal blanking period, still mode  0x0000  207
+#define  EREG_VBLANK_S        0x012c   //Vertical blanking period, still mode    0x0000  208
+#define  EREG_MIN_MAX_F_S     0x012e   //Frame convergence rates, still mode     0x0002  209
+#define  EREG_OUTPUT_CTRL_S   0x0130   //Output control, still mode              0x8019  210
+#define  EREG_PROC_CTRL_S     0x0132   //Processing control, still mode          0x0280  212
+#define  EREG_RPT_S           0x0134   //Row processing time, still mode         0x0546  214
+#define  EREG_HYSNC_PER_S     0x0136   //HSYNC period, still mode                0x0545  215
+#define  EREG_CLK_DIV_S       0x0138   //Clock divisors, still mode              0x0000  216
+#define  EREG_PARALLEL_CTRL_S 0x013a   //Parallel output control, still mode     0x0000  217
+#define  EREG_SEN_CTRL_S      0x013c   //Sensor control, still mode              0x0000  218
+
+#define  EREG_AF_CTRL1        0x0140   //Auto functions control 1                0x0013  220
+#define  EREG_AF_CTRL2        0x0142   //Auto functions control 2                0x0001  221
+#define  EREG_AF_STATUS       0x0144   //Auto functions status                   0x0000  222
+#define  EREG_SOF_CODES       0x0146   //Start of frame codes                    0xfeff  223
+#define  EREG_EOF_CODES       0x0148   //End of frame codes                      0x0100  224
+#define  EREG_ABL_TARGET      0x014a   //Auto black level target                 0x0005  225
+#define  EREG_ABL_MAX_BIN     0x014c   //Auto black level maximum bin            0x0003  226
+#define  EREG_ABL_MAX_BLACK   0x014e   //Auto black level maximum black          0x0010  227
+#define  EREG_AE_GAIN_MIN     0x0150   //Auto exposure gain minimum              0x01c0  228
+#define  EREG_AE_GAIN_MIN_P   0x0152   //Auto exposure gain minimum, preferred   0x0200  229
+#define  EREG_AE_GAIN_MAX     0x0154   //Auto exposure gain maximum              0x0500  230
+#define  EREG_AE_GAIN_DFLT    0x0156   //Auto exposure gain default              0x0200  231
+#define  EREG_AE_ETIME_MIN    0x0158   //Auto exposure time minimum              0x0005  232
+#define  EREG_AE_ETIME_MAX    0x015a   //Auto exposure time maximum              0x4e20  233
+#define  EREG_AE_ETIME_DFLT   0x015c   //Auto exposure time default              0x03e8  234
+#define  EREG_AE_TARGET       0x015e   //Auto exposure target                    0x0040  235
+#define  EREG_AE_TOL_ACQ      0x0160   //Auto exposure tolerance acquire         0x0118  236
+#define  EREG_AE_TOL_MON      0x0162   //Auto exposure tolerance monitor         0x0118  237
+#define  EREG_AE_MARGIN       0x0164   //Auto exposure margin                    0x0120  238
+#define  EREG_AE_DOE_FACTOR   0x0166   //AE deliberate overexposure factor       0x014e  239
+#define  EREG_AE_DOE_MARGIN   0x0168   //AE deliberate overexposure margin       0x0140  240
+
+#define  EREG_AWB_RED_MIN     0x0170   //AWB minimum red/green ratio             0x00c0  242
+#define  EREG_AWB_RED_MAX     0x0172   //AWB maximum red/green ratio             0x01a6  243
+#define  EREG_AWB_RED_DFLT    0x0174   //AWB default red/green ratio             0x0134  244
+#define  EREG_AWB_BLUE_MIN    0x0176   //AWB minimum blue/green ratio            0x00c0  245
+#define  EREG_AWB_BLUE_MAX    0x0178   //AWB maximum blue/green ratio            0x02a4  246
+#define  EREG_AWB_BLUE_DFLT   0x017a   //AWB default blue/green ratio            0x01e4  247
+#define  EREG_AWB_TOL_ACQ     0x017c   //Auto white balance tolerance acquire    0x0110  248
+#define  EREG_AWB_TOL_MON     0x017e   //Auto white balance tolerance monitor    0x0120  249
+#define  EREG_FIRMWARE_REV    0x0180   //Current firmware revision               0x0152  250
+#define  EREG_FLICK_CFG_1     0x0182   //Flicker configuration 1                 0x2aeb  251
+#define  EREG_FLICK_CFG_2     0x0184   //Flicker configuration 2                 0x0005  252
+
+#define  EREG_MAX_SCLK        0x018a   //Maximum sensor clock                    0x1964  254
+
+#define  EREG_CSC_00_V        0x0190   //Color conversion coefficient 00, video  0x0026  256
+#define  EREG_CSC_01_V        0x0192   //Color conversion coefficient 01, video  0x004b  256
+#define  EREG_CSC_02_V        0x0194   //Color conversion coefficient 02, video  0x000f  256
+#define  EREG_CSC_10_V        0x0196   //Color conversion coefficient 10, video  0x01ed  256
+#define  EREG_CSC_11_V        0x0198   //Color conversion coefficient 11, video  0x01db  256
+#define  EREG_CSC_12_V        0x019a   //Color conversion coefficient 12, video  0x0038  256
+#define  EREG_CSC_20_V        0x019c   //Color conversion coefficient 20, video  0x004f  256
+#define  EREG_CSC_21_V        0x019e   //Color conversion coefficient 21, video  0x01be  256
+#define  EREG_CSC_22_V        0x01a0   //Color conversion coefficient 22, video  0x01f3  256
+
+#define  EREG_CSC_OS0_V       0x01a2   //Color space conversion offset 0, video  0x0000  257
+#define  EREG_CSC_OS1_V       0x01a4   //Color space conversion offset 1, video  0x0080  257
+#define  EREG_CSC_OS2_V       0x01a6   //Color space conversion offset 2, video  0x0080  257
+
+#define  EREG_CSC_00_S        0x01a8   //Color conversion coefficient 00, still  0x0026  258
+#define  EREG_CSC_01_S        0x01aa   //Color conversion coefficient 01, still  0x004b  258
+#define  EREG_CSC_02_S        0x01ac   //Color conversion coefficient 02, still  0x000f  258
+#define  EREG_CSC_10_S        0x01ae   //Color conversion coefficient 10, still  0x01ed  258
+#define  EREG_CSC_11_S        0x01b0   //Color conversion coefficient 11, still  0x01db  258
+#define  EREG_CSC_12_S        0x01b2   //Color conversion coefficient 12, still  0x0038  258
+#define  EREG_CSC_20_S        0x01b4   //Color conversion coefficient 20, still  0x004f  258
+#define  EREG_CSC_21_S        0x01b6   //Color conversion coefficient 21, still  0x01be  258
+#define  EREG_CSC_22_S        0x01b8   //Color conversion coefficient 22, still  0x01f3  258
+                                                                                       
+#define  EREG_CSC_OS0_S       0x01ba   //Color space conversion offset 0, still  0x0000  259
+#define  EREG_CSC_OS1_S       0x01bc   //Color space conversion offset 1, still  0x0080  259
+#define  EREG_CSC_OS2_S       0x01be   //Color space conversion offset 2, still  0x0080  259
+
+
+#define  EREG_TM_COEF_00_V    0x01c0   //Tonemap coefficient 00, video           0x0000  261
+#define  EREG_TM_COEF_01_V    0x01c2   //Tonemap coefficient 01, video           0x0017  261
+#define  EREG_TM_COEF_02_V    0x01c4   //Tonemap coefficient 02, video           0x0032  261
+#define  EREG_TM_COEF_03_V    0x01c6   //Tonemap coefficient 03, video           0x0046  261
+#define  EREG_TM_COEF_04_V    0x01c8   //Tonemap coefficient 04, video           0x0056  261
+#define  EREG_TM_COEF_05_V    0x01ca   //Tonemap coefficient 05, video           0x0064  261
+#define  EREG_TM_COEF_06_V    0x01cc   //Tonemap coefficient 06, video           0x0071  261
+#define  EREG_TM_COEF_07_V    0x01ce   //Tonemap coefficient 07, video           0x007c  261
+#define  EREG_TM_COEF_08_V    0x01d0   //Tonemap coefficient 08, video           0x0086  261
+#define  EREG_TM_COEF_09_V    0x01d2   //Tonemap coefficient 09, video           0x0099  261
+#define  EREG_TM_COEF_10_V    0x01d4   //Tonemap coefficient 10, video           0x00a9  261
+#define  EREG_TM_COEF_11_V    0x01d6   //Tonemap coefficient 11, video           0x00b8  261
+#define  EREG_TM_COEF_12_V    0x01d8   //Tonemap coefficient 12, video           0x00c6  261
+#define  EREG_TM_COEF_13_V    0x01da   //Tonemap coefficient 13, video           0x00df  261
+#define  EREG_TM_COEF_14_V    0x01dc   //Tonemap coefficient 14, video           0x00f5  261
+#define  EREG_TM_COEF_15_V    0x01de   //Tonemap coefficient 15, video           0x0109  261
+#define  EREG_TM_COEF_16_V    0x01e0   //Tonemap coefficient 16, video           0x011b  261
+#define  EREG_TM_COEF_17_V    0x01e2   //Tonemap coefficient 17, video           0x013d  261
+#define  EREG_TM_COEF_18_V    0x01e4   //Tonemap coefficient 18, video           0x015a  261
+#define  EREG_TM_COEF_19_V    0x01e6   //Tonemap coefficient 19, video           0x0175  261
+#define  EREG_TM_COEF_20_V    0x01e8   //Tonemap coefficient 20, video           0x018d  261
+#define  EREG_TM_COEF_21_V    0x01ea   //Tonemap coefficient 21, video           0x01ba  261
+#define  EREG_TM_COEF_22_V    0x01ec   //Tonemap coefficient 22, video           0x01e1  261
+#define  EREG_TM_COEF_23_V    0x01ee   //Tonemap coefficient 23, video           0x0205  261
+#define  EREG_TM_COEF_24_V    0x01f0   //Tonemap coefficient 24, video           0x0225  261
+#define  EREG_TM_COEF_25_V    0x01f2   //Tonemap coefficient 25, video           0x0261  261
+#define  EREG_TM_COEF_26_V    0x01f4   //Tonemap coefficient 26, video           0x0295  261
+#define  EREG_TM_COEF_27_V    0x01f6   //Tonemap coefficient 27, video           0x02c5  261
+#define  EREG_TM_COEF_28_V    0x01f8   //Tonemap coefficient 28, video           0x02f1  261
+#define  EREG_TM_COEF_29_V    0x01fa   //Tonemap coefficient 29, video           0x033f  261
+#define  EREG_TM_COEF_30_V    0x01fc   //Tonemap coefficient 30, video           0x0385  261
+#define  EREG_TM_COEF_31_V    0x01fe   //Tonemap coefficient 31, video           0x03c5  261
+#define  EREG_TM_COEF_32_V    0x0200   //Tonemap coefficient 32, video           0x0400  261
+
+#define  EREG_TM_COEF_00_S    0x0202   //Tonemap coefficient 00, still           0x0000  262
+#define  EREG_TM_COEF_01_S    0x0204   //Tonemap coefficient 01, still           0x0017  262
+#define  EREG_TM_COEF_02_S    0x0206   //Tonemap coefficient 02, still           0x0032  262
+#define  EREG_TM_COEF_03_S    0x0208   //Tonemap coefficient 03, still           0x0046  262
+#define  EREG_TM_COEF_04_S    0x020a   //Tonemap coefficient 04, still           0x0056  262
+#define  EREG_TM_COEF_05_S    0x020c   //Tonemap coefficient 05, still           0x0064  262
+#define  EREG_TM_COEF_06_S    0x020e   //Tonemap coefficient 06, still           0x0071  262
+#define  EREG_TM_COEF_07_S    0x0210   //Tonemap coefficient 07, still           0x007c  262
+#define  EREG_TM_COEF_08_S    0x0212   //Tonemap coefficient 08, still           0x0086  262
+#define  EREG_TM_COEF_09_S    0x0214   //Tonemap coefficient 09, still           0x0099  262
+#define  EREG_TM_COEF_10_S    0x0216   //Tonemap coefficient 10, still           0x00a9  262
+#define  EREG_TM_COEF_11_S    0x0218   //Tonemap coefficient 11, still           0x00b8  262
+#define  EREG_TM_COEF_12_S    0x021a   //Tonemap coefficient 12, still           0x00c6  262
+#define  EREG_TM_COEF_13_S    0x021c   //Tonemap coefficient 13, still           0x00df  262
+#define  EREG_TM_COEF_14_S    0x021e   //Tonemap coefficient 14, still           0x00f5  262
+#define  EREG_TM_COEF_15_S    0x0220   //Tonemap coefficient 15, still           0x0109  262
+#define  EREG_TM_COEF_16_S    0x0222   //Tonemap coefficient 16, still           0x011b  262
+#define  EREG_TM_COEF_17_S    0x0224   //Tonemap coefficient 17, still           0x013d  262
+#define  EREG_TM_COEF_18_S    0x0226   //Tonemap coefficient 18, still           0x015a  262
+#define  EREG_TM_COEF_19_S    0x0228   //Tonemap coefficient 19, still           0x0175  262
+#define  EREG_TM_COEF_20_S    0x022a   //Tonemap coefficient 20, still           0x018d  262
+#define  EREG_TM_COEF_21_S    0x022c   //Tonemap coefficient 21, still           0x01ba  262
+#define  EREG_TM_COEF_22_S    0x022e   //Tonemap coefficient 22, still           0x01e1  262
+#define  EREG_TM_COEF_23_S    0x0230   //Tonemap coefficient 23, still           0x0205  262
+#define  EREG_TM_COEF_24_S    0x0232   //Tonemap coefficient 24, still           0x0225  262
+#define  EREG_TM_COEF_25_S    0x0234   //Tonemap coefficient 25, still           0x0261  262
+#define  EREG_TM_COEF_26_S    0x0236   //Tonemap coefficient 26, still           0x0295  262
+#define  EREG_TM_COEF_27_S    0x0238   //Tonemap coefficient 27, still           0x02c5  262
+#define  EREG_TM_COEF_28_S    0x023a   //Tonemap coefficient 28, still           0x02f1  262
+#define  EREG_TM_COEF_29_S    0x023c   //Tonemap coefficient 29, still           0x033f  262
+#define  EREG_TM_COEF_30_S    0x023e   //Tonemap coefficient 30, still           0x0385  262
+#define  EREG_TM_COEF_31_S    0x0240   //Tonemap coefficient 31, still           0x03c5  262
+#define  EREG_TM_COEF_32_S    0x0242   //Tonemap coefficient 32, still           0x0400  262
+
+#define  EREG_NACC_EGP_1      0x0250   //NACC EGP 1                              0x05dc  265
+#define  EREG_NACC_SAT_1      0x0252   //NACC saturation 1                       0x0000  265
+#define  EREG_NACC_EGP_2      0x0254   //NACC EGP 2                              0x0465  265
+#define  EREG_NACC_SAT_2      0x0256   //NACC saturation 2                       0x0040  265
+#define  EREG_NACC_EGP_3      0x0258   //NACC EGP 3                              0x02ee  265
+#define  EREG_NACC_SAT_3      0x025a   //NACC saturation 3                       0x0080  265
+#define  EREG_NACC_EGP_4      0x025c   //NACC EGP 4                              0x0177  265
+#define  EREG_NACC_SAT_4      0x025e   //NACC saturation 4                       0x00c0  265
+#define  EREG_NACC_EGP_5      0x0260   //NACC EGP 5                              0x0000  265
+#define  EREG_NACC_SAT_5      0x0262   //NACC saturation 5                       0x0100  265
+#define  EREG_NACC_EGP_6      0x0264   //NACC EGP 6                              0x0000  265
+#define  EREG_NACC_SAT_6      0x0266   //NACC saturation 6                       0x0000  265
+#define  EREG_NACC_EGP_7      0x0268   //NACC EGP 7                              0x0000  265
+#define  EREG_NACC_SAT_7      0x026a   //NACC saturation 7                       0x0000  265
+#define  EREG_NACC_EGP_8      0x026c   //NACC EGP 8                              0x0000  265
+#define  EREG_NACC_SAT_8      0x026e   //NACC saturation 8                       0x0000  265
+#define  EREG_NACC_BC_00      0x0270   //NACC NACC bright coefficients 00        0x0235  266
+#define  EREG_NACC_BC_01      0x0272   //NACC NACC bright coefficients 01        0xff46  266
+#define  EREG_NACC_BC_02      0x0274   //NACC bright coefficients 02             0xff85  266
+#define  EREG_NACC_BC_10      0x0276   //NACC bright coefficients 10             0xff64  266
+#define  EREG_NACC_BC_11      0x0278   //NACC bright coefficients 11             0x01fc  266
+#define  EREG_NACC_BC_12      0x027a   //NACC bright coefficients 12             0xff9f  266
+#define  EREG_NACC_BC_20      0x027c   //NACC bright coefficients 20             0x0008  266
+#define  EREG_NACC_BC_21      0x027e   //NACC bright coefficients 21             0xfe8d  266
+#define  EREG_NACC_BC_22      0x0280   //NACC bright coefficients 22             0x026b  266
+#define  EREG_NACC_DC_00      0x0282   //NACC dark coefficients 00               0x0048  266
+#define  EREG_NACC_DC_01      0x0284   //NACC dark coefficients 01               0x010b  266
+#define  EREG_NACC_DC_02      0x0286   //NACC dark coefficients 02               0xffaa  266
+#define  EREG_NACC_DC_10      0x0288   //NACC dark coefficients 10               0x0048  266
+#define  EREG_NACC_DC_11      0x028a   //NACC dark coefficients 11               0x010b  266
+#define  EREG_NACC_DC_12      0x028c   //NACC dark coefficients 12               0xffaa  266
+#define  EREG_NACC_DC_20      0x028e   //NACC dark coefficients 20               0x0048  266
+#define  EREG_NACC_DC_21      0x0290   //NACC dark coefficients 21               0x010b  266
+#define  EREG_NACC_DC_22      0x0292   //NACC dark coefficients 22               0xffaa  266
+                         
+/*************************************************************************************
+ *
+ * Expert Sensor Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                             default  page
+#define  EREG_IDENT          0x0800    //Image sensor identification             0x60     272
+#define  EREG_IS_STATUS      0x0801    //Image sensor status                     0x00     273
+#define  EREG_ICTRL          0x0805    //Interface control                       0x00     275
+
+#define  EREG_ADC_CTRL       0x0809    //ADC control                             0x01     277
+#define  EREG_FWROW          0x080a    //Window first row address                0x01     278
+#define  EREG_FWCOL          0x080b    //Window first column address             0x01     279
+#define  EREG_LWROW          0x080c    //Window last row address                 0x7a     280
+#define  EREG_LWCOL          0x080d    //Window last column address              0xa2     281
+#define  EREG_CLK_PIXEL      0x080e    //Clocks per pixel                        0x02     282
+#define  EREG_EREC_PGA       0x080f    //Even row, even column(green 1)PGA gain  0x00     283
+#define  EREG_EROC_PGA       0x0810    //Even row, odd column (red) PGA gain     0x00     284
+#define  EREG_OREC_PGA       0x0811    //Odd row, even column (blue) PGA gain    0x00     285
+#define  EREG_OROC_PGA       0x0812    //Odd row, odd column (green 2) PGA gain  0x00     286
+#define  EREG_ROWEXP_L       0x0813    //Row exposure low                        0x54     287
+#define  EREG_ROWEXP_H       0x0814    //Row exposure high                       0x00     288
+#define  EREG_SROWEXP        0x0815    //Sub row exposure                        0x31     289
+#define  EREG_ERROR          0x0816    //Error control                           0x00     290
+
+#define  EREG_HBLANK         0x0819    //Horizontal blank                        0x00     292
+#define  EREG_VBLANK         0x081a    //Vertical blank                          0x00     293
+#define  EREG_CONFIG_1       0x081b    //Image sensor configuration 1            0x0e     294
+#define  EREG_CONTROL_1      0x081c    //Image sensor control 1                  0x24     295
+
+#define  EREG_CONFIG_2       0x0827    //Image sensor configuration 2            0x00     298
+#define  EREG_GRR_CTRL       0x0828    //Ground reset reference control          0x00     299
+
+#define  EREG_BIAS_TRM       0x0837    //Bias trim                               0x00     301
+#define  EREG_SMP_GR_E2      0x08d7    //Sample ground reference edge 2          0x00     303
+#define  EREG_SMP_GR_E1      0x08d8    //Sample ground reference edge 1          0x10     304
+#define  EREG_SMP_GR_E0      0x08d9    //Sample ground reference edge 0          0x0a     305
+
+#define  EREG_EXP_GR_E1      0x08dc    //Exposure, ground reference edge 1       0x10     307
+#define  EREG_EXP_GR_E0      0x08dd    //Exposure, ground reference edge 0       0x06     308
+#define  EREG_GR_POL         0x08df    //Ground reference polarity               0xd3     310
+
+#define  EREG_SMP_RST_E2     0x08eb    //Sample, reset edge 2                    0x04     312
+#define  EREG_SMP_RST_E1     0x08ec    //Sample, reset edge 1                    0x10     313
+#define  EREG_SMP_RST_E0     0x08ed    //Sample, reset edge 0                    0x07     314
+
+#define  EREG_EXP_RST_E1     0x08f0    //Exposure, reset edge 1                  0x10     316
+#define  EREG_EXP_RST_E0     0x08f1    //Exposure, reset edge 1                  0x03     317
+#define  EREG_RESET_POL      0x08f3    //Reset polarity enable                   0xd3     319
+
+#define  EREG_SMP_PRST_E2    0x08f5    //Sample, preset edge 2                   0x00     321
+#define  EREG_SMP_PRST_E1    0x08f6    //Sample, preset edge 1                   0x02     322
+#define  EREG_SMP_PRST_E0    0x08f7    //Sample, preset edge 0                   0x0a     323
+
+#define  EREG_EXP_PRST_E1    0x08fa    //Exposure, preset edge 1                 0x02     325
+#define  EREG_EXP_PRST_E0    0x08fb    //Exposure, preset edge 1                 0x06     326
+#define  EREG_PRESET_POL     0x08fd    //Preset polarity enable                  0xd3     328
+
+/*************************************************************************************
+ *
+ * Expert Image Pipeline Registers
+ *
+ *************************************************************************************/
+//      name                  addr      description                               default  page
+                                    
+#define  EREG_CMD_1           0x1002    //Main command 1                           0x0000  335
+#define  EREG_CMD_2           0x1004    //Main command 2 (write 1¡¯s only)         0x0002  336
+#define  EREG_OUTPUT_CTRL     0x1008    //Output control, working                  0x9019  338
+#define  EREG_PARALLEL_CTRL   0x100a    //Parallel output control working copy     0x0000  340
+#define  EREG_SOF_CODE_W      0x100c    //Start of frame code working copy         0x00ff  341
+#define  EREG_PEOF_CODES      0x100e    //End of frame codes working copy          0x0100  342
+#define  EREG_CCIR_TIMING     0x1010    //CCIR interface timing                    0x0000  343
+#define  EREG_R_Y_MAX_MIN     0x1012    //Luminance, Y (or red) maximum/minimum    0xff00  344
+#define  EREG_G_CB_MAX_MIN    0x1014    //Chrominance,Cb(or green)maximum/minimum  0xff00  345
+#define  EREG_B_CR_MAX_MIN    0x1016    //Chrominance,Cr(or blue)maximum/minimum   0xff00  346
+#define  EREG_PROCESS_CTRL    0x1018    //Processing control working copy          0x0280  347
+#define  EREG_BPA_SF_GTHRESH  0x101a    //BPA scale factor,green filter threshold  0x0220  349
+#define  EREG_BPA_OUTL_PED    0x101c    //BPA outlier, pedestal                    0x4008  350
+#define  EREG_BPA_BADPIX_CNT  0x101e    //BPA bad pixel count (read only)          0x0000  351
+#define  EREG_SZR_IN_W        0x1020    //Sizer input width                        0x0280  352
+#define  EREG_SZR_IN_H        0x1022    //Sizer input height                       0x01e0  353
+#define  EREG_SZR_OUT_W       0x1024    //Sizer output width                       0x0140  354
+#define  EREG_SZR_OUT_H       0x1026    //Sizer output height                      0x00f0  355
+
+
+#define  EREG_CC_COEF_00      0x1028    //Color correction coefficient 00          0x02f9  358
+#define  EREG_CC_COEF_01      0x102a    //Color correction coefficient 01          0x0f03  358
+#define  EREG_CC_COEF_02      0x102c    //Color correction coefficient 02          0x0f02  358
+#define  EREG_CC_COEF_10      0x102e    //Color correction coefficient 10          0x0f4f  358
+#define  EREG_CC_COEF_11      0x1030    //Color correction coefficient 11          0x025c  358
+#define  EREG_CC_COEF_12      0x1032    //Color correction coefficient 12          0x0f54  358
+#define  EREG_CC_COEF_20      0x1034    //Color correction coefficient 20          0x0fe0  358
+#define  EREG_CC_COEF_21      0x1036    //Color correction coefficient 21          0x0e4a  358
+#define  EREG_CC_COEF_22      0x1038    //Color correction coefficient 22          0x02d5  358
+                                                                                         
+#define  EREG_CC_PRE_OS_0     0x103a    //Color correction pre-offset 0            0x01f8  360
+#define  EREG_CC_PRE_OS_1     0x103c    //Color correction pre-offset 1            0x01f8  360
+#define  EREG_CC_PRE_OS_2     0x103e    //Color correction pre-offset 2            0x01f8  360
+#define  EREG_CC_POST_OS_0    0x1040    //Color correction post-offset 0           0x0000  360
+#define  EREG_CC_POST_OS_1    0x1042    //Color correction post-offset 1           0x0000  360
+#define  EREG_CC_POST_OS_2    0x1044    //Color correction post-offset 2           0x0000  360
+
+#define  EREG_CSC_COEF_00     0x1046    //Color space conversion coefficient 00    0x0026  363
+#define  EREG_CSC_COEF_01     0x1048    //Color space conversion coefficient 01    0x004b  363
+#define  EREG_CSC_COEF_02     0x104a    //Color space conversion coefficient 02    0x000f  363
+#define  EREG_CSC_COEF_10     0x104c    //Color space conversion coefficient 10    0x01ed  363
+#define  EREG_CSC_COEF_11     0x104e    //Color space conversion coefficient 11    0x01db  363
+#define  EREG_CSC_COEF_12     0x1050    //Color space conversion coefficient 12    0x0038  363
+#define  EREG_CSC_COEF_20     0x1052    //Color space conversion coefficient 20    0x004f  363
+#define  EREG_CSC_COEF_21     0x1054    //Color space conversion coefficient 21    0x01be  363
+#define  EREG_CSC_COEF_22     0x1056    //Color space conversion coefficient 22    0x01f3  363
+#define  EREG_CSC_OS_0        0x1058    //Color space conversion offset 0          0x0000  364
+#define  EREG_CSC_OS_1        0x105a    //Color space conversion offset 1          0x0080  364
+#define  EREG_CSC_OS_2        0x105c    //Color space conversion offset 2          0x0080  364
+#define  EREG_DATA_GEN        0x105e    //Test data generator                      0x0000  365
+#define  EREG_HSYNC_PER       0x1060    //Horizontal synchronization period        0x0a8b  366
+#define  EREG_APS_COEF_GRN1   0x1062    //Green 1 AWB gain                         0x0080  368
+#define  EREG_APS_COEF_RED    0x1064    //Red AWB gain                             0x0080  368
+
+
+#define  EREG_APS_COEF_BLUE     0x1066  //Blue AWB gain                            0x0080  368
+#define  EREG_APS_COEF_GRN2     0x1068  //Green 2 AWB gain                         0x0080  368
+#define  EREG_AV_LEFT_TOP       0x106a  //Anti-v,sensor first row and column       0x0101  369
+#define  EREG_AV_RIGHT_BOT      0x106c  //Anti-v, sensor last row and column       0xa27a  370
+#define  EREG_AV_CENTER_COL     0x106e  //Anti-v, sensor center column             0x0148  371
+#define  EREG_AV_CENTER_ROW     0x1070  //Anti-v, sensor center row                0x00f8  372
+#define  EREG_STAT_CAP_CTRL     0x1072  //Image statistics capture control         0x0021  373
+#define  EREG_STAT_MODE_CTRL    0x1074  //Image statistics mode control            0x0000  374
+#define  EREG_GREEN_1_SUM       0x1076  //Green 1 pixel sum                        0x0000  375
+#define  EREG_RED_SUM           0x1078  //Red pixel sum                            0x0000  375
+#define  EREG_BLUE_SUM          0x107a  //Blue pixel sum                           0x0000  375
+#define  EREG_GREEN_2_SUM       0x107c  //Green 2 pixel sum                        0x0000  375
+#define  EREG_I_WIDTH           0x107e  //Current image width                      0x0000  376
+#define  EREG_I_HEIGHT          0x1080  //Current image height                     0x0000  377
+#define  EREG_STATUS_FLAGS      0x1082  //Status flags (read only)                 0x0000  378
+#define  EREG_CLK_GATE_DIS      0x1084  //Clock gate disable                       0x0000  379
+#define  EREG_CCIR_TIMING2      0x1086  //CCIR interface timing 2                  0x0000  381
+#define  EREG_CCIR_TIMING3      0x1088  //CCIR interface timing 3                  0x0010  382
+#define  EREG_G1G2_DIAG_THRESH  0x108a  //Green 1/green 2 diagonal threshold       0x0040  383
+#define  EREG_BPA_D2_THRESH     0x108c  //BPA second derivative threshold          0x0100  384
+#define  EREG_SERIAL_CTRL       0x108e  //Serial control                           0x0000  385
+#define  EREG_INTP_CTRL_1       0x1090  //Interpolation control 1(demosaic)        0x0188  387
+#define  EREG_INTP_CTRL_2       0x1092  //Interpolation control 2(demosaic)        0x00c8  388
+#define  EREG_AV_OVAL_FACT      0x1094  //Anti-vignetting oval factor              0x0100  389
+#define  EREG_AV_OS_GREEN1      0x1096  //Anti-vignetting green 1 offset           0x0000  391
+#define  EREG_AV_OS_RED         0x1098  //Anti-vignetting red offset               0x0000  391
+#define  EREG_AV_OS_BLUE        0x109a  //Anti-vignetting blue offset              0x0000  391
+#define  EREG_AV_OS_GREEN2      0x109c  //Anti-vignetting green 2 offset           0x0000  391
+                                    
+
+/***********************************************************************
+ * 
+ * typedefs & Structures
+ *
+ ***********************************************************************/
+ 
+struct adcm3800_context_s
+{
+    int video_running;      // =1 video is running
+    int SCL_partial;        // =1 partial SCL updated
+    int SCL_restart;        // =1 SCL & restart updated
+
+    u32 chipid;
+
+    u16 format;
+    u16 sensor_w;
+    u16 sensor_h;
+    u16 output_w;
+    u16 output_h;
+
+    // frame rate control
+    unsigned int fps;
+    unsigned int mclk;
+
+	int            bright;
+	V4l_PIC_STYLE  style;
+	V4l_PIC_WB     light;
+	int            flicker_freq;
+
+    V4l_NM expo_mode;
+    int max_expotime;
+};
+
+typedef struct adcm3800_context_s adcm3800_context_t, *p_adcm3800_context_t;
+                                                                            
+
+/***********************************************************************                   
+ *                                                                                         
+ * Function Prototype                 
+ *                                    
+ ***********************************************************************/
+
+// Configuration Procedures
+int adcm3800_power_on(u32 clk);
+int adcm3800_power_off(void );
+int adcm3800_viewfinder_on( void );
+int adcm3800_viewfinder_off( void );
+int adcm3800_reconfigure(p_camera_context_t cam_ctx, int frames);
+
+int adcm3800_set_output_format(u16 format);
+int adcm3800_set_output_size(u16 width, u16 height);
+int adcm3800_set_sensor_size(u16 width, u16 height);
+
+int adcm3800_set_fps(u16 fps);
+
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+int adcm3800_set_style(V4l_PIC_STYLE style);
+/*set picture light(direct sun/incandescent/fluorescent)*/     
+int adcm3800_set_light(V4l_PIC_WB light);
+/*set picture brightness*/
+int adcm3800_set_bright(int bright);
+int adcm3800_set_flicker(int freq);
+int adcm3800_set_exposure_mode(V4l_NM mode, int maxexpotime);
+
+extern int i2c_adcm3800_read(u16 addr, u16 *pvalue);
+extern int i2c_adcm3800_write(u16 addr, u16 value);
+extern int i2c_adcm3800_read_byte(u16 addr, u8 *pvalue);
+extern int i2c_adcm3800_write_byte(u16 addr, u8 value);
+
+#endif /* _PXA_ADCM3800_HW_H__ */
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/camera.h linux-2.6.16.5-exz/drivers/media/video/camera.h
--- linux-2.6.16.5/drivers/media/video/camera.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/camera.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,663 @@
+/*================================================================================
+                                                                               
+                     Module Name:  camera.h
+
+General Description: Camera module adcm2700  head file
+
+==================================================================================
+                      Motorola Confidential Proprietary
+                  Advanced Technology and Software Operations
+                (c) Copyright Motorola 1999, All Rights Reserved
+  
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Wangfei(w20239)     12/19/2003      LIBdd35749    Created
+wangfei(w20239)     02/26/2004      LIBdd81055    Update algorithm for DMA transfer
+
+Portability: Indicate ifthis module is portable to other compilers or 
+platforms. If not, indicate specific reasons why is it not portable.
+
+==================================================================================
+                                 INCLUDE FILES
+================================================================================*/
+#ifndef CAMERA_H_
+#define CAMERA_H_
+
+#include <linux/pxa_camera.h>
+#include <linux/videodev.h>
+
+#define DEBUG   1
+ 
+#ifdef CONFIG_CAMERA_ADCM2700
+#endif
+
+#ifdef CONFIG_CAMERA_OV9640
+#endif
+
+#ifdef CONFIG_CAMERA_MT9M111
+#endif
+
+/*
+Bpp definition
+*/
+
+#define YUV422_BPP				16
+#define RGB565_BPP				16
+#define RGB666_UNPACKED_BPP       32
+#define RGB666_PACKED_BPP         24
+
+//---------------------------------------------------------------------------
+// Register definitions
+//---------------------------------------------------------------------------
+
+enum CI_REGBITS_CICR0 {
+        CI_CICR0_FOM       = 0x00000001,
+        CI_CICR0_EOFM      = 0x00000002,
+        CI_CICR0_SOFM      = 0x00000004,
+        CI_CICR0_CDM       = 0x00000008,
+        CI_CICR0_QDM       = 0x00000010,
+        CI_CICR0_PERRM     = 0x00000020,
+        CI_CICR0_EOLM      = 0x00000040,
+        CI_CICR0_FEM       = 0x00000080,
+        CI_CICR0_RDAVM     = 0x00000100,
+        CI_CICR0_TOM       = 0x00000200,
+        CI_CICR0_RESERVED  = 0x03FFFC00,
+        CI_CICR0_SIM_SHIFT = 24,
+        CI_CICR0_SIM_SMASK = 0x7,
+        CI_CICR0_DIS       = 0x08000000,
+        CI_CICR0_ENB       = 0x10000000,
+        CI_CICR0_SL_CAP_EN = 0x20000000,
+        CI_CICR0_PAR_EN    = 0x40000000,
+        CI_CICR0_DMA_EN    = 0x80000000,
+        CI_CICR0_INTERRUPT_MASK = 0x3FF
+};
+
+enum CI_REGBITS_CICR1 {
+        CI_CICR1_DW_SHIFT       = 0,
+        CI_CICR1_DW_SMASK       = 0x7,
+        CI_CICR1_COLOR_SP_SHIFT = 3,
+        CI_CICR1_COLOR_SP_SMASK = 0x3,
+        CI_CICR1_RAW_BPP_SHIFT  = 5,
+        CI_CICR1_RAW_BPP_SMASK  = 0x3,
+        CI_CICR1_RGB_BPP_SHIFT  = 7,
+        CI_CICR1_RGB_BPP_SMASK  = 0x7,
+        CI_CICR1_YCBCR_F        = 0x00000400,
+        CI_CICR1_RBG_F          = 0x00000800,
+        CI_CICR1_RGB_CONV_SHIFT = 12,
+        CI_CICR1_RGB_CONV_SMASK = 0x7,
+        CI_CICR1_PPL_SHIFT      = 15,
+        CI_CICR1_PPL_SMASK      = 0x7FF,
+        CI_CICR1_RESERVED       = 0x1C000000,
+        CI_CICR1_RGBT_CONV_SHIFT= 29,
+        CI_CICR1_RGBT_CONV_SMASK= 0x3,
+        CI_CICR1_TBIT           = 0x80000000
+};
+
+enum CI_REGBITS_CICR2 {
+        CI_CICR2_FSW_SHIFT = 0,
+        CI_CICR2_FSW_SMASK = 0x3,
+        CI_CICR2_BFPW_SHIFT= 3,
+        CI_CICR2_BFPW_SMASK= 0x3F,
+        CI_CICR2_RESERVED  = 0x00000200,
+        CI_CICR2_HSW_SHIFT = 10,
+        CI_CICR2_HSW_SMASK = 0x3F,
+        CI_CICR2_ELW_SHIFT = 16,
+        CI_CICR2_ELW_SMASK = 0xFF,
+        CI_CICR2_BLW_SHIFT = 24,     
+        CI_CICR2_BLW_SMASK = 0xFF    
+};
+
+enum CI_REGBITS_CICR3 {
+    CI_CICR3_LPF_SHIFT = 0,
+    CI_CICR3_LPF_SMASK = 0x7FF,
+    CI_CICR3_VSW_SHIFT = 11,
+    CI_CICR3_VSW_SMASK = 0x1F,
+    CI_CICR3_EFW_SHIFT = 16,
+    CI_CICR3_EFW_SMASK = 0xFF,
+    CI_CICR3_BFW_SHIFT = 24,
+    CI_CICR3_BFW_SMASK = 0xFF
+};
+
+enum CI_REGBITS_CICR4 {
+    CI_CICR4_DIV_SHIFT = 0,
+    CI_CICR4_DIV_SMASK = 0xFF,
+    CI_CICR4_FR_RATE_SHIFT = 8,
+    CI_CICR4_FR_RATE_SMASK = 0x7,
+    CI_CICR4_RESERVED1 = 0x0007F800,
+    CI_CICR4_MCLK_EN   = 0x00080000,
+    CI_CICR4_VSP       = 0x00100000,
+    CI_CICR4_HSP       = 0x00200000,
+    CI_CICR4_PCP       = 0x00400000,
+    CI_CICR4_PCLK_EN   = 0x00800000,
+    CI_CICR4_RESERVED2 = 0xFF000000,
+    CI_CICR4_RESERVED  = CI_CICR4_RESERVED1 | CI_CICR4_RESERVED2
+};
+
+enum CI_REGBITS_CISR {
+    CI_CISR_IFO_0      = 0x00000001,
+    CI_CISR_IFO_1      = 0x00000002,
+    CI_CISR_IFO_2      = 0x00000004,
+    CI_CISR_EOF        = 0x00000008,
+    CI_CISR_SOF        = 0x00000010,
+    CI_CISR_CDD        = 0x00000020,
+    CI_CISR_CQD        = 0x00000040,
+    CI_CISR_PAR_ERR    = 0x00000080,
+    CI_CISR_EOL        = 0x00000100,
+    CI_CISR_FEMPTY_0   = 0x00000200,
+    CI_CISR_FEMPTY_1   = 0x00000400,
+    CI_CISR_FEMPTY_2   = 0x00000800,
+    CI_CISR_RDAV_0     = 0x00001000,
+    CI_CISR_RDAV_1     = 0x00002000,
+    CI_CISR_RDAV_2     = 0x00004000, 
+    CI_CISR_FTO        = 0x00008000,
+    CI_CISR_RESERVED   = 0xFFFF0000
+};
+
+enum CI_REGBITS_CIFR {
+    CI_CIFR_FEN0       = 0x00000001,
+    CI_CIFR_FEN1       = 0x00000002,
+    CI_CIFR_FEN2       = 0x00000004,
+    CI_CIFR_RESETF     = 0x00000008,
+    CI_CIFR_THL_0_SHIFT= 4,
+    CI_CIFR_THL_0_SMASK= 0x3,
+    CI_CIFR_RESERVED1  = 0x000000C0,
+    CI_CIFR_FLVL0_SHIFT= 8,
+    CI_CIFR_FLVL0_SMASK= 0xFF,
+    CI_CIFR_FLVL1_SHIFT= 16,
+    CI_CIFR_FLVL1_SMASK= 0x7F,
+    CI_CIFR_FLVL2_SHIFT= 23,
+    CI_CIFR_FLVL2_SMASK= 0x7F,
+    CI_CIFR_RESERVED2  = 0xC0000000,
+    CI_CIFR_RESERVED   = CI_CIFR_RESERVED1 | CI_CIFR_RESERVED2 
+};
+
+//---------------------------------------------------------------------------
+//     Parameter Type definitions
+//---------------------------------------------------------------------------
+typedef enum  {
+        CI_RAW8 = 0,                   //RAW
+        CI_RAW9,
+        CI_RAW10,
+        CI_YCBCR422,               //YCBCR
+        CI_YCBCR422_PLANAR,        //YCBCR Planaried
+        CI_RGB444,                 //RGB
+        CI_RGB555,
+        CI_RGB565,
+        CI_RGB666,
+        CI_RGB888,
+        CI_RGBT555_0,              //RGB+Transparent bit 0
+        CI_RGBT888_0,
+        CI_RGBT555_1,              //RGB+Transparent bit 1  
+        CI_RGBT888_1,
+        CI_RGB666_PACKED,          //RGB Packed 
+        CI_RGB888_PACKED,
+        CI_INVALID_FORMAT = 0xFF
+} CI_IMAGE_FORMAT;
+
+typedef enum {
+    CI_INTSTATUS_IFO_0      = 0x00000001,
+    CI_INTSTATUS_IFO_1      = 0x00000002,
+    CI_INTSTATUS_IFO_2      = 0x00000004,
+    CI_INTSTATUS_EOF        = 0x00000008,
+    CI_INTSTATUS_SOF        = 0x00000010,
+    CI_INTSTATUS_CDD        = 0x00000020,
+    CI_INTSTATUS_CQD        = 0x00000040,
+    CI_INTSTATUS_PAR_ERR    = 0x00000080,
+    CI_INTSTATUS_EOL        = 0x00000100,
+    CI_INTSTATUS_FEMPTY_0   = 0x00000200,
+    CI_INTSTATUS_FEMPTY_1   = 0x00000400,
+    CI_INTSTATUS_FEMPTY_2   = 0x00000800,
+    CI_INTSTATUS_RDAV_0     = 0x00001000,
+    CI_INTSTATUS_RDAV_1     = 0x00002000,
+    CI_INTSTATUS_RDAV_2     = 0x00004000, 
+    CI_INTSTATUS_FTO        = 0x00008000,
+    CI_INTSTATUS_ALL       = 0x0000FFFF
+} CI_INTERRUPT_STATUS;
+
+typedef enum {
+    CI_INT_IFO      = 0x00000001,
+    CI_INT_EOF      = 0x00000002,
+    CI_INT_SOF      = 0x00000004,
+    CI_INT_CDD      = 0x00000008,
+    CI_INT_CQD      = 0x00000010,
+    CI_INT_PAR_ERR  = 0x00000020,
+    CI_INT_EOL      = 0x00000040,
+    CI_INT_FEMPTY   = 0x00000080,
+    CI_INT_RDAV     = 0x00000100,
+    CI_INT_FTO      = 0x00000200,
+    CI_INT_ALL      = 0x000003FF
+} CI_INTERRUPT_MASK;
+#define CI_INT_MAX 10
+
+typedef enum CI_MODE {
+        CI_MODE_MP,             // Master-Parallel
+        CI_MODE_SP,             // Slave-Parallel
+        CI_MODE_MS,             // Master-Serial
+        CI_MODE_EP,             // Embedded-Parallel
+        CI_MODE_ES              // Embedded-Serial
+} CI_MODE;
+
+
+typedef enum  {
+        CI_FR_ALL = 0,          // Capture all incoming frames
+        CI_FR_1_2,              // Capture 1 out of every 2 frames
+        CI_FR_1_3,              // Capture 1 out of every 3 frames
+        CI_FR_1_4,
+        CI_FR_1_5,
+        CI_FR_1_6,
+        CI_FR_1_7,
+        CI_FR_1_8
+} CI_FRAME_CAPTURE_RATE;
+
+
+typedef enum  {
+        CI_FIFO_THL_32 = 0,
+        CI_FIFO_THL_64,
+        CI_FIFO_THL_96
+} CI_FIFO_THRESHOLD;
+
+typedef struct {
+    unsigned int BFW;
+    unsigned int BLW;
+} CI_MP_TIMING, CI_MS_TIMING;
+
+typedef struct {
+    unsigned int BLW;
+    unsigned int ELW; 
+    unsigned int HSW;
+    unsigned int BFPW;
+    unsigned int FSW; 
+    unsigned int BFW;
+    unsigned int EFW;
+    unsigned int VSW; 
+} CI_SP_TIMING;
+
+typedef enum {
+    CI_DATA_WIDTH4 = 0x0,
+    CI_DATA_WIDTH5 = 0x1,
+    CI_DATA_WIDTH8 = 0x2,  
+    CI_DATA_WIDTH9 = 0x3,  
+    CI_DATA_WIDTH10= 0x4   
+} CI_DATA_WIDTH;
+
+//-------------------------------------------------------------------------------------------------------
+//      Configuration APIs
+//-------------------------------------------------------------------------------------------------------
+
+void ci_set_frame_rate(CI_FRAME_CAPTURE_RATE frate);
+CI_FRAME_CAPTURE_RATE ci_get_frame_rate(void);
+void ci_set_image_format(CI_IMAGE_FORMAT input_format, CI_IMAGE_FORMAT output_format); 
+void ci_set_mode(CI_MODE mode, CI_DATA_WIDTH data_width);
+void ci_configure_mp(unsigned int PPL, unsigned int LPF, CI_MP_TIMING* timing);
+void ci_configure_sp(unsigned int PPL, unsigned int LPF, CI_SP_TIMING* timing);
+void ci_configure_ms(unsigned int PPL, unsigned int LPF, CI_MS_TIMING* timing);
+void ci_configure_ep(int parity_check);
+void ci_configure_es(int parity_check);
+void ci_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz);
+void ci_set_polarity(int pclk_sample_falling, int hsync_active_low, int vsync_active_low);
+void ci_set_fifo( unsigned int timeout, CI_FIFO_THRESHOLD threshold, int fifo1_enable, 
+                   int fifo2_enable);
+void ci_set_int_mask( unsigned int mask);
+void ci_clear_int_status( unsigned int status);
+void ci_set_reg_value( unsigned int reg_offset, unsigned int value);
+int ci_get_reg_value(unsigned int reg_offset);
+
+void ci_reset_fifo(void);
+unsigned int ci_get_int_mask(void);
+unsigned int ci_get_int_status(void);
+void ci_slave_capture_enable(void);
+void ci_slave_capture_disable(void);
+
+//-------------------------------------------------------------------------------------------------------
+//      Control APIs
+//-------------------------------------------------------------------------------------------------------
+int  ci_init(void);
+void ci_deinit(void);
+void ci_enable( int dma_en);
+int  ci_disable(int quick);
+
+//debug
+void ci_dump(void);
+// IRQ
+irqreturn_t pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs);
+
+#ifdef DEBUG
+
+#define dbg_print(fmt, args...) printk(KERN_INFO "fun %s "fmt"\n", __FUNCTION__, ##args)
+
+#if DEBUG > 1
+#define ddbg_print(fmt, args...) printk(KERN_INFO "fun %s "fmt"\n", __FUNCTION__, ##args)
+#else
+#define ddbg_print(fmt, args...) ;
+#endif
+
+#else
+
+#define dbg_print(fmt, args...)  ;
+#define ddbg_print(fmt, args...) ;
+
+#endif
+
+
+#define VID_HARDWARE_PXA_CAMERA 	50 /* subject to change */
+
+#define STATUS_FAILURE	(0)
+#define STATUS_SUCCESS	(1)
+#define STATUS_WRONG_PARAMETER  -1
+
+#ifdef CONFIG_CAMERA_OV9640
+#define CIBR0_PHY       (0x50000000 + 0x28)
+#define CIBR1_PHY       (0x50000000 + 0x30)
+#define CIBR2_PHY       (0x50000000 + 0x38)
+#endif
+/*
+Macros
+*/
+/*GPIO and CIF pin definitions*/
+#define CIF_PD       50
+#define CIF_RST      19
+#define CIF_MCLK     23
+#define CIF_PCLK     54
+#define CIF_LV       85
+#define CIF_FV       84
+#define CIF_DD0      27
+#define CIF_DD1      114
+#define CIF_DD2      51
+#define CIF_DD3      115 
+#define CIF_DD4      95
+#define CIF_DD5      94 
+#define CIF_DD6      17
+#define CIF_DD7      108
+
+#define CIF_PD_MD      (CIF_PD   | GPIO_OUT)
+#define CIF_RST_MD     (CIF_RST  | GPIO_OUT) 
+#define CIF_MCLK_MD    (CIF_MCLK | GPIO_ALT_FN_1_OUT)
+#define CIF_PCLK_MD    (CIF_PCLK | GPIO_ALT_FN_3_IN)
+#define CIF_LV_MD      (CIF_LV   | GPIO_ALT_FN_3_IN)
+#define CIF_FV_MD      (CIF_FV   | GPIO_ALT_FN_3_IN)
+#define CIF_DD0_MD     (CIF_DD0  | GPIO_ALT_FN_3_IN)
+#define CIF_DD1_MD     (CIF_DD1  | GPIO_ALT_FN_1_IN)
+#define CIF_DD2_MD     (CIF_DD2  | GPIO_ALT_FN_1_IN)
+#define CIF_DD3_MD     (CIF_DD3  | GPIO_ALT_FN_2_IN)
+#define CIF_DD4_MD     (CIF_DD4  | GPIO_ALT_FN_2_IN)
+#define CIF_DD5_MD     (CIF_DD5  | GPIO_ALT_FN_2_IN)
+#define CIF_DD6_MD     (CIF_DD6  | GPIO_ALT_FN_2_IN)
+#define CIF_DD7_MD     (CIF_DD7  | GPIO_ALT_FN_1_IN)
+
+/*
+Image format definition
+*/
+#define CAMERA_IMAGE_FORMAT_MAX                CAMERA_IMAGE_FORMAT_YCBCR444_PLANAR
+
+// Interrupt mask
+#define CAMERA_INTMASK_FIFO_OVERRUN            0x0001
+#define CAMERA_INTMASK_END_OF_FRAME            0x0002  
+#define CAMERA_INTMASK_START_OF_FRAME          0x0004
+#define CAMERA_INTMASK_CI_DISABLE_DONE         0x0008
+#define CAMERA_INTMASK_CI_QUICK_DISABLE        0x0010
+#define CAMERA_INTMASK_PARITY_ERROR            0x0020
+#define CAMERA_INTMASK_END_OF_LINE             0x0040
+#define CAMERA_INTMASK_FIFO_EMPTY              0x0080
+#define CAMERA_INTMASK_RCV_DATA_AVALIBLE       0x0100
+#define CAMERA_INTMASK_TIME_OUT                0x0200
+#define CAMERA_INTMASK_END_OF_DMA              0x0400
+
+// Interrupt status
+#define CAMERA_INTSTATUS_FIFO_OVERRUN_0        0x00000001
+#define CAMERA_INTSTATUS_FIFO_OVERRUN_1        0x00000002
+#define CAMERA_INTSTATUS_FIFO_OVERRUN_2        0x00000004
+#define CAMERA_INTSTATUS_END_OF_FRAME          0x00000008  
+#define CAMERA_INTSTATUS_START_OF_FRAME        0x00000010
+#define CAMERA_INTSTATUS_CI_DISABLE_DONE       0x00000020
+#define CAMERA_INTSTATUS_CI_QUICK_DISABLE      0x00000040
+#define CAMERA_INTSTATUS_PARITY_ERROR          0x00000080
+#define CAMERA_INTSTATUS_END_OF_LINE           0x00000100
+#define CAMERA_INTSTATUS_FIFO_EMPTY_0          0x00000200
+#define CAMERA_INTSTATUS_FIFO_EMPTY_1          0x00000400
+#define CAMERA_INTSTATUS_FIFO_EMPTY_2          0x00000800
+#define CAMERA_INTSTATUS_RCV_DATA_AVALIBLE_0   0x00001000
+#define CAMERA_INTSTATUS_RCV_DATA_AVALIBLE_1   0x00002000
+#define CAMERA_INTSTATUS_RCV_DATA_AVALIBLE_2   0x00004000
+#define CAMERA_INTSTATUS_TIME_OUT              0x00008000
+#define CAMERA_INTSTATUS_END_OF_DMA            0x00010000
+
+// Capture status
+#define CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS 0x0001
+#define CAMERA_STATUS_RING_BUFFER_FULL         0x0002
+
+
+/*
+Structures
+*/
+typedef struct camera_context_s camera_context_t, *p_camera_context_t;
+
+typedef struct {
+    int (*init)(p_camera_context_t context);
+    int (*deinit)(p_camera_context_t);   
+    int (*set_capture_format)(p_camera_context_t);
+    int (*start_capture)(p_camera_context_t, unsigned int frames);
+    int (*stop_capture)(p_camera_context_t);
+    int (*command)(p_camera_context_t, unsigned int cmd, void *param);
+    int (*pm_management)(p_camera_context_t, int suspend);
+} camera_function_t, *p_camera_function_t;
+// context
+
+struct camera_context_s {
+	// syncronization stuff
+	atomic_t refcount;
+
+	/*
+	 * DRIVER FILLED PARAMTER
+	 */
+
+	// sensor info  
+	unsigned int sensor_type;
+
+	// capture image info
+	unsigned int capture_width; 
+	unsigned int capture_height;
+    unsigned int sensor_width;
+    unsigned int sensor_height;
+    
+	unsigned int    capture_input_format;
+	unsigned int    capture_output_format;
+	V4l_PIC_STYLE   capture_style;
+	V4l_PIC_WB      capture_light;
+	int             capture_bright;
+	int             capture_contrast;
+	int             flicker_freq;
+
+	
+    
+    struct video_capability vc;
+
+    
+	// frame rate control
+    unsigned int frame_rate;
+	unsigned int fps;
+    unsigned int mini_fps;
+    
+    unsigned int mclk;
+
+   	// ring buffers
+	// note: must pass in 8 bytes aligned address
+	void *buffer_virtual;
+	void *buffer_physical;
+	unsigned int buf_size;
+
+	// memory for dma descriptors, layout:
+	//  dma descriptor chain 0,
+	//  dma descriptor chain 1,
+	//  ...  
+	void *dma_descriptors_virtual;
+	void *dma_descriptors_physical;
+	unsigned int dma_descriptors_size;
+
+	// os mapped register address   
+	unsigned int clk_reg_base;
+	unsigned int ost_reg_base;
+	unsigned int gpio_reg_base;
+	unsigned int ci_reg_base;
+	unsigned int board_reg_base;
+
+	// function dispatch table
+	p_camera_function_t camera_functions;
+
+	/*
+	 * FILLED PARAMTER
+	 */
+	int dma_channels[3];
+	unsigned int capture_status;
+
+	/*
+	 * INTERNALLY USED: DON'T TOUCH!
+	 */
+	unsigned int block_number, block_size, block_number_max;
+	unsigned int block_header, block_tail;
+	unsigned int fifo0_descriptors_virtual, fifo0_descriptors_physical;
+	unsigned int fifo1_descriptors_virtual, fifo1_descriptors_physical;
+	unsigned int fifo2_descriptors_virtual, fifo2_descriptors_physical;
+	unsigned int fifo0_num_descriptors;
+	unsigned int fifo1_num_descriptors;
+	unsigned int fifo2_num_descriptors;
+	unsigned int fifo0_transfer_size;
+	unsigned int fifo1_transfer_size;
+	unsigned int fifo2_transfer_size;
+
+	struct page **page_array;
+
+	unsigned int pages_allocated;
+	unsigned int page_aligned_block_size;
+	unsigned int pages_per_block;
+	unsigned int pages_per_fifo0;
+	unsigned int pages_per_fifo1;
+	unsigned int pages_per_fifo2;
+
+#ifdef CONFIG_DPM
+        struct pm_dev *pmdev;
+#endif
+	int dma_started;
+};
+
+
+/*
+Prototypes
+*/
+/***********************************************************************
+ *
+ * Init/Deinit APIs
+ *
+ ***********************************************************************/
+// Setup the sensor type, configure image capture format (RGB, yuv 444, yuv 422, yuv 420, packed | planar, MJPEG) regardless
+// of current operating mode (i.e. sets mode for both still capture and video capture)
+int camera_init( p_camera_context_t camera_context );
+
+// Power off sensor
+int camera_deinit( p_camera_context_t camera_context );
+
+
+/***********************************************************************
+ *
+ * Capture APIs
+ *
+ ***********************************************************************/
+// Set the image format
+int camera_set_capture_format( p_camera_context_t camera_context );
+
+// take a picture and copy it into the ring buffer
+int camera_capture_still_image( p_camera_context_t camera_context, unsigned int block_id );
+
+// capture motion video and copy it the ring buffer
+int camera_start_video_capture( p_camera_context_t camera_context, unsigned int block_id );
+
+// disable motion video image capture
+void camera_stop_video_capture( p_camera_context_t camera_context );
+
+int camera_func_ov9640_command(p_camera_context_t camera_context, unsigned int cmd, void *param);
+
+/***********************************************************************
+ *
+ * Flow Control APIs
+ *
+ ***********************************************************************/
+// continue capture image to next available buffer
+// Returns the continued buffer id, -1 means buffer full and no transfer started
+void camera_continue_transfer( p_camera_context_t camera_context ); 
+
+// Return 1: there is available buffer, 0: buffer is full
+int camera_next_buffer_available( p_camera_context_t camera_context );
+
+// Application supplies the FrameBufferID to the driver to tell it that the application has completed processing of the given frame buffer, and that buffer is now available for re-use.
+void camera_release_frame_buffer( p_camera_context_t camera_context, unsigned int frame_buffer_id ); 
+
+// Returns the FrameBufferID for the first filled frame
+// Note: -1 represents buffer empty
+int camera_get_first_frame_buffer_id( p_camera_context_t camera_context ); 
+
+/*
+Returns the FrameBufferID for the last filled frame, this would be used if we were polling for image completion data, 
+or we wanted to make sure there were no frames waiting for us to process.
+Note: -1 represents buffer empty
+*/
+int camera_get_last_frame_buffer_id( p_camera_context_t camera_context ); 
+
+
+/***********************************************************************
+ *
+ * Buffer Info APIs
+ *
+ ***********************************************************************/
+// Return: the number of frame buffers allocated for use.
+unsigned int camera_get_num_frame_buffers( p_camera_context_t camera_context );
+
+/* 
+FrameBufferID is a number between 0 and N-1, where N is the total number of frame buffers in use.  
+Returns the address of the given frame buffer.  
+The application will call this once for each frame buffer at application initialization only.
+*/
+void* camera_get_frame_buffer_addr( p_camera_context_t camera_context, unsigned int frame_buffer_id );
+
+// Return the block id
+int camera_get_frame_buffer_id( p_camera_context_t camera_context, void* address );
+
+/***********************************************************************
+ *
+ * Frame rate APIs
+ *
+ ***********************************************************************/
+// Set desired frame rate
+void camera_set_capture_frame_rate( p_camera_context_t camera_context ); 
+
+// return current setting
+void camera_get_capture_frame_rate( p_camera_context_t camera_context ); 
+
+
+/***********************************************************************
+ *
+ * Interrupt APIs
+ *
+ ***********************************************************************/
+// set interrupt mask 
+void camera_set_int_mask( p_camera_context_t camera_context, unsigned int mask ); 
+
+// get interrupt mask 
+unsigned int camera_get_int_mask( p_camera_context_t camera_context ); 
+
+// clear interrupt status
+void camera_clear_int_status( p_camera_context_t camera_context, unsigned int status );
+
+// gpio init
+void camera_gpio_init(void);
+void camera_gpio_deinit(void);
+
+// ci functions
+void ci_reset(void);
+
+// dma functions
+extern void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id);
+extern void stop_dma_transfer(p_camera_context_t camera_context);
+extern int camera_ring_buf_init(p_camera_context_t camera_context);
+
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ci.h linux-2.6.16.5-exz/drivers/media/video/ci.h
--- linux-2.6.16.5/drivers/media/video/ci.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ci.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,303 @@
+/****************************************************************************** 
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+********************************************************************************/
+#ifndef __CI_H__
+#define __CI_H__
+
+//---------------------------------------------------------------------------
+// Register definitions
+//---------------------------------------------------------------------------
+
+extern unsigned long ci_regs_base ;   /* for CI registers IOMEM mapping */
+
+#define CI_REG(x)             (* (volatile u32*)(x) )
+#define CI_REG_SIZE             0x40 /* 0x5000_0000 --- 0x5000_0038 * 64K */
+#define CI_REGS_PHYS            0x50000000  /* Start phyical address of CI registers */
+//
+#define CICR0		        CI_REG((u32)(ci_regs_base) + 0x00)
+#define CICR1           	CI_REG((u32)(ci_regs_base) + 0x04)
+#define CICR2 		        CI_REG((u32)(ci_regs_base) + 0x08)
+#define CICR3           	CI_REG((u32)(ci_regs_base) + 0x0c)
+#define CICR4             	CI_REG((u32)(ci_regs_base) + 0x10)
+#define CISR 	        	CI_REG((u32)(ci_regs_base) + 0x14)
+#define CIFR              	CI_REG((u32)(ci_regs_base) + 0x18)
+#define CITOR             	CI_REG((u32)(ci_regs_base) + 0x1c)
+#define CIBR0             	CI_REG((u32)(ci_regs_base) + 0x28)
+#define CIBR1             	CI_REG((u32)(ci_regs_base) + 0x30)
+#define CIBR2             	CI_REG((u32)(ci_regs_base) + 0x38)
+/*
+*/
+enum CI_REGBITS_CICR0 {
+        CI_CICR0_FOM       = 0x00000001,
+        CI_CICR0_EOFM      = 0x00000002,
+        CI_CICR0_SOFM      = 0x00000004,
+        CI_CICR0_CDM       = 0x00000008,
+        CI_CICR0_QDM       = 0x00000010,
+        CI_CICR0_PERRM     = 0x00000020,
+        CI_CICR0_EOLM      = 0x00000040,
+        CI_CICR0_FEM       = 0x00000080,
+        CI_CICR0_RDAVM     = 0x00000100,
+        CI_CICR0_TOM       = 0x00000200,
+        CI_CICR0_RESERVED  = 0x03FFFC00,
+        CI_CICR0_SIM_SHIFT = 24,
+        CI_CICR0_SIM_SMASK = 0x7,
+        CI_CICR0_DIS       = 0x08000000,
+        CI_CICR0_ENB       = 0x10000000,
+        CI_CICR0_SL_CAP_EN = 0x20000000,
+        CI_CICR0_PAR_EN    = 0x40000000,
+        CI_CICR0_DMA_EN    = 0x80000000,
+        CI_CICR0_INTERRUPT_MASK = 0x3FF
+};
+
+enum CI_REGBITS_CICR1 {
+        CI_CICR1_DW_SHIFT       = 0,
+        CI_CICR1_DW_SMASK       = 0x7,
+        CI_CICR1_COLOR_SP_SHIFT = 3,
+        CI_CICR1_COLOR_SP_SMASK = 0x3,
+        CI_CICR1_RAW_BPP_SHIFT  = 5,
+        CI_CICR1_RAW_BPP_SMASK  = 0x3,
+        CI_CICR1_RGB_BPP_SHIFT  = 7,
+        CI_CICR1_RGB_BPP_SMASK  = 0x7,
+        CI_CICR1_YCBCR_F        = 0x00000400,
+        CI_CICR1_RBG_F          = 0x00000800,
+        CI_CICR1_RGB_CONV_SHIFT = 12,
+        CI_CICR1_RGB_CONV_SMASK = 0x7,
+        CI_CICR1_PPL_SHIFT      = 15,
+        CI_CICR1_PPL_SMASK      = 0x7FF,
+        CI_CICR1_RESERVED       = 0x1C000000,
+        CI_CICR1_RGBT_CONV_SHIFT= 29,
+        CI_CICR1_RGBT_CONV_SMASK= 0x3,
+        CI_CICR1_TBIT           = 0x80000000
+};
+
+enum CI_REGBITS_CICR2 {
+        CI_CICR2_FSW_SHIFT = 0,
+        CI_CICR2_FSW_SMASK = 0x3,
+        CI_CICR2_BFPW_SHIFT= 3,
+        CI_CICR2_BFPW_SMASK= 0x3F,
+        CI_CICR2_RESERVED  = 0x00000200,
+        CI_CICR2_HSW_SHIFT = 10,
+        CI_CICR2_HSW_SMASK = 0x3F,
+        CI_CICR2_ELW_SHIFT = 16,
+        CI_CICR2_ELW_SMASK = 0xFF,
+        CI_CICR2_BLW_SHIFT = 24,     
+        CI_CICR2_BLW_SMASK = 0xFF    
+};
+
+enum CI_REGBITS_CICR3 {
+    CI_CICR3_LPF_SHIFT = 0,
+    CI_CICR3_LPF_SMASK = 0x7FF,
+    CI_CICR3_VSW_SHIFT = 11,
+    CI_CICR3_VSW_SMASK = 0x1F,
+    CI_CICR3_EFW_SHIFT = 16,
+    CI_CICR3_EFW_SMASK = 0xFF,
+    CI_CICR3_BFW_SHIFT = 24,
+    CI_CICR3_BFW_SMASK = 0xFF
+};
+
+enum CI_REGBITS_CICR4 {
+    CI_CICR4_DIV_SHIFT = 0,
+    CI_CICR4_DIV_SMASK = 0xFF,
+    CI_CICR4_FR_RATE_SHIFT = 8,
+    CI_CICR4_FR_RATE_SMASK = 0x7,
+    CI_CICR4_RESERVED1 = 0x0007F800,
+    CI_CICR4_MCLK_EN   = 0x00080000,
+    CI_CICR4_VSP       = 0x00100000,
+    CI_CICR4_HSP       = 0x00200000,
+    CI_CICR4_PCP       = 0x00400000,
+    CI_CICR4_PCLK_EN   = 0x00800000,
+    CI_CICR4_RESERVED2 = 0xFF000000,
+    CI_CICR4_RESERVED  = CI_CICR4_RESERVED1 | CI_CICR4_RESERVED2
+};
+
+enum CI_REGBITS_CISR {
+    CI_CISR_IFO_0      = 0x00000001,
+    CI_CISR_IFO_1      = 0x00000002,
+    CI_CISR_IFO_2      = 0x00000004,
+    CI_CISR_EOF        = 0x00000008,
+    CI_CISR_SOF        = 0x00000010,
+    CI_CISR_CDD        = 0x00000020,
+    CI_CISR_CQD        = 0x00000040,
+    CI_CISR_PAR_ERR    = 0x00000080,
+    CI_CISR_EOL        = 0x00000100,
+    CI_CISR_FEMPTY_0   = 0x00000200,
+    CI_CISR_FEMPTY_1   = 0x00000400,
+    CI_CISR_FEMPTY_2   = 0x00000800,
+    CI_CISR_RDAV_0     = 0x00001000,
+    CI_CISR_RDAV_1     = 0x00002000,
+    CI_CISR_RDAV_2     = 0x00004000, 
+    CI_CISR_FTO        = 0x00008000,
+    CI_CISR_RESERVED   = 0xFFFF0000
+};
+
+enum CI_REGBITS_CIFR {
+    CI_CIFR_FEN0       = 0x00000001,
+    CI_CIFR_FEN1       = 0x00000002,
+    CI_CIFR_FEN2       = 0x00000004,
+    CI_CIFR_RESETF     = 0x00000008,
+    CI_CIFR_THL_0_SHIFT= 4,
+    CI_CIFR_THL_0_SMASK= 0x3,
+    CI_CIFR_RESERVED1  = 0x000000C0,
+    CI_CIFR_FLVL0_SHIFT= 8,
+    CI_CIFR_FLVL0_SMASK= 0xFF,
+    CI_CIFR_FLVL1_SHIFT= 16,
+    CI_CIFR_FLVL1_SMASK= 0x7F,
+    CI_CIFR_FLVL2_SHIFT= 23,
+    CI_CIFR_FLVL2_SMASK= 0x7F,
+    CI_CIFR_RESERVED2  = 0xC0000000,
+    CI_CIFR_RESERVED   = CI_CIFR_RESERVED1 | CI_CIFR_RESERVED2 
+};
+
+//---------------------------------------------------------------------------
+//     Parameter Type definitions
+//---------------------------------------------------------------------------
+typedef enum  {
+        CI_RAW8 = 0,                   //RAW
+        CI_RAW9,
+        CI_RAW10,
+        CI_YCBCR422,               //YCBCR
+        CI_YCBCR422_PLANAR,        //YCBCR Planaried
+        CI_RGB444,                 //RGB
+        CI_RGB555,
+        CI_RGB565,
+        CI_RGB666,
+        CI_RGB888,
+        CI_RGBT555_0,              //RGB+Transparent bit 0
+        CI_RGBT888_0,
+        CI_RGBT555_1,              //RGB+Transparent bit 1  
+        CI_RGBT888_1,
+        CI_RGB666_PACKED,          //RGB Packed 
+        CI_RGB888_PACKED,
+        CI_INVALID_FORMAT = 0xFF
+} CI_IMAGE_FORMAT;
+
+typedef enum {
+    CI_INTSTATUS_IFO_0      = 0x00000001,
+    CI_INTSTATUS_IFO_1      = 0x00000002,
+    CI_INTSTATUS_IFO_2      = 0x00000004,
+    CI_INTSTATUS_EOF        = 0x00000008,
+    CI_INTSTATUS_SOF        = 0x00000010,
+    CI_INTSTATUS_CDD        = 0x00000020,
+    CI_INTSTATUS_CQD        = 0x00000040,
+    CI_INTSTATUS_PAR_ERR    = 0x00000080,
+    CI_INTSTATUS_EOL        = 0x00000100,
+    CI_INTSTATUS_FEMPTY_0   = 0x00000200,
+    CI_INTSTATUS_FEMPTY_1   = 0x00000400,
+    CI_INTSTATUS_FEMPTY_2   = 0x00000800,
+    CI_INTSTATUS_RDAV_0     = 0x00001000,
+    CI_INTSTATUS_RDAV_1     = 0x00002000,
+    CI_INTSTATUS_RDAV_2     = 0x00004000, 
+    CI_INTSTATUS_FTO        = 0x00008000,
+    CI_INTSTATUS_ALL       = 0x0000FFFF
+} CI_INTERRUPT_STATUS;
+
+typedef enum {
+    CI_INT_IFO      = 0x00000001,
+    CI_INT_EOF      = 0x00000002,
+    CI_INT_SOF      = 0x00000004,
+    CI_INT_CDD      = 0x00000008,
+    CI_INT_CQD      = 0x00000010,
+    CI_INT_PAR_ERR  = 0x00000020,
+    CI_INT_EOL      = 0x00000040,
+    CI_INT_FEMPTY   = 0x00000080,
+    CI_INT_RDAV     = 0x00000100,
+    CI_INT_FTO      = 0x00000200,
+    CI_INT_ALL      = 0x000003FF
+} CI_INTERRUPT_MASK;
+#define CI_INT_MAX 10
+
+typedef enum CI_MODE {
+        CI_MODE_MP,             // Master-Parallel
+        CI_MODE_SP,             // Slave-Parallel
+        CI_MODE_MS,             // Master-Serial
+        CI_MODE_EP,             // Embedded-Parallel
+        CI_MODE_ES              // Embedded-Serial
+} CI_MODE;
+
+
+typedef enum  {
+        CI_FR_ALL = 0,          // Capture all incoming frames
+        CI_FR_1_2,              // Capture 1 out of every 2 frames
+        CI_FR_1_3,              // Capture 1 out of every 3 frames
+        CI_FR_1_4,
+        CI_FR_1_5,
+        CI_FR_1_6,
+        CI_FR_1_7,
+        CI_FR_1_8
+} CI_FRAME_CAPTURE_RATE;
+
+
+typedef enum  {
+        CI_FIFO_THL_32 = 0,
+        CI_FIFO_THL_64,
+        CI_FIFO_THL_96
+} CI_FIFO_THRESHOLD;
+
+typedef struct {
+    unsigned int BFW;
+    unsigned int BLW;
+} CI_MP_TIMING, CI_MS_TIMING;
+
+typedef struct {
+    unsigned int BLW;
+    unsigned int ELW; 
+    unsigned int HSW;
+    unsigned int BFPW;
+    unsigned int FSW; 
+    unsigned int BFW;
+    unsigned int EFW;
+    unsigned int VSW; 
+} CI_SP_TIMING;
+
+typedef enum {
+    CI_DATA_WIDTH4 = 0x0,
+    CI_DATA_WIDTH5 = 0x1,
+    CI_DATA_WIDTH8 = 0x2,  
+    CI_DATA_WIDTH9 = 0x3,  
+    CI_DATA_WIDTH10= 0x4   
+} CI_DATA_WIDTH;
+
+//-------------------------------------------------------------------------------------------------------
+//      Configuration APIs
+//-------------------------------------------------------------------------------------------------------
+
+void ci_set_frame_rate(CI_FRAME_CAPTURE_RATE frate);
+CI_FRAME_CAPTURE_RATE ci_get_frame_rate();
+void ci_set_image_format(CI_IMAGE_FORMAT input_format, CI_IMAGE_FORMAT output_format); 
+void ci_set_mode(CI_MODE mode, CI_DATA_WIDTH data_width);
+void ci_configure_mp(unsigned int PPL, unsigned int LPF, CI_MP_TIMING* timing);
+void ci_configure_sp(unsigned int PPL, unsigned int LPF, CI_SP_TIMING* timing);
+void ci_configure_ms(unsigned int PPL, unsigned int LPF, CI_MS_TIMING* timing);
+void ci_configure_ep(int parity_check);
+void ci_configure_es(int parity_check);
+void ci_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz);
+void ci_set_polarity(int pclk_sample_falling, int hsync_active_low, int vsync_active_low);
+void ci_set_fifo( unsigned int timeout, CI_FIFO_THRESHOLD threshold, int fifo1_enable, 
+                   int fifo2_enable);
+void ci_set_int_mask( unsigned int mask);
+void ci_clear_int_status( unsigned int status);
+void ci_set_reg_value( unsigned int reg_offset, unsigned int value);
+int ci_get_reg_value(unsigned int reg_offset);
+
+void ci_reset_fifo(void);
+unsigned int ci_get_int_mask(void);
+unsigned int ci_get_int_status(void);
+void ci_slave_capture_enable(void);
+void ci_slave_capture_disable(void);
+
+//-------------------------------------------------------------------------------------------------------
+//      Control APIs
+//-------------------------------------------------------------------------------------------------------
+int ci_init(void);
+void ci_deinit(void);
+void ci_enable( int dma_en);
+int  ci_disable(int quick);
+
+//debug
+void ci_dump(void);
+// IRQ
+void pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs);
+
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/e680_camera.c linux-2.6.16.5-exz/drivers/media/video/e680_camera.c
--- linux-2.6.16.5/drivers/media/video/e680_camera.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/e680_camera.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,144 @@
+
+ 
+/*================================================================================
+                                                                               
+                      Header Name: e680_camera.c
+
+General Description: Camera module  interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      04/15/2004                  Created   
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+
+#include <asm/pgtable.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include "camera.h"
+#include "adcm2700.h"
+
+#define MCLK_DEFT	        13             /* Default Master clock*/
+
+extern int i2c_adcm2700_init(void);
+extern int i2c_mt9v111_init(void);
+//////////////////////////////////////////////////////////////////////////////////////
+//adcm2700 functions
+//
+int camera_func_adcm2700_init(p_camera_context_t);
+int camera_func_adcm2700_deinit(p_camera_context_t);
+int camera_func_adcm2700_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+int camera_func_adcm2700_set_capture_format(p_camera_context_t);
+int camera_func_adcm2700_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_adcm2700_stop_capture(p_camera_context_t);
+
+int camera_func_adcm2700_pm_management(p_camera_context_t, int);
+
+//////////////////////////////////////////////////////////////////////////////////////
+//mt9v111 functions
+//
+int camera_func_mt9v111_init(p_camera_context_t);
+int camera_func_mt9v111_deinit(p_camera_context_t);
+int camera_func_mt9v111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+int camera_func_mt9v111_set_capture_format(p_camera_context_t);
+int camera_func_mt9v111_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_mt9v111_stop_capture(p_camera_context_t);
+
+int camera_func_mt9v111_pm_management(p_camera_context_t, int);
+
+
+extern int camera_func_init(p_camera_context_t cam_ctx);
+
+
+camera_function_t  camera_func = 
+{
+   init:                camera_func_init,
+};
+
+int camera_func_init(p_camera_context_t cam_ctx)
+{
+     // Configure CI according to hardware
+  	// master parallel with 8 data pins
+	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8); 
+
+	// enable pixel clock(sensor will provide pclock) and master clock = 26MHZ
+	ci_set_clock(cam_ctx->clk_reg_base, 1, 1, MCLK_DEFT);
+
+	// data sample on rising and h,vsync active high
+	ci_set_polarity(0, 0, 0);
+	
+	// fifo control
+	ci_set_fifo(0, CI_FIFO_THL_32, 1, 1); // quality
+
+	// Turn on M_CLK using xx MHz and wait for 150 ms.
+	ci_enable(1);
+	mdelay(150);
+    
+    cam_ctx->mclk = MCLK_DEFT;
+    dbg_print("detect...");    
+    if(i2c_adcm2700_init() == 0)
+    {
+      dbg_print("Agilent ADCM2700 camera module detected!");
+      cam_ctx->sensor_type = CAMERA_TYPE_ADCM_2700;
+      
+      camera_func.deinit             = camera_func_adcm2700_deinit;
+      camera_func.command          = camera_func_adcm2700_docommand;
+      camera_func.set_capture_format = camera_func_adcm2700_set_capture_format;
+      camera_func.start_capture      = camera_func_adcm2700_start_capture; 
+      camera_func.stop_capture       = camera_func_adcm2700_stop_capture;
+      camera_func.pm_management      = camera_func_adcm2700_pm_management;
+
+      return camera_func_adcm2700_init(cam_ctx);
+    }
+    else if(i2c_mt9v111_init() == 0)
+    {
+       dbg_print("Micro MT9V111 camera module detected!");
+       cam_ctx->sensor_type = CAMERA_TYPE_MT9V111;
+
+       camera_func.deinit             = camera_func_mt9v111_deinit;
+       camera_func.command          = camera_func_mt9v111_docommand;
+       camera_func.set_capture_format = camera_func_mt9v111_set_capture_format;
+       camera_func.start_capture      = camera_func_mt9v111_start_capture; 
+       camera_func.stop_capture       = camera_func_mt9v111_stop_capture;
+       camera_func.pm_management      = camera_func_mt9v111_pm_management;
+
+      return camera_func_mt9v111_init(cam_ctx);
+    }
+    return -1;
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/mt9m111.c linux-2.6.16.5-exz/drivers/media/video/mt9m111.c
--- linux-2.6.16.5/drivers/media/video/mt9m111.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/mt9m111.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,795 @@
+ 
+/*================================================================================
+                                                                               
+                      Header Name: mt9m111.c
+
+General Description: Camera module mt9m111 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Ma Zhiqiang          06/29/2004                 Change for auto-detect
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+
+#include <asm/pgtable.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include "camera.h"
+#include "mt9m111.h"
+#include "mt9m111_hw.h"
+
+//#define LOG_TIME_STAMP   //If defined, the time stamp log will be printed out
+//#define MT9M111_LOG      //If defined, the mt9m111_mt9m111_dbg_print logs will be printed out
+//#define MT9M111_ECHO_CMD //If defined, the "echo {address, value} > cam" commands will be enabled.
+
+#ifdef  MT9M111_LOG
+#define mt9m111_dbg_print(fmt, args...) dbg_print(fmt, ##args)
+#else
+#define mt9m111_dbg_print(fmt, args...) ;
+#endif
+
+#define MCLK_DEFT           (24)         /* Default Master clock*/
+#define MSCWR1_CAMERA_ON    (0x1 << 15)     /* Camera Interface Power Control */
+#define MSCWR1_CAMERA_SEL   (0x1 << 14)     /* Camera Interface Mux control */
+
+#define MAX_WIDTH     1280
+#define MAX_HEIGHT    1024
+
+#define MIN_WIDTH     40
+#define MIN_HEIGHT    30
+
+#define VIEW_FINDER_WIDTH_DEFT     320
+#define VIEW_FINDER_HEIGHT_DEFT    240
+
+#define FRAMERATE_DEFT    15
+#define BUF_SIZE_DEFT     ((PAGE_ALIGN(MAX_WIDTH * MAX_HEIGHT) + (PAGE_ALIGN(MAX_WIDTH*MAX_HEIGHT/2)*2)))
+
+extern int mt9m111_read(u16 addr, u16 *pvalue);
+extern int mt9m111_write(u16 addr, u16 value);
+extern int i2c_mt9m111_cleanup(void);
+extern int i2c_mt9m111_init(void);
+
+extern void stop_dma_transfer(p_camera_context_t camera_context);
+extern int camera_ring_buf_init(p_camera_context_t camera_context);
+extern void camera_gpio_init(void);
+extern void camera_gpio_deinit(void);
+extern void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id);
+
+/***********************************************************************
+ *
+ * MT9M111 Functions
+ *
+ ***********************************************************************/
+int camera_func_mt9m111_init(p_camera_context_t);
+int camera_func_mt9m111_deinit(p_camera_context_t);
+int camera_func_mt9m111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+int camera_func_mt9m111_set_capture_format(p_camera_context_t);
+int camera_func_mt9m111_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_mt9m111_stop_capture(p_camera_context_t);
+int camera_func_mt9m111_pm_management(p_camera_context_t, int);
+
+
+camera_function_t  mt9m111_func = 
+{
+    init:                camera_func_mt9m111_init,
+    deinit:              camera_func_mt9m111_deinit,
+    command:             camera_func_mt9m111_docommand,
+    set_capture_format:  camera_func_mt9m111_set_capture_format,
+    start_capture:       camera_func_mt9m111_start_capture,
+    stop_capture:        camera_func_mt9m111_stop_capture,
+    pm_management:       camera_func_mt9m111_pm_management
+};
+
+int camera_func_mt9m111_init(  p_camera_context_t cam_ctx )
+{
+    u16 device_id = 0 ;
+
+    // init context status
+    cam_ctx->dma_channels[0] = 0xFF;
+    cam_ctx->dma_channels[1] = 0xFF;
+    cam_ctx->dma_channels[2] = 0xFF;
+    
+    cam_ctx->capture_width  = VIEW_FINDER_WIDTH_DEFT;
+    cam_ctx->capture_height = VIEW_FINDER_HEIGHT_DEFT;
+    
+    cam_ctx->capture_input_format  = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    
+    cam_ctx->frame_rate = cam_ctx->fps = FRAMERATE_DEFT;
+    
+    cam_ctx->mini_fps = FRAMERATE_DEFT;
+    
+    cam_ctx->mclk = MCLK_DEFT;
+    
+    cam_ctx->buf_size     = BUF_SIZE_DEFT;
+    cam_ctx->dma_descriptors_size = (cam_ctx->buf_size/PAGE_SIZE + 10);
+    strcpy (cam_ctx->vc.name, "Micron MT9M111");
+    cam_ctx->vc.maxwidth  = MAX_WIDTH;
+    cam_ctx->vc.maxheight = MAX_HEIGHT;
+    cam_ctx->vc.minwidth  = MIN_WIDTH; 
+    cam_ctx->vc.minheight = MIN_HEIGHT;
+
+    camera_gpio_init();
+    ci_init();
+ 
+    // Configure CI according to MT9M111's hardware
+    // master parallel with 8 data pins
+    ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8); 
+
+    // enable pixel clock(sensor will provide pclock) 
+    ci_set_clock(cam_ctx->clk_reg_base, 1, 1, cam_ctx->mclk);
+
+    // data sample on rising and h,vsync active high
+    ci_set_polarity(1, 0, 0);
+    
+    // fifo control
+    ci_set_fifo(0, CI_FIFO_THL_32, 1, 1); // quality
+
+    // Turn on M_CLK and wait for 150 ms.
+    ci_enable(1);
+    //mdelay(150);
+
+    i2c_mt9m111_init();
+
+    // read out device id
+    mt9m111_get_device_id(&device_id);
+    if(device_id != 0x1419 && device_id != 0x1429 && device_id != 0x143A) 
+    {
+        //ci_disable(1);
+        //camera_gpio_deinit();
+        return -1;
+    }
+    else
+    {
+        mt9m111_dbg_print("Micron MT9M111 camera module detected!");
+    }
+
+
+    /* To resolve the vertical line in view finder issue (LIBff11930)
+     * The solution is:
+     * AP Kernel camera driver: set TCMM_EN to low when camera is running and TCMM_EN to high when camera stops.
+     * BP Software: if TCMM_EN is low, BP do not shut off 26M clock ,but BP can sleep itself.*/ 
+
+    set_GPIO_mode(99|GPIO_OUT);//It's GPIO99 for the "TCMM_EN"
+    GPCR(99) = GPIO_bit(99);
+    
+    cam_ctx->sensor_type = CAMERA_TYPE_MT9M111;
+
+    mt9m111_default_settings();
+    
+    mt9m111_dbg_print("mt9m111 init success!");
+
+#ifdef MT9M111_ECHO_CMD
+    /*for test commmand throught terminal*/
+    struct proc_dir_entry *pw;
+    static ssize_t test_command_write(struct file *file, const char *buf, size_t count, loff_t *pos);
+
+    static struct file_operations test_command_funcs = 
+    {
+        read:NULL,
+        write:test_command_write,
+    };
+
+    if ((pw = create_proc_entry ("cam", 0666, 0)) != NULL)
+    {
+        pw->proc_fops = &test_command_funcs;
+    }
+#endif
+    return 0;
+}
+    
+static void mt9m111_gpio_deinit(void)
+{
+    GPSR(CIF_PD) = GPIO_bit(CIF_PD);
+}
+
+int camera_func_mt9m111_deinit(  p_camera_context_t camera_context )
+{
+    mt9m111_write(0x1B3, 0);
+    mdelay(5);
+
+    i2c_mt9m111_cleanup();
+
+    /* disable CI */
+    ci_disable(1);
+	
+    mt9m111_gpio_deinit();
+
+#ifdef MT9M111_ECHO_CMD
+    /*for test commmand throught terminal*/
+    remove_proc_entry ("cam", NULL);
+#endif
+
+    /* To resolve the vertical line in view finder issue (LIBff11930)
+     * The solution is:
+     * AP Kernel camera driver: set TCMM_EN to low when camera is running and TCMM_EN to high when camera stops.
+     * BP Software: if TCMM_EN is low, BP do not shut off 26M clock ,but BP can sleep itself.*/ 
+
+    set_GPIO_mode(99|GPIO_OUT);//It's GPIO99 for the "TCMM_EN"
+    GPSR(99) = GPIO_bit(99);
+
+    return 0;
+}
+
+int camera_func_mt9m111_set_capture_format(  p_camera_context_t camera_context )
+{
+    micron_window_size wsize;
+    u16 micron_format;
+    mt9m111_dbg_print("");
+
+    // set sensor input/output window
+    wsize.width = camera_context->capture_width;
+    wsize.height = camera_context->capture_height;
+    mt9m111_output_size(&wsize);
+
+    // set sensor format
+    switch(camera_context->capture_input_format) {
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+        micron_format = O_FORMAT_422_YCbYCr;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB565:
+        micron_format = O_FORMAT_565_RGB;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB555:
+        micron_format = O_FORMAT_555_RGB;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB444:
+        micron_format = O_FORMAT_444_RGB;
+        break;
+    default:
+        micron_format = O_FORMAT_422_YCbYCr;
+        break;
+    }
+    mt9m111_output_format(micron_format);
+
+    return 0;
+}
+
+int camera_func_mt9m111_start_capture(  p_camera_context_t cam_ctx, unsigned int frames )
+{
+    int waitingFrame = 0;
+
+#ifdef LOG_TIME_STAMP
+    struct timeval tv0,tv1,tv2,tv3,tv4;
+    do_gettimeofday(&tv0);
+#endif
+
+    ci_reset_fifo();
+    ci_clear_int_status(0xFFFFFFFF);
+
+    // frames=0 means video mode capture    
+    if (frames == 0) 
+    {
+        mt9m111_dbg_print("video capture!"); 
+        mt9m111_viewfinder_on();
+    }
+    else 
+    {
+        mt9m111_dbg_print("still capture");
+        mt9m111_snapshot_trigger();
+    }
+
+#ifdef LOG_TIME_STAMP
+    do_gettimeofday(&tv1);
+#endif
+
+    ci_disable(1);
+    ci_enable(1);
+
+#ifdef LOG_TIME_STAMP
+    do_gettimeofday(&tv2);
+#endif
+
+    if(frames == 1) //Wait 1 frames to begin capture photo
+    {
+        waitingFrame = 1;
+    } 
+    else
+    { 
+        waitingFrame = 1;
+    }
+
+    while(waitingFrame--)
+    {
+        CISR |= (1<<4);
+        while(!(CISR&(1<<4))); //Wait a SOF then begin start DMA
+    }
+
+#ifdef LOG_TIME_STAMP
+    do_gettimeofday(&tv3);
+#endif
+
+    ci_disable(1);
+    ci_enable(1);
+    ci_reset_fifo();
+    start_dma_transfer(cam_ctx, 0);
+     
+#ifdef LOG_TIME_STAMP
+    do_gettimeofday(&tv4);
+
+    printk("mt9m111 capture: Begin time is sec: %d , msec: %d\n", tv0.tv_sec, tv0.tv_usec/1000);
+    printk("mt9m111 capture: End time is sec: %d , msec: %d\n", tv4.tv_sec, tv4.tv_usec/1000);
+    if(frames)
+        printk("mt9m111 capture: Total time(photo) is %d ms\n\n", (tv4.tv_sec-tv0.tv_sec)*1000+ (tv4.tv_usec-tv0.tv_usec)/1000);
+    else
+        printk("mt9m111 capture: Total time(preview) is %d ms\n\n", (tv4.tv_sec-tv0.tv_sec)*1000+ (tv4.tv_usec-tv0.tv_usec)/1000);
+    printk("mt9m111 capture: Write reg time is %d ms\n\n", (tv1.tv_sec-tv0.tv_sec)*1000+ (tv1.tv_usec-tv0.tv_usec)/1000);
+    printk("mt9m111 capture: Reset ci time is %d ms\n\n", (tv2.tv_sec-tv1.tv_sec)*1000+ (tv2.tv_usec-tv1.tv_usec)/1000);
+    printk("mt9m111 capture: Wait sof time is %d ms\n\n", (tv3.tv_sec-tv2.tv_sec)*1000+ (tv3.tv_usec-tv2.tv_usec)/1000);
+    printk("mt9m111 capture: Left time is %d ms\n\n", (tv4.tv_sec-tv3.tv_sec)*1000+ (tv4.tv_usec-tv3.tv_usec)/1000);
+#endif
+    return 0;
+}
+
+int camera_func_mt9m111_stop_capture(  p_camera_context_t camera_context )
+{
+    mt9m111_viewfinder_off();
+    stop_dma_transfer(camera_context);
+
+    /* disable CI */
+    //ci_disable(1);
+
+    return 0;
+}
+
+static int camera_mt9m111_restore_settings(p_camera_context_t cam_ctx)
+{
+    micron_window_size size;
+    
+    size.width  = cam_ctx->sensor_width;
+    size.height = cam_ctx->sensor_height;
+    mt9m111_input_size(&size);
+      
+    size.width  = cam_ctx->capture_width;
+    size.height = cam_ctx->capture_height;
+    mt9m111_output_size(&size);
+      
+    mt9m111_set_bright(cam_ctx->capture_bright);
+   
+    mt9m111_set_fps(cam_ctx->fps, cam_ctx->mini_fps);
+    mt9m111_set_light(cam_ctx->capture_light);
+    mt9m111_set_style(cam_ctx->capture_style);
+    //mt9m111_set_contrast(cam_ctx->capture_contrast);
+    mt9m111_set_autoexposure_zone(cam_ctx->mini_fps);
+    mt9m111_set_flicker(cam_ctx->flicker_freq);
+  
+    return 0;
+}
+
+int camera_func_mt9m111_pm_management(p_camera_context_t cam_ctx, int suspend)
+{
+    static int resume_dma = 0;
+    if(suspend)
+    {
+        if(cam_ctx != NULL )
+        {
+            if(cam_ctx->dma_started) 
+            {
+                mt9m111_dbg_print("camera running, suspended");
+                stop_dma_transfer(cam_ctx);
+                resume_dma = 1;
+            }
+        }
+
+        disable_irq(IRQ_CAMERA);
+        CKEN &= ~CKEN24_CAMERA;
+    }
+    else
+    {
+        CKEN |= CKEN24_CAMERA;
+        enable_irq(IRQ_CAMERA);
+
+        if(cam_ctx != NULL)
+        {  
+            mt9m111_dbg_print("camera running, resumed");
+            camera_init(cam_ctx);
+
+            camera_mt9m111_restore_settings(cam_ctx);
+               
+            if(resume_dma == 1)
+            {
+                camera_start_video_capture(cam_ctx, 0);
+                resume_dma = 0;
+            }
+        }
+    }
+    return 0;
+}
+
+static int pxa_camera_WCAM_VIDIOCGCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    int reg_value, offset;
+    mt9m111_dbg_print("WCAM_VIDIOCGCAMREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return -EFAULT;
+    }
+    reg_value = (int)mt9m111_reg_read((u16)offset);
+
+    if(copy_to_user(param, &reg_value, sizeof(int))) 
+    {
+        return -EFAULT;
+    } 
+
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCSCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    struct reg_set_s{int val1; int val2;} reg_s;
+    mt9m111_dbg_print("WCAM_VIDIOCSCAMREG");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    mt9m111_reg_write((u16)reg_s.val1, (u16)reg_s.val2);
+    return 0;
+} 
+ 
+static int pxa_cam_WCAM_VIDIOCSFPS(p_camera_context_t cam_ctx, void * param)
+{
+    struct {int fps, minfps;} cam_fps;
+    mt9m111_dbg_print("WCAM_VIDIOCSFPS");
+    if(copy_from_user(&cam_fps, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    cam_ctx->fps = cam_fps.fps;
+    cam_ctx->mini_fps = cam_fps.minfps;
+    mt9m111_set_fps(cam_fps.fps, cam_fps.minfps);
+    return 0;
+}
+
+
+/*Set  sensor size*/  
+static int pxa_cam_WCAM_VIDIOCSSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+  micron_window_size size;
+  mt9m111_dbg_print("WCAM_VIDIOCSSSIZE");
+  
+  if(copy_from_user(&size, param, sizeof(micron_window_size))) 
+  {
+        return  -EFAULT;
+  }
+  
+  size.width = (size.width+3)/4 * 4;
+  size.height = (size.height+3)/4 * 4;
+  cam_ctx->sensor_width = size.width;
+  cam_ctx->sensor_height = size.height;
+  mt9m111_input_size(&size);
+  return 0;
+}
+
+//set  output size
+static int pxa_cam_WCAM_VIDIOCSOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+   micron_window_size size;
+   CI_MP_TIMING     timing;
+   mt9m111_dbg_print("WCAM_VIDIOCSOSIZE");
+  
+   if(copy_from_user(&size, param, sizeof(micron_window_size))) 
+   {
+        return  -EFAULT;
+   }
+
+   //make it in an even number
+   size.width = (size.width+1)/2 * 2;
+   size.height = (size.height+1)/2 * 2;
+   mt9m111_output_size(&size);
+   
+   cam_ctx->capture_width  = size.width;
+   cam_ctx->capture_height = size.height;
+   timing.BFW = timing.BLW = 0;
+   
+   ci_configure_mp(cam_ctx->capture_width-1, cam_ctx->capture_height-1, &timing);
+   camera_ring_buf_init(cam_ctx);
+   
+   return 0;
+}
+    
+/*set picture style*/  
+static int pxa_cam_WCAM_VIDIOCSSTYLE(p_camera_context_t cam_ctx, void * param)
+{
+  mt9m111_dbg_print("WCAM_VIDIOCSSTYLE");
+  cam_ctx->capture_style = (V4l_PIC_STYLE)param;
+  
+  return mt9m111_set_style(cam_ctx->capture_style);
+}
+
+/*set picture light*/     
+static int pxa_cam_WCAM_VIDIOCSLIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   mt9m111_dbg_print("WCAM_VIDIOCSLIGHT");
+   cam_ctx->capture_light = (V4l_PIC_WB)param;
+
+   return  mt9m111_set_light((V4l_PIC_WB)param);
+}
+    
+/*set picture brightness*/
+static int pxa_cam_WCAM_VIDIOCSBRIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   mt9m111_dbg_print("WCAM_VIDIOCSBRIGHT");
+   cam_ctx->capture_bright = (int)param;
+
+   return  mt9m111_set_bright((int)param);
+}
+
+/*set picture contrast*/
+/*static int pxa_cam_WCAM_VIDIOCSCONTRAST(p_camera_context_t cam_ctx, void * param)
+{
+   mt9m111_dbg_print("WCAM_VIDIOCSCONTRAST");
+   cam_ctx->capture_contrast = ((int)param-50)/12;
+
+   return  mt9m111_set_contrast(cam_ctx->capture_contrast);
+}*/
+
+/*set flicker frequency*/
+static int pxa_cam_WCAM_VIDIOCSFLICKER(p_camera_context_t cam_ctx, void * param)
+{
+   mt9m111_dbg_print("WCAM_VIDIOCSFLICKER");
+   cam_ctx->flicker_freq = (int)param;
+
+   return  mt9m111_set_flicker(cam_ctx->flicker_freq);
+}
+
+
+/*set night mode*/
+static int pxa_cam_WCAM_VIDIOCSNIGHTMODE(p_camera_context_t cam_ctx, void * param)
+{
+    struct {u32 mode, maxexpotime; } cam_mode;
+    u32 maxexpotime;
+    
+    if (copy_from_user(&cam_mode, param, sizeof(cam_mode))) 
+    {
+        return -EFAULT;
+    }
+
+    maxexpotime = cam_mode.maxexpotime;
+    if(maxexpotime == 0)
+    {
+        return -EFAULT;
+    }
+
+    switch (cam_mode.mode)
+    {
+        case V4l_NM_NIGHT:
+        case V4l_NM_ACTION:
+        case V4l_NM_AUTO:
+            cam_ctx->mini_fps = (1000000+maxexpotime/2)/maxexpotime;
+            mt9m111_set_autoexposure_zone(cam_ctx->mini_fps);
+            break;
+        default:
+            return -EFAULT;
+    }
+
+    return 0;
+}
+
+int camera_func_mt9m111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+   switch(cmd)
+   {
+     /*read mt9m111 registers*/
+    case WCAM_VIDIOCGCAMREG:
+         return pxa_camera_WCAM_VIDIOCGCAMREG(cam_ctx, param);
+
+    /*write mt9m111 registers*/
+    case WCAM_VIDIOCSCAMREG:
+          return pxa_camera_WCAM_VIDIOCSCAMREG(cam_ctx, param);
+        
+    /*set sensor size */  
+    case WCAM_VIDIOCSSSIZE:
+         return pxa_cam_WCAM_VIDIOCSSSIZE(cam_ctx, param);
+
+    /*set output size*/
+    case WCAM_VIDIOCSOSIZE:
+         return pxa_cam_WCAM_VIDIOCSOSIZE(cam_ctx, param);
+         
+    /*set video mode fps*/
+    case WCAM_VIDIOCSFPS:
+         return pxa_cam_WCAM_VIDIOCSFPS(cam_ctx, param);
+            
+    /*set picture style*/  
+    case WCAM_VIDIOCSSTYLE:
+         return pxa_cam_WCAM_VIDIOCSSTYLE(cam_ctx, param);
+         
+    /*set picture light*/     
+    case WCAM_VIDIOCSLIGHT:
+         return pxa_cam_WCAM_VIDIOCSLIGHT(cam_ctx, param);
+    
+    /*set picture brightness*/
+    case WCAM_VIDIOCSBRIGHT:
+         return pxa_cam_WCAM_VIDIOCSBRIGHT(cam_ctx, param);
+    
+    /*set picture contrast*/
+    //case WCAM_VIDIOCSCONTRAST:
+    //     return pxa_cam_WCAM_VIDIOCSCONTRAST(cam_ctx, param);
+
+    /*set flicker frequency*/
+    case WCAM_VIDIOCSFLICKER:
+         return pxa_cam_WCAM_VIDIOCSFLICKER(cam_ctx, param);
+
+    case WCAM_VIDIOCSNIGHTMODE:
+         return pxa_cam_WCAM_VIDIOCSNIGHTMODE(cam_ctx, param);
+
+    default:
+         {
+           mt9m111_dbg_print("Error cmd=0x%x", cmd);
+           return -1;
+         }
+    }
+    return 0;
+ 
+}
+
+#ifdef MT9M111_ECHO_CMD
+/***********************************************************************
+ *
+ * MT9M111 test command throught terminal
+ *
+ ***********************************************************************/
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX_WRITE_LEN 12
+
+extern int mt9m111_write(u16 addr, u16 value);
+
+static ssize_t test_command_write (struct file *file, const char *buf, size_t count, loff_t * pos)
+{
+    char feedback[2*MAX_WRITE_LEN + 1] ={0};
+    char feedback1[2*MAX_WRITE_LEN + 1] = {0};
+    size_t n = count;
+    size_t l;
+    char c;
+    int i,x,y,t;
+
+    u16 reg, value;
+
+    MOD_INC_USE_COUNT;
+
+    if (n > 0)
+    {
+        l = MIN (n, MAX_WRITE_LEN);
+        if (copy_from_user (feedback, buf, l))
+        {
+            count = -1;
+        }
+        else
+        {
+            if (l > 0 && feedback[l - 1] == '\n')
+            {
+                l -= 1;
+            }
+            feedback[l] = 0;
+            n -= l;
+
+            while (n > 0)
+            {
+                if (copy_from_user (&c, buf + (count - n), 1))
+                {
+                    count = -1;
+                    break;
+                }
+                n -= 1;
+            }
+        }
+    }
+
+    i = x = y = 1;
+  
+    if (count > 0 && feedback[0] == '{')
+    {
+        while(feedback[i] != '}' && i<=MAX_WRITE_LEN*2)
+        {
+            c= feedback[i];
+            i++; 
+            if(c>='a' && c<='f')
+            {
+                c -= 0x20;
+            }
+            if(!((c>='0'&& c<='9')||(c>='A'&&c<='F')||c==','))
+            {
+                continue;
+            }
+            feedback1[x++] = c;
+        }
+
+        feedback1[x]='}';
+        feedback1[0]='{';
+    
+        for(i=1;i<=x;i++)
+        {
+            if(feedback1[i] == ',')
+            {
+                y=3;
+                for(t=i-1;t>=1;t--)
+                {
+                    if(y==0)
+                        break;
+                    feedback[y--]=feedback1[t];
+                }
+                if(y>=1)
+                {
+                    for(t=y;t>=1;t--)
+                    {
+                        feedback[t] = '0';
+                    }
+                }
+            }
+        
+            if(feedback1[i] == '}')
+            {
+                y=8;
+                for(t=i-1;feedback1[t]!=','&&t>=1;t--)
+                {
+                    if(y==4)
+                        break;
+                    feedback[y--]=feedback1[t];
+                }
+                if(y>=5)
+                {
+                    for(t=y;t>=5;t--)
+                    {
+                        feedback[t] = '0';
+                    }
+                }
+            }
+        }
+
+        reg = 16 * 16 * (feedback[1]>='A'?feedback[1]-'A'+10:feedback[1]-0x30) + 16 *  (feedback[2]>='A'?feedback[2]-'A'+10:feedback[2]-0x30) + (feedback[3]>='A'?feedback[3]-'A'+10:feedback[3]-0x30) ;
+        value = 16 * 16 * 16 *  (feedback[5]>='A'?feedback[5]-'A'+10:feedback[5]-0x30) + 16 *16*  (feedback[6]>='A'?feedback[6]-'A'+10:feedback[6]-0x30) + 16 *  (feedback[7]>='A'?feedback[7]-'A'+10:feedback[7]-0x30) + (feedback[8]>='A'?feedback[8]-'A'+10:feedback[8]-0x30) ;
+
+        if(reg == 0xFFF && value == 0xFFFF)
+        {
+            mt9m111_dump_register(0,0x2ff,NULL);
+        }
+        else if(reg == 0xFFF || reg == 0xFF)
+        {
+             mt9m111_reg_read(value);
+        }
+        else
+        {
+            mt9m111_write(reg, value); 
+        }
+    }
+
+    MOD_DEC_USE_COUNT;
+
+    return (count);
+}
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/mt9m111.h linux-2.6.16.5-exz/drivers/media/video/mt9m111.h
--- linux-2.6.16.5/drivers/media/video/mt9m111.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/mt9m111.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,44 @@
+
+/*================================================================================
+                                                                               
+                      Header Name: mt9m111.h
+
+General Description: Camera module mt9m111  interface head file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Ma Zhiqiang         6/30/2004                    Change for auto-detect
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _MT9M111_H_
+#define _MT9M111_H_
+
+#include "camera.h"
+
+//////////////////////////////////////////////////////////////////////////////////////
+//
+//          Prototypes
+//
+//////////////////////////////////////////////////////////////////////////////////////
+
+int camera_func_mt9m111_init(p_camera_context_t);
+int camera_func_mt9m111_deinit(p_camera_context_t);
+int camera_func_mt9m111_set_capture_format(p_camera_context_t);
+int camera_func_mt9m111_start_capture(p_camera_context_t, unsigned int frames);
+int camera_func_mt9m111_stop_capture(p_camera_context_t);
+int camera_func_mt9m111_pm_management(p_camera_context_t cam_ctx, int suspend);
+int camera_func_mt9m111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param);
+
+#endif /* _MT9M111_H_ */
+
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/mt9m111_hw.c linux-2.6.16.5-exz/drivers/media/video/mt9m111_hw.c
--- linux-2.6.16.5/drivers/media/video/mt9m111_hw.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/mt9m111_hw.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,994 @@
+/*================================================================================
+                                                                               
+                      Header Name: mt9m111_hw.c
+
+General Description: Camera module mt9m111 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Ma Zhiqiang         6/30/2004                    Change for auto-detect
+Ma Zhiqiang         9/03/2004                    Add the update from Peter 
+                                                 (worked out with Micron/Flextronix and LV CTO team)
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/wrapper.h>
+#include <linux/delay.h>
+#include <linux/i2c.h> 
+
+#include "mt9m111_hw.h"
+#include "camera.h"
+
+//#define MT9M111_LOG
+
+#ifdef  MT9M111_LOG
+#define mt9m111_dbg_print(fmt, args...) dbg_print(fmt, ##args)
+#else
+#define mt9m111_dbg_print(fmt, args...) ;
+#endif
+
+extern int mt9m111_read(u16 addr, u16 *pvalue);
+extern int mt9m111_write(u16 addr, u16 value);
+ 
+static u16 outWidth = 320;
+static u16 outHeight = 240;
+static u16 sensorWidth = 1280;
+static u16 sensorHeight = 1024;
+
+static u16 preferredFlickerMask = 0;
+static int inSkipMode = 1;
+static int didSnapPhoto = 0;
+static u16 minFPS = -1;
+static u16 maxFPS = -1;
+
+static u8 isHalfSensorSize = 0;
+
+// light tables
+
+#if 0
+// table generated by Micron's default calibration
+
+// auto
+static u16 autoLight[] =
+{  0x00AE, 0x2923, 0x04E4, 0x00B7, 0x009F, 0x0068, 0x00C5, 0x0088,
+   0x0027, 0x007A, 0x0088, 0x00AF, 0x00C9, 0x0014, 0x0005, 0x0033,
+   0x0031, 0x0004, 0x0052, 0x0057, 0x0091, 0x005B, 0x6345, 0x3E26,
+   0x0002 };
+
+// direct sun
+static u16 directSun[] =         
+{ 0x00AE, 0x2923, 0x0524, 0x00BF, 0x009B, 0x004A, 0x00AC, 0x008A,
+  0x0051, 0x004F, 0x007E, 0x0082, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4458, 0x0000,
+  0x0000 };
+
+// incandescent
+static u16 incandescentLight[] =
+{ 0x00A6, 0x2923, 0x04E4, 0x00A8, 0x0090, 0x007A, 0x00DC, 0x0083,
+  0x0004, 0x00A7, 0x00CC, 0x00DB, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8232, 0x0000,
+  0x0000 };
+
+// fluorescent
+static u16 tl84Light[] =
+{ 0x00A6, 0x2737, 0x04E4, 0x00AF, 0x006F, 0x003C, 0x008B, 0x0097,
+  0x000F, 0x00D2, 0x00B5, 0x00DF, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8630, 0x0000,
+  0x0000 };
+
+#endif
+
+#if 1
+// no lens cover ccmat -- Satish likes this one
+
+/*
+static u16 autoLight[] =
+{ 0x00AE, 0x271B, 0x02A4, 0x00E9, 0x0082, 0x006D, 0x007A, 0x009C,
+  0x0047, 0x0095, 0x0065, 0x006C, 0x00C9, 0x0010, 0x0007, 0x0027,
+  0x001A, 0x0001, 0x004C, 0x0062, 0x0059, 0x0037, 0x6345, 0x3E26,
+  0x0002 };
+*/
+// 
+static u16 autoLight[] =
+{ 0x00AE, 0x2923, 0x04E4, 0x00C8, 0x00DF, 0x0080, 0x00C2, 0x0084,
+  0x001F, 0x006B, 0x007F, 0x00AB, 0x00C9, 0x001F, 0x0002, 0x002F,
+  0x0022, 0x000D, 0x005E, 0x002E, 0x007B, 0x0048, 0x604C, 0x3C28,
+  0x0002 };
+
+static u16 incandescentLight[] =
+{ 0x00AE, 0x2723, 0x02A4, 0x00D8, 0x00EB, 0x0076, 0x0084, 0x0096,
+  0x001E, 0x00C5, 0x008D, 0x0085, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8232, 0x0000,
+  0x0000 };
+
+static u16 tl84Light[] =
+{ 0x00AE, 0x2723, 0x02A4, 0x00EB, 0x00D6, 0x002C, 0x00A8, 0x00B0,
+  0x000E, 0x00F8, 0x0086, 0x008B, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8630, 0x0000,
+  0x0000 };
+
+static u16 d65Light[] =
+{ 0x00AE, 0x291B, 0x0524, 0x00EF, 0x0082, 0x0054, 0x00D9, 0x009D,
+  0x006E, 0x0064, 0x00E0, 0x00A1, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4458, 0x0000,
+  0x0000 };
+
+#endif
+
+#if 0
+
+// lens cover ccmat -- Satish doesn't like this one
+
+static u16 autoLight[] =
+{ 0x00AE, 0x271A, 0x02A4, 0x007E, 0x0081, 0x003A, 0x0082, 0x00BB,
+  0x00AD, 0x009B, 0x007D, 0x0079, 0x0099, 0x000C, 0x0025, 0x0011,
+  0x0024, 0x0009, 0x001E, 0x007F, 0x0063, 0x003F, 0x6344, 0x3A28,
+  0x0002 };
+
+static u16 incandescentLight[] =
+{ 0x00AE, 0x2723, 0x02A4, 0x00EF, 0x00DE, 0x0032, 0x0094, 0x00BF,
+  0x009E, 0x00DA, 0x00AF, 0x0098, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8030, 0x0000,
+  0x0000 };
+
+static u16 tl84Light[] =
+{ 0x00AE, 0x2723, 0x02A4, 0x00E9, 0x00EC, 0x0045, 0x0093, 0x0097,
+  0x0001, 0x00DA, 0x0092, 0x008A, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8630, 0x0000,
+  0x0000 };
+
+static u16 d65Light[] =
+{ 0x00AE, 0x291A, 0x04E4, 0x0082, 0x0092, 0x0042, 0x00DD, 0x00B4,
+  0x00B9, 0x005A, 0x0096, 0x00B0, 0x0000, 0x0000, 0x0000, 0x0000,
+  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4658, 0x0000,
+  0x0000 };
+
+#endif
+
+
+/*****************************************************************************
+*
+*****************************************************************************/
+static void mt9m111_reset(void)
+{
+    minFPS = -1;
+    maxFPS = -1;
+    inSkipMode = 1;
+    didSnapPhoto = 0;
+    isHalfSensorSize = 0;
+}
+
+/*****************************************************************************
+*									     *
+*        I2C Management		 					     *
+*									     *
+*****************************************************************************/
+u16 mt9m111_reg_read(u16 reg_addr)
+{
+    u16 value=0;
+    mt9m111_read(reg_addr, &value);
+    return value;
+}
+
+void mt9m111_reg_write(u16 reg_addr, u16 reg_value)
+{
+    mt9m111_write(reg_addr, reg_value);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+//   
+//  Programming Guide : Configuration Methods 
+//
+/////////////////////////////////////////////////////////////////////////////////////
+
+int mt9m111_get_device_id(u16 *id)
+{
+    /*Device ID is in register 0x0 */
+    *id = mt9m111_reg_read(0x0);
+    mt9m111_dbg_print("mt9m111 device ID is 0x%x", *id);       
+
+    return MICRON_ERR_NONE;
+}
+
+static int mt9m111_update_size(int context)
+{
+    mt9m111_dbg_print("mt9m111_update_size, sensor=%dx%d, out=%dx%d", sensorWidth, sensorHeight, outWidth, outHeight);
+
+    /* set the sensor size */ 
+    if(context == 0)
+    {
+        //context A
+        mt9m111_write(0x1A6, sensorWidth);
+        mt9m111_write(0x1A9, sensorHeight);
+    }
+    else
+    {
+        //context B
+        mt9m111_write(0x1A0, sensorWidth);
+        mt9m111_write(0x1A3, sensorHeight);
+    }
+    /* set output size */
+    if(outWidth > sensorWidth)
+    {
+        outWidth = sensorWidth;
+    }
+    if(outHeight > sensorHeight)
+    {
+        outHeight = sensorHeight;
+    }
+
+    if(context == 0)
+    {
+        //context A
+        mt9m111_write(0x1A7, outWidth);
+        mt9m111_write(0x1AA, outHeight);
+    }
+    else
+    {
+        //context B
+        mt9m111_write(0x1A1, outWidth);
+        mt9m111_write(0x1A4, outHeight);
+    }
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_viewfinder_on()
+{
+    mt9m111_dbg_print("mt9m111_viewfinder_on, sensor=%dx%d, out=%dx%d", sensorWidth, sensorHeight, outWidth, outHeight);
+
+    if((outWidth*2 > sensorWidth) || (outHeight*2 > sensorHeight))
+    {
+        mt9m111_dbg_print("mt9m111_viewfinder_on: making sure skip mode is off");
+
+	// make sure skip mode is off
+
+	    if (inSkipMode || didSnapPhoto)
+	    {
+            mt9m111_dbg_print("mt9m111_viewfinder_on: skip mode is on -- turning in off");
+	    //
+	    // set to full power, turn off subsampling
+	    //     switch to context B for read mode, full frame, and max line delay
+ 	    //
+
+    	    mt9m111_write(0x2D2, 0x0041);	// turn off subsampling and turn on full power mode
+    	    mt9m111_write(0x2CC, 0x4);		// Context Ctl Program Select -- use default program
+    	    u16 v = mt9m111_reg_read(0x2CB);	// read Context Ctl Program Advance
+    	    mt9m111_write(0x2CB, v|1);		// advance program
+
+    	    didSnapPhoto = 0;
+	        inSkipMode = 0;
+
+            //
+            // after program advance, we need to poll Global Context Ctl to wait for 
+            // sensor read mode context has switched to context B
+            //
+
+	        int count = 0;
+	        while ((mt9m111_reg_read(0x00C8) != 0x000B) && (++count < 20))
+	        {
+	            mdelay(10);
+            }
+        }
+
+    	mt9m111_update_size(0);
+    }
+    else
+    {
+    	mt9m111_update_size(0);
+
+	// make sure skip mode is on
+
+        mt9m111_dbg_print("mt9m111_viewfinder_on: making sure skip mode is on");
+
+	    if (!inSkipMode || didSnapPhoto)
+	    { 
+            mt9m111_dbg_print("mt9m111_viewfinder_on: skip mode is off -- turning in on");
+
+	    //
+	    // set to low power, turn on subsampling
+            //     switch to context A for read mode, full frame, and max line delay
+
+    	    mt9m111_write(0x2D2, 0x0000);	// turn off subsampling and turn on full power mode
+    	    mt9m111_write(0x2CC, 0x4);		// Context Ctl Program Select -- use default program
+    	    u16 v = mt9m111_reg_read(0x2CB);	// read Context Ctl Program Advance
+    	    mt9m111_write(0x2CB, v|1);		// advance program
+
+	        inSkipMode = 1;
+    	    didSnapPhoto = 0;
+	    }
+    }
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_viewfinder_off()
+{
+    mt9m111_dbg_print("mt9m111_viewfinder_off");
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_snapshot_trigger()
+{
+    mt9m111_dbg_print("mt9m111_snapshot_trigger");
+
+    mt9m111_update_size(1);
+
+    mt9m111_write(0x2D2, 0x007F);		// Context return to default => all in context B
+    mt9m111_write(0x2CC, 0x0004);		// Program Select = default => run program to default
+    u16 v = mt9m111_reg_read(0x2CB);		
+    mt9m111_write(0x2CB, v | 1);	        // Program Advance = RUN/GO
+
+    didSnapPhoto = 1;
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_snapshot_complete()
+{
+    mt9m111_dbg_print("mt9m111_snapshot_complete");
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_input_size(micron_window_size * window)
+{
+    sensorWidth = window->width;
+    sensorHeight = window->height;
+
+    mt9m111_dbg_print("mt9m111_input_size, sensor=%dx%d", sensorWidth, sensorHeight);
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_output_size(micron_window_size * window)
+{
+    outWidth = window->width;
+    outHeight = window->height;
+
+    mt9m111_dbg_print("mt9m111_output_size, out=%dx%d", outWidth, outHeight);
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_get_input_size( micron_window_size * window)
+{
+    window->width = mt9m111_reg_read(0x1A6);
+    window->height = mt9m111_reg_read(0x1A9);
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_set_fps(u16 newMaxFPS, u16 newMinFPS)
+{
+    mt9m111_dbg_print("mt9m111_set_fps: newMaxFPS=%d, newMinFPS=%d", newMaxFPS, newMinFPS);
+
+    //
+    // clamp newMaxFPS to a legal range
+    //
+
+    const int MIN_FPS = 5;
+    const int MAX_FPS = 15;
+
+    newMaxFPS = (newMaxFPS > MAX_FPS) ? MAX_FPS : newMaxFPS;
+    newMaxFPS = (newMaxFPS < MIN_FPS) ? MIN_FPS : newMaxFPS;
+
+    mt9m111_dbg_print("mt9m111_set_fps: newMaxFPS=%d, newMinFPS=%d", newMaxFPS, newMinFPS);
+
+    //
+    // if the maxFPS has changed, update the vblank
+    //
+
+    if (newMaxFPS != maxFPS)
+    {
+
+        //
+        // enforce max fps by setting the vertical blanking
+        //
+        // The table below assumes:
+        //    MCLK = 24.375 MHz
+        //    target line time = 127 micro seconds
+        //    HBLANK in low power = ???
+        //    HBLANK in full power = ???
+        //
+        // The following values came from Micron during a site visit on 9/1.
+        //
+        // If the input clock changes, these settings also need to change.
+        //
+        // The basic idea is that a flicker-detection friendly framerate close
+        // to the requested frame rate is chosen.
+        //
+
+        const u16 vblanksLowPower[] = 
+        { 
+            1021,	/* 5.11   */ 
+            701, 	/* 6.45   */
+            556, 	/* 7.32   */ 
+            412, 	/* 8.45   */
+            309, 	/* 9.5    */
+            233, 	/* 10.45  */
+            162, 	/* 11.55  */
+            123, 	/* 12.25  */
+            90, 	/* 12.91  */
+            50, 	/* 13.81  */
+            18   	/* 14.645 */
+        };
+
+        const u16 vblanksFullPower[] = 
+        { 
+            509, 	/* 5.11 */  
+            189, 	/* 6.45 */  
+            44, 	/* 7.32 */ 
+            44, 	/* 7.32 */  
+            44, 	/* 7.32 */ 
+            44, 	/* 7.32 */
+            44, 	/* 7.32 */
+            44, 	/* 7.32 */ 
+            44, 	/* 7.32 */ 
+            44, 	/* 7.32 */ 
+            44 		/* 7.32 */
+        };
+
+        //
+        // use the following hblanks to achieve a line rate of 127us
+        //
+
+        const u16 readModeLowPower = 0x040C;
+        const u16 readModeFullPower = 0x0300;
+        const u16 hblankLowPower = 126;
+        const u16 hblankFullPower = 260;
+        const u16 aeLineSizeLowPower = 1548;
+        const u16 aeLineSizeFullPower = 1548;
+        const u16 aeShutterDelayLimitLowPower = 1548;
+        const u16 aeShutterDelayLimitFullPower = 1548;
+        const u16 aeFlickerFullFrameTime60HzLowPower = 262;
+        const u16 aeFlickerFullFrameTime60HzFullPower = 262;
+        const u16 aeFlickerFullFrameTime50HzLowPower = 314;
+        const u16 aeFlickerFullFrameTime50HzFullPower = 314;
+        const u16 flickerSearchRange50HZ = 0x1712;
+        const u16 flickerSearchRange60HZ = 0x120D;
+        // const u16 flickerParameter = 0x1E1C; // 7/8 trials
+        const u16 flickerParameter = 0x0D1C; 	// 3/4 trials
+
+        mt9m111_write(0x005, hblankFullPower);
+        mt9m111_write(0x006, vblanksFullPower[newMaxFPS-5]);
+        mt9m111_write(0x007, hblankLowPower);
+        mt9m111_write(0x008, vblanksLowPower[newMaxFPS-5]);
+        mt9m111_write(0x020, readModeFullPower);
+        mt9m111_write(0x021, readModeLowPower);
+        mt9m111_write(0x239, aeLineSizeLowPower);
+        mt9m111_write(0x23A, aeLineSizeFullPower);
+        mt9m111_write(0x23B, aeShutterDelayLimitLowPower);
+        mt9m111_write(0x23C, aeShutterDelayLimitFullPower);
+        mt9m111_write(0x257, aeFlickerFullFrameTime60HzLowPower);
+        mt9m111_write(0x258, aeFlickerFullFrameTime50HzLowPower);
+        mt9m111_write(0x259, aeFlickerFullFrameTime60HzFullPower);
+        mt9m111_write(0x25A, aeFlickerFullFrameTime50HzFullPower);
+        mt9m111_write(0x25C, flickerSearchRange60HZ);
+        mt9m111_write(0x25D, flickerSearchRange50HZ);
+        mt9m111_write(0x264, flickerParameter);
+ 
+        maxFPS = newMaxFPS;
+    }
+
+    return MICRON_ERR_NONE;
+
+}
+
+int mt9m111_set_autoexposure_zone(u16 newMinFPS)
+{
+    const int MIN_FPS = 5;
+    const int MAX_FPS = 15;
+
+    //
+    // This driver only implements two minimum framerates: 5fps and 15fps.
+    //
+    // The mt9m111 can support every min fps between 5fps and 15fps, but the AE settings 
+    // will become very complex.
+    // 
+
+    if (newMinFPS > 5)
+    {
+        newMinFPS = MAX_FPS;
+    }
+    else
+    {
+        newMinFPS = MIN_FPS;
+    }
+
+    //
+    // if the minFPS has changed, update the AE limit
+    //
+
+    if (newMinFPS != minFPS)
+    {
+        //
+        // enforce min fps by setting max exposure time
+        //
+
+        if (newMinFPS == 5)
+        {
+            // set min fps to 5 fps -> AE Zone 24
+            u16 limitAE = ((120/5) << 5) & 0x03E0;
+            mt9m111_write(0x237, limitAE);
+
+            //
+            // work-around for AE strangeness
+            // symptom: start in dark, preview gets darker, darker, very dark, black, then is OK.
+            //
+
+            if (mt9m111_reg_read(0x23F) == 8)
+            {
+                u16 v;
+                v = mt9m111_reg_read(0x22E);	// read target luma register
+
+                // by setting target luma to 0, trick AE into zone <= 8
+                mt9m111_write(0x22E, 0x0000);	// set target luma to 0
+
+                //
+                // wait until AE zone is in bounds (or time exceeds 1500ms)
+                //
+                // 1500ms is a long time!
+                //
+
+                int count=0;
+                while ((mt9m111_reg_read(0x23F) == 8) && (++count < 30))
+                {
+                    mdelay(50);
+                }
+
+                mt9m111_write(0x22E, v);	// rewrite target luma register
+            }
+        }
+        else
+        {
+            // set min fps to 15 fps -> AE Zone 8
+            u16 limitAE = ((120/15) << 5) & 0x03E0;
+            mt9m111_write(0x237, limitAE);
+            mt9m111_dbg_print("AE zone limit is %0x\n", limitAE);
+
+            //
+            // work-around for AE strangeness
+            // symptom: start in dark, preview gets darker, darker, very dark, black, then is OK.
+            //
+
+            if (mt9m111_reg_read(0x23F) > 8)
+            {
+                u16 v;
+                v = mt9m111_reg_read(0x22E);	// read target luma register
+
+                // by setting target luma to 0, trick AE into zone <= 8
+                mt9m111_write(0x22E, 0x0000);	// set target luma to 0
+
+                //
+                // wait until AE zone is in bounds (or time exceeds 1500ms)
+                //
+                // 1500ms is a long time!
+                //
+
+                int count=0;
+                while ((mt9m111_reg_read(0x23F) > 8) && (++count < 30))
+                {
+                    mdelay(50);
+                }
+
+                mt9m111_write(0x22E, v);	// rewrite target luma register
+            }
+        }
+
+        minFPS = newMinFPS;
+    }
+
+    return MICRON_ERR_NONE;
+    
+}
+
+int mt9m111_output_format(u16 format)
+{
+    u16 value;
+
+    if(format == O_FORMAT_422_YCbYCr)
+    {
+        mt9m111_write(0x13A, 0);
+    }
+    else
+    {
+        value = (1<<8)|((format-1)<<6);
+        mt9m111_write(0x13A, value);
+    }
+    return MICRON_ERR_NONE;
+}
+
+void mt9m111_dump_register(u16 startRegAddr, u16 endRegAddr, u16* buffer)
+{
+    u16 addr,value;
+	
+    for(addr = startRegAddr; addr <= endRegAddr; addr++)
+    {
+        unsigned long flags;
+        local_irq_save(flags);
+	   
+        mt9m111_read(addr, &value);
+	  
+        local_irq_restore(flags);
+
+        mt9m111_dbg_print("mt9m111 register: 0x%04x = %04x",addr,value);
+	   
+        if(buffer)
+        {
+            *buffer = value;
+            buffer++;
+        }
+    }
+}
+
+//
+// TODO: make this an IOCTL that is called by the application some time after set_flicker() is
+// called
+//
+
+int mt9m111_set_flicker_2(void)
+{
+    mt9m111_dbg_print("mt9m111_set_flicker_2: %04x", preferredFlickerMask);
+
+    int count=0;
+
+    //
+    // read flicker_control_1 until it verifies that flicker is set to the preferred rate.
+    //
+
+    while(((mt9m111_reg_read(0x25B) & 0x8000) != preferredFlickerMask) && (++count < 50))
+    {
+        mdelay(20);
+    }
+
+    mt9m111_write(0x25B, 0x0002);	// back to auto mode
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_set_flicker(int flicker)
+{
+    mt9m111_dbg_print("mt9m111_set_flicker: %d", flicker);
+
+    preferredFlickerMask = (flicker == 50) ? 0x0000 : 0x8000;
+
+    if (flicker == 50)
+    {
+        mt9m111_write(0x25B, 0x0001);	// manual mode 50Hz
+    }
+    else if (flicker == 60)
+    {
+        mt9m111_write(0x25B, 0x0003);	// manual mode 60Hz
+    }
+    else
+    { 
+        return MICRON_ERR_PARAMETER;
+    }
+
+    mt9m111_set_flicker_2();
+
+    return MICRON_ERR_NONE;
+}
+
+int mt9m111_set_contrast(int contrast)
+{
+    mt9m111_dbg_print("mt9m111_set_contrast: %d (skipped)", contrast);
+    return MICRON_ERR_NONE;
+
+#if 0
+    //
+    // we don't support setting the contrast in the initial release of A780
+    //
+
+    const u16 gammaTable[] = 
+    {
+        //0x3B2C,0x664D,0x9F87,0xC3B3,0xE0D2, //0.40
+        //0x3224,0x664D,0x9F87,0xC3B3,0xE0D2, //0.45
+        0x2A1D,0x543B,0x9277,0xBDA9,0xE0CF, //0.50
+        0x2318,0x4C34,0x8C70,0xBAA4,0xE0CD, //0.55
+        0x1E14,0x462E,0x876A,0xB7A0,0xE0CC, //0.60
+        0x1910,0x3F28,0x8163,0xB39B,0xE0CA, //0.65
+        0x150D,0x3923,0x7B5D,0xB097,0xE0C9, //0.70
+        0x120A,0x341E,0x7657,0xAE93,0xE0C7, //0.75
+        0x0F08,0x2F1B,0x7152,0xAB8F,0xE0C6, //0.80
+        0x0D07,0x2A17,0x6D4D,0xA88B,0xE0C4, //0.85
+        0x0B05,0x2614,0x6848,0xA587,0xE0C2, //0.90
+        //0x0804,0x2010,0x6040,0xA080,0xE0C0, //1.00
+        //0x0502,0x1A0C,0x5838,0x9A79,0xE0BD, //1.10
+        //0x0401,0x1509,0x5131,0x9572,0xE0BA, //1.20
+    };
+
+    if(contrast < -4 || contrast > 4)
+    {
+        return MICRON_ERR_PARAMETER;
+    }
+
+    u16 i, regA=0x153, regB=0x1DC;
+
+    for(i=0; i<5; i++)
+    {
+        mt9m111_write(regA++, gammaTable[(contrast+4)*5+i]);
+        mt9m111_write(regB++, gammaTable[(contrast+4)*5+i]);
+    } 
+
+    return MICRON_ERR_NONE;
+#endif
+
+}
+
+/*set picture style(normal/black white/sepia/solarize/neg.art)*/
+int mt9m111_set_style(V4l_PIC_STYLE style)
+{
+    mt9m111_dbg_print("mt9m111_set_style: %d", style);
+
+  switch(style)
+  {
+  case V4l_STYLE_BLACK_WHITE:
+       mt9m111_write(0x1E2,0x7001);
+       break;
+  case V4l_STYLE_SEPIA:
+       mt9m111_write(0x1E2,0x7002);
+       mt9m111_write(0x1E3,0xB023);
+       break;
+  case V4l_STYLE_SOLARIZE:
+       mt9m111_write(0x1E2,0x7004);
+       break;
+  case V4l_STYLE_NEG_ART:
+       mt9m111_write(0x1E2,0x7003);
+       break;
+  default:
+       mt9m111_write(0x1E2,0x7000);
+       break;
+  }
+
+  return MICRON_ERR_NONE;
+}
+
+        
+/*set picture light(auto/direct sun/incandescent/fluorescent)*/     
+int mt9m111_set_light(V4l_PIC_WB light)
+{ 
+    u16 *m;
+    u16 v;
+
+    switch(light)
+    {
+        case V4l_WB_DIRECT_SUN:
+
+            mt9m111_dbg_print("mt9m111_set_light: %d (direct sun)", light);
+            m = d65Light;
+            break;       
+
+        case V4l_WB_INCANDESCENT:
+
+            mt9m111_dbg_print("mt9m111_set_light: %d (incandescent)", light);
+            m = incandescentLight;
+            break;       
+
+        case V4l_WB_FLUORESCENT:
+
+            mt9m111_dbg_print("mt9m111_set_light: %d (fluorescent)", light);
+            m = tl84Light;
+            break;
+
+        default:
+    
+            mt9m111_dbg_print("mt9m111_set_light: %d (default)", light);
+            m = autoLight;
+            break;
+
+    }
+
+    mt9m111_write(0x202, m[0]);  //BASE_MATRIX_SIGNS
+    mt9m111_write(0x203, m[1]);  //BASE_MATRIX_SCALE_K1_K5
+    mt9m111_write(0x204, m[2]);  //BASE_MATRIX_SCALE_K6_K9
+
+    mt9m111_write(0x209, m[3]);  //BASE_MATRIX_COEF_K1
+    mt9m111_write(0x20A, m[4]);  //BASE_MATRIX_COEF_K2
+    mt9m111_write(0x20B, m[5]);  //BASE_MATRIX_COEF_K3
+    mt9m111_write(0x20C, m[6]);  //BASE_MATRIX_COEF_K4
+    mt9m111_write(0x20D, m[7]);  //BASE_MATRIX_COEF_K5
+    mt9m111_write(0x20E, m[8]);  //BASE_MATRIX_COEF_K6
+    mt9m111_write(0x20F, m[9]);  //BASE_MATRIX_COEF_K7
+    mt9m111_write(0x210, m[10]); //BASE_MATRIX_COEF_K8
+    mt9m111_write(0x211, m[11]); //BASE_MATRIX_COEF_K9
+    mt9m111_write(0x215, m[12]); //DELTA_COEF_SIGNS
+    mt9m111_write(0x216, m[13]); //DELTA_MATRIX_COEF_D1
+    mt9m111_write(0x217, m[14]); //DELTA_MATRIX_COEF_D2
+    mt9m111_write(0x218, m[15]); //DELTA_MATRIX_COEF_D3
+    mt9m111_write(0x219, m[16]); //DELTA_MATRIX_COEF_D4
+    mt9m111_write(0x21A, m[17]); //DELTA_MATRIX_COEF_D5
+    mt9m111_write(0x21B, m[18]); //DELTA_MATRIX_COEF_D6
+    mt9m111_write(0x21C, m[19]); //DELTA_MATRIX_COEF_D7
+    mt9m111_write(0x21D, m[20]); //DELTA_MATRIX_COEF_D8
+    mt9m111_write(0x21E, m[21]); //DELTA_MATRIX_COEF_D9
+
+    mt9m111_write(0x25E, m[22]); //RATIO_BASE_REG
+    mt9m111_write(0x25F, m[23]); //RATIO_DELTA_REG
+    mt9m111_write(0x260, m[24]); //SIGNS_DELTA_REG
+
+    //Toggle Manual White Balance to force loading the new table
+    v = mt9m111_reg_read(0x106);
+    mt9m111_write(0x106, v|0x8000); // Operating Mode Control -- P.13 708E 
+    mdelay(200);		    // TODO: correct amount of time? 
+    mt9m111_write(0x106, v&~0x8000);
+
+    return MICRON_ERR_NONE;
+}
+
+    
+/*set picture brightness*/
+int mt9m111_set_bright(int bright)
+{
+    mt9m111_dbg_print("mt9m111_set_bright (gamma) %d", bright);
+
+    const u16 target[] = 
+    { 
+        37,      // -2.0 EV
+        44,      // -1.5 EV
+        52,      // -1.0 EV
+        62,      // -0.5 EV
+        74,      //  0.0 EV
+        88,      // +0.5 EV
+        105,     // +1.0 EV
+        124,     // +1.5 EV
+        148      // +2.0 EV
+    };
+
+    if(bright < -4 || bright > 4)
+    {
+        return MICRON_ERR_PARAMETER;
+    }
+
+    /*set luma value of AE target*/
+    mt9m111_write(0x22E, 0x0C00 + target[bright+4]);
+    return MICRON_ERR_NONE;
+}
+
+
+int mt9m111_default_settings()
+{
+    mt9m111_dbg_print("mt9m111_default_settings");
+
+    mt9m111_reset();
+
+    // Soft Reset -- Reset both sensor AND SOC (and leave sensor digital logic enabled)
+
+    mt9m111_write(0x00D, 0x29);   // Reset sensor and SOC -- P.54
+    // i2c will delay enough here for reset to finish (1us is enough)
+    mt9m111_write(0x00D, 0x08);   // Release reset -- P.54
+
+    mt9m111_write(0x285, 0x0061);   // AE Gain table 
+    mt9m111_write(0x286, 0x0080);   // AE Gain table
+    mt9m111_write(0x287, 0x0061);   // AE Gain table
+    mt9m111_write(0x288, 0x0061);   // AE Gain table
+    mt9m111_write(0x289, 0x03E2);   // AE Gain table
+    mt9m111_write(0x238, 0x0840);   // Shutter priority transition zone
+
+    //Enable flicker detection
+    mt9m111_write(0x106, 0x708E);   // Operating Mode Control -- P.13 0x0708C
+
+    // Enable 2D defect correction in both contexts 
+    mt9m111_write(0x14C, 0x0001);   // Defect Buffer Context A -- P.13 0x0000 -- Enable 2D defect correct context A 
+    mt9m111_write(0x14D, 0x0001);   // Defect Buffer Context B -- P.13 0x0000 -- Enable 2D defect correct context B 
+    
+    // Set centered origin 
+    mt9m111_write(0x1a8, 0x4000);   // Reducer YPan A -- P.14 0x0000 -- Cntxt A Y Crop centering 
+    mt9m111_write(0x1a5, 0x4000);   // Reducer XPan A -- P.14 0x0000 -- Cntxt A X Crop centering 
+    mt9m111_write(0x1a2, 0x4000);   // Reducer YPan B -- P.14 0x0000 -- Cntxt B Y Crop centering 
+    mt9m111_write(0x19F, 0x4000);   // Reducer XPan B -- P.14 0x0000 -- Cntxt B X Crop centering 
+
+    // Sensor is running in semi auto mode only 
+    mt9m111_write(0x2CC, 0x0004);   // Context Ctl Pgm Select -- P.19 0x0000 
+
+    //mt9m111_write(0x034, 0xC039);   // Reserved -- P.54 0xC019 in es3 -- turn on eclipse
+
+    // Do not invert the pixel clock
+    mt9m111_write(0x13A, 0x0000);   // Output Format Control 2A -- P.13 0x0000 
+    mt9m111_write(0x19B, 0x0000);   // Output Format Control 2B -- P.14 0x0000
+
+    //Auto sharpening
+    mt9m111_write(0x105, 0x000B);   // Aperature Correction (sharpening) gain -- 0x0003 
+				    // 75% sharpening, auto-sharpening on
+
+    //Enable classic interpolation at full res
+    mt9m111_write(0x1AF, 0x0018);   // Reducer Zoom Control -- P.14 0x0010
+    
+    //AWB settings for 12mm lens, no ulens shift
+    mt9m111_write(0x222, 0xb070);   // Red Gain AWB Limits -- P.16 0x0D960 -- overconstrained currently? (sunburned->0x8870)
+    mt9m111_write(0x223, 0xb070);   // Blue Gain AWB Limits -- P.16 0x0D960 -- overconstrained currently?
+    mt9m111_write(0x229, 0x847C);   // Reserved -- P.16 0x8D73 -- Thresholds (tied into digital gains above)
+
+    //mt9m111_set_light(V4l_WB_AUTO); //the app will call ioctl to set light
+
+    // lens correction for Micron es3 + flex module 9/31
+
+    mt9m111_write(0x180, 0x0003);    // LENS_ADJ_PARAM_0_5
+    mt9m111_write(0x181, 0xC813);    // LENS_ADJ_VERT_RED_0
+    mt9m111_write(0x182, 0xEEE2);    // LENS_ADJ_VERT_RED_1_2
+    mt9m111_write(0x183, 0xFDF9);    // LENS_ADJ_VERT_RED_3_4
+    mt9m111_write(0x184, 0xE10C);    // LENS_ADJ_VERT_GREEN_0
+    mt9m111_write(0x185, 0xF0E9);    // LENS_ADJ_VERT_GREEN_1_2
+    mt9m111_write(0x186, 0xFFF8);    // LENS_ADJ_VERT_GREEN_3_4
+    mt9m111_write(0x187, 0xE60A);    // LENS_ADJ_VERT_BLUE_0
+    mt9m111_write(0x188, 0xF2EB);    // LENS_ADJ_VERT_BLUE_1_2
+    mt9m111_write(0x189, 0x01F9);    // LENS_ADJ_VERT_BLUE_3_4
+    mt9m111_write(0x18A, 0xAE25);    // LENS_ADJ_HORIZ_RED_0
+    mt9m111_write(0x18B, 0xDACE);    // LENS_ADJ_HORIZ_RED_1_2
+    mt9m111_write(0x18C, 0xF5EF);    // LENS_ADJ_HORIZ_RED_3_4
+    mt9m111_write(0x18D, 0x00FD);    // LENS_ADJ_HORIZ_RED_5
+    mt9m111_write(0x18E, 0xDE18);    // LENS_ADJ_HORIZ_GREEN_0
+    mt9m111_write(0x18F, 0xE5E2);    // LENS_ADJ_HORIZ_GREEN_1_2
+    mt9m111_write(0x190, 0xF7F2);    // LENS_ADJ_HORIZ_GREEN_3_4
+    mt9m111_write(0x191, 0x00FE);    // LENS_ADJ_HORIZ_GREEN_5
+    mt9m111_write(0x192, 0xCF17);    // LENS_ADJ_HORIZ_BLUE_0
+    mt9m111_write(0x193, 0xEAE4);    // LENS_ADJ_HORIZ_BLUE_1_2
+    mt9m111_write(0x194, 0xF8F4);    // LENS_ADJ_HORIZ_BLUE_3_4
+    mt9m111_write(0x195, 0x00FF);    // LENS_ADJ_HORIZ_BLUE_5
+    mt9m111_write(0x1B6, 0x1104);    // LENS_ADJ_VERT_RED_5_6
+    mt9m111_write(0x1B7, 0x3420);    // LENS_ADJ_VERT_RED_7_8
+    mt9m111_write(0x1B8, 0x0503);    // LENS_ADJ_VERT_GREEN_5_6
+    mt9m111_write(0x1B9, 0x1C0F);    // LENS_ADJ_VERT_GREEN_7_8
+    mt9m111_write(0x1BA, 0x0502);    // LENS_ADJ_VERT_BLUE_5_6
+    mt9m111_write(0x1BB, 0x1B0C);    // LENS_ADJ_VERT_BLUE_7_8
+    mt9m111_write(0x1BC, 0x0F03);    // LENS_ADJ_HORIZ_RED_6_7
+    mt9m111_write(0x1BD, 0x2E1C);    // LENS_ADJ_HORIZ_RED_8_9
+    mt9m111_write(0x1BE, 0x0050);    // LENS_ADJ_HORIZ_RED_10
+    mt9m111_write(0x1BF, 0x0A02);    // LENS_ADJ_HORIZ_GREEN_6_7
+    mt9m111_write(0x1C0, 0x1C13);    // LENS_ADJ_HORIZ_GREEN_8_9
+    mt9m111_write(0x1C1, 0x0023);    // LENS_ADJ_HORIZ_GREEN_10
+    mt9m111_write(0x1C2, 0x0801);    // LENS_ADJ_HORIZ_BLUE_6_7
+    mt9m111_write(0x1C3, 0x1B0F);    // LENS_ADJ_HORIZ_BLUE_8_9
+    mt9m111_write(0x1C4, 0x0027);    // LENS_ADJ_HORIZ_BLUE_10
+    
+    //turn on lens correction
+    mt9m111_write(0x106, 0x748E);   // Operating Mode Control -- P.13 0x708E 
+
+    // set luma offset and clip for both contexts
+    mt9m111_write(0x134, 0x0000);   // Luma offset (Brightness Offset)
+    mt9m111_write(0x135, 0xFF01);   // Luma clip (Brightness Offset)
+    // TODO: why FF01, why not FF00?
+
+    // load hard-coded 0.6 gamma table (Context A)
+    mt9m111_write(0x153, 0x2217);
+    mt9m111_write(0x154, 0x4F34);
+    mt9m111_write(0x155, 0x9978);
+    mt9m111_write(0x156, 0xD0B6);
+    mt9m111_write(0x157, 0xFEE8);
+    mt9m111_write(0x158, 0x0000);
+
+    // load hard-coded 0.6 gamma table (Context B)
+    mt9m111_write(0x1DC, 0x2217);
+    mt9m111_write(0x1DD, 0x4F34);
+    mt9m111_write(0x1DE, 0x9978);
+    mt9m111_write(0x1DF, 0xD0B6);
+    mt9m111_write(0x1E0, 0xFEE8);
+    mt9m111_write(0x1E1, 0x0000);
+
+    // add new setting from Kenta's email, Nov.2, 2004
+    mt9m111_write(0x21F, 0x0090);
+    //mt9m111_write(0x222, 0xb070);     // aleady write above
+    //mt9m111_write(0x223, 0xb070);     // aleady write above
+    mt9m111_write(0x228, 0xef14);
+
+    return MICRON_ERR_NONE;
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/mt9m111_hw.h linux-2.6.16.5-exz/drivers/media/video/mt9m111_hw.h
--- linux-2.6.16.5/drivers/media/video/mt9m111_hw.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/mt9m111_hw.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,89 @@
+/*================================================================================
+                                                                               
+                      Header Name: mt9m111_hw.h
+
+General Description: Camera module mt9m111 interface header file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Ma Zhiqiang        6/30/2004                    Change for auto-detect
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+
+#ifndef _PXA_MT9M111_HW_H__
+#define _PXA_MT9M111_HW_H__
+
+#include "camera.h"
+/***********************************************************************
+ * 
+ * Constants & Structures
+ *
+ ***********************************************************************/
+ 
+/* MICRON_WINDOWSIZE */
+typedef struct {
+    u16 width;
+    u16 height;
+} micron_window_size;
+
+
+// Return codes
+#define MICRON_ERR_NONE        0
+#define MICRON_ERR_TIMEOUT    -1
+#define MICRON_ERR_PARAMETER  -2  
+
+
+// Output Format
+#define O_FORMAT_422_YCbYCr   0
+#define O_FORMAT_565_RGB      1
+#define O_FORMAT_555_RGB      2
+#define O_FORMAT_444_RGB      3
+
+                                                                            
+/***********************************************************************                   
+ *                                                                                         
+ * Function Prototype                 
+ *                                    
+ ***********************************************************************/
+
+u16  mt9m111_reg_read(u16 reg_addr);
+void mt9m111_reg_write(u16 reg_addr, u16 reg_value);
+
+
+// Configuration Procedures
+int mt9m111_get_device_id(u16 *id);
+
+int mt9m111_viewfinder_on( void );
+int mt9m111_viewfinder_off( void );
+int mt9m111_snapshot_trigger( void );
+int mt9m111_snapshot_complete( void );
+
+int mt9m111_set_fps(u16 fps, u16 minfps);
+int mt9m111_set_autoexposure_zone(u16 minfps);
+
+int mt9m111_input_size(micron_window_size * win);
+int mt9m111_output_size(micron_window_size * win);
+int mt9m111_get_input_size(micron_window_size * win);
+int mt9m111_output_format(u16 format);
+
+int mt9m111_set_contrast(int contrast);
+int mt9m111_set_style(V4l_PIC_STYLE style);
+int mt9m111_set_light(V4l_PIC_WB light);
+int mt9m111_set_bright(int bright);
+int mt9m111_set_flicker(int bright);
+
+int mt9m111_default_settings( void );
+
+void mt9m111_dump_register(u16 startRegAddr, u16 endRegAddr, u16* buffer);
+
+#endif /* _PXA_MT9M111_HW_H__ */
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/mt9v111.c linux-2.6.16.5-exz/drivers/media/video/mt9v111.c
--- linux-2.6.16.5/drivers/media/video/mt9v111.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/mt9v111.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,910 @@
+ 
+/*================================================================================
+                                                                               
+                      Header Name: mt9v111.c
+
+General Description: Camera module mt9v111 interface source file
+ 
+==================================================================================
+                     Motorola Confidential Proprietary
+                 Advanced Technology and Software Operations
+               (c) Copyright Motorola 1999, All Rights Reserved
+ 
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+wangfei(w20239)      04/14/2003                 Created   
+
+==================================================================================
+                                 INCLUDE FILES
+==================================================================================*/
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+
+#include <asm/pgtable.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include <asm/arch/pxa-regs.h>
+
+#include "adcm2700.h"
+#include "adcm2700_hw.h"
+
+#define ADDRSPACE_CORE          0x04              /* code to select core registers 0-170*/
+#define ADDRSPACE_IFP           0x01              /* code to select IFP/SOC registers 0-255*/
+#define MT9V111_SENSOR_WIDTH    640
+#define MT9V111_SENSOR_HEIGHT   480
+
+extern int mt9v111_write(u8 addrSpace, u16 addr, u16 value);
+extern int mt9v111_read(u8 addrSpace, u16 addr);
+extern int i2c_mt9v111_cleanup(void);
+extern int camera_ring_buf_init(p_camera_context_t);
+extern void adcm2700_wait(u32);
+extern void start_dma_transfer(p_camera_context_t,unsigned);
+extern void stop_dma_transfer(p_camera_context_t);
+extern int camera_func_mt9v111_stop_capture(p_camera_context_t camera_context);
+
+static int mt9v111_restore_property(p_camera_context_t);
+
+static inline int mt9v111_read_core_reg(u16 addr)
+{
+    return mt9v111_read(ADDRSPACE_CORE, addr);
+}
+
+static inline int mt9v111_read_ifp_reg(u16 addr)
+{
+    return mt9v111_read(ADDRSPACE_IFP, addr);
+}
+static inline int mt9v111_write_core_reg(u16 addr, u16 value)
+{
+    return mt9v111_write(ADDRSPACE_CORE, addr, value);
+}
+static inline int mt9v111_write_ifp_reg(u16 addr, u16 value)
+{
+    return mt9v111_write(ADDRSPACE_IFP, addr, value);
+}
+static int mt9v111_input_size(adcm_window_size * size)
+{
+    u16 pan_ver,pan_hor;
+    pan_hor=(MT9V111_SENSOR_WIDTH - size->width)>>1;
+    pan_ver=(MT9V111_SENSOR_HEIGHT- size->height)>>1;
+    
+    mt9v111_write_ifp_reg(0xa5,0x8000|pan_hor);
+    mt9v111_write_ifp_reg(0xa8,0x8000|pan_ver);
+    mt9v111_write_ifp_reg(0xa6,0x8000|size->width);
+    mt9v111_write_ifp_reg(0xa9,size->height);
+    dbg_print("set sensor width : %d  height : %d\n",size->width , size->height);
+    //dbg_print("horizontal pan :%d  vertical pan %d \n",pan_hor,pan_ver);
+    return 0;
+}
+static int mt9v111_set_fps(int fps, int minfps)
+{    
+    //write to r55 (0x37) [9..5] to change minimum fps
+    u16 blank_v,r55,zone_low,zone_high;
+    dbg_print("set fps : %d min fps : %d\n",fps,minfps);
+    
+    //Set vertical blank to adjust frame rate
+    blank_v = (15-fps)*496/fps + 4;
+    mt9v111_write_core_reg(0x06,blank_v);
+    
+    //shut width
+    zone_low=0;
+    zone_high=fps*8/minfps;
+    r55 = zone_low|(zone_high<<5);
+    mt9v111_write_ifp_reg(0x37, r55);
+    
+    return 0;
+}
+static int mt9v111_set_bright(int bright)
+{
+    const u16 target[]=
+    {
+        25,
+        35,
+        50,
+        75,
+        100,
+        120,
+        140,
+        160,
+        180
+    };
+    if(bright > 4|| bright < -4)
+    {
+        return -EFAULT;
+    }
+    mt9v111_write_ifp_reg(0x2e,(16<<8)|target[bright+4]);
+    return 0;
+}
+static int mt9v111_output_size(adcm_window_size * size)
+{
+    //0xA7  Horizontal size of output 
+    //0xAA  Vertical size of output 
+    //refer to mt9v111-datasheet.pdf page 45 and page 46
+    mt9v111_write_ifp_reg(0xA7, 0x8000|size->width);
+    mt9v111_write_ifp_reg(0xAA, size->height);
+    dbg_print("output size :%d * %d \n",size->width,size->height);
+    adcm2700_wait(50);
+    return 0;
+}
+static int mt9v111_set_blackwhite(int black_white)
+{
+    u16 value = mt9v111_read_ifp_reg(0x08);
+    if(black_white)
+    {
+        value |= 1<<5;
+    }
+    else
+    {
+        value &= ~(1<<5);
+    }
+    
+    mt9v111_write_ifp_reg(0x08, value);
+    return 0;
+}
+//set color correction matrix
+static int mt9v111_set_ccm(int index)
+{
+    int i;
+    u16 r6;
+    const u16 regs[]=
+    {
+        72,                                  //digital gain
+        2,                                   //sign
+        3,4,                                 //scale
+        9,10,11,12,13,14,15,16,17,           //magnitude
+        21,22,23,24,25,26,27,28,29,30,       //delta matrix
+        94,95,96
+    };
+    const u16 value[][26]=
+    {
+        //default
+        {
+            
+            0,
+            0x6e,
+            0x2923,0x0524,                 
+            146,22,8,171,147,88,77,169,160,
+            373,22,67,12,0,21,31,22,152,76,
+            26684,12296,2
+           /*    
+            0,
+            110,
+            10531,1316,
+            125,108,58,129,141,112,95,128,138,
+            145,6,231,221,15,65,208,72,59,43,
+            26953,11283,2
+           */
+        },
+        //direct sun
+        {
+        /*
+            128,
+            0xea,
+            0x3922,0x4e4,
+            0x8d,0x71,0xc5,0x9d,0xf8,0x53,0x0d,0xa7,0x90,
+            0,0,0,0,0,0,0,0,0,0
+        */
+            128,
+            174,
+            14627,1828,
+            128,7,52,122,215,7,59,99,232,
+            0,0,0,0,0,0,0,0,0,0,
+            21331,0,0
+
+        },
+        //incandescent
+        {
+        /*
+            128,
+            0xee,
+            0x2922,0x4a4,
+            0x8c,0xcc,0x6e,0xa6,0x86,0x72,0x06,0x85,0xc6,
+            0,0,0,0,0,0,0,0,0,0
+        */
+            128,
+            110,
+            10532,1316,
+            245,244,168,137,174,216,131,158,160,
+            0,0,0,0,0,0,0,0,0,0,
+            32832,0,0
+        },
+        //fluorescent
+        {
+            /*
+            0,
+            0xea,
+            0x3922,0x4e4,
+            0x8d,0xba,0x7b,0x9c,0xfe,0x61,0x08,0xb9,0x9a,
+            0,0,0,0,0,0,0,0,0,0
+            */
+            128,
+            166,
+            10531,1316,
+            197,160,77,230,132,3,122,91,131,
+            0,0,0,0,0,0,0,0,0,0,
+            32844,0,0
+       
+        },
+        //sepia
+        {
+            128,
+            36,
+            10516,2276,
+            9,142,17,24,134,43,10,147,17,
+            0,0,0,0,0,0,0,0,0,0,
+            20560,0,0
+        },
+    };
+    
+    for(i=0; i<26; i++)
+    {
+        mt9v111_write_ifp_reg(regs[i],value[index][i]);
+    }
+    
+    r6=mt9v111_read_ifp_reg(0x06);
+    r6 |= 1<<15;
+    mt9v111_write_ifp_reg(0x06,r6);
+    r6 &= ~(1<<15);
+    mt9v111_write_ifp_reg(0x06,r6);
+    return 0;
+}
+static int mt9v111_set_gamma(int index)
+{
+    const u16 regs[]=
+    {
+        0x58,0x53,0x54,0x55,0x56,0x57,
+    };
+    const u16 value[][11]=
+    {
+        //default
+        {
+            //0x0,0x09,0x0f,0x1b,0x2f,0x52,0x71,0x8f,0xab,0xc6,0xe0
+            0,10,18,31,54,94,130,164,196,226,255
+        },
+        //solarize
+        {
+           // 224,23,17,128,220,175,105,53,33,8,0
+           0,4,8,16,32,64,96,128,160,192,224
+        },
+        //neg art
+        {
+           // 224,204,194,178,174,118,89,64,41,20,0
+           0,4,8,16,32,64,96,128,160,192,224
+        }
+    };
+    int i;
+    dbg_print("mt9v111_set_gamma to index :%d \n",index);
+    mt9v111_write_ifp_reg(regs[0],value[index][0]);
+    for(i=0; i<5; i++)
+    {
+        mt9v111_write_ifp_reg(regs[i+1],value[index][2*i+1]|(value[index][2*i+2]<<8));
+    }
+    return 0;
+}
+static int mt9v111_set_light(V4l_PIC_WB light)
+{
+    int index;
+    switch(light)
+    {
+        case V4l_WB_DIRECT_SUN:
+            index = 1;
+            break;
+        case V4l_WB_INCANDESCENT:
+            index = 2;
+            break;
+        case V4l_WB_FLUORESCENT:
+            index = 3;
+            break;
+        case V4l_WB_AUTO:
+            index = 0;
+            break;    
+        default:
+            dbg_print("incorrect light type!\n");
+            return -EFAULT;
+    }
+    return mt9v111_set_ccm(index);
+}
+static int mt9v111_set_style(V4l_PIC_STYLE style)
+{
+    if(style != V4l_STYLE_BLACK_WHITE)
+    {      
+        mt9v111_set_blackwhite(0);  
+    }
+    switch(style)
+    {
+    case V4l_STYLE_BLACK_WHITE:
+        mt9v111_set_gamma(0);
+        mt9v111_set_blackwhite(1);  
+        break;
+    case V4l_STYLE_SEPIA:
+        mt9v111_set_gamma(0);
+        mt9v111_set_ccm(4);
+        break;
+    case V4l_STYLE_SOLARIZE:
+        mt9v111_set_gamma(1);
+        break;
+    case V4l_STYLE_NEG_ART:
+        mt9v111_set_gamma(2);
+        break;
+    default:
+        mt9v111_set_gamma(0);
+        break;
+    }
+    return 0;
+}
+
+static inline int mt9v111_set_effects(p_camera_context_t cam_ctx)
+{
+    mt9v111_set_light(cam_ctx->capture_light);
+    mt9v111_set_style(cam_ctx->capture_style);
+    return 0;
+}
+static int mt9v111_reset(void)
+{
+   //stop and reset
+    mt9v111_write_core_reg(0x07, 0x0);
+    adcm2700_wait(20);
+    mt9v111_write_core_reg(0x0D, 0x1);
+    adcm2700_wait(5);
+    mt9v111_write_core_reg(0x0D, 0x0);
+    adcm2700_wait(5);
+    mt9v111_write_ifp_reg(0x07, 0x1);
+    adcm2700_wait(5);
+    mt9v111_write_ifp_reg(0x07, 0x0);
+
+    return 0;
+}
+static int mt9v111_set_flicker(int flicker)
+{
+/*
+    if (flicker == 50)
+    {
+        mt9v111_write(0x5b,0x01);
+    }
+    else if (flicker ==60)
+    {
+        mt9v111_write(0x5b,0x03);
+    }
+    else
+    {
+        return -EFAULT;
+    }
+*/
+    return 0;
+}
+/***********************************************************************
+ *
+ * MT9V111 Functions
+ *
+ ***********************************************************************/
+int camera_func_mt9v111_init( p_camera_context_t cam_ctx )
+{
+    u16 addr;
+    u16 reg_value;
+    const u16 values2[] = 
+    {
+        0x0006, 0xCE12, 0x00F0, 0x370D, 0xE20C, 0xFDF5,
+        0x280B, 0xDE0D, 0x00F4, 0x280A, 0xBD20, 0xF8E4,
+        0x1E0A, 0x0050, 0xD812, 0xFCEC, 0x1407, 0x0028,
+        0xD413, 0xFEEC, 0x1405, 0x0028
+    };
+    
+    ci_disable(1);
+    cam_ctx->mclk=12;
+    ci_set_clock(cam_ctx->clk_reg_base, 1, 1, cam_ctx->mclk);
+    ci_enable(1);
+    adcm2700_wait(10);
+    mt9v111_reset();
+    /* lens shading */
+    for(addr = 0x80; addr <= 0x95; addr++)
+    {
+        mt9v111_write_ifp_reg(addr, values2[addr-0x80]);
+    }
+    //accelerate AE speed
+    //mt9v111_write_ifp_reg(0x2f,0x80);
+    /* 100% sharpening */
+    //mt9v111_write_ifp_reg(0x05,0x0c);
+//codes from jason
+    //lens shading enable
+    //*
+    reg_value = mt9v111_read_ifp_reg(0x08);
+    reg_value |= 0x0100;
+    mt9v111_write_ifp_reg(0x08,reg_value);
+    //*/
+    mt9v111_write_core_reg(0x09,280);
+    mt9v111_write_core_reg(0x21,0xe401);
+    reg_value = mt9v111_read_core_reg(0x07);
+    reg_value &= ~(0x0010);
+    mt9v111_write_core_reg(0x07,reg_value);
+    mt9v111_write_core_reg(0x2f,0xe7b6);
+    mt9v111_write_ifp_reg(0x39,282);
+    mt9v111_write_ifp_reg(0x59,280);
+    mt9v111_write_ifp_reg(0x5a,336);
+    mt9v111_write_ifp_reg(0x5c,4624);
+    mt9v111_write_ifp_reg(0x5d,5652);
+    mt9v111_write_ifp_reg(0x25,0x4514);
+    //mt9v111_write_ifp_reg(0x25,0x6d14);
+    mt9v111_write_ifp_reg(0x34,0x0);
+    mt9v111_write_ifp_reg(0x35,0xff00);
+    mt9v111_write_ifp_reg(0x33,0x1411);
+    mt9v111_write_ifp_reg(0x3e,0x0fff);
+    mt9v111_write_ifp_reg(0x3b,0x042c);
+    mt9v111_write_ifp_reg(0x3d,0x01da);
+    mt9v111_write_ifp_reg(0x38,0x0878);
+    mt9v111_write_ifp_reg(0x40,0x1e10);
+    mt9v111_write_ifp_reg(0x41,0x1417);
+    mt9v111_write_ifp_reg(0x42,0x1213);
+    mt9v111_write_ifp_reg(0x43,0x1112);
+    mt9v111_write_ifp_reg(0x44,0x7110);
+    mt9v111_write_ifp_reg(0x45,0x7473);
+    
+    dbg_print("Mt9v111 init success!");
+    return 0;
+}
+
+int camera_func_mt9v111_deinit(  p_camera_context_t camera_context )
+{
+    //stop camera run
+    camera_func_mt9v111_stop_capture(camera_context);
+    ci_disable(1);
+    i2c_mt9v111_cleanup();
+    return 0;
+}
+
+int camera_func_mt9v111_set_capture_format(p_camera_context_t camera_context)
+{
+    adcm_window_size wsize;
+    u16 fmt_v1, fmt_v2;
+    u16 old1, old2;
+ 
+    //set sensor input/output window
+    wsize.width = camera_context->capture_width;
+    wsize.height = camera_context->capture_height;
+    mt9v111_output_size(&wsize);
+    dbg_print("output size width=%d, height=%d", wsize.width, wsize.height);
+    /*
+    0x08 output format contorl     bit 12 
+                                        1 RGB
+                                        0 YCbCr
+    0x3A output format control 2   bit 6-7
+                                        00 16-bit RGB565
+                                        01 15-bit RGB555
+                                        10 12-bit RGB444x
+                                        11 12-bit RGB444
+    refer to mt9v111-datasheet.pdf page 32 and page 39
+    */
+    old1 = mt9v111_read_ifp_reg(0x08);
+    old2 = mt9v111_read_ifp_reg(0x3A);
+    
+    // set sensor format
+    switch(camera_context->capture_input_format) 
+    {
+      case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+      case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+           dbg_print("output format YCBCR422");
+           fmt_v1 = 0;
+           fmt_v2 = 0;
+           break;
+        
+      case CAMERA_IMAGE_FORMAT_RGB565:
+          dbg_print("output format RGB565");
+          fmt_v1 = (1<<12);
+          fmt_v2 = 0;
+          break;
+        
+     case CAMERA_IMAGE_FORMAT_RGB444:
+          dbg_print("output format RGB444");
+          fmt_v1 = (1<<12);
+          fmt_v2 = (0x03<<6);
+          break;
+    
+     case CAMERA_IMAGE_FORMAT_RGB555:
+          dbg_print("output format RGB555");
+          fmt_v1 = (1<<12);
+          fmt_v2 = (0x01<<6);
+          break;
+        
+     default:
+          dbg_print("unsupported format!");
+          return -EFAULT;
+    }
+    
+    old1 = (old1 & ~(1<<12)) | fmt_v1;
+    old2 = ((old2 & ~(3<<6)) & (~0x03)) | fmt_v2; // | (2<<3)/*out test ramp*/;
+    mt9v111_write_ifp_reg(0x08, old1);
+    mt9v111_write_ifp_reg(0x3A, old2);
+    return 0;
+}
+
+int camera_func_mt9v111_start_capture(p_camera_context_t cam_ctx, unsigned int frames)
+{   
+    int cisr;
+    int wait_count = 1;
+    unsigned int start_time;
+    unsigned int flags;
+    int error_count = 0;
+    //mt9v111_restore_property(cam_ctx);
+restart:    
+    start_time = 0x1000000;
+    if(frames == 1)
+    {
+        wait_count = 2;
+    }
+    //mt9v111_write_core_reg(0x07, 0x0002);
+    dbg_print("wait for EOF %d time", wait_count);
+    ci_disable(1);
+    ci_enable(1);
+
+    start_time *= wait_count;
+    CISR|=CI_CISR_EOF;
+    cisr=CISR;
+    //local_irq_save(flags);
+    //mdelay(200);
+    while(wait_count)
+    {
+        if(cisr & CI_CISR_EOF)
+        {
+            wait_count -- ;
+            CISR|=CI_CISR_EOF;
+        }
+        cisr=CISR;
+        if(!(--start_time))
+        {
+           goto start_error;
+        }
+    }
+   // ci_clear_int_status(0xFFFFFFFF);
+    mdelay(1);
+    ci_reset_fifo();
+    ci_disable(1);
+    ci_enable(1);
+    start_dma_transfer(cam_ctx, 0);
+    //local_irq_restore(flags);
+    return 0;
+    
+start_error:
+    dbg_print("start error \n");
+    if(error_count++ > 3)
+    {
+       return -1;
+    }
+    ci_disable(1);
+    ci_enable(1);
+    adcm2700_wait(10);
+    mt9v111_reset();
+    mt9v111_restore_property(cam_ctx);
+    goto restart;
+    
+}
+
+int camera_func_mt9v111_stop_capture(  p_camera_context_t camera_context )
+{
+    /*
+    u16 old = mt9v111_read_core_reg(0x07);
+    old &= ~0x02;
+    mt9v111_write_core_reg(0x07, old);
+    */
+ //   stop_dma_transfer(camera_context);
+    return 0;
+}
+/*set output size*/
+static int pxa_cam_WCAM_VIDIOCSOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+  
+   adcm_window_size size;
+   CI_MP_TIMING     timing;
+   int ret = 0;
+   unsigned int  value;
+   memset(&timing, 0, sizeof(timing));
+   dbg_print("WCAM_VIDIOCSOSIZE");
+   if(copy_from_user(&size, param, sizeof(adcm_window_size))) 
+   {
+        return  -EFAULT;
+   }
+   size.height = (size.height+7)/8 * 8;
+   size.width  = (size.width +7)/8 * 8;
+   if(size.height != cam_ctx->capture_height || size.width != cam_ctx->capture_width)
+   {
+       cam_ctx->capture_width  = size.width;
+       cam_ctx->capture_height = size.height;
+       ret = mt9v111_output_size(&size);
+       timing.BFW = 0;
+       timing.BLW = 0;
+       ci_disable(1);
+       ci_configure_mp(cam_ctx->capture_width-1, cam_ctx->capture_height-1, &timing);
+       camera_ring_buf_init(cam_ctx);
+       ci_enable(1);
+       //mdelay(150);
+   }   
+   return ret;
+}
+
+/*read mt9v111 registers*/
+static int pxa_camera_WCAM_VIDIOCGCAMREG(p_camera_context_t cam_ctx, void *param)
+{
+  dbg_print("");
+  int data, reg_value;
+  if(copy_from_user(&data, param, sizeof(data))) 
+  {
+        return  -EFAULT;
+  }
+  u16 space = (u16)(data>>16);
+  u16 addr  = (u16)data;
+  
+  if(space == ADDRSPACE_CORE)
+  {
+    reg_value = mt9v111_read_core_reg(addr);
+  }
+  else if(space == ADDRSPACE_IFP)
+  {
+    reg_value = mt9v111_read_ifp_reg(addr);
+  }
+  else
+  {
+    return -EFAULT;
+  }
+  
+  if(copy_to_user(param, &reg_value, sizeof(int))) 
+  {
+       return -EFAULT;
+  }
+  return 0;
+}
+
+/*write mt9v111 registers*/
+static int pxa_camera_WCAM_VIDIOCSCAMREG(p_camera_context_t cam_ctx, void *param)
+{
+  dbg_print("");
+  
+  struct reg_set_s {int  val1, val2;}reg_value;
+  
+  if(copy_from_user(&reg_value, param, sizeof(reg_value))) 
+  {
+        return  -EFAULT;
+  }
+  
+  u16 space = (u16)(reg_value.val1 >> 16);
+  u16 addr  = (u16)(reg_value.val1);
+  
+  if(space == ADDRSPACE_CORE)
+  {
+    mt9v111_write_core_reg(addr, (u16)(reg_value.val2));
+  }
+  else if(space == ADDRSPACE_IFP)
+  {
+    mt9v111_write_ifp_reg(addr, (u16)(reg_value.val2));
+  }
+  else
+  {
+    return -EFAULT;
+  }
+  
+  return 0;
+}
+
+/*set sensor size*/
+static int pxa_cam_WCAM_VIDIOCSSSIZE(p_camera_context_t cam_ctx, void *param)
+{
+  dbg_print("");
+  adcm_window_size size;
+  int ret = 0;
+  if(copy_from_user(&size, param, sizeof(adcm_window_size))) 
+  {
+        return  -EFAULT;
+  }
+  size.width  = ((size.width+7)/8) * 8;
+  size.height = ((size.height+7)/8) *8;
+  if(size.width != cam_ctx->sensor_width || size.height != cam_ctx->sensor_height)
+  {
+      cam_ctx->sensor_width  = size.width;
+      cam_ctx->sensor_height = size.height;
+  
+      if(size.width > MT9V111_SENSOR_WIDTH || size.height > MT9V111_SENSOR_HEIGHT)
+      {
+        dbg_print("error input size width %d height %d",size.width, size.height);
+        return -EFAULT;
+      }
+  
+      ret = mt9v111_input_size(&size);
+  }
+  return ret;
+}
+
+/*set fps*/
+static int pxa_cam_WCAM_VIDIOCSFPS(p_camera_context_t cam_ctx, void *param)
+{
+  dbg_print("WCAM_VIDIOCSFPS");
+  struct {int fps, minfps;} cam_fps;
+  int ret = 0;
+
+  if(copy_from_user(&cam_fps, param, sizeof(int) * 2)) 
+  {
+        return  -EFAULT;
+  }
+  
+  if(cam_fps.minfps < 5)
+  {
+     cam_fps.minfps = 5;
+  }
+  if(cam_fps.fps >15)
+  {
+     cam_fps.fps = 15;
+  }
+  
+  if(cam_fps.fps != cam_ctx->fps || cam_fps.minfps != cam_ctx->mini_fps)
+  {
+     cam_ctx->fps =  cam_fps.fps;
+     cam_ctx->mini_fps = cam_fps.minfps;
+     ret = mt9v111_set_fps(cam_ctx->fps, cam_ctx->mini_fps);
+  }
+  
+  return ret;
+}
+/*set image style*/
+static int pxa_cam_WCAM_VIDIOCSSTYLE(p_camera_context_t cam_ctx, void *param)
+{
+    dbg_print("WCAM_VIDIOCSSTYLE");
+    int ret=0;
+    if(cam_ctx->capture_style != (V4l_PIC_STYLE)param)
+    {
+        cam_ctx->capture_style = (V4l_PIC_STYLE)param;
+        ret = mt9v111_set_effects(cam_ctx);
+    }
+    return ret;
+}
+/*set video light*/
+static int pxa_cam_WCAM_VIDIOCSLIGHT(p_camera_context_t cam_ctx, void *param)
+{
+    dbg_print("WACM_VIDIOCSLIGHT");
+    int ret=0;
+    if(cam_ctx->capture_light!= (V4l_PIC_WB)param)
+    {
+        cam_ctx->capture_light=(V4l_PIC_WB)param;
+        ret = mt9v111_set_effects(cam_ctx);
+    }
+    return ret;
+}
+/*set picture brightness*/
+static int pxa_cam_WCAM_VIDIOCSBRIGHT(p_camera_context_t cam_ctx, void *param)
+{
+    dbg_print("WCAM_VIDIOCSBRIGHT");
+    int ret =0;
+    if( cam_ctx->capture_bright !=  (int)param)
+    {
+        cam_ctx->capture_bright = (int)param;
+        ret=mt9v111_set_bright(cam_ctx->capture_bright);
+    }
+    return ret;
+}
+static int pxa_cam_WCAM_VIDIOCSFLICKER(p_camera_context_t cam_ctx, void * param)
+{
+   dbg_print("WCAM_VIDIOCSFLICKER");
+   cam_ctx->flicker_freq = (int)param;
+   return  mt9v111_set_flicker(cam_ctx->flicker_freq);
+}
+static int mt9v111_restore_property(p_camera_context_t cam_ctx)
+{    
+    adcm_window_size size;
+    
+    size.width = cam_ctx->sensor_width;
+    size.height= cam_ctx->sensor_height;
+    mt9v111_input_size(&size);
+    
+    camera_func_mt9v111_set_capture_format(cam_ctx);
+    
+    mt9v111_set_fps(cam_ctx->fps,cam_ctx->mini_fps);
+    
+    mt9v111_set_bright(cam_ctx->capture_bright);
+    
+    mt9v111_set_effects(cam_ctx);
+    
+    return 0;
+}
+int camera_func_mt9v111_pm_management(p_camera_context_t cam_ctx, int suspend)
+{
+   static int resume_dma = 0;
+   if(suspend)
+   {
+    if(cam_ctx != NULL )
+    {
+        if(cam_ctx->dma_started)
+        {
+            dbg_print("camera running, suspended");
+            stop_dma_transfer(cam_ctx);
+            resume_dma = 1;
+        }
+    }
+    disable_irq(IRQ_CAMERA);
+    pxa_set_cken(CKEN24_CAMERA, 0);
+   }
+   else
+   {
+       pxa_set_cken(CKEN24_CAMERA, 1);
+       if(cam_ctx != NULL)
+       {
+           dbg_print("camera running, resumed");
+           camera_init(cam_ctx);
+           mt9v111_restore_property(cam_ctx);
+           if(resume_dma == 1)
+           {
+               camera_start_video_capture(cam_ctx, 0);
+               resume_dma = 0;
+           }
+       }
+       enable_irq(IRQ_CAMERA);
+   } 
+   return  0;
+}
+
+int camera_func_mt9v111_docommand(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+   switch(cmd)
+   {
+       /*read mt9v111 registers*/
+    case WCAM_VIDIOCGCAMREG:
+         return pxa_camera_WCAM_VIDIOCGCAMREG(cam_ctx, param);
+
+        /*write mt9v111 registers*/
+    case WCAM_VIDIOCSCAMREG:
+          return pxa_camera_WCAM_VIDIOCSCAMREG(cam_ctx, param);
+        
+        /*set sensor size */  
+    case WCAM_VIDIOCSSSIZE:
+         return pxa_cam_WCAM_VIDIOCSSSIZE(cam_ctx, param);
+    
+        /*set output size*/
+    case WCAM_VIDIOCSOSIZE:
+         return pxa_cam_WCAM_VIDIOCSOSIZE(cam_ctx, param);
+         
+         /*set video mode fps*/
+    case WCAM_VIDIOCSFPS:
+         return pxa_cam_WCAM_VIDIOCSFPS(cam_ctx, param);
+            
+    /*set picture style*/  
+    case WCAM_VIDIOCSSTYLE:
+         return pxa_cam_WCAM_VIDIOCSSTYLE(cam_ctx, param);
+         
+    /*set picture light*/     
+    case WCAM_VIDIOCSLIGHT:
+         return pxa_cam_WCAM_VIDIOCSLIGHT(cam_ctx, param);
+    
+    /*set picture brightness*/
+    case WCAM_VIDIOCSBRIGHT:
+         return pxa_cam_WCAM_VIDIOCSBRIGHT(cam_ctx, param);
+    /*set flicker frequency*/
+    case WCAM_VIDIOCSFLICKER:
+         return pxa_cam_WCAM_VIDIOCSFLICKER(cam_ctx, param);
+    default:
+         {
+           dbg_print("Error cmd=0x%x", cmd);
+           return -EFAULT;
+         }
+    }
+  return 0;
+
+}
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9640.c linux-2.6.16.5-exz/drivers/media/video/ov9640.c
--- linux-2.6.16.5/drivers/media/video/ov9640.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9640.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,608 @@
+/* 
+    ov9640 - Omnivision 9640 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+
+#include <asm/pgtable.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+
+#include "camera.h"
+#include "ov9640.h"
+#include "ov9640_hw.h"
+
+
+#define MAX_WIDTH	1280
+#define MAX_HEIGHT	960
+#define MIN_WIDTH	88
+#define MIN_HEIGHT	72
+
+#define MAX_BPP		16
+#define WIDTH_DEFT	320
+#define HEIGHT_DEFT	240
+#define FRAMERATE_DEFT	0xf
+
+/*
+ * It is required to have at least 3 frames in buffer
+ * in current implementation
+ */
+#define FRAMES_IN_BUFFER	3
+#define MIN_FRAMES_IN_BUFFER	3
+#define MAX_FRAME_SIZE		(MAX_WIDTH * MAX_HEIGHT * (MAX_BPP >> 3))
+#define BUF_SIZE_DEFT		(MAX_FRAME_SIZE )
+#define SINGLE_DESC_TRANS_MAX  	PAGE_SIZE
+#define MAX_DESC_NUM		((MAX_FRAME_SIZE / SINGLE_DESC_TRANS_MAX + 1) *\
+				 MIN_FRAMES_IN_BUFFER)
+
+#define MAX_BLOCK_NUM	20
+extern ov9640 g_ov;
+
+camera_function_t ov9640_func = {
+	.init = camera_func_ov9640_init,
+	.deinit = camera_func_ov9640_deinit,
+	.set_capture_format = camera_func_ov9640_set_capture_format,
+	.start_capture = camera_func_ov9640_start_capture,
+	.stop_capture = camera_func_ov9640_stop_capture,
+	.command = camera_func_ov9640_command,
+	.pm_management = camera_func_ov9640_pm,
+};
+
+/***********************************************************************
+ *
+ * OV9640 Functions
+ *
+ ***********************************************************************/
+static void ov9640_gpio_init()
+{
+
+	set_GPIO_mode(27 | GPIO_ALT_FN_3_IN);	/* CIF_DD[0] */
+	set_GPIO_mode(114 | GPIO_ALT_FN_1_IN);	/* CIF_DD[1] */
+	set_GPIO_mode(51 | GPIO_ALT_FN_1_IN);	/* CIF_DD[2] */
+	set_GPIO_mode(115 | GPIO_ALT_FN_2_IN);	/* CIF_DD[3] */
+	set_GPIO_mode(95 | GPIO_ALT_FN_2_IN);	/* CIF_DD[4] */
+	set_GPIO_mode(94 | GPIO_ALT_FN_2_IN);	/* CIF_DD[5] */
+	set_GPIO_mode(17 | GPIO_ALT_FN_2_IN);	/* CIF_DD[6] */
+	set_GPIO_mode(108 | GPIO_ALT_FN_1_IN);	/* CIF_DD[7] */
+	set_GPIO_mode(23 | GPIO_ALT_FN_1_OUT);	/* CIF_MCLK */
+	set_GPIO_mode(54 | GPIO_ALT_FN_3_IN);	/* CIF_PCLK */
+	set_GPIO_mode(85 | GPIO_ALT_FN_3_IN);	/* CIF_LV */
+	set_GPIO_mode(84 | GPIO_ALT_FN_3_IN);	/* CIF_FV */
+	set_GPIO_mode(50 | GPIO_OUT);	/*CIF_PD */
+	set_GPIO_mode(19 | GPIO_IN);	/*CIF_RST */
+
+
+	return;
+
+}
+
+void ov9640_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz)
+{
+	unsigned int ciclk = 0, value, div, cccr_l, K;
+
+	// determine the LCLK frequency programmed into the CCCR.
+	cccr_l = (CCCR & 0x0000001F);
+
+	if (cccr_l < 8)		// L = [2 - 7]
+		ciclk = (13 * cccr_l) * 100;
+	else if (cccr_l < 17)	// L = [8 - 16]
+		ciclk = ((13 * cccr_l) * 100) >> 1;
+	else if (cccr_l < 32)	// L = [17 - 31]
+		ciclk = ((13 * cccr_l) * 100) >> 2;
+	DPRINTK(KERN_WARNING "the mclk_khz = %d \n", mclk_khz);
+
+	// want a divisor that gives us a clock rate as close to, but not more than the given mclk.
+	div = (ciclk + mclk_khz) / (2 * mclk_khz) - 1;
+
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCLK_EN | CI_CICR4_MCLK_EN | CI_CICR4_DIV_SMASK << CI_CICR4_DIV_SHIFT);
+	value |= (pclk_enable) ? CI_CICR4_PCLK_EN : 0;
+	value |= (mclk_enable) ? CI_CICR4_MCLK_EN : 0;
+	value |= div << CI_CICR4_DIV_SHIFT;
+	CICR4 = value;
+	return;
+}
+
+int camera_func_ov9640_init(p_camera_context_t cam_ctx)
+{
+	u8 cm_rev, cm_pid;
+	u32 timeout;
+	int status;
+	ov9640 *pov;
+
+	pov = &g_ov;
+	memset(pov, 0, sizeof(ov9640));
+
+	pov->pre_size = OV_SIZE_NONE;
+	pov->win.width = cam_ctx->capture_width;
+	pov->win.height = cam_ctx->capture_height;
+	// init context status
+	cam_ctx->dma_channels[0] = 0xFF;
+	cam_ctx->dma_channels[1] = 0xFF;
+	cam_ctx->dma_channels[2] = 0xFF;
+
+	cam_ctx->capture_width = WIDTH_DEFT;
+	cam_ctx->capture_height = HEIGHT_DEFT;
+
+	cam_ctx->capture_input_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+	cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+
+	cam_ctx->frame_rate = cam_ctx->fps = FRAMERATE_DEFT;
+
+	cam_ctx->mini_fps = FRAMERATE_DEFT - 2;
+
+	cam_ctx->buf_size = BUF_SIZE_DEFT;
+	cam_ctx->dma_descriptors_size = MAX_DESC_NUM;
+	DPRINTK(KERN_WARNING "dma_descriptors_size =%d,cam_ctx->buf_size=%d\n", cam_ctx->dma_descriptors_size,
+		cam_ctx->buf_size);
+	cam_ctx->vc.maxwidth = 1280;
+	cam_ctx->vc.maxheight = 960;
+	cam_ctx->vc.minwidth = MIN_WIDTH;
+	cam_ctx->vc.minheight = MIN_HEIGHT;
+	//DPRINTK( KERN_WARNING" before ov9640_gpio_init\n");
+	ov9640_gpio_init();
+	ci_init();
+	// Configure CI according to OV9640's hardware        
+	// master parallel with 8 data pins
+	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8);
+	// enable pixel clock(sensor will provide pclock) and master clock = 26MHZ
+	//ci_set_clock(cam_ctx->clk_reg_base, 1, 1, 26);
+	ov9640_set_clock(cam_ctx->clk_reg_base, 1, 1, 2400);
+	pov->mclock = 24;
+
+	// data sample on rising and h,vsync active high
+	ci_set_polarity(0, 0, 0);
+
+	// fifo control
+	// CISetFIFO(cam_ctx->ci_reg_base, 4000, XLLP_CI_FIFO_THL_32, XLLP_TRUE, XLLP_TRUE);
+	ci_set_fifo(0, CI_FIFO_THL_32, 1, 1);
+
+	// OV9640 Power on sequence
+	// Take out of Power down mode, PWRDWN=1, NORMAL=0
+	// Assert Reset
+	// Delay
+	// Remove reset
+	// Delay
+	ov9640_power_down(0);
+	ov9640_reset();
+	mdelay(1);
+
+	// init I2C.
+	status = i2c_init();
+	if (status)
+		return status;
+
+	// 2 Turn on M_CLK using xx MHz and wait for 150 ms. ??
+	ci_enable(1);
+	mdelay(20);
+
+	// read out version
+	//timeout = 50;
+	timeout = 5;
+	do {
+		cm_pid = cm_rev = 0;
+		status = ov9640_version_revision(&cm_pid, &cm_rev);
+
+		// Check to make sure we are working with an OV9640
+		if (cm_pid == PID_OV && cm_rev == PID_9640) {
+			int ver = (PID_OV << 8) | (PID_9640);
+			pov->version = ver;
+		}
+		else if (cm_pid == PID_OV_v3 || cm_rev == PID_9640_v3) {
+			int ver = (PID_OV_v3 << 8) | (PID_9640_v3);
+			pov->version = ver;
+		}
+		else {
+			ov9640_power_down(1);
+			ov9640_power_down(0);
+			ov9640_reset();
+			mdelay(1);
+		}
+		printk("in fun camera_func_ov9640_init version=%x\n", pov->version);
+		if (--timeout == 0)
+			return -1;
+	}
+	while (cm_pid != PID_OV);
+
+	cam_ctx->sensor_type = CAMERA_TYPE_OMNIVISION_9640;
+	// turn sensor output off
+	ov9640_viewfinder_off();
+
+	return 0;
+}
+
+int camera_func_ov9640_deinit(p_camera_context_t cam_ctx)
+{
+	//init the prev_xx value.
+	ov9640_set_format(OV_SIZE_NONE, OV_FORMAT_NONE);
+	mdelay(20);
+	// power off the external module
+	ov9640_power_down(1);
+
+	return 0;
+}
+
+int camera_func_ov9640_sleep(p_camera_context_t cam_ctx)
+{
+	camera_func_ov9640_deinit(cam_ctx);
+}
+
+int camera_func_ov9640_wake(p_camera_context_t cam_ctx)
+{
+	camera_func_ov9640_init(cam_ctx);
+}
+
+static get_ov_format(p_camera_context_t cam_ctx, u32 * size_format, u32 * color_format)
+{
+	u32 ovSizeFormat, ovFormat;
+
+	// Set the current mode
+	switch (cam_ctx->capture_input_format) {
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+		ovFormat = OV_FORMAT_YUV_422;
+		printk("in get_ov_format ovFormat = OV_FORMAT_YUV_422\n");
+		break;
+	case CAMERA_IMAGE_FORMAT_RGB565:
+		ovFormat = OV_FORMAT_RGB_565;
+		break;
+	default:
+		printk(KERN_INFO "The Format doesn't support by OV9640 Sensor \n");
+		return -1;
+	}
+	if (cam_ctx->capture_width == 88 && cam_ctx->capture_height == 72)
+		ovSizeFormat = OV_SIZE_QQCIF;
+	else if (cam_ctx->capture_width == 160 && cam_ctx->capture_height == 120)
+		ovSizeFormat = OV_SIZE_QQVGA;
+	else if (cam_ctx->capture_width == 176 && cam_ctx->capture_height == 144)
+		ovSizeFormat = OV_SIZE_QCIF;
+	else if (cam_ctx->capture_width == 320 && cam_ctx->capture_height == 240)
+		ovSizeFormat = OV_SIZE_QVGA;
+	else if (cam_ctx->capture_width == 352 && cam_ctx->capture_height == 288)
+		ovSizeFormat = OV_SIZE_CIF;
+	else if (cam_ctx->capture_width == 640 && cam_ctx->capture_height == 480)
+		ovSizeFormat = OV_SIZE_VGA;
+	else if (cam_ctx->capture_width == 1280 && cam_ctx->capture_height == 960)
+		ovSizeFormat = OV_SIZE_SXGA;
+	else {
+		return -1;
+	}
+	if (ovSizeFormat == OV_SIZE_QVGA)
+		printk("ovSizeFormat =OV_SIZE_QVGA \n");
+	*size_format = ovSizeFormat;
+	*color_format = ovFormat;
+	return 0;
+}
+
+int camera_func_ov9640_set_capture_format(p_camera_context_t cam_ctx)
+{
+	CI_MP_TIMING timing;
+	int status = -1;
+	u32 ovSizeFormat, ovFormat;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+	status = get_ov_format(cam_ctx, &ovSizeFormat, &ovFormat);
+	if (status)
+		return -1;
+
+	status = ov9640_set_format(ovSizeFormat, ovFormat);
+	if (status)
+		return -1;
+
+	// set capture width/height and timing 
+	//timing.BFW = pov->win.x;
+	//timing.BLW = pov->win.y;
+	timing.BFW = 0;
+	timing.BLW = 0;
+	//ci_configure_mp(pov->win.width - 1, pov->win.height - 1, &timing);
+
+	return status;
+}
+
+#define COPY_BUFFERS(pdes, p_page, size) \
+do { \
+	unsigned int len; \
+	unsigned int remain_size = size; \
+	while (remain_size > 0) { \
+		if (remain_size > PAGE_SIZE) \
+			len = PAGE_SIZE; \
+		else \
+			len = remain_size; \
+		if (memcpy(page_address(*pdes), page_address(*p_page), len)) \
+			return -EFAULT; \
+		remain_size -= len; \
+		pdes ++;\
+		p_page++; \
+	} \
+} while (0);
+
+int camera_func_ov9640_start_capture(p_camera_context_t cam_ctx, unsigned int frames)
+{
+	int status = -1;
+	u32 ovSizeFormat, ovFormat;
+	ov9640 *pov;
+	u8 value;
+
+	pov = &g_ov;
+
+	ci_disable(1);
+	mdelay(1);
+	ci_enable(1);
+	// clear ci fifo
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+
+	camera_set_int_mask(cam_ctx, 0x3ff | 0x0400);
+	// turn auto function on only doing continues capture
+	if (frames == 0) {
+//              CISR |= (1 << 3);
+//              while (!(CISR & (1 << 3)));     //Wait a EOF then begin start DMA
+		ov9640_auto_function_on();
+		// start dma
+		start_dma_transfer(cam_ctx, 0);
+	}
+	else {
+		status = get_ov_format(cam_ctx, &ovSizeFormat, &ovFormat);
+		if (status)
+			return -1;
+		if (pov->pre_size == OV_SIZE_NONE)
+			return -1;
+		printk("in function %s, cam_ctx->block_tail == 0\n", __FUNCTION__);
+		if (pov->pre_size == ovSizeFormat) {
+			if (cam_ctx->block_tail == 0) {
+			}
+			else {
+				struct page **p_page;
+				struct page **pdes;
+
+				printk("in function %s, cam_ctx->block_tail != 0\n", __FUNCTION__);
+				p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+				pdes = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo0_transfer_size);
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo1_transfer_size);
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo2_transfer_size);
+			}
+			set_still_image_ready(1);
+			return 0;
+		}
+		else {
+			ov9640_auto_function_off();
+			cam_ctx->block_tail = cam_ctx->block_header = 0;
+			ov9640_prepare_capture(cam_ctx, ovSizeFormat, ovFormat);
+		}
+		// turn viewfinder on
+		ov9640_viewfinder_on();
+	}
+	// turn viewfinder on
+	ov9640_viewfinder_on();
+	ov9640_read(0xc, &value);
+	ov9640_set_start();
+	return 0;
+}
+
+int Ov9640AutoFunctionOn()
+{
+	u8 regValue;
+
+	printk("in function %s \n", __FUNCTION__);
+	ov9640_read(0x13, &regValue);
+	if ((regValue & 0x7) == 7)
+		return 1;
+	return 0;
+}
+
+int camera_func_ov9640_stop_capture(p_camera_context_t cam_ctx)
+{
+	if (ov9640_output_stoped())
+		return 0;
+	printk("in camera_func_ov9640_stop_capture\n");
+	//if (Ov9640AutoFunctionOn())
+	ov9640_save_gains();
+	// turn auto function off
+	//ov9640_auto_function_off();
+
+	// turn viewfinder off
+	ov9640_viewfinder_off();
+	stop_dma_transfer(cam_ctx);
+	ov9640_set_stop(cam_ctx);
+	return 0;
+}
+
+int camera_func_ov9640_command(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+	int ret = 0;
+
+	printk("in function %s, param =%d, \n", __FUNCTION__, param);
+	switch (cmd) {
+		/* get capture size */
+	case VIDIOCGWIN:
+	{
+		struct video_window vw;
+		vw.width = cam_ctx->capture_width;
+		vw.height = cam_ctx->capture_height;
+		ov9640_get_window(&vw);
+		if (copy_to_user(param, &vw, sizeof(struct video_window)))
+			ret = -EFAULT;
+		break;
+	}
+
+		/* set capture size. */
+	case VIDIOCSWIN:
+	{
+		struct video_window vw;
+		if (copy_from_user(&vw, param, sizeof(vw))) {
+			ret = -EFAULT;
+			break;
+		}
+		printk("in %s, vw-x =%d, vw-y=%d,vw.width=%d,vw.height=%d\n",
+		       __FUNCTION__, vw.x, vw.y, vw.width, vw.height);
+		if (vw.width > 1280 || vw.height > 960 || vw.width < MIN_WIDTH || vw.height < MIN_HEIGHT) {
+			ret = -EFAULT;
+			break;
+		}
+		/*
+		 */
+		ov9640_set_window(&vw);
+		cam_ctx->capture_width = vw.width;
+		cam_ctx->capture_height = vw.height;
+		camera_set_capture_format(cam_ctx);
+		break;
+	}
+		/*set picture style */
+	case WCAM_VIDIOCSSTYLE:
+	{
+		V4l_PIC_STYLE capture_style;
+		capture_style = (V4l_PIC_STYLE) param;
+		cam_ctx->capture_style = (V4l_PIC_STYLE) param;
+		//ret = ov9640_set_special_effect(capture_style);
+		printk("in camera_func_ov9640_command ret=%d\n", ret);
+		if (cam_ctx->capture_style != V4l_STYLE_BLACK_WHITE && cam_ctx->capture_style != V4l_STYLE_SEPIA) {
+		}
+	}
+		break;
+		/*set picture light */
+	case WCAM_VIDIOCSLIGHT:
+		cam_ctx->capture_light = (int) param;
+		ret = ov9640_set_white_balance(param);
+		break;
+		/*set picture brightness */
+	case WCAM_VIDIOCSBRIGHT:
+		cam_ctx->capture_bright = (int) param;
+		//ret = ov9640_set_expose_compensation((int) param);
+		ret = ov9640_set_brightness((int) param);
+		break;
+		/*set sensor size */
+	case WCAM_VIDIOCSSSIZE:
+		return ov9640_set_sensor_size(cam_ctx, param);
+
+		/*get sensor size */
+	case WCAM_VIDIOCGSSIZE:
+		return ov9640_get_sensor_size(cam_ctx, param);
+
+		/*set output size */
+	case WCAM_VIDIOCSOSIZE:
+		return ov9640_set_output_size(cam_ctx, param);
+
+		/*get output size */
+	case WCAM_VIDIOCGOSIZE:
+		return ov9640_get_output_size(cam_ctx, param);
+#if 0
+#endif
+		/*set video mode fps */
+	case WCAM_VIDIOCSFPS:
+	{
+		struct {
+			int fps, minfps;
+		} cam_fps;
+		DPRINTK("WCAM_VIDIOCSFPS");
+		if (copy_from_user(&cam_fps, param, sizeof(int) * 2)) {
+			return -EFAULT;
+		}
+		cam_ctx->fps = cam_fps.fps;
+		cam_ctx->mini_fps = cam_fps.minfps;
+		return ov9640_set_fps(cam_fps.fps, cam_fps.minfps);
+	}
+		return -1;
+	case WCAM_VIDIOCSNIGHTMODE:
+	{
+		struct {
+			int mode, maxexpottime;
+		} cam_mode;
+		int mode;
+		if (copy_from_user(&cam_mode, param, sizeof(cam_mode))) {
+			return -EFAULT;
+		}
+		mode = cam_mode.mode;
+		if (mode == V4l_NM_NIGHT)
+			ov9640_set_night_mode();
+		if (mode == V4l_NM_ACTION)
+			ov9640_set_action_mode();
+		if (mode == V4l_NM_AUTO)
+			ov9640_set_auto_mode();
+	}
+		break;
+	case WCAM_VIDIOCSCONTRAST:
+	{
+		DPRINTK("WCAM_VIDIOCSCONTRAST  parameter=%d",param);
+		ret = ov9640_set_contrast((int)param/50);
+		break;
+	}
+	case WCAM_VIDIOCSFLICKER:
+	{
+		ret = ov9640_set_light_environment(param);
+		break;
+	}
+	default:
+		printk("in %s default case -----------------cmd =%d param=%d\n", __FUNCTION__, cmd, param);
+		ret = -1;
+	}
+	return ret;
+}
+int camera_func_ov9640_pm(p_camera_context_t cam_ctx, int suspend)
+{
+	static int resume_dma = 0;
+	if (suspend) {
+		if (cam_ctx != NULL) {
+			if (cam_ctx->dma_started) {
+				dbg_print("camera running, suspended");
+				stop_dma_transfer(cam_ctx);
+				resume_dma = 1;
+			}
+		}
+
+		disable_irq(IRQ_CAMERA);
+		CKEN &= ~CKEN24_CAMERA;
+	}
+	else {
+		CKEN |= CKEN24_CAMERA;
+		enable_irq(IRQ_CAMERA);
+
+		if (cam_ctx != NULL) {
+			dbg_print("camera running, resumed");
+			camera_init(cam_ctx);
+			//ov9640_restore_property(cam_ctx, 0);
+
+
+			if (resume_dma == 1) {
+				camera_start_video_capture(cam_ctx, 0);
+				resume_dma = 0;
+			}
+		}
+	}
+	return 0;
+}
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9640.h linux-2.6.16.5-exz/drivers/media/video/ov9640.h
--- linux-2.6.16.5/drivers/media/video/ov9640.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9640.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,67 @@
+/* 
+    ov9640 - Omnivision 9640 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+#ifndef _OV_9640_H_
+#define _OV_9640_H_
+
+#include <linux/videodev.h>
+#include "camera.h"
+typedef struct {
+	u32 version;
+	u32 stoped;
+	u32 mclock;
+	u32 pre_size;
+	u32 exp_value;
+	u32 exp_time;
+	u32 adjusted_exp_value;
+	u32 adjusted_exp_time;
+	u8 pclock;
+	u8 gain;
+	u8 blue_gain;
+	u8 red_gain;
+	u8 y_average;
+	u32 sensor_width;
+	u32 sensor_height;
+	u32 sub_win;
+	u32 night_mode;
+	struct video_window win;
+}ov9640;
+	
+//////////////////////////////////////////////////////////////////////////////////////
+//
+//          Prototypes
+//
+//////////////////////////////////////////////////////////////////////////////////////
+
+int camera_func_ov9640_init( p_camera_context_t );
+
+int camera_func_ov9640_deinit( p_camera_context_t );
+
+int camera_func_ov9640_sleep(  p_camera_context_t camera_context );
+
+int camera_func_ov9640_wake(  p_camera_context_t camera_context );
+
+int camera_func_ov9640_set_capture_format( p_camera_context_t );
+
+int camera_func_ov9640_start_capture( p_camera_context_t, unsigned int frames );
+
+int camera_func_ov9640_stop_capture( p_camera_context_t );
+
+int camera_func_ov9640_pm(p_camera_context_t cam_ctx, int suspend);
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9640_hw.c linux-2.6.16.5-exz/drivers/media/video/ov9640_hw.c
--- linux-2.6.16.5/drivers/media/video/ov9640_hw.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9640_hw.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,3034 @@
+/* 
+    ov9640_hw - Omnivision 9640 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/types.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/wrapper.h>
+#include <linux/delay.h>
+#include <linux/videodev.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+
+#include <linux/i2c.h>
+#include "camera.h"
+#include "ov9640.h"
+#include "ov9640_hw.h"
+
+ov9640 g_ov;
+/***********************************************************************
+*  Attention: This is platform related!
+***********************************************************************/
+static const u32 OV9640_PWRDWN_GPIO[2] = { 1, 50 };
+//static const u32 OV9640_RESET_GPIO[2] = { 1, xxx };
+volatile int ov9640_step = 0;
+
+/***********************************************************************
+*  Register Settings
+***********************************************************************/
+static u8 gDelta[] = {
+	OV9640_COM7,		//0x12
+	OV9640_COM1,		//0x04
+//      OV9640_CLKRC,           //0x11
+	OV9640_COM4,		//0x0d
+	OV9640_COM3,		//0x0c
+	OV9640_REGEND		// End of list delimiter.        
+};
+const static u8 gYUV_QQVGA[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x10,
+	OV9640_COM1, 0x24,
+	OV9640_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0xC0,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_QQCIF[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x08,
+	OV9640_COM1, 0x24,
+	OV9640_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0xC0,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_QVGA1[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x10,
+	OV9640_COM1, 0x00,
+	OV9640_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0xC0,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	/*
+	   OV9640_MTX1     , 0x3c,
+	   OV9640_MTX2     , 0x32,
+	   OV9640_MTX3     , 0x09,
+	   OV9640_MTX4     , 0x13,
+	   OV9640_MTX5     , 0x39,
+	   OV9640_MTX6     , 0x4c,
+	 */
+
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_VGA[] = {
+	0x15, 0x20,
+	0x12, 0x40,
+	0x04, 0x00,
+	0x11, 0x83,
+	//0x01  , 0x80,
+	//0x02  , 0x80,
+	0x0C, 0x05,
+	0x0D, 0xC0,
+	0x0E, 0x01,
+	0x0F, 0x4F,
+	0x13, 0x82,		//0x80
+	0x14, 0x4A,
+	0x1B, 0x01,
+	0x24, 0x78,
+	0x25, 0x70,
+	0x27, 0x90,
+	0x33, 0x08,
+	0x36, 0xC9,
+	0x3A, 0x08,
+	0x3B, 0x00,
+	0x3C, 0x46,
+	0x3D, 0x90,
+	0x3E, 0x02,
+	0x3F, 0xF2,
+	0x41, 0x02,
+	0x42, 0xC8,
+	0x43, 0xF0,
+	0x44, 0x10,
+	0x45, 0x5C,
+	0x46, 0x70,
+	0x47, 0x46,
+	0x48, 0x4D,
+	0x4F, 0x3C,
+	0x50, 0x32,
+	0x51, 0x09,
+	0x52, 0x13,
+	0x53, 0x39,
+	0x54, 0x4C,
+	0x59, 0x1F,
+	0x5A, 0x55,
+	0x5B, 0x43,
+	0x5C, 0x7C,
+	0x5D, 0x54,
+	0x5E, 0x0A,
+	0x5F, 0x01,
+	0x60, 0x94,
+	0x61, 0xCE,
+	0x6B, 0x3A,
+	0x6C, 0x40,
+	0x6D, 0x30,
+	0x6E, 0x4B,
+	0x6F, 0x60,
+	0x70, 0x70,
+	0x71, 0x70,
+	0x72, 0x70,
+	0x73, 0x70,
+	0x74, 0x60,
+	0x75, 0x60,
+	0x76, 0x50,
+	0x77, 0x48,
+	0x78, 0x3A,
+	0x79, 0x2E,
+	0x7A, 0x28,
+	0x7B, 0x22,
+	0x7C, 0x04,
+	0x7D, 0x07,
+	0x7E, 0x10,
+	0x7F, 0x28,
+	0x80, 0x36,
+	0x81, 0x44,
+	0x82, 0x52,
+	0x83, 0x60,
+	0x84, 0x6C,
+	0x85, 0x78,
+	0x86, 0x8C,
+	0x87, 0x9E,
+	0x88, 0xBB,
+	0x89, 0xD2,
+	0x8A, 0xE6,
+	0x13, 0xaF,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_QVGA[] = {
+	0x15, 0x20,
+	0x12, 0x10,
+	0x04, 0x00,
+	0x11, 0x81,
+	0x01, 0x80,
+	0x02, 0x24,
+	0x0C, 0x05,
+	0x0D, 0xC0,
+	0x0E, 0x01,
+	0x0F, 0x4F,
+	0x13, 0x80,		//0x82
+	0x14, 0x8A,
+	0x1B, 0x01,
+	0x24, 0x90,
+	0x25, 0x80,
+	0x2A, 0x00,
+	0x2b, 0x00,
+	0x27, 0x90,
+	0x33, 0x08,
+	0x36, 0xC9,
+	0x3A, 0x08,
+	0x3B, 0x00,
+	0x3C, 0x46,
+	0x3D, 0x90,
+	0x3E, 0x02,
+	0x3F, 0xa4,
+	0x41, 0x02,
+	0x42, 0xC8,
+	0x43, 0xF0,
+	0x44, 0x10,
+	0x45, 0x5C,
+	0x46, 0x70,
+	0x47, 0x46,
+	0x48, 0x4D,
+	0x4F, 0x3C,
+	0x50, 0x32,
+	0x51, 0x09,
+	0x52, 0x13,
+	0x53, 0x39,
+	0x54, 0x4C,
+	0x59, 0x1F,
+	0x5A, 0x55,
+	0x5B, 0x43,
+	0x5C, 0x7C,
+	0x5D, 0x54,
+	0x5E, 0x0A,
+	0x5F, 0x01,
+	0x60, 0x94,
+	0x61, 0xCE,
+	0x6B, 0x3A,
+	0x6C, 0x50,
+	0x6D, 0x60,
+	0x6E, 0x58,
+	0x6F, 0x58,
+	0x70, 0x58,
+	0x71, 0x50,
+	0x72, 0x50,
+	0x73, 0x50,
+	0x74, 0x50,
+	0x75, 0x50,
+	0x76, 0x4c,
+	0x77, 0x4c,
+	0x78, 0x45,
+	0x79, 0x3c,
+	0x7A, 0x2c,
+	0x7B, 0x24,
+	0x7C, 0x05,
+	0x7D, 0x0b,
+	0x7E, 0x16,
+	0x7F, 0x2c,
+	0x80, 0x37,
+	0x81, 0x41,
+	0x82, 0x4b,
+	0x83, 0x55,
+	0x84, 0x5f,
+	0x85, 0x69,
+	0x86, 0x7C,
+	0x87, 0x8f,
+	0x88, 0xB1,
+	0x89, 0xcf,
+	0x8A, 0xE5,
+	0x13, 0xad,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_CIF[] = {
+	0x15, 0x20,
+	0x12, 0x20,
+	0x04, 0x00,
+	0x11, 0x87,
+	//0x01  , 0x80,
+	//0x02  , 0x80,
+	0x0C, 0x05,
+	0x0D, 0xC0,
+	0x0E, 0x01,
+	0x0F, 0x4F,
+	0x13, 0x80,
+	0x14, 0x4A,
+	0x1B, 0x01,
+	0x24, 0x78,
+	0x25, 0x70,
+	0x27, 0x90,
+	0x33, 0x08,
+	0x36, 0xC9,
+	0x3A, 0x08,
+	0x3B, 0x00,
+	0x3C, 0x46,
+	0x3D, 0x90,
+	0x3E, 0x02,
+	0x3F, 0xF2,
+	0x41, 0x02,
+	0x42, 0xC8,
+	0x43, 0xF0,
+	0x44, 0x10,
+	0x45, 0x5C,
+	0x46, 0x70,
+	0x47, 0x46,
+	0x48, 0x4D,
+	0x4F, 0x3C,
+	0x50, 0x32,
+	0x51, 0x09,
+	0x52, 0x13,
+	0x53, 0x39,
+	0x54, 0x4C,
+	0x59, 0x1F,
+	0x5A, 0x55,
+	0x5B, 0x43,
+	0x5C, 0x7C,
+	0x5D, 0x54,
+	0x5E, 0x0A,
+	0x5F, 0x01,
+	0x60, 0x94,
+	0x61, 0xCE,
+	0x6B, 0x3A,
+	0x6C, 0x40,
+	0x6D, 0x30,
+	0x6E, 0x4B,
+	0x6F, 0x60,
+	0x70, 0x70,
+	0x71, 0x70,
+	0x72, 0x70,
+	0x73, 0x70,
+	0x74, 0x60,
+	0x75, 0x60,
+	0x76, 0x50,
+	0x77, 0x48,
+	0x78, 0x3A,
+	0x79, 0x2E,
+	0x7A, 0x28,
+	0x7B, 0x22,
+	0x7C, 0x04,
+	0x7D, 0x07,
+	0x7E, 0x10,
+	0x7F, 0x28,
+	0x80, 0x36,
+	0x81, 0x44,
+	0x82, 0x52,
+	0x83, 0x60,
+	0x84, 0x6C,
+	0x85, 0x78,
+	0x86, 0x8C,
+	0x87, 0x9E,
+	0x88, 0xBB,
+	0x89, 0xD2,
+	0x8A, 0xE6,
+	0x13, 0xaF,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+#if 0
+#endif
+const static u8 gYUV_QCIF[] = {
+	0x15, 0x20,
+	0x12, 0x08,
+	0x04, 0x00,
+	0x11, 0x87,
+	//0x01  , 0x80,
+	//0x02  , 0x80,
+	0x0C, 0x05,
+	0x0D, 0xC0,
+	0x0E, 0x01,
+	0x0F, 0x4F,
+	0x13, 0x80,
+	0x14, 0x4A,
+	0x1B, 0x01,
+	0x24, 0x78,
+	0x25, 0x70,
+	0x27, 0x90,
+	0x33, 0x08,
+	0x36, 0xC9,
+	0x3A, 0x08,
+	0x3B, 0x00,
+	0x3C, 0x46,
+	0x3D, 0x90,
+	0x3E, 0x02,
+	0x3F, 0xF2,
+	0x41, 0x02,
+	0x42, 0xC8,
+	0x43, 0xF0,
+	0x44, 0x10,
+	0x45, 0x5C,
+	0x46, 0x70,
+	0x47, 0x46,
+	0x48, 0x4D,
+	0x4F, 0x3C,
+	0x50, 0x32,
+	0x51, 0x09,
+	0x52, 0x13,
+	0x53, 0x39,
+	0x54, 0x4C,
+	0x59, 0x1F,
+	0x5A, 0x55,
+	0x5B, 0x43,
+	0x5C, 0x7C,
+	0x5D, 0x54,
+	0x5E, 0x0A,
+	0x5F, 0x01,
+	0x60, 0x94,
+	0x61, 0xCE,
+	0x6B, 0x3A,
+	0x6C, 0x40,
+	0x6D, 0x30,
+	0x6E, 0x4B,
+	0x6F, 0x60,
+	0x70, 0x70,
+	0x71, 0x70,
+	0x72, 0x70,
+	0x73, 0x70,
+	0x74, 0x60,
+	0x75, 0x60,
+	0x76, 0x50,
+	0x77, 0x48,
+	0x78, 0x3A,
+	0x79, 0x2E,
+	0x7A, 0x28,
+	0x7B, 0x22,
+	0x7C, 0x04,
+	0x7D, 0x07,
+	0x7E, 0x10,
+	0x7F, 0x28,
+	0x80, 0x36,
+	0x81, 0x44,
+	0x82, 0x52,
+	0x83, 0x60,
+	0x84, 0x6C,
+	0x85, 0x78,
+	0x86, 0x8C,
+	0x87, 0x9E,
+	0x88, 0xBB,
+	0x89, 0xD2,
+	0x8A, 0xE6,
+	0x13, 0xaF,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_QCIF1[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x08,
+	OV9640_COM1, 0x00,
+	OV9640_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0xC0,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+
+const static u8 gYUV_VGA1[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x40,
+	OV9640_COM1, 0x00,
+	OV9640_CLKRC, 0x00,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0x40,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.        
+};
+
+const static u8 gYUV_CIF1[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x20,
+	OV9640_COM1, 0x00,
+	OV9640_CLKRC, 0x00,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x5,	//0x04
+	OV9640_COM4, 0x40,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x8,
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.        
+};
+
+const static u8 gYUV_SXGA[] = {
+	OV9640_COM10, 0x20,
+	OV9640_COM7, 0x00,
+	OV9640_COM1, 0x00,
+	OV9640_CLKRC, 0x80,
+
+	// From OmniVision
+	OV9640_COM8, 0x8D,
+	OV9640_BLUE, 0x80,
+	OV9640_RED, 0x80,
+	OV9640_COM3, 0x1,	//0x04
+	OV9640_COM4, 0x40,
+	OV9640_COM6, 0x4E,	//0x4F
+	OV9640_COM9, 0x4A,	//0x0A
+	OV9640_PSHFT, 0x1,
+	OV9640_AEW, 0x78,
+	OV9640_AEB, 0x70,
+	OV9640_BBIAS, 0x90,
+	OV9640_CHLF, 0x8,
+	OV9640_VIDO, 0xC9,
+	OV9640_TSLB, 0x0,	//0x8
+	OV9640_COM11, 0x8,
+	OV9640_COM12, 0x46,
+	OV9640_COM13, 0x90,
+	OV9640_COM14, 0x2,
+	OV9640_EDGE, 0xA4,
+	OV9640_COM16, 0x2,
+	OV9640_COM17, 0xC8,
+	OV9640_AWBTH1, 0xF0,
+	OV9640_AWBTH2, 0x10,
+	OV9640_AWBTH3, 0x5C,
+	OV9640_AWBTH4, 0x70,
+	OV9640_AWBTH5, 0x46,
+	OV9640_AWBTH6, 0x4D,
+	OV9640_MTX1, 0x63,
+	OV9640_MTX2, 0x4E,
+	OV9640_MTX3, 0x15,
+	OV9640_MTX4, 0x1D,
+	OV9640_MTX5, 0xBE,
+	OV9640_MTX6, 0xDC,
+	OV9640_MTXS, 0xF,
+	OV9640_AWBC1, 0x1F,
+	OV9640_AWBC2, 0x55,
+	OV9640_AWBC3, 0x43,
+	OV9640_AWBC4, 0x7C,
+	OV9640_AWBC5, 0x54,
+	OV9640_AWBC6, 0xA,
+	OV9640_AWBC7, 0x5,
+	OV9640_AWBC8, 0x14,
+	OV9640_AWBC9, 0xCE,
+	OV9640_DBLV, 0x3A,
+	OV9640_GST0, 0x2,
+	OV9640_GSP0, 0x40,
+	OV9640_GSP1, 0x30,
+	OV9640_GSP2, 0x4B,
+	OV9640_GSP3, 0x60,
+	OV9640_GSP4, 0x70,
+	OV9640_GSP5, 0x70,
+	OV9640_GSP6, 0x70,
+	OV9640_GSP7, 0x70,
+	OV9640_GSP8, 0x60,
+	OV9640_GSP9, 0x60,
+	OV9640_GSP10, 0x50,
+	OV9640_GSP11, 0x48,
+	OV9640_GSP12, 0x3A,
+	OV9640_GSP13, 0x2E,
+	OV9640_GSP14, 0x28,
+	OV9640_GSP15, 0x22,
+	OV9640_GST0, 0x4,
+	OV9640_GST1, 0x7,
+	OV9640_GST2, 0x10,
+	OV9640_GST3, 0x28,
+	OV9640_GST4, 0x36,
+	OV9640_GST5, 0x44,
+	OV9640_GST6, 0x52,
+	OV9640_GST7, 0x60,
+	OV9640_GST8, 0x6C,
+	OV9640_GST9, 0x78,
+	OV9640_GST10, 0x8C,
+	OV9640_GST11, 0x9E,
+	OV9640_GST12, 0xBB,
+	OV9640_GST13, 0xD2,
+	OV9640_GST14, 0xE6,
+	OV9640_COM8, 0x8F,
+	OV9640_REGEND, 0x00	// End of list delimiter.        
+};
+
+
+const static u8 gRGB_QQVGA[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_QVGA[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_QCIF[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+
+const static u8 gRGB_VGA[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_CIF[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_SXGA[] = {
+	OV9640_COM7, 0x80,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_QVGA_v3[] = {
+	0x11, 0x83,
+	0x12, 0x10,
+//      0x13, 0xA8,
+	0x01, 0x80,
+	0x02, 0x80,
+	0x04, 0x00,
+	0x0C, 0x05,
+	0x0D, 0xC0,
+	0x0E, 0x81,
+	0x0F, 0x4F,
+	0x14, 0x8A,
+	0x16, 0x02,
+	0x1B, 0x01,
+	0x24, 0x70,
+	0x25, 0x68,
+	0x26, 0xD1,
+	0x27, 0x88,
+	0x2A, 0x00,
+	0x2B, 0x00,
+	0x2c, 0x88,
+	0x33, 0x02,
+	0x37, 0x05,
+	0x38, 0x13,
+	0x39, 0xF0,
+	0x3A, 0x0C,
+	0x3B, 0x01,
+	0x3C, 0x46,
+	0x3D, 0x90,
+	0x3E, 0x02,
+	0x3F, 0xa4,
+	0x41, 0x02,
+	0x42, 0xC8,
+
+	/*
+	   0x43, 0xF0,
+	   0x44, 0x10,
+	   0x45, 0x5C,
+	   0x46, 0x70,
+	   0x47, 0x46,
+	   0x48, 0x4d,
+
+	   0x43, 0xF0,
+	   0x44, 0x10,
+	   0x45, 0x6C,
+	   0x46, 0x6c,
+	   0x47, 0x44,
+	   0x48, 0x44,
+	 */
+
+	0x43, 0xF0,
+	0x44, 0x10,
+	0x45, 0x20,
+	0x46, 0x20,
+	0x47, 0x20,
+	0x48, 0x20,
+
+	0x49, 0x03,
+	0x4f, 0x3c,
+	0x50, 0x32,
+	0x51, 0x09,
+	0x52, 0x13,
+	0x53, 0x39,
+	0x54, 0x4c,
+
+	/*
+	   0x59, 0x1f,
+	   0x5A, 0x55,
+	   0x5B, 0x43,
+	   0x5C, 0x7c,
+	   0x5D, 0x54,
+	   0x5E, 0x0a,
+	   0x5F, 0x01,
+	   0x60, 0x94,
+	   0x61, 0xCE,
+
+	   0x59, 0x49,
+	   0x5A, 0x94,
+	   0x5B, 0x46,
+	   0x5C, 0x84,
+	   0x5D, 0x5c,
+	   0x5E, 0x08,
+	   0x5F, 0x00,
+	   0x60, 0x14,
+	   0x61, 0xCE,
+	 */
+	0x59, 0x27,
+	0x5A, 0x72,
+	0x5B, 0x56,
+	0x5C, 0x7a,
+	0x5D, 0x5d,
+	0x5E, 0x17,
+	0x5F, 0x00,
+	0x60, 0x14,
+	0x61, 0xCE,
+	0x62, 0x78,
+	0x63, 0x00,
+	0x64, 0x04,
+	0x65, 0x50,
+	0x66, 0x01,
+	0x69, 0x00,
+	0x6A, 0x3d,		//for QVGA 3e-->3d, 
+	0x6B, 0x3F,
+	/*
+	   0x6C, 0x50,
+	   0x6D, 0x60,
+	   0x6E, 0x58,
+	   0x6F, 0x58,
+	   0x70, 0x58,
+	   0x71, 0x50,
+	   0x72, 0x50,
+	   0x73, 0x50,
+	   0x74, 0x50,
+	   0x75, 0x50,
+	   0x76, 0x4c,
+	   0x77, 0x4c,
+	   0x78, 0x45,
+	   0x79, 0x3c,
+	   0x7A, 0x2c,
+	   0x7B, 0x24,
+	   0x7C, 0x05,
+	   0x7D, 0x0b,
+	   0x7E, 0x16,
+	   0x7F, 0x2c,
+	   0x80, 0x37,
+	   0x81, 0x41,
+	   0x82, 0x4b,
+	   0x83, 0x55,
+	   0x84, 0x5f,
+	   0x85, 0x69,
+	   0x86, 0x7C,
+	   0x87, 0x8f,
+	   0x88, 0xB1,
+	   0x89, 0xcf,
+	   0x8A, 0xE5,
+	 */
+	0x6C, 0x40,
+	0x6D, 0x30,
+	0x6E, 0x4B,
+	0x6F, 0x60,
+	0x70, 0x70,
+	0x71, 0x70,
+	0x72, 0x70,
+	0x73, 0x70,
+	0x74, 0x60,
+	0x75, 0x60,
+	0x76, 0x50,
+	0x77, 0x48,
+	0x78, 0x3A,
+	0x79, 0x2E,
+	0x7A, 0x28,
+	0x7B, 0x22,
+	0x7C, 0x04,
+	0x7D, 0x07,
+	0x7E, 0x10,
+	0x7F, 0x28,
+	0x80, 0x36,
+	0x81, 0x44,
+	0x82, 0x52,
+	0x83, 0x60,
+	0x84, 0x6C,
+	0x85, 0x78,
+	0x86, 0x8C,
+	0x87, 0x9E,
+	0x88, 0xBB,
+	0x89, 0xD2,
+	0x8A, 0xE6,
+	/*
+	 */
+	0x13, 0xAF,
+	OV9640_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gSensorSlaveAddr = 0x30;
+
+int i2c_init(void)
+{
+	return i2c_ov9640_init();
+}
+
+int i2c_deinit(void)
+{
+	return i2c_ov9640_cleanup();
+}
+
+/***********************************************************************
+*  Private/helper api
+***********************************************************************/
+static int prv_get_reg_value(u8 * regP, u8 regAddr, u8 * regValueP)
+{
+	unsigned int index = 0;
+	u8 curReg = 0;
+	while (curReg < OV9640_REGEND) {
+		curReg = regP[index << 1];
+		if (curReg == regAddr) {
+			*regValueP = regP[(index << 1) + 1];
+			return 0;
+		}
+		index++;
+	}
+
+	return -1;
+
+}
+
+static int prv_set_reg_value(u8 * regP, u8 regAddr, u8 regValue)
+{
+	unsigned int index = 0;
+	u8 curReg = 0;
+
+	while (curReg < OV9640_REGEND) {
+		curReg = regP[index << 1];
+		if (curReg == regAddr) {
+			regP[(index << 1) + 1] = regValue;
+			return 0;
+		}
+		index++;
+	}
+
+	return -1;
+
+}
+
+/***********************************************************************
+*  Sensor read/write 
+***********************************************************************/
+static int prv_read_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return ov9640_read(subAddress, bufP);
+}
+
+static int prv_write_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return ov9640_write(subAddress, *bufP);
+}
+
+static int prv_RMW_sensor_reg(const u8 subAddress, u8 * bufP, u8 andMask, u8 orMask)
+{
+	int status;
+	status = prv_read_sensor_reg(subAddress, bufP);
+	if (!status) {
+		*bufP &= andMask;
+		*bufP |= orMask;
+		status = prv_write_sensor_reg(subAddress, bufP);
+	}
+	return status;
+}
+
+int ov9640_read_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return prv_read_sensor_reg(subAddress, bufP);
+}
+
+int ov9640_write_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return prv_write_sensor_reg(subAddress, bufP);
+}
+
+int ov9640_set_regs(u8 * regP)
+{
+	u32 curReg = 0;
+	int status = 0;
+
+	// The list is a register number followed by the value.
+	while (regP[curReg << 1] < OV9640_REGEND) {
+		status = prv_write_sensor_reg(regP[curReg << 1], &regP[(curReg << 1) + 1]);
+		if (curReg == 0)
+			ov9640_wait(1);
+
+		curReg++;
+	}
+	return status;
+}
+
+int ov9640_read_all_regs(u8 * bufP, u32 numRegs)
+{
+	u32 curReg;
+
+	for (curReg = 0; curReg < numRegs; curReg++, bufP++)
+		prv_read_sensor_reg(curReg, bufP);
+
+	return 0;
+}
+
+/***********************************************************************
+*  Power & Reset
+***********************************************************************/
+void ov9640_power_down(int powerDown)
+{
+	// OV9640 PWRDWN, 0 = NORMAL, 1=POWER DOWN
+	//GPDR1 |= GPIO_bit(50);
+	//OV9640 reset CIF_RST, 0 = NORMAL, 1=RESET
+	//GPDR0 |= GPIO_bit(19);
+	if (powerDown == 1) {
+		mdelay(200);
+		ov9640_soft_reset();
+		ov9640_write(0x39, 0xf4);
+		ov9640_write(0x1e, 0x80);
+		ov9640_write(0x6b, 0x3f);
+		ov9640_write(0x36, 0x49);
+		ov9640_write(0x12, 0x05);
+		mdelay(800);
+		GPSR1 = GPIO_bit(50);
+	}
+	else {
+		ov9640_write(0x39, 0xf0);
+		ov9640_write(0x1e, 0x00);
+		ov9640_write(0x6b, 0x3f);
+		ov9640_write(0x36, 0x49);
+		ov9640_write(0x12, 0x10);
+		GPCR1 = GPIO_bit(50);
+		//GPSR0 = GPIO_bit(19);
+		mdelay(20);
+		//GPCR0 = GPIO_bit(19);
+	}
+	mdelay(100);
+}
+
+void ov9640_soft_reset(void)
+{
+	u8 regValue;
+	regValue = 0x80;
+	prv_write_sensor_reg(OV9640_COM7, &regValue);
+	mdelay(10);
+	return;
+}
+
+void ov9640_reset(void)
+{
+	// do nothing on Zoar
+	return 0;
+}
+
+void ov9640_wait(int ms)
+{
+	mdelay(ms);
+}
+
+int ov9640_output_stoped()
+{
+	ov9640 *pov;
+	pov = &g_ov;
+	return pov->stoped;
+}
+
+void ov9640_set_start()
+{
+	ov9640 *pov;
+	pov = &g_ov;
+
+	pov->stoped = 0;
+}
+
+void ov9640_set_stop(p_camera_context_t cam_ctx)
+{
+	ov9640 *pov;
+	pov = &g_ov;
+
+	pov->stoped = 1;
+}
+
+/***********************************************************************
+*  Settings
+***********************************************************************/
+int ov9640_version_revision(u8 * pCmRevision, u8 * pSensorRevision)
+{
+	prv_read_sensor_reg(OV9640_PID, pCmRevision);
+	prv_read_sensor_reg(OV9640_VER, pSensorRevision);
+	return 0;
+}
+
+void ov9640_set_HSYNC(void)
+{
+	u8 val;
+
+	// Makes HREF become HSYNC
+	prv_read_sensor_reg(OV9640_COM10, &val);
+	val |= 0x40;
+	prv_write_sensor_reg(OV9640_COM10, &val);
+}
+
+void ov9640_auto_function_on(void)
+{
+	u8 val;
+	DPRINTK("in function %s\n", __FUNCTION__);
+	prv_read_sensor_reg(OV9640_COM8, &val);
+	val |= 0x07;
+	prv_write_sensor_reg(OV9640_COM8, &val);
+}
+
+void ov9640_auto_function_off(void)
+{
+	u8 val;
+	DPRINTK("in function %s\n", __FUNCTION__);
+	prv_read_sensor_reg(OV9640_COM8, &val);
+	val &= ~0x07;
+	prv_write_sensor_reg(OV9640_COM8, &val);
+}
+
+
+/***********************************************************************
+*  Viewfinder, still 
+***********************************************************************/
+int ov9640_viewfinder_on(void)
+{
+	u8 com3;
+
+	prv_read_sensor_reg(OV9640_COM3, &com3);
+	com3 &= ~0x01;
+	prv_write_sensor_reg(OV9640_COM3, &com3);
+
+	return OV_ERR_NONE;
+}
+
+
+int ov9640_viewfinder_off(void)
+{
+	u8 com3;
+
+	prv_read_sensor_reg(OV9640_COM3, &com3);
+	com3 |= 0x01;
+	prv_write_sensor_reg(OV9640_COM3, &com3);
+
+	mdelay(200);
+	return OV_ERR_NONE;
+}
+
+
+int ov9640_halt_video_output(void)
+{
+	u8 com3;
+
+	// Set the camera to only output 1 frame.
+	prv_read_sensor_reg(OV9640_COM3, &com3);
+	com3 |= 1;
+	prv_write_sensor_reg(OV9640_COM3, &com3);
+
+	return OV_ERR_NONE;
+}
+
+int ov9640_resume_to_full_output_mode(void)
+{
+	u8 mode;
+
+	// Output still frames continuously
+	// Turn off single capture mode COM3.
+	prv_RMW_sensor_reg(OV9640_COM3, (&mode), ((u8) ~ 1), 0);
+	return OV_ERR_NONE;
+}
+
+int ov9640_get_single_image(void)
+{
+	u8 mode;
+
+	prv_RMW_sensor_reg(OV9640_COM3, &mode, (u8) ~ 1, 1);
+	return OV_ERR_NONE;
+}
+static u8 *ov9640_get_regs_list(u32 captureSizeFormat, u32 colorFormat)
+{
+	char *formatNameP;
+	u8 *defaultDataP = NULL;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+
+	// Get the default setting.
+	if (colorFormat == OV_FORMAT_YUV_422) {
+		switch (captureSizeFormat) {
+		case OV_SIZE_QQVGA:
+			defaultDataP = gYUV_QQVGA;
+			formatNameP = "QQVGA.422";
+			break;
+		case OV_SIZE_QQCIF:
+			defaultDataP = gYUV_QQCIF;
+			formatNameP = "QQCIF.422";
+			break;
+		case OV_SIZE_QVGA:
+			defaultDataP = gYUV_QVGA;
+			formatNameP = "QVGA.422";
+			//version 3 support:
+			if (pov->version == ((PID_OV_v3 << 8) | (PID_9640_v3))) {
+				DPRINTK("ver 3 sensor!\n");
+				defaultDataP = gYUV_QVGA_v3;
+			}
+			break;
+		case OV_SIZE_QCIF:
+			defaultDataP = gYUV_QCIF;
+			formatNameP = "QCIF.422";
+			break;
+		case OV_SIZE_VGA:
+			defaultDataP = gYUV_VGA;
+			formatNameP = "VGA.422";
+			break;
+		case OV_SIZE_CIF:
+			defaultDataP = gYUV_CIF;
+			formatNameP = "CIF.422";
+			break;
+		case OV_SIZE_SXGA:
+			defaultDataP = gYUV_SXGA;
+			formatNameP = "SXGA.422";
+			break;
+		default:
+			return NULL;
+		}
+	}
+
+	if (colorFormat == OV_FORMAT_RGB_565) {
+		switch (captureSizeFormat) {
+		case OV_SIZE_QQVGA:
+			defaultDataP = gRGB_QQVGA;
+			formatNameP = "QQVGA.RGB";
+			break;
+		case OV_SIZE_QCIF:
+			defaultDataP = gRGB_QCIF;
+			formatNameP = "QCIF.RGB";
+			break;
+
+		case OV_SIZE_QVGA:
+			defaultDataP = gRGB_QVGA;
+			formatNameP = "QVGA.RGB";
+			break;
+		case OV_SIZE_VGA:
+			defaultDataP = gRGB_VGA;
+			formatNameP = "VGA.RGB";
+			break;
+		case OV_SIZE_CIF:
+			defaultDataP = gRGB_CIF;
+			formatNameP = "CIF.RGB";
+			break;
+		case OV_SIZE_SXGA:
+			defaultDataP = gRGB_SXGA;
+			formatNameP = "SXGA.RGB";
+			break;
+		default:
+			return NULL;
+		}
+	}
+	return defaultDataP;
+}
+
+/***********************************************************************
+*  Format 
+***********************************************************************/
+int ov9640_set_format(u32 captureSizeFormat, u32 colorFormat)
+{
+	int status = OV_ERR_PARAMETER;
+	u8 *regsP, regValue;
+	unsigned int index = 0;
+	u8 curReg = 0;
+	static u32 prev_colorFormat = OV_FORMAT_NONE, prev_size = OV_SIZE_NONE;
+
+	if (prev_colorFormat == colorFormat && captureSizeFormat == prev_size)
+		return 0;
+	if ((captureSizeFormat == OV_SIZE_NONE) && (colorFormat == OV_FORMAT_NONE))
+		goto no_set;
+
+	if ((prev_colorFormat == OV_FORMAT_NONE) && (prev_size == OV_SIZE_NONE)) {
+		regsP = (u8 *) ov9640_get_regs_list(captureSizeFormat, colorFormat);
+		// Get the pointer to the basic setting.  The pointer must be freed after exiting.
+
+		if (regsP == NULL)
+			return OV_ERR_PARAMETER;
+		ov9640_soft_reset();
+		// Blast the entire parameter tree into the part.
+		status = ov9640_set_regs(regsP);
+	}
+	else {
+		status = ov9640_switch_format(captureSizeFormat, colorFormat);
+	}
+      no_set:
+	prev_colorFormat = colorFormat;
+	prev_size = captureSizeFormat;
+	return status;
+}
+
+void ov9640_save_gains()
+{
+	u8 gain, aech, aecl, laec, blue, red;
+	ov9640 *pov;
+	u8 regValue;
+	u32 current_size;
+
+	pov = &g_ov;
+
+	// Get current size
+	prv_read_sensor_reg(OV9640_COM7, &regValue);
+	switch (regValue) {
+	case 0x00:
+		current_size = OV_SIZE_SXGA;
+		break;
+	case 0x08:
+		prv_read_sensor_reg(OV9640_COM1, &regValue);
+		if (regValue & 0x20)
+			current_size = OV_SIZE_QQCIF;
+		else
+			current_size = OV_SIZE_QCIF;
+		break;
+	case 0x10:
+		prv_read_sensor_reg(OV9640_COM1, &regValue);
+		if (regValue & 0x20)
+			current_size = OV_SIZE_QQVGA;
+		else
+			current_size = OV_SIZE_QVGA;
+		break;
+	case 0x20:
+		current_size = OV_SIZE_CIF;
+		break;
+	case 0x40:
+		current_size = OV_SIZE_VGA;
+		break;
+	default:
+		current_size = OV_SIZE_SXGA;
+		break;
+	}
+	pov->pre_size = current_size;
+
+	// Get the awb, gain, exposure values
+	prv_read_sensor_reg(OV9640_BLUE, &blue);
+	prv_read_sensor_reg(OV9640_RED, &red);
+	prv_read_sensor_reg(OV9640_GAIN, &gain);
+	gain &= 0x3F;
+	prv_read_sensor_reg(OV9640_AECH, &aech);
+	prv_read_sensor_reg(OV9640_COM1, &aecl);
+	aecl &= 0x3;
+	prv_read_sensor_reg(OV9640_LAEC, &laec);
+
+	pov->gain = gain;
+	pov->blue_gain = blue;
+	pov->red_gain = red;
+	pov->exp_value = (aech << 2) | aecl;
+	pov->exp_time = laec;
+
+}
+
+void ov9640_adjust_gains(u32 prev_size, u32 cur_size)
+{
+	u8 expMultiple = 1;
+	u8 gain;
+	ov9640 *pov;
+
+	pov = &g_ov;
+	if (prev_size == OV_SIZE_QVGA) {
+		if (cur_size == OV_SIZE_VGA) {
+			if (pov->gain & 0x20) {
+				/* hight gain capture 7.5 fps */
+				pov->pclock = 0x83;
+				pov->gain = pov->gain & ~0x20;
+				pov->adjusted_exp_value = pov->exp_value * 2;
+			}
+			else {
+				/* capture 15 fps */
+				pov->pclock = 0x81;
+				pov->adjusted_exp_value = pov->exp_value * 2;
+			}
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x87;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x80;
+			}
+		}
+		else if (cur_size == OV_SIZE_SXGA) {
+			if (pov->gain & 0x20) {
+				/* 8x gain capture 7.5 fps to 4x gain */
+				pov->pclock = 0x80;
+				pov->gain = pov->gain & ~0x20;
+				pov->adjusted_exp_value = pov->exp_value * 4;
+			}
+			else if (pov->gain & 0x10) {
+				/* 4x gain capture 7.5 fps to 2x gain */
+				pov->pclock = 0x80;
+				pov->gain = pov->gain & ~0x10;
+				pov->adjusted_exp_value = pov->exp_value * 4;
+			}
+			else {
+				pov->pclock = 0x80;
+				pov->adjusted_exp_value = pov->exp_value * 2;
+			}
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x81;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x80;
+			}
+		}
+		else if (cur_size == OV_SIZE_QVGA) {
+			if (pov->gain & 0x20) {
+				/* hight gain capture 7.5 fps */
+				pov->pclock = 0x87;
+				pov->gain = pov->gain & ~0x20;
+				pov->adjusted_exp_value = pov->exp_value;
+			}
+			else {
+				/* capture 15 fps */
+				pov->pclock = 0x83;
+				pov->adjusted_exp_value = pov->exp_value;
+			}
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x89;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x81;
+			}
+		}
+		pov->red_gain=pov->red_gain*9 /10;
+		pov->blue_gain=pov->blue_gain *21 /20;
+	}
+}
+
+static void ov9640_upload_gains()
+{
+	ov9640 *pov;
+	u32 expValue;
+	u8 gain, aech, aecl, laec, blue, red;
+	u8 regValue;
+
+	pov = &g_ov;
+
+	gain = pov->gain;
+	blue = pov->blue_gain;
+	red = pov->red_gain;
+	expValue = pov->adjusted_exp_value;
+	// Set awb
+	prv_write_sensor_reg(OV9640_BLUE, &blue);
+	prv_write_sensor_reg(OV9640_RED, &red);
+
+	// Set gain 
+	prv_write_sensor_reg(OV9640_GAIN, &gain);
+	// Set exposure
+	prv_read_sensor_reg(OV9640_COM1, &regValue);
+	regValue = (regValue & 0xFC) | (expValue & 0x03);
+	prv_write_sensor_reg(OV9640_COM1, &regValue);
+	expValue >>= 2;
+	if (expValue > 0xFF)
+		regValue = 0xFF;
+	else
+		regValue = expValue;
+	prv_write_sensor_reg(OV9640_AECH, &regValue);
+	prv_write_sensor_reg(OV9640_CLKRC, &pov->pclock);
+}
+
+int ov9640_switch_format(u32 captureSizeFormat, u32 colorFormat)
+{
+	int status;
+	u32 index, curReg;
+	u8 *regsP;
+	u8 regValue;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+	regsP = (u8 *) ov9640_get_regs_list(captureSizeFormat, colorFormat);
+	// Get the pointer to the basic setting.  The pointer must be freed after exiting.
+
+	if (regsP == NULL)
+		return OV_ERR_PARAMETER;
+	// Apply the delta registers.
+	index = curReg = 0;
+	while ((curReg = gDelta[index]) < OV9640_REGEND) {
+		status = prv_get_reg_value(regsP, curReg, &regValue);
+		if (status == 0) {
+			prv_write_sensor_reg(curReg, &regValue);
+		}
+		else
+			break;
+		index++;
+	}
+	mdelay(50);
+	if (pov->night_mode == 1) {
+		//night mode 
+		ov9640_set_night_mode();
+	}
+	else if (pov->night_mode == 2) {	//action mode
+		ov9640_set_action_mode();
+	}
+	else
+		ov9640_set_auto_mode();
+
+	return status;
+}
+
+int
+ov9640_set_dma_pages(pxa_dma_desc ** pdes,
+		     pxa_dma_desc ** des_physical, int num, struct page *array[], int total_size, int dsadr, int flags)
+{
+	int remain_size, des_transfer_size;
+	int j, target_page_num = num;
+	pxa_dma_desc *cur_des_virtual = *pdes;
+	pxa_dma_desc *cur_des_physical = *des_physical;
+
+	// in each iteration, generate one dma chain for one frame
+	remain_size = total_size;
+
+	for (j = 0; j < num; j++) {
+		// set descriptor
+		if (remain_size > PAGE_SIZE)
+			des_transfer_size = PAGE_SIZE;
+		else
+			des_transfer_size = remain_size;
+		cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+		cur_des_virtual->dsadr = dsadr;	// FIFO0 physical address
+		cur_des_virtual->dtadr = page_to_bus(array[j]);
+		cur_des_virtual->dcmd = des_transfer_size | flags;
+
+		// advance pointers
+		remain_size -= des_transfer_size;
+		cur_des_virtual++;
+		cur_des_physical++;
+		target_page_num++;
+	}
+	*pdes = cur_des_virtual;
+	*des_physical = cur_des_physical;
+}
+
+int
+ov9640_set_dma_page1(pxa_dma_desc ** pdes,
+		     pxa_dma_desc ** des_physical, int num, struct page *page1, int total_size, int dsadr, int flags)
+{
+	int remain_size, des_transfer_size;
+	int j, target_page_num = num;
+	pxa_dma_desc *cur_des_virtual = *pdes;
+	pxa_dma_desc *cur_des_physical = *des_physical;
+	int dump_page;
+
+	// in each iteration, generate one dma chain for one frame
+	remain_size = total_size;
+	dump_page = page_to_bus(page1);
+	DPRINTK("dump_page=%x", dump_page);
+
+	for (j = 0; j < num; j++) {
+		// set descriptor
+		if (remain_size > PAGE_SIZE)
+			des_transfer_size = PAGE_SIZE;
+		else
+			des_transfer_size = remain_size;
+		cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+		cur_des_virtual->dsadr = dsadr;	// FIFO0 physical address
+		cur_des_virtual->dtadr = dump_page;
+		cur_des_virtual->dcmd = des_transfer_size | flags;
+
+		// advance pointers
+		remain_size -= des_transfer_size;
+		cur_des_virtual++;
+		cur_des_physical++;
+		target_page_num++;
+	}
+	*pdes = cur_des_virtual;
+	*des_physical = cur_des_physical;
+}
+
+int ov9640_update_still_dma_chain(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+	int des_transfer_size, remain_size;
+	unsigned int i, j;
+
+	int target_page_num;
+
+	DPRINTK("ov9640_update_still_dma_chain\n");
+	// clear descriptor pointers
+	cam_ctx->fifo0_descriptors_virtual = cam_ctx->fifo0_descriptors_physical = 0;
+	cam_ctx->fifo1_descriptors_virtual = cam_ctx->fifo1_descriptors_physical = 0;
+	cam_ctx->fifo2_descriptors_virtual = cam_ctx->fifo2_descriptors_physical = 0;
+
+	// calculate how many descriptors are needed per frame
+	cam_ctx->fifo0_num_descriptors = cam_ctx->pages_per_fifo0;
+
+	cam_ctx->fifo1_num_descriptors = cam_ctx->pages_per_fifo1;
+
+	cam_ctx->fifo2_num_descriptors = cam_ctx->pages_per_fifo2;
+
+	// check if enough memory to generate descriptors
+	DPRINTK("in %s, cam_ctx->block_number =%d\n", __FUNCTION__, cam_ctx->block_number);
+	if ((cam_ctx->fifo0_num_descriptors + cam_ctx->fifo1_num_descriptors +
+	     cam_ctx->fifo2_num_descriptors) * cam_ctx->block_number > cam_ctx->dma_descriptors_size)
+		return -1;
+
+	// generate fifo0 dma chains
+	cam_ctx->fifo0_descriptors_virtual = (unsigned) cam_ctx->dma_descriptors_virtual;
+	cam_ctx->fifo0_descriptors_physical = (unsigned) cam_ctx->dma_descriptors_physical;
+	cur_des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual;
+	cur_des_physical = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_physical;
+
+	DPRINTK("pages_allocated=%d,fifo0_descriptors_virtual=%x\n", cam_ctx->pages_allocated, cur_des_virtual);
+
+	for (i = 0; i < 2; i++) {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = cam_ctx->fifo0_transfer_size;
+		ov9640_set_dma_page1(&cur_des_virtual, &cur_des_physical,
+				     cam_ctx->fifo0_num_descriptors,
+				     cam_ctx->page_array[cam_ctx->
+							 pages_allocated -
+							 1], remain_size, CIBR0_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+	}
+	DPRINTK("after ov9640_set_dma_page1=%d\n", cam_ctx->pages_allocated);
+	for (i = 0; i < 1; i++) {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = cam_ctx->fifo0_transfer_size;
+
+		// assume the blocks are stored consecutively
+		target_page_num = cam_ctx->pages_per_block * i;
+		DPRINTK("target_page_num=%d\n", target_page_num);
+		ov9640_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+				     cam_ctx->fifo0_num_descriptors,
+				     &cam_ctx->page_array[target_page_num],
+				     remain_size, CIBR0_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+		// stop the dma transfer on one frame captured
+		last_des_virtual = cur_des_virtual - 1;
+	}
+	last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo0_descriptors_physical);
+	last_des_virtual->ddadr |= 0x1;
+	last_des_virtual->dcmd |= DCMD_ENDIRQEN;
+
+	// generate fifo1 dma chains
+	if (cam_ctx->fifo1_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo1_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo1_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < 2; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo1_transfer_size;
+			ov9640_set_dma_page1(&cur_des_virtual,
+					     &cur_des_physical,
+					     cam_ctx->
+					     fifo1_num_descriptors,
+					     cam_ctx->page_array[cam_ctx->
+								 pages_allocated
+								 - 2],
+					     remain_size, CIBR1_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		for (i = 0; i < 1; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo1_transfer_size;
+
+			target_page_num = cam_ctx->pages_per_block * i + cam_ctx->pages_per_fifo0;
+			ov9640_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+					     cam_ctx->fifo1_num_descriptors,
+					     &cam_ctx->page_array[target_page_num],
+					     remain_size, CIBR1_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo1_descriptors_physical);
+		last_des_virtual->ddadr |= 0x1;
+	}
+	// generate fifo2 dma chains
+	if (cam_ctx->fifo2_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo2_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo2_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < 2; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo2_transfer_size;
+			ov9640_set_dma_page1(&cur_des_virtual,
+					     &cur_des_physical,
+					     cam_ctx->
+					     fifo2_num_descriptors,
+					     cam_ctx->page_array[cam_ctx->
+								 pages_allocated
+								 - 3],
+					     remain_size, CIBR2_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		DPRINTK("last target_page_num=%d\n", target_page_num + cam_ctx->fifo2_num_descriptors);
+		for (i = 0; i < 1; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo2_transfer_size;
+			target_page_num =
+			    cam_ctx->pages_per_block * i + cam_ctx->pages_per_fifo0 + cam_ctx->pages_per_fifo1;
+			ov9640_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+					     cam_ctx->fifo2_num_descriptors,
+					     &cam_ctx->page_array[target_page_num],
+					     remain_size, CIBR2_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			DPRINTK("last target_page_num=%d\n", target_page_num + cam_ctx->fifo2_num_descriptors);
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo2_descriptors_physical);
+		last_des_virtual->ddadr |= 0x1;
+	}
+	return 0;
+}
+
+int ov9640_prepare_capture(p_camera_context_t cam_ctx, u32 captureSizeFormat, u32 colorFormat)
+{
+	static int first = 1;
+	int status;
+	//u32 expMultiple, expValue;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+	stop_dma_transfer(cam_ctx);
+	ov9640_switch_format(captureSizeFormat, colorFormat);
+	ov9640_adjust_gains(pov->pre_size, captureSizeFormat);
+	ov9640_upload_gains();
+	if (captureSizeFormat == OV_SIZE_VGA) {
+		//ov9640_update_still_dma_chain(cam_ctx);
+		ov9640_stop_third_des(cam_ctx);
+		/*
+		 */
+	}
+	else if (captureSizeFormat == OV_SIZE_SXGA) {
+		camera_set_int_mask(cam_ctx, 0x3fd | 0x0400);
+		ov9640_update_still_dma_chain(cam_ctx);
+		//ov9640_halt_video_output();
+		//ci_clear_int_status(0xFFFFFFFF);
+		//DPRINTK("before camera_sleep \n");
+		//camera_sleep();
+	}
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+	start_dma_transfer(cam_ctx, 1);
+	DPRINTK("after ov9640_prepare_capture \n");
+}
+
+int ov9640_set_special_effect(int style)
+{
+	int ret = 0;
+	u32 index, curReg;
+	u8 *regsP;
+	u8 regValue;
+
+	DPRINTK("in function %s parameter=%d\n", __FUNCTION__, style);
+	curReg = 0x3a;
+	ov9640_read(0x3a, &regValue);
+	regValue = regValue & 0xf;
+	switch (style) {
+	case V4l_STYLE_NORMAL:
+		DPRINTK("V4l_STYLE_NORMAL\n");
+		regValue &= 0x7f;
+		//ov9640_write(0x3a, 0x08);
+		ov9640_write(0x3a, regValue);
+		ov9640_write(0x67, 0x80);
+		ov9640_write(0x68, 0x80);
+		break;
+	case V4l_STYLE_BLACK_WHITE:
+		DPRINTK("V4l_STYLE_BLACK_WHITE\n");
+		regValue |= 0x10;
+		//ov9640_write(0x3a, 0x18);
+		ov9640_write(0x3a, regValue);
+		ov9640_write(0x67, 0x80);
+		ov9640_write(0x68, 0x80);
+		break;
+	case V4l_STYLE_SEPIA:
+		DPRINTK("V4l_STYLE_SEPIA\n");
+		regValue |= 0x10;
+		//ov9640_write(0x3a, 0x18);
+		ov9640_write(0x3a, regValue);
+		ov9640_write(0x67, 0xa0);
+		ov9640_write(0x68, 0x40);
+		break;
+		//case V4l_STYLE_BULISH:
+		DPRINTK("V4l_STYLE_BULISH\n");
+		ov9640_write(0x3a, 0x18);
+		ov9640_write(0x67, 0x80);
+		ov9640_write(0x68, 0xc0);
+		break;
+	default:
+		DPRINTK("case default ????????????????????\n");
+		//ret=OV_ERR_PARAMETER;
+	}
+	return ret;
+
+}
+
+int ov9640_set_brightness(int bright)
+{
+	int ret = 0;
+	const u8 BN[] = {
+		//BN-3
+		0x0f, 0x4f,
+		0x27, 0xe8,
+		0x28, 0xe0,
+		0x29, 0xe0,
+		0x2c, 0xe0,
+		//BN-2
+		0x0f, 0x4f,
+		0x27, 0xc8,
+		0x28, 0xc0,
+		0x29, 0xc0,
+		0x2c, 0xc0,
+		//BN-1
+		0x0f, 0x4f,
+		0x27, 0xa8,
+		0x28, 0xa0,
+		0x29, 0xa0,
+		0x2c, 0xa0,
+		//BN-0
+		0x0f, 0x4f,
+		0x27, 0x88,
+		0x28, 0x80,
+		0x29, 0x80,
+		0x2c, 0x88,
+		//BN+1
+		0x0f, 0x4f,
+		0x27, 0x28,
+		0x28, 0x20,
+		0x29, 0x20,
+		0x2c, 0x20,
+		//BN+2
+		0x0f, 0x4f,
+		0x27, 0x48,
+		0x28, 0x40,
+		0x29, 0x40,
+		0x2c, 0x40,
+		//BN+3
+		0x0f, 0x4f,
+		0x27, 0x68,
+		0x28, 0x60,
+		0x29, 0x60,
+		0x2c, 0x60,
+	};
+	u8 *regs;
+	int n = 5;
+	int i;
+
+	DPRINTK("in function %s bright =%d \n", __FUNCTION__, bright);
+	if (bright < -3)
+		bright = -3;
+	if (bright > 3)
+		bright = 3;
+	//bright = -4 .. 4
+	regs = &BN[(bright + 3) * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ret |= ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+
+}
+int ov9640_set_expose_compensation(int bright)
+{
+	int ret = 0;
+	const u8 EV[] = {
+		//EV-3
+		0x24, 0x1c,
+		0x25, 0x14,
+		//EV-3
+		0x24, 0x28,
+		0x25, 0x20,
+		//EV-2
+		0x24, 0x38,
+		0x25, 0x30,
+		//EV-1
+		0x24, 0x50,
+		0x25, 0x48,
+		//EV-0
+		0x24, 0x70,
+		0x25, 0x68,
+		//EV+1
+		0x24, 0x90,
+		0x25, 0x88,
+		//EV+2
+		0x24, 0xb4,
+		0x25, 0xac,
+		//EV+3
+		0x24, 0xc8,
+		0x25, 0xc0,
+		//EV+4
+		0x24, 0xe0,
+		0x25, 0xd8,
+	};
+	u8 *regs;
+	int n = 2;
+	int i;
+
+	DPRINTK("in function %s bright =%d \n", __FUNCTION__, bright);
+	if (bright < -4)
+		bright = -4;
+	if (bright > 4)
+		bright = 4;
+	//bright = -4 .. 4
+	regs = &EV[(bright + 4) * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ret |= ov9640_write(regs[i], regs[i + 1]);
+//      if ( ret) 
+//              return OV_ERR_PARAMETER;
+	return OV_ERR_NONE;
+
+}
+
+int ov9640_set_white_balance(V4l_PIC_WB light)
+{
+	int ret = 0;
+	const u8 WB_v3[] = {
+		//V4l_WB_DIRECT_SUN
+		0x13, 0xad,
+		0x01, 0x80,
+		0x02, 0x80,
+		0x45, 0x20,
+		0x46, 0x20,
+		0x47, 0x58,
+		0x48, 0x58,
+		0x5C, 0x7a,
+		0x5D, 0x5d,
+		0x5F, 0x00,
+		0x60, 0x14,
+		0x13, 0xaf,
+		0x14, 0x4a,
+		//V4l_WB_INCANDESCENT home mode
+		0x13, 0xad,
+		0x01, 0x80,
+		0x02, 0x80,
+		0x45, 0x64,
+		0x46, 0x64,
+		0x47, 0x20,
+		0x48, 0x20,
+		0x5C, 0x7a,
+		0x5D, 0x48,
+		0x5F, 0x00,
+		0x60, 0x14,
+		0x13, 0xaf,
+		0x14, 0x8a,
+		//V4l_WB_FLUORESCENT office mode
+		0x13, 0xad,
+		0x01, 0x80,
+		0x02, 0x80,
+		0x45, 0x64,
+		0x46, 0x64,
+		0x47, 0x58,
+		0x48, 0x58,
+		0x5C, 0x7a,
+		0x5D, 0x5d,
+		0x5F, 0x00,
+		0x60, 0x14,
+		0x13, 0xaf,
+		0x14, 0x8a,
+		// auto
+		0x13, 0xaf,
+		0x01, 0x80,
+		0x02, 0x80,
+/*
+		0x43, 0xF0,
+		0x44, 0x10,
+		0x45, 0x6C,
+		0x46, 0x6c,
+		0x47, 0x44,
+		0x48, 0x44,
+		0x59, 0x49,
+		0x5A, 0x94,
+		0x5B, 0x46,
+		0x5C, 0x84,
+		0x5D, 0x5c,
+		0x5E, 0x08,
+		0x5F, 0x00,
+		0x60, 0x14,
+		0x61, 0xCE,
+	*/
+		0x43, 0xF0,
+		0x44, 0x10,
+		0x45, 0x20,
+		0x46, 0x20,
+		0x47, 0x20,
+		0x48, 0x20,
+		0x59, 0x27,
+		0x5A, 0x72,
+		0x5B, 0x56,
+		0x5C, 0x7a,
+		0x5D, 0x5d,
+		0x5E, 0x17,
+		0x5F, 0x00,
+		0x60, 0x14,
+		0x61, 0xCE,
+
+		0x14, 0x8a,
+	};
+	u8 *regs;
+	int n = 13;
+	int i = 0;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, light);
+	switch (light) {
+	case V4l_WB_DIRECT_SUN:
+		//ov9640_set_color_saturation(3);
+		DPRINTK("V4l_WB_DIRECT_SUN\n");
+		i = 0 * n * 2;
+		//ov9640_set_night_mode();
+		break;
+	case V4l_WB_INCANDESCENT:
+		//ov9640_set_color_saturation(2);
+		DPRINTK("V4l_WB_INCANDESCENT\n");
+		i = 1 * n * 2;
+		//ov9640_set_action_mode();
+		break;
+	case V4l_WB_FLUORESCENT:
+		//ov9640_set_color_saturation(2);
+		DPRINTK("V4l_WB_FLUORESCENT\n");
+		i = 2 * n * 2;
+		break;
+	default:
+		/* auto */
+		//ov9640_set_color_saturation(2);
+		DPRINTK("case default ????????????????????\n");
+		i = 3 * n * 2;
+		n = 19;
+		//ov9640_set_auto_mode();
+		break;
+	}
+	regs = &WB_v3[i];
+	if (pov->version == ((PID_OV_v3 << 8) | (PID_9640_v3))) {
+		DPRINTK("ver 3 sensor!\n");
+		regs = &WB_v3[i];
+	}
+
+	for (i = 0; i < n * 2; i += 2)
+		ret |= ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+}
+
+int ov9640_set_night_mode()
+{
+	const u8 NM_v3[] = {
+		//auto
+		0x11, 0x89,
+		//night mode
+		//action mode
+	};
+	ov9640 *pov;
+
+	pov = &g_ov;
+	pov->night_mode = 1;
+	//ov9640_write(0x11, 0x89);
+	ov9640_write(0x3b, 0xe1);
+
+}
+
+int ov9640_set_action_mode()
+{
+	ov9640 *pov;
+
+	pov = &g_ov;
+	pov->night_mode = 2;
+	ov9640_write(0x11, 0x81);
+	ov9640_write(0x3b, 0x01);
+	ov9640_write(0x2d, 0x0);
+	ov9640_write(0x2e, 0x0);
+
+
+}
+
+int ov9640_set_auto_mode()
+{
+	ov9640 *pov;
+
+	pov = &g_ov;
+	pov->night_mode = 0;
+	ov9640_write(0x11, 0x83);
+	ov9640_write(0x3b, 0x01);
+	ov9640_write(0x2d, 0x0);
+	ov9640_write(0x2e, 0x0);
+}
+
+int ov9640_set_light_environment(V4l_PIC_WB light)
+{
+	int ret = 0;
+	const u8 LE_v3[] = {
+		//OutDoor
+		0x3b, 0x00,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 60Hz(Default)
+		0x3b, 0x01,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 50Hz
+		0x3b, 0x01,
+		0x2a, 0x10,
+		0x2b, 0x40,
+		0x6a, 0x3d,
+	};
+	const u8 LE_v2[] = {
+		//OutDoor
+		0x13, 0x8d,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 60Hz(Default)
+		0x13, 0x8d,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 50Hz
+		0x13, 0x8d,
+		0x2a, 0x10,
+		0x2b, 0x14,
+		0x6a, 0x3d,
+	};
+	u8 *regs;
+	int n = 4;
+	int i = 0;
+	ov9640 *pov;
+
+	pov = &g_ov;
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, light);
+	switch (light) {
+	case 0:
+		i = 0 * n * 2;
+		break;
+	case 60:
+		i = 1 * n * 2;
+		break;
+	case 50:
+		i = 2 * n * 2;
+		break;
+	default:
+		i = 0;
+		break;
+	}
+
+	regs = &LE_v2[i];
+	if (pov->version == ((PID_OV_v3 << 8) | (PID_9640_v3))) {
+		DPRINTK("ver 3 sensor!\n");
+		regs = &LE_v3[i];
+	}
+
+
+	for (i = 0; i < n * 2; i += 2)
+		ret |= ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+}
+
+int ov9640_set_color_saturation(int saturation)
+{
+	const u8 CS[] = {
+		//Saturation: 0.25
+		0x4f, 0x14,
+		0x50, 0x10,
+		0x51, 0x3,
+		0x52, 0x6,
+		0x53, 0x13,
+		0x54, 0x19,
+		//Saturation 0.5
+		0x4f, 0x28,
+		0x50, 0x22,
+		0x51, 0x6,
+		0x52, 0xc,
+		0x53, 0x26,
+		0x54, 0x33,
+		//Saturation 0.75 (Default)
+		0x4f, 0x3c,
+		0x50, 0x32,
+		0x51, 0x9,
+		0x52, 0x13,
+		0x53, 0x39,
+		0x54, 0x4c,
+		//Saturation 1.0
+		0x4f, 0x50,
+		0x50, 0x43,
+		0x51, 0xd,
+		0x52, 0x19,
+		0x53, 0x4d,
+		0x54, 0x66,
+		//Saturation 1.25
+		0x4f, 0x64,
+		0x50, 0x53,
+		0x51, 0x10,
+		0x52, 0x1f,
+		0x53, 0x5f,
+		0x54, 0x7f,
+	};
+	u8 *regs;
+	int n = 6;
+	int i;
+
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, saturation);
+	if (saturation < 0)
+		saturation = 0;
+	if (saturation > 4)
+		saturation = 4;
+
+	regs = &CS[saturation * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+
+}
+
+int ov9640_set_contrast(int contrast)
+{
+	const u8 CO[] = {
+		//Low contrast
+		0x6C, 0x20,
+		0x6D, 0x50,
+		0x6E, 0xc0,
+		0x6F, 0xa8,
+		0x70, 0x88,
+		0x71, 0x80,
+		0x72, 0x78,
+		0x73, 0x70,
+		0x74, 0x68,
+		0x75, 0x58,
+		0x76, 0x40,
+		0x77, 0x30,
+		0x78, 0x28,
+		0x79, 0x20,
+		0x7A, 0x1e,
+		0x7B, 0x18,
+		0x7C, 0x04,
+		0x7D, 0x07,
+		0x7E, 0x1f,
+		0x7F, 0x49,
+		0x80, 0x5a,
+		0x81, 0x6a,
+		0x82, 0x79,
+		0x83, 0x87,
+		0x84, 0x94,
+		0x85, 0x9f,
+		0x86, 0xaf,
+		0x87, 0xbb,
+		0x88, 0xcf,
+		0x89, 0xdf,
+		0x8A, 0xee,
+		//Middle contrast (default)
+		0x6C, 0x40,
+		0x6D, 0x30,
+		0x6E, 0x4B,
+		0x6F, 0x60,
+		0x70, 0x70,
+		0x71, 0x70,
+		0x72, 0x70,
+		0x73, 0x70,
+		0x74, 0x60,
+		0x75, 0x60,
+		0x76, 0x50,
+		0x77, 0x48,
+		0x78, 0x3A,
+		0x79, 0x2E,
+		0x7A, 0x28,
+		0x7B, 0x22,
+		0x7C, 0x04,
+		0x7D, 0x07,
+		0x7E, 0x10,
+		0x7F, 0x28,
+		0x80, 0x36,
+		0x81, 0x44,
+		0x82, 0x52,
+		0x83, 0x60,
+		0x84, 0x6C,
+		0x85, 0x78,
+		0x86, 0x8C,
+		0x87, 0x9E,
+		0x88, 0xBB,
+		0x89, 0xD2,
+		0x8A, 0xE6,
+		//High contrast
+		0x6c, 0x50,
+		0x6d, 0x60,
+		0x6e, 0x58,
+		0x6f, 0x58,
+		0x70, 0x58,
+		0x71, 0x50,
+		0x72, 0x50,
+		0x73, 0x50,
+		0x74, 0x50,
+		0x75, 0x50,
+		0x76, 0x4c,
+		0x77, 0x4c,
+		0x78, 0x45,
+		0x79, 0x3c,
+		0x7a, 0x2c,
+		0x7b, 0x24,
+		0x7c, 0x05,
+		0x7d, 0x0b,
+		0x7e, 0x16,
+		0x7f, 0x2c,
+		0x80, 0x37,
+		0x81, 0x41,
+		0x82, 0x4b,
+		0x83, 0x55,
+		0x84, 0x5f,
+		0x85, 0x69,
+		0x86, 0x7c,
+		0x87, 0x8f,
+		0x88, 0xb1,
+		0x89, 0xcf,
+		0x8a, 0xe5,
+	};
+
+	u8 *regs;
+	int n = 31;
+	int i;
+
+	DPRINTK("in function %s parameter=%d \n", __FUNCTION__, contrast);
+	if (contrast < 0)
+		contrast = 0;
+	if (contrast > 2)
+		contrast = 2;
+
+	regs = &CO[contrast * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+
+}
+
+int ov9640_set_back_light(int b_light)
+{
+	const u8 BL[] = {
+		0x3B, 0,
+		0x3B, 8,
+		0x3B, 0x10,
+		0x3B, 0x18,
+	};
+	u8 *regs;
+	int n = 1;
+	int i;
+
+	DPRINTK("in function %s parameter=%d\n", __FUNCTION__, b_light);
+	if (b_light < 0)
+		b_light = 0;
+	if (b_light > 3)
+		b_light = 3;
+
+	regs = &BL[b_light * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ov9640_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+}
+
+int ov9640_stop_third_des(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *pdesc, *ptmp;
+	unsigned int phy_addr;
+	int i;
+
+	// stop the dma transfer on one frame captured
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo0_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo0_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo0_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+
+	pdesc += cam_ctx->fifo0_num_descriptors - 1;
+	pdesc->dcmd = (pdesc->dcmd & DCMD_LENGTH) | DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->dcmd = (pdesc->dcmd & DCMD_LENGTH) | DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo1_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo1_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo1_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+	pdesc += cam_ctx->fifo1_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo2_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo2_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo2_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+	pdesc += cam_ctx->fifo2_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+}
+
+int ov9640_stop_third_des1(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *pdesc, *ptmp;
+	unsigned int phy_addr;
+	int i;
+
+	// stop the dma transfer on one frame captured
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo0_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo0_num_descriptors * 2;
+	/*
+	   for (i=0;i<cam_ctx->fifo0_num_descriptors;i++)
+	   (ptmp+i)->dtadr = (pdesc+i)->dtadr;
+	 */
+	pdesc += cam_ctx->fifo0_num_descriptors - 1;
+	pdesc->dcmd = DCMD_FLOWSRC | DCMD_BURST32;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->dcmd = DCMD_FLOWSRC | DCMD_BURST32;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo1_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo1_num_descriptors * 2;
+	/*
+	   for (i=0;i<cam_ctx->fifo1_num_descriptors;i++)
+	   (ptmp+i)->dtadr = (pdesc+i)->dtadr;
+	 */
+	pdesc += cam_ctx->fifo1_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo2_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo2_num_descriptors * 2;
+	/*
+	   for (i=0;i<cam_ctx->fifo2_num_descriptors;i++)
+	   (ptmp+i)->dtadr = (pdesc+i)->dtadr;
+	 */
+	pdesc += cam_ctx->fifo2_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+}
+
+int find_window(struct video_window *vw, int *sub_win)
+{
+	int ret = OV_SIZE_NONE;
+
+	*sub_win = 1;
+	if (vw->width > 1280 || vw->height > 960 || vw->width < 88 || vw->height < 72) {
+		ret = OV_SIZE_NONE;
+	}
+	else if (vw->width == 1280 && vw->height == 960) {
+		*sub_win = 0;
+		ret = OV_SIZE_SXGA;
+	}
+	else if (vw->width >= 640 && vw->height >= 480) {
+		if (vw->width == 640 && vw->height == 480)
+			*sub_win = 0;
+		ret = OV_SIZE_VGA;
+	}
+	else if (vw->width >= 352 && vw->height >= 288) {
+		if (vw->width == 352 && vw->height == 288)
+			*sub_win = 0;
+		ret = OV_SIZE_CIF;
+	}
+	else if (vw->width >= 320 && vw->height >= 240) {
+		if (vw->width == 320 && vw->height == 240)
+			*sub_win = 0;
+		ret = OV_SIZE_QVGA;
+	}
+	else if (vw->width >= 176 && vw->height >= 144) {
+		if (vw->width == 176 && vw->height == 144)
+			*sub_win = 0;
+		ret = OV_SIZE_QCIF;
+	}
+	else if (vw->width >= 160 && vw->height >= 120) {
+		if (vw->width == 160 && vw->height == 120)
+			*sub_win = 0;
+		ret = OV_SIZE_QQVGA;
+	}
+	else if (vw->width >= 88 && vw->height >= 72) {
+		if (vw->width == 88 && vw->height == 72)
+			*sub_win = 0;
+		ret = OV_SIZE_QQCIF;
+	}
+	DPRINTK("in %s,ret = %d, subwin=%d\n", __FUNCTION__, ret, *sub_win);
+	return ret;
+}
+
+int ov9640_set_window(struct video_window *vw)
+{
+	int ret = 0;
+	int x_start, x_end;
+	int y_start, y_end;
+	struct video_window window;
+	int width;
+	int height;
+	int sub_win;
+	ov9640 *pov;
+
+	pov = &g_ov;
+	vw->width = (vw->width + 7) & (~0x7);
+	vw->height = (vw->height + 7) & (~0x7);
+	vw->x = vw->y = 0;
+	x_end = window.width = (vw->width + vw->x);
+	y_end = window.height = (vw->height + vw->y);
+	DPRINTK("in %s, vw-x =%d, vw-y=%d,vw->width=%d,vw->height=%d\n",
+		__FUNCTION__, vw->x, vw->y, vw->width, vw->height);
+	ret = find_window(&window, &sub_win);
+	if (ret <= OV_SIZE_NONE)
+		return -1;
+
+	ret = ov9640_set_format(ret, OV_FORMAT_YUV_422);
+	if (ret < 0)
+		return -1;
+
+	/*
+	   if ((sub_win == 1) || (vw->x != 0) || (vw->y != 0) || (pov->sub_win != sub_win)) {
+	   u8 href = 0;
+	   u8 vref = 0;
+	   ov9640_read(0x32, &href);
+	   href = href & 0xc0 | (vw->width & 0x7) << 3 | (vw->x & 0x7);
+	   ov9640_write(0x17, vw->x >> 3);
+	   ov9640_write(0x18, x_end >> 3);
+	   ov9640_write(0x19, vw->y >> 2);
+	   ov9640_write(0x20, y_end >> 2);
+	   ov9640_read(0x3, &vref);
+	   vref = vref & 0xf0 | (vw->height & 0x3) << 2 | (vw->y & 0x3);
+	   pov->sub_win = sub_win;
+	   }
+	 */
+	pov->win = *vw;
+	return ret;
+}
+
+int ov9640_get_window(struct video_window *vw)
+{
+	ov9640 *pov;
+	pov = &g_ov;
+	*vw = pov->win;
+	return 0;
+}
+
+struct win_size {
+	int width;
+	int height;
+};
+int ov9640_set_sensor_size(void *w_size)
+{
+	struct win_size size;
+	ov9640 *pov;
+	pov = &g_ov;
+	if (copy_from_user(&size, w_size, sizeof(struct win_size))) {
+		return -EFAULT;
+	}
+//make it in an even of multiple of 8
+	size.height = (size.height + 7) / 8 * 8;
+	pov->sensor_width = size.width;
+	pov->sensor_height = size.height;
+	return 0;
+}
+
+int ov9640_get_sensor_size(void *w_size)
+{
+}
+int ov9640_set_output_size(void *w_size)
+{
+	struct win_size size;
+	ov9640 *pov;
+	pov = &g_ov;
+	if (copy_from_user(&size, w_size, sizeof(struct win_size))) {
+		return -EFAULT;
+	}
+//make it in an even of multiple of 8
+	size.height = (size.height + 7) / 8 * 8;
+	pov->sensor_width = size.width;
+	pov->sensor_height = size.height;
+	return 0;
+}
+
+int ov9640_get_output_size(void *w_size)
+{
+}
+int test_divider(int res, int fps)
+{
+	int max_hz = 48 * 1000000;
+	int div = 1;
+	int i;
+	int ov_fps[5] = { 3, 7, 15, 30, 60 };
+	u32 value = 320 * 240;
+	/*
+	   switch (prevSize) {
+	   case OV_SIZE_QQCIF:
+	   value = 88 * 72;
+	   break;
+	   case OV_SIZE_QQVGA:
+	   value = 176 * 144;
+	   break;
+	   case OV_SIZE_QCIF:
+	   value = 160 * 120;
+	   break;
+	   case OV_SIZE_QVGA:
+	   value = 320 * 240;
+	   break;
+	   case OV_SIZE_CIF:
+	   value = 352 * 288;
+	   break;
+	   case OV_SIZE_VGA:
+	   value = 640 * 480;
+	   break;
+	   case OV_SIZE_SXGA:
+	   value = 1280 * 960;
+	   break;
+	   }
+
+	   while (max_hz / res / div > fps)
+	   div++;
+	   if (div > 64)
+	   div = 64;
+	   return (div - 1);
+
+	   for (i =0;i<5;i++)
+	   if ( fps < ov_fps[i] ) 
+	   continue;
+	 */
+	if (fps == 0)
+		return 0;
+	if (fps > 60)
+		fps = 60;
+	return (div = 60 / fps - 1);
+}
+
+int ov9640_set_fps(int fps, int min_fps)
+{
+	u32 res = 0;
+	u8 value;
+	if (fps < 0) {
+		DPRINTK("in %s fps = %d divider value =%d\n", __FUNCTION__, fps, res);
+		fps = 15;
+	}
+	res = test_divider(0, fps);
+	ov9640_read(OV9640_CLKRC, &value);
+	value = (value & 0xc0) | res;
+	ov9640_write(OV9640_CLKRC, value);
+	DPRINTK("in %s fps = %d divider value =%d\n", __FUNCTION__, fps, res);
+	/*
+	   ov9640_set_night_mode();
+	   ov9640_set_action_mode();
+	   ov9640_set_auto_mode();
+	 */
+	return 0;
+}
+
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+void write_balance()
+{
+	u8 yav, uav, vav;
+	static int bg = 0x80;
+	static int rg = 0x24;
+	int awb_mode;
+	ov9640 *pov;
+
+	pov = &g_ov;
+
+	if (pov->version == ((PID_OV_v3 << 8) | (PID_9640_v3))) {
+		DPRINTK("ver 3 sensor!\n");
+		return;
+	}
+
+
+	prv_read_sensor_reg(0x5, &vav);
+	prv_read_sensor_reg(0x6, &yav);
+	prv_read_sensor_reg(0x8, &uav);
+	DPRINTK("in %s, v =%x ,y =%x,u =%x\n)", __FUNCTION__, vav, yav, uav);
+	if (yav >= 0x20 && yav <= 0xc0) {
+		if (vav < 50)
+			rg = MIN(255, rg + 40);
+		else if (vav < 80)
+			rg = MIN(255, rg + 20);
+		else if (vav < 100)
+			rg = MIN(255, rg + 5);
+		else if (vav < 120)
+			rg = MIN(255, rg + 1);
+		else if (vav > 206)
+			rg = MAX(0, rg - 40);
+		else if (vav > 180)
+			rg = MAX(0, rg - 20);
+		else if (vav > 156)
+			rg = MAX(0, rg - 5);
+		else if (vav > 136)
+			rg = MAX(0, rg - 1);
+
+		if (uav < 50)
+			bg = MIN(255, bg + 40);
+		else if (uav < 80)
+			bg = MIN(255, bg + 20);
+		else if (uav < 100)
+			bg = MIN(255, bg + 5);
+		else if (uav < 120)
+			bg = MIN(255, bg + 1);
+		else if (uav > 206)
+			bg = MAX(0, bg - 40);
+		else if (uav > 180)
+			bg = MAX(0, bg - 20);
+		else if (uav > 156)
+			bg = MAX(0, bg - 5);
+		else if (uav > 136)
+			bg = MAX(0, bg - 1);
+	}
+	ov9640_write(0x01, bg);
+	ov9640_write(0x2, rg);
+}
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9640_hw.h linux-2.6.16.5-exz/drivers/media/video/ov9640_hw.h
--- linux-2.6.16.5/drivers/media/video/ov9640_hw.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9640_hw.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,259 @@
+/* 
+    ov9640_hw - Omnivision 9640 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _OV_9640_HW_H_
+#define _OV_9640_HW_H_
+
+/***********************************************************************
+ *
+ * Constants & Structures
+ *
+ ***********************************************************************/
+// Revision constants
+#define PID_OV			0x96
+#define PID_9640		0x48
+
+#define PID_OV_v3		0x96
+#define PID_9640_v3		0x49
+
+// Return codes
+#define OV_ERR_NONE       	0x00
+#define OV_ERR_TIMEOUT    	-1
+#define OV_ERR_PARAMETER  	-2  
+#define OV_COMM_ERR		-3
+
+#define CIBR0_PHY	(0x50000000 + 0x28)
+#define CIBR1_PHY	(0x50000000 + 0x30)
+#define CIBR2_PHY	(0x50000000 + 0x38)
+#define DEBUG 1
+#define DPRINTK(fmt,args...)	do { if (DEBUG) printk("in function %s "fmt,__FUNCTION__,##args);} while(0)
+
+// Output Size & Format
+/*
+#define OV_SIZE_NONE		0
+#define OV_SIZE_QQVGA		0x01
+#define OV_SIZE_QVGA		( OV_SIZE_QQVGA << 1 )
+#define OV_SIZE_VGA		( OV_SIZE_QQVGA << 2 )
+#define OV_SIZE_SXGA		( OV_SIZE_QQVGA << 3 )
+#define OV_SIZE_QQCIF		0x10
+#define OV_SIZE_QCIF		( OV_SIZE_QQCIF << 1 )			
+#define OV_SIZE_CIF		( OV_SIZE_QQCIF << 2 )			
+#define OV_FORMAT_NONE		0
+#define OV_FORMAT_YUV_422	1
+#define OV_FORMAT_RGB_565	2
+*/
+enum OV_SIZE {
+	OV_SIZE_NONE=0	,
+	OV_SIZE_QQVGA	,
+	OV_SIZE_QVGA	,
+	OV_SIZE_VGA	,
+	OV_SIZE_SXGA	,
+	OV_SIZE_QQCIF	,
+	OV_SIZE_QCIF	,
+	OV_SIZE_CIF	
+};
+enum OV_FORMAT {
+	OV_FORMAT_NONE=0 ,
+	OV_FORMAT_YUV_422,
+	OV_FORMAT_RGB_565,
+};
+
+// Camera Mode
+#define VIEWFINDER_MODE     0x10
+#define STILLFRAME_MODE     0x20
+
+// Others
+#define OV9640_TIMEOUT    1000    // ms to timeout.
+
+// OV9640 Register Definitions
+#define OV9640_GAIN		0x0000
+#define OV9640_BLUE		0x0001
+#define OV9640_RED		0x0002
+#define OV9640_VREF		0x0003
+#define OV9640_COM1		0x0004
+#define OV9640_BAVE		0x0005				// U/B Average Level
+#define OV9640_GEAVE		0x0006				// Y/Ge Average Level
+#define OV9640_GOAVE		0x0007				// Y/Go Average Level
+#define OV9640_RAVE		0x0008				// V/R Average level
+#define OV9640_COM2		0x0009				// Common control 2
+#define OV9640_PID		0x000A				// Product ID
+#define OV9640_VER		0x000B				// Version
+#define OV9640_COM3		0x000C
+#define OV9640_COM4		0x000D
+#define OV9640_COM5		0x000E
+#define OV9640_COM6		0x000F
+#define OV9640_AECH		0x0010
+#define OV9640_CLKRC		0x0011
+#define OV9640_COM7		0x0012
+#define OV9640_COM8		0x0013
+#define OV9640_COM9		0x0014
+#define OV9640_COM10		0x0015
+#define OV9640_WS		0x0016
+#define OV9640_HSTART		0x0017
+#define OV9640_HSTOP		0x0018
+#define OV9640_VSTRT		0x0019
+#define OV9640_VSTOP		0x001A
+#define OV9640_PSHFT		0x001B
+#define OV9640_MIDH		0x001C
+#define OV9640_MIDL		0x001D
+#define OV9640_DLY		0x001E
+#define OV9640_LAEC		0x001F
+#define OV9640_BOS		0x0020
+#define OV9640_GBOS		0x0021
+#define OV9640_GROS		0x0022
+#define OV9640_ROS		0x0023
+#define OV9640_AEW		0x0024
+#define OV9640_AEB		0x0025
+#define OV9640_VPT		0x0026
+#define OV9640_BBIAS		0x0027
+#define OV9640_GbBIAS		0x0028
+#define OV9640_GrBIAS		0x0029
+#define OV9640_EXHCH		0x002A
+#define OV9640_EXHCL		0x002B
+#define OV9640_RBIAS		0x002C
+#define OV9640_ADVFL		0x002D
+#define OV9640_ADVFH		0x002E
+#define OV9640_YAVE		0x002F
+#define OV9640_HSYST		0x0030
+#define OV9640_HSYEN		0x0031
+#define OV9640_HREF		0x0032
+#define OV9640_CHLF		0x0033
+#define OV9640_ARBLM		0x0034
+#define OV9640_VRHL		0x0035
+#define OV9640_VIDO		0x0036
+#define OV9640_ADC		0x0037
+#define OV9640_ACOM		0x0038
+#define OV9640_OFON		0x0039
+#define OV9640_TSLB		0x003A
+#define OV9640_COM11		0x003B
+#define OV9640_COM12		0x003C
+#define OV9640_COM13		0x003D
+#define OV9640_COM14		0x003E
+#define OV9640_EDGE		0x003F
+#define OV9640_COM15		0x0040
+#define OV9640_COM16		0x0041
+#define OV9640_COM17		0x0042
+#define OV9640_AWBTH1		0x0043
+#define OV9640_AWBTH2		0x0044
+#define OV9640_AWBTH3		0x0045
+#define OV9640_AWBTH4		0x0046
+#define OV9640_AWBTH5		0x0047
+#define OV9640_AWBTH6		0x0048
+#define OV9640_MTX1		0x004F
+#define OV9640_MTX2		0x0050
+#define OV9640_MTX3		0x0051
+#define OV9640_MTX4		0x0052
+#define OV9640_MTX5		0x0053
+#define OV9640_MTX6		0x0054
+#define OV9640_MTX7		0x0055
+#define OV9640_MTX8		0x0056
+#define OV9640_MTX9		0x0057
+#define OV9640_MTXS		0x0058
+#define OV9640_AWBC1		0x0059
+#define OV9640_AWBC2		0x005A
+#define OV9640_AWBC3		0x005B
+#define OV9640_AWBC4		0x005C
+#define OV9640_AWBC5		0x005D
+#define OV9640_AWBC6		0x005E
+#define OV9640_AWBC7		0x005F
+#define OV9640_AWBC8		0x0060
+#define OV9640_AWBC9		0x0061
+#define OV9640_LCC1		0x0062
+#define OV9640_LCC2		0x0063
+#define OV9640_LCC3		0x0064
+#define OV9640_LCC4		0x0065
+#define OV9640_LCC5		0x0066
+#define OV9640_MANU		0x0067
+#define OV9640_MANV		0x0068
+#define OV9640_HV		0x0069
+#define OV9640_MBD		0x006A
+#define OV9640_DBLV		0x006B
+#define OV9640_GSP0		0x006C
+#define OV9640_GSP1		0x006D
+#define OV9640_GSP2		0x006E
+#define OV9640_GSP3		0x006F
+#define OV9640_GSP4		0x0070
+#define OV9640_GSP5		0x0071
+#define OV9640_GSP6		0x0072
+#define OV9640_GSP7		0x0073
+#define OV9640_GSP8		0x0074
+#define OV9640_GSP9		0x0075
+#define OV9640_GSP10		0x0076
+#define OV9640_GSP11		0x0077
+#define OV9640_GSP12		0x0078
+#define OV9640_GSP13		0x0079
+#define OV9640_GSP14		0x007A
+#define OV9640_GSP15		0x007B
+#define OV9640_GST0		0x007C
+#define OV9640_GST1		0x007D
+#define OV9640_GST2		0x007E
+#define OV9640_GST3		0x007F
+#define OV9640_GST4		0x0080
+#define OV9640_GST5		0x0081
+#define OV9640_GST6		0x0082
+#define OV9640_GST7		0x0083
+#define OV9640_GST8		0x0084
+#define OV9640_GST9		0x0085
+#define OV9640_GST10		0x0086
+#define OV9640_GST11		0x0087
+#define OV9640_GST12		0x0088
+#define OV9640_GST13		0x0089
+#define OV9640_GST14		0x008A
+
+// End of OV9640 register
+#define OV9640_REGEND		( OV9640_GST14 + 1 )
+
+
+
+/***********************************************************************
+ *
+ * Function Prototype
+ *
+ ***********************************************************************/
+int ov9640_set_regs( u8 *regP );
+int ov9640_read_all_regs( u8 *bufP, u32 numRegs );
+
+void ov9640_power_down( int powerDown );
+void ov9640_reset( void );
+void ov9640_wait( int ms );
+
+int ov9640_version_revision(u8 * pCmRevision, u8 *pSensorRevision);
+void ov9640_set_HSYNC(void);
+void ov9640_auto_fucntion_on(void);
+void ov9640_auto_fucntion_off(void);
+
+int ov9640_viewfinder_on(void);
+int ov9640_viewfinder_off(void);
+int ov9640_halt_video_output(void);
+int ov9640_resume_to_full_output_mode(void);
+int ov9640_get_single_image(void);
+
+int ov9640_set_format( u32 captureSizeFormat, u32 colorFormat );
+
+int i2c_init(void);
+int i2c_deinit(void);
+
+extern int i2c_ov9640_init(void);
+extern int i2c_ov9640_cleanup(void);
+extern int ov9640_read(u8 addr, u8 *pvalue);
+extern int ov9640_write(u8 addr, u8 value);
+
+
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9650.c linux-2.6.16.5-exz/drivers/media/video/ov9650.c
--- linux-2.6.16.5/drivers/media/video/ov9650.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9650.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,576 @@
+/* 
+    ov9650 - Omnivision 9650 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include <linux/types.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/ctype.h>
+
+#include <asm/irq.h>
+#include <asm/hardware.h>
+
+#include "camera.h"
+#include "ov9650.h"
+#include "ov9650_hw.h"
+
+
+#define MAX_WIDTH	1280
+#define MAX_HEIGHT	1024
+#define MIN_WIDTH	88
+#define MIN_HEIGHT	72
+
+#define MAX_BPP		16
+#define WIDTH_DEFT	320
+#define HEIGHT_DEFT	240
+#define FRAMERATE_DEFT	0xf
+
+/*
+ * It is required to have at least 3 frames in buffer
+ * in current implementation
+ */
+#define FRAMES_IN_BUFFER	3
+#define MIN_FRAMES_IN_BUFFER	3
+#define MAX_FRAME_SIZE		(MAX_WIDTH * MAX_HEIGHT * (MAX_BPP >> 3))
+#define BUF_SIZE_DEFT		(MAX_FRAME_SIZE )
+#define SINGLE_DESC_TRANS_MAX  	PAGE_SIZE
+#define MAX_DESC_NUM		((MAX_FRAME_SIZE / SINGLE_DESC_TRANS_MAX + 1) *\
+				 MIN_FRAMES_IN_BUFFER)
+
+#define MAX_BLOCK_NUM	20
+extern ov9650 g_ov9650;
+extern void set_still_image_ready(int);
+
+camera_function_t camera_ov9650_func = {
+	.init = camera_func_ov9650_init,
+	.deinit = camera_func_ov9650_deinit,
+	.set_capture_format = camera_func_ov9650_set_capture_format,
+	.start_capture = camera_func_ov9650_start_capture,
+	.stop_capture = camera_func_ov9650_stop_capture,
+	.command = camera_func_ov9650_command,
+	.pm_management = camera_func_ov9650_pm,
+};
+
+/***********************************************************************
+ *
+ * OV9650 Functions
+ *
+ ***********************************************************************/
+static void ov9650_gpio_init(void)
+{
+
+	set_GPIO_mode(27 | GPIO_ALT_FN_3_IN);	/* CIF_DD[0] */
+	set_GPIO_mode(114 | GPIO_ALT_FN_1_IN);	/* CIF_DD[1] */
+	set_GPIO_mode(51 | GPIO_ALT_FN_1_IN);	/* CIF_DD[2] */
+	set_GPIO_mode(115 | GPIO_ALT_FN_2_IN);	/* CIF_DD[3] */
+	set_GPIO_mode(95 | GPIO_ALT_FN_2_IN);	/* CIF_DD[4] */
+	set_GPIO_mode(94 | GPIO_ALT_FN_2_IN);	/* CIF_DD[5] */
+	set_GPIO_mode(17 | GPIO_ALT_FN_2_IN);	/* CIF_DD[6] */
+	set_GPIO_mode(108 | GPIO_ALT_FN_1_IN);	/* CIF_DD[7] */
+	set_GPIO_mode(23 | GPIO_ALT_FN_1_OUT);	/* CIF_MCLK */
+	set_GPIO_mode(54 | GPIO_ALT_FN_3_IN);	/* CIF_PCLK */
+	set_GPIO_mode(85 | GPIO_ALT_FN_3_IN);	/* CIF_LV */
+	set_GPIO_mode(84 | GPIO_ALT_FN_3_IN);	/* CIF_FV */
+	set_GPIO_mode(50 | GPIO_OUT);	/*CIF_PD */
+	set_GPIO_mode(19 | GPIO_OUT);	/*CIF_RST */
+
+
+	return;
+
+}
+
+void ov9650_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz)
+{
+	unsigned int ciclk = 0, value, div, cccr_l;
+
+	// determine the LCLK frequency programmed into the CCCR.
+	cccr_l = (CCCR & 0x0000001F);
+
+	if (cccr_l < 8)		// L = [2 - 7]
+		ciclk = (13 * cccr_l) * 100;
+	else if (cccr_l < 17)	// L = [8 - 16]
+		ciclk = ((13 * cccr_l) * 100) >> 1;
+	else if (cccr_l < 32)	// L = [17 - 31]
+		ciclk = ((13 * cccr_l) * 100) >> 2;
+	DPRINTK(KERN_WARNING "the mclk_khz = %d \n", mclk_khz);
+
+	// want a divisor that gives us a clock rate as close to, but not more than the given mclk.
+	div = (ciclk + mclk_khz) / (2 * mclk_khz) - 1;
+
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCLK_EN | CI_CICR4_MCLK_EN | CI_CICR4_DIV_SMASK << CI_CICR4_DIV_SHIFT);
+	value |= (pclk_enable) ? CI_CICR4_PCLK_EN : 0;
+	value |= (mclk_enable) ? CI_CICR4_MCLK_EN : 0;
+	value |= div << CI_CICR4_DIV_SHIFT;
+	CICR4 = value;
+	return;
+}
+
+int camera_func_ov9650_init(p_camera_context_t cam_ctx)
+{
+	u8 cm_rev, cm_pid;
+	int status;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	memset(pov, 0, sizeof(ov9650));
+
+	pov->pre_size = OV_SIZE_NONE;
+	pov->win.width = cam_ctx->capture_width;
+	pov->win.height = cam_ctx->capture_height;
+	// init context status
+	cam_ctx->dma_channels[0] = 0xFF;
+	cam_ctx->dma_channels[1] = 0xFF;
+	cam_ctx->dma_channels[2] = 0xFF;
+
+	cam_ctx->capture_width = WIDTH_DEFT;
+	cam_ctx->capture_height = HEIGHT_DEFT;
+
+	cam_ctx->capture_input_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+	cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+
+	cam_ctx->frame_rate = cam_ctx->fps = FRAMERATE_DEFT;
+
+	cam_ctx->mini_fps = FRAMERATE_DEFT - 2;
+
+	cam_ctx->buf_size = BUF_SIZE_DEFT;
+	cam_ctx->dma_descriptors_size = MAX_DESC_NUM;
+	DPRINTK(KERN_WARNING "dma_descriptors_size =%d,cam_ctx->buf_size=%d\n", cam_ctx->dma_descriptors_size,
+		cam_ctx->buf_size);
+	cam_ctx->vc.maxwidth  = MAX_WIDTH;
+	cam_ctx->vc.maxheight = MAX_HEIGHT;
+	cam_ctx->vc.minwidth  = MIN_WIDTH;
+	cam_ctx->vc.minheight = MIN_HEIGHT;
+	//DPRINTK( KERN_WARNING" before ov9650_gpio_init\n");
+	ov9650_gpio_init();
+	ci_init();
+	wmb();
+	// Configure CI according to OV9650's hardware        
+	// master parallel with 8 data pins
+	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8);
+	// enable pixel clock(sensor will provide pclock) and master clock = 26MHZ
+	//ci_set_clock(cam_ctx->clk_reg_base, 1, 1, 24);
+	ov9650_set_clock(cam_ctx->clk_reg_base, 1, 1, 2400);
+	pov->mclock = 24;
+
+	// data sample on rising and h,vsync active high
+	ci_set_polarity(0, 0, 0);
+
+	// fifo control
+	// CISetFIFO(cam_ctx->ci_reg_base, 4000, XLLP_CI_FIFO_THL_32, XLLP_TRUE, XLLP_TRUE);
+	ci_set_fifo(0, CI_FIFO_THL_32, 1, 1);
+
+	// OV9650 Power on sequence
+	// Take out of Power down mode, PWRDWN=1, NORMAL=0
+	// Assert Reset
+	// Delay
+	// Remove reset
+	// Delay
+	ov9650_power_down(0);
+	mdelay(1);
+
+	// init I2C.
+	status = i2c_ov9650_init();
+	if (status)
+		return status;
+
+	// 2 Turn on M_CLK using xx MHz and wait for 150 ms. ??
+	ci_enable(1);
+	mdelay(1);
+
+	// read out version
+    {
+		cm_pid = cm_rev = 0;
+		status = ov9650_version_revision(&cm_pid, &cm_rev);
+
+		// Check to make sure we are working with an OV9650
+		if (cm_pid == PID_OV) {
+			int ver = (PID_OV << 8) | cm_rev;
+			pov->version = ver;
+		}
+		else {
+            return -1;
+        }
+		printk("in fun camera_func_ov9650_init version=%x\n", pov->version);
+    }
+
+	cam_ctx->sensor_type = CAMERA_TYPE_OV9650;
+
+    ov9650_soft_reset();
+
+	// turn sensor output off
+	ov9650_viewfinder_off();
+
+	return 0;
+}
+
+int camera_func_ov9650_deinit(p_camera_context_t cam_ctx)
+{
+	//init the prev_xx value.
+	ov9650_set_format(OV_SIZE_NONE, OV_FORMAT_NONE);
+	// power off the external module
+	ov9650_power_down(1);
+
+	return 0;
+}
+
+static int get_ov_format(p_camera_context_t cam_ctx, u32 * size_format, u32 * color_format)
+{
+	u32 ovSizeFormat, ovFormat;
+
+	// Set the current mode
+	switch (cam_ctx->capture_input_format) {
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+		ovFormat = OV_FORMAT_YUV_422;
+		printk("in get_ov_format ovFormat = OV_FORMAT_YUV_422\n");
+		break;
+	case CAMERA_IMAGE_FORMAT_RGB565:
+		ovFormat = OV_FORMAT_RGB_565;
+		break;
+	default:
+		printk(KERN_INFO "The Format doesn't support by OV9650 Sensor \n");
+		return -1;
+	}
+	if (cam_ctx->capture_width == 88 && cam_ctx->capture_height == 72)
+		ovSizeFormat = OV_SIZE_QQCIF;
+	else if (cam_ctx->capture_width == 160 && cam_ctx->capture_height == 120)
+		ovSizeFormat = OV_SIZE_QQVGA;
+	else if (cam_ctx->capture_width == 176 && cam_ctx->capture_height == 144)
+		ovSizeFormat = OV_SIZE_QCIF;
+	else if (cam_ctx->capture_width == 320 && cam_ctx->capture_height == 240)
+		ovSizeFormat = OV_SIZE_QVGA;
+	else if (cam_ctx->capture_width == 352 && cam_ctx->capture_height == 288)
+		ovSizeFormat = OV_SIZE_CIF;
+	else if (cam_ctx->capture_width == 640 && cam_ctx->capture_height == 480)
+		ovSizeFormat = OV_SIZE_VGA;
+	else if (cam_ctx->capture_width == 1280 && cam_ctx->capture_height == 960)
+		ovSizeFormat = OV_SIZE_SXGA;
+	else if (cam_ctx->capture_width == 1280 && cam_ctx->capture_height == 1024)
+		ovSizeFormat = OV_SIZE_SXGA;
+	else {
+		return -1;
+	}
+	if (ovSizeFormat == OV_SIZE_QVGA)
+		printk("ovSizeFormat =OV_SIZE_QVGA \n");
+	*size_format = ovSizeFormat;
+	*color_format = ovFormat;
+	return 0;
+}
+
+int camera_func_ov9650_set_capture_format(p_camera_context_t cam_ctx)
+{
+	CI_MP_TIMING timing;
+	int status = -1;
+	u32 ovSizeFormat, ovFormat;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	status = get_ov_format(cam_ctx, &ovSizeFormat, &ovFormat);
+	if (status)
+		return -1;
+
+	status = ov9650_set_format(ovSizeFormat, ovFormat);
+	if (status)
+		return -1;
+
+	// set capture width/height and timing 
+	//timing.BFW = pov->win.x;
+	//timing.BLW = pov->win.y;
+	timing.BFW = 0;
+	timing.BLW = 0;
+	//ci_configure_mp(pov->win.width - 1, pov->win.height - 1, &timing);
+
+	return status;
+}
+
+#define COPY_BUFFERS(pdes, p_page, size) \
+do { \
+	unsigned int len; \
+	unsigned int remain_size = size; \
+	while (remain_size > 0) { \
+		if (remain_size > PAGE_SIZE) \
+			len = PAGE_SIZE; \
+		else \
+			len = remain_size; \
+		if (memcpy(page_address(*pdes), page_address(*p_page), len)) \
+			return -EFAULT; \
+		remain_size -= len; \
+		pdes ++;\
+		p_page++; \
+	} \
+} while (0);
+
+int camera_func_ov9650_start_capture(p_camera_context_t cam_ctx, unsigned int frames)
+{
+	int status = -1;
+	u32 ovSizeFormat, ovFormat;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	ci_disable(1);
+	mdelay(1);
+	ci_enable(1);
+	// clear ci fifo
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+
+	camera_set_int_mask(cam_ctx, 0x3ff | 0x0400);
+	// turn auto function on only doing continues capture
+	if (frames == 0) {
+//              CISR |= (1 << 3);
+//              while (!(CISR & (1 << 3)));     //Wait a EOF then begin start DMA
+		ov9650_auto_function_on();
+		// start dma
+		start_dma_transfer(cam_ctx, 0);
+	}
+	else {
+		status = get_ov_format(cam_ctx, &ovSizeFormat, &ovFormat);
+		if (status)
+			return -1;
+		if (pov->pre_size == OV_SIZE_NONE)
+			return -1;
+		printk("in function %s, cam_ctx->block_tail == 0\n", __FUNCTION__);
+		if (pov->pre_size == ovSizeFormat) {
+			if (cam_ctx->block_tail == 0) {
+			}
+			else {
+				struct page **p_page;
+				struct page **pdes;
+
+				printk("in function %s, cam_ctx->block_tail != 0\n", __FUNCTION__);
+				p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+				pdes = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo0_transfer_size);
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo1_transfer_size);
+				COPY_BUFFERS(pdes, p_page, cam_ctx->fifo2_transfer_size);
+			}
+			set_still_image_ready(1);
+			return 0;
+		}
+		else {
+			ov9650_auto_function_off();
+			cam_ctx->block_tail = cam_ctx->block_header = 0;
+			ov9650_prepare_capture(cam_ctx, ovSizeFormat, ovFormat);
+		}
+		// turn viewfinder on
+		ov9650_viewfinder_on();
+	}
+	// turn viewfinder on
+	ov9650_viewfinder_on();
+	ov9650_set_start();
+	return 0;
+}
+
+int Ov9650AutoFunctionOn(void)
+{
+	u8 regValue = 0;
+
+	printk("in function %s \n", __FUNCTION__);
+	//ov9650_read(0x13, &regValue);
+	if ((regValue & 0x7) == 7)
+		return 1;
+	return 0;
+}
+
+int camera_func_ov9650_stop_capture(p_camera_context_t cam_ctx)
+{
+	if (ov9650_output_stoped())
+		return 0;
+	printk("in camera_func_ov9650_stop_capture\n");
+	//if (Ov9650AutoFunctionOn())
+	// turn auto function off
+	ov9650_auto_function_off();
+	ov9650_save_gains();
+
+	// turn viewfinder off
+	ov9650_viewfinder_off();
+	stop_dma_transfer(cam_ctx);
+	ov9650_set_stop(cam_ctx);
+	return 0;
+}
+
+int camera_func_ov9650_command(p_camera_context_t cam_ctx, unsigned int cmd, void *param)
+{
+	int ret = 0;
+
+	printk("in function %s, param =%p, \n", __FUNCTION__, param);
+	switch (cmd) {
+		/* get capture size */
+	case VIDIOCGWIN:
+	{
+		struct video_window vw;
+		vw.width = cam_ctx->capture_width;
+		vw.height = cam_ctx->capture_height;
+		ov9650_get_window(&vw);
+		if (copy_to_user(param, &vw, sizeof(struct video_window)))
+			ret = -EFAULT;
+		break;
+	}
+
+		/* set capture size. */
+	case VIDIOCSWIN:
+	{
+		struct video_window vw;
+		if (copy_from_user(&vw, param, sizeof(vw))) {
+			ret = -EFAULT;
+			break;
+		}
+		printk("in %s, vw-x =%d, vw-y=%d,vw.width=%d,vw.height=%d\n",
+		       __FUNCTION__, vw.x, vw.y, vw.width, vw.height);
+		if (vw.width > 1280 || vw.height > 1024 || vw.width < MIN_WIDTH || vw.height < MIN_HEIGHT) {
+			ret = -EFAULT;
+			break;
+		}
+		/*
+		 */
+		ov9650_set_window(&vw);
+		cam_ctx->capture_width = vw.width;
+		cam_ctx->capture_height = vw.height;
+		camera_set_capture_format(cam_ctx);
+		break;
+	}
+		/*set picture style */
+	case WCAM_VIDIOCSSTYLE:
+	{
+		V4l_PIC_STYLE capture_style;
+		capture_style = (V4l_PIC_STYLE) param;
+		cam_ctx->capture_style = (V4l_PIC_STYLE) param;
+		ret = ov9650_set_special_effect(capture_style);
+		printk("in camera_func_ov9650_command ret=%d\n", ret);
+		if (cam_ctx->capture_style != V4l_STYLE_BLACK_WHITE && cam_ctx->capture_style != V4l_STYLE_SEPIA) {
+		}
+	}
+		break;
+		/*set picture light */
+	case WCAM_VIDIOCSLIGHT:
+		cam_ctx->capture_light = (int) param;
+		ret = ov9650_set_white_balance((int)param);
+		break;
+		/*set picture brightness */
+	case WCAM_VIDIOCSBRIGHT:
+		cam_ctx->capture_bright = (int) param;
+		ret = ov9650_set_brightness((int) param);
+		break;
+		/*set sensor size */
+	case WCAM_VIDIOCSSSIZE:
+		return ov9650_set_sensor_size(param);
+
+		/*get sensor size */
+	case WCAM_VIDIOCGSSIZE:
+		return ov9650_get_sensor_size(param);
+
+		/*set output size */
+	case WCAM_VIDIOCSOSIZE:
+		return ov9650_set_output_size(param);
+
+		/*get output size */
+	case WCAM_VIDIOCGOSIZE:
+		return ov9650_get_output_size(param);
+#if 0
+#endif
+		/*set video mode fps */
+	case WCAM_VIDIOCSFPS:
+	{
+		struct {
+			int fps, minfps;
+		} cam_fps;
+		DPRINTK("WCAM_VIDIOCSFPS");
+		if (copy_from_user(&cam_fps, param, sizeof(int) * 2)) {
+			return -EFAULT;
+		}
+		cam_ctx->fps = cam_fps.fps;
+		cam_ctx->mini_fps = cam_fps.minfps;
+		return ov9650_set_fps(cam_fps.fps, cam_fps.minfps);
+	}
+		return -1;
+	case WCAM_VIDIOCSNIGHTMODE:
+	{
+		struct {
+			int mode, maxexpottime;
+		} cam_mode;
+		int mode;
+		if (copy_from_user(&cam_mode, param, sizeof(cam_mode))) {
+			return -EFAULT;
+		}
+		mode = cam_mode.mode;
+		if (mode == V4l_NM_NIGHT)
+			ov9650_set_night_mode();
+		if (mode == V4l_NM_ACTION)
+			ov9650_set_action_mode();
+		if (mode == V4l_NM_AUTO)
+			ov9650_set_auto_mode();
+	}
+		break;
+	case WCAM_VIDIOCSCONTRAST:
+	{
+		ret = ov9650_set_contrast((int)param/50);
+		break;
+	}
+	case WCAM_VIDIOCSFLICKER:
+	{
+		ret = ov9650_set_flicker((int)param);
+		break;
+	}
+	default:
+		printk("in %s default case -----------------cmd =%d param=%p\n", __FUNCTION__, cmd, param);
+		ret = -1;
+	}
+	return ret;
+}
+int camera_func_ov9650_pm(p_camera_context_t cam_ctx, int suspend)
+{
+	static int resume_dma = 0;
+	if (suspend) {
+		if (cam_ctx != NULL) {
+			if (cam_ctx->dma_started) {
+				dbg_print("camera running, suspended");
+				stop_dma_transfer(cam_ctx);
+				resume_dma = 1;
+			}
+		}
+
+		disable_irq(IRQ_CAMERA);
+		CKEN &= ~CKEN24_CAMERA;
+	}
+	else {
+		CKEN |= CKEN24_CAMERA;
+		enable_irq(IRQ_CAMERA);
+
+		if (cam_ctx != NULL) {
+			dbg_print("camera running, resumed");
+			camera_init(cam_ctx);
+			//ov9650_restore_property(cam_ctx, 0);
+
+
+			if (resume_dma == 1) {
+				camera_start_video_capture(cam_ctx, 0);
+				resume_dma = 0;
+			}
+		}
+	}
+	return 0;
+}
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9650.h linux-2.6.16.5-exz/drivers/media/video/ov9650.h
--- linux-2.6.16.5/drivers/media/video/ov9650.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9650.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,71 @@
+/* 
+    ov9650 - Omnivision 9650 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+#ifndef _OV_9650_H_
+#define _OV_9650_H_
+
+#include <linux/videodev.h>
+#include "camera.h"
+typedef struct {
+	u32 version;
+	u32 stoped;
+	u32 mclock;
+	u32 pre_size;
+	u32 exp_value;
+	u32 exp_time;
+	u32 adjusted_exp_value;
+	u32 adjusted_exp_time;
+	u8 pclock;
+	u32 gain;
+	u32 gaina;
+	u8 blue_gain;
+	u8 red_gain;
+	u8 y_average;
+	u32 sensor_width;
+	u32 sensor_height;
+	u32 sub_win;
+	u32 night_mode;
+	struct video_window win;
+}ov9650;
+	
+//////////////////////////////////////////////////////////////////////////////////////
+//
+//          Prototypes
+//
+//////////////////////////////////////////////////////////////////////////////////////
+
+int camera_func_ov9650_init( p_camera_context_t );
+
+int camera_func_ov9650_deinit( p_camera_context_t );
+
+int camera_func_ov9650_sleep(  p_camera_context_t camera_context );
+
+int camera_func_ov9650_wake(  p_camera_context_t camera_context );
+
+int camera_func_ov9650_set_capture_format( p_camera_context_t );
+
+int camera_func_ov9650_start_capture( p_camera_context_t, unsigned int frames );
+
+int camera_func_ov9650_stop_capture( p_camera_context_t );
+
+int camera_func_ov9650_pm(p_camera_context_t cam_ctx, int suspend);
+
+int camera_func_ov9650_command(p_camera_context_t camera_context, unsigned int cmd, void *param);
+
+#endif  // _OV_9650_H_
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9650_hw.c linux-2.6.16.5-exz/drivers/media/video/ov9650_hw.c
--- linux-2.6.16.5/drivers/media/video/ov9650_hw.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9650_hw.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,1773 @@
+/* 
+    ov9650_hw - Omnivision 9650 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/types.h>
+#include <linux/delay.h>
+#include <asm/hardware.h>
+#include <asm/dma.h>
+
+#include "camera.h"
+#include "ov9650.h"
+#include "ov9650_hw.h"
+
+ov9650 g_ov9650;
+/***********************************************************************
+*  Attention: This is platform related!
+***********************************************************************/
+static const u32 OV9650_PWRDWN_GPIO[2] = { 1, 50 };
+//static const u32 OV9650_RESET_GPIO[2] = { 1, xxx };
+volatile int ov9650_step = 0;
+
+/***********************************************************************
+*  Register Settings
+***********************************************************************/
+
+static u8 gInit_9650[] = {
+    /*
+	//0x12,  0x80,	//0x12
+	0x11,  0x87,	//0x11
+	0x39,  0x40,	//0x39
+	0x13,  0x80,	//0x13
+	0x01,  0x80,	//0x01
+	0x02,  0x80,	//0x
+	0x00,  0x00,	//0x
+	0x0c,  0x05,	//0x            stop frame
+	0x0d,  0x80,	//0x
+	0x12,  0x10,	//0x
+	0x10,  0xf0,	//0x
+	0xa1,  0x00,	//0x
+	0x3a,  0x0c,	//0x            ???
+	0x8c,  0x23,	//0x
+	0x3d,  0x92,	//0x
+	0x18,  0xc6,	//0x
+	0x17,  0x26,	//0x
+	0x1b,  0x01,	//0x
+	0x16,  0x02,	//0x
+	0x33,  0x10,	//0x
+	0x34,  0x38,	//0x
+	0xa8,  0x81,	//0x
+	0x41,  0x10,	//0x
+	0x96,  0x04,	//0x
+*/
+	//0x12,  0x80,	//0x12
+	0x11,  0x83,	//0x11
+	0x39,  0x40,	//0x39
+	0x0e,  0x01,	//0x
+	0x38,  0x12,	//0x
+	0x13,  0xc7,	//0x13
+	0x14,  0x2a,	//Gain Control
+	0x1e,  0x04,	//0x01
+
+	0x01,  0x80,	//0x
+	0x02,  0x80,	//0x
+	0x00,  0x00,	//0x
+	0x10,  0xf0,	//0x
+
+	0x12,  0x10,	//0x
+	0x0c,  0x05,	//0x            stop frame
+	0x0d,  0x80,	//0x
+	//0x3a,  0x0d,	//enable Digital BLC, Rev0 0x0c
+
+	//0x1b,  0x00,	//0x
+	0x16,  0x06,	//0x
+	0x33,  0x10,	//0x
+	0x34,  0xbf,	//0x
+	0xa8,  0x81,	//0x
+	0x41,  0x10,	//0x
+	0x96,  0x04,	//0x
+	0x3d,  0x19,	//0x
+	0x1b,  0x01,	//0x
+
+        0x18,  0xc6,
+        0x17,  0x26,
+        0x32,  0xa4,
+        0x03,  0x36,
+        //0x1a,  0x1e,
+        //0x19,  0x00,
+        0x8e,  0x00,
+        
+        0x3c,  0x60,
+        0x8f,  0xcf,
+        0x8b,  0x06,
+        0x35,  0x91,
+        0x94,  0x99,
+        0x95,  0x99,
+        0x40,  0xc1,
+        0x29,  0x2f,
+        //0x0f,  0x42,    //Rev0 0x4a
+        0x27,  0x90,
+        0x28,  0x8c,
+        0x2c,  0x08,
+        0xa5,  0x80,
+
+        0x41,  0x00,
+        0x13,  0xc5,
+        0x26,  0xe2,
+
+        0x3d,  0x92,
+        0x69,  0x80,
+        0x43,  0xf0,
+        0x44,  0x10,
+        0x45,  0x67,
+        0x46,  0x96,
+        0x47,  0x4e,
+        0x48,  0x9a,
+        0x59,  0x36,
+        0x5a,  0x73,
+        0x5b,  0x55,
+        0x5c,  0xa8,
+        0x5d,  0x84,
+        0x5e,  0x0f,
+        0x5f,  0xf0,
+        0x60,  0x0c,
+        0x61,  0x20,
+
+        0xa5,  0xd9,
+        0xa4,  0x74,
+        0x8d,  0x02,
+
+        0x13,  0xc7,
+
+        0x4f,  0x32,
+        0x50,  0x27,
+        0x51,  0x0b,
+        0x52,  0x0d,
+        0x53,  0x48,
+        0x54,  0x55,
+        0x41,  0x32,
+
+        0x8c,  0x23,
+        0x3d,  0x92,
+        0x3e,  0x02,
+        0xa9,  0x97,
+
+        0x8f,  0xcf,
+        0x90,  0x00,
+        0x91,  0x00,
+        0x9f,  0x00,
+        0xa0,  0x00,
+	0xff,0,	// End of list delimiter.        
+
+	0xff,0	// End of list delimiter.        
+};
+
+const static u8 gYUV_QQVGA[] = {
+	OV9650_COM10, 0x20,
+	OV9650_COM7, 0x10,
+	OV9650_COM1, 0x24,
+	OV9650_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_QQCIF[] = {
+	OV9650_COM10, 0x20,
+	OV9650_COM7, 0x08,
+	OV9650_COM1, 0x24,
+	OV9650_CLKRC, 0x01,
+
+	// From OmniVision
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_VGA[] = {
+	0x0d, 0x80,
+	0x11, 0x81,
+	0x12, 0x40,
+        0x18, 0xc6,
+        0x17, 0x26,
+        0x32, 0xad,
+        0x03, 0x00,
+        0x1a, 0x3d,
+        0x19, 0x01,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_QVGA[] = {
+	//0x0c, 0x05,
+	0x0d, 0x80,
+	0x11, 0x83,
+	0x12, 0x10,
+        0x18, 0xc6,
+        0x17, 0x26,
+        0x32, 0xa4,
+        0x03, 0x36,
+        0x1a, 0x1e,
+        0x19, 0x00,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+const static u8 gYUV_CIF[] = {
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_QCIF[] = {
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gYUV_SXGA[] = {
+	// From OmniVision
+	0x0d, 0x40,
+	0x11, 0x80,
+	0x12, 0x00,
+        0x18, 0xbd,
+        0x17, 0x1d,
+        0x32, 0xad,
+        0x03, 0x12,
+        0x1a, 0x81,
+        0x19, 0x01,
+	OV9650_REGEND, 0x00	// End of list delimiter.        
+};
+
+
+const static u8 gRGB_QQVGA[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_QVGA[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_QCIF[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+
+const static u8 gRGB_VGA[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_CIF[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+const static u8 gRGB_SXGA[] = {
+	OV9650_COM7, 0x80,
+	OV9650_REGEND, 0x00	// End of list delimiter.
+};
+
+/***********************************************************************
+*  Private/helper api
+***********************************************************************/
+static void ov9650_wait(int ms)
+{
+	mdelay(ms);
+}
+
+/***********************************************************************
+*  Sensor read/write 
+***********************************************************************/
+// TODO: temp
+static int ov9650_read(u8 addr, u8 *pvalue)
+{
+    return i2c_ov9650_read(addr, pvalue);
+}
+
+static int ov9650_write(u8 addr, u8 value)
+{
+    return i2c_ov9650_write(addr, value);
+}
+// end TODO
+
+static int prv_read_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return ov9650_read(subAddress, bufP);
+}
+
+static int prv_write_sensor_reg(const u8 subAddress, u8 * bufP)
+{
+	return ov9650_write(subAddress, *bufP);
+}
+
+static int ov9650_set_regs(u8 * regP)
+{
+	u32 curReg = 0;
+	int status = 0;
+
+	// The list is a register number followed by the value.
+	while (regP[curReg << 1] < OV9650_REGEND) {
+		status = prv_write_sensor_reg(regP[curReg << 1], &regP[(curReg << 1) + 1]);
+		if (curReg == 0)
+			ov9650_wait(1);
+
+		curReg++;
+	}
+	return status;
+}
+
+static void ov9650_print_all_regs(void)
+{
+#if 0
+    // read all register after power up
+	ov9650 *pov;
+	pov = &g_ov9650;
+    int i, maxreg;
+    maxreg = OV9650_LASTREG;
+
+    dbg_print("start read all default register (0x%x)", maxreg);
+    for(i=0; i<=maxreg; i++)
+    {
+        char value;
+	    ov9650_read(i, &value);
+        //dbg_print("reg addr(0x%x) value(0x%x)", i, value);
+    }
+    dbg_print("end read all default register");
+#endif
+}
+
+/***********************************************************************
+*  Power & Reset
+***********************************************************************/
+void ov9650_power_down(int powerDown)
+{
+	// OV9650 PWRDWN, 0 = NORMAL, 1=POWER DOWN
+	GPDR1 |= GPIO_bit(50);
+	//OV9650 reset CIF_RST, 0 = NORMAL, 1=RESET
+	GPDR0 |= GPIO_bit(19);
+	if (powerDown == 1) {
+		GPSR1 = GPIO_bit(50);
+	}
+	else {
+		GPCR1 = GPIO_bit(50);
+		GPSR0 = GPIO_bit(19);
+		mdelay(20);
+		GPCR0 = GPIO_bit(19);
+	}
+	mdelay(100);
+}
+
+void ov9650_soft_reset(void)
+{
+    ov9650 *pov = &g_ov9650;
+	u8 regValue;
+	regValue = 0x80;
+	prv_write_sensor_reg(OV9650_COM7, &regValue);
+	mdelay(10);
+
+    ov9650_print_all_regs();
+
+    ov9650_set_regs(gInit_9650);
+
+    //0x3a,  0x0d,	//enable Digital BLC, Rev0 0x0c
+    //0x0f,  0x42,    //Rev0 0x4a
+    if ( (pov->version&0xff) == PID_9650_0 ) 
+    {
+		ov9650_write(0x3a, 0x0c);
+		ov9650_write(0x0f, 0x4a);
+    }
+    else
+    {
+		ov9650_write(0x3a, 0x0d);
+		ov9650_write(0x0f, 0x42);
+    }
+
+    dbg_print("end initial register");
+	return;
+}
+
+int ov9650_output_stoped()
+{
+	ov9650 *pov;
+	pov = &g_ov9650;
+	return pov->stoped;
+}
+
+void ov9650_set_start()
+{
+	ov9650 *pov;
+	pov = &g_ov9650;
+
+	pov->stoped = 0;
+}
+
+void ov9650_set_stop(p_camera_context_t cam_ctx)
+{
+	ov9650 *pov;
+	pov = &g_ov9650;
+
+	pov->stoped = 1;
+}
+
+/***********************************************************************
+*  Settings
+***********************************************************************/
+int ov9650_version_revision(u8 * pCmRevision, u8 * pSensorRevision)
+{
+	prv_read_sensor_reg(OV9650_PID, pCmRevision);
+	prv_read_sensor_reg(OV9650_VER, pSensorRevision);
+	return 0;
+}
+
+void ov9650_auto_function_on(void)
+{
+	u8 val;
+	DPRINTK("in function %s\n", __FUNCTION__);
+	prv_read_sensor_reg(OV9650_COM8, &val);
+	val |= 0x07;
+	prv_write_sensor_reg(OV9650_COM8, &val);
+}
+
+void ov9650_auto_function_off(void)
+{
+	u8 val;
+	DPRINTK("in function %s\n", __FUNCTION__);
+	prv_read_sensor_reg(OV9650_COM8, &val);
+	val &= ~0x07;
+	prv_write_sensor_reg(OV9650_COM8, &val);
+}
+
+
+/***********************************************************************
+*  Viewfinder, still 
+***********************************************************************/
+int ov9650_viewfinder_on(void)
+{
+	u8 com3;
+
+    ov9650_print_all_regs();
+
+	prv_read_sensor_reg(OV9650_COM3, &com3);
+	com3 &= ~0x01;
+	prv_write_sensor_reg(OV9650_COM3, &com3);
+
+	return OV_ERR_NONE;
+}
+
+
+int ov9650_viewfinder_off(void)
+{
+	u8 com3;
+
+	prv_read_sensor_reg(OV9650_COM3, &com3);
+	com3 |= 0x01;
+	prv_write_sensor_reg(OV9650_COM3, &com3);
+
+    ov9650_print_all_regs();
+
+	mdelay(200);
+	return OV_ERR_NONE;
+}
+
+
+static u8 *ov9650_get_regs_list(u32 captureSizeFormat, u32 colorFormat)
+{
+	char *formatNameP=NULL;
+	u8 *defaultDataP=NULL;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	// Get the default setting.
+	if (colorFormat == OV_FORMAT_YUV_422) {
+		switch (captureSizeFormat) {
+		case OV_SIZE_QQVGA:
+			defaultDataP = (u8 *)gYUV_QQVGA;
+			formatNameP = "QQVGA.422";
+			break;
+		case OV_SIZE_QQCIF:
+			defaultDataP = (u8 *)gYUV_QQCIF;
+			formatNameP = "QQCIF.422";
+			break;
+		case OV_SIZE_QVGA:
+			defaultDataP = (u8 *)gYUV_QVGA;
+			formatNameP = "QVGA.422";
+			break;
+		case OV_SIZE_QCIF:
+			defaultDataP = (u8 *)gYUV_QCIF;
+			formatNameP = "QCIF.422";
+			break;
+		case OV_SIZE_VGA:
+			defaultDataP = (u8 *)gYUV_VGA;
+			formatNameP = "VGA.422";
+			break;
+		case OV_SIZE_CIF:
+			defaultDataP = (u8 *)gYUV_CIF;
+			formatNameP = "CIF.422";
+			break;
+		case OV_SIZE_SXGA:
+			defaultDataP = (u8 *)gYUV_SXGA;
+			formatNameP = "SXGA.422";
+			break;
+		default:
+			return NULL;
+		}
+	}
+
+	if (colorFormat == OV_FORMAT_RGB_565) {
+		switch (captureSizeFormat) {
+		case OV_SIZE_QQVGA:
+			defaultDataP = (u8 *)gRGB_QQVGA;
+			formatNameP = "QQVGA.RGB";
+			break;
+		case OV_SIZE_QCIF:
+			defaultDataP = (u8 *)gRGB_QCIF;
+			formatNameP = "QCIF.RGB";
+			break;
+
+		case OV_SIZE_QVGA:
+			defaultDataP = (u8 *)gRGB_QVGA;
+			formatNameP = "QVGA.RGB";
+			break;
+		case OV_SIZE_VGA:
+			defaultDataP = (u8 *)gRGB_VGA;
+			formatNameP = "VGA.RGB";
+			break;
+		case OV_SIZE_CIF:
+			defaultDataP = (u8 *)gRGB_CIF;
+			formatNameP = "CIF.RGB";
+			break;
+		case OV_SIZE_SXGA:
+			defaultDataP = (u8 *)gRGB_SXGA;
+			formatNameP = "SXGA.RGB";
+			break;
+		default:
+			return NULL;
+		}
+	}
+    dbg_print("%s", formatNameP);
+	return defaultDataP;
+}
+
+/***********************************************************************
+*  Format 
+***********************************************************************/
+static int ov9650_switch_format(u32 captureSizeFormat, u32 colorFormat)
+{
+	int status;
+	u8 *regsP;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	regsP = (u8 *) ov9650_get_regs_list(captureSizeFormat, colorFormat);
+	// Get the pointer to the basic setting.  The pointer must be freed after exiting.
+
+	if (regsP == NULL)
+		return OV_ERR_PARAMETER;
+
+    status = ov9650_set_regs(regsP);
+	mdelay(50);
+	if (pov->night_mode == 1) {
+		//night mode 
+		ov9650_set_night_mode();
+	}
+	else if (pov->night_mode == 2) {	//action mode
+		ov9650_set_action_mode();
+	}
+	else
+		ov9650_set_auto_mode();
+
+	return status;
+}
+
+int ov9650_set_format(u32 captureSizeFormat, u32 colorFormat)
+{
+	int status = OV_ERR_PARAMETER;
+	u8 *regsP;
+	static u32 prev_colorFormat = OV_FORMAT_NONE, prev_size = OV_SIZE_NONE;
+
+	if (prev_colorFormat == colorFormat && captureSizeFormat == prev_size)
+		return 0;
+	if ((captureSizeFormat == OV_SIZE_NONE) && (colorFormat == OV_FORMAT_NONE))
+		goto no_set;
+
+	if ((prev_colorFormat == OV_FORMAT_NONE) && (prev_size == OV_SIZE_NONE)) {
+		regsP = (u8 *) ov9650_get_regs_list(captureSizeFormat, colorFormat);
+		// Get the pointer to the basic setting.  The pointer must be freed after exiting.
+
+		if (regsP == NULL)
+			return OV_ERR_PARAMETER;
+		//ov9650_soft_reset();
+		// Blast the entire parameter tree into the part.
+		status = ov9650_set_regs(regsP);
+	}
+	else {
+		status = ov9650_switch_format(captureSizeFormat, colorFormat);
+	}
+no_set:
+	prev_colorFormat = colorFormat;
+	prev_size = captureSizeFormat;
+	return status;
+}
+
+void ov9650_save_gains(void)
+{
+	u8 gainh, gainl, aech, aechm, aecl, laec, blue, red;
+	u32 gain, gaina, exp_value;
+	ov9650 *pov;
+	u8 regValue;
+	static u32 prevSize;
+
+	pov = &g_ov9650;
+
+	// Get current size
+	prv_read_sensor_reg(OV9650_COM7, &regValue);
+	switch (regValue) {
+	case 0x00:
+		prevSize = OV_SIZE_SXGA;
+		break;
+	case 0x08:
+		prv_read_sensor_reg(OV9650_COM1, &regValue);
+		if (regValue & 0x20)
+			prevSize = OV_SIZE_QQCIF;
+		else
+			prevSize = OV_SIZE_QCIF;
+		break;
+	case 0x10:
+		prv_read_sensor_reg(OV9650_COM1, &regValue);
+		if (regValue & 0x20)
+			prevSize = OV_SIZE_QQVGA;
+		else
+			prevSize = OV_SIZE_QVGA;
+		break;
+	case 0x20:
+		prevSize = OV_SIZE_CIF;
+		break;
+	case 0x40:
+		prevSize = OV_SIZE_VGA;
+		break;
+	default:
+		prevSize = OV_SIZE_SXGA;
+		break;
+	}
+	pov->pre_size = prevSize;
+
+	// Get the awb, gain, exposure values
+	prv_read_sensor_reg(OV9650_BLUE, &blue);
+	prv_read_sensor_reg(OV9650_RED, &red);
+	prv_read_sensor_reg(OV9650_GAIN, &gainl);
+	prv_read_sensor_reg(OV9650_VREF, &gainh);
+	gain = gainl + ((gainh>>6)&0x03);
+	prv_read_sensor_reg(OV9650_AECHM, &aechm);
+	prv_read_sensor_reg(OV9650_AECH, &aech);
+	prv_read_sensor_reg(OV9650_COM1, &aecl);
+	exp_value = (((aechm&0x3f)<<10) + (aech << 2)) | (aecl&0x03);
+	prv_read_sensor_reg(OV9650_LAEC, &laec);
+
+	pov->gain = gain;
+	pov->blue_gain = blue;
+	pov->red_gain = red;
+	pov->exp_value = exp_value;
+	pov->exp_time = laec;
+
+    //TODO:
+    gaina = (gainl & 0x0f) + 16;
+    if(gainl&0x20)
+        gaina *= 2;
+    if(gainl&0x10)
+        gaina *= 2;
+	pov->gaina = gaina;
+
+	DPRINTK("gain=%x gaina=%x blue=%x red=%x, expv=%x expt=%x\n", 
+             gain, gaina, blue, red, exp_value, laec);
+}
+
+static void ov9650_adjust_gains(u32 prev_size, u32 cur_size)
+{
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	if (prev_size == OV_SIZE_QVGA) {
+		if (cur_size == OV_SIZE_VGA) {
+			{
+				/* capture 15 fps */
+				pov->pclock = 0x81;
+				pov->adjusted_exp_value = pov->exp_value * 2;
+			}
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x87;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x80;
+			}
+		}
+		else if (cur_size == OV_SIZE_SXGA) {
+            int adjexp = 0;
+			adjexp = pov->exp_value * 2;
+#if 0
+			if (pov->gain & 0x80) {
+				/* 8x gain capture 7.5 fps to 4x gain */
+                if(adjexp<500)
+                {
+				    //pov->pclock = 0x80;
+			        adjexp = adjexp * 2;
+			        pov->gain = pov->gain & ~0x80;
+                }
+			}
+			if (pov->gain & 0x40) {
+				/* 4x gain capture 7.5 fps to 2x gain */
+                if(adjexp<500)
+                {
+				    //pov->pclock = 0x80;
+			        adjexp = adjexp * 2;
+				    pov->gain = pov->gain & ~0x40;
+                }
+			}
+			if (pov->gain & 0x20) {
+                if(adjexp<500)
+                {
+				    //pov->pclock = 0x80;
+			        adjexp = adjexp * 2;
+				    pov->gain = pov->gain & ~0x20;
+                }
+			}
+			if (pov->gain & 0x10) {
+                if(adjexp<500)
+                {
+				    //pov->pclock = 0x80;
+			        adjexp = adjexp * 2;
+				    pov->gain = pov->gain & ~0x10;
+                }
+			}
+#endif
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x81;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x80;
+			}
+			pov->adjusted_exp_value = adjexp;
+		}
+		else if (cur_size == OV_SIZE_QVGA) {
+			if (pov->gain & 0x20) {
+				/* hight gain capture 7.5 fps */
+				pov->pclock = 0x87;
+				pov->gain = pov->gain & ~0x20;
+				pov->adjusted_exp_value = pov->exp_value;
+			}
+			else {
+				/* capture 15 fps */
+				pov->pclock = 0x83;
+				pov->adjusted_exp_value = pov->exp_value;
+			}
+			if (pov->night_mode == 1) {
+				//night mode 
+				//pov->pclock = 0x89;
+			}
+			else if (pov->night_mode == 2) {	//action mode
+				pov->pclock = 0x81;
+			}
+		}
+	}
+}
+
+static void ov9650_upload_gains(void)
+{
+	ov9650 *pov;
+	u32 expValue, gain, gaina;
+	u8 gainh, gainl, aechm, aech, aecl, laec, blue, red;
+	u8 regValue;
+
+	pov = &g_ov9650;
+
+	gain = pov->gain;
+	gaina = pov->gaina;
+	blue = pov->blue_gain;
+	red = pov->red_gain;
+	expValue = pov->adjusted_exp_value;
+	laec = pov->exp_time;
+	// Set awb
+	prv_write_sensor_reg(OV9650_BLUE, &blue);
+	prv_write_sensor_reg(OV9650_RED, &red);
+
+	// Set gain 
+    gaina = (gaina*5)/7;
+    gain = 0;
+    if(gaina>62)
+    {
+        gain |= 0x20;
+        gaina /= 2;
+    }
+    if(gaina>31)
+    {
+        gain |= 0x10;
+        gaina /= 2;
+    }
+    if( gaina>16 )
+        gaina -= 16;
+    else
+        gaina = 0;
+    gain = gain | gaina;
+
+    gainl = gain & 0xff;
+    gainh = (gain&0x0300)>>2;
+	prv_write_sensor_reg(OV9650_GAIN, &gainl);
+	prv_read_sensor_reg(OV9650_VREF, &regValue);
+	regValue = (regValue & 0x3f) | gainh;
+	prv_write_sensor_reg(OV9650_VREF, &regValue);
+	// Set exposure
+        aechm = (expValue>>10)&0x3f;
+        aech  = (expValue>>2)&0xff;
+        aecl  = expValue&0x03;
+	prv_read_sensor_reg(OV9650_AECHM, &regValue);
+	regValue = (regValue & 0xc0) | aechm;
+	prv_write_sensor_reg(OV9650_AECHM, &regValue);
+	prv_write_sensor_reg(OV9650_AECH, &aech);
+	prv_read_sensor_reg(OV9650_COM1, &regValue);
+	regValue = (regValue & 0xfc) | aecl;
+	prv_write_sensor_reg(OV9650_COM1, &regValue);
+
+	//prv_write_sensor_reg(OV9650_CLKRC, &pov->pclock);
+	DPRINTK("gain=%x gaina=%x blue=%x red=%x, expv=%x, pclock=%x\n", 
+                gain, gaina, blue, red, expValue, pov->pclock);
+}
+
+static int
+ov9650_set_dma_pages(pxa_dma_desc ** pdes,
+		     pxa_dma_desc ** des_physical, int num, struct page *array[], int total_size, int dsadr, int flags)
+{
+	int remain_size, des_transfer_size;
+	int j, target_page_num = num;
+	pxa_dma_desc *cur_des_virtual = *pdes;
+	pxa_dma_desc *cur_des_physical = *des_physical;
+
+	// in each iteration, generate one dma chain for one frame
+	remain_size = total_size;
+
+	for (j = 0; j < num; j++) {
+		// set descriptor
+		if (remain_size > PAGE_SIZE)
+			des_transfer_size = PAGE_SIZE;
+		else
+			des_transfer_size = remain_size;
+		cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+		cur_des_virtual->dsadr = dsadr;	// FIFO0 physical address
+		cur_des_virtual->dtadr = page_to_bus(array[j]);
+		cur_des_virtual->dcmd = des_transfer_size | flags;
+
+		// advance pointers
+		remain_size -= des_transfer_size;
+		cur_des_virtual++;
+		cur_des_physical++;
+		target_page_num++;
+	}
+	*pdes = cur_des_virtual;
+	*des_physical = cur_des_physical;
+    return 0;
+}
+
+static int
+ov9650_set_dma_page1(pxa_dma_desc ** pdes,
+		     pxa_dma_desc ** des_physical, int num, struct page *page1, int total_size, int dsadr, int flags)
+{
+	int remain_size, des_transfer_size;
+	int j, target_page_num = num;
+	pxa_dma_desc *cur_des_virtual = *pdes;
+	pxa_dma_desc *cur_des_physical = *des_physical;
+	int dump_page;
+
+	// in each iteration, generate one dma chain for one frame
+	remain_size = total_size;
+	dump_page = page_to_bus(page1);
+	DPRINTK("dump_page=%x", dump_page);
+
+	for (j = 0; j < num; j++) {
+		// set descriptor
+		if (remain_size > PAGE_SIZE)
+			des_transfer_size = PAGE_SIZE;
+		else
+			des_transfer_size = remain_size;
+		cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+		cur_des_virtual->dsadr = dsadr;	// FIFO0 physical address
+		cur_des_virtual->dtadr = dump_page;
+		cur_des_virtual->dcmd = des_transfer_size | flags;
+
+		// advance pointers
+		remain_size -= des_transfer_size;
+		cur_des_virtual++;
+		cur_des_physical++;
+		target_page_num++;
+	}
+	*pdes = cur_des_virtual;
+	*des_physical = cur_des_physical;
+    return 0;
+}
+
+static int ov9650_update_still_dma_chain(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+	int remain_size;
+	unsigned int i;
+
+	int target_page_num;
+
+	DPRINTK("ov9650_update_still_dma_chain\n");
+	// clear descriptor pointers
+	cam_ctx->fifo0_descriptors_virtual = cam_ctx->fifo0_descriptors_physical = 0;
+	cam_ctx->fifo1_descriptors_virtual = cam_ctx->fifo1_descriptors_physical = 0;
+	cam_ctx->fifo2_descriptors_virtual = cam_ctx->fifo2_descriptors_physical = 0;
+
+	// calculate how many descriptors are needed per frame
+	cam_ctx->fifo0_num_descriptors = cam_ctx->pages_per_fifo0;
+
+	cam_ctx->fifo1_num_descriptors = cam_ctx->pages_per_fifo1;
+
+	cam_ctx->fifo2_num_descriptors = cam_ctx->pages_per_fifo2;
+
+	// check if enough memory to generate descriptors
+	DPRINTK("in %s, cam_ctx->block_number =%d\n", __FUNCTION__, cam_ctx->block_number);
+	if ((cam_ctx->fifo0_num_descriptors + cam_ctx->fifo1_num_descriptors +
+	     cam_ctx->fifo2_num_descriptors) * cam_ctx->block_number > cam_ctx->dma_descriptors_size)
+		return -1;
+
+	// generate fifo0 dma chains
+	cam_ctx->fifo0_descriptors_virtual = (unsigned) cam_ctx->dma_descriptors_virtual;
+	cam_ctx->fifo0_descriptors_physical = (unsigned) cam_ctx->dma_descriptors_physical;
+	cur_des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual;
+	cur_des_physical = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_physical;
+
+	DPRINTK("pages_allocated=%d,fifo0_descriptors_virtual=%p\n", cam_ctx->pages_allocated, cur_des_virtual);
+
+	for (i = 0; i < 2; i++) {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = cam_ctx->fifo0_transfer_size;
+		ov9650_set_dma_page1(&cur_des_virtual, &cur_des_physical,
+				     cam_ctx->fifo0_num_descriptors,
+				     cam_ctx->page_array[cam_ctx->
+							 pages_allocated -
+							 1], remain_size, CIBR0_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+	}
+	DPRINTK("after ov9650_set_dma_page1=%d\n", cam_ctx->pages_allocated);
+	for (i = 0; i < 1; i++) {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = cam_ctx->fifo0_transfer_size;
+
+		// assume the blocks are stored consecutively
+		target_page_num = cam_ctx->pages_per_block * i;
+		DPRINTK("target_page_num=%d\n", target_page_num);
+		ov9650_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+				     cam_ctx->fifo0_num_descriptors,
+				     &cam_ctx->page_array[target_page_num],
+				     remain_size, CIBR0_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+		// stop the dma transfer on one frame captured
+		last_des_virtual = cur_des_virtual - 1;
+	}
+	last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo0_descriptors_physical);
+	last_des_virtual->ddadr |= 0x1;
+	last_des_virtual->dcmd |= DCMD_ENDIRQEN;
+
+	// generate fifo1 dma chains
+	if (cam_ctx->fifo1_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo1_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo1_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < 2; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo1_transfer_size;
+			ov9650_set_dma_page1(&cur_des_virtual,
+					     &cur_des_physical,
+					     cam_ctx->
+					     fifo1_num_descriptors,
+					     cam_ctx->page_array[cam_ctx->
+								 pages_allocated
+								 - 2],
+					     remain_size, CIBR1_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		for (i = 0; i < 1; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo1_transfer_size;
+
+			target_page_num = cam_ctx->pages_per_block * i + cam_ctx->pages_per_fifo0;
+			ov9650_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+					     cam_ctx->fifo1_num_descriptors,
+					     &cam_ctx->page_array[target_page_num],
+					     remain_size, CIBR1_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo1_descriptors_physical);
+		last_des_virtual->ddadr |= 0x1;
+	}
+	// generate fifo2 dma chains
+	if (cam_ctx->fifo2_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo2_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo2_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < 2; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo2_transfer_size;
+			ov9650_set_dma_page1(&cur_des_virtual,
+					     &cur_des_physical,
+					     cam_ctx->
+					     fifo2_num_descriptors,
+					     cam_ctx->page_array[cam_ctx->
+								 pages_allocated
+								 - 3],
+					     remain_size, CIBR2_PHY, DCMD_FLOWSRC | DCMD_BURST32);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		DPRINTK("last target_page_num=%d\n", target_page_num + cam_ctx->fifo2_num_descriptors);
+		for (i = 0; i < 1; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo2_transfer_size;
+			target_page_num =
+			    cam_ctx->pages_per_block * i + cam_ctx->pages_per_fifo0 + cam_ctx->pages_per_fifo1;
+			ov9650_set_dma_pages(&cur_des_virtual, &cur_des_physical,
+					     cam_ctx->fifo2_num_descriptors,
+					     &cam_ctx->page_array[target_page_num],
+					     remain_size, CIBR2_PHY, DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR);
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			DPRINTK("last target_page_num=%d\n", target_page_num + cam_ctx->fifo2_num_descriptors);
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo2_descriptors_physical);
+		last_des_virtual->ddadr |= 0x1;
+	}
+	return 0;
+}
+
+static int ov9650_stop_third_des(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *pdesc, *ptmp;
+	int i;
+
+	// stop the dma transfer on one frame captured
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo0_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo0_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo0_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+
+	pdesc += cam_ctx->fifo0_num_descriptors - 1;
+	pdesc->dcmd = (pdesc->dcmd & DCMD_LENGTH) | DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->dcmd = (pdesc->dcmd & DCMD_LENGTH) | DCMD_FLOWSRC | DCMD_BURST32 | DCMD_INCTRGADDR;
+	pdesc += cam_ctx->fifo0_num_descriptors;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo1_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo1_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo1_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+	pdesc += cam_ctx->fifo1_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+
+	pdesc = (pxa_dma_desc *) (cam_ctx->fifo2_descriptors_virtual);
+	ptmp = pdesc + cam_ctx->fifo2_num_descriptors * 2;
+	for (i = 0; i < cam_ctx->fifo2_num_descriptors; i++)
+		(ptmp + i)->dtadr = (pdesc + i)->dtadr;
+	pdesc += cam_ctx->fifo2_num_descriptors * 3 - 1;
+	pdesc->ddadr |= 0x1;
+    return 0;
+}
+
+int ov9650_prepare_capture(p_camera_context_t cam_ctx, u32 captureSizeFormat, u32 colorFormat)
+{
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	stop_dma_transfer(cam_ctx);
+	ov9650_switch_format(captureSizeFormat, colorFormat);
+	ov9650_adjust_gains(pov->pre_size, captureSizeFormat);
+	ov9650_upload_gains();
+	if (captureSizeFormat == OV_SIZE_VGA) {
+		//ov9650_update_still_dma_chain(cam_ctx);
+		ov9650_stop_third_des(cam_ctx);
+		/*
+		 */
+	}
+	else if (captureSizeFormat == OV_SIZE_SXGA) {
+		camera_set_int_mask(cam_ctx, 0x3fd | 0x0400);
+		ov9650_update_still_dma_chain(cam_ctx);
+		//ci_clear_int_status(0xFFFFFFFF);
+		//DPRINTK("before camera_sleep \n");
+		//camera_sleep();
+	}
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+	start_dma_transfer(cam_ctx, 1);
+	DPRINTK("after ov9650_prepare_capture \n");
+    return 0;
+}
+
+int ov9650_set_special_effect(int style)
+{
+#if 0
+	int ret = 0;
+	u32 index, curReg;
+	u8 *regsP;
+	u8 regValue;
+
+	DPRINTK("in function %s parameter=%d\n", __FUNCTION__, style);
+	curReg = 0x3a;
+	ov9650_read(0x3a, &regValue);
+	regValue = regValue & 0xf;
+	switch (style) {
+	case V4l_STYLE_NORMAL:
+		DPRINTK("V4l_STYLE_NORMAL\n");
+		regValue &= 0x7f;
+		//ov9650_write(0x3a, 0x08);
+		ov9650_write(0x3a, regValue);
+		ov9650_write(0x67, 0x80);
+		ov9650_write(0x68, 0x80);
+		break;
+	case V4l_STYLE_BLACK_WHITE:
+		DPRINTK("V4l_STYLE_BLACK_WHITE\n");
+		regValue |= 0x10;
+		//ov9650_write(0x3a, 0x18);
+		ov9650_write(0x3a, regValue);
+		ov9650_write(0x67, 0x80);
+		ov9650_write(0x68, 0x80);
+		break;
+	case V4l_STYLE_SEPIA:
+		DPRINTK("V4l_STYLE_SEPIA\n");
+		regValue |= 0x10;
+		//ov9650_write(0x3a, 0x18);
+		ov9650_write(0x3a, regValue);
+		ov9650_write(0x67, 0xa0);
+		ov9650_write(0x68, 0x40);
+		break;
+		//case V4l_STYLE_BULISH:
+		DPRINTK("V4l_STYLE_BULISH\n");
+		ov9650_write(0x3a, 0x18);
+		ov9650_write(0x67, 0x80);
+		ov9650_write(0x68, 0xc0);
+		break;
+	default:
+		DPRINTK("case default ????????????????????\n");
+		//ret=OV_ERR_PARAMETER;
+	}
+	return ret;
+#else
+	return 0;
+#endif
+}
+
+int ov9650_set_brightness(int bright)
+{
+#if 0
+	int ret = 0;
+	const u8 BN[] = {
+		//BN-3
+		0x0f, 0x4f,
+		0x27, 0xe8,
+		0x28, 0xe0,
+		0x29, 0xe0,
+		0x2c, 0xe0,
+		//BN-2
+		0x0f, 0x4f,
+		0x27, 0xc8,
+		0x28, 0xc0,
+		0x29, 0xc0,
+		0x2c, 0xc0,
+		//BN-1
+		0x0f, 0x4f,
+		0x27, 0xa8,
+		0x28, 0xa0,
+		0x29, 0xa0,
+		0x2c, 0xa0,
+		//BN-0
+		0x0f, 0x4f,
+		0x27, 0x88,
+		0x28, 0x80,
+		0x29, 0x80,
+		0x2c, 0x80,
+		//BN+1
+		0x0f, 0x4f,
+		0x27, 0x28,
+		0x28, 0x20,
+		0x29, 0x20,
+		0x2c, 0x20,
+		//BN+2
+		0x0f, 0x4f,
+		0x27, 0x48,
+		0x28, 0x40,
+		0x29, 0x40,
+		0x2c, 0x40,
+		//BN+3
+		0x0f, 0x4f,
+		0x27, 0x68,
+		0x28, 0x60,
+		0x29, 0x60,
+		0x2c, 0x60,
+	};
+	u8 *regs;
+	int n = 5;
+	int i;
+
+	DPRINTK("in function %s bright =%d \n", __FUNCTION__, bright);
+	if (bright < -3)
+		bright = -3;
+	if (bright > 3)
+		bright = 3;
+	//bright = -4 .. 4
+	regs = &BN[(bright + 3) * n * 2];
+	//for (i = 0; i < n * 2; i += 2)
+	//	ret |= ov9650_write(regs[i], regs[i + 1]);
+#endif
+	return OV_ERR_NONE;
+}
+
+#if 0
+static int ov9650_set_color_saturation(int saturation)
+{
+	const u8 CS[] = {
+		//Saturation: 0.25
+		0x4f, 0x14,
+		0x50, 0x10,
+		0x51, 0x3,
+		0x52, 0x6,
+		0x53, 0x13,
+		0x54, 0x19,
+		//Saturation 0.5
+		0x4f, 0x28,
+		0x50, 0x22,
+		0x51, 0x6,
+		0x52, 0xc,
+		0x53, 0x26,
+		0x54, 0x33,
+		//Saturation 0.75 (Default)
+		0x4f, 0x3c,
+		0x50, 0x32,
+		0x51, 0x9,
+		0x52, 0x13,
+		0x53, 0x39,
+		0x54, 0x4c,
+		//Saturation 1.0
+		0x4f, 0x50,
+		0x50, 0x43,
+		0x51, 0xd,
+		0x52, 0x19,
+		0x53, 0x4d,
+		0x54, 0x66,
+		//Saturation 1.25
+		0x4f, 0x64,
+		0x50, 0x53,
+		0x51, 0x10,
+		0x52, 0x1f,
+		0x53, 0x5f,
+		0x54, 0x7f,
+	};
+	u8 *regs;
+	int n = 6;
+	int i;
+
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, saturation);
+	if (saturation < 0)
+		saturation = 0;
+	if (saturation > 4)
+		saturation = 4;
+
+	regs = &CS[saturation * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ov9650_write(regs[i], regs[i + 1]);
+	return OV_ERR_NONE;
+
+}
+#endif
+
+int ov9650_set_white_balance(V4l_PIC_WB light)
+{
+#if 0
+	int ret = 0;
+	u8 *regs;
+	int n = 13;
+	int i = 0;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, light);
+	switch (light) {
+	case V4l_WB_DIRECT_SUN:
+		//ov9650_set_color_saturation(3);
+		DPRINTK("V4l_WB_DIRECT_SUN\n");
+		i = 0 * n * 2;
+		//ov9650_set_night_mode();
+		break;
+	case V4l_WB_INCANDESCENT:
+		//ov9650_set_color_saturation(2);
+		DPRINTK("V4l_WB_INCANDESCENT\n");
+		i = 1 * n * 2;
+		//ov9650_set_action_mode();
+		break;
+	case V4l_WB_FLUORESCENT:
+		//ov9650_set_color_saturation(2);
+		DPRINTK("V4l_WB_FLUORESCENT\n");
+		i = 2 * n * 2;
+		break;
+	default:
+		/* auto */
+		//ov9650_set_color_saturation(2);
+		DPRINTK("case default ????????????????????\n");
+		i = 3 * n * 2;
+		n = 19;
+		//ov9650_set_auto_mode();
+		break;
+	}
+    //TODO:
+#endif
+
+	return OV_ERR_NONE;
+}
+
+int ov9650_set_night_mode()
+{
+#if 0
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	pov->night_mode = 1;
+	//ov9650_write(0x11, 0x89);
+	ov9650_write(0x3b, 0xe1);
+#endif
+    return 0;
+}
+
+int ov9650_set_action_mode()
+{
+#if 0
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	pov->night_mode = 2;
+	ov9650_write(0x11, 0x81);
+	ov9650_write(0x3b, 0x01);
+	ov9650_write(0x2d, 0x0);
+	ov9650_write(0x2e, 0x0);
+#endif
+    return 0;
+}
+
+int ov9650_set_auto_mode()
+{
+#if 0
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	pov->night_mode = 0;
+	ov9650_write(0x11, 0x83);
+	ov9650_write(0x3b, 0x01);
+	ov9650_write(0x2d, 0x0);
+	ov9650_write(0x2e, 0x0);
+#endif
+    return 0;
+}
+
+int ov9650_set_flicker(int freq)
+{
+#if 0
+	int ret = 0;
+	const u8 LE_v3[] = {
+		//OutDoor
+		0x3b, 0x00,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 60Hz(Default)
+		0x3b, 0x01,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 50Hz
+		0x3b, 0x01,
+		0x2a, 0x10,
+		0x2b, 0x40,
+		0x6a, 0x3d,
+	};
+	const u8 LE_v2[] = {
+		//OutDoor
+		0x13, 0x8d,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 60Hz(Default)
+		0x13, 0x8d,
+		0x2a, 0,
+		0x2b, 0,
+		0x6a, 0x3d,
+		//Indoor 50Hz
+		0x13, 0x8d,
+		0x2a, 0x10,
+		0x2b, 0x14,
+		0x6a, 0x3d,
+	};
+	u8 *regs;
+	int n = 4;
+	int i = 0;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	DPRINTK("in function %s ,parameter=%d\n", __FUNCTION__, freq);
+	switch (freq) {
+	case 0:
+		i = 0 * n * 2;
+		break;
+	case 60:
+		i = 1 * n * 2;
+		break;
+	case 50:
+		i = 2 * n * 2;
+		break;
+	default:
+		i = 0;
+		break;
+	}
+
+	//regs = &LE_v2[i];
+	regs = &LE_v3[i];
+
+
+	for (i = 0; i < n * 2; i += 2)
+		ret |= ov9650_write(regs[i], regs[i + 1]);
+#endif
+	return OV_ERR_NONE;
+}
+
+int ov9650_set_contrast(int contrast)
+{
+#if 0
+	const u8 CO[] = {
+		//Low contrast
+		0x6C, 0x20,
+		0x6D, 0x50,
+		0x6E, 0xc0,
+		0x6F, 0xa8,
+		0x70, 0x88,
+		0x71, 0x80,
+		0x72, 0x78,
+		0x73, 0x70,
+		0x74, 0x68,
+		0x75, 0x58,
+		0x76, 0x40,
+		0x77, 0x30,
+		0x78, 0x28,
+		0x79, 0x20,
+		0x7A, 0x1e,
+		0x7B, 0x18,
+		0x7C, 0x04,
+		0x7D, 0x07,
+		0x7E, 0x1f,
+		0x7F, 0x49,
+		0x80, 0x5a,
+		0x81, 0x6a,
+		0x82, 0x79,
+		0x83, 0x87,
+		0x84, 0x94,
+		0x85, 0x9f,
+		0x86, 0xaf,
+		0x87, 0xbb,
+		0x88, 0xcf,
+		0x89, 0xdf,
+		0x8A, 0xee,
+		//Middle contrast (default)
+		0x6C, 0x40,
+		0x6D, 0x30,
+		0x6E, 0x4B,
+		0x6F, 0x60,
+		0x70, 0x70,
+		0x71, 0x70,
+		0x72, 0x70,
+		0x73, 0x70,
+		0x74, 0x60,
+		0x75, 0x60,
+		0x76, 0x50,
+		0x77, 0x48,
+		0x78, 0x3A,
+		0x79, 0x2E,
+		0x7A, 0x28,
+		0x7B, 0x22,
+		0x7C, 0x04,
+		0x7D, 0x07,
+		0x7E, 0x10,
+		0x7F, 0x28,
+		0x80, 0x36,
+		0x81, 0x44,
+		0x82, 0x52,
+		0x83, 0x60,
+		0x84, 0x6C,
+		0x85, 0x78,
+		0x86, 0x8C,
+		0x87, 0x9E,
+		0x88, 0xBB,
+		0x89, 0xD2,
+		0x8A, 0xE6,
+		//High contrast
+		0x6c, 0x50,
+		0x6d, 0x60,
+		0x6e, 0x58,
+		0x6f, 0x58,
+		0x70, 0x58,
+		0x71, 0x50,
+		0x72, 0x50,
+		0x73, 0x50,
+		0x74, 0x50,
+		0x75, 0x50,
+		0x76, 0x4c,
+		0x77, 0x4c,
+		0x78, 0x45,
+		0x79, 0x3c,
+		0x7a, 0x2c,
+		0x7b, 0x24,
+		0x7c, 0x05,
+		0x7d, 0x0b,
+		0x7e, 0x16,
+		0x7f, 0x2c,
+		0x80, 0x37,
+		0x81, 0x41,
+		0x82, 0x4b,
+		0x83, 0x55,
+		0x84, 0x5f,
+		0x85, 0x69,
+		0x86, 0x7c,
+		0x87, 0x8f,
+		0x88, 0xb1,
+		0x89, 0xcf,
+		0x8a, 0xe5,
+	};
+
+	u8 *regs;
+	int n = 31;
+	int i;
+
+	DPRINTK("in function %s parameter=%d \n", __FUNCTION__, contrast);
+	if (contrast < 0)
+		contrast = 0;
+	if (contrast > 2)
+		contrast = 2;
+
+	regs = &CO[contrast * n * 2];
+	for (i = 0; i < n * 2; i += 2)
+		ov9650_write(regs[i], regs[i + 1]);
+#endif
+	return OV_ERR_NONE;
+
+}
+
+static int ov9650_find_window(struct video_window *vw, int *sub_win)
+{
+	int ret = OV_SIZE_NONE;
+
+	*sub_win = 1;
+	if (vw->width > 1280 || vw->height > 1024 || vw->width < 88|| vw->height < 72) {
+		ret = OV_SIZE_NONE;
+	}
+	else if (vw->width == 1280 && ((vw->height == 960)||(vw->height == 1024))) {
+		*sub_win = 0;
+		ret = OV_SIZE_SXGA;
+	}
+	else if (vw->width >= 640 && vw->height >= 480) {
+		if (vw->width == 640 && vw->height == 480)
+			*sub_win = 0;
+		ret = OV_SIZE_VGA;
+	}
+	else if (vw->width >= 352 && vw->height >= 288) {
+		if (vw->width == 352 && vw->height == 288)
+			*sub_win = 0;
+		ret = OV_SIZE_CIF;
+	}
+	else if (vw->width >= 320 && vw->height >= 240) {
+		if (vw->width == 320 && vw->height == 240)
+			*sub_win = 0;
+		ret = OV_SIZE_QVGA;
+	}
+	else if (vw->width >= 176 && vw->height >= 144) {
+		if (vw->width == 176 && vw->height == 144)
+			*sub_win = 0;
+		ret = OV_SIZE_QCIF;
+	}
+	else if (vw->width >= 160 && vw->height >= 120) {
+		if (vw->width == 160 && vw->height == 120)
+			*sub_win = 0;
+		ret = OV_SIZE_QQVGA;
+	}
+	else if (vw->width >= 88 && vw->height >= 72) {
+		if (vw->width == 88 && vw->height == 72)
+			*sub_win = 0;
+		ret = OV_SIZE_QQCIF;
+	}
+	DPRINTK("in %s,ret = %d, subwin=%d\n", __FUNCTION__, ret, *sub_win);
+	return ret;
+}
+
+int ov9650_set_window(struct video_window *vw)
+{
+	int ret = 0;
+	int x_end;
+	int y_end;
+	struct video_window window;
+	int sub_win;
+	ov9650 *pov;
+
+	pov = &g_ov9650;
+	vw->width = (vw->width + 7) & (~0x7);
+	vw->height = (vw->height + 7) & (~0x7);
+	vw->x = vw->y = 0;
+	x_end = window.width = (vw->width + vw->x);
+	y_end = window.height = (vw->height + vw->y);
+	DPRINTK("in %s, vw-x =%d, vw-y=%d,vw->width=%d,vw->height=%d\n",
+		__FUNCTION__, vw->x, vw->y, vw->width, vw->height);
+	ret = ov9650_find_window(&window, &sub_win);
+	if (ret <= OV_SIZE_NONE)
+		return -1;
+
+	ret = ov9650_set_format(ret, OV_FORMAT_YUV_422);
+	if (ret < 0)
+		return -1;
+
+	pov->win = *vw;
+	return ret;
+}
+
+int ov9650_get_window(struct video_window *vw)
+{
+	ov9650 *pov;
+	pov = &g_ov9650;
+	*vw = pov->win;
+	return 0;
+}
+
+struct win_size {
+	int width;
+	int height;
+};
+int ov9650_set_sensor_size(void *w_size)
+{
+	struct win_size size;
+	ov9650 *pov;
+	pov = &g_ov9650;
+	if (copy_from_user(&size, w_size, sizeof(struct win_size))) {
+		return -EFAULT;
+	}
+//make it in an even of multiple of 8
+	size.height = (size.height + 7) / 8 * 8;
+	pov->sensor_width = size.width;
+	pov->sensor_height = size.height;
+	return 0;
+}
+
+int ov9650_get_sensor_size(void *w_size)
+{
+    return 0;
+}
+
+int ov9650_set_output_size(void *w_size)
+{
+	struct win_size size;
+	ov9650 *pov;
+	pov = &g_ov9650;
+	if (copy_from_user(&size, w_size, sizeof(struct win_size))) {
+		return -EFAULT;
+	}
+//make it in an even of multiple of 8
+	size.height = (size.height + 7) / 8 * 8;
+	pov->sensor_width = size.width;
+	pov->sensor_height = size.height;
+	return 0;
+}
+
+int ov9650_get_output_size(void *w_size)
+{
+    return 0;
+}
+
+#if 0
+static int test_divider(int res, int fps)
+{
+	int max_hz = 48 * 1000000;
+	int div = 1;
+	int i;
+	int ov_fps[5] = { 3, 7, 15, 30, 60 };
+	u32 value = 320 * 240;
+	/*
+	   switch (prevSize) {
+	   case OV_SIZE_QQCIF:
+	   value = 88 * 72;
+	   break;
+	   case OV_SIZE_QQVGA:
+	   value = 176 * 144;
+	   break;
+	   case OV_SIZE_QCIF:
+	   value = 160 * 120;
+	   break;
+	   case OV_SIZE_QVGA:
+	   value = 320 * 240;
+	   break;
+	   case OV_SIZE_CIF:
+	   value = 352 * 288;
+	   break;
+	   case OV_SIZE_VGA:
+	   value = 640 * 480;
+	   break;
+	   case OV_SIZE_SXGA:
+	   value = 1280 * 960;
+	   break;
+	   }
+
+	   while (max_hz / res / div > fps)
+	   div++;
+	   if (div > 64)
+	   div = 64;
+	   return (div - 1);
+
+	   for (i =0;i<5;i++)
+	   if ( fps < ov_fps[i] ) 
+	   continue;
+	 */
+	if (fps == 0)
+		return 0;
+	if (fps > 60)
+		fps = 60;
+	return (div = 60 / fps - 1);
+}
+#endif
+
+int ov9650_set_fps(int fps, int min_fps)
+{
+#if 0
+	u32 res = 0;
+	u8 value;
+	if (fps < 0) {
+		DPRINTK("in %s fps = %d divider value =%d\n", __FUNCTION__, fps, res);
+		fps = 15;
+	}
+	res = test_divider(0, fps);
+	ov9650_read(OV9650_CLKRC, &value);
+	value = (value & 0xc0) | res;
+	ov9650_write(OV9650_CLKRC, value);
+	DPRINTK("in %s fps = %d divider value =%d\n", __FUNCTION__, fps, res);
+	/*
+		ov9650_set_night_mode();
+		ov9650_set_action_mode();
+		ov9650_set_auto_mode();
+	 */
+#endif
+	return 0;
+}
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/ov9650_hw.h linux-2.6.16.5-exz/drivers/media/video/ov9650_hw.h
--- linux-2.6.16.5/drivers/media/video/ov9650_hw.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/ov9650_hw.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,284 @@
+/* 
+    ov9650_hw - Omnivision 9650 CMOS sensor driver 
+
+    Copyright (C) 2003, Intel Corporation
+
+    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.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _OV_9650_HW_H_
+#define _OV_9650_HW_H_
+
+/***********************************************************************
+ *
+ * Constants & Structures
+ *
+ ***********************************************************************/
+// Revision constants
+#define PID_OV			0x96
+#define PID_9650_0		0x51
+#define PID_9650		0x52
+
+// Return codes
+#define OV_ERR_NONE       	0x00
+#define OV_ERR_TIMEOUT    	-1
+#define OV_ERR_PARAMETER  	-2  
+#define OV_COMM_ERR		-3
+
+#define CIBR0_PHY	(0x50000000 + 0x28)
+#define CIBR1_PHY	(0x50000000 + 0x30)
+#define CIBR2_PHY	(0x50000000 + 0x38)
+#define DPRINTK(fmt,args...)	do { if (DEBUG) printk("in function %s "fmt,__FUNCTION__,##args);} while(0)
+
+// Output Size & Format
+/*
+#define OV_SIZE_NONE		0
+#define OV_SIZE_QQVGA		0x01
+#define OV_SIZE_QVGA		( OV_SIZE_QQVGA << 1 )
+#define OV_SIZE_VGA		( OV_SIZE_QQVGA << 2 )
+#define OV_SIZE_SXGA		( OV_SIZE_QQVGA << 3 )
+#define OV_SIZE_QQCIF		0x10
+#define OV_SIZE_QCIF		( OV_SIZE_QQCIF << 1 )			
+#define OV_SIZE_CIF		( OV_SIZE_QQCIF << 2 )			
+#define OV_FORMAT_NONE		0
+#define OV_FORMAT_YUV_422	1
+#define OV_FORMAT_RGB_565	2
+*/
+enum OV_SIZE {
+	OV_SIZE_NONE=0	,
+	OV_SIZE_QQVGA	,
+	OV_SIZE_QVGA	,
+	OV_SIZE_VGA	,
+	OV_SIZE_SXGA	,
+	OV_SIZE_QQCIF	,
+	OV_SIZE_QCIF	,
+	OV_SIZE_CIF	
+};
+enum OV_FORMAT {
+	OV_FORMAT_NONE=0 ,
+	OV_FORMAT_YUV_422,
+	OV_FORMAT_RGB_565,
+};
+
+// Camera Mode
+#define VIEWFINDER_MODE     0x10
+#define STILLFRAME_MODE     0x20
+
+// Others
+#define OV9650_TIMEOUT    1000    // ms to timeout.
+
+// OV9650 Register Definitions
+#define OV9650_GAIN		0x0000
+#define OV9650_BLUE		0x0001
+#define OV9650_RED		0x0002
+#define OV9650_VREF		0x0003
+#define OV9650_COM1		0x0004
+#define OV9650_BAVE		0x0005				// U/B Average Level
+#define OV9650_GEAVE		0x0006				// Y/Ge Average Level
+#define OV9650_GOAVE		0x0007				// Y/Go Average Level
+#define OV9650_RAVE		0x0008				// V/R Average level
+#define OV9650_COM2		0x0009				// Common control 2
+#define OV9650_PID		0x000A				// Product ID
+#define OV9650_VER		0x000B				// Version
+#define OV9650_COM3		0x000C
+#define OV9650_COM4		0x000D
+#define OV9650_COM5		0x000E
+#define OV9650_COM6		0x000F
+#define OV9650_AECH		0x0010
+#define OV9650_CLKRC		0x0011
+#define OV9650_COM7		0x0012
+#define OV9650_COM8		0x0013
+#define OV9650_COM9		0x0014
+#define OV9650_COM10		0x0015
+#define OV9650_WS		0x0016
+#define OV9650_HSTART		0x0017
+#define OV9650_HSTOP		0x0018
+#define OV9650_VSTRT		0x0019
+#define OV9650_VSTOP		0x001A
+#define OV9650_PSHFT		0x001B
+#define OV9650_MIDH		0x001C
+#define OV9650_MIDL		0x001D
+#define OV9650_MVLP		0x001E
+#define OV9650_LAEC		0x001F
+#define OV9650_BOS		0x0020
+#define OV9650_GBOS		0x0021
+#define OV9650_GROS		0x0022
+#define OV9650_ROS		0x0023
+#define OV9650_AEW		0x0024
+#define OV9650_AEB		0x0025
+#define OV9650_VPT		0x0026
+#define OV9650_BBIAS		0x0027
+#define OV9650_GbBIAS		0x0028
+//#define OV9650_GrBIAS		0x0029
+#define OV9650_GrCOM		0x0029
+#define OV9650_EXHCH		0x002A
+#define OV9650_EXHCL		0x002B
+#define OV9650_RBIAS		0x002C
+#define OV9650_ADVFL		0x002D
+#define OV9650_ADVFH		0x002E
+#define OV9650_YAVE		0x002F
+#define OV9650_HSYST		0x0030
+#define OV9650_HSYEN		0x0031
+#define OV9650_HREF		0x0032
+#define OV9650_CHLF		0x0033
+#define OV9650_ARBLM		0x0034
+#define OV9650_VRHL		0x0035
+#define OV9650_VIDO		0x0036
+#define OV9650_ADC		0x0037
+#define OV9650_ACOM		0x0038
+#define OV9650_OFON		0x0039
+#define OV9650_TSLB		0x003A
+#define OV9650_COM11		0x003B
+#define OV9650_COM12		0x003C
+#define OV9650_COM13		0x003D
+#define OV9650_COM14		0x003E
+#define OV9650_EDGE		0x003F
+#define OV9650_COM15		0x0040
+#define OV9650_COM16		0x0041
+#define OV9650_COM17		0x0042
+#define OV9650_AWBTH1		0x0043
+#define OV9650_AWBTH2		0x0044
+#define OV9650_AWBTH3		0x0045
+#define OV9650_AWBTH4		0x0046
+#define OV9650_AWBTH5		0x0047
+#define OV9650_AWBTH6		0x0048
+#define OV9650_MTX1		0x004F
+#define OV9650_MTX2		0x0050
+#define OV9650_MTX3		0x0051
+#define OV9650_MTX4		0x0052
+#define OV9650_MTX5		0x0053
+#define OV9650_MTX6		0x0054
+#define OV9650_MTX7		0x0055
+#define OV9650_MTX8		0x0056
+#define OV9650_MTX9		0x0057
+#define OV9650_MTXS		0x0058
+#define OV9650_AWBC1		0x0059
+#define OV9650_AWBC2		0x005A
+#define OV9650_AWBC3		0x005B
+#define OV9650_AWBC4		0x005C
+#define OV9650_AWBC5		0x005D
+#define OV9650_AWBC6		0x005E
+#define OV9650_AWBC7		0x005F
+#define OV9650_AWBC8		0x0060
+#define OV9650_AWBC9		0x0061
+#define OV9650_LCC1		0x0062
+#define OV9650_LCC2		0x0063
+#define OV9650_LCC3		0x0064
+#define OV9650_LCC4		0x0065
+#define OV9650_LCC5		0x0066
+#define OV9650_MANU		0x0067
+#define OV9650_MANV		0x0068
+#define OV9650_HV		0x0069
+#define OV9650_MBD		0x006A
+#define OV9650_DBLV		0x006B
+#define OV9650_GSP0		0x006C
+#define OV9650_GSP1		0x006D
+#define OV9650_GSP2		0x006E
+#define OV9650_GSP3		0x006F
+#define OV9650_GSP4		0x0070
+#define OV9650_GSP5		0x0071
+#define OV9650_GSP6		0x0072
+#define OV9650_GSP7		0x0073
+#define OV9650_GSP8		0x0074
+#define OV9650_GSP9		0x0075
+#define OV9650_GSP10		0x0076
+#define OV9650_GSP11		0x0077
+#define OV9650_GSP12		0x0078
+#define OV9650_GSP13		0x0079
+#define OV9650_GSP14		0x007A
+#define OV9650_GSP15		0x007B
+#define OV9650_GST0		0x007C
+#define OV9650_GST1		0x007D
+#define OV9650_GST2		0x007E
+#define OV9650_GST3		0x007F
+#define OV9650_GST4		0x0080
+#define OV9650_GST5		0x0081
+#define OV9650_GST6		0x0082
+#define OV9650_GST7		0x0083
+#define OV9650_GST8		0x0084
+#define OV9650_GST9		0x0085
+#define OV9650_GST10		0x0086
+#define OV9650_GST11		0x0087
+#define OV9650_GST12		0x0088
+#define OV9650_GST13		0x0089
+#define OV9650_GST14		0x008A
+// OV9650 Register Definitions
+#define OV9650_COM21		0x008B
+#define OV9650_COM22		0x008C
+#define OV9650_COM23		0x008D
+#define OV9650_COM24		0x008E
+#define OV9650_DBLC1		0x008F
+#define OV9650_DBLCB		0x0090
+#define OV9650_DBLCR		0x0091
+#define OV9650_DMLNL		0x0092
+#define OV9650_DMLNH		0x0093
+
+#define OV9650_AECHM		0x00A1
+
+// End of OV9650 register
+#define OV9650_LASTREG		0x00AA
+
+// End flag of register
+#define OV9650_REGEND		( 0xff )
+
+
+
+/***********************************************************************
+ *
+ * Function Prototype
+ *
+ ***********************************************************************/
+
+void ov9650_power_down( int powerDown );
+void ov9650_soft_reset( void );
+
+int ov9650_version_revision(u8 * pCmRevision, u8 *pSensorRevision);
+void ov9650_auto_function_on(void);
+void ov9650_auto_function_off(void);
+
+int ov9650_viewfinder_on(void);
+int ov9650_viewfinder_off(void);
+
+int ov9650_set_format( u32 captureSizeFormat, u32 colorFormat );
+int ov9650_prepare_capture(p_camera_context_t cam_ctx, u32 captureSizeFormat, u32 colorFormat);
+void ov9650_set_start(void);
+int ov9650_output_stoped(void);
+void ov9650_set_stop(p_camera_context_t cam_ctx);
+void ov9650_save_gains(void);
+int ov9650_set_window(struct video_window *vw);
+int ov9650_get_window(struct video_window *vw);
+int ov9650_set_sensor_size(void *w_size);
+int ov9650_get_sensor_size(void *w_size);
+int ov9650_set_output_size(void *w_size);
+int ov9650_get_output_size(void *w_size);
+int ov9650_set_special_effect(int style);
+int ov9650_set_white_balance(V4l_PIC_WB light);
+int ov9650_set_flicker(int freq);
+int ov9650_set_brightness(int);
+int ov9650_set_fps(int fps, int min_fps);
+int ov9650_set_night_mode(void);
+int ov9650_set_auto_mode(void);
+int ov9650_set_action_mode(void);
+int ov9650_set_contrast(int);
+
+extern int i2c_ov9650_deinit(void);
+
+extern int i2c_ov9650_init(void);
+extern int i2c_ov9650_cleanup(void);
+extern int i2c_ov9650_read(u8 addr, u8 *pvalue);
+extern int i2c_ov9650_write(u8 addr, u8 value);
+
+
+#endif
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/pxa_camera.c linux-2.6.16.5-exz/drivers/media/video/pxa_camera.c
--- linux-2.6.16.5/drivers/media/video/pxa_camera.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/pxa_camera.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,2860 @@
+/*================================================================================
+                                                                               
+                     Module Name:  pxa-camera.c
+
+General Description: Camera module e680 camera  source file
+
+==================================================================================
+                      Motorola Confidential Proprietary
+                  Advanced Technology and Software Operations
+                (c) Copyright Motorola 1999, All Rights Reserved
+  
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Wangfei(w20239)     12/19/2003      LIBdd35749   Created
+
+WangWenxin(w20158)  1/1/2004        LIBdd35749   Modified
+
+wangfei(w20239)     02/05/2004      LIBdd74309   Set frame rate in video mode
+
+wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
+                                                 Update algorithm for DMA transfer
+                                                 Update strategy for memory management
+                                                 Fix still picture capture failed sometime
+                                                 New Agilent sensor chip ID support
+                                                 Make output height in an even multiple of 8
+                                                 Dynamic power management feature 
+                                                 
+wangfei(w20239)     03/08/2004      LIBdd84578   Photo effects setting
+                                                 Fix segmentation fault in rmmod
+                                                 Adjust default image buffer size  
+
+wangfei(w20239)     04/26/2004      LIBdd97716   Power Management added
+                                                 Photo effects setting bug fix
+                                                                                   
+wangfei(w20239)     05/28/2004      LIBee13628   add two new interface.
+                                                 1 get ready frames
+                                                 2 set frame buffer count
+                    
+                    06/10/2004                   add mt9v111 support                                                                                
+
+Portability: Indicate ifthis module is portable to other compilers or 
+platforms. If not, indicate specific reasons why is it not portable.
+
+==================================================================================
+                                 INCLUDE FILES
+================================================================================*/  
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include <linux/types.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/dma.h>
+#include <asm/arch/irqs.h>
+#include <asm/irq.h>
+
+#include <asm/arch/pxa-regs.h>
+
+#include "camera.h"
+//#include "adcm2700_hw.h"
+
+#define CIBR0_PHY	(0x50000000 + 0x28)
+#define CIBR1_PHY	(0x50000000 + 0x30)
+#define CIBR2_PHY	(0x50000000 + 0x38)
+/*
+ * It is required to have at least 3 frames in buffer
+ * in current implementation
+ */
+#define FRAMES_IN_BUFFER    	3
+#define SINGLE_DESC_TRANS_MAX  	 PAGE_SIZE
+
+
+#define DRCMR68		__REG(0x40001110)  /* Request to Channel Map Register for Camera FIFO 0 Request */
+#define DRCMR69		__REG(0x40001114)  /* Request to Channel Map Register for Camera FIFO 1 Request */
+#define DRCMR70		__REG(0x40001118)  /* Request to Channel Map Register for Camera FIFO 2 Request */
+
+static camera_context_t  *g_camera_context;
+#ifdef  CONFIG_ARCH_EZX_E680
+extern camera_function_t  e680_camera_func;
+#endif
+#ifdef CONFIG_ARCH_EZX_A780
+  #ifdef CONFIG_CAMERA_MT9M111
+  extern camera_function_t  mt9m111_func;
+  #endif
+  #ifdef CONFIG_CAMERA_OV9640
+  extern camera_function_t  ov9640_func;
+  #endif
+  #ifdef CONFIG_CAMERA_OV9650
+  extern camera_function_t  camera_ov9650_func;
+  #endif
+  #ifdef CONFIG_CAMERA_ADCM3800
+  extern camera_function_t  camera_adcm3800_func;
+  #endif
+#endif
+wait_queue_head_t  camera_wait_q;	
+
+/* /dev/videoX registration number */
+static int    minor     = 0;
+static int    ci_dma_y  = -1;
+static int    ci_dma_cb = -1;
+static int    ci_dma_cr = -1;
+static int    task_waiting      = 0;
+static int    still_image_mode  = 0;
+static int    still_image_rdy   = 0;
+static int    first_video_frame = 0;
+static int    detected_sensor_type = 0;
+// map of camera image format (camera.h) ==> capture interface format (ci.h)
+static const CI_IMAGE_FORMAT FORMAT_MAPPINGS[] = 
+{
+        CI_RAW8,                   //RAW
+        CI_RAW9,
+        CI_RAW10,
+
+        CI_RGB444,                 //RGB
+        CI_RGB555,
+        CI_RGB565,
+        CI_RGB666_PACKED,          //RGB Packed 
+        CI_RGB666,
+        CI_RGB888_PACKED,
+        CI_RGB888,
+        CI_RGBT555_0,              //RGB+Transparent bit 0
+        CI_RGBT888_0,
+        CI_RGBT555_1,              //RGB+Transparent bit 1  
+        CI_RGBT888_1,
+    
+        CI_INVALID_FORMAT,
+        CI_YCBCR422,               //YCBCR
+        CI_YCBCR422_PLANAR,        //YCBCR Planaried
+        CI_INVALID_FORMAT,
+        CI_INVALID_FORMAT
+};
+
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs);
+void stop_dma_transfer(p_camera_context_t camera_context);
+int  start_capture(p_camera_context_t camera_context, unsigned int block_id, unsigned int frames);
+int  camera_init(p_camera_context_t camera_context);
+static int update_dma_chain(p_camera_context_t camera_context);
+
+static int pxa_camera_open(struct inode *inode, struct file *file);
+static int pxa_camera_close(struct inode *inode, struct file *file);
+static ssize_t pxa_camera_read(struct file *file, char __user *data, 
+			       size_t count, loff_t *ppos);
+static ssize_t pxa_camera_write(struct file *file, const char __user *data, 
+			       size_t count, loff_t *ppos);
+static unsigned int pxa_camera_poll(struct file *file, poll_table *wait);
+static int pxa_camera_ioctl(struct inode *inode, struct file *file,
+			    unsigned int cmd, unsigned long arg);
+static int pxa_camera_mmap(struct file *file, struct vm_area_struct *vma);
+int pxa_camera_video_init(struct video_device *vdev);
+
+void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id);
+void pxa_dma_repeat(camera_context_t  *cam_ctx);
+void pxa_dma_continue(camera_context_t *cam_ctx);
+
+int pxa_camera_mem_deinit(void);
+int pxa_camera_mem_init(void);
+
+static struct file_operations vd_fops = {
+	.owner		= THIS_MODULE,
+	.open 		= pxa_camera_open,
+	.release	= pxa_camera_close,
+	.read		= pxa_camera_read,
+	.poll		= pxa_camera_poll,
+	.ioctl		= pxa_camera_ioctl,
+	.mmap		= pxa_camera_mmap,
+	.llseek		= no_llseek,
+	.write		= pxa_camera_write,
+};
+
+static struct video_device vd = {
+	.owner		= THIS_MODULE,
+	.name 		= "E680 camera",
+	.type		= VID_TYPE_CAPTURE,
+	.hardware	= VID_HARDWARE_PXA_CAMERA,      /* FIXME */
+	.fops		= &vd_fops,
+	//FIXME .initialize	= pxa_camera_video_init,
+	.minor		= -1,
+};
+
+
+/***********************************************************************
+ *
+ * Declarations
+ *
+ ***********************************************************************/
+
+
+#ifdef CONFIG_PM
+    static struct pm_dev *pm_dev;
+#endif   
+
+#ifdef CONFIG_PM
+static int camera_pm_callback(struct pm_dev *pm_dev, pm_request_t req, void *data)
+{
+    if(g_camera_context == NULL)
+    {
+      return 0;
+    }
+    
+    if(g_camera_context->camera_functions == NULL)
+    {
+      return 0;
+    }
+   
+    switch(req)
+    {
+   	case PM_SUSPEND:
+           g_camera_context->camera_functions->pm_management(g_camera_context, 1);
+	   	break;
+        
+       case PM_RESUME:
+           g_camera_context->camera_functions->pm_management(g_camera_context, 0);
+           break;
+           
+	   default:
+           break;
+    }
+  return 0;
+}
+#endif   
+/***********************************************************************
+ *
+ * Private functions
+ *
+ ***********************************************************************/
+ 
+static int pxa_dma_buffer_init(p_camera_context_t camera_context)
+{
+	struct page    *page;
+	unsigned int	pages;
+	unsigned int	page_count;
+
+	camera_context->pages_allocated = 0;
+
+	pages = (PAGE_ALIGN(camera_context->buf_size) / PAGE_SIZE);
+
+	camera_context->page_array = (struct page **)
+                                 kmalloc(pages * sizeof(struct page *),
+                                 GFP_KERNEL);
+                               
+	if(camera_context->page_array == NULL)
+	{
+		return -ENOMEM;
+	}
+	memset(camera_context->page_array, 0, pages * sizeof(struct page *));
+
+	for(page_count = 0; page_count < pages; page_count++)
+	{
+		page = alloc_page(GFP_KERNEL);
+		if(page == NULL)
+		{
+			goto error;
+		}
+		camera_context->page_array[page_count] = page;
+		set_page_count(page, 1);
+		SetPageReserved(page);
+	}
+	camera_context->buffer_virtual = remap_page_array(camera_context->page_array, 
+                                                      pages,
+ 	                                                  GFP_KERNEL);
+	if(camera_context->buffer_virtual == NULL)
+	{
+		goto error;
+	}
+
+	camera_context->pages_allocated = pages;
+
+	return 0;
+
+error:
+	for(page_count = 0; page_count < pages; page_count++)
+	{
+		if((page = camera_context->page_array[page_count]) != NULL)
+		{
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(camera_context->page_array);
+
+	return -ENOMEM;
+}
+
+static void pxa_dma_buffer_free(p_camera_context_t camera_context)
+{
+	struct page *page;
+	int page_count;
+
+	if(camera_context->buffer_virtual == NULL)
+		return;
+
+	vfree(camera_context->buffer_virtual);
+
+	for(page_count = 0; page_count < camera_context->pages_allocated; page_count++)
+	{
+		if((page = camera_context->page_array[page_count]) != NULL)
+		{
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(camera_context->page_array);
+}
+/*
+Generate dma descriptors
+Pre-condition: these variables must be set properly
+                block_number, fifox_transfer_size 
+                dma_descriptors_virtual, dma_descriptors_physical, dma_descirptors_size
+Post-condition: these variables will be set
+                fifox_descriptors_virtual, fifox_descriptors_physical              
+                fifox_num_descriptors 
+*/
+//#ifdef  CONFIG_ARCH_EZX_E680
+static int generate_fifo2_dma_chain(p_camera_context_t camera_context, pxa_dma_desc ** cur_vir, pxa_dma_desc ** cur_phy)
+{
+    pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+    int des_transfer_size, remain_size, target_page_num;
+    unsigned int i,j;
+
+    cur_des_virtual  = (pxa_dma_desc *)camera_context->fifo2_descriptors_virtual;
+    cur_des_physical = (pxa_dma_desc *)camera_context->fifo2_descriptors_physical;
+
+    for(i=0; i<camera_context->block_number; i++) 
+    {
+        // in each iteration, generate one dma chain for one frame
+        remain_size = camera_context->fifo2_transfer_size;
+
+        target_page_num = camera_context->pages_per_block * i +
+        camera_context->pages_per_fifo0 +
+        camera_context->pages_per_fifo1;
+
+        if (camera_context->pages_per_fifo1 > 1) 
+        {
+            for(j=0; j<camera_context->fifo2_num_descriptors; j++) 
+            {
+                // set descriptor
+                if (remain_size > SINGLE_DESC_TRANS_MAX) 
+                {
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX;
+                }
+                else
+                {
+                    des_transfer_size = remain_size;
+                }
+                    
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
+                cur_des_virtual->dtadr =
+                page_to_bus(camera_context->page_array[target_page_num]);
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+                target_page_num++;
+            }
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+        }
+        else 
+        {
+            for(j=0; j<camera_context->fifo2_num_descriptors; j++) 
+            {
+                // set descriptor
+                if (remain_size > SINGLE_DESC_TRANS_MAX/2) 
+                {
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX/2;
+                }
+                else
+                {
+                    des_transfer_size = remain_size;
+                }
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
+                if (!(j % 2))
+                {
+                    cur_des_virtual->dtadr =
+                    page_to_bus(camera_context->page_array[target_page_num]);
+                }
+                else 
+                {
+                    cur_des_virtual->dtadr =
+                    page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
+                }
+
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+    
+                ddbg_print(" CR: the ddadr = %8x, dtadr = %8x, dcmd = %8x, page = %8x \n", 
+                            cur_des_virtual->ddadr,
+                            cur_des_virtual->dtadr,
+                            cur_des_virtual->dcmd,
+                            page_to_bus(camera_context->page_array[target_page_num]) );
+    
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+        
+                if (j % 2)
+                {
+                    target_page_num++;
+                }
+            }
+
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+            //last_des_virtual->ddadr |= 0x1;
+        }
+    }
+    last_des_virtual->ddadr = ((unsigned)camera_context->fifo2_descriptors_physical);
+    
+    *cur_vir = cur_des_virtual;
+    *cur_phy = cur_des_physical;
+    return 0;
+}
+static int generate_fifo1_dma_chain(p_camera_context_t camera_context, pxa_dma_desc ** cur_vir, pxa_dma_desc ** cur_phy)
+{
+    pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+    int des_transfer_size, remain_size, target_page_num;
+    unsigned int i,j;
+
+    cur_des_virtual  = (pxa_dma_desc *)camera_context->fifo1_descriptors_virtual;
+    cur_des_physical = (pxa_dma_desc *)camera_context->fifo1_descriptors_physical;
+
+    for(i=0; i<camera_context->block_number; i++)
+    {
+        // in each iteration, generate one dma chain for one frame
+        remain_size = camera_context->fifo1_transfer_size;
+
+        target_page_num = camera_context->pages_per_block * i +
+        camera_context->pages_per_fifo0;
+
+        if (camera_context->pages_per_fifo1 > 1) 
+        {
+            for(j=0; j<camera_context->fifo1_num_descriptors; j++) 
+            {
+                // set descriptor
+                if (remain_size > SINGLE_DESC_TRANS_MAX) 
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX;
+                else
+                    des_transfer_size = remain_size;
+                
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
+                cur_des_virtual->dtadr =
+                page_to_bus(camera_context->page_array[target_page_num]);
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+
+                target_page_num++;
+            }
+
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+            //last_des_virtual->ddadr |= 0x1;
+        }
+        else  
+        {
+            for(j=0; j<camera_context->fifo1_num_descriptors; j++) 
+            {
+                // set descriptor
+                if (remain_size > SINGLE_DESC_TRANS_MAX/2) 
+                {
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX/2;
+                }
+                else
+                {
+                    des_transfer_size = remain_size;
+                }
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
+                if(!(j % 2))
+                {
+                    cur_des_virtual->dtadr =
+                    page_to_bus(camera_context->page_array[target_page_num]);
+                }
+                else 
+                {
+                    cur_des_virtual->dtadr =
+                    page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
+                }
+
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+                ddbg_print("CB: the ddadr = %8x, dtadr = %8x, dcmd = %8x, page = %8x \n", 
+                        cur_des_virtual->ddadr,
+                        cur_des_virtual->dtadr,
+                        cur_des_virtual->dcmd,
+                        page_to_bus(camera_context->page_array[target_page_num]));
+
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+                if (j % 2)
+                {
+                    target_page_num++;
+                }
+            }//end of for j...
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+          }// end of else
+    }//end of for i...
+    last_des_virtual->ddadr = ((unsigned)camera_context->fifo1_descriptors_physical);
+    *cur_vir = cur_des_virtual;
+    *cur_phy = cur_des_physical;
+
+    return 0;
+}
+static int generate_fifo0_dma_chain(p_camera_context_t camera_context, pxa_dma_desc ** cur_vir, pxa_dma_desc ** cur_phy)
+{
+    pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+    int des_transfer_size, remain_size, target_page_num;
+    unsigned int i,j;
+    
+    cur_des_virtual = (pxa_dma_desc *)camera_context->fifo0_descriptors_virtual;
+    cur_des_physical = (pxa_dma_desc *)camera_context->fifo0_descriptors_physical;
+
+    for(i=0; i<camera_context->block_number; i++) 
+    {
+        // in each iteration, generate one dma chain for one frame
+        remain_size = camera_context->fifo0_transfer_size;
+
+        // assume the blocks are stored consecutively
+        target_page_num = camera_context->pages_per_block * i;
+
+        if (camera_context->pages_per_fifo0 > 2) 
+        {
+            for(j=0; j<camera_context->fifo0_num_descriptors; j++) 
+            {
+                // set descriptor
+                if (remain_size > SINGLE_DESC_TRANS_MAX)
+                {
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX;
+                }
+                else
+                {
+                    des_transfer_size = remain_size;
+                }
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
+                cur_des_virtual->dtadr =
+                page_to_bus(camera_context->page_array[target_page_num]);
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+                target_page_num++;
+            }
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+            //last_des_virtual->ddadr |= 0x1;
+        }
+        else
+        {
+            for(j=0; j<camera_context->fifo0_num_descriptors; j++) 
+            {
+                // set descriptor
+                if(remain_size > SINGLE_DESC_TRANS_MAX/2) 
+                {
+                    des_transfer_size = SINGLE_DESC_TRANS_MAX/2;
+                }
+                else
+                {
+                    des_transfer_size = remain_size;
+                }
+                cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+                cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
+                if(!(j % 2))
+                {
+                    cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+                }
+                else 
+                {
+                    cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE / 2);
+                }
+
+                cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+ 
+                ddbg_print(" Y: the ddadr = %8x, dtadr = %8x, dcmd = %8x, page = %8x, page_num = %d \n", 
+                            cur_des_virtual->ddadr,
+                            cur_des_virtual->dtadr,
+                            cur_des_virtual->dcmd,
+                            page_to_bus(camera_context->page_array[target_page_num]),
+                            target_page_num);
+                // advance pointers
+                remain_size -= des_transfer_size;
+                cur_des_virtual++;
+                cur_des_physical++;
+                if (j % 2)
+                {
+                    target_page_num++;
+                }
+            }//end of for j..
+            // stop the dma transfer on one frame captured
+            last_des_virtual = cur_des_virtual - 1;
+            //last_des_virtual->ddadr |= 0x1;
+        }// end of else	
+    }
+    last_des_virtual->ddadr = ((unsigned)camera_context->fifo0_descriptors_physical);
+    *cur_vir = cur_des_virtual;
+    *cur_phy = cur_des_physical;
+    return 0;
+}
+
+int update_dma_chain(p_camera_context_t camera_context)
+{
+    pxa_dma_desc *cur_des_virtual, *cur_des_physical; 
+    // clear descriptor pointers
+    camera_context->fifo0_descriptors_virtual = camera_context->fifo0_descriptors_physical = 0;
+    camera_context->fifo1_descriptors_virtual = camera_context->fifo1_descriptors_physical = 0;
+    camera_context->fifo2_descriptors_virtual = camera_context->fifo2_descriptors_physical = 0;
+
+    // calculate how many descriptors are needed per frame
+    camera_context->fifo0_num_descriptors =
+    camera_context->pages_per_fifo0 > 2 ? camera_context->pages_per_fifo0 : (camera_context->fifo0_transfer_size / (PAGE_SIZE/2) + 1);
+
+    camera_context->fifo1_num_descriptors =
+    camera_context->pages_per_fifo1  > 1 ? camera_context->pages_per_fifo1 : (camera_context->fifo1_transfer_size / (PAGE_SIZE/2) + 1);
+
+    camera_context->fifo2_num_descriptors =
+    camera_context->pages_per_fifo2  > 1 ? camera_context->pages_per_fifo2 : (camera_context->fifo2_transfer_size / (PAGE_SIZE/2) + 1);
+
+    // check if enough memory to generate descriptors
+    if((camera_context->fifo0_num_descriptors + camera_context->fifo1_num_descriptors + 
+        camera_context->fifo2_num_descriptors) * camera_context->block_number 
+         > camera_context->dma_descriptors_size)
+    {
+      return -1;
+    }
+
+    // generate fifo0 dma chains
+    camera_context->fifo0_descriptors_virtual = (unsigned)camera_context->dma_descriptors_virtual;
+    camera_context->fifo0_descriptors_physical = (unsigned)camera_context->dma_descriptors_physical;
+    // generate fifo0 dma chains
+    generate_fifo0_dma_chain(camera_context, &cur_des_virtual, &cur_des_physical);
+     
+    // generate fifo1 dma chains
+    if(!camera_context->fifo1_transfer_size)
+    {
+       return 0;
+    }
+    // record fifo1 descriptors' start address
+    camera_context->fifo1_descriptors_virtual = (unsigned)cur_des_virtual;
+    camera_context->fifo1_descriptors_physical = (unsigned)cur_des_physical;
+    // generate fifo1 dma chains
+    generate_fifo1_dma_chain(camera_context, &cur_des_virtual, &cur_des_physical);
+    
+    if(!camera_context->fifo2_transfer_size) 
+    {
+      return 0;
+    }
+    // record fifo1 descriptors' start address
+    camera_context->fifo2_descriptors_virtual = (unsigned)cur_des_virtual;
+    camera_context->fifo2_descriptors_physical = (unsigned)cur_des_physical;
+    // generate fifo2 dma chains
+    generate_fifo2_dma_chain(camera_context,  &cur_des_virtual, &cur_des_physical);
+        
+    return 0;   
+}
+//#else
+#if 0
+int update_dma_chain(p_camera_context_t camera_context)
+{
+    
+	pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+	int des_transfer_size, remain_size;
+	unsigned int i,j;
+	int target_page_num;
+    
+    dbg_print("");
+
+	// clear descriptor pointers
+	camera_context->fifo0_descriptors_virtual = camera_context->fifo0_descriptors_physical = 0;
+	camera_context->fifo1_descriptors_virtual = camera_context->fifo1_descriptors_physical = 0;
+	camera_context->fifo2_descriptors_virtual = camera_context->fifo2_descriptors_physical = 0;
+
+	// calculate how many descriptors are needed per frame
+	camera_context->fifo0_num_descriptors =
+		camera_context->pages_per_fifo0;
+
+	camera_context->fifo1_num_descriptors =
+		camera_context->pages_per_fifo1;
+
+	camera_context->fifo2_num_descriptors =
+		camera_context->pages_per_fifo2;
+
+	// check if enough memory to generate descriptors
+	if((camera_context->fifo0_num_descriptors + 
+        camera_context->fifo1_num_descriptors +
+		camera_context->fifo2_num_descriptors) * camera_context->block_number
+		> camera_context->dma_descriptors_size)
+    {
+		return -1;
+    }
+
+    dbg_print("1");
+	// generate fifo0 dma chains
+	camera_context->fifo0_descriptors_virtual  = (unsigned)camera_context->dma_descriptors_virtual;
+	camera_context->fifo0_descriptors_physical = (unsigned)camera_context->dma_descriptors_physical;
+    
+	cur_des_virtual  = (pxa_dma_desc *)camera_context->fifo0_descriptors_virtual;
+	cur_des_physical = (pxa_dma_desc *)camera_context->fifo0_descriptors_physical;
+
+	for(i=0; i<camera_context->block_number; i++) 
+    {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = camera_context->fifo0_transfer_size;
+
+		// assume the blocks are stored consecutively
+		target_page_num = camera_context->pages_per_block * i;
+
+		for(j=0; j<camera_context->fifo0_num_descriptors; j++)
+        {
+			// set descriptor
+		        if(remain_size > SINGLE_DESC_TRANS_MAX)
+        			des_transfer_size = SINGLE_DESC_TRANS_MAX;
+        		else
+		       		des_transfer_size = remain_size;
+                    
+		        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+        		cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
+        		cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        		cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+		        // advance pointers
+        		remain_size -= des_transfer_size;
+        		cur_des_virtual++;
+		        cur_des_physical++;
+			    target_page_num++;
+		}
+
+		// stop the dma transfer on one frame captured
+		last_des_virtual = cur_des_virtual - 1;
+	}
+
+	last_des_virtual->ddadr = ((unsigned)camera_context->fifo0_descriptors_physical);
+
+	// generate fifo1 dma chains
+	if(camera_context->fifo1_transfer_size) 
+    {
+		// record fifo1 descriptors' start address
+		camera_context->fifo1_descriptors_virtual = (unsigned)cur_des_virtual;
+		camera_context->fifo1_descriptors_physical = (unsigned)cur_des_physical;
+
+		for(i=0; i<camera_context->block_number; i++) 
+        {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = camera_context->fifo1_transfer_size;
+
+			target_page_num = camera_context->pages_per_block * i +
+				              camera_context->pages_per_fifo0;
+
+        		for(j=0; j<camera_context->fifo1_num_descriptors; j++)
+                {
+        		        // set descriptor
+        		    if(remain_size > SINGLE_DESC_TRANS_MAX)
+        		        des_transfer_size = SINGLE_DESC_TRANS_MAX;
+        		    else
+        		        des_transfer_size = remain_size;
+                            
+        	        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+        	        cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
+        	        cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        	        cur_des_virtual->dcmd  = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+       		     // advance pointers
+       		     
+       		     remain_size -= des_transfer_size;
+       		     cur_des_virtual++;
+       		     cur_des_physical++;
+ 	      		 target_page_num++;
+       			}
+
+        		// stop the dma transfer on one frame captured
+        		last_des_virtual = cur_des_virtual - 1;
+		}
+		last_des_virtual->ddadr = ((unsigned)camera_context->fifo1_descriptors_physical);
+	}
+
+	// generate fifo2 dma chains
+	if(camera_context->fifo2_transfer_size) 
+    {
+		// record fifo1 descriptors' start address
+		camera_context->fifo2_descriptors_virtual = (unsigned)cur_des_virtual;
+		camera_context->fifo2_descriptors_physical = (unsigned)cur_des_physical;
+
+		for(i=0; i<camera_context->block_number; i++) 
+        {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = camera_context->fifo2_transfer_size;
+
+			target_page_num = camera_context->pages_per_block * i +
+				              camera_context->pages_per_fifo0 +
+  	                  	  camera_context->pages_per_fifo1;
+
+	        for(j=0; j<camera_context->fifo2_num_descriptors; j++) 
+            {
+                		// set descriptor
+              	if(remain_size > SINGLE_DESC_TRANS_MAX)
+              		des_transfer_size = SINGLE_DESC_TRANS_MAX;
+              	else
+              		des_transfer_size = remain_size;
+              	cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+              	cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
+              	cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+              	cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+              	// advance pointers
+              	remain_size -= des_transfer_size;
+              	cur_des_virtual++;
+              	cur_des_physical++;
+  		        target_page_num++;
+	        }
+
+	        // stop the dma transfer on one frame captured
+       		last_des_virtual = cur_des_virtual - 1;
+       	}
+		last_des_virtual->ddadr = ((unsigned)camera_context->fifo2_descriptors_physical);
+	}
+    
+    dbg_print(" success!");
+	return 0;  
+}
+#endif
+void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id)
+{
+	pxa_dma_desc *des_virtual, *des_physical;
+    /*
+	if(block_id >= camera_context->block_number)
+    {
+       	return;
+    }
+      */  
+	// start channel 0
+	des_virtual = (pxa_dma_desc *)camera_context->fifo0_descriptors_virtual +
+		           block_id * camera_context->fifo0_num_descriptors;
+
+	des_physical = (pxa_dma_desc *)camera_context->fifo0_descriptors_physical +
+		           block_id * camera_context->fifo0_num_descriptors;
+
+    DDADR(camera_context->dma_channels[0]) = des_physical;
+    DCSR(camera_context->dma_channels[0]) |= DCSR_RUN;
+
+	// start channel 1
+	if(camera_context->fifo1_descriptors_virtual) 
+    {
+		des_virtual = (pxa_dma_desc *)camera_context->fifo1_descriptors_virtual + 
+			           block_id * camera_context->fifo1_num_descriptors;
+
+		des_physical = (pxa_dma_desc *)camera_context->fifo1_descriptors_physical + 
+			           block_id * camera_context->fifo1_num_descriptors;
+
+        DDADR(camera_context->dma_channels[1]) = des_physical;
+        DCSR(camera_context->dma_channels[1]) |= DCSR_RUN;
+	}
+
+	// start channel 2
+	if(camera_context->fifo2_descriptors_virtual) 
+    {
+		des_virtual = (pxa_dma_desc *)camera_context->fifo2_descriptors_virtual + 
+			           block_id * camera_context->fifo2_num_descriptors;
+
+		des_physical = (pxa_dma_desc *)camera_context->fifo2_descriptors_physical + 
+			           block_id * camera_context->fifo2_num_descriptors;
+
+        DDADR(camera_context->dma_channels[2]) = des_physical;
+        DCSR(camera_context->dma_channels[2]) |= DCSR_RUN;
+	}
+
+	camera_context->dma_started = 1;
+}
+
+void set_still_image_ready(int rdy)
+{
+	still_image_rdy = rdy;
+}
+void stop_dma_transfer(p_camera_context_t camera_context)
+{	
+    int ch0, ch1, ch2;
+
+    ch0 = camera_context->dma_channels[0];
+    ch1 = camera_context->dma_channels[1];
+    ch2 = camera_context->dma_channels[2];
+
+    DCSR(ch0) &= ~DCSR_RUN;
+    DCSR(ch1) &= ~DCSR_RUN;
+    DCSR(ch2) &= ~DCSR_RUN;
+	camera_context->dma_started = 0;
+
+    return;
+}
+
+int start_capture(p_camera_context_t camera_context, unsigned int block_id, unsigned int frames)
+{
+    int status;
+    status = camera_context->camera_functions->start_capture(camera_context, frames);
+
+	return status;
+}
+ 
+/***********************************************************************
+ *
+ * Init/Deinit APIs
+ *
+ ***********************************************************************/
+int camera_init(p_camera_context_t camera_context)
+{
+    int ret=0;
+    dbg_print(""); 
+   
+    /*init gpio pins*/
+    //camera_gpio_init();
+    
+    /*init cif*/
+  //	ci_init();
+	
+    /*init sensor */
+    if(detected_sensor_type == 0) {
+    /* test sensor type */
+#ifdef  CONFIG_ARCH_EZX_E680
+    camera_context->camera_functions = &e680_camera_func;
+    if((ret = camera_context->camera_functions->init(camera_context)) ==0)
+    {
+	    goto test_success;
+    }
+#endif
+#ifdef CONFIG_ARCH_EZX_A780
+
+  #ifdef CONFIG_CAMERA_MT9M111
+    camera_context->camera_functions = &mt9m111_func;
+    if((ret = camera_context->camera_functions->init(camera_context)) ==0)
+    {
+	    goto test_success;
+    }
+  #endif
+
+  #ifdef CONFIG_CAMERA_ADCM3800
+    dbg_print("detect ADCM3800...");
+    camera_context->camera_functions = &camera_adcm3800_func;
+    if((ret = camera_context->camera_functions->init(camera_context)) ==0)
+    {
+	    goto test_success;
+    }
+  #endif
+
+  #ifdef CONFIG_CAMERA_OV9650
+    dbg_print("detect OV9650...");
+    camera_context->camera_functions = &camera_ov9650_func;
+    if((ret = camera_context->camera_functions->init(camera_context)) ==0)
+    {
+	    goto test_success;
+    }
+  #endif
+
+  #ifdef CONFIG_CAMERA_OV9640
+    camera_context->camera_functions = &ov9640_func;
+    if((ret = camera_context->camera_functions->init(camera_context)) ==0)
+    {
+	    goto test_success;
+    }
+  #endif
+
+#endif
+
+        camera_context->camera_functions = 0;
+	    
+        dbg_print("camera function init error!!");
+        goto camera_init_err;
+    }
+    else 
+    {
+        switch (detected_sensor_type) {
+#ifdef  CONFIG_ARCH_EZX_E680
+                case CAMERA_TYPE_ADCM_2700:
+                    camera_context->camera_functions = &e680_camera_func;
+                break;
+                case CAMERA_TYPE_MT9V111:
+                    camera_context->camera_functions = &e680_camera_func;
+                break;
+#endif
+#ifdef CONFIG_ARCH_EZX_A780
+    #ifdef CONFIG_CAMERA_OV9640
+                case CAMERA_TYPE_OMNIVISION_9640:
+                    camera_context->camera_functions = &ov9640_func;
+                break;
+    #endif
+    #ifdef CONFIG_CAMERA_MT9M111
+                case CAMERA_TYPE_MT9M111:
+                    camera_context->camera_functions = &mt9m111_func;
+                break;
+    #endif
+    #ifdef CONFIG_CAMERA_ADCM3800
+                case CAMERA_TYPE_ADCM3800:
+                    camera_context->camera_functions = &camera_adcm3800_func;
+                break;
+    #endif
+    #ifdef CONFIG_CAMERA_OV9650
+                case CAMERA_TYPE_OV9650:
+                    camera_context->camera_functions = &camera_ov9650_func;
+                break;
+    #endif
+#endif
+        }
+        camera_context->camera_functions->init(camera_context);
+    }
+test_success:
+    camera_context->dma_channels[0] = ci_dma_y;
+    camera_context->dma_channels[1] = ci_dma_cb;
+    camera_context->dma_channels[2] = ci_dma_cr;
+    DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+    DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+    DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;	
+
+    detected_sensor_type = camera_context->sensor_type;
+#ifdef DEBUG
+	ci_dump();
+#endif
+    return 0;
+
+camera_init_err:
+    camera_deinit(camera_context);
+    return -1; 
+}
+
+void camera_gpio_init()
+{
+
+    pxa_gpio_mode(  CIF_PD_MD );         /*CIF_PD*/
+    GPCR(CIF_PD)  = GPIO_bit(CIF_PD);    /*set to low*/
+    pxa_gpio_mode(  CIF_RST_MD );        /*CIF_RST*/
+    GPSR(CIF_RST) = GPIO_bit(CIF_RST);   /*set to high*/
+    
+    pxa_gpio_mode( CIF_DD0_MD );  /* CIF_DD[0] */
+    pxa_gpio_mode( CIF_DD1_MD );  /* CIF_DD[1] */
+    pxa_gpio_mode( CIF_DD2_MD );  /* CIF_DD[2] */
+    pxa_gpio_mode( CIF_DD3_MD );  /* CIF_DD[3] */
+    pxa_gpio_mode( CIF_DD4_MD );  /* CIF_DD[4] */
+    pxa_gpio_mode( CIF_DD5_MD );  /* CIF_DD[5] */
+    pxa_gpio_mode( CIF_DD6_MD );  /* CIF_DD[6] */
+    pxa_gpio_mode( CIF_DD7_MD );  /* CIF_DD[7] */   
+    pxa_gpio_mode( CIF_MCLK_MD ); /* CIF_MCLK  */
+    pxa_gpio_mode( CIF_PCLK_MD ); /* CIF_PCLK  */
+    pxa_gpio_mode( CIF_LV_MD );   /* CIF_LV    */
+    pxa_gpio_mode( CIF_FV_MD );   /* CIF_FV    */
+}   
+
+
+void camera_gpio_deinit()
+{
+    /* Turn off M_VCC  CIF_PD*/
+    GPSR(CIF_PD) = GPIO_bit(CIF_PD);   /* Set PD to low */
+    pxa_gpio_mode( CIF_MCLK | GPIO_IN); /*trun off MCLK*/      
+}
+
+int camera_deinit( p_camera_context_t camera_context )
+{
+    // deinit sensor
+	if(camera_context->camera_functions)
+		camera_context->camera_functions->deinit(camera_context);  
+	
+	// capture interface deinit
+	ci_deinit();
+	//camera_gpio_deinit();
+	return 0;
+}
+
+int camera_ring_buf_init(p_camera_context_t camera_context)
+{
+	unsigned         frame_size;
+    dbg_print("");    
+    switch(camera_context->capture_output_format)
+    {
+    case CAMERA_IMAGE_FORMAT_RGB565:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size / 2;
+        camera_context->fifo1_transfer_size = frame_size / 4;
+        camera_context->fifo2_transfer_size = frame_size / 4;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB666_PLANAR:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 4;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB666_PACKED:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 3;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    default:
+        return STATUS_WRONG_PARAMETER;
+        break;
+    }
+
+    camera_context->block_size = frame_size;
+
+	camera_context->pages_per_fifo0 =
+		(PAGE_ALIGN(camera_context->fifo0_transfer_size) / PAGE_SIZE);
+	camera_context->pages_per_fifo1 =
+		(PAGE_ALIGN(camera_context->fifo1_transfer_size) / PAGE_SIZE);
+	camera_context->pages_per_fifo2 =
+		(PAGE_ALIGN(camera_context->fifo2_transfer_size) / PAGE_SIZE);
+
+	camera_context->pages_per_block =
+		camera_context->pages_per_fifo0 +
+		camera_context->pages_per_fifo1 +
+		camera_context->pages_per_fifo2;
+
+	camera_context->page_aligned_block_size =
+		camera_context->pages_per_block * PAGE_SIZE;
+
+	camera_context->block_number_max =
+		camera_context->pages_allocated /
+		camera_context->pages_per_block;
+
+
+    //restrict max block number 
+    if(camera_context->block_number_max > FRAMES_IN_BUFFER)
+    {
+       camera_context->block_number = FRAMES_IN_BUFFER; 
+    }
+    else
+    {
+       camera_context->block_number = camera_context->block_number_max;
+    }
+	camera_context->block_header = camera_context->block_tail = 0;
+	// generate dma descriptor chain
+	return update_dma_chain(camera_context);
+
+}
+/***********************************************************************
+ *
+ * Capture APIs
+ *
+ ***********************************************************************/
+// Set the image format
+int camera_set_capture_format(p_camera_context_t camera_context)
+{
+
+	int status=-1;
+	CI_IMAGE_FORMAT  ci_input_format, ci_output_format;
+	CI_MP_TIMING     timing;
+
+	if(camera_context->capture_input_format >  CAMERA_IMAGE_FORMAT_MAX ||
+	   camera_context->capture_output_format > CAMERA_IMAGE_FORMAT_MAX )
+    {
+		return STATUS_WRONG_PARAMETER;
+    }
+
+	ci_input_format  = FORMAT_MAPPINGS[camera_context->capture_input_format];
+	ci_output_format = FORMAT_MAPPINGS[camera_context->capture_output_format];
+    
+	if(ci_input_format == CI_INVALID_FORMAT || ci_output_format == CI_INVALID_FORMAT)
+    {
+	  return STATUS_WRONG_PARAMETER;
+    }
+    
+	ci_set_image_format(ci_input_format, ci_output_format);
+
+ 
+    timing.BFW = 0;
+    timing.BLW = 0;
+ 
+    ci_configure_mp(camera_context->capture_width-1, camera_context->capture_height-1, &timing);
+
+    if(camera_context == NULL || camera_context->camera_functions == NULL || 
+       camera_context->camera_functions->set_capture_format == NULL)
+    {
+	  dbg_print("camera_context point NULL!!!");
+	  return -1;
+    } 
+    status = camera_ring_buf_init(camera_context);
+	// set sensor setting
+	if(camera_context->camera_functions->set_capture_format(camera_context))
+    {
+ 	   return -1;
+    }
+   
+    // ring buffer init
+    return status;
+    
+}
+
+// take a picture and copy it into the ring buffer
+int camera_capture_still_image(p_camera_context_t camera_context, unsigned int block_id)
+{
+	// init buffer status & capture
+    camera_set_int_mask(camera_context, 0x3ff | 0x0400);
+    still_image_mode = 1;
+    first_video_frame = 0;
+    task_waiting = 0;
+	camera_context->block_header   = camera_context->block_tail = block_id;  
+	camera_context->capture_status = 0;
+    still_image_rdy = 0;
+	return  start_capture(camera_context, block_id, 1);
+    
+}
+
+// capture motion video and copy it to the ring buffer
+int camera_start_video_capture( p_camera_context_t camera_context, unsigned int block_id )
+{
+	//init buffer status & capture
+    camera_set_int_mask(camera_context, 0x3ff | 0x0400);
+    still_image_mode = 0;
+    first_video_frame = 1;
+	camera_context->block_header   = camera_context->block_tail = block_id; 
+	camera_context->capture_status = CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+	return start_capture(camera_context, block_id, 0);
+}
+
+// disable motion video image capture
+void camera_stop_video_capture( p_camera_context_t camera_context )
+{
+	
+	//stop capture
+	camera_context->camera_functions->stop_capture(camera_context);
+  
+	//stop dma
+	stop_dma_transfer(camera_context);
+    
+	//update the flag
+	if(!(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+		camera_context->capture_status &= ~CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+    }
+}
+
+
+/***********************************************************************
+ *
+ * Flow Control APIs
+ *
+ ***********************************************************************/
+// continue capture image to next available buffer
+void camera_continue_transfer( p_camera_context_t camera_context )
+{
+	// don't think we need this either.  JR
+	// continue transfer on next block
+	start_dma_transfer( camera_context, camera_context->block_tail );
+}
+
+// Return 1: there is available buffer, 0: buffer is full
+int camera_next_buffer_available( p_camera_context_t camera_context )
+{
+	camera_context->block_header = (camera_context->block_header + 1) % camera_context->block_number;
+	if(((camera_context->block_header + 1) % camera_context->block_number) != camera_context->block_tail)
+	{
+		return 1;
+	}
+
+	camera_context->capture_status |= CAMERA_STATUS_RING_BUFFER_FULL;
+	return 0;
+}
+
+// Application supplies the FrameBufferID to the driver to tell it that the application has completed processing of 
+// the given frame buffer, and that buffer is now available for re-use.
+void camera_release_frame_buffer(p_camera_context_t camera_context, unsigned int frame_buffer_id)
+{
+
+	camera_context->block_tail = (camera_context->block_tail + 1) % camera_context->block_number;
+
+	// restart video capture only ifvideo capture is in progress and space is available for image capture
+	if((camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL ) && 
+	   (camera_context->capture_status & CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS))
+	{
+		if(((camera_context->block_header + 2) % camera_context->block_number) != camera_context->block_tail)
+		{
+			camera_context->capture_status &= ~CAMERA_STATUS_RING_BUFFER_FULL;
+			start_capture(camera_context, camera_context->block_tail, 0);
+		}
+	}
+}
+
+// Returns the FrameBufferID for the first filled frame
+// Note: -1 represents buffer empty
+int camera_get_first_frame_buffer_id(p_camera_context_t camera_context)
+{
+	// not sure ifthis routine makes any sense.. JR
+
+	// check whether buffer is empty
+	if((camera_context->block_header == camera_context->block_tail) && 
+		 !(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+	    return -1;
+    }
+
+	// return the block header
+	return camera_context->block_header;
+}
+
+// Returns the FrameBufferID for the last filled frame, this would be used ifwe were polling for image completion data, 
+// or we wanted to make sure there were no frames waiting for us to process.
+// Note: -1 represents buffer empty
+int camera_get_last_frame_buffer_id(p_camera_context_t camera_context)
+{
+
+	// check whether buffer is empty
+	if((camera_context->block_header == camera_context->block_tail) && 
+	     !(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+		return -1;
+    }
+
+	// return the block before the block_tail
+	return (camera_context->block_tail + camera_context->block_number - 1) % camera_context->block_number;
+}
+
+
+/***********************************************************************
+ *
+ * Buffer Info APIs
+ *
+ ***********************************************************************/
+// Return: the number of frame buffers allocated for use.
+unsigned int camera_get_num_frame_buffers(p_camera_context_t camera_context)
+{
+	return camera_context->block_number;
+}
+
+// FrameBufferID is a number between 0 and N-1, where N is the total number of frame buffers in use.  Returns the address of
+// the given frame buffer.  The application will call this once for each frame buffer at application initialization only.
+void * camera_get_frame_buffer_addr(p_camera_context_t camera_context, unsigned int frame_buffer_id)
+{
+	return (void*)((unsigned)camera_context->buffer_virtual +
+		 camera_context->page_aligned_block_size * frame_buffer_id);
+}
+
+// Return the block id
+int camera_get_frame_buffer_id(p_camera_context_t camera_context, void* address)
+{
+	if(((unsigned)address >= (unsigned)camera_context->buffer_virtual) && 
+	   ((unsigned)address <= (unsigned)camera_context->buffer_virtual + camera_context->buf_size))
+    {
+		return ((unsigned)address - 
+                (unsigned)camera_context->buffer_virtual) / 
+                camera_context->page_aligned_block_size;
+    }
+
+	return -1;
+}
+
+
+/***********************************************************************
+ *
+ * Frame rate APIs
+ *
+ ***********************************************************************/
+// Set desired frame rate
+void camera_set_capture_frame_rate(p_camera_context_t camera_context)
+{
+	ci_set_frame_rate(camera_context->fps);
+} 
+
+// return current setting
+void camera_get_capture_frame_rate(p_camera_context_t camera_context)
+{
+	camera_context->fps = ci_get_frame_rate();
+} 
+
+
+/***********************************************************************
+ *
+ * Interrupt APIs
+ *
+ ***********************************************************************/
+// set interrupt mask 
+void camera_set_int_mask(p_camera_context_t cam_ctx, unsigned int mask)
+{
+	pxa_dma_desc * end_des_virtual;
+	int dma_interrupt_on, i;
+
+	// set CI interrupt
+	ci_set_int_mask( mask & CI_CICR0_INTERRUPT_MASK );
+
+	// set dma end interrupt
+	if( mask & CAMERA_INTMASK_END_OF_DMA )
+		dma_interrupt_on = 1;
+	else
+		dma_interrupt_on = 0;
+
+	// set fifo0 dma chains' flag
+	end_des_virtual = (pxa_dma_desc*)cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+
+    for(i=0; i<cam_ctx->block_number; i++) 
+    {
+        if(dma_interrupt_on)
+            end_des_virtual->dcmd |= DCMD_ENDIRQEN;
+        else
+            end_des_virtual->dcmd &= ~DCMD_ENDIRQEN;
+
+        end_des_virtual += cam_ctx->fifo0_num_descriptors;
+    }
+}
+ 
+// get interrupt mask 
+unsigned int camera_get_int_mask(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *end_des_virtual;
+	unsigned int ret;
+
+	// get CI mask
+	ret = ci_get_int_mask();
+	
+	// get dma end mask
+	end_des_virtual = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+
+	if(end_des_virtual->dcmd & DCMD_ENDIRQEN)
+    {
+		ret |= CAMERA_INTMASK_END_OF_DMA;
+    }
+	return ret;   
+} 
+
+// clear interrupt status
+void camera_clear_int_status( p_camera_context_t camera_context, unsigned int status )
+{
+	ci_clear_int_status( (status & 0xFFFF) );   
+}
+
+static void camera_free_dma_irq()
+{
+     if(ci_dma_y>=0) 
+    {
+        pxa_free_dma(ci_dma_y);
+        ci_dma_y = 0;
+    }
+    if(ci_dma_cb>=0) 
+    {
+        pxa_free_dma(ci_dma_cb);
+        ci_dma_cb = 0;
+    }
+    if(ci_dma_cr>=0) 
+    {
+        pxa_free_dma(ci_dma_cr);
+        ci_dma_cr = 0;
+    }
+	DRCMR68 = 0;
+	DRCMR69 = 0;
+	DRCMR70 = 0;
+}
+/***********************************************************************************
+* Application interface 							   *
+***********************************************************************************/
+//static int pxa_camera_open(struct video_device *dev, int flags)
+static int pxa_camera_open(struct inode *inode, struct file *file)
+{
+	unsigned int minor = iminor(inode);
+    camera_context_t *cam_ctx;
+    dbg_print("start...");
+    /*
+      According to Peter's suggestion, move the code of request camera IRQ and DMQ channel to here
+    */     
+    /* 1. mapping CI registers, so that we can access the CI */
+   	
+    ci_dma_y = pxa_request_dma("CI_Y",DMA_PRIO_HIGH, pxa_ci_dma_irq_y, &vd);
+    if(ci_dma_y < 0) 
+    {
+	    camera_free_dma_irq();
+      dbg_print( "PXA_CAMERA: Cann't request DMA for Y\n");
+      return -EIO;
+    }
+    dbg_print( "PXA_CAMERA: Request DMA for Y successfully [%d]\n",ci_dma_y);
+   
+    ci_dma_cb = pxa_request_dma("CI_Cb",DMA_PRIO_HIGH, pxa_ci_dma_irq_cb, &vd);
+    if(ci_dma_cb < 0) 
+    {
+	    camera_free_dma_irq();
+	dbg_print( "PXA_CAMERA: Cann't request DMA for Cb\n");
+	return -EIO;
+    } 
+    dbg_print( "PXA_CAMERA: Request DMA for Cb successfully [%d]\n",ci_dma_cb);
+    
+    ci_dma_cr = pxa_request_dma("CI_Cr",DMA_PRIO_HIGH, pxa_ci_dma_irq_cr, &vd);
+    if(ci_dma_cr < 0) 
+    {
+	    camera_free_dma_irq();
+	dbg_print( "PXA_CAMERA: Cann't request DMA for Cr\n");
+	return -EIO;
+    }
+    
+    dbg_print( "PXA_CAMERA: Request DMA for Cr successfully [%d]\n",ci_dma_cr);
+   
+    DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+    DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+    DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;	
+
+
+    init_waitqueue_head(&camera_wait_q);
+   
+    /*alloc memory for camera context*/
+    if(pxa_camera_mem_init())
+    {
+	    camera_free_dma_irq();
+      dbg_print("memory allocate failed!");
+      return -1;
+    }
+
+    cam_ctx = g_camera_context;
+    
+    /*
+     camera_init call init function for E680
+    */
+    if(camera_init(cam_ctx))
+    {
+       dbg_print("camera_init faile!");
+	    camera_free_dma_irq();
+       pxa_camera_mem_deinit();
+       return -1;
+    }
+    
+    /*
+       allocate memory for dma descriptors 
+       init function of each sensor should set proper value for cam_ctx->buf_size 
+    */
+   	cam_ctx->dma_started = 0;
+    cam_ctx->dma_descriptors_virtual = consistent_alloc(GFP_KERNEL, 
+                                                        (cam_ctx->dma_descriptors_size) * sizeof(pxa_dma_desc),
+                                                        (void *)&(cam_ctx->dma_descriptors_physical));
+    if(cam_ctx->dma_descriptors_virtual == NULL)
+    {
+       dbg_print("consistent alloc memory for dma_descriptors_virtual fail!");
+	    camera_free_dma_irq();
+       pxa_camera_mem_deinit();
+       return -1;
+    }
+
+
+    /*
+      alloc memory for picture buffer 
+      init function of each sensor should set proper value for cam_ctx->buf_size 
+    */    
+    if(pxa_dma_buffer_init(cam_ctx) != 0)
+    {
+      dbg_print("alloc memory for buffer_virtual  %d bytes fail!", g_camera_context->buf_size);
+	    camera_free_dma_irq();
+      pxa_camera_mem_deinit();
+      return -1;
+    }
+     
+    /*
+      set default size and capture format
+      init function of each sensor should set proper value 
+      for capture_width, capture_height, etc. of camera context 
+    */    
+	if(camera_set_capture_format(cam_ctx) != 0)
+	{
+		dbg_print("camera function init error! capture format!");
+	    camera_free_dma_irq();
+		pxa_camera_mem_deinit();
+		return -1;
+    }
+    dbg_print("PXA_CAMERA: pxa_camera_open success!");
+    return 0;
+}
+
+//static void pxa_camera_close(struct video_device *dev)
+static int pxa_camera_close(struct inode *inode, struct file *file)
+{
+    camera_deinit(g_camera_context);
+    pxa_camera_mem_deinit();
+    camera_free_dma_irq();
+    dbg_print("PXA_CAMERA: pxa_camera_close\n");
+}
+
+#define PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, size) \
+do { \
+	unsigned int len; \
+	unsigned int remain_size = size; \
+	while (remain_size > 0) { \
+		if(remain_size > PAGE_SIZE) \
+			len = PAGE_SIZE; \
+		else \
+			len = remain_size; \
+		if(copy_to_user(buf, page_address(*p_page), len)) \
+			return -EFAULT; \
+		remain_size -= len; \
+		buf += len; \
+		p_page++; \
+	} \
+} while (0);
+
+static ssize_t pxa_camera_write(struct file *file, const char __user *data,
+				size_t count, loff_t *ppos)
+{
+	return -EINVAL;
+}
+
+static ssize_t pxa_camera_read(struct file *file, char   __user *buf,
+                            size_t count, loff_t *ppos)
+{
+
+	struct page **p_page;
+
+	camera_context_t *cam_ctx = g_camera_context;
+
+	if(still_image_mode == 1 && still_image_rdy == 1) 
+    {
+		p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+
+		still_image_rdy = 0;
+		return cam_ctx->block_size;
+	}
+
+	if(still_image_mode == 0)
+	{
+		if(first_video_frame == 1)
+			cam_ctx->block_tail = cam_ctx->block_header;
+		else
+			cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+	}
+
+	first_video_frame = 0;
+
+	if(cam_ctx->block_header == cam_ctx->block_tail)  
+    {
+		task_waiting = 1;
+		interruptible_sleep_on (&camera_wait_q);
+	}
+
+	p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+
+	return cam_ctx->block_size;
+}
+
+struct reg_set_s 
+{
+	int  val1;
+	int  val2;
+};
+
+/*ioctl sub functions*/
+static int pxa_camera_VIDIOCGCAP(p_camera_context_t cam_ctx, void * param)
+{
+    dbg_print("VIDIOCGCAP");
+    /*
+      add a vc member to camera context
+    */
+    if(copy_to_user(param, &(cam_ctx->vc), sizeof(struct video_capability)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_VIDIOCGWIN(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_window vw;
+    dbg_print("VIDIOCGWIN");
+    vw.width  = cam_ctx->capture_width;
+    vw.height = cam_ctx->capture_height;
+    if(copy_to_user(param, &vw, sizeof(struct video_window)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_VIDIOCSWIN(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_window vw;
+    dbg_print("VIDIOCSWIN");
+    if(copy_from_user(&vw, param, sizeof(vw))) 
+    {
+        dbg_print("VIDIOCSWIN get parameter error!");
+        return  -EFAULT;
+    } 
+    
+    if(vw.width > cam_ctx->vc.maxwidth  ||
+       vw.height > cam_ctx->vc.maxheight || 
+       vw.width < cam_ctx->vc.minwidth   || 
+       vw.height < cam_ctx->vc.minheight) 
+    {
+        dbg_print("VIDIOCSWIN error parameter!");
+        dbg_print("vw.width:%d, MAX_WIDTH:%d, MIN_WIDTH:%d", vw.width, cam_ctx->vc.maxwidth, cam_ctx->vc.minwidth);
+        dbg_print("vw.height:%d, MAX_HEIGHT:%d, MIN_HEIGHT:%d", vw.width, cam_ctx->vc.maxheight, cam_ctx->vc.minheight);	
+        return  -EFAULT;
+    }
+    
+    //make it in an even multiple of 8 
+    
+    cam_ctx->capture_width  = (vw.width+7)/8;
+    cam_ctx->capture_width  *= 8;
+    
+    cam_ctx->capture_height = (vw.height+7)/8;
+    cam_ctx->capture_height *= 8;
+    
+    return camera_set_capture_format(cam_ctx);
+}
+static int pxa_camera_VIDIOCSPICT(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_picture vp;
+    dbg_print("VIDIOCSPICT");
+    if(copy_from_user(&vp, param, sizeof(vp))) 
+    {
+        return  -EFAULT;
+    }
+    cam_ctx->capture_output_format = vp.palette;
+
+    return  camera_set_capture_format(cam_ctx);
+    
+}
+
+static int pxa_camera_VIDIOCGPICT(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_picture vp;
+    dbg_print("VIDIOCGPICT");
+    vp.palette = cam_ctx->capture_output_format;
+    if(copy_to_user(param, &vp, sizeof(struct video_picture)))
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_VIDIOCCAPTURE(p_camera_context_t cam_ctx, void * param)
+{
+    int capture_flag = (int)param;
+    dbg_print("VIDIOCCAPTURE");
+    if(capture_flag > 0) 
+    {			
+        dbg_print("Still Image capture!");
+        camera_capture_still_image(cam_ctx, 0);
+    }
+    else if(capture_flag == 0) 
+    {
+        dbg_print("Video Image capture!");
+        camera_start_video_capture(cam_ctx, 0);
+    }
+    else if(capture_flag == -1) 
+    {
+        dbg_print("Capture stop!"); 
+        camera_set_int_mask(cam_ctx, 0x3ff);
+        camera_stop_video_capture(cam_ctx);
+    }
+    else 
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_VIDIOCGMBUF(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_mbuf vm;
+    int i;
+
+    dbg_print("VIDIOCGMBUF");
+
+    memset(&vm, 0, sizeof(vm));
+    vm.size   = cam_ctx->buf_size;
+    vm.frames = cam_ctx->block_number;
+    for(i = 0; i < vm.frames; i++)
+    {
+        vm.offsets[i] = cam_ctx->page_aligned_block_size * i;
+    }
+    if(copy_to_user((void *)param, (void *)&vm, sizeof(vm)))
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCSINFOR(p_camera_context_t cam_ctx, void * param)
+{
+
+    struct reg_set_s reg_s;
+    int ret;
+    dbg_print("WCAM_VIDIOCSINFOR");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    
+    cam_ctx->capture_input_format = reg_s.val1;
+    cam_ctx->capture_output_format = reg_s.val2;
+    ret=camera_set_capture_format(cam_ctx);
+    return  ret;
+}
+static int pxa_camera_WCAM_VIDIOCGINFOR(p_camera_context_t cam_ctx, void * param)
+{
+    struct reg_set_s reg_s;
+    dbg_print("WCAM_VIDIOCGINFOR");
+    reg_s.val1 = cam_ctx->capture_input_format;
+    reg_s.val2 = cam_ctx->capture_output_format;
+    if(copy_to_user(param, &reg_s, sizeof(int) * 2)) 
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCGCIREG(p_camera_context_t cam_ctx, void * param)
+{
+
+    int reg_value, offset;
+    dbg_print("WCAM_VIDIOCGCIREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return  -EFAULT;
+    }
+    reg_value = ci_get_reg_value (offset);
+    if(copy_to_user(param, &reg_value, sizeof(int)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_WCAM_VIDIOCSCIREG(p_camera_context_t cam_ctx, void * param)
+{
+
+    struct reg_set_s reg_s;
+    dbg_print("WCAM_VIDIOCSCIREG");
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    ci_set_reg_value (reg_s.val1, reg_s.val2);
+    return 0;
+
+}
+    
+/*get sensor size */
+static int pxa_cam_WCAM_VIDIOCGSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+   struct adcm_window_size{u16 width, height;} size;
+   dbg_print("WCAM_VIDIOCGSSIZE");  
+   size.width = cam_ctx->sensor_width;
+   size.height = cam_ctx->sensor_height;
+
+   if(copy_to_user(param, &size, sizeof(struct adcm_window_size)))
+   {
+       return -EFAULT;
+   }
+  return 0;
+}
+         
+/*get output size*/
+static int pxa_cam_WCAM_VIDIOCGOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+
+   struct adcm_window_size{u16 width, height;}size;
+   dbg_print("WCAM_VIDIOCGOSIZE");  
+   size.width  = cam_ctx->capture_width;
+   size.height = cam_ctx->capture_height;
+   if(copy_to_user(param, &size, sizeof(struct adcm_window_size)))
+   {
+       return -EFAULT;
+   }
+   return 0;
+}
+
+
+
+/*set frame buffer count*/
+static int pxa_cam_WCAM_VIDIOCSBUFCOUNT(p_camera_context_t cam_ctx, void * param)
+{
+	int count;
+	dbg_print("");
+ 	if (copy_from_user(&count, param, sizeof(int)))
+		return -EFAULT;
+   
+   if(cam_ctx->block_number_max == 0) {
+     dbg_print("windows size or format not setting!!");
+     return -EFAULT;
+   }
+   
+   if(count < FRAMES_IN_BUFFER)
+   {
+      count = FRAMES_IN_BUFFER;
+   }
+   
+   if(count > cam_ctx->block_number_max)
+   {
+      count = cam_ctx->block_number_max;
+   }
+      
+
+   cam_ctx->block_number = count;
+   cam_ctx->block_header = cam_ctx->block_tail = 0;
+   //generate dma descriptor chain
+   update_dma_chain(cam_ctx);
+     
+   if(copy_to_user(param, &count, sizeof(int)))
+   {
+     return -EFAULT;
+   }
+   
+   return 0;
+}
+         
+/*get cur avaliable frames*/     
+static int pxa_cam_WCAM_VIDIOCGCURFRMS(p_camera_context_t cam_ctx, void * param)
+{
+  //dbg_print("");
+  struct {int first, last;}pos;
+  
+  pos.first = cam_ctx->block_tail;
+  pos.last  = cam_ctx->block_header;
+  
+  if(copy_to_user(param, &pos, sizeof(pos)))
+  {
+     return -EFAULT;
+  }
+  return 0;
+}
+
+/*get sensor type*/
+static int pxa_cam_WCAM_VIDIOCGSTYPE(p_camera_context_t cam_ctx, void * param)
+{
+  dbg_print("");
+  if(copy_to_user(param, &(cam_ctx->sensor_type), sizeof(cam_ctx->sensor_type)))
+  {
+    return -EFAULT;
+  }
+  return 0;
+}
+
+static int pxa_camera_ioctl(struct inode *inode, struct file *file,
+			    unsigned int cmd, unsigned long arg)
+{
+	void *param = (void *) arg;
+
+   	switch (cmd) 
+    {
+        /*get capture capability*/
+    case VIDIOCGCAP:
+        return pxa_camera_VIDIOCGCAP(g_camera_context, param);
+        /* get capture size */
+    case VIDIOCGWIN:
+        return  pxa_camera_VIDIOCGWIN(g_camera_context, param);
+
+        /* set capture size. */
+    case VIDIOCSWIN:
+        return pxa_camera_VIDIOCSWIN(g_camera_context, param);
+        /*set capture output format*/
+    case VIDIOCSPICT:
+        return pxa_camera_VIDIOCSPICT(g_camera_context, param);
+
+        /*get capture output format*/
+    case VIDIOCGPICT:
+        return pxa_camera_VIDIOCGPICT(g_camera_context, param);
+
+        /*start capture */
+    case VIDIOCCAPTURE:
+        return pxa_camera_VIDIOCCAPTURE(g_camera_context, param);
+
+        /* mmap interface */
+    case VIDIOCGMBUF:
+         return pxa_camera_VIDIOCGMBUF(g_camera_context, param);
+
+        /* Application extended IOCTL.  */
+        /* Register access interface	*/
+    case WCAM_VIDIOCSINFOR:
+         return pxa_camera_WCAM_VIDIOCSINFOR(g_camera_context, param);
+
+        /*get capture format*/
+    case WCAM_VIDIOCGINFOR:
+         return pxa_camera_WCAM_VIDIOCGINFOR(g_camera_context, param);
+
+        /*get ci reg value*/
+    case WCAM_VIDIOCGCIREG:
+        return pxa_camera_WCAM_VIDIOCGCIREG(g_camera_context, param);
+
+        /*set ci reg*/
+    case WCAM_VIDIOCSCIREG:
+        return pxa_camera_WCAM_VIDIOCSCIREG(g_camera_context, param);
+            
+        /*get sensor size */  
+    case WCAM_VIDIOCGSSIZE:
+         return pxa_cam_WCAM_VIDIOCGSSIZE(g_camera_context, param);
+    
+         /*get output size*/
+    case WCAM_VIDIOCGOSIZE:
+         return pxa_cam_WCAM_VIDIOCGOSIZE(g_camera_context, param);
+
+         /*set frame buffer count*/     
+    case WCAM_VIDIOCSBUFCOUNT:
+         return pxa_cam_WCAM_VIDIOCSBUFCOUNT(g_camera_context, param);
+         
+         /*get cur avaliable frames*/     
+    case WCAM_VIDIOCGCURFRMS:
+         return pxa_cam_WCAM_VIDIOCGCURFRMS(g_camera_context, param);
+         
+         /*get cur sensor type*/
+    case WCAM_VIDIOCGSTYPE:
+         return pxa_cam_WCAM_VIDIOCGSTYPE(g_camera_context, param);
+    
+    default:
+         return  g_camera_context->camera_functions->command(g_camera_context, cmd, param);
+    }
+    
+   return 0;
+}
+
+//static int pxa_camera_mmap(struct video_device *dev, const char *adr, unsigned long size)
+static int pxa_camera_mmap(struct file *file, struct vm_area_struct *vma)
+{
+   	unsigned long start = vma->vm_start;
+	unsigned long size = (vma->vm_end - vma->vm_start);
+	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+	camera_context_t *cam_ctx = g_camera_context;
+	struct page **p_page = cam_ctx->page_array;
+
+	size = PAGE_ALIGN(size);
+	if (remap_pfn_range(vma, start, page_to_phys(*p_page), size,
+			    PAGE_SHARED)) {
+			return -EFAULT;
+	}
+	return 0;
+ }
+
+static unsigned int pxa_camera_poll(struct file *file, poll_table *wait) 
+{
+    static int waited = 0;
+    camera_context_t *cam_ctx = g_camera_context;
+
+    poll_wait(file, &camera_wait_q, wait);
+    
+    if(still_image_mode == 1 && still_image_rdy == 1) 
+    {
+        still_image_rdy = 0;
+        waited = 0;
+        return POLLIN | POLLRDNORM;
+	}
+    
+    if(first_video_frame == 1)
+    {
+       first_video_frame = 0;
+    }
+    else if(still_image_mode == 0 && waited != 1)
+    {
+       cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+    }
+
+    if(cam_ctx->block_header == cam_ctx->block_tail)  
+    {
+        task_waiting = 1;
+        waited = 1;
+        return 0;
+    }
+    waited = 0;
+    return POLLIN | POLLRDNORM;
+}
+
+int pxa_camera_mem_deinit(void)
+{
+    if(g_camera_context)
+    {
+        if(g_camera_context->dma_descriptors_virtual != NULL) 
+        {
+         consistent_free(g_camera_context->dma_descriptors_virtual, 
+                         g_camera_context->dma_descriptors_size * sizeof(pxa_dma_desc),  
+                         (int)g_camera_context->dma_descriptors_physical);
+		      
+          g_camera_context->dma_descriptors_virtual = NULL;
+
+        }
+       if(g_camera_context->buffer_virtual != NULL)  
+       {
+        pxa_dma_buffer_free(g_camera_context);		     
+        g_camera_context->buffer_virtual = NULL;
+       }
+       kfree(g_camera_context);
+       g_camera_context = NULL;
+    }
+    
+    return 0;
+}
+
+int pxa_camera_mem_init(void)
+{
+   g_camera_context = kmalloc(sizeof(struct camera_context_s), GFP_KERNEL);
+
+    if(g_camera_context == NULL)
+    {
+    	dbg_print( "PXA_CAMERA: Cann't allocate buffer for camera control structure \n");
+        return -1;
+    }
+	
+    memset(g_camera_context, 0, sizeof(struct camera_context_s));
+    
+    dbg_print("success!"); 
+    return 0;
+}
+
+int pxa_camera_video_init(struct video_device *vdev)
+{
+  return 0;
+}
+
+
+static int __init pxa_camera_init(void)
+{
+	camera_context_t cam_ctx;
+ 
+	if (request_irq(IRQ_CAMERA, pxa_camera_irq, 0, "PXA Camera", &vd)) {
+		dbg_print("Camera interrupt register failed failed number \n");
+		return -EIO;
+ 	} 
+    dbg_print ("Camera interrupt register successful \n");
+    
+    minor =0 ;
+ 
+    if(video_register_device(&vd, VFL_TYPE_GRABBER, minor) < 0) 
+    {
+	dbg_print("PXA_CAMERA: video_register_device failed\n");
+	return -EIO;
+    }
+#ifdef CONFIG_ARCH_EZX_A780
+    PGSR1 |= GPIO_bit(50);
+    PGSR0 |= GPIO_bit(19);
+#endif
+
+#ifdef CONFIG_PM    
+    pm_dev = pm_register(PM_SYS_DEV, 0, camera_pm_callback);
+#endif
+
+    dbg_print("PXA_CAMERA: video_register_device successfully. /dev/video%d \n",minor);
+  
+    return 0;
+}
+
+static void __exit pxa_camera_exit(void)
+{
+    free_irq(IRQ_CAMERA,  &vd);
+    
+#ifdef CONFIG_PM
+     pm_unregister(pm_dev);
+#endif
+    
+    video_unregister_device(&vd);
+    
+}
+
+
+//-------------------------------------------------------------------------------------------------------
+//      Configuration APIs
+//-------------------------------------------------------------------------------------------------------
+void ci_set_frame_rate(CI_FRAME_CAPTURE_RATE frate)
+{
+	unsigned int value;
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_FR_RATE_SMASK << CI_CICR4_FR_RATE_SHIFT);
+	value |= (unsigned)frate << CI_CICR4_FR_RATE_SHIFT;
+	CICR4 = value;
+}
+
+CI_FRAME_CAPTURE_RATE ci_get_frame_rate(void)
+{
+	unsigned int value;
+	value = CICR4;
+	return (CI_FRAME_CAPTURE_RATE)((value >> CI_CICR4_FR_RATE_SHIFT) & CI_CICR4_FR_RATE_SMASK);
+}
+
+void ci_set_image_format(CI_IMAGE_FORMAT input_format, CI_IMAGE_FORMAT output_format)
+{
+
+    unsigned int value, tbit, rgbt_conv, rgb_conv, rgb_f, ycbcr_f, rgb_bpp, raw_bpp, cspace;
+    // write cicr1: preserve ppl value and data width value
+    dbg_print("0");
+    value = CICR1;
+    dbg_print("1");
+    value &= ( (CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT) | ((CI_CICR1_DW_SMASK) << CI_CICR1_DW_SHIFT));
+    tbit = rgbt_conv = rgb_conv = rgb_f = ycbcr_f = rgb_bpp = raw_bpp = cspace = 0;
+    switch(input_format) 
+    {
+    case CI_RAW8:
+        cspace = 0;
+        raw_bpp = 0;
+        break;
+    case CI_RAW9:
+        cspace = 0;
+        raw_bpp = 1;
+        break;
+    case CI_RAW10:
+        cspace = 0;
+        raw_bpp = 2;
+        break;
+    case CI_YCBCR422:
+    case CI_YCBCR422_PLANAR:
+        cspace = 2;
+        if(output_format == CI_YCBCR422_PLANAR) 
+        {
+            ycbcr_f = 1;
+        }
+        break;
+    case CI_RGB444:
+        cspace = 1;
+        rgb_bpp = 0;
+        break;  
+    case CI_RGB555:
+        cspace = 1;
+        rgb_bpp = 1;
+        if(output_format == CI_RGBT555_0) 
+        {
+            rgbt_conv = 2;
+            tbit = 0;
+        } 
+        else if(output_format == CI_RGBT555_1) 
+        {
+            rgbt_conv = 2;
+            tbit = 1;
+        }
+        break;  
+    case CI_RGB565:
+        cspace = 1;
+        rgb_bpp = 2;
+        rgb_f = 1;
+        break;  
+    case CI_RGB666: 
+        cspace = 1;
+        rgb_bpp = 3;
+        if(output_format == CI_RGB666_PACKED) 
+        {
+            rgb_f = 1;
+        }
+        break;  
+    case CI_RGB888:
+    case CI_RGB888_PACKED:
+        cspace = 1;
+        rgb_bpp = 4;
+        switch(output_format) 
+        {
+        case CI_RGB888_PACKED:
+            rgb_f = 1;
+            break;
+        case CI_RGBT888_0:
+            rgbt_conv = 1;
+            tbit = 0;
+            break;
+        case CI_RGBT888_1:
+            rgbt_conv = 1;
+            tbit = 1;
+            break;
+        case CI_RGB666:
+            rgb_conv = 1;
+            break;
+            // RGB666 PACKED - JamesL
+        case CI_RGB666_PACKED:
+            rgb_conv = 1;
+            rgb_f = 1;
+            break;
+            // end
+        case CI_RGB565:
+            dbg_print("format : 565");
+            rgb_conv = 2;
+            break;
+        case CI_RGB555:
+            rgb_conv = 3;
+            break;
+        case CI_RGB444:
+            rgb_conv = 4;
+            break;
+        default:
+            break;
+        }
+        break;  
+    default:
+        break;
+    }
+        dbg_print("2");
+    value |= (tbit==1) ? CI_CICR1_TBIT : 0;
+    value |= rgbt_conv << CI_CICR1_RGBT_CONV_SHIFT;
+    value |= rgb_conv << CI_CICR1_RGB_CONV_SHIFT;
+    value |= (rgb_f==1) ? CI_CICR1_RBG_F : 0;
+    value |= (ycbcr_f==1) ? CI_CICR1_YCBCR_F : 0;
+    value |= rgb_bpp << CI_CICR1_RGB_BPP_SHIFT;
+    value |= raw_bpp << CI_CICR1_RAW_BPP_SHIFT;
+    value |= cspace << CI_CICR1_COLOR_SP_SHIFT;
+    CICR1 = value;   
+
+}
+
+void ci_set_mode(CI_MODE mode, CI_DATA_WIDTH data_width)
+{
+	unsigned int value;
+	
+	// write mode field in cicr0
+	value = CICR0;
+	value &= ~(CI_CICR0_SIM_SMASK << CI_CICR0_SIM_SHIFT);
+	value |= (unsigned int)mode << CI_CICR0_SIM_SHIFT;
+	CICR0 = value;   
+	
+	// write data width cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_DW_SMASK << CI_CICR1_DW_SHIFT);
+	value |= ((unsigned)data_width) << CI_CICR1_DW_SHIFT;
+	CICR1 = value;   
+	return; 
+}
+
+void ci_configure_mp(unsigned int ppl, unsigned int lpf, CI_MP_TIMING* timing)
+{
+	unsigned int value;
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;   
+	
+	// write BLW, ELW in cicr2  
+	value = CICR2;
+	value &= ~(CI_CICR2_BLW_SMASK << CI_CICR2_BLW_SHIFT | CI_CICR2_ELW_SMASK << CI_CICR2_ELW_SHIFT );
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	CICR2 = value;   
+	
+	// write BFW, LPF in cicr3
+	value = CICR3;
+	value &= ~(CI_CICR3_BFW_SMASK << CI_CICR3_BFW_SHIFT | CI_CICR3_LPF_SMASK << CI_CICR3_LPF_SHIFT );
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;   
+
+}
+
+void ci_configure_sp(unsigned int ppl, unsigned int lpf, CI_SP_TIMING* timing)
+{
+	unsigned int value;
+
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;   
+	
+	// write cicr2
+	value = CICR2;
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	value |= (timing->ELW & CI_CICR2_ELW_SMASK) << CI_CICR2_ELW_SHIFT;
+	value |= (timing->HSW & CI_CICR2_HSW_SMASK) << CI_CICR2_HSW_SHIFT;
+	value |= (timing->BFPW & CI_CICR2_BFPW_SMASK) << CI_CICR2_BFPW_SHIFT;
+	value |= (timing->FSW & CI_CICR2_FSW_SMASK) << CI_CICR2_FSW_SHIFT;
+	CICR2 = value;   
+
+	// write cicr3
+	value = CICR3;
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (timing->EFW & CI_CICR3_EFW_SMASK) << CI_CICR3_EFW_SHIFT;
+	value |= (timing->VSW & CI_CICR3_VSW_SMASK) << CI_CICR3_VSW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;   
+	return;
+}
+
+void ci_configure_ms(unsigned int ppl, unsigned int lpf, CI_MS_TIMING* timing)
+{
+	// the operation is same as Master-Parallel
+	ci_configure_mp(ppl, lpf, (CI_MP_TIMING*)timing);
+}
+
+void ci_configure_ep(int parity_check)
+{
+	unsigned int value;
+
+	// write parity_enable field in cicr0   
+	value = CICR0;
+	if(parity_check) 
+    {
+		value |= CI_CICR0_PAR_EN;
+	}
+	else 
+    {
+		value &= ~CI_CICR0_PAR_EN;
+	}
+	CICR0 = value;   
+	return; 
+}
+
+void ci_configure_es(int parity_check)
+{
+	// the operationi is same as Embedded-Parallel
+	ci_configure_ep(parity_check);
+}
+
+void ci_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz)
+{
+	unsigned int ciclk,  value, div, cccr_l, K;
+
+	// determine the LCLK frequency programmed into the CCCR.
+	cccr_l = (CCCR & 0x0000001F);
+
+	if(cccr_l < 8)
+		K = 1;
+	else if(cccr_l < 17)
+		K = 2;
+	else 
+		K = 3;
+
+	ciclk = (13 * cccr_l) / K;
+	
+	div = (ciclk + mclk_khz) / ( 2 * mclk_khz ) - 1;
+	dbg_print("cccr=%xciclk=%d,cccr_l=%d,K=%d,div=%d,mclk=%d\n",CCCR,ciclk,cccr_l,K,div,mclk_khz);
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCLK_EN | CI_CICR4_MCLK_EN | CI_CICR4_DIV_SMASK<<CI_CICR4_DIV_SHIFT);
+	value |= (pclk_enable) ? CI_CICR4_PCLK_EN : 0;
+	value |= (mclk_enable) ? CI_CICR4_MCLK_EN : 0;
+	value |= div << CI_CICR4_DIV_SHIFT;
+	CICR4 = value;   
+	return; 
+}
+
+void ci_set_polarity(int pclk_sample_falling, int hsync_active_low, int vsync_active_low)
+{
+	unsigned int value;
+          dbg_print(""); 
+	
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCP | CI_CICR4_HSP | CI_CICR4_VSP);
+	value |= (pclk_sample_falling)? CI_CICR4_PCP : 0;
+	value |= (hsync_active_low) ? CI_CICR4_HSP : 0;
+	value |= (vsync_active_low) ? CI_CICR4_VSP : 0;
+	CICR4 = value;   
+	return; 
+}
+
+void ci_set_fifo(unsigned int timeout, CI_FIFO_THRESHOLD threshold, int fifo1_enable,
+               int fifo2_enable)
+{
+	unsigned int value;
+        dbg_print("");
+	// write citor
+	CITOR = timeout; 
+	
+	// write cifr: always enable fifo 0! also reset input fifo 
+	value = CIFR;
+	value &= ~(CI_CIFR_FEN0 | CI_CIFR_FEN1 | CI_CIFR_FEN2 | CI_CIFR_RESETF | 
+	CI_CIFR_THL_0_SMASK<<CI_CIFR_THL_0_SHIFT);
+	value |= (unsigned int)threshold << CI_CIFR_THL_0_SHIFT;
+	value |= (fifo1_enable) ? CI_CIFR_FEN1 : 0;
+	value |= (fifo2_enable) ? CI_CIFR_FEN2 : 0;
+	value |= CI_CIFR_RESETF | CI_CIFR_FEN0;
+	CIFR = value;
+}
+
+void ci_reset_fifo()
+{
+	unsigned int value;
+	value = CIFR;
+	value |= CI_CIFR_RESETF;
+	CIFR = value;
+}
+
+void ci_set_int_mask(unsigned int mask)
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_INTERRUPT_MASK;
+	value |= (mask & CI_CICR0_INTERRUPT_MASK);
+	dbg_print("-----------value=0x%x\n",value);
+	CICR0 = value;   
+	return; 
+}
+
+unsigned int ci_get_int_mask()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	return (value & CI_CICR0_INTERRUPT_MASK);
+}
+
+void ci_clear_int_status(unsigned int status)
+{
+	// write 1 to clear
+	CISR = status;
+}
+
+unsigned int ci_get_int_status()
+{
+	int value;
+
+	value = CISR;
+
+	return  value;
+}
+
+void ci_set_reg_value(unsigned int reg_offset, unsigned int value)
+{
+    switch(reg_offset)
+    {
+      case 0:
+        CICR0 = value;
+        break;
+      case 1:
+        CICR1 = value;
+        break;
+      case 2:
+        CICR2 = value;
+        break;
+      case 3:
+        CICR3 = value;
+        break;
+      case 4:
+        CICR4 = value;
+        break;        
+      case 5:
+        CISR  = value;
+        break;        
+      case 6:
+        CIFR = value;
+        break;        
+      case 7:
+        CITOR = value;
+        break;
+    }
+}
+
+int ci_get_reg_value(unsigned int reg_offset)
+{
+    
+    unsigned values[] = {CICR0, CICR1, CICR2, CICR3, CICR4, CISR, CIFR, CITOR};
+    
+    if(reg_offset >=0 && reg_offset <= 7)
+    	return values[reg_offset];
+     else
+        return CISR;
+}
+
+//-------------------------------------------------------------------------------------------------------
+//  Control APIs
+//-------------------------------------------------------------------------------------------------------
+int ci_init()
+{
+
+	// clear all CI registers  disable all interrupts
+	CICR0 = 0x3FF;   
+	CICR1 = 0;
+	CICR2 = 0;
+	CICR3 = 0;
+	CICR4 = 0;
+	CISR = ~0;
+	CIFR = 0;
+	CITOR = 0;
+	
+	// enable CI clock
+	CKEN |= CKEN24_CAMERA;
+	return 0;
+}
+
+void ci_deinit()
+{
+	// disable CI clock
+	CICR4 = 0;
+	mdelay(1);
+	CKEN &= ~CKEN24_CAMERA;
+}
+void ci_reset()
+{
+  ci_disable(1);
+  ci_enable(1);
+  mdelay(30);
+}
+void ci_enable(int dma_en)
+{        
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_ENB;
+	if(dma_en) {
+		value |= CI_CICR0_DMA_EN;
+	}
+	CICR0 = value;   
+	return; 
+}
+
+int ci_disable(int quick)
+{
+	volatile unsigned int value, mask;
+	int retry;
+
+	// write control bit in cicr0   
+	value = CICR0;
+	if(quick)
+        {
+		value &= ~CI_CICR0_ENB;
+		mask = CI_CISR_CQD;
+	}
+	else 
+        {
+		value |= CI_CICR0_DIS;
+		mask = CI_CISR_CDD;
+	}
+	CICR0 = value;   
+	
+	// wait shutdown complete
+	retry = 50;
+	while ( retry-- > 0 ) 
+    {
+ 	value = CISR;
+	 if( value & mask ) 
+     {
+		CISR = mask;
+		return 0;
+	 }
+	 mdelay(10);
+	}
+	return -1; 
+}
+
+void ci_slave_capture_enable()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_SL_CAP_EN;
+	CICR0 = value;   
+	return; 
+}
+
+void ci_slave_capture_disable()
+{
+	unsigned int value;
+	
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_SL_CAP_EN;
+	CICR0 = value;   
+	return; 
+}
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs)
+{
+
+    static int dma_repeated = 0;
+    camera_context_t  *cam_ctx = g_camera_context;
+    int        dcsr;
+    
+    dcsr = DCSR(channel);
+    DCSR(channel) = dcsr & ~DCSR_STOPIRQEN;
+ 
+    if(still_image_mode == 1) 
+    {
+        if(task_waiting == 1) 
+        {
+            wake_up_interruptible (&camera_wait_q);
+            task_waiting = 0;
+        }
+        still_image_rdy = 1;
+    	stop_dma_transfer(cam_ctx);
+    } 
+    else if(dma_repeated == 0 &&
+           (cam_ctx->block_tail == ((cam_ctx->block_header + 2) % cam_ctx->block_number)))  
+    {
+        dma_repeated = 1;
+        pxa_dma_repeat(cam_ctx);
+        //dbg_print ("DMA repeated.");
+        cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+    }
+    else if(dma_repeated == 1 && 
+        (cam_ctx->block_tail != ((cam_ctx->block_header + 1) % cam_ctx->block_number)) && 
+        (cam_ctx->block_tail != ((cam_ctx->block_header + 2) % cam_ctx->block_number)))  
+    {
+        pxa_dma_continue(cam_ctx);
+        //dbg_print ("DMA continue.");
+        dma_repeated = 0;
+    }
+    else if(dma_repeated == 0) 
+    {
+        cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+    }
+    
+    if(task_waiting == 1 && !(cam_ctx->block_header == cam_ctx->block_tail)) 
+    {
+        wake_up_interruptible (&camera_wait_q);
+        task_waiting = 0;
+    }
+
+}
+
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs)
+{
+    return;
+}
+
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs)
+{
+    return;
+}
+
+
+static irqreturn_t pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs)
+{
+	unsigned int cisr;
+
+	disable_irq(IRQ_CAMERA);
+	cisr = CISR;
+
+	if (cisr & CI_CISR_SOF) 
+        	CISR |= CI_CISR_SOF;
+
+    	if (cisr & CI_CISR_EOF) 
+        	CISR |= CI_CISR_EOF;
+
+	enable_irq(IRQ_CAMERA);
+
+	return IRQ_HANDLED;
+}
+
+void pxa_dma_repeat(camera_context_t  *cam_ctx)
+{
+    pxa_dma_desc *cnt_head, *cnt_tail;
+	int cnt_block;
+
+	cnt_block = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+    
+    // FIFO0
+	(pxa_dma_desc *)cnt_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + 
+                                cnt_block * cam_ctx->fifo0_num_descriptors;
+                                
+	cnt_tail = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+	cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+    
+    // FIFO1
+	if(cam_ctx->fifo1_transfer_size) 
+    {
+		cnt_head = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo1_num_descriptors;
+                    
+		cnt_tail = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+    
+    // FIFO2
+	if(cam_ctx->fifo2_transfer_size) 
+    {
+		cnt_head = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo2_num_descriptors;
+                    
+		cnt_tail = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+ }
+
+void pxa_dma_continue(camera_context_t *cam_ctx)
+{
+   	pxa_dma_desc *cnt_head, *cnt_tail;
+	pxa_dma_desc *next_head;
+	int cnt_block, next_block;
+
+	cnt_block = cam_ctx->block_header;
+	next_block = (cnt_block + 1) % cam_ctx->block_number;
+    
+    // FIFO0
+	cnt_head  = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + 
+                cnt_block * cam_ctx->fifo0_num_descriptors;
+                
+	cnt_tail  = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+    
+	next_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual +
+                next_block * cam_ctx->fifo0_num_descriptors;
+
+    cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+    
+    // FIFO1
+	if(cam_ctx->fifo1_transfer_size) 
+    {
+		cnt_head  = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo1_num_descriptors;
+                    
+		cnt_tail  = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+        
+		next_head = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                     next_block * cam_ctx->fifo1_num_descriptors;
+                     
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+    
+    // FIFO2
+	if(cam_ctx->fifo2_transfer_size) 
+    {
+		cnt_head  = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                   cnt_block * cam_ctx->fifo2_num_descriptors;
+                   
+		cnt_tail  = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+        
+		next_head = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                    next_block * cam_ctx->fifo2_num_descriptors;
+                    
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+	return;
+
+}
+
+void ci_dump(void)
+{
+    dbg_print ("CICR0 = 0x%8lx ", CICR0);
+    dbg_print ("CICR1 = 0x%8lx ", CICR1);
+    dbg_print ("CICR2 = 0x%8lx ", CICR2);
+    dbg_print ("CICR3 = 0x%8lx ", CICR3);
+    dbg_print ("CICR4 = 0x%8lx ", CICR4);
+    dbg_print ("CISR  = 0x%8lx ", CISR);
+    dbg_print ("CITOR = 0x%8lx ", CITOR);
+    dbg_print ("CIFR  = 0x%8lx ", CIFR);
+}
+
+
+module_init(pxa_camera_init);
+module_exit(pxa_camera_exit);
+
+MODULE_DESCRIPTION("Bulverde Camera Interface driver");
+MODULE_LICENSE("GPL");
+
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/pxa_camera_micron.c linux-2.6.16.5-exz/drivers/media/video/pxa_camera_micron.c
--- linux-2.6.16.5/drivers/media/video/pxa_camera_micron.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/pxa_camera_micron.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,2905 @@
+/*================================================================================
+                                                                               
+                     Module Name:  pxa-camera.c
+
+General Description: Camera module mt9m111  source file
+
+==================================================================================
+                      Motorola Confidential Proprietary
+                  Advanced Technology and Software Operations
+                (c) Copyright Motorola 1999, All Rights Reserved
+  
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+                                                 
+Portability: Indicate ifthis module is portable to other compilers or 
+platforms. If not, indicate specific reasons why is it not portable.
+
+==================================================================================
+                                 INCLUDE FILES
+================================================================================*/  
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+
+#include <linux/types.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/dma.h>
+#include <asm/arch/irqs.h>
+#include <asm/irq.h>
+
+
+#define DEBUG
+#include "camera.h"
+#include "mt9m111.h"
+#include "mt9m111_hw.h"
+
+#define CIBR0_PHY	(0x50000000 + 0x28)
+#define CIBR1_PHY	(0x50000000 + 0x30)
+#define CIBR2_PHY	(0x50000000 + 0x38)
+
+#define MAX_WIDTH	1280
+#define MAX_HEIGHT	1024
+
+#define MIN_WIDTH	88
+#define MIN_HEIGHT	72
+#define WIDTH_DEFT	320
+#define HEIGHT_DEFT	240
+#define FRAMERATE_DEFT	15
+
+/*
+ * It is required to have at least 3 frames in buffer
+ * in current implementation
+ */
+#define FRAMES_IN_BUFFER    	3
+#define BUF_SIZE_DEFT		    ((PAGE_ALIGN(MAX_WIDTH * MAX_HEIGHT) + (PAGE_ALIGN(MAX_WIDTH*MAX_HEIGHT/2)*2)))
+#define SINGLE_DESC_TRANS_MAX  	 PAGE_SIZE
+#define MAX_DESC_NUM		    (BUF_SIZE_DEFT/PAGE_SIZE +10)
+
+#define DRCMR68		__REG(0x40001110)  /* Request to Channel Map Register for Camera FIFO 0 Request */
+#define DRCMR69		__REG(0x40001114)  /* Request to Channel Map Register for Camera FIFO 1 Request */
+#define DRCMR70		__REG(0x40001118)  /* Request to Channel Map Register for Camera FIFO 2 Request */
+
+static camera_context_t  *g_camera_context;
+
+#ifdef CONFIG_CAMERA_MT9M111
+static camera_function_t  mt9m111_func;
+#endif 
+#ifdef CONFIG_CAMERA_OV9640
+extern camera_function_t  ov9640_func;
+#endif
+
+static int         irq_n        =0;
+static int         camera_irq_n =0;
+wait_queue_head_t  camera_wait_q;	
+
+static int         waitingFrame = 0;
+
+/* /dev/videoX registration number */
+static int 	minor     = 0;
+static int	ci_dma_y  = -1;
+static int	ci_dma_cb = -1;
+static int	ci_dma_cr = -1;
+static int 	task_waiting      = 0;
+static int 	still_image_mode  = 0;
+static int	still_image_rdy	  = 0;
+static int 	first_video_frame = 0;
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs);
+
+static unsigned long ci_regs_base = 0;   /* for CI registers IOMEM mapping */
+
+#define CI_REG(x)             (* (volatile u32*)(x) )
+#define CI_REG_SIZE             0x40 /* 0x5000_0000 --- 0x5000_0038 * 64K */
+#define CI_REGS_PHYS            0x50000000  /* Start phyical address of CI registers */
+ 
+/*
+#define CICR0		        CI_REG((u32)(ci_regs_base) + 0x00)
+#define CICR1           	CI_REG((u32)(ci_regs_base) + 0x04)
+#define CICR2 		        CI_REG((u32)(ci_regs_base) + 0x08)
+#define CICR3           	CI_REG((u32)(ci_regs_base) + 0x0c)
+#define CICR4             	CI_REG((u32)(ci_regs_base) + 0x10)
+#define CISR 	        	CI_REG((u32)(ci_regs_base) + 0x14)
+#define CIFR              	CI_REG((u32)(ci_regs_base) + 0x18)
+#define CITOR             	CI_REG((u32)(ci_regs_base) + 0x1c)
+#define CIBR0             	CI_REG((u32)(ci_regs_base) + 0x28)
+#define CIBR1             	CI_REG((u32)(ci_regs_base) + 0x30)
+#define CIBR2             	CI_REG((u32)(ci_regs_base) + 0x38)
+*/
+
+/***********************************************************************
+ *
+ * Declarations
+ *
+ ***********************************************************************/
+
+// map of camera image format (camera.h) ==> capture interface format (ci.h)
+static const CI_IMAGE_FORMAT FORMAT_MAPPINGS[] = {
+        CI_RAW8,                   //RAW
+        CI_RAW9,
+        CI_RAW10,
+
+        CI_RGB444,                 //RGB
+        CI_RGB555,
+        CI_RGB565,
+        CI_RGB666_PACKED,          //RGB Packed 
+        CI_RGB666,
+        CI_RGB888_PACKED,
+        CI_RGB888,
+        CI_RGBT555_0,              //RGB+Transparent bit 0
+        CI_RGBT888_0,
+        CI_RGBT555_1,              //RGB+Transparent bit 1  
+        CI_RGBT888_1,
+    
+        CI_INVALID_FORMAT,
+        CI_YCBCR422,               //YCBCR
+        CI_YCBCR422_PLANAR,        //YCBCR Planaried
+        CI_INVALID_FORMAT,
+        CI_INVALID_FORMAT
+};
+
+static int update_dma_chain(p_camera_context_t camera_context);
+static void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id);
+void stop_dma_transfer(p_camera_context_t camera_context);
+static int start_capture(p_camera_context_t camera_context, unsigned int block_id, unsigned int frames);
+int camera_init(p_camera_context_t camera_context);
+
+#ifdef CONFIG_PM
+      static struct pm_dev *pm_dev;
+      static int resume_dma = 0;
+#endif   
+
+#ifdef CONFIG_PM
+
+static int pxa_camera_pm_suspend()
+{
+	if(g_camera_context != NULL )
+	{
+   		if(g_camera_context->dma_started) 
+   		{
+	  		dbg_print("camera running, suspended");
+	  		stop_dma_transfer(g_camera_context);
+      		resume_dma = 1;
+   		}
+	}
+    
+   disable_irq(IRQ_CAMERA);
+   CKEN &= ~CKEN24_CAMERA;
+   return 0;
+}
+
+static int pxa_camera_pm_resume()
+{
+   CKEN |= CKEN24_CAMERA;
+   enable_irq(IRQ_CAMERA);
+
+   if(g_camera_context != NULL)
+   {  
+   	  dbg_print("camera running, resumed");
+      micron_window_size size;
+      camera_init(g_camera_context);
+      
+      size.width  = g_camera_context->sensor_width;
+      size.height = g_camera_context->sensor_height;
+      mt9m111_input_size(&size);
+      
+      size.width  = g_camera_context->capture_width;
+      size.height = g_camera_context->capture_height;
+      mt9m111_output_size(&size);
+      
+      mt9m111_set_bright(g_camera_context->capture_bright);
+   
+      mt9m111_set_fps(g_camera_context->fps, g_camera_context->mini_fps);
+      mt9m111_set_light(g_camera_context->capture_light);
+      mt9m111_set_style(g_camera_context->capture_style);
+      
+      if(resume_dma == 1)
+      {
+        camera_start_video_capture(g_camera_context, 0);
+        resume_dma = 0;
+      }
+       
+   }
+   
+  return 0;
+}
+static int camera_pm_callback(struct pm_dev *pm_dev, pm_request_t req, void *data)
+{
+    switch(req)
+    {
+   	case PM_SUSPEND:
+           	pxa_camera_pm_suspend();
+	   	break;
+        
+       	case PM_RESUME:
+		    pxa_camera_pm_resume();
+        break;
+        
+	default:
+        break;
+    }
+  return 0;
+}
+#endif   
+/***********************************************************************
+ *
+ * Private functions
+ *
+ ***********************************************************************/
+ 
+static int pxa_dma_buffer_init(p_camera_context_t camera_context)
+{
+	struct page    *page;
+	unsigned int	pages;
+	unsigned int	page_count;
+
+	camera_context->pages_allocated = 0;
+
+	pages = (PAGE_ALIGN(camera_context->buf_size) / PAGE_SIZE);
+
+	camera_context->page_array = (struct page **)
+                                 kmalloc(pages * sizeof(struct page *),
+                                 GFP_KERNEL);
+                               
+	if(camera_context->page_array == NULL)
+	{
+		return -ENOMEM;
+	}
+	memset(camera_context->page_array, 0, pages * sizeof(struct page *));
+
+	for(page_count = 0; page_count < pages; page_count++)
+	{
+		page = alloc_page(GFP_KERNEL);
+		if(page == NULL)
+		{
+			goto error;
+		}
+		camera_context->page_array[page_count] = page;
+		set_page_count(page, 1);
+		SetPageReserved(page);
+	}
+	camera_context->buffer_virtual = remap_page_array(camera_context->page_array, 
+                                                      pages,
+ 	                                                  GFP_KERNEL);
+
+	if(camera_context->buffer_virtual == NULL)
+	{
+		goto error;
+	}
+
+	camera_context->pages_allocated = pages;
+
+	return 0;
+
+error:
+	for(page_count = 0; page_count < pages; page_count++)
+	{
+		if((page = camera_context->page_array[page_count]) != NULL)
+		{
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(camera_context->page_array);
+
+	return -ENOMEM;
+}
+
+static void pxa_dma_buffer_free(p_camera_context_t camera_context)
+{
+	struct page *page;
+	int page_count;
+
+	if(camera_context->buffer_virtual == NULL)
+		return;
+
+	vfree(camera_context->buffer_virtual);
+
+	for(page_count = 0; page_count < camera_context->pages_allocated; page_count++)
+	{
+		if((page = camera_context->page_array[page_count]) != NULL)
+		{
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(camera_context->page_array);
+}
+/*
+Generate dma descriptors
+Pre-condition: these variables must be set properly
+                block_number, fifox_transfer_size 
+                dma_descriptors_virtual, dma_descriptors_physical, dma_descirptors_size
+Post-condition: these variables will be set
+                fifox_descriptors_virtual, fifox_descriptors_physical              
+                fifox_num_descriptors 
+*/
+int update_dma_chain(p_camera_context_t camera_context)
+{
+    
+	pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+	int des_transfer_size, remain_size;
+	unsigned int i,j;
+	int target_page_num;
+    
+    dbg_print("");
+
+	// clear descriptor pointers
+	camera_context->fifo0_descriptors_virtual = camera_context->fifo0_descriptors_physical = 0;
+	camera_context->fifo1_descriptors_virtual = camera_context->fifo1_descriptors_physical = 0;
+	camera_context->fifo2_descriptors_virtual = camera_context->fifo2_descriptors_physical = 0;
+
+	// calculate how many descriptors are needed per frame
+	camera_context->fifo0_num_descriptors =
+		camera_context->pages_per_fifo0;
+
+	camera_context->fifo1_num_descriptors =
+		camera_context->pages_per_fifo1;
+
+	camera_context->fifo2_num_descriptors =
+		camera_context->pages_per_fifo2;
+
+	// check if enough memory to generate descriptors
+	if((camera_context->fifo0_num_descriptors + 
+        camera_context->fifo1_num_descriptors +
+		camera_context->fifo2_num_descriptors) * camera_context->block_number
+		> camera_context->dma_descriptors_size)
+    {
+		return -1;
+    }
+
+    dbg_print("1");
+	// generate fifo0 dma chains
+	camera_context->fifo0_descriptors_virtual  = (unsigned)camera_context->dma_descriptors_virtual;
+	camera_context->fifo0_descriptors_physical = (unsigned)camera_context->dma_descriptors_physical;
+    
+	cur_des_virtual  = (pxa_dma_desc *)camera_context->fifo0_descriptors_virtual;
+	cur_des_physical = (pxa_dma_desc *)camera_context->fifo0_descriptors_physical;
+
+	for(i=0; i<camera_context->block_number; i++) 
+    {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = camera_context->fifo0_transfer_size;
+
+		// assume the blocks are stored consecutively
+		target_page_num = camera_context->pages_per_block * i;
+
+		for(j=0; j<camera_context->fifo0_num_descriptors; j++)
+        {
+			// set descriptor
+		        if(remain_size > SINGLE_DESC_TRANS_MAX)
+        			des_transfer_size = SINGLE_DESC_TRANS_MAX;
+        		else
+		       		des_transfer_size = remain_size;
+                    
+		        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+        		cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
+        		cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        		cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+		        // advance pointers
+        		remain_size -= des_transfer_size;
+        		cur_des_virtual++;
+		        cur_des_physical++;
+			    target_page_num++;
+		}
+
+		// stop the dma transfer on one frame captured
+		last_des_virtual = cur_des_virtual - 1;
+	}
+
+	last_des_virtual->ddadr = ((unsigned)camera_context->fifo0_descriptors_physical);
+
+	// generate fifo1 dma chains
+	if(camera_context->fifo1_transfer_size) 
+    {
+		// record fifo1 descriptors' start address
+		camera_context->fifo1_descriptors_virtual = (unsigned)cur_des_virtual;
+		camera_context->fifo1_descriptors_physical = (unsigned)cur_des_physical;
+
+		for(i=0; i<camera_context->block_number; i++) 
+        {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = camera_context->fifo1_transfer_size;
+
+			target_page_num = camera_context->pages_per_block * i +
+				              camera_context->pages_per_fifo0;
+
+        		for(j=0; j<camera_context->fifo1_num_descriptors; j++)
+                {
+        		        // set descriptor
+        		    if(remain_size > SINGLE_DESC_TRANS_MAX)
+        		        des_transfer_size = SINGLE_DESC_TRANS_MAX;
+        		    else
+        		        des_transfer_size = remain_size;
+                            
+        	        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+        	        cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
+        	        cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        	        cur_des_virtual->dcmd  = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+       		        // advance pointers
+       		        remain_size -= des_transfer_size;
+       		        cur_des_virtual++;
+       		        cur_des_physical++;
+ 	      		    target_page_num++;
+       			}
+
+        		// stop the dma transfer on one frame captured
+        		last_des_virtual = cur_des_virtual - 1;
+		}
+		last_des_virtual->ddadr = ((unsigned)camera_context->fifo1_descriptors_physical);
+	}
+
+	// generate fifo2 dma chains
+	if(camera_context->fifo2_transfer_size) 
+    {
+		// record fifo1 descriptors' start address
+		camera_context->fifo2_descriptors_virtual = (unsigned)cur_des_virtual;
+		camera_context->fifo2_descriptors_physical = (unsigned)cur_des_physical;
+
+		for(i=0; i<camera_context->block_number; i++) 
+        {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = camera_context->fifo2_transfer_size;
+
+			target_page_num = camera_context->pages_per_block * i +
+				              camera_context->pages_per_fifo0 +
+		                  	  camera_context->pages_per_fifo1;
+
+	        for(j=0; j<camera_context->fifo2_num_descriptors; j++) 
+            {
+                		// set descriptor
+              		if(remain_size > SINGLE_DESC_TRANS_MAX)
+               			des_transfer_size = SINGLE_DESC_TRANS_MAX;
+               		else
+               			des_transfer_size = remain_size;
+               		cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
+               		cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
+               		cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+               		cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+               		// advance pointers
+               		remain_size -= des_transfer_size;
+               		cur_des_virtual++;
+               		cur_des_physical++;
+ 			        target_page_num++;
+	        }
+
+	        // stop the dma transfer on one frame captured
+       		last_des_virtual = cur_des_virtual - 1;
+       	}
+		last_des_virtual->ddadr = ((unsigned)camera_context->fifo2_descriptors_physical);
+	}
+    
+    dbg_print(" success!");
+	return 0;  
+}
+
+void start_dma_transfer(p_camera_context_t camera_context, unsigned block_id)
+{
+	pxa_dma_desc *des_virtual, *des_physical;
+    
+	if(block_id >= camera_context->block_number)
+    {
+       	return;
+    }
+        
+	// start channel 0
+	des_virtual = (pxa_dma_desc *)camera_context->fifo0_descriptors_virtual +
+		           block_id * camera_context->fifo0_num_descriptors;
+
+	des_physical = (pxa_dma_desc *)camera_context->fifo0_descriptors_physical +
+		           block_id * camera_context->fifo0_num_descriptors;
+
+    DDADR(camera_context->dma_channels[0]) = des_physical;
+    DCSR(camera_context->dma_channels[0]) |= DCSR_RUN;
+
+	// start channel 1
+	if(camera_context->fifo1_descriptors_virtual) 
+    {
+		des_virtual = (pxa_dma_desc *)camera_context->fifo1_descriptors_virtual + 
+			           block_id * camera_context->fifo1_num_descriptors;
+
+		des_physical = (pxa_dma_desc *)camera_context->fifo1_descriptors_physical + 
+			           block_id * camera_context->fifo1_num_descriptors;
+
+        DDADR(camera_context->dma_channels[1]) = des_physical;
+        DCSR(camera_context->dma_channels[1]) |= DCSR_RUN;
+	}
+
+	// start channel 2
+	if(camera_context->fifo2_descriptors_virtual) 
+    {
+		des_virtual = (pxa_dma_desc *)camera_context->fifo2_descriptors_virtual + 
+			           block_id * camera_context->fifo2_num_descriptors;
+
+		des_physical = (pxa_dma_desc *)camera_context->fifo2_descriptors_physical + 
+			           block_id * camera_context->fifo2_num_descriptors;
+
+        DDADR(camera_context->dma_channels[2]) = des_physical;
+        DCSR(camera_context->dma_channels[2]) |= DCSR_RUN;
+	}
+
+	camera_context->dma_started = 1;
+}
+
+void stop_dma_transfer(p_camera_context_t camera_context)
+{	
+    int ch0, ch1, ch2;
+
+    ch0 = camera_context->dma_channels[0];
+    ch1 = camera_context->dma_channels[1];
+    ch2 = camera_context->dma_channels[2];
+
+    DCSR(ch0) &= ~DCSR_RUN;
+    DCSR(ch1) &= ~DCSR_RUN;
+    DCSR(ch2) &= ~DCSR_RUN;
+	camera_context->dma_started = 0;
+
+    return;
+}
+
+int start_capture(p_camera_context_t camera_context, unsigned int block_id, unsigned int frames)
+{
+	int   status;
+	//clear ci fifo
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+
+    //start dma
+//	start_dma_transfer(camera_context, block_id);
+    
+    
+	// start capture
+	status = camera_context->camera_functions->start_capture(camera_context, frames);
+	
+	ci_enable(1);
+	
+	if(frames == 1) //Wait 2 frames to begin capture photo
+	{
+   	  waitingFrame = 2;
+	} 
+	else
+	{ 
+	   waitingFrame = 1;
+	}
+	while(waitingFrame--)
+	{
+	    CISR|=(1<<3);
+	    while(!(CISR&(1<<3))); //Wait a EOF then begin start DMA
+	}
+	ci_reset_fifo();
+	start_dma_transfer(camera_context, block_id);
+	return status;
+}
+
+/***********************************************************************
+ *
+ * Init/Deinit APIs
+ *
+ ***********************************************************************/
+int camera_init(p_camera_context_t camera_context)
+{
+	int ret=0;
+    int i;
+    dbg_print("0"); 
+#ifdef DEBUG
+    // parameter check
+    if(camera_context->buffer_virtual == NULL  || 
+        camera_context->buf_size == 0)
+    {
+        dbg_print("camera_context->buffer wrong!");    
+        return STATUS_WRONG_PARAMETER; 
+    }
+
+    if(camera_context->dma_descriptors_virtual == NULL  || 
+        camera_context->dma_descriptors_physical == NULL || 
+        camera_context->dma_descriptors_size == 0)
+    {
+        dbg_print("camera_context->dma_descriptors wrong!");    
+        return STATUS_WRONG_PARAMETER; 
+    }
+
+    if(camera_context->sensor_type > CAMERA_TYPE_MAX)
+    {
+        dbg_print("camera_context->sensor type wrong!");     
+        return STATUS_WRONG_PARAMETER; 
+    }
+
+    if(camera_context->capture_input_format > CAMERA_IMAGE_FORMAT_MAX ||
+        camera_context->capture_output_format > CAMERA_IMAGE_FORMAT_MAX)
+    {
+        dbg_print("camera_context->capture format wrong!");    
+        return STATUS_WRONG_PARAMETER; 
+    }
+
+    // check the function dispatch table according to the sensor type
+    if(!camera_context->camera_functions )
+    {
+        dbg_print("camera_context->camera_functions wrong!");    
+        return STATUS_WRONG_PARAMETER;
+    }
+
+    if( !camera_context->camera_functions->init || 	
+        !camera_context->camera_functions->deinit ||
+        !camera_context->camera_functions->set_capture_format ||
+        !camera_context->camera_functions->start_capture ||
+        !camera_context->camera_functions->stop_capture )     	
+    {
+        return STATUS_WRONG_PARAMETER;
+    }
+#endif
+    dbg_print("");
+    // init context status
+    for(i=0; i<3; i++)
+    {
+        camera_context->dma_channels[i] = 0xFF;
+    }
+
+    (int)camera_context->fifo0_descriptors_virtual = NULL;
+    (int)camera_context->fifo1_descriptors_virtual = NULL;
+    (int)camera_context->fifo2_descriptors_virtual = NULL;
+    (int)camera_context->fifo0_descriptors_physical = NULL;
+    (int)camera_context->fifo1_descriptors_physical = NULL;
+    (int)camera_context->fifo2_descriptors_physical = NULL;
+
+    camera_context->fifo0_num_descriptors = 0;
+    camera_context->fifo1_num_descriptors = 0;
+    camera_context->fifo2_num_descriptors = 0;
+
+    camera_context->fifo0_transfer_size = 0;
+    camera_context->fifo1_transfer_size = 0;
+    camera_context->fifo2_transfer_size = 0;
+
+    camera_context->block_number = 0;
+    camera_context->block_size = 0;
+    camera_context->block_header = 0;
+    camera_context->block_tail = 0;
+
+    // Enable hardware
+    camera_gpio_init();
+
+    // capture interface init
+    ci_init();
+  
+
+    // sensor init
+    if(camera_context->camera_functions->init(camera_context))
+    {
+        dbg_print("camera function init error!!");
+        goto camera_init_err;
+    }
+
+    camera_context->dma_channels[0] = ci_dma_y;
+    camera_context->dma_channels[1] = ci_dma_cb;
+    camera_context->dma_channels[2] = ci_dma_cr;
+    DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+    DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+    DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;	
+	ret = camera_set_capture_format(camera_context);
+	if(ret)
+	{
+		dbg_print("camera function init error!!");
+		goto camera_init_err;
+   }
+   
+#ifdef DEBUG
+	ci_dump();
+#endif
+    
+    ci_disable(1);
+    return 0;
+
+camera_init_err:
+    camera_deinit(camera_context);
+    return -1; 
+}
+
+void camera_gpio_init()
+{
+#ifdef CONFIG_CAMERA_OV9640
+	set_GPIO_mode(  50 | GPIO_OUT );        /*CIF_PD*/
+	set_GPIO_mode(  19 | GPIO_OUT );        /*CIF_RST*/
+        set_GPIO_mode(  27 | GPIO_ALT_FN_3_IN); /* CIF_DD[0] */
+        set_GPIO_mode( 114 | GPIO_ALT_FN_1_IN); /* CIF_DD[1] */
+        set_GPIO_mode(  51 | GPIO_ALT_FN_1_IN); /* CIF_DD[2] */
+        set_GPIO_mode(  115| GPIO_ALT_FN_2_IN); /* CIF_DD[3] */
+        set_GPIO_mode(  95 | GPIO_ALT_FN_2_IN); /* CIF_DD[4] */
+        set_GPIO_mode(  94 | GPIO_ALT_FN_2_IN); /* CIF_DD[5] */
+        set_GPIO_mode(  17 | GPIO_ALT_FN_2_IN); /* CIF_DD[6] */
+        set_GPIO_mode( 108 | GPIO_ALT_FN_1_IN); /* CIF_DD[7] */
+//      set_GPIO_mode( 107 | GPIO_ALT_FN_1_IN); /* CIF_DD[8] */
+//      set_GPIO_mode( 106 | GPIO_ALT_FN_1_IN); /* CIF_DD[9] */
+        set_GPIO_mode(  23 | GPIO_ALT_FN_1_OUT); /* CIF_MCLK */
+        set_GPIO_mode(  54 | GPIO_ALT_FN_3_IN);  /* CIF_PCLK */
+        set_GPIO_mode(  85 | GPIO_ALT_FN_3_IN);  /* CIF_LV */
+        set_GPIO_mode(  84 | GPIO_ALT_FN_3_IN);  /* CIF_FV */
+
+#endif
+
+#ifdef CONFIG_CAMERA_MT9M111
+     set_GPIO_mode(  CIF_PD_MD );         /*CIF_PD*/
+     GPCR(CIF_PD)  = GPIO_bit(CIF_PD);    /*set to low*/
+     set_GPIO_mode(  CIF_RST_MD );        /*CIF_RST*/
+     GPSR(CIF_RST) = GPIO_bit(CIF_RST);   /*set to high*/
+    set_GPIO_mode( CIF_DD0_MD );  /* CIF_DD[0] */
+    set_GPIO_mode( CIF_DD1_MD );  /* CIF_DD[1] */
+    set_GPIO_mode( CIF_DD2_MD );  /* CIF_DD[2] */
+    set_GPIO_mode( CIF_DD3_MD );  /* CIF_DD[3] */
+    set_GPIO_mode( CIF_DD4_MD );  /* CIF_DD[4] */
+    set_GPIO_mode( CIF_DD5_MD );  /* CIF_DD[5] */
+    set_GPIO_mode( CIF_DD6_MD );  /* CIF_DD[6] */
+    set_GPIO_mode( CIF_DD7_MD );  /* CIF_DD[7] */   
+    set_GPIO_mode( CIF_MCLK_MD ); /* CIF_MCLK  */
+    set_GPIO_mode( CIF_PCLK_MD ); /* CIF_PCLK  */
+    set_GPIO_mode( CIF_LV_MD );   /* CIF_LV    */
+    set_GPIO_mode( CIF_FV_MD );   /* CIF_FV    */
+#endif
+
+
+    return;
+}   
+
+
+void camera_gpio_deinit()
+{
+
+ #ifdef CONFIG_CAMERA_MT9M111
+    /* Turn off M_VCC  CIF_PD*/
+    GPSR(CIF_PD) = GPIO_bit(CIF_PD);   /* Set PD to low */
+
+    set_GPIO_mode( CIF_MCLK | GPIO_IN); /*trun off MCLK*/      
+ #endif
+}
+
+int camera_deinit( p_camera_context_t camera_context )
+{
+
+	// free dma channel
+	/*
+	for(i=0; i<3; i++)
+    {
+		if(camera_context->dma_channels[i] != 0x00) 
+        {
+			pxa_free_dma(camera_context->dma_channels[i]);   
+			camera_context->dma_channels[i] = 0;
+		}
+     }
+     */
+
+	// deinit sensor
+	 camera_context->camera_functions->deinit(camera_context);  
+	
+	// capture interface deinit
+	ci_deinit();
+	camera_gpio_deinit();
+	return 0;
+}
+
+int camera_ring_buf_init(p_camera_context_t camera_context)
+{
+    dbg_print("");    
+	unsigned         frame_size;
+    switch(camera_context->capture_output_format)
+    {
+    case CAMERA_IMAGE_FORMAT_RGB565:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 2;
+        camera_context->fifo0_transfer_size = frame_size / 2;
+        camera_context->fifo1_transfer_size = frame_size / 4;
+        camera_context->fifo2_transfer_size = frame_size / 4;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB666_PLANAR:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 4;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    case CAMERA_IMAGE_FORMAT_RGB666_PACKED:
+        frame_size = camera_context->capture_width * camera_context->capture_height * 3;
+        camera_context->fifo0_transfer_size = frame_size;
+        camera_context->fifo1_transfer_size = 0;
+        camera_context->fifo2_transfer_size = 0;
+        break;
+    default:
+        return STATUS_WRONG_PARAMETER;
+        break;
+    }
+
+    camera_context->block_size = frame_size;
+
+	camera_context->pages_per_fifo0 =
+		(PAGE_ALIGN(camera_context->fifo0_transfer_size) / PAGE_SIZE);
+	camera_context->pages_per_fifo1 =
+		(PAGE_ALIGN(camera_context->fifo1_transfer_size) / PAGE_SIZE);
+	camera_context->pages_per_fifo2 =
+		(PAGE_ALIGN(camera_context->fifo2_transfer_size) / PAGE_SIZE);
+
+	camera_context->pages_per_block =
+		camera_context->pages_per_fifo0 +
+		camera_context->pages_per_fifo1 +
+		camera_context->pages_per_fifo2;
+
+	camera_context->page_aligned_block_size =
+		camera_context->pages_per_block * PAGE_SIZE;
+
+	camera_context->block_number_max =
+		camera_context->pages_allocated /
+		camera_context->pages_per_block;
+
+
+    //restrict max block number 
+    if(camera_context->block_number_max > FRAMES_IN_BUFFER)
+    {
+		camera_context->block_number = FRAMES_IN_BUFFER;
+    }
+    else
+    {
+		camera_context->block_number = camera_context->block_number_max;
+    }
+    
+	camera_context->block_header = camera_context->block_tail = 0;
+
+	// generate dma descriptor chain
+	return update_dma_chain(camera_context);
+
+}
+/***********************************************************************
+ *
+ * Capture APIs
+ *
+ ***********************************************************************/
+// Set the image format
+int camera_set_capture_format(p_camera_context_t camera_context)
+{
+
+	CI_IMAGE_FORMAT  ci_input_format, ci_output_format;
+	CI_MP_TIMING     timing;
+
+	if(camera_context->capture_input_format >  CAMERA_IMAGE_FORMAT_MAX ||
+	   camera_context->capture_output_format > CAMERA_IMAGE_FORMAT_MAX )
+    {
+		return STATUS_WRONG_PARAMETER;
+    }
+
+	ci_input_format  = FORMAT_MAPPINGS[camera_context->capture_input_format];
+	ci_output_format = FORMAT_MAPPINGS[camera_context->capture_output_format];
+    
+	if(ci_input_format == CI_INVALID_FORMAT || ci_output_format == CI_INVALID_FORMAT)
+    {
+	  return STATUS_WRONG_PARAMETER;
+    }
+    
+	ci_set_image_format(ci_input_format, ci_output_format);
+
+#ifdef CONFIG_CAMERA_MT9M111
+       timing.BFW = 0;
+       timing.BLW = 0;
+#endif
+#ifdef CONFIG_CAMERA_OV9640
+      timing.BFW =  0;
+      timing.BLW =  51*2;
+#endif
+
+    
+	ci_configure_mp(camera_context->capture_width-1, camera_context->capture_height-1, &timing);
+
+	if(camera_context == NULL || camera_context->camera_functions == NULL || 
+	   camera_context->camera_functions->set_capture_format == NULL)
+	{
+	  dbg_print("camera_context point NULL!!!");
+	  return -1;
+	} 
+	// set sensor setting
+	if(camera_context->camera_functions->set_capture_format(camera_context))
+    {
+ 	   return -1;
+    }
+   
+    // ring buffer init
+    return  camera_ring_buf_init(camera_context);
+    
+}
+
+// take a picture and copy it into the ring buffer
+int camera_capture_still_image(p_camera_context_t camera_context, unsigned int block_id)
+{
+	// init buffer status & capture
+    camera_set_int_mask(camera_context, 0x3ff | 0x0400);
+    still_image_mode = 1;
+    first_video_frame = 0;
+	camera_context->block_header   = camera_context->block_tail = block_id;  
+	camera_context->capture_status = 0;
+	return  start_capture(camera_context, block_id, 1);
+}
+
+// capture motion video and copy it to the ring buffer
+int camera_start_video_capture( p_camera_context_t camera_context, unsigned int block_id )
+{
+	//init buffer status & capture
+    camera_set_int_mask(camera_context, 0x3ff | 0x0400);
+    still_image_mode = 0;
+    first_video_frame = 1;
+	camera_context->block_header   = camera_context->block_tail = block_id; 
+	camera_context->capture_status = CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+	return start_capture(camera_context, block_id, 0);
+}
+
+// disable motion video image capture
+void camera_stop_video_capture( p_camera_context_t camera_context )
+{
+	//stop capture
+	camera_context->camera_functions->stop_capture(camera_context);
+
+	//stop dma
+	stop_dma_transfer(camera_context);
+    
+	//update the flag
+	if(!(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+		camera_context->capture_status &= ~CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+    }
+
+	ci_disable(1);
+}
+
+
+/***********************************************************************
+ *
+ * Flow Control APIs
+ *
+ ***********************************************************************/
+// continue capture image to next available buffer
+void camera_continue_transfer( p_camera_context_t camera_context )
+{
+	// don't think we need this either.  JR
+	// continue transfer on next block
+	start_dma_transfer( camera_context, camera_context->block_tail );
+}
+
+// Return 1: there is available buffer, 0: buffer is full
+int camera_next_buffer_available( p_camera_context_t camera_context )
+{
+	camera_context->block_header = (camera_context->block_header + 1) % camera_context->block_number;
+	if(((camera_context->block_header + 1) % camera_context->block_number) != camera_context->block_tail)
+	{
+		return 1;
+	}
+
+	camera_context->capture_status |= CAMERA_STATUS_RING_BUFFER_FULL;
+	return 0;
+}
+
+// Application supplies the FrameBufferID to the driver to tell it that the application has completed processing of 
+// the given frame buffer, and that buffer is now available for re-use.
+void camera_release_frame_buffer(p_camera_context_t camera_context, unsigned int frame_buffer_id)
+{
+
+	camera_context->block_tail = (camera_context->block_tail + 1) % camera_context->block_number;
+
+	// restart video capture only ifvideo capture is in progress and space is available for image capture
+	if((camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL ) && 
+	   (camera_context->capture_status & CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS))
+	{
+		if(((camera_context->block_header + 2) % camera_context->block_number) != camera_context->block_tail)
+		{
+			camera_context->capture_status &= ~CAMERA_STATUS_RING_BUFFER_FULL;
+			start_capture(camera_context, camera_context->block_tail, 0);
+		}
+	}
+}
+
+// Returns the FrameBufferID for the first filled frame
+// Note: -1 represents buffer empty
+int camera_get_first_frame_buffer_id(p_camera_context_t camera_context)
+{
+	// not sure ifthis routine makes any sense.. JR
+
+	// check whether buffer is empty
+	if((camera_context->block_header == camera_context->block_tail) && 
+		 !(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+	    return -1;
+    }
+
+	// return the block header
+	return camera_context->block_header;
+}
+
+// Returns the FrameBufferID for the last filled frame, this would be used ifwe were polling for image completion data, 
+// or we wanted to make sure there were no frames waiting for us to process.
+// Note: -1 represents buffer empty
+int camera_get_last_frame_buffer_id(p_camera_context_t camera_context)
+{
+
+	// check whether buffer is empty
+	if((camera_context->block_header == camera_context->block_tail) && 
+	     !(camera_context->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+    {
+		return -1;
+    }
+
+	// return the block before the block_tail
+	return (camera_context->block_tail + camera_context->block_number - 1) % camera_context->block_number;
+}
+
+
+/***********************************************************************
+ *
+ * Buffer Info APIs
+ *
+ ***********************************************************************/
+// Return: the number of frame buffers allocated for use.
+unsigned int camera_get_num_frame_buffers(p_camera_context_t camera_context)
+{
+	return camera_context->block_number;
+}
+
+// FrameBufferID is a number between 0 and N-1, where N is the total number of frame buffers in use.  Returns the address of
+// the given frame buffer.  The application will call this once for each frame buffer at application initialization only.
+void * camera_get_frame_buffer_addr(p_camera_context_t camera_context, unsigned int frame_buffer_id)
+{
+	return (void*)((unsigned)camera_context->buffer_virtual +
+		 camera_context->page_aligned_block_size * frame_buffer_id);
+}
+
+// Return the block id
+int camera_get_frame_buffer_id(p_camera_context_t camera_context, void* address)
+{
+	if(((unsigned)address >= (unsigned)camera_context->buffer_virtual) && 
+	   ((unsigned)address <= (unsigned)camera_context->buffer_virtual + camera_context->buf_size))
+    {
+		return ((unsigned)address - 
+                (unsigned)camera_context->buffer_virtual) / 
+                camera_context->page_aligned_block_size;
+    }
+
+	return -1;
+}
+
+
+/***********************************************************************
+ *
+ * Frame rate APIs
+ *
+ ***********************************************************************/
+// Set desired frame rate
+void camera_set_capture_frame_rate(p_camera_context_t camera_context)
+{
+	ci_set_frame_rate(camera_context->fps);
+} 
+
+// return current setting
+void camera_get_capture_frame_rate(p_camera_context_t camera_context)
+{
+	camera_context->fps = ci_get_frame_rate();
+} 
+
+
+/***********************************************************************
+ *
+ * Interrupt APIs
+ *
+ ***********************************************************************/
+// set interrupt mask 
+void camera_set_int_mask(p_camera_context_t cam_ctx, unsigned int mask)
+{
+	pxa_dma_desc * end_des_virtual;
+	int dma_interrupt_on, i;
+
+	// set CI interrupt
+	ci_set_int_mask( mask & CI_CICR0_INTERRUPT_MASK );
+
+	// set dma end interrupt
+	if( mask & CAMERA_INTMASK_END_OF_DMA )
+		dma_interrupt_on = 1;
+	else
+		dma_interrupt_on = 0;
+
+	// set fifo0 dma chains' flag
+	end_des_virtual = (pxa_dma_desc*)cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+
+    for(i=0; i<cam_ctx->block_number; i++) 
+    {
+        if(dma_interrupt_on)
+            end_des_virtual->dcmd |= DCMD_ENDIRQEN;
+        else
+            end_des_virtual->dcmd &= ~DCMD_ENDIRQEN;
+
+        end_des_virtual += cam_ctx->fifo0_num_descriptors;
+    }
+}
+ 
+// get interrupt mask 
+unsigned int camera_get_int_mask(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *end_des_virtual;
+	unsigned int ret;
+
+	// get CI mask
+	ret = ci_get_int_mask();
+	
+	// get dma end mask
+	end_des_virtual = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+
+	if(end_des_virtual->dcmd & DCMD_ENDIRQEN)
+    {
+		ret |= CAMERA_INTMASK_END_OF_DMA;
+    }
+	return ret;   
+} 
+
+// clear interrupt status
+void camera_clear_int_status( p_camera_context_t camera_context, unsigned int status )
+{
+	ci_clear_int_status( (status & 0xFFFF) );   
+}
+
+/***********************************************************************************
+* Application interface 							   *
+***********************************************************************************/
+static int pxa_camera_open(struct video_device *dev, int flags)
+{
+    dbg_print("start...");
+    camera_context_t *cam_ctx;
+
+   init_waitqueue_head(&camera_wait_q);
+   
+   if(pxa_camera_mem_init())
+    {
+      dbg_print("DMA memory allocate failed!");
+      return -1;
+    }
+
+
+  cam_ctx = g_camera_context;
+
+#ifdef CONFIG_CAMERA_MT9M111
+    cam_ctx->sensor_type    = CAMERA_TYPE_MT9M111;
+    cam_ctx->capture_width  = WIDTH_DEFT;
+    cam_ctx->capture_height = HEIGHT_DEFT;
+    cam_ctx->camera_functions = &mt9m111_func;
+#endif
+#ifdef CONFIG_CAMERA_OV9640
+    cam_ctx->sensor_type = CAMERA_TYPE_OMNIVISION_9640;
+    cam_ctx->capture_width =  320;
+    cam_ctx->capture_height = 240;
+    cam_ctx->camera_functions = &ov9640_func;
+#endif
+
+    cam_ctx->capture_input_format  = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+    cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+
+    cam_ctx->fps = FRAMERATE_DEFT;
+
+//    cam_ctx->ost_reg_base   = 0;
+//    cam_ctx->gpio_reg_base  = 0;
+//    cam_ctx->ci_reg_base    = 0;
+//    cam_ctx->board_reg_base = 0;
+    
+    if(cam_ctx->dma_descriptors_virtual == NULL)
+    {
+      dbg_print("descriptors virtual memory not allocated!");
+      return -1;
+    }
+     
+    if(cam_ctx->buffer_virtual == NULL)
+    {
+      dbg_print("buffer virtual memory not allocated!");
+      return -1;
+    }
+
+    cam_ctx->ost_reg_base   = 0;
+    cam_ctx->gpio_reg_base  = 0;
+    cam_ctx->ci_reg_base    = 0;
+    cam_ctx->board_reg_base = 0;
+
+       
+    if(camera_init(cam_ctx))
+    {
+       dbg_print("camera_init faile!");
+       return -1;
+    }
+
+    dbg_print("PXA_CAMERA: pxa_camera_open success!");
+    return 0;
+}
+
+static void pxa_camera_close(struct video_device *dev)
+{
+    camera_deinit(g_camera_context);
+    pxa_camera_mem_deinit();
+    dbg_print("PXA_CAMERA: pxa_camera_close\n");
+}
+
+#define PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, size) \
+do { \
+	unsigned int len; \
+	unsigned int remain_size = size; \
+	while (remain_size > 0) { \
+		if(remain_size > PAGE_SIZE) \
+			len = PAGE_SIZE; \
+		else \
+			len = remain_size; \
+		if(copy_to_user(buf, page_address(*p_page), len)) \
+			return -EFAULT; \
+		remain_size -= len; \
+		buf += len; \
+		p_page++; \
+	} \
+} while (0);
+
+
+static long pxa_camera_read(struct video_device *dev, 
+                            char   *buf,
+                            unsigned long count, 
+                            int noblock)
+{
+
+	struct page **p_page;
+
+	camera_context_t *cam_ctx = g_camera_context;
+
+	if(still_image_mode == 1 && still_image_rdy == 1) 
+    {
+		p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+                
+		still_image_rdy = 0;
+		return cam_ctx->block_size;
+	}
+
+	if(still_image_mode == 0)
+	{
+		if(first_video_frame == 1)
+			cam_ctx->block_tail = cam_ctx->block_header;
+		else
+			cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+	}
+
+	first_video_frame = 0;
+
+	if(cam_ctx->block_header == cam_ctx->block_tail)  
+    {
+		task_waiting = 1;
+		interruptible_sleep_on (&camera_wait_q);
+	}
+
+	p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+
+	return cam_ctx->block_size;
+}
+
+struct reg_set_s 
+{
+	int  val1;
+	int  val2;
+};
+
+/*ioctl sub functions*/
+static int pxa_camera_VIDIOCGCAP(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_capability vc;
+    dbg_print("VIDIOCGCAP");
+    strcpy (vc.name, "Micron MT9M111");
+    vc.maxwidth  = MAX_WIDTH;
+    vc.maxheight = MAX_HEIGHT;
+    vc.minwidth  = MIN_WIDTH; 
+    vc.minheight = MIN_HEIGHT;
+    if(copy_to_user(param, &vc, sizeof(struct video_capability)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_VIDIOCGWIN(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_window vw;
+    dbg_print("VIDIOCGWIN");
+    vw.width  = cam_ctx->capture_width;
+    vw.height = cam_ctx->capture_height;
+    if(copy_to_user(param, &vw, sizeof(struct video_window)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_VIDIOCSWIN(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_window vw;
+    dbg_print("VIDIOCSWIN");
+    if(copy_from_user(&vw, param, sizeof(vw))) 
+    {
+        dbg_print("VIDIOCSWIN get parameter error!");
+        return  -EFAULT;
+    }
+    if(vw.width > MAX_WIDTH || vw.height > MAX_HEIGHT || vw.width < MIN_WIDTH || vw.height < MIN_HEIGHT) 
+    {
+        dbg_print("VIDIOCSWIN error parameter!");
+        dbg_print("vw.width:%d, MAX_WIDTH:%d, MIN_WIDTH:%d", vw.width, MAX_WIDTH, MIN_WIDTH);
+        dbg_print("vw.height:%d, MAX_HEIGHT:%d, MIN_HEIGHT:%d", vw.width, MAX_HEIGHT, MIN_HEIGHT);	
+        return  -EFAULT;
+    }
+    cam_ctx->capture_width  = vw.width;
+    //make it in an even 
+    cam_ctx->capture_width = (vw.width+1)/2;
+    cam_ctx->capture_width *= 2;
+
+    cam_ctx->capture_height = (vw.height+1)/2;
+    cam_ctx->capture_height *= 2;
+    
+    return camera_set_capture_format(cam_ctx);
+}
+static int pxa_camera_VIDIOCSPICT(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_picture vp;
+    dbg_print("VIDIOCSPICT");
+    if(copy_from_user(&vp, param, sizeof(vp))) 
+    {
+        return  -EFAULT;
+    }
+    cam_ctx->capture_output_format = vp.palette;
+
+    return  camera_set_capture_format(cam_ctx);
+    
+}
+
+static int pxa_camera_VIDIOCGPICT(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_picture vp;
+    dbg_print("VIDIOCGPICT");
+    vp.palette = cam_ctx->capture_output_format;
+    if(copy_to_user(param, &vp, sizeof(struct video_picture)))
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_VIDIOCCAPTURE(p_camera_context_t cam_ctx, void * param)
+{
+    int capture_flag = (int)param;
+    dbg_print("VIDIOCCAPTURE");
+    if(capture_flag > 0) 
+    {			
+        dbg_print("Still Image capture!");
+        camera_capture_still_image(cam_ctx, 0);
+    }
+    else if(capture_flag == 0) 
+    {
+        dbg_print("Video Image capture!");
+        camera_start_video_capture(cam_ctx, 0);
+    }
+    else if(capture_flag == -1) 
+    {
+        dbg_print("Capture stop!"); 
+        camera_set_int_mask(cam_ctx, 0x3ff);
+        camera_stop_video_capture(cam_ctx);
+    }
+    else 
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_VIDIOCGMBUF(p_camera_context_t cam_ctx, void * param)
+{
+    struct video_mbuf vm;
+    int i;
+
+    dbg_print("VIDIOCGMBUF");
+
+    memset(&vm, 0, sizeof(vm));
+    vm.size   = cam_ctx->buf_size;
+    vm.frames = cam_ctx->block_number;
+    for(i = 0; i < vm.frames; i++)
+    {
+        vm.offsets[i] = cam_ctx->page_aligned_block_size * i;
+    }
+    if(copy_to_user((void *)param, (void *)&vm, sizeof(vm)))
+    {
+        return  -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCSINFOR(p_camera_context_t cam_ctx, void * param)
+{
+
+    struct reg_set_s reg_s;
+    int ret;
+    dbg_print("WCAM_VIDIOCSINFOR");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+
+    cam_ctx->capture_input_format = reg_s.val1;
+    cam_ctx->capture_output_format = reg_s.val2;
+    ret=camera_set_capture_format(cam_ctx);
+    ci_dump();
+    return  ret;
+}
+static int pxa_camera_WCAM_VIDIOCGINFOR(p_camera_context_t cam_ctx, void * param)
+{
+
+    struct reg_set_s reg_s;
+    dbg_print("WCAM_VIDIOCGINFOR");
+    reg_s.val1 = cam_ctx->capture_input_format;
+    reg_s.val2 = cam_ctx->capture_output_format;
+    if(copy_to_user(param, &reg_s, sizeof(int) * 2)) 
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCGCIREG(p_camera_context_t cam_ctx, void * param)
+{
+
+    int reg_value, offset;
+    dbg_print("WCAM_VIDIOCGCIREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return  -EFAULT;
+
+    }
+    reg_value = ci_get_reg_value (offset);
+    if(copy_to_user(param, &reg_value, sizeof(int)))
+    {
+        return -EFAULT;
+    }
+    return 0;
+}
+
+static int pxa_camera_WCAM_VIDIOCSCIREG(p_camera_context_t cam_ctx, void * param)
+{
+
+    struct reg_set_s reg_s;
+    dbg_print("WCAM_VIDIOCSCIREG");
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    ci_set_reg_value (reg_s.val1, reg_s.val2);
+    return 0;
+
+}
+static int pxa_camera_WCAM_VIDIOCGCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    int reg_value, offset;
+    dbg_print("WCAM_VIDIOCGCAMREG");
+    if(copy_from_user(&offset, param, sizeof(int))) 
+    {
+        return -EFAULT;
+    }
+    reg_value = (int)mt9m111_reg_read((u16)offset);
+
+    if(copy_to_user(param, &reg_value, sizeof(int))) 
+    {
+        return -EFAULT;
+    } 
+
+    return 0;
+}
+static int pxa_camera_WCAM_VIDIOCSCAMREG(p_camera_context_t cam_ctx, void * param)
+{
+    struct reg_set_s reg_s;
+    dbg_print("WCAM_VIDIOCSCAMREG");
+
+    if(copy_from_user(&reg_s, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    mt9m111_reg_write((u16)reg_s.val1, (u16)reg_s.val2);
+    return 0;
+} 
+ 
+static int pxa_cam_WCAM_VIDIOCSFPS(p_camera_context_t cam_ctx, void * param)
+{
+    struct {int fps, minfps;} cam_fps;
+    dbg_print("WCAM_VIDIOCSFPS");
+    if(copy_from_user(&cam_fps, param, sizeof(int) * 2)) 
+    {
+        return  -EFAULT;
+    }
+    cam_ctx->fps = cam_fps.fps;
+    cam_ctx->mini_fps = cam_fps.minfps;
+    mt9m111_set_fps(cam_fps.fps, cam_fps.minfps);
+    return 0;
+}
+
+
+/*Set  sensor size*/  
+static int pxa_cam_WCAM_VIDIOCSSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+  micron_window_size size;
+  dbg_print("WCAM_VIDIOCSSSIZE");
+  
+  if(copy_from_user(&size, param, sizeof(micron_window_size))) 
+  {
+        return  -EFAULT;
+  }
+
+  size.width = (size.width+1)/2 * 2;
+  size.height = (size.height+1)/2 * 2;
+  cam_ctx->sensor_width = size.width;
+  cam_ctx->sensor_height = size.height;
+  mt9m111_input_size(&size);
+  return 0;
+}
+
+//set  output size
+static int pxa_cam_WCAM_VIDIOCSOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+   micron_window_size size;
+   CI_MP_TIMING     timing;
+   dbg_print("WCAM_VIDIOCSOSIZE");
+  
+   if(copy_from_user(&size, param, sizeof(micron_window_size))) 
+   {
+        return  -EFAULT;
+   }
+
+   //make it in an even number
+   size.width = (size.width+1)/2 * 2;
+   size.height = (size.height+1)/2 * 2;
+   mt9m111_output_size(&size);
+   
+   cam_ctx->capture_width  = size.width;
+   cam_ctx->capture_height = size.height;
+   timing.BFW = timing.BLW = 0;
+   
+   ci_configure_mp(cam_ctx->capture_width-1, cam_ctx->capture_height-1, &timing);
+   camera_ring_buf_init(cam_ctx);
+   
+   return 0;
+}
+    
+
+    
+/*get sensor size */
+static int pxa_cam_WCAM_VIDIOCGSSIZE(p_camera_context_t cam_ctx, void * param)
+{
+   micron_window_size size;
+   dbg_print("WCAM_VIDIOCGSSIZE");  
+   mt9m111_get_input_size(&size);
+   if(copy_to_user(param, &size, sizeof(micron_window_size)))
+   {
+       return -EFAULT;
+   }
+  return 0;
+}
+         
+/*get output size*/
+static int pxa_cam_WCAM_VIDIOCGOSIZE(p_camera_context_t cam_ctx, void * param)
+{
+    
+   micron_window_size size;
+   dbg_print("WCAM_VIDIOCGOSIZE");  
+   size.width  = cam_ctx->capture_width;
+   size.height = cam_ctx->capture_height;
+   if(copy_to_user(param, &size, sizeof(micron_window_size)))
+   {
+       return -EFAULT;
+   }
+   return 0;
+}
+
+/*set picture style*/  
+static int pxa_cam_WCAM_VIDIOCSSTYLE(p_camera_context_t cam_ctx, void * param)
+{
+  dbg_print("WCAM_VIDIOCSSTYLE");
+  cam_ctx->capture_style = (V4l_PIC_STYLE)param;
+  
+  if(cam_ctx->capture_style != V4l_STYLE_BLACK_WHITE  && cam_ctx->capture_style != V4l_STYLE_SEPIA)
+  {
+      mt9m111_set_light(cam_ctx->capture_light);
+  }
+  
+  return mt9m111_set_style(cam_ctx->capture_style);
+}
+
+        
+/*set picture light*/     
+static int pxa_cam_WCAM_VIDIOCSLIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   
+   dbg_print("WCAM_VIDIOCSLIGHT");
+   cam_ctx->capture_light = (V4l_PIC_WB)param;
+   if(cam_ctx->capture_style != V4l_STYLE_BLACK_WHITE && cam_ctx->capture_style != V4l_STYLE_SEPIA)
+   {
+     return  mt9m111_set_light((V4l_PIC_WB)param);
+   }
+   return 0;
+}
+    
+/*set picture brightness*/
+static int pxa_cam_WCAM_VIDIOCSBRIGHT(p_camera_context_t cam_ctx, void * param)
+{
+   dbg_print("WCAM_VIDIOCSBRIGHT");
+   cam_ctx->capture_bright = (int)param;
+   return  mt9m111_set_bright((int)param);
+}
+
+/*set frame buffer count*/
+static int pxa_cam_WCAM_VIDIOCSBUFCOUNT(p_camera_context_t cam_ctx, void * param)
+{
+//   dbg_print("");
+   int count;
+   if(copy_from_user(&count, param, sizeof(int)))
+   {
+     return -EFAULT;
+   }
+   
+   if(cam_ctx->block_number_max == 0)
+   {
+     dbg_print("windows size or format not setting!!");
+     return -EFAULT;
+   }
+   
+   if(count < FRAMES_IN_BUFFER)
+   {
+      count = FRAMES_IN_BUFFER;
+   }
+   
+   if(count > cam_ctx->block_number_max)
+   {
+      count = cam_ctx->block_number_max;
+   }
+      
+
+   cam_ctx->block_number = count;
+   cam_ctx->block_header = cam_ctx->block_tail = 0;
+   //generate dma descriptor chain
+   update_dma_chain(cam_ctx);
+     
+   if(copy_to_user(param, &count, sizeof(int)))
+   {
+     return -EFAULT;
+   }
+   
+   return 0;
+}
+         
+/*get cur avaliable frames*/     
+static int pxa_cam_WCAM_VIDIOCGCURFRMS(p_camera_context_t cam_ctx, void * param)
+{
+//  dbg_print("");
+  struct {int first, last;}pos;
+  pos.first = cam_ctx->block_tail;
+  pos.last  = cam_ctx->block_header;
+  
+  if(copy_to_user(param, &pos, sizeof(pos)))
+  {
+     return -EFAULT;
+  }
+  return 0;
+}
+
+static int pxa_camera_ioctl(struct video_device *dev, unsigned int cmd, void *param)
+{
+    //dbg_print ("mt9m111: ioctl cmd = %d\n",cmd);
+   	switch (cmd) 
+    {
+        /*get capture capability*/
+    case VIDIOCGCAP:
+        return pxa_camera_VIDIOCGCAP(g_camera_context, param);
+
+        /* get capture size */
+    case VIDIOCGWIN:
+        return  pxa_camera_VIDIOCGWIN(g_camera_context, param);
+
+        /* set capture size. */
+    case VIDIOCSWIN:
+        return pxa_camera_VIDIOCSWIN(g_camera_context, param);
+
+        /*set capture output format*/
+    case VIDIOCSPICT:
+        return pxa_camera_VIDIOCSPICT(g_camera_context, param);
+
+        /*get capture output format*/
+    case VIDIOCGPICT:
+        return pxa_camera_VIDIOCGPICT(g_camera_context, param);
+
+        /*start capture */
+    case VIDIOCCAPTURE:
+        return pxa_camera_VIDIOCCAPTURE(g_camera_context, param);
+
+        /* mmap interface */
+    case VIDIOCGMBUF:
+         return pxa_camera_VIDIOCGMBUF(g_camera_context, param);
+
+        /* Application extended IOCTL.  */
+        /* Register access interface	*/
+    case WCAM_VIDIOCSINFOR:
+         return pxa_camera_WCAM_VIDIOCSINFOR(g_camera_context, param);
+
+        /*get capture format*/
+    case WCAM_VIDIOCGINFOR:
+         return pxa_camera_WCAM_VIDIOCGINFOR(g_camera_context, param);
+
+        /*get ci reg value*/
+    case WCAM_VIDIOCGCIREG:
+        return pxa_camera_WCAM_VIDIOCGCIREG(g_camera_context, param);
+
+        /*set ci reg*/
+    case WCAM_VIDIOCSCIREG:
+        return pxa_camera_WCAM_VIDIOCSCIREG(g_camera_context, param);
+#ifdef CONFIG_CAMERA_MT9M111
+
+        /*read mt9m111 registers*/
+    case WCAM_VIDIOCGCAMREG:
+         return pxa_camera_WCAM_VIDIOCGCAMREG(g_camera_context, param);
+
+        /*write mt9m111 registers*/
+    case WCAM_VIDIOCSCAMREG:
+          return pxa_camera_WCAM_VIDIOCSCAMREG(g_camera_context, param);
+        
+        /*set sensor size */  
+    case WCAM_VIDIOCSSSIZE:
+         return pxa_cam_WCAM_VIDIOCSSSIZE(g_camera_context, param);
+    
+        /*get sensor size */  
+    case WCAM_VIDIOCGSSIZE:
+         return pxa_cam_WCAM_VIDIOCGSSIZE(g_camera_context, param);
+    
+        /*set output size*/
+    case WCAM_VIDIOCSOSIZE:
+         return pxa_cam_WCAM_VIDIOCSOSIZE(g_camera_context, param);
+         
+         /*get output size*/
+    case WCAM_VIDIOCGOSIZE:
+         return pxa_cam_WCAM_VIDIOCGOSIZE(g_camera_context, param);
+         
+         /*set video mode fps*/
+    case WCAM_VIDIOCSFPS:
+         return pxa_cam_WCAM_VIDIOCSFPS(g_camera_context, param);
+                  
+#endif
+    /*set picture style*/  
+    case WCAM_VIDIOCSSTYLE:
+         return pxa_cam_WCAM_VIDIOCSSTYLE(g_camera_context, param);
+         
+    /*set picture light*/     
+    case WCAM_VIDIOCSLIGHT:
+         return pxa_cam_WCAM_VIDIOCSLIGHT(g_camera_context, param);
+    
+    /*set picture brightness*/
+    case WCAM_VIDIOCSBRIGHT:
+         return pxa_cam_WCAM_VIDIOCSBRIGHT(g_camera_context, param);
+    /*set frame buffer count*/     
+    case WCAM_VIDIOCSBUFCOUNT:
+         return pxa_cam_WCAM_VIDIOCSBUFCOUNT(g_camera_context, param);
+         
+    /*get cur avaliable frames*/     
+    case WCAM_VIDIOCGCURFRMS:
+         return pxa_cam_WCAM_VIDIOCGCURFRMS(g_camera_context, param); 
+    default:
+        {
+            //dbg_print ("mt9m111: Invalid ioctl parameters.cmd = %d\n",cmd);
+            return -ENOIOCTLCMD;
+            break;
+        }
+    }
+	return 0;
+}
+
+static int pxa_camera_mmap(struct video_device *dev, const char *adr, unsigned long size)
+{
+   	unsigned long start = (unsigned long)adr;
+	camera_context_t *cam_ctx = g_camera_context;
+	struct page **p_page = cam_ctx->page_array;
+
+	size = PAGE_ALIGN(size);
+	while (size > 0) 
+    {
+		if(remap_page_range(start, page_to_phys(*p_page), PAGE_SIZE, PAGE_SHARED)) 
+        {
+			return -EFAULT;
+		}
+		start += PAGE_SIZE;
+		p_page++;
+		size -= PAGE_SIZE;
+	}
+	return 0;
+ }
+
+unsigned int pxa_camera_poll(struct video_device *dev, struct file *file, poll_table *wait) 
+{
+    camera_context_t *cam_ctx = g_camera_context;
+	static int waited = 0;
+
+	poll_wait(file, &camera_wait_q, wait);
+
+	if(still_image_mode == 1 && still_image_rdy == 1) 
+    {
+		still_image_rdy = 0;
+		waited = 0;
+		return POLLIN | POLLRDNORM;
+	}
+    
+	if(first_video_frame == 1)
+		first_video_frame = 0;
+	else if(still_image_mode == 0 && waited != 1)
+		cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+
+	if(cam_ctx->block_header == cam_ctx->block_tail)  
+    {
+		//dbg_print ("enter waiting, tail = %d, header = %d \n", cam_ctx->block_tail, cam_ctx->block_header);
+		task_waiting = 1;
+		waited = 1;
+		//interruptible_sleep_on (&camera_wait_q);
+		return 0;
+	}
+	else 
+    {
+      waited = 0;
+    }
+
+	return POLLIN | POLLRDNORM;
+}
+
+int pxa_camera_mem_deinit()
+{
+    if(g_camera_context)
+    {
+        if(g_camera_context->dma_descriptors_virtual != NULL) 
+        {
+         consistent_free(g_camera_context->dma_descriptors_virtual, 
+                         MAX_DESC_NUM * sizeof(pxa_dma_desc),  
+                         (int)g_camera_context->dma_descriptors_physical);
+		      
+          g_camera_context->dma_descriptors_virtual = NULL;
+
+        }
+       if(g_camera_context->buffer_virtual != NULL)  
+       {
+        pxa_dma_buffer_free(g_camera_context);		     
+        g_camera_context->buffer_virtual = NULL;
+       }
+       kfree(g_camera_context);
+       g_camera_context = NULL;
+    }
+    
+    return 0;
+}
+
+int pxa_camera_mem_init()
+{
+   g_camera_context = kmalloc(sizeof(struct camera_context_s), GFP_KERNEL);
+
+    if(g_camera_context == NULL)
+    {
+    	dbg_print( "PXA_CAMERA: Cann't allocate buffer for camera control structure \n");
+        return -1;
+    }
+	
+    memset(g_camera_context, 0, sizeof(struct camera_context_s));
+    
+	g_camera_context->dma_started = 0;
+    g_camera_context->dma_descriptors_virtual = consistent_alloc(GFP_KERNEL, MAX_DESC_NUM * sizeof(pxa_dma_desc),
+                                                                 (void *)&(g_camera_context->dma_descriptors_physical));
+    if(g_camera_context->dma_descriptors_virtual == NULL)
+    {
+      dbg_print("consistent alloc memory for dma_descriptors_virtual fail!");
+      goto  err_init;
+    }
+    
+    g_camera_context->buf_size             = BUF_SIZE_DEFT;
+    g_camera_context->dma_descriptors_size = MAX_DESC_NUM;
+
+    
+    if(pxa_dma_buffer_init(g_camera_context) != 0)
+    {
+      dbg_print("alloc memory for buffer_virtual  %d bytes fail!", g_camera_context->buf_size);
+      goto  err_init;
+    }
+#ifdef CONFIG_CAMERA_MT9M111
+     // init function dispatch table
+   mt9m111_func.init = camera_func_mt9m111_init;
+   mt9m111_func.deinit = camera_func_mt9m111_deinit;
+   mt9m111_func.set_capture_format = camera_func_mt9m111_set_capture_format;
+   mt9m111_func.start_capture = camera_func_mt9m111_start_capture;
+   mt9m111_func.stop_capture = camera_func_mt9m111_stop_capture;
+ 
+    g_camera_context->camera_functions = &mt9m111_func;
+#endif
+    dbg_print("success!"); 
+    return 0;
+   
+err_init:
+    pxa_camera_mem_deinit();
+    return -1;
+}
+
+int pxa_camera_video_init(struct video_device *vdev)
+{
+  return 0;
+}
+
+static struct video_device vd = {
+	owner:		THIS_MODULE,
+	name:		"E680 camera",
+	type:		VID_TYPE_CAPTURE,
+	hardware:	VID_HARDWARE_PXA_CAMERA,      /* FIXME */
+	open:		pxa_camera_open,
+	close:		pxa_camera_close,
+	read:		pxa_camera_read,
+	poll:		pxa_camera_poll,
+	ioctl:		pxa_camera_ioctl,
+	mmap:		pxa_camera_mmap,
+	initialize:	pxa_camera_video_init,
+	minor:		-1,
+};
+
+
+
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX_WRITE_LEN 12
+static ssize_t camera_write (struct file *file, const char *buf, size_t count, loff_t * pos)
+{
+
+  char feedback[2*MAX_WRITE_LEN + 1] ={0};
+  char feedback1[2*MAX_WRITE_LEN + 1] = {0};
+  size_t n = count;
+  size_t l;
+  char c;
+  int i,x,y,t;
+
+  u16 reg, value;
+
+  MOD_INC_USE_COUNT;
+  if (n > 0)
+    {
+      l = MIN (n, MAX_WRITE_LEN);
+      if (copy_from_user (feedback, buf, l))
+	{
+	  count = -EFAULT;
+	}
+      else
+	{
+	  if (l > 0 && feedback[l - 1] == '\n')
+	    {
+	      l -= 1;
+	    }
+	  feedback[l] = 0;
+	  n -= l;
+	  // flush remainder, if any
+	  while (n > 0)
+	    {
+	      // Not too efficient, but it shouldn't matter
+	      if (copy_from_user (&c, buf + (count - n), 1))
+		{
+		  count = -EFAULT;
+		  break;
+		}
+	      n -= 1;
+	    }
+	}
+    }
+
+  i=1;
+  x=1;
+  y=1;
+  if (count > 0 && feedback[0] == '{')
+    {
+       while(feedback[i] != '}' && i<=MAX_WRITE_LEN*2)
+       {
+	 c= feedback[i];
+	 i++; 
+	if(c>='a' && c<='f')
+	{
+	  c-=0x20;
+	}
+	if(!((c>='0'&& c<='9')||(c>='A'&&c<='F')||c==','))
+	{
+	  continue;
+	}
+        feedback1[x++] = c;
+      }
+
+    feedback1[x]='}';
+    feedback1[0]='{';
+    for(i=1;i<=x;i++)
+    {
+       if(feedback1[i] == ',')
+       {
+	 y=3;
+         for(t=i-1;t>=1;t--)
+         {
+	    if(y==0)
+	      break;
+            feedback[y--]=feedback1[t];
+         }
+         if(y>=1)
+	 {
+	   for(t=y;t>=1;t--)
+	   {
+	      feedback[t] = '0';
+           }
+         }
+       }
+	    
+       if(feedback1[i] == '}')
+       {
+	 y=8;
+         for(t=i-1;feedback1[t]!=','&&t>=1;t--)
+         {
+	    if(y==4)
+	      break;
+            feedback[y--]=feedback1[t];
+         }
+         if(y>=5)
+	 {
+	   for(t=y;t>=5;t--)
+	   {
+	      feedback[t] = '0';
+           }
+         }
+       }
+     }
+
+       
+	    reg = 16 * 16 * (feedback[1]>='A'?feedback[1]-'A'+10:feedback[1]-0x30) + 16 *  (feedback[2]>='A'?feedback[2]-'A'+10:feedback[2]-0x30) + (feedback[3]>='A'?feedback[3]-'A'+10:feedback[3]-0x30) ;
+      value = 16 * 16 * 16 *  (feedback[5]>='A'?feedback[5]-'A'+10:feedback[5]-0x30) + 16 *16*  (feedback[6]>='A'?feedback[6]-'A'+10:feedback[6]-0x30) + 16 *  (feedback[7]>='A'?feedback[7]-'A'+10:feedback[7]-0x30) + (feedback[8]>='A'?feedback[8]-'A'+10:feedback[8]-0x30) ;
+
+     if(reg == 0xFFF && value == 0xFFFF)
+     {
+	     mt9m111_dump_register(0,0x2ff,NULL);
+     }
+     else if(reg == 0xFFF)
+     {
+	     mt9m111_reg_read(value);
+     }
+     else
+     mt9m111_write(reg, value); 
+    }
+  MOD_DEC_USE_COUNT;
+
+  return (count);
+}
+
+
+static struct file_operations camera_funcs = {
+  read:NULL,
+  write:camera_write,
+};
+
+
+static int __init pxa_camera_init(void)
+{
+  struct proc_dir_entry *pw;
+   /* 1. mapping CI registers, so that we can access the CI */
+    if(request_irq(IRQ_CAMERA, pxa_camera_irq, 0, "PXA Camera", &vd)) 
+    {
+	dbg_print ("Camera interrupt register failed failed number \n");
+	return -EIO;
+    } 
+    dbg_print ("Camera interrupt register successful \n");
+
+	
+    ci_dma_y = pxa_request_dma("CI_Y",DMA_PRIO_HIGH, pxa_ci_dma_irq_y, &vd);
+    if(ci_dma_y < 0) 
+    {
+      dbg_print( "PXA_CAMERA: Cann't request DMA for Y\n");
+      return -EIO;
+    }
+    dbg_print( "PXA_CAMERA: Request DMA for Y successfully [%d]\n",ci_dma_y);
+   
+    ci_dma_cb = pxa_request_dma("CI_Cb",DMA_PRIO_HIGH, pxa_ci_dma_irq_cb, &vd);
+    if(ci_dma_cb < 0) 
+    {
+	dbg_print( "PXA_CAMERA: Cann't request DMA for Cb\n");
+	return -EIO;
+    } 
+    dbg_print( "PXA_CAMERA: Request DMA for Cb successfully [%d]\n",ci_dma_cb);
+    
+    ci_dma_cr = pxa_request_dma("CI_Cr",DMA_PRIO_HIGH, pxa_ci_dma_irq_cr, &vd);
+    if(ci_dma_cr < 0) 
+    {
+	dbg_print( "PXA_CAMERA: Cann't request DMA for Cr\n");
+	return -EIO;
+    }
+    
+    dbg_print( "PXA_CAMERA: Request DMA for Cr successfully [%d]\n",ci_dma_cr);
+   
+    
+    DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+    DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+    DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;	
+
+#ifdef CONFIG_CAMERA_OV9640
+    minor =1;
+#endif
+
+#ifdef CONFIG_CAMERA_MT9M111
+   minor =0 ;
+#endif
+
+    if(video_register_device(&vd, VFL_TYPE_GRABBER, minor) < 0) 
+    {
+	dbg_print("PXA_CAMERA: video_register_device failed\n");
+	return -EIO;
+    }
+
+#ifdef CONFIG_PM    
+    pm_dev = pm_register(PM_SYS_DEV, 0, camera_pm_callback);
+#endif
+    
+    dbg_print("PXA_CAMERA: video_register_device successfully. /dev/video%d \n",minor);
+  
+    if ((pw = create_proc_entry ("cam", 0666, 0)) == NULL)
+    {
+      return -ENOMEM;
+    }
+  pw->proc_fops = &camera_funcs;
+  
+    return 0;
+}
+
+static void __exit pxa_camera_exit(void)
+{
+
+#ifdef CONFIG_PM
+     pm_unregister(pm_dev);
+#endif
+    if(ci_dma_y) 
+    {
+        pxa_free_dma(ci_dma_y);
+        ci_dma_y = 0;
+    }
+    if(ci_dma_cb) 
+    {
+        pxa_free_dma(ci_dma_cb);
+        ci_dma_cb = 0;
+    }
+    if(ci_dma_cr) 
+    {
+        pxa_free_dma(ci_dma_cr);
+        ci_dma_cr = 0;
+    }
+   
+   	DRCMR68 = 0;
+	DRCMR69 = 0;
+	DRCMR70 = 0;
+    
+    pxa_camera_mem_deinit();
+    
+    free_irq(IRQ_CAMERA,  &vd);
+    
+    video_unregister_device(&vd);
+
+
+  remove_proc_entry ("cam", NULL);
+    
+}
+
+
+//-------------------------------------------------------------------------------------------------------
+//      Configuration APIs
+//-------------------------------------------------------------------------------------------------------
+void ci_set_frame_rate(CI_FRAME_CAPTURE_RATE frate)
+{
+	unsigned int value;
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_FR_RATE_SMASK << CI_CICR4_FR_RATE_SHIFT);
+	value |= (unsigned)frate << CI_CICR4_FR_RATE_SHIFT;
+	CICR4 = value;
+}
+
+CI_FRAME_CAPTURE_RATE ci_get_frame_rate(void)
+{
+	unsigned int value;
+	value = CICR4;
+	return (CI_FRAME_CAPTURE_RATE)((value >> CI_CICR4_FR_RATE_SHIFT) & CI_CICR4_FR_RATE_SMASK);
+}
+
+void ci_set_image_format(CI_IMAGE_FORMAT input_format, CI_IMAGE_FORMAT output_format)
+{
+
+    unsigned int value, tbit, rgbt_conv, rgb_conv, rgb_f, ycbcr_f, rgb_bpp, raw_bpp, cspace;
+    // write cicr1: preserve ppl value and data width value
+    dbg_print("0");
+    value = CICR1;
+    dbg_print("1");
+    value &= ( (CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT) | ((CI_CICR1_DW_SMASK) << CI_CICR1_DW_SHIFT));
+    tbit = rgbt_conv = rgb_conv = rgb_f = ycbcr_f = rgb_bpp = raw_bpp = cspace = 0;
+    switch(input_format) 
+    {
+    case CI_RAW8:
+        cspace = 0;
+        raw_bpp = 0;
+        break;
+    case CI_RAW9:
+        cspace = 0;
+        raw_bpp = 1;
+        break;
+    case CI_RAW10:
+        cspace = 0;
+        raw_bpp = 2;
+        break;
+    case CI_YCBCR422:
+    case CI_YCBCR422_PLANAR:
+        cspace = 2;
+        if(output_format == CI_YCBCR422_PLANAR) 
+        {
+            ycbcr_f = 1;
+        }
+        break;
+    case CI_RGB444:
+        cspace = 1;
+        rgb_bpp = 0;
+        break;  
+    case CI_RGB555:
+        cspace = 1;
+        rgb_bpp = 1;
+        if(output_format == CI_RGBT555_0) 
+        {
+            rgbt_conv = 2;
+            tbit = 0;
+        } 
+        else if(output_format == CI_RGBT555_1) 
+        {
+            rgbt_conv = 2;
+            tbit = 1;
+        }
+        break;  
+    case CI_RGB565:
+        cspace = 1;
+        rgb_bpp = 2;
+        rgb_f = 1;
+        break;  
+    case CI_RGB666: 
+        cspace = 1;
+        rgb_bpp = 3;
+        if(output_format == CI_RGB666_PACKED) 
+        {
+            rgb_f = 1;
+        }
+        break;  
+    case CI_RGB888:
+    case CI_RGB888_PACKED:
+        cspace = 1;
+        rgb_bpp = 4;
+        switch(output_format) 
+        {
+        case CI_RGB888_PACKED:
+            rgb_f = 1;
+            break;
+        case CI_RGBT888_0:
+            rgbt_conv = 1;
+            tbit = 0;
+            break;
+        case CI_RGBT888_1:
+            rgbt_conv = 1;
+            tbit = 1;
+            break;
+        case CI_RGB666:
+            rgb_conv = 1;
+            break;
+            // RGB666 PACKED - JamesL
+        case CI_RGB666_PACKED:
+            rgb_conv = 1;
+            rgb_f = 1;
+            break;
+            // end
+        case CI_RGB565:
+            dbg_print("format : 565");
+            rgb_conv = 2;
+            break;
+        case CI_RGB555:
+            rgb_conv = 3;
+            break;
+        case CI_RGB444:
+            rgb_conv = 4;
+            break;
+        default:
+            break;
+        }
+        break;  
+    default:
+        break;
+    }
+        dbg_print("2");
+    value |= (tbit==1) ? CI_CICR1_TBIT : 0;
+    value |= rgbt_conv << CI_CICR1_RGBT_CONV_SHIFT;
+    value |= rgb_conv << CI_CICR1_RGB_CONV_SHIFT;
+    value |= (rgb_f==1) ? CI_CICR1_RBG_F : 0;
+    value |= (ycbcr_f==1) ? CI_CICR1_YCBCR_F : 0;
+    value |= rgb_bpp << CI_CICR1_RGB_BPP_SHIFT;
+    value |= raw_bpp << CI_CICR1_RAW_BPP_SHIFT;
+    value |= cspace << CI_CICR1_COLOR_SP_SHIFT;
+    CICR1 = value;   
+
+}
+
+void ci_set_mode(CI_MODE mode, CI_DATA_WIDTH data_width)
+{
+	unsigned int value;
+	
+	// write mode field in cicr0
+	value = CICR0;
+	value &= ~(CI_CICR0_SIM_SMASK << CI_CICR0_SIM_SHIFT);
+	value |= (unsigned int)mode << CI_CICR0_SIM_SHIFT;
+	CICR0 = value;   
+	
+	// write data width cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_DW_SMASK << CI_CICR1_DW_SHIFT);
+	value |= ((unsigned)data_width) << CI_CICR1_DW_SHIFT;
+	CICR1 = value;   
+	return; 
+}
+
+void ci_configure_mp(unsigned int ppl, unsigned int lpf, CI_MP_TIMING* timing)
+{
+	unsigned int value;
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;   
+	
+	// write BLW, ELW in cicr2  
+	value = CICR2;
+	value &= ~(CI_CICR2_BLW_SMASK << CI_CICR2_BLW_SHIFT | CI_CICR2_ELW_SMASK << CI_CICR2_ELW_SHIFT );
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	CICR2 = value;   
+	
+	// write BFW, LPF in cicr3
+	value = CICR3;
+	value &= ~(CI_CICR3_BFW_SMASK << CI_CICR3_BFW_SHIFT | CI_CICR3_LPF_SMASK << CI_CICR3_LPF_SHIFT );
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;   
+
+}
+
+void ci_configure_sp(unsigned int ppl, unsigned int lpf, CI_SP_TIMING* timing)
+{
+	unsigned int value;
+
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;   
+	
+	// write cicr2
+	value = CICR2;
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	value |= (timing->ELW & CI_CICR2_ELW_SMASK) << CI_CICR2_ELW_SHIFT;
+	value |= (timing->HSW & CI_CICR2_HSW_SMASK) << CI_CICR2_HSW_SHIFT;
+	value |= (timing->BFPW & CI_CICR2_BFPW_SMASK) << CI_CICR2_BFPW_SHIFT;
+	value |= (timing->FSW & CI_CICR2_FSW_SMASK) << CI_CICR2_FSW_SHIFT;
+	CICR2 = value;   
+
+	// write cicr3
+	value = CICR3;
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (timing->EFW & CI_CICR3_EFW_SMASK) << CI_CICR3_EFW_SHIFT;
+	value |= (timing->VSW & CI_CICR3_VSW_SMASK) << CI_CICR3_VSW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;   
+	return;
+}
+
+void ci_configure_ms(unsigned int ppl, unsigned int lpf, CI_MS_TIMING* timing)
+{
+	// the operation is same as Master-Parallel
+	ci_configure_mp(ppl, lpf, (CI_MP_TIMING*)timing);
+}
+
+void ci_configure_ep(int parity_check)
+{
+	unsigned int value;
+
+	// write parity_enable field in cicr0   
+	value = CICR0;
+	if(parity_check) 
+    {
+		value |= CI_CICR0_PAR_EN;
+	}
+	else 
+    {
+		value &= ~CI_CICR0_PAR_EN;
+	}
+	CICR0 = value;   
+	return; 
+}
+
+void ci_configure_es(int parity_check)
+{
+	// the operationi is same as Embedded-Parallel
+	ci_configure_ep(parity_check);
+}
+
+void ci_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz)
+{
+	unsigned int ciclk,  value, div, cccr_l, K;
+
+	// determine the LCLK frequency programmed into the CCCR.
+	cccr_l = (CCCR & 0x0000001F);
+
+	if(cccr_l < 8)
+		K = 1;
+	else if(cccr_l < 17)
+		K = 2;
+	else 
+		K = 3;
+
+	ciclk = (13 * cccr_l) / K;
+	
+	div = (ciclk + mclk_khz) / ( 2 * mclk_khz ) - 1 ;  
+	dbg_print("cccr=%xciclk=%d,cccr_l=%d,K=%d,div=%d\n",CCCR,ciclk,cccr_l,K,div);
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCLK_EN | CI_CICR4_MCLK_EN | CI_CICR4_DIV_SMASK<<CI_CICR4_DIV_SHIFT);
+	value |= (pclk_enable) ? CI_CICR4_PCLK_EN : 0;
+	value |= (mclk_enable) ? CI_CICR4_MCLK_EN : 0;
+	value |= div << CI_CICR4_DIV_SHIFT;
+	CICR4 = value;   
+	return; 
+}
+
+void ci_set_polarity(int pclk_sample_falling, int hsync_active_low, int vsync_active_low)
+{
+          dbg_print(""); 
+	unsigned int value;
+	
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCP | CI_CICR4_HSP | CI_CICR4_VSP);
+	value |= (pclk_sample_falling)? CI_CICR4_PCP : 0;
+	value |= (hsync_active_low) ? CI_CICR4_HSP : 0;
+	value |= (vsync_active_low) ? CI_CICR4_VSP : 0;
+	CICR4 = value;   
+	return; 
+}
+
+void ci_set_fifo(unsigned int timeout, CI_FIFO_THRESHOLD threshold, int fifo1_enable,
+               int fifo2_enable)
+{
+	unsigned int value;
+        dbg_print("");
+	// write citor
+	CITOR = timeout; 
+	
+	// write cifr: always enable fifo 0! also reset input fifo 
+	value = CIFR;
+	value &= ~(CI_CIFR_FEN0 | CI_CIFR_FEN1 | CI_CIFR_FEN2 | CI_CIFR_RESETF | 
+	CI_CIFR_THL_0_SMASK<<CI_CIFR_THL_0_SHIFT);
+	value |= (unsigned int)threshold << CI_CIFR_THL_0_SHIFT;
+	value |= (fifo1_enable) ? CI_CIFR_FEN1 : 0;
+	value |= (fifo2_enable) ? CI_CIFR_FEN2 : 0;
+	value |= CI_CIFR_RESETF | CI_CIFR_FEN0;
+	CIFR = value;
+}
+
+void ci_reset_fifo()
+{
+	unsigned int value;
+	value = CIFR;
+	value |= CI_CIFR_RESETF;
+	CIFR = value;
+}
+
+void ci_set_int_mask(unsigned int mask)
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_INTERRUPT_MASK;
+	value |= (mask & CI_CICR0_INTERRUPT_MASK);
+	dbg_print("-----------value=0x%x\n",value);
+	CICR0 = value;   
+	return; 
+}
+
+unsigned int ci_get_int_mask()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	return (value & CI_CICR0_INTERRUPT_MASK);
+}
+
+void ci_clear_int_status(unsigned int status)
+{
+	// write 1 to clear
+	CISR = status;
+}
+
+unsigned int ci_get_int_status()
+{
+	int value;
+
+	value = CISR;
+
+	return  value;
+}
+
+void ci_set_reg_value(unsigned int reg_offset, unsigned int value)
+{
+	CI_REG((u32)(ci_regs_base) + reg_offset) = value;
+}
+
+int ci_get_reg_value(unsigned int reg_offset)
+{
+	int value;
+
+	value = CI_REG((u32)(ci_regs_base) + reg_offset);
+	return value;
+}
+
+//-------------------------------------------------------------------------------------------------------
+//  Control APIs
+//-------------------------------------------------------------------------------------------------------
+int ci_init()
+{
+//	(unsigned long*)ci_regs_base = (unsigned long*)ioremap(CI_REGS_PHYS, CI_REG_SIZE);
+
+//	if(ci_regs_base == NULL) 
+//  {   
+//	   dbg_print ("ci regs base apply failed \n");
+//	   return -1;
+//	}
+
+	// clear all CI registers
+	CICR0 = 0x3FF;   // disable all interrupts
+	CICR1 = 0;
+	CICR2 = 0;
+	CICR3 = 0;
+	CICR4 = 0;
+	CISR = ~0;
+	CIFR = 0;
+	CITOR = 0;
+	
+	// enable CI clock
+	CKEN |= CKEN24_CAMERA;
+	return 0;
+}
+
+void ci_deinit()
+{
+	// disable CI clock
+	CKEN &= ~CKEN24_CAMERA;
+}
+
+void ci_enable(int dma_en)
+{        
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_ENB;
+	if(dma_en) {
+		value |= CI_CICR0_DMA_EN;
+	}
+	CICR0 = value;   
+	return; 
+}
+
+int ci_disable(int quick)
+{
+	volatile unsigned int value, mask;
+	int retry;
+
+	// write control bit in cicr0   
+	value = CICR0;
+	if(quick)
+        {
+		value &= ~CI_CICR0_ENB;
+		mask = CI_CISR_CQD;
+	}
+	else 
+        {
+		value |= CI_CICR0_DIS;
+		mask = CI_CISR_CDD;
+	}
+	CICR0 = value;   
+	
+	// wait shutdown complete
+	retry = 50;
+	while ( retry-- > 0 ) 
+        {
+		value = CISR;
+		if( value & mask ) 
+                {
+			CISR = mask;
+			return 0;
+		}
+		mdelay(10);
+	}
+
+	return -1; 
+}
+
+void ci_slave_capture_enable()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_SL_CAP_EN;
+	CICR0 = value;   
+	return; 
+}
+
+void ci_slave_capture_disable()
+{
+	unsigned int value;
+	
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_SL_CAP_EN;
+	CICR0 = value;   
+	return; 
+}
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs)
+{
+
+    static int dma_repeated = 0;
+    camera_context_t  *cam_ctx = g_camera_context;
+    int        dcsr;
+    
+    //dbg_print ("");
+    dcsr = DCSR(channel);
+    DCSR(channel) = dcsr & ~DCSR_STOPIRQEN;
+#ifdef CONFIG_OV9640
+    if(dma_repeated==1)
+	    repeated_n++;
+    else
+	irq_n ++;
+#endif
+    if(irq_n <14)
+	   {
+		   irq_n++;
+	    }
+    else
+    {irq_n=0;
+	    dbg_print("got 15 frame !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+	   }
+    if(still_image_mode == 1) 
+    {
+
+        if(task_waiting == 1) 
+        {
+            wake_up_interruptible (&camera_wait_q);
+            task_waiting = 0;
+        }
+        //else 
+        {
+            still_image_rdy = 1;
+	    stop_dma_transfer(g_camera_context);
+	    dbg_print("Photo ready!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+        }
+    } 
+    else if(dma_repeated == 0 &&
+           (cam_ctx->block_tail == ((cam_ctx->block_header + 2) % cam_ctx->block_number)))  
+    {
+        dma_repeated = 1;
+        pxa_dma_repeat(cam_ctx);
+        //dbg_print ("DMA repeated.");
+        cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+    }
+    else if(dma_repeated == 1 && 
+        (cam_ctx->block_tail != ((cam_ctx->block_header + 1) % cam_ctx->block_number)) && 
+        (cam_ctx->block_tail != ((cam_ctx->block_header + 2) % cam_ctx->block_number)))  
+    {
+        pxa_dma_continue(cam_ctx);
+        //dbg_print ("DMA continue.");
+        dma_repeated = 0;
+        /*		
+        if(task_waiting == 1) 
+        {
+         wake_up_interruptible (&camera_wait_q);
+         task_waiting = 0;
+        }
+        */
+    }
+    else if(dma_repeated == 0) 
+    {
+        cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+        /*	
+        if(task_waiting == 1) 
+        {
+         wake_up_interruptible (&camera_wait_q);
+         task_waiting = 0;
+        }
+        */
+    }
+    
+    if(task_waiting == 1 && !(cam_ctx->block_header == cam_ctx->block_tail)) 
+    {
+        wake_up_interruptible (&camera_wait_q);
+        task_waiting = 0;
+    }
+
+    //dbg_print("Get a frame: block-tail = %d, block-header = %d \n", cam_ctx->block_tail, cam_ctx->block_header);
+}
+
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs)
+{
+    return;
+}
+
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs)
+{
+    return;
+}
+
+
+void pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs)
+{
+    int cisr;
+    static int dma_started=0;
+    camera_irq_n++;
+    disable_irq(IRQ_CAMERA);
+    cisr = CISR;
+    if(cisr & CI_CISR_SOF) 
+    {
+        if(dma_started == 0) 
+        {
+            dma_started = 1;
+        }
+        CISR |= CI_CISR_SOF;
+    }
+    if(cisr & CI_CISR_EOF) 
+    {
+        CISR |= CI_CISR_EOF;
+    }
+    enable_irq(IRQ_CAMERA);
+}
+
+void pxa_dma_repeat(camera_context_t  *cam_ctx)
+{
+    pxa_dma_desc *cnt_head, *cnt_tail;
+	int cnt_block;
+
+	cnt_block = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+    
+    // FIFO0
+	(pxa_dma_desc *)cnt_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + 
+                                cnt_block * cam_ctx->fifo0_num_descriptors;
+                                
+	cnt_tail = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+	cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+    
+    // FIFO1
+	if(cam_ctx->fifo1_transfer_size) 
+    {
+		cnt_head = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo1_num_descriptors;
+                    
+		cnt_tail = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+    
+    // FIFO2
+	if(cam_ctx->fifo2_transfer_size) 
+    {
+		cnt_head = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo2_num_descriptors;
+                    
+		cnt_tail = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+ }
+
+void pxa_dma_continue(camera_context_t *cam_ctx)
+{
+   	pxa_dma_desc *cnt_head, *cnt_tail;
+	pxa_dma_desc *next_head;
+	int cnt_block, next_block;
+
+	cnt_block = cam_ctx->block_header;
+	next_block = (cnt_block + 1) % cam_ctx->block_number;
+    
+    // FIFO0
+	cnt_head  = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + 
+                cnt_block * cam_ctx->fifo0_num_descriptors;
+                
+	cnt_tail  = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+    
+	next_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual +
+                next_block * cam_ctx->fifo0_num_descriptors;
+
+    cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+    
+    // FIFO1
+	if(cam_ctx->fifo1_transfer_size) 
+    {
+		cnt_head  = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                    cnt_block * cam_ctx->fifo1_num_descriptors;
+                    
+		cnt_tail  = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+        
+		next_head = (pxa_dma_desc *)cam_ctx->fifo1_descriptors_virtual + 
+                     next_block * cam_ctx->fifo1_num_descriptors;
+                     
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+    
+    // FIFO2
+	if(cam_ctx->fifo2_transfer_size) 
+    {
+		cnt_head  = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                   cnt_block * cam_ctx->fifo2_num_descriptors;
+                   
+		cnt_tail  = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+        
+		next_head = (pxa_dma_desc *)cam_ctx->fifo2_descriptors_virtual + 
+                    next_block * cam_ctx->fifo2_num_descriptors;
+                    
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+	return;
+
+}
+
+void ci_dump(void)
+{
+    dbg_print ("CICR0 = 0x%8x ", CICR0);
+    dbg_print ("CICR1 = 0x%8x ", CICR1);
+    dbg_print ("CICR2 = 0x%8x ", CICR2);
+    dbg_print ("CICR3 = 0x%8x ", CICR3);
+    dbg_print ("CICR4 = 0x%8x ", CICR4);
+    dbg_print ("CISR  = 0x%8x ", CISR);
+    dbg_print ("CITOR = 0x%8x ", CITOR);
+    dbg_print ("CIFR  = 0x%8x ", CIFR);
+}
+
+
+module_init(pxa_camera_init);
+module_exit(pxa_camera_exit);
+
+MODULE_DESCRIPTION("Bulverde Camera Interface driver");
+MODULE_LICENSE("GPL");
+EXPORT_NO_SYMBOL;
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/drivers/media/video/pxa_camera_ov.c linux-2.6.16.5-exz/drivers/media/video/pxa_camera_ov.c
--- linux-2.6.16.5/drivers/media/video/pxa_camera_ov.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/drivers/media/video/pxa_camera_ov.c	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,2449 @@
+/*
+ *  pxa_camera.c
+ *
+ *  Bulverde Processor Camera Interface driver.
+ *
+ *  Copyright (C) 2003, Intel Corporation
+ *  Copyright (C) 2003, Montavista Software Inc.
+ *
+ *  Author: Intel Corporation Inc.
+ *          MontaVista Software, Inc.
+ *           source@mvista.com
+ * 
+ *  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.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/ctype.h>
+#include <linux/pagemap.h>
+#include <linux/wrapper.h>
+#include <linux/videodev.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
+#include <linux/poll.h>
+#include <linux/wait.h>
+#ifdef CONFIG_DPM
+#include <linux/device.h>
+#include <asm/arch/ldm.h>
+#endif
+
+#include <linux/types.h>
+#include <asm/mach-types.h>
+#include <asm/io.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+#include <asm/arch/irqs.h>
+
+
+#include "camera.h"
+
+
+#ifdef CONFIG_CAMERA_OV9640
+#define   OV9640
+#elif defined CONFIG_CAMERA_ADCM2700
+#define   ADCM2700
+#elif defined CONFIG_CAMERA_ADCM2650
+#define   ADCM2650
+#endif
+
+#ifdef ADCM2650
+#include "pxa_camera.h"
+#include "adcm2650.h"
+#include "adcm2650_hw.h"
+#endif
+
+#ifdef ADCM2700
+#include "adcm2700.h"
+#include "adcm2700_hw.h"
+#endif
+
+#ifdef OV9640
+#include "ov9640.h"
+#include "ov9640_hw.h"
+#endif
+
+#define PREFIX "PXA camera: "
+
+#ifdef ADCM2650
+#define MAX_WIDTH	480
+#define MAX_HEIGHT	640
+#define MIN_WIDTH	72
+#define MIN_HEIGHT	72
+#endif
+
+#ifdef ADCM2700
+#define MAX_WIDTH	480
+#define MAX_HEIGHT	640
+#define MIN_WIDTH	72
+#define MIN_HEIGHT	72
+#endif
+
+#ifdef OV9640
+/* in ov9640.h */
+#endif
+
+#define MAX_BPP		32
+#define WIDTH_DEFT	320
+#define HEIGHT_DEFT	240
+#define FRAMERATE_DEFT	0x0
+
+
+/*
+ * It is required to have at least 3 frames in buffer
+ * in current implementation
+ */
+#define FRAMES_IN_BUFFER	3
+#define MIN_FRAMES_IN_BUFFER	3
+#define MAX_FRAME_SIZE		(MAX_WIDTH * MAX_HEIGHT * (MAX_BPP >> 3))
+#define BUF_SIZE_DEFT		(MAX_FRAME_SIZE * MIN_FRAMES_IN_BUFFER)
+#define SINGLE_DESC_TRANS_MAX  	PAGE_SIZE
+#define MAX_DESC_NUM		((MAX_FRAME_SIZE / SINGLE_DESC_TRANS_MAX + 1) *\
+				 MIN_FRAMES_IN_BUFFER*2)
+
+#define MAX_BLOCK_NUM	20
+
+static camera_context_t *g_camera_context = NULL;
+#ifdef ADCM2650
+static camera_function_t adcm2650_func;
+#endif
+#ifdef ADCM2700
+static camera_function_t adcm2700_func;
+#endif
+#ifdef OV9640
+static camera_function_t ov9640_func;
+#endif
+wait_queue_head_t camera_wait_q;
+
+/* /dev/videoX registration number */
+static int minor = 0;
+static int ci_dma_y = -1;
+static int ci_dma_cb = -1;
+static int ci_dma_cr = -1;
+volatile int task_waiting = 0;
+static int still_image_mode = 0;
+static int still_image_rdy = 0;
+static int first_video_frame = 0;
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs);
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs);
+
+static unsigned long ci_regs_base = 0;	/* for CI registers IOMEM mapping */
+
+#define CI_REG(x)             (* (volatile u32*)(x) )
+#define CI_REG_SIZE             0x40	/* 0x5000_0000 --- 0x5000_0038 * 64K */
+#define CI_REGS_PHYS            0x50000000	/* Start phyical address of CI registers */
+/* placed in include/asm/arch/pxa_regs.h
+#define CICR0		        CI_REG((u32)(ci_regs_base) + 0x00)
+#define CICR1           	CI_REG((u32)(ci_regs_base) + 0x04)
+#define CICR2 		        CI_REG((u32)(ci_regs_base) + 0x08)
+#define CICR3           	CI_REG((u32)(ci_regs_base) + 0x0c)
+#define CICR4             	CI_REG((u32)(ci_regs_base) + 0x10)
+#define CISR 	        	CI_REG((u32)(ci_regs_base) + 0x14)
+#define CIFR              	CI_REG((u32)(ci_regs_base) + 0x18)
+#define CITOR             	CI_REG((u32)(ci_regs_base) + 0x1c)
+#define CIBR0             	CI_REG((u32)(ci_regs_base) + 0x28)
+#define CIBR1             	CI_REG((u32)(ci_regs_base) + 0x30)
+#define CIBR2             	CI_REG((u32)(ci_regs_base) + 0x38)
+*/
+/***********************************************************************
+ *
+ * Declarations
+ *
+ ***********************************************************************/
+
+// map of camera image format (camera.h) ==> capture interface format (ci.h)
+static const CI_IMAGE_FORMAT FORMAT_MAPPINGS[] = {
+	CI_RAW8,		//RAW
+	CI_RAW9,
+	CI_RAW10,
+
+	CI_RGB444,		//RGB
+	CI_RGB555,
+	CI_RGB565,
+	CI_RGB666_PACKED,	//RGB Packed 
+	CI_RGB666,
+	CI_RGB888_PACKED,
+	CI_RGB888,
+	CI_RGBT555_0,		//RGB+Transparent bit 0
+	CI_RGBT888_0,
+	CI_RGBT555_1,		//RGB+Transparent bit 1  
+	CI_RGBT888_1,
+
+	CI_INVALID_FORMAT,
+	CI_YCBCR422,		//YCBCR
+	CI_YCBCR422_PLANAR,	//YCBCR Planaried
+	CI_INVALID_FORMAT,
+	CI_INVALID_FORMAT
+};
+
+static int update_dma_chain(p_camera_context_t cam_ctx);
+void start_dma_transfer(p_camera_context_t cam_ctx, unsigned block_id);
+void stop_dma_transfer(p_camera_context_t cam_ctx);
+static int start_capture(p_camera_context_t cam_ctx, unsigned int block_id, unsigned int frames);
+
+static void pxa_dma_repeat(camera_context_t * cam_ctx);
+static void pxa_dma_continue(camera_context_t * cam_ctx);
+
+#ifdef ADCM2650
+extern int adcm2650_pipeline_read(u16 reg_addr, u16 * reg_value);
+extern int adcm2650_pipeline_write(u16 reg_addr, u16 reg_value);
+#define sensor_pipeline_read adcm2650_pipeline_read
+#define sensor_pipeline_write adcm2650_pipeline_write
+
+#endif
+
+#ifdef ADCM2700
+extern int adcm2700_pipeline_read(u16 reg_addr, u16 * reg_value);
+extern int adcm2700_pipeline_write(u16 reg_addr, u16 reg_value);
+#define sensor_pipeline_read adcm2700_pipeline_read
+#define sensor_pipeline_write adcm2700_pipeline_write
+#endif
+
+#ifdef OV9640
+//int ov9640_pipeline_read( u16 reg_addr, u16 * reg_value){return 0;}
+//int ov9640_pipeline_write( u16 reg_addr, u16 reg_value){return 0;}
+#define sensor_pipeline_read ov9640_read
+#define sensor_pipeline_write ov9640_write
+#endif
+/***************
+ *
+ * DPM functions
+ *
+ ***************/
+#ifdef CONFIG_DPM
+
+static int last_buffer_id;
+
+static int pxa_camera_dpm_suspend(struct device *dev, u32 state, u32 level)
+{
+	DPRINTK(KERN_DEBUG PREFIX "DPM suspend (state %d, level %d)\n", state, level);
+	switch (level) {
+	case SUSPEND_POWER_DOWN:
+		if (g_camera_context->dma_started) {
+			DPRINTK(KERN_DEBUG PREFIX "DMA running, suspended\n");
+			last_buffer_id = camera_get_last_frame_buffer_id(g_camera_context);
+			stop_dma_transfer(g_camera_context);
+		}
+		disable_irq(IRQ_CAMERA);
+		CKEN &= ~CKEN24_CAMERA;
+		break;
+	}
+	return 0;
+}
+
+static int pxa_camera_dpm_resume(struct device *dev, u32 level)
+{
+	DPRINTK(KERN_DEBUG PREFIX "DPM resume (level %d)\n", level);
+	switch (level) {
+	case RESUME_POWER_ON:
+		CKEN |= CKEN24_CAMERA;
+		enable_irq(IRQ_CAMERA);
+		if (g_camera_context->dma_started) {
+			DPRINTK(KERN_DEBUG PREFIX "resume DMA\n");
+			start_dma_transfer(g_camera_context, last_buffer_id);
+		}
+		break;
+	}
+	return 0;
+}
+
+static int pxa_camera_dpm_scale(struct bus_op_point *op, u32 level)
+{
+	DPRINTK(KERN_DEBUG PREFIX "DPM scale (level %d)\n", level);
+	/* CCCR is changed - adjust clock */
+	ci_set_clock(g_camera_context->clk_reg_base, 1, 1, 7 /* MCLK_DEFT in adcm2650.c */ );
+	return 0;
+}
+
+static struct device_driver pxa_camera_driver_ldm = {
+	name:"camera",
+	devclass:NULL,
+	probe:NULL,
+	suspend:pxa_camera_dpm_suspend,
+	resume:pxa_camera_dpm_resume,
+	scale:pxa_camera_dpm_scale,
+	remove:NULL,
+	constraints:NULL
+};
+
+static struct device pxa_camera_device_ldm = {
+	name:"PXA camera",
+	bus_id:"video",
+	driver:NULL,
+	power_state:DPM_POWER_ON
+};
+
+static void pxa_camera_ldm_register(void)
+{
+	pxaebc_driver_register(&pxa_camera_driver_ldm);
+	pxaebc_device_register(&pxa_camera_device_ldm);
+}
+
+static void pxa_camera_ldm_unregister(void)
+{
+	pxaebc_driver_unregister(&pxa_camera_driver_ldm);
+	pxaebc_device_unregister(&pxa_camera_device_ldm);
+}
+#endif				/* CONFIG_DPM */
+#ifdef CONFIG_PM
+static struct pm_dev *pm_dev;
+static int resume_dma = 0;
+
+static int pxa_camera_pm_suspend()
+{
+	if (g_camera_context != NULL) {
+		if (g_camera_context->dma_started) {
+			dbg_print("camera running, suspended");
+			stop_dma_transfer(g_camera_context);
+			resume_dma = 1;
+		}
+	}
+
+	disable_irq(IRQ_CAMERA);
+	CKEN &= ~CKEN24_CAMERA;
+	return 0;
+}
+
+static int pxa_camera_pm_resume()
+{
+	CKEN |= CKEN24_CAMERA;
+	enable_irq(IRQ_CAMERA);
+
+	DPRINTK(" in %s, camera running, resumed", __FUNCTION__);
+	if (g_camera_context != NULL) {
+		/*
+		 */
+		struct video_window vw;
+		vw.width = g_camera_context->capture_width;
+		vw.height = g_camera_context->capture_height;
+		ov9640_set_window(&vw);
+
+		// set_bright(g_camera_context->capture_bright);
+		ov9640_set_expose_compensation(g_camera_context->capture_bright);
+		// set_fps(g_camera_context->fps, g_camera_context->mini_fps);
+		ov9640_set_fps(g_camera_context->fps);
+		//  set_light(g_camera_context->capture_light);
+		ov9640_set_light_environment(g_camera_context->capture_light);
+		// set_style(g_camera_context->capture_style);
+		ov9640_set_special_effect(g_camera_context->capture_style);
+
+		if (resume_dma == 1) {
+			camera_start_video_capture(g_camera_context, 0);
+			resume_dma = 0;
+		}
+
+	}
+
+	return 0;
+}
+static int camera_pm_callback(struct pm_dev *pm_dev, pm_request_t req, void *data)
+{
+	switch (req) {
+	case PM_SUSPEND:
+		pxa_camera_pm_suspend();
+		break;
+
+	case PM_RESUME:
+		pxa_camera_pm_resume();
+		break;
+
+	default:
+		break;
+	}
+	return 0;
+}
+#endif
+
+/***********************************************************************
+ *
+ * Private functions
+ *
+ ***********************************************************************/
+
+static int pxa_dma_buffer_init(p_camera_context_t cam_ctx)
+{
+	struct page *page;
+	unsigned int pages;
+	unsigned int page_count;
+
+	cam_ctx->pages_allocated = 0;
+
+	pages = (PAGE_ALIGN(cam_ctx->buf_size) / PAGE_SIZE);
+
+	cam_ctx->page_array = (struct page **) kmalloc(pages * sizeof(struct page *), GFP_KERNEL);
+	if (cam_ctx->page_array == NULL) {
+		return -ENOMEM;
+	}
+	memset(cam_ctx->page_array, 0, pages * sizeof(struct page *));
+
+	for (page_count = 0; page_count < pages; page_count++) {
+		page = alloc_page(GFP_KERNEL);
+		if (page == NULL) {
+			goto error;
+		}
+		cam_ctx->page_array[page_count] = page;
+		set_page_count(page, 1);
+		SetPageReserved(page);
+	}
+	cam_ctx->buffer_virtual = remap_page_array(cam_ctx->page_array, pages, GFP_KERNEL);
+
+	if (cam_ctx->buffer_virtual == NULL) {
+		goto error;
+	}
+
+	cam_ctx->pages_allocated = pages;
+
+	return 0;
+
+      error:
+	for (page_count = 0; page_count < pages; page_count++) {
+		if ((page = cam_ctx->page_array[page_count]) != NULL) {
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(cam_ctx->page_array);
+
+	return -ENOMEM;
+}
+
+static void pxa_dma_buffer_free(p_camera_context_t cam_ctx)
+{
+	struct page *page;
+	int page_count;
+
+	if (cam_ctx->buffer_virtual == NULL)
+		return;
+
+	vfree(cam_ctx->buffer_virtual);
+
+	for (page_count = 0; page_count < cam_ctx->pages_allocated; page_count++) {
+		if ((page = cam_ctx->page_array[page_count]) != NULL) {
+			ClearPageReserved(page);
+			set_page_count(page, 1);
+			put_page(page);
+		}
+	}
+	kfree(cam_ctx->page_array);
+}
+
+/*
+Generate dma descriptors
+Pre-condition: these variables must be set properly
+                block_number, fifox_transfer_size 
+                dma_descriptors_virtual, dma_descriptors_physical, dma_descirptors_size
+Post-condition: these variables will be set
+                fifox_descriptors_virtual, fifox_descriptors_physical              
+                fifox_num_descriptors 
+*/
+int update_dma_chain(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
+	int des_transfer_size, remain_size;
+	unsigned int i, j;
+
+	int target_page_num;
+
+	// clear descriptor pointers
+	cam_ctx->fifo0_descriptors_virtual = cam_ctx->fifo0_descriptors_physical = 0;
+	cam_ctx->fifo1_descriptors_virtual = cam_ctx->fifo1_descriptors_physical = 0;
+	cam_ctx->fifo2_descriptors_virtual = cam_ctx->fifo2_descriptors_physical = 0;
+
+	// calculate how many descriptors are needed per frame
+	cam_ctx->fifo0_num_descriptors = cam_ctx->pages_per_fifo0;
+
+	cam_ctx->fifo1_num_descriptors = cam_ctx->pages_per_fifo1;
+
+	cam_ctx->fifo2_num_descriptors = cam_ctx->pages_per_fifo2;
+
+	// check if enough memory to generate descriptors
+	if ((cam_ctx->fifo0_num_descriptors + cam_ctx->fifo1_num_descriptors +
+	     cam_ctx->fifo2_num_descriptors) * cam_ctx->block_number > cam_ctx->dma_descriptors_size)
+		return -1;
+
+	// generate fifo0 dma chains
+	cam_ctx->fifo0_descriptors_virtual = (unsigned) cam_ctx->dma_descriptors_virtual;
+	cam_ctx->fifo0_descriptors_physical = (unsigned) cam_ctx->dma_descriptors_physical;
+	cur_des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual;
+	cur_des_physical = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_physical;
+
+	for (i = 0; i < cam_ctx->block_number; i++) {
+		// in each iteration, generate one dma chain for one frame
+		remain_size = cam_ctx->fifo0_transfer_size;
+
+		// assume the blocks are stored consecutively
+		target_page_num = cam_ctx->pages_per_block * i;
+
+		for (j = 0; j < cam_ctx->fifo0_num_descriptors; j++) {
+			// set descriptor
+			if (remain_size > SINGLE_DESC_TRANS_MAX)
+				des_transfer_size = SINGLE_DESC_TRANS_MAX;
+			else
+				des_transfer_size = remain_size;
+			cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+			cur_des_virtual->dsadr = CIBR0_PHY;	// FIFO0 physical address
+			cur_des_virtual->dtadr = page_to_bus(cam_ctx->page_array[target_page_num]);
+			cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+			// advance pointers
+			remain_size -= des_transfer_size;
+			cur_des_virtual++;
+			cur_des_physical++;
+			target_page_num++;
+		}
+
+		// stop the dma transfer on one frame captured
+		last_des_virtual = cur_des_virtual - 1;
+		//last_des_virtual->ddadr |= 0x1;
+	}
+
+	last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo0_descriptors_physical);
+
+	// generate fifo1 dma chains
+	if (cam_ctx->fifo1_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo1_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo1_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < cam_ctx->block_number; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo1_transfer_size;
+
+			target_page_num = cam_ctx->pages_per_block * i + cam_ctx->pages_per_fifo0;
+
+			for (j = 0; j < cam_ctx->fifo1_num_descriptors; j++) {
+				// set descriptor
+				if (remain_size > SINGLE_DESC_TRANS_MAX)
+					des_transfer_size = SINGLE_DESC_TRANS_MAX;
+				else
+					des_transfer_size = remain_size;
+				cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+				cur_des_virtual->dsadr = CIBR1_PHY;	// FIFO1 physical address
+				cur_des_virtual->dtadr = page_to_bus(cam_ctx->page_array[target_page_num]);
+				cur_des_virtual->dcmd =
+				    des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+				// advance pointers
+				remain_size -= des_transfer_size;
+				cur_des_virtual++;
+				cur_des_physical++;
+
+				target_page_num++;
+			}
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo1_descriptors_physical);
+	}
+	// generate fifo2 dma chains
+	if (cam_ctx->fifo2_transfer_size) {
+		// record fifo1 descriptors' start address
+		cam_ctx->fifo2_descriptors_virtual = (unsigned) cur_des_virtual;
+		cam_ctx->fifo2_descriptors_physical = (unsigned) cur_des_physical;
+
+		for (i = 0; i < cam_ctx->block_number; i++) {
+			// in each iteration, generate one dma chain for one frame
+			remain_size = cam_ctx->fifo2_transfer_size;
+
+			target_page_num = cam_ctx->pages_per_block * i +
+			    cam_ctx->pages_per_fifo0 + cam_ctx->pages_per_fifo1;
+
+			for (j = 0; j < cam_ctx->fifo2_num_descriptors; j++) {
+				// set descriptor
+				if (remain_size > SINGLE_DESC_TRANS_MAX)
+					des_transfer_size = SINGLE_DESC_TRANS_MAX;
+				else
+					des_transfer_size = remain_size;
+				cur_des_virtual->ddadr = (unsigned) cur_des_physical + sizeof(pxa_dma_desc);
+				cur_des_virtual->dsadr = CIBR2_PHY;	// FIFO2 physical address
+				cur_des_virtual->dtadr = page_to_bus(cam_ctx->page_array[target_page_num]);
+				cur_des_virtual->dcmd =
+				    des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
+
+				// advance pointers
+				remain_size -= des_transfer_size;
+				cur_des_virtual++;
+				cur_des_physical++;
+				target_page_num++;
+			}
+
+			// stop the dma transfer on one frame captured
+			last_des_virtual = cur_des_virtual - 1;
+			//last_des_virtual->ddadr |= 0x1;
+		}
+		last_des_virtual->ddadr = ((unsigned) cam_ctx->fifo2_descriptors_physical);
+	}
+	return 0;
+}
+
+void start_dma_transfer(p_camera_context_t cam_ctx, unsigned block_id)
+{
+	pxa_dma_desc *des_virtual, *des_physical;
+
+	DPRINTK("in %s,cam_ctx->block_number =%d\n", __FUNCTION__, cam_ctx->block_number);
+	/*
+	   if (block_id >= cam_ctx->block_number)
+	   return;
+	 */
+	// start channel 0
+	des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + block_id * cam_ctx->fifo0_num_descriptors;
+	des_physical = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_physical + block_id * cam_ctx->fifo0_num_descriptors;
+
+	DDADR(cam_ctx->dma_channels[0]) = des_physical;
+	DCSR(cam_ctx->dma_channels[0]) |= DCSR_RUN;
+
+	// start channel 1
+	if (cam_ctx->fifo1_descriptors_virtual) {
+		des_virtual = (pxa_dma_desc *) cam_ctx->fifo1_descriptors_virtual +
+		    block_id * cam_ctx->fifo1_num_descriptors;
+		des_physical = (pxa_dma_desc *) cam_ctx->fifo1_descriptors_physical +
+		    block_id * cam_ctx->fifo1_num_descriptors;
+		DDADR(cam_ctx->dma_channels[1]) = des_physical;
+		DCSR(cam_ctx->dma_channels[1]) |= DCSR_RUN;
+	}
+	// start channel 2
+	if (cam_ctx->fifo2_descriptors_virtual) {
+		des_virtual = (pxa_dma_desc *) cam_ctx->fifo2_descriptors_virtual +
+		    block_id * cam_ctx->fifo2_num_descriptors;
+		des_physical = (pxa_dma_desc *) cam_ctx->fifo2_descriptors_physical +
+		    block_id * cam_ctx->fifo2_num_descriptors;
+		DDADR(cam_ctx->dma_channels[2]) = des_physical;
+		DCSR(cam_ctx->dma_channels[2]) |= DCSR_RUN;
+	}
+	cam_ctx->dma_started = 1;
+}
+
+void set_still_image_ready(int rdy)
+{
+	still_image_rdy = rdy;
+}
+
+void stop_dma_transfer(p_camera_context_t cam_ctx)
+{
+	int ch0, ch1, ch2;
+
+	ch0 = cam_ctx->dma_channels[0];
+	ch1 = cam_ctx->dma_channels[1];
+	ch2 = cam_ctx->dma_channels[2];
+	DCSR(ch0) &= ~DCSR_RUN;
+	DCSR(ch1) &= ~DCSR_RUN;
+	DCSR(ch2) &= ~DCSR_RUN;
+	cam_ctx->dma_started = 0;
+#ifdef CONFIG_DPM
+#endif
+}
+int start_capture(p_camera_context_t cam_ctx, unsigned int block_id, unsigned int frames)
+{
+	int status;
+	int i;
+
+	// clear ci fifo
+	ci_reset_fifo();
+	ci_clear_int_status(0xFFFFFFFF);
+
+	// start dma
+	start_dma_transfer(cam_ctx, block_id);
+
+	// start capture
+	status = cam_ctx->camera_functions->start_capture(cam_ctx, frames);
+	return status;
+}
+
+/***********************************************************************
+ *
+ * Init/Deinit APIs
+ *
+ ***********************************************************************/
+int camera_init(p_camera_context_t cam_ctx)
+{
+	int ret = 0;
+	int i;
+
+// parameter check
+	if (cam_ctx->buffer_virtual == NULL || cam_ctx->buf_size == 0)
+		return STATUS_WRONG_PARAMETER;
+	if (cam_ctx->dma_descriptors_virtual == NULL ||
+	    cam_ctx->dma_descriptors_physical == NULL || cam_ctx->dma_descriptors_size == 0)
+		return STATUS_WRONG_PARAMETER;
+	if (cam_ctx->sensor_type > CAMERA_TYPE_MAX)
+		return STATUS_WRONG_PARAMETER;
+	if (cam_ctx->capture_input_format > CAMERA_IMAGE_FORMAT_MAX ||
+	    cam_ctx->capture_output_format > CAMERA_IMAGE_FORMAT_MAX)
+		return STATUS_WRONG_PARAMETER;
+
+	// check the function dispatch table according to the sensor type
+	if (!cam_ctx->camera_functions)
+		return STATUS_WRONG_PARAMETER;
+	if (!cam_ctx->camera_functions->init ||
+	    !cam_ctx->camera_functions->deinit ||
+	    !cam_ctx->camera_functions->set_capture_format ||
+	    !cam_ctx->camera_functions->start_capture || !cam_ctx->camera_functions->stop_capture)
+		return STATUS_WRONG_PARAMETER;
+
+	// init context status
+	for (i = 0; i < 3; i++)
+		cam_ctx->dma_channels[i] = 0xFF;
+	(int) cam_ctx->fifo0_descriptors_virtual = NULL;
+	(int) cam_ctx->fifo1_descriptors_virtual = NULL;
+	(int) cam_ctx->fifo2_descriptors_virtual = NULL;
+	(int) cam_ctx->fifo0_descriptors_physical = NULL;
+	(int) cam_ctx->fifo1_descriptors_physical = NULL;
+	(int) cam_ctx->fifo2_descriptors_physical = NULL;
+
+	cam_ctx->fifo0_num_descriptors = 0;
+	cam_ctx->fifo1_num_descriptors = 0;
+	cam_ctx->fifo2_num_descriptors = 0;
+
+	cam_ctx->fifo0_transfer_size = 0;
+	cam_ctx->fifo1_transfer_size = 0;
+	cam_ctx->fifo2_transfer_size = 0;
+
+	cam_ctx->block_number = 0;
+	cam_ctx->block_size = 0;
+	cam_ctx->block_header = 0;
+	cam_ctx->block_tail = 0;
+
+	// Enable hardware
+	camera_gpio_init();
+	DPRINTK("gpio init\n");
+
+	// capture interface init
+	ci_init();
+
+	// sensor init
+	ret = cam_ctx->camera_functions->init(cam_ctx);
+	DPRINTK("after cam_ctx->camera_functions->init\n");
+	if (ret)
+		goto camera_init_err;
+
+
+	cam_ctx->dma_channels[0] = ci_dma_y;
+	cam_ctx->dma_channels[1] = ci_dma_cb;
+	cam_ctx->dma_channels[2] = ci_dma_cr;
+	DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+	DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+	DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;
+
+
+	// set capture format
+	ret = camera_set_capture_format(cam_ctx);
+	if (ret)
+		goto camera_init_err;
+
+	// set frame rate
+	//camera_set_capture_frame_rate(cam_ctx);
+
+	return 0;
+
+      camera_init_err:
+	camera_deinit(cam_ctx);
+	return -1;
+}
+
+void camera_gpio_init()
+{
+#ifdef ADCM2650
+	set_GPIO_mode(27 | GPIO_ALT_FN_3_IN);	/* CIF_DD[0] */
+	set_GPIO_mode(114 | GPIO_ALT_FN_1_IN);	/* CIF_DD[1] */
+	set_GPIO_mode(116 | GPIO_ALT_FN_1_IN);	/* CIF_DD[2] */
+	set_GPIO_mode(115 | GPIO_ALT_FN_2_IN);	/* CIF_DD[3] */
+	set_GPIO_mode(90 | GPIO_ALT_FN_3_IN);	/* CIF_DD[4] */
+	set_GPIO_mode(91 | GPIO_ALT_FN_3_IN);	/* CIF_DD[5] */
+	set_GPIO_mode(17 | GPIO_ALT_FN_2_IN);	/* CIF_DD[6] */
+	set_GPIO_mode(12 | GPIO_ALT_FN_2_IN);	/* CIF_DD[7] */
+	set_GPIO_mode(23 | GPIO_ALT_FN_1_OUT);	/* CIF_MCLK */
+	set_GPIO_mode(26 | GPIO_ALT_FN_2_IN);	/* CIF_PCLK */
+	set_GPIO_mode(25 | GPIO_ALT_FN_1_IN);	/* CIF_LV */
+	set_GPIO_mode(24 | GPIO_ALT_FN_1_IN);	/* CIF_FV */
+#endif
+
+#ifdef OV9640
+	set_GPIO_mode(27 | GPIO_ALT_FN_3_IN);	/* CIF_DD[0] */
+	set_GPIO_mode(114 | GPIO_ALT_FN_1_IN);	/* CIF_DD[1] */
+	set_GPIO_mode(51 | GPIO_ALT_FN_1_IN);	/* CIF_DD[2] */
+	set_GPIO_mode(115 | GPIO_ALT_FN_2_IN);	/* CIF_DD[3] */
+	set_GPIO_mode(95 | GPIO_ALT_FN_2_IN);	/* CIF_DD[4] */
+	set_GPIO_mode(94 | GPIO_ALT_FN_2_IN);	/* CIF_DD[5] */
+	set_GPIO_mode(17 | GPIO_ALT_FN_2_IN);	/* CIF_DD[6] */
+	set_GPIO_mode(108 | GPIO_ALT_FN_1_IN);	/* CIF_DD[7] */
+	set_GPIO_mode(23 | GPIO_ALT_FN_1_OUT);	/* CIF_MCLK */
+	set_GPIO_mode(54 | GPIO_ALT_FN_3_IN);	/* CIF_PCLK */
+	set_GPIO_mode(85 | GPIO_ALT_FN_3_IN);	/* CIF_LV */
+	set_GPIO_mode(84 | GPIO_ALT_FN_3_IN);	/* CIF_FV */
+	set_GPIO_mode(50 | GPIO_OUT);	/*CIF_PD */
+	set_GPIO_mode(19 | GPIO_OUT);	/*CIF_RST */
+
+#endif
+
+#ifdef ADCM2700
+	set_GPIO_mode(CIF_PD_MD);	/*CIF_PD */
+	GPCR(CIF_PD) |= GPIO_bit(CIF_PD);	/*set to low */
+	set_GPIO_mode(CIF_RST_MD);	/*CIF_RST */
+	GPSR(CIF_RST) |= GPIO_bit(CIF_RST);	/*set to high */
+	set_GPIO_mode(CIF_DD0_MD);	/* CIF_DD[0] */
+	set_GPIO_mode(CIF_DD1_MD);	/* CIF_DD[1] */
+	set_GPIO_mode(CIF_DD2_MD);	/* CIF_DD[2] */
+	set_GPIO_mode(CIF_DD3_MD);	/* CIF_DD[3] */
+	set_GPIO_mode(CIF_DD4_MD);	/* CIF_DD[4] */
+	set_GPIO_mode(CIF_DD5_MD);	/* CIF_DD[5] */
+	set_GPIO_mode(CIF_DD6_MD);	/* CIF_DD[6] */
+	set_GPIO_mode(CIF_DD7_MD);	/* CIF_DD[7] */
+	set_GPIO_mode(CIF_MCLK_MD);	/* CIF_MCLK  */
+	set_GPIO_mode(CIF_PCLK_MD);	/* CIF_PCLK  */
+	set_GPIO_mode(CIF_LV_MD);	/* CIF_LV    */
+	set_GPIO_mode(CIF_FV_MD);	/* CIF_FV    */
+
+#endif
+
+	return;
+}
+
+int camera_deinit(p_camera_context_t cam_ctx)
+{
+	int ret = 0;
+
+	ret = cam_ctx->camera_functions->deinit(cam_ctx);
+
+	// capture interface deinit
+	ci_deinit();
+	return ret;
+}
+
+/***********************************************************************
+ *
+ * Capture APIs
+ *
+ ***********************************************************************/
+// Set the image format
+
+int camera_set_capture_format(p_camera_context_t cam_ctx)
+{
+	int ret;
+	unsigned frame_size;
+	CI_IMAGE_FORMAT ci_input_format, ci_output_format;
+	CI_MP_TIMING timing;
+
+	// set capture interface
+	if (cam_ctx->capture_input_format > CAMERA_IMAGE_FORMAT_MAX ||
+	    cam_ctx->capture_output_format > CAMERA_IMAGE_FORMAT_MAX)
+		return STATUS_WRONG_PARAMETER;
+	ci_input_format = FORMAT_MAPPINGS[cam_ctx->capture_input_format];
+	ci_output_format = FORMAT_MAPPINGS[cam_ctx->capture_output_format];
+	if (ci_input_format == CI_INVALID_FORMAT || ci_output_format == CI_INVALID_FORMAT)
+		return STATUS_WRONG_PARAMETER;
+	ci_set_image_format(ci_input_format, ci_output_format);
+
+	// ring buffer init
+	switch (cam_ctx->capture_output_format) {
+	case CAMERA_IMAGE_FORMAT_RGB565:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 2;
+		cam_ctx->fifo0_transfer_size = frame_size;
+		cam_ctx->fifo1_transfer_size = 0;
+		cam_ctx->fifo2_transfer_size = 0;
+		break;
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 2;
+		cam_ctx->fifo0_transfer_size = frame_size;
+		cam_ctx->fifo1_transfer_size = 0;
+		cam_ctx->fifo2_transfer_size = 0;
+		break;
+	case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 2;
+		cam_ctx->fifo0_transfer_size = frame_size / 2;
+		cam_ctx->fifo1_transfer_size = frame_size / 4;
+		cam_ctx->fifo2_transfer_size = frame_size / 4;
+		break;
+// RGB666 support - JamesL
+	case CAMERA_IMAGE_FORMAT_RGB666_PLANAR:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 4;
+		cam_ctx->fifo0_transfer_size = frame_size;
+		cam_ctx->fifo1_transfer_size = 0;
+		cam_ctx->fifo2_transfer_size = 0;
+		break;
+	case CAMERA_IMAGE_FORMAT_RGB666_PACKED:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 3;
+		cam_ctx->fifo0_transfer_size = frame_size;
+		cam_ctx->fifo1_transfer_size = 0;
+		cam_ctx->fifo2_transfer_size = 0;
+		break;
+// RGB888 support - JamesL
+	case CAMERA_IMAGE_FORMAT_RGB888_PLANAR:
+		frame_size = cam_ctx->capture_width * cam_ctx->capture_height * 4;
+		cam_ctx->fifo0_transfer_size = frame_size;
+		cam_ctx->fifo1_transfer_size = 0;
+		cam_ctx->fifo2_transfer_size = 0;
+		break;
+//
+	default:
+		return STATUS_WRONG_PARAMETER;
+		break;
+	}
+	cam_ctx->block_size = frame_size;
+
+	cam_ctx->pages_per_fifo0 = (PAGE_ALIGN(cam_ctx->fifo0_transfer_size) / PAGE_SIZE);
+	cam_ctx->pages_per_fifo1 = (PAGE_ALIGN(cam_ctx->fifo1_transfer_size) / PAGE_SIZE);
+	cam_ctx->pages_per_fifo2 = (PAGE_ALIGN(cam_ctx->fifo2_transfer_size) / PAGE_SIZE);
+
+	cam_ctx->pages_per_block = cam_ctx->pages_per_fifo0 + cam_ctx->pages_per_fifo1 + cam_ctx->pages_per_fifo2;
+
+	cam_ctx->page_aligned_block_size = cam_ctx->pages_per_block * PAGE_SIZE;
+
+	cam_ctx->block_number = cam_ctx->pages_allocated / cam_ctx->pages_per_block;
+	cam_ctx->block_number_max = cam_ctx->pages_allocated / cam_ctx->pages_per_block;
+	DPRINTK("in %s,cam_ctx->block_number =%d \n", __FUNCTION__, cam_ctx->block_number);
+
+	if (cam_ctx->block_number > 3)
+		cam_ctx->block_number = 3;
+
+	if (cam_ctx->block_number > VIDEO_MAX_FRAME)
+		cam_ctx->block_number = VIDEO_MAX_FRAME;
+
+	//cam_ctx->block_header = cam_ctx->block_tail = 0;
+
+	// generate dma descriptor chain
+	ret = update_dma_chain(cam_ctx);
+	if (ret)
+		return -1;
+	timing.BFW = timing.BLW = 0;
+	ci_configure_mp(cam_ctx->capture_width - 1, cam_ctx->capture_height - 1, &timing);
+	DPRINTK("before cam_ctx->camera_functions->set_capture_format \n");
+	// set sensor setting
+	ret = cam_ctx->camera_functions->set_capture_format(cam_ctx);
+	if (ret)
+		return ret;
+
+	DPRINTK("after cam_ctx->camera_functions->set_capture_format \n");
+	return 0;
+}
+
+// take a picture and copy it into the ring buffer
+int camera_capture_still_image(p_camera_context_t cam_ctx, unsigned int block_id)
+{
+	int status;
+
+	// init buffer status & capture
+	cam_ctx->block_header = cam_ctx->block_tail = block_id;
+	cam_ctx->capture_status = 0;
+	status = start_capture(cam_ctx, block_id, 1);
+
+	return status;
+}
+
+// capture motion video and copy it to the ring buffer
+int camera_start_video_capture(p_camera_context_t cam_ctx, unsigned int block_id)
+{
+	int status;
+
+	// init buffer status & capture
+	cam_ctx->block_header = cam_ctx->block_tail = block_id;
+	cam_ctx->capture_status = CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+	status = start_capture(cam_ctx, block_id, 0);
+
+	return status;
+}
+
+// disable motion video image capture
+void camera_stop_video_capture(p_camera_context_t cam_ctx)
+{
+	int status;
+
+	// stop capture
+	status = cam_ctx->camera_functions->stop_capture(cam_ctx);
+
+	// stop dma
+	stop_dma_transfer(cam_ctx);
+
+	// update the flag
+	if (!(cam_ctx->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+		cam_ctx->capture_status &= ~CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS;
+	return;
+}
+
+
+/***********************************************************************
+ *
+ * Flow Control APIs
+ *
+ ***********************************************************************/
+// continue capture image to next available buffer
+void camera_continue_transfer(p_camera_context_t cam_ctx)
+{
+	// don't think we need this either.  JR
+	// continue transfer on next block
+	start_dma_transfer(cam_ctx, cam_ctx->block_tail);
+}
+
+// Return 1: there is available buffer, 0: buffer is full
+int camera_next_buffer_available(p_camera_context_t cam_ctx)
+{
+	cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+	if (((cam_ctx->block_header + 1) % cam_ctx->block_number) != cam_ctx->block_tail) {
+		return 1;
+	}
+	cam_ctx->capture_status |= CAMERA_STATUS_RING_BUFFER_FULL;
+
+	return 0;
+}
+
+// Application supplies the FrameBufferID to the driver to tell it that the application has completed processing of 
+// the given frame buffer, and that buffer is now available for re-use.
+void camera_release_frame_buffer(p_camera_context_t cam_ctx, unsigned int frame_buffer_id)
+{
+
+	cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+
+	// restart video capture only if video capture is in progress and space is available for image capture
+	if ((cam_ctx->capture_status & CAMERA_STATUS_RING_BUFFER_FULL) &&
+	    (cam_ctx->capture_status & CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS)) {
+		if (((cam_ctx->block_header + 2) % cam_ctx->block_number) != cam_ctx->block_tail) {
+			cam_ctx->capture_status &= ~CAMERA_STATUS_RING_BUFFER_FULL;
+			start_capture(cam_ctx, cam_ctx->block_tail, 0);
+		}
+	}
+}
+
+// Returns the FrameBufferID for the first filled frame
+// Note: -1 represents buffer empty
+int camera_get_first_frame_buffer_id(p_camera_context_t cam_ctx)
+{
+	// not sure if this routine makes any sense.. JR
+
+	// check whether buffer is empty
+	if ((cam_ctx->block_header == cam_ctx->block_tail) &&
+	    !(cam_ctx->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+		return -1;
+
+	// return the block header
+	return cam_ctx->block_header;
+}
+
+// Returns the FrameBufferID for the last filled frame, this would be used if we were polling for image completion data, 
+// or we wanted to make sure there were no frames waiting for us to process.
+// Note: -1 represents buffer empty
+int camera_get_last_frame_buffer_id(p_camera_context_t cam_ctx)
+{
+	int ret;
+
+	// check whether buffer is empty
+	if ((cam_ctx->block_header == cam_ctx->block_tail) &&
+	    !(cam_ctx->capture_status & CAMERA_STATUS_RING_BUFFER_FULL))
+		return -1;
+
+	// return the block before the block_tail
+	ret = (cam_ctx->block_tail + cam_ctx->block_number - 1) % cam_ctx->block_number;
+	return ret;
+}
+
+/***********************************************************************
+ *
+ * Buffer Info APIs
+ *
+ ***********************************************************************/
+// Return: the number of frame buffers allocated for use.
+unsigned int camera_get_num_frame_buffers(p_camera_context_t cam_ctx)
+{
+	return cam_ctx->block_number;
+}
+
+// FrameBufferID is a number between 0 and N-1, where N is the total number of frame buffers in use.  Returns the address of
+// the given frame buffer.  The application will call this once for each frame buffer at application initialization only.
+void *camera_get_frame_buffer_addr(p_camera_context_t cam_ctx, unsigned int frame_buffer_id)
+{
+	return (void *) ((unsigned) cam_ctx->buffer_virtual + cam_ctx->page_aligned_block_size * frame_buffer_id);
+}
+
+// Return the block id
+int camera_get_frame_buffer_id(p_camera_context_t cam_ctx, void *address)
+{
+	if (((unsigned) address >=
+	     (unsigned) cam_ctx->buffer_virtual) &&
+	    ((unsigned) address <= (unsigned) cam_ctx->buffer_virtual + cam_ctx->buf_size)) {
+		return ((unsigned) address - (unsigned) cam_ctx->buffer_virtual) / cam_ctx->page_aligned_block_size;
+	}
+	return -1;
+}
+
+
+/***********************************************************************
+ *
+ * Frame rate APIs
+ *
+ ***********************************************************************/
+// Set desired frame rate
+void camera_set_capture_frame_rate(p_camera_context_t cam_ctx)
+{
+	ci_set_frame_rate(cam_ctx->frame_rate);
+	return;
+}
+
+// return current setting
+void camera_get_capture_frame_rate(p_camera_context_t cam_ctx)
+{
+	cam_ctx->frame_rate = ci_get_frame_rate();
+	return;
+}
+
+
+/***********************************************************************
+ *
+ * Interrupt APIs
+ *
+ ***********************************************************************/
+// set interrupt mask 
+void camera_set_int_mask(p_camera_context_t cam_ctx, unsigned int mask)
+{
+	pxa_dma_desc *end_des_virtual;
+	int dma_interrupt_on;
+	unsigned int i;
+
+	// set CI interrupt
+	ci_set_int_mask(mask & CI_CICR0_INTERRUPT_MASK);
+
+	// set dma end interrupt
+	if (mask & CAMERA_INTMASK_END_OF_DMA)
+		dma_interrupt_on = 1;
+	else
+		dma_interrupt_on = 0;
+
+	// set fifo0 dma chains' flag
+	end_des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+	for (i = 0; i < cam_ctx->block_number; i++) {
+		if (dma_interrupt_on)
+			end_des_virtual->dcmd |= DCMD_ENDIRQEN;
+		else
+			end_des_virtual->dcmd &= ~DCMD_ENDIRQEN;
+		end_des_virtual += cam_ctx->fifo0_num_descriptors;
+	}
+}
+
+// get interrupt mask 
+unsigned int camera_get_int_mask(p_camera_context_t cam_ctx)
+{
+	pxa_dma_desc *end_des_virtual;
+	unsigned int ret;
+
+	// get CI mask
+	ret = ci_get_int_mask();
+
+	// get dma end mask
+	end_des_virtual = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + cam_ctx->fifo0_num_descriptors - 1;
+	if (end_des_virtual->dcmd & DCMD_ENDIRQEN)
+		ret |= CAMERA_INTMASK_END_OF_DMA;
+
+	return ret;
+}
+
+// clear interrupt status
+void camera_clear_int_status(p_camera_context_t cam_ctx, unsigned int status)
+{
+	ci_clear_int_status((status & 0xFFFF));
+}
+
+/***********************************************************************************
+* Application interface 							   *
+***********************************************************************************/
+static int pxa_camera_open(struct video_device *dev, int flags)
+{
+	int status = -1;
+	camera_context_t *cam_ctx;
+
+	init_waitqueue_head(&camera_wait_q);
+	if (pxa_camera_mem_init()) {
+		DPRINTK("DMA memory allocate failed!");
+		return -1;
+	}
+	DPRINTK("in %s, after pxa_camera_mem_init \n", __FUNCTION__);
+	cam_ctx = g_camera_context;
+	if (atomic_read(&cam_ctx->refcount))
+		return -EBUSY;
+	atomic_inc(&cam_ctx->refcount);
+
+
+#ifdef ADCM2650
+	cam_ctx->sensor_type = CAMERA_TYPE_ADCM_2650;
+#endif
+#ifdef ADCM2700
+	cam_ctx->sensor_type = CAMERA_TYPE_ADCM_2700;
+#endif
+#ifdef OV9640
+	cam_ctx->sensor_type = CAMERA_TYPE_OMNIVISION_9640;
+#endif
+	cam_ctx->capture_width = WIDTH_DEFT;
+	cam_ctx->capture_height = HEIGHT_DEFT;
+	cam_ctx->capture_input_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+	cam_ctx->capture_output_format = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+	cam_ctx->frame_rate = FRAMERATE_DEFT;
+
+	// init function dispatch table
+#ifdef ADCM2650
+	adcm2650_func.init = camera_func_adcm2650_init;
+	adcm2650_func.deinit = camera_func_adcm2650_deinit;
+	adcm2650_func.set_capture_format = camera_func_adcm2650_set_capture_format;
+	adcm2650_func.start_capture = camera_func_adcm2650_start_capture;
+	adcm2650_func.stop_capture = camera_func_adcm2650_stop_capture;
+	cam_ctx->camera_functions = &adcm2650_func;
+#endif
+
+#ifdef ADCM2700
+	adcm2700_func.init = camera_func_adcm2700_init;
+	adcm2700_func.deinit = camera_func_adcm2700_deinit;
+	adcm2700_func.set_capture_format = camera_func_adcm2700_set_capture_format;
+	adcm2700_func.start_capture = camera_func_adcm2700_start_capture;
+	adcm2700_func.stop_capture = camera_func_adcm2700_stop_capture;
+	cam_ctx->camera_functions = &adcm2700_func;
+#endif
+
+#ifdef OV9640
+	ov9640_func.init = camera_func_ov9640_init;
+	ov9640_func.deinit = camera_func_ov9640_deinit;
+	ov9640_func.set_capture_format = camera_func_ov9640_set_capture_format;
+	ov9640_func.start_capture = camera_func_ov9640_start_capture;
+	ov9640_func.stop_capture = camera_func_ov9640_stop_capture;
+	ov9640_func.command = camera_func_ov9640_command;
+	cam_ctx->camera_functions = &ov9640_func;
+#endif
+
+	cam_ctx->ost_reg_base = 0;
+	cam_ctx->gpio_reg_base = 0;
+	cam_ctx->ci_reg_base = 0;
+	cam_ctx->board_reg_base = 0;
+	still_image_rdy = 0;
+
+	/* FIXME: handle camera_init() errors ? */
+	status = camera_init(cam_ctx);
+	DPRINTK(KERN_DEBUG PREFIX "camera opened\n");
+	status = 0;
+	return status;
+}
+
+static void pxa_camera_close(struct video_device *dev)
+{
+	camera_context_t *cam_ctx = g_camera_context;
+
+	DPRINTK(KERN_DEBUG PREFIX "camera closed\n");
+	atomic_dec(&cam_ctx->refcount);
+	camera_deinit(cam_ctx);
+	pxa_camera_mem_deinit();
+}
+
+#define PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, size) \
+do { \
+	unsigned int len; \
+	unsigned int remain_size = size; \
+	while (remain_size > 0) { \
+		if (remain_size > PAGE_SIZE) \
+			len = PAGE_SIZE; \
+		else \
+			len = remain_size; \
+		if (copy_to_user(buf, page_address(*p_page), len)) \
+			return -EFAULT; \
+		remain_size -= len; \
+		buf += len; \
+		p_page++; \
+	} \
+} while (0);
+
+
+static long pxa_camera_read(struct video_device *dev, char *buf, unsigned long count, int noblock)
+{
+	struct page **p_page;
+
+	camera_context_t *cam_ctx = g_camera_context;
+
+	if (still_image_mode == 1) {
+		while (still_image_rdy != 1)
+			mdelay(1);
+		/*
+		   if (cam_ctx->capture_width ==1280 && cam_ctx->capture_height==960)
+		   cam_ctx->block_tail = cam_ctx->block_header = 0;
+		   else if (cam_ctx->capture_width==960 && cam_ctx->capture_height==480)
+		   cam_ctx->block_tail = cam_ctx->block_header = 2;
+		   DPRINTK("cam_ctx->block_number =%d \n",cam_ctx->block_number);
+		   cam_ctx->camera_functions->stop_capture(cam_ctx);
+		 */
+		p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+		PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+
+		still_image_rdy = 0;
+		return cam_ctx->block_size;
+	}
+	if (still_image_mode == 0) {
+		if (first_video_frame == 1)
+			cam_ctx->block_tail = cam_ctx->block_header;
+		else
+			cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+	}
+
+	first_video_frame = 0;
+
+	if (cam_ctx->block_header == cam_ctx->block_tail) {
+		if (still_image_mode == 0) {
+			task_waiting = 1;
+			interruptible_sleep_on(&camera_wait_q);
+		} else {
+			while (still_image_rdy != 1) {
+				DPRINTK("wait still_image_rdy =1 \n");
+				mdelay(1);
+			}
+		}
+	}
+
+	p_page = &cam_ctx->page_array[cam_ctx->block_tail * cam_ctx->pages_per_block];
+
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo0_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo1_transfer_size);
+	PXA_CAMERA_BUFFER_COPY_TO_USER(buf, p_page, cam_ctx->fifo2_transfer_size);
+
+	return cam_ctx->block_size;
+}
+
+int camera_sleep()
+{
+	interruptible_sleep_on(&camera_wait_q);
+}
+
+struct reg_set_s {
+	int val1;
+	int val2;
+};
+
+static int pxa_camera_ioctl(struct video_device *dev, unsigned int cmd, void *param)
+{
+	int retval = 0;
+	camera_context_t *cam_ctx = g_camera_context;
+
+	switch (cmd) {
+/* V4L Standard IOCTL. */
+	case VIDIOCGCAP:
+	{
+		struct video_capability vc;
+		strcpy(vc.name, "Bulverde Camera");
+		vc.maxwidth = MAX_WIDTH;
+		vc.maxheight = MAX_HEIGHT;
+#ifdef OV9640
+		vc.maxwidth = 1280;
+		vc.maxheight = 960;
+#endif
+		vc.minwidth = MIN_WIDTH;
+		vc.minheight = MIN_HEIGHT;
+		if (copy_to_user(param, &vc, sizeof(struct video_capability)))
+			return -EFAULT;
+		break;
+	}
+
+
+	case VIDIOCSPICT:
+	{
+		struct video_picture vp;
+		if (copy_from_user(&vp, param, sizeof(vp))) {
+			retval = -EFAULT;
+			break;
+		}
+		cam_ctx->capture_output_format = vp.palette;
+		retval = camera_set_capture_format(cam_ctx);
+		break;
+	}
+	case VIDIOCGPICT:
+	{
+		struct video_picture vp;
+		vp.palette = cam_ctx->capture_output_format;
+		if (copy_to_user(param, &vp, sizeof(struct video_picture)))
+			retval = -EFAULT;
+		break;
+	}
+
+	case VIDIOCCAPTURE:
+	{
+		int capture_flag;
+
+		capture_flag = (int) param;
+/* Still Image Capture */
+		if (capture_flag == STILL_IMAGE) {
+			camera_set_int_mask(cam_ctx, 0x3ff | 0x0400);
+			still_image_mode = 1;
+			task_waiting = 0;
+			camera_capture_still_image(cam_ctx, 0);
+			cam_ctx->block_header = 0;
+			cam_ctx->block_tail = 0;
+			break;
+		}
+/* Video Capture Start */
+		else if (capture_flag == VIDEO_START) {
+			camera_set_int_mask(cam_ctx, 0x3ff | 0x0400);
+			cam_ctx->block_header = 0;
+			cam_ctx->block_tail = 0;
+			still_image_mode = 0;
+			first_video_frame = 1;
+			camera_start_video_capture(cam_ctx, 0);
+			break;
+		}
+/* Video Capture Stop */
+		else if (capture_flag == VIDEO_STOP) {
+			camera_set_int_mask(cam_ctx, 0x3ff);
+			camera_stop_video_capture(cam_ctx);
+			break;
+		} else {
+			retval = -EFAULT;
+			break;
+		}
+	}
+
+/* mmap interface */
+	case VIDIOCGMBUF:
+	{
+		struct video_mbuf vm;
+		int i;
+
+		memset(&vm, 0, sizeof(vm));
+		vm.size = cam_ctx->buf_size;
+		vm.frames = cam_ctx->block_number;
+		for (i = 0; i < vm.frames; i++)
+			vm.offsets[i] = cam_ctx->page_aligned_block_size * i;
+
+		if (copy_to_user((void *) param, (void *) &vm, sizeof(vm)))
+			retval = -EFAULT;
+		break;
+	}
+
+/* Application extended IOCTL.  */
+/* Register access interface	*/
+	case WCAM_VIDIOCSINFOR:
+	{
+		struct reg_set_s reg_s;
+		if (copy_from_user(&reg_s, param, sizeof(int) * 2)) {
+			retval = -EFAULT;
+			break;
+		}
+		cam_ctx->capture_input_format = reg_s.val1;
+		cam_ctx->capture_output_format = reg_s.val2;
+
+		retval = camera_set_capture_format(cam_ctx);
+		DPRINTK("WCAM_VIDIOCSINFOR retval=%d\n", retval);
+		break;
+	}
+
+	case WCAM_VIDIOCGINFOR:
+	{
+		struct reg_set_s reg_s;
+		reg_s.val1 = cam_ctx->capture_input_format;
+		reg_s.val2 = cam_ctx->capture_output_format;
+		if (copy_to_user(param, &reg_s, sizeof(int) * 2))
+			retval = -EFAULT;
+		break;
+	}
+
+	case WCAM_VIDIOCGCIREG:
+	{
+		struct reg_set_s reg_s;
+		if (copy_from_user(&reg_s, param, sizeof(int) * 2)) {
+			retval = -EFAULT;
+			break;
+		}
+
+		reg_s.val2 = ci_get_reg_value(reg_s.val1);
+		if (copy_to_user(param, &reg_s, sizeof(int) * 2))
+			retval = -EFAULT;
+		break;
+	}
+
+	case WCAM_VIDIOCSCIREG:
+	{
+		struct reg_set_s reg_s;
+		if (copy_from_user(&reg_s, param, sizeof(int) * 2)) {
+			retval = -EFAULT;
+			break;
+		}
+		ci_set_reg_value(reg_s.val1, reg_s.val2);
+		break;
+	}
+
+	case WCAM_VIDIOCGCAMREG:
+	{
+		struct reg_set_s reg_s;
+		if (copy_from_user(&reg_s, param, sizeof(int) * 2)) {
+			retval = -EFAULT;
+			break;
+		}
+		sensor_pipeline_read((u16) reg_s.val1, (u16 *) & reg_s.val2);
+		DPRINTK("WCAM_VIDIOCGCAMREG reg.val1=0x%x,reg.val2=0x%x\n", reg_s.val1, reg_s.val2);
+		if (copy_to_user(param, &reg_s, sizeof(int) * 2))
+			retval = -EFAULT;
+		ci_dump();
+		break;
+	}
+
+	case WCAM_VIDIOCSCAMREG:
+	{
+		struct reg_set_s reg_s;
+		if (copy_from_user(&reg_s, param, sizeof(int) * 2)) {
+			retval = -EFAULT;
+			break;
+		}
+		sensor_pipeline_write((u16) reg_s.val1, (u16) reg_s.val2);
+		break;
+	}
+		/*set frame buffer count */
+	case WCAM_VIDIOCSBUFCOUNT:
+	{
+		int count;
+		if (copy_from_user(&count, param, sizeof(int))) {
+			return -EFAULT;
+		}
+		if (cam_ctx->block_number_max == 0) {
+			dbg_print("windows size or format not setting!!");
+			return -EFAULT;
+		}
+
+		if (count >= FRAMES_IN_BUFFER && count <= cam_ctx->block_number_max) {
+			cam_ctx->block_number = count;
+			cam_ctx->block_header = cam_ctx->block_tail = 0;
+			// generate dma descriptor chain
+			update_dma_chain(cam_ctx);
+		}
+
+		count = cam_ctx->block_number;
+
+		if (copy_to_user(param, &count, sizeof(int))) {
+			return -EFAULT;
+		}
+
+	}
+		break;
+		/*get cur avaliable frames */
+	case WCAM_VIDIOCGCURFRMS:
+	{
+		struct {
+			int first, last;
+		} pos;
+		pos.first = cam_ctx->block_tail;
+		pos.last = cam_ctx->block_header;
+
+		if (copy_to_user(param, &pos, sizeof(pos))) {
+			return -EFAULT;
+		}
+	}
+
+		break;
+
+	default:
+	{
+		int ret;
+		DPRINTK("in _ioctl default command,param=%d!!!!!!!!!!!!!!!!!!!!\n", param);
+		ret = cam_ctx->camera_functions->command(cam_ctx, cmd, param);
+		DPRINTK("cam_ctx->camera_functions->command ret=%d\n", ret);
+		retval = ret;
+		if (ret) {
+			DPRINTK(KERN_WARNING PREFIX "invalid ioctl %x\n", cmd);
+			retval = -ENOIOCTLCMD;
+		}
+		break;
+	}
+	}
+	return retval;
+}
+
+static int pxa_camera_mmap(struct video_device *dev, const char *adr, unsigned long size)
+{
+	unsigned long start = (unsigned long) adr;
+	camera_context_t *cam_ctx = g_camera_context;
+	struct page **p_page = cam_ctx->page_array;
+
+	size = PAGE_ALIGN(size);
+	while (size > 0) {
+		if (remap_page_range(start, page_to_phys(*p_page), PAGE_SIZE, PAGE_SHARED)) {
+			return -EFAULT;
+		}
+		start += PAGE_SIZE;
+		p_page++;
+		size -= PAGE_SIZE;
+	}
+	return 0;
+}
+
+unsigned int pxa_camera_poll(struct video_device *dev, struct file *file, poll_table * wait)
+{
+	camera_context_t *cam_ctx = g_camera_context;
+	static int waited = 0;
+
+	poll_wait(file, &camera_wait_q, wait);
+
+	if (still_image_mode == 1)
+		if (still_image_rdy == 1) {
+			still_image_rdy = 0;
+			write_balance();
+			return POLLIN | POLLRDNORM;
+		}
+	//else
+	//    return 0;
+	if (first_video_frame == 1)
+		first_video_frame = 0;
+	else if (still_image_mode == 0 && waited != 1)
+		cam_ctx->block_tail = (cam_ctx->block_tail + 1) % cam_ctx->block_number;
+
+	if (cam_ctx->block_header == cam_ctx->block_tail) {
+		DPRINTK("enter poll waiting, tail = %d, header = %d \n", cam_ctx->block_tail, cam_ctx->block_header);
+		task_waiting = 1;
+		waited = 1;
+		//interruptible_sleep_on(&camera_wait_q);
+		return 0;
+	} else
+		waited = 0;
+
+	write_balance();
+	return POLLIN | POLLRDNORM;
+}
+
+
+int pxa_camera_video_init(struct video_device *vdev)
+{
+	DPRINTK(KERN_DEBUG PREFIX "camera initialized\n");
+	return 0;
+}
+
+
+static struct video_device vd = {
+	owner:THIS_MODULE,
+	name:"PXA Camera",
+	type:VID_TYPE_CAPTURE,
+	hardware:VID_HARDWARE_PXA_CAMERA,	/* FIXME */
+	open:pxa_camera_open,
+	close:pxa_camera_close,
+	read:pxa_camera_read,
+	poll:pxa_camera_poll,
+	ioctl:pxa_camera_ioctl,
+	mmap:pxa_camera_mmap,
+	initialize:pxa_camera_video_init,
+	minor:-1,
+};
+
+int pxa_camera_mem_deinit()
+{
+	camera_context_t *cam_ctx = g_camera_context;
+	if (ci_regs_base)
+		iounmap((unsigned long *) ci_regs_base);
+	if (g_camera_context) {
+		if (cam_ctx->dma_descriptors_virtual) {
+			consistent_free(cam_ctx->dma_descriptors_virtual,
+					MAX_DESC_NUM * sizeof(pxa_dma_desc), (int) cam_ctx->dma_descriptors_physical);
+			g_camera_context->dma_descriptors_virtual = NULL;
+		}
+
+		if (cam_ctx->buffer_virtual) {
+			pxa_dma_buffer_free(cam_ctx);
+			g_camera_context->buffer_virtual = NULL;
+
+		}
+
+		kfree(g_camera_context);
+		g_camera_context = NULL;
+	}
+	return 0;
+}
+
+int pxa_camera_mem_init()
+{
+	p_camera_context_t cam_ctx;
+	(unsigned long *) ci_regs_base = (unsigned long *) ioremap(CI_REGS_PHYS, CI_REG_SIZE);
+	if (!ci_regs_base) {
+		DPRINTK(KERN_ERR PREFIX "can't remap I/O registers at %x\n", CI_REGS_PHYS);
+		return -1;
+	}
+
+	cam_ctx = (camera_context_t *)
+	    kmalloc(sizeof(struct camera_context_s), GFP_KERNEL);
+	if (cam_ctx == NULL) {
+		DPRINTK(KERN_WARNING PREFIX "can't allocate buffer for camera control structure\n");
+		return -1;
+	}
+	g_camera_context = cam_ctx;
+	memset(g_camera_context, 0, sizeof(struct camera_context_s));
+	atomic_set(&cam_ctx->refcount, 0);
+	cam_ctx->dma_started = 0;
+
+	cam_ctx->dma_descriptors_virtual =
+	    consistent_alloc(GFP_KERNEL, MAX_DESC_NUM * sizeof(pxa_dma_desc),
+			     (void *) &cam_ctx->dma_descriptors_physical);
+	if (cam_ctx->dma_descriptors_virtual == NULL) {
+		DPRINTK(KERN_WARNING PREFIX
+		       "memory allocation for DMA descriptors (%ld bytes) failed\n",
+		       MAX_DESC_NUM * sizeof(pxa_dma_desc));
+		goto err_mem;
+	}
+
+	cam_ctx->buf_size = BUF_SIZE_DEFT;
+
+	if (pxa_dma_buffer_init(cam_ctx) != 0) {
+		DPRINTK(KERN_WARNING PREFIX
+		       "memory allocation for capture buffer (%d bytes) failed\n", cam_ctx->buf_size);
+		goto err_mem;
+	}
+
+	cam_ctx->dma_descriptors_size = MAX_DESC_NUM;
+	return 0;
+      err_mem:
+	pxa_camera_mem_deinit();
+	return -ENXIO;
+}
+
+static int __init pxa_camera_init(void)
+{
+	camera_context_t *cam_ctx = NULL;
+	int err;
+
+	/* 1. mapping CI registers, so that we can access the CI */
+	if ((err = request_irq(IRQ_CAMERA, pxa_camera_irq, 0, "PXA Camera", &vd))) {
+		DPRINTK(KERN_WARNING PREFIX "camera interrupt register failed, error %d\n", err);
+		return -ENXIO;
+	}
+	ci_dma_y = pxa_request_dma("CI_Y", DMA_PRIO_HIGH, pxa_ci_dma_irq_y, &vd);
+	if (ci_dma_y < 0) {
+		DPRINTK(KERN_WARNING PREFIX "can't request DMA for Y\n");
+		goto err_init;
+	}
+	ci_dma_cb = pxa_request_dma("CI_Cb", DMA_PRIO_HIGH, pxa_ci_dma_irq_cb, &vd);
+	if (ci_dma_cb < 0) {
+		DPRINTK(KERN_WARNING PREFIX "can't request DMA for Cb\n");
+		goto err_init;
+	}
+	ci_dma_cr = pxa_request_dma("CI_Cr", DMA_PRIO_HIGH, pxa_ci_dma_irq_cr, &vd);
+	if (ci_dma_cr < 0) {
+		DPRINTK(KERN_WARNING PREFIX "can't request DMA for Cr\n");
+		goto err_init;
+	}
+
+	DRCMR68 = ci_dma_y | DRCMR_MAPVLD;
+	DRCMR69 = ci_dma_cb | DRCMR_MAPVLD;
+	DRCMR70 = ci_dma_cr | DRCMR_MAPVLD;
+
+
+	if (video_register_device(&vd, VFL_TYPE_GRABBER, minor) < 0) {
+		DPRINTK(KERN_WARNING PREFIX "can't register video device\n");
+		goto err_init;
+	}
+#ifdef CONFIG_DPM
+	pxa_camera_ldm_register();
+#endif
+#ifdef CONFIG_PM
+	pm_dev = pm_register(PM_SYS_DEV, 0, camera_pm_callback);
+#endif
+
+
+	DPRINTK(KERN_NOTICE PREFIX "video device registered, use device /dev/video%d \n", minor);
+	return 0;
+
+      err_init:
+	free_irq(IRQ_CAMERA, &vd);
+
+	if (ci_dma_y >= 0)
+		pxa_free_dma(ci_dma_y);
+
+	if (ci_dma_cb >= 0)
+		pxa_free_dma(ci_dma_cb);
+
+	if (ci_dma_cr >= 0)
+		pxa_free_dma(ci_dma_cr);
+
+	DRCMR68 = 0;
+	DRCMR69 = 0;
+	DRCMR70 = 0;
+
+	return 0;
+}
+
+static void __exit pxa_camera_exit(void)
+{
+	camera_context_t *cam_ctx = g_camera_context;
+#ifdef CONFIG_DPM
+	pxa_camera_ldm_unregister();
+#endif
+#ifdef CONFIG_PM
+	pm_unregister(pm_dev);
+#endif
+
+	video_unregister_device(&vd);
+
+	free_irq(IRQ_CAMERA, &vd);
+
+	if (ci_dma_y >= 0)
+		pxa_free_dma(ci_dma_y);
+
+	if (ci_dma_cb >= 0)
+		pxa_free_dma(ci_dma_cb);
+
+	if (ci_dma_cr >= 0)
+		pxa_free_dma(ci_dma_cr);
+
+	DRCMR68 = 0;
+	DRCMR69 = 0;
+	DRCMR70 = 0;
+
+	pxa_camera_mem_deinit();
+
+}
+
+//-------------------------------------------------------------------------------------------------------
+//      Configuration APIs
+//-------------------------------------------------------------------------------------------------------
+void ci_set_frame_rate(CI_FRAME_CAPTURE_RATE frate)
+{
+	unsigned int value;
+
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_FR_RATE_SMASK << CI_CICR4_FR_RATE_SHIFT);
+	value |= (unsigned) frate << CI_CICR4_FR_RATE_SHIFT;
+	CICR4 = value;
+}
+
+CI_FRAME_CAPTURE_RATE ci_get_frame_rate(void)
+{
+	unsigned int value;
+	value = CICR4;
+	return (CI_FRAME_CAPTURE_RATE) ((value >> CI_CICR4_FR_RATE_SHIFT) & CI_CICR4_FR_RATE_SMASK);
+}
+
+void ci_set_image_format(CI_IMAGE_FORMAT input_format, CI_IMAGE_FORMAT output_format)
+{
+	unsigned int value, tbit, rgbt_conv, rgb_conv, rgb_f, ycbcr_f, rgb_bpp, raw_bpp, cspace;
+
+	// write cicr1: preserve ppl value and data width value
+	value = CICR1;
+	value &= ((CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT) | ((CI_CICR1_DW_SMASK) << CI_CICR1_DW_SHIFT));
+	tbit = rgbt_conv = rgb_conv = rgb_f = ycbcr_f = rgb_bpp = raw_bpp = cspace = 0;
+	switch (input_format) {
+	case CI_RAW8:
+		cspace = 0;
+		raw_bpp = 0;
+		break;
+	case CI_RAW9:
+		cspace = 0;
+		raw_bpp = 1;
+		break;
+	case CI_RAW10:
+		cspace = 0;
+		raw_bpp = 2;
+		break;
+	case CI_YCBCR422:
+	case CI_YCBCR422_PLANAR:
+		cspace = 2;
+		if (output_format == CI_YCBCR422_PLANAR) {
+			ycbcr_f = 1;
+		}
+		break;
+	case CI_RGB444:
+		cspace = 1;
+		rgb_bpp = 0;
+		break;
+	case CI_RGB555:
+		cspace = 1;
+		rgb_bpp = 1;
+		if (output_format == CI_RGBT555_0) {
+			rgbt_conv = 2;
+			tbit = 0;
+		} else if (output_format == CI_RGBT555_1) {
+			rgbt_conv = 2;
+			tbit = 1;
+		}
+		break;
+	case CI_RGB565:
+		cspace = 1;
+		rgb_bpp = 2;
+		rgb_f = 1;
+		break;
+	case CI_RGB666:
+		cspace = 1;
+		rgb_bpp = 3;
+		if (output_format == CI_RGB666_PACKED) {
+			rgb_f = 1;
+		}
+		break;
+	case CI_RGB888:
+	case CI_RGB888_PACKED:
+		cspace = 1;
+		rgb_bpp = 4;
+		switch (output_format) {
+		case CI_RGB888_PACKED:
+			rgb_f = 1;
+			break;
+		case CI_RGBT888_0:
+			rgbt_conv = 1;
+			tbit = 0;
+			break;
+		case CI_RGBT888_1:
+			rgbt_conv = 1;
+			tbit = 1;
+			break;
+		case CI_RGB666:
+			rgb_conv = 1;
+			break;
+// RGB666 PACKED - JamesL
+		case CI_RGB666_PACKED:
+			rgb_conv = 1;
+			rgb_f = 1;
+			break;
+// end
+		case CI_RGB565:
+			rgb_conv = 2;
+			break;
+		case CI_RGB555:
+			rgb_conv = 3;
+			break;
+		case CI_RGB444:
+			rgb_conv = 4;
+			break;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+	value |= (tbit == 1) ? CI_CICR1_TBIT : 0;
+	value |= rgbt_conv << CI_CICR1_RGBT_CONV_SHIFT;
+	value |= rgb_conv << CI_CICR1_RGB_CONV_SHIFT;
+	value |= (rgb_f == 1) ? CI_CICR1_RBG_F : 0;
+	value |= (ycbcr_f == 1) ? CI_CICR1_YCBCR_F : 0;
+	value |= rgb_bpp << CI_CICR1_RGB_BPP_SHIFT;
+	value |= raw_bpp << CI_CICR1_RAW_BPP_SHIFT;
+	value |= cspace << CI_CICR1_COLOR_SP_SHIFT;
+	CICR1 = value;
+
+	return;
+}
+
+void ci_set_mode(CI_MODE mode, CI_DATA_WIDTH data_width)
+{
+	unsigned int value;
+
+	// write mode field in cicr0
+	value = CICR0;
+	value &= ~(CI_CICR0_SIM_SMASK << CI_CICR0_SIM_SHIFT);
+	value |= (unsigned int) mode << CI_CICR0_SIM_SHIFT;
+	CICR0 = value;
+
+	// write data width cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_DW_SMASK << CI_CICR1_DW_SHIFT);
+	value |= ((unsigned) data_width) << CI_CICR1_DW_SHIFT;
+	CICR1 = value;
+	return;
+}
+
+void ci_configure_mp(unsigned int ppl, unsigned int lpf, CI_MP_TIMING * timing)
+{
+	unsigned int value;
+
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;
+
+	// write BLW, ELW in cicr2  
+	value = CICR2;
+	value &= ~(CI_CICR2_BLW_SMASK << CI_CICR2_BLW_SHIFT | CI_CICR2_ELW_SMASK << CI_CICR2_ELW_SHIFT);
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	CICR2 = value;
+
+	// write BFW, LPF in cicr3
+	value = CICR3;
+	value &= ~(CI_CICR3_BFW_SMASK << CI_CICR3_BFW_SHIFT | CI_CICR3_LPF_SMASK << CI_CICR3_LPF_SHIFT);
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;
+	return;
+}
+
+void ci_configure_sp(unsigned int ppl, unsigned int lpf, CI_SP_TIMING * timing)
+{
+	unsigned int value;
+
+	// write ppl field in cicr1
+	value = CICR1;
+	value &= ~(CI_CICR1_PPL_SMASK << CI_CICR1_PPL_SHIFT);
+	value |= (ppl & CI_CICR1_PPL_SMASK) << CI_CICR1_PPL_SHIFT;
+	CICR1 = value;
+
+	// write cicr2
+	value = CICR2;
+	value |= (timing->BLW & CI_CICR2_BLW_SMASK) << CI_CICR2_BLW_SHIFT;
+	value |= (timing->ELW & CI_CICR2_ELW_SMASK) << CI_CICR2_ELW_SHIFT;
+	value |= (timing->HSW & CI_CICR2_HSW_SMASK) << CI_CICR2_HSW_SHIFT;
+	value |= (timing->BFPW & CI_CICR2_BFPW_SMASK) << CI_CICR2_BFPW_SHIFT;
+	value |= (timing->FSW & CI_CICR2_FSW_SMASK) << CI_CICR2_FSW_SHIFT;
+	CICR2 = value;
+
+	// write cicr3
+	value = CICR3;
+	value |= (timing->BFW & CI_CICR3_BFW_SMASK) << CI_CICR3_BFW_SHIFT;
+	value |= (timing->EFW & CI_CICR3_EFW_SMASK) << CI_CICR3_EFW_SHIFT;
+	value |= (timing->VSW & CI_CICR3_VSW_SMASK) << CI_CICR3_VSW_SHIFT;
+	value |= (lpf & CI_CICR3_LPF_SMASK) << CI_CICR3_LPF_SHIFT;
+	CICR3 = value;
+	return;
+}
+
+void ci_configure_ms(unsigned int ppl, unsigned int lpf, CI_MS_TIMING * timing)
+{
+	// the operation is same as Master-Parallel
+	ci_configure_mp(ppl, lpf, (CI_MP_TIMING *) timing);
+}
+
+void ci_configure_ep(int parity_check)
+{
+	unsigned int value;
+
+	// write parity_enable field in cicr0   
+	value = CICR0;
+	if (parity_check) {
+		value |= CI_CICR0_PAR_EN;
+	} else {
+		value &= ~CI_CICR0_PAR_EN;
+	}
+	CICR0 = value;
+	return;
+}
+
+void ci_configure_es(int parity_check)
+{
+	// the operationi is same as Embedded-Parallel
+	ci_configure_ep(parity_check);
+}
+
+void ci_set_clock(unsigned int clk_regs_base, int pclk_enable, int mclk_enable, unsigned int mclk_khz)
+{
+	unsigned int ciclk = 0, value, div, cccr_l, K;
+
+	// determine the LCLK frequency programmed into the CCCR.
+	cccr_l = (CCCR & 0x0000001F);
+
+	if (cccr_l < 8)		// L = [2 - 7]
+		ciclk = (13 * cccr_l) * 100;
+	else if (cccr_l < 17)	// L = [8 - 16]
+		ciclk = ((13 * cccr_l) * 100) >> 1;
+	else if (cccr_l < 32)	// L = [17 - 31]
+		ciclk = ((13 * cccr_l) * 100) >> 2;
+	DPRINTK("the mclk_khz = %d \n", mclk_khz);
+
+	// want a divisor that gives us a clock rate as close to, but not more than the given mclk.
+	div = (ciclk + mclk_khz) / (2 * mclk_khz) - 1;
+
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCLK_EN | CI_CICR4_MCLK_EN | CI_CICR4_DIV_SMASK << CI_CICR4_DIV_SHIFT);
+	value |= (pclk_enable) ? CI_CICR4_PCLK_EN : 0;
+	value |= (mclk_enable) ? CI_CICR4_MCLK_EN : 0;
+	value |= div << CI_CICR4_DIV_SHIFT;
+	CICR4 = value;
+	return;
+}
+
+
+void ci_set_polarity(int pclk_sample_falling, int hsync_active_low, int vsync_active_low)
+{
+	unsigned int value;
+
+	// write cicr4
+	value = CICR4;
+	value &= ~(CI_CICR4_PCP | CI_CICR4_HSP | CI_CICR4_VSP);
+	value |= (pclk_sample_falling) ? CI_CICR4_PCP : 0;
+	value |= (hsync_active_low) ? CI_CICR4_HSP : 0;
+	value |= (vsync_active_low) ? CI_CICR4_VSP : 0;
+	CICR4 = value;
+	return;
+}
+
+void ci_set_fifo(unsigned int timeout, CI_FIFO_THRESHOLD threshold, int fifo1_enable, int fifo2_enable)
+{
+	unsigned int value;
+
+	// write citor
+	CITOR = timeout;
+
+	// write cifr: always enable fifo 0! also reset input fifo 
+	value = CIFR;
+	value &= ~(CI_CIFR_FEN0 | CI_CIFR_FEN1 | CI_CIFR_FEN2 | CI_CIFR_RESETF |
+		   CI_CIFR_THL_0_SMASK << CI_CIFR_THL_0_SHIFT);
+	value |= (unsigned int) threshold << CI_CIFR_THL_0_SHIFT;
+	value |= (fifo1_enable) ? CI_CIFR_FEN1 : 0;
+	value |= (fifo2_enable) ? CI_CIFR_FEN2 : 0;
+	value |= CI_CIFR_RESETF | CI_CIFR_FEN0;
+	CIFR = value;
+	return;
+}
+
+void ci_reset_fifo()
+{
+	unsigned int value;
+	value = CIFR;
+	value |= CI_CIFR_RESETF;
+	CIFR = value;
+}
+
+void ci_set_int_mask(unsigned int mask)
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_INTERRUPT_MASK;
+	value |= (mask & CI_CICR0_INTERRUPT_MASK);
+	CICR0 = value;
+	return;
+}
+
+unsigned int ci_get_int_mask()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	return (value & CI_CICR0_INTERRUPT_MASK);
+}
+
+void ci_clear_int_status(unsigned int status)
+{
+	// write 1 to clear
+	CISR = status;
+}
+
+unsigned int ci_get_int_status()
+{
+	int value;
+
+	value = CISR;
+
+	return value;
+}
+
+void ci_set_reg_value(unsigned int reg_offset, unsigned int value)
+{
+	CI_REG((u32) (ci_regs_base) + reg_offset) = value;
+}
+
+int ci_get_reg_value(unsigned int reg_offset)
+{
+	int value;
+
+	value = CI_REG((u32) (ci_regs_base) + reg_offset);
+	return value;
+}
+
+//-------------------------------------------------------------------------------------------------------
+//  Control APIs
+//-------------------------------------------------------------------------------------------------------
+int ci_init()
+{
+	// clear all CI registers
+	CICR0 = 0x3FF;		// disable all interrupts
+	CICR1 = 0;
+	CICR2 = 0;
+	CICR3 = 0;
+	CICR4 = 0;
+	CISR = ~0;
+	CIFR = 0;
+	CITOR = 0;
+
+	// enable CI clock
+	CKEN |= CKEN24_CAMERA;
+	return 0;
+}
+
+void ci_deinit()
+{
+	// disable CI clock
+	CKEN &= ~CKEN24_CAMERA;
+}
+
+void ci_enable(int dma_en)
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_ENB;
+	if (dma_en) {
+		value |= CI_CICR0_DMA_EN;
+	}
+	CICR0 = value;
+	return;
+}
+
+int ci_disable(int quick)
+{
+	volatile unsigned int value, mask;
+	int retry;
+
+	// write control bit in cicr0   
+	value = CICR0;
+	if (quick) {
+		value &= ~CI_CICR0_ENB;
+		mask = CI_CISR_CQD;
+	} else {
+		value |= CI_CICR0_DIS;
+		mask = CI_CISR_CDD;
+	}
+	CICR0 = value;
+
+	// wait shutdown complete
+	retry = 50;
+	while (retry-- > 0) {
+		value = CISR;
+		if (value & mask) {
+			CISR = mask;
+			return 0;
+		}
+		mdelay(10);
+	}
+
+	return -1;
+}
+
+void ci_slave_capture_enable()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value |= CI_CICR0_SL_CAP_EN;
+	CICR0 = value;
+	return;
+}
+
+void ci_slave_capture_disable()
+{
+	unsigned int value;
+
+	// write mask in cicr0  
+	value = CICR0;
+	value &= ~CI_CICR0_SL_CAP_EN;
+	CICR0 = value;
+	return;
+}
+
+void pxa_ci_dma_irq_y(int channel, void *data, struct pt_regs *regs)
+{
+	int dcsr;
+	static int dma_repeated = 0;
+	static unsigned int count = 0;
+
+	camera_context_t *cam_ctx = g_camera_context;
+
+	dcsr = DCSR(channel);
+	DCSR(channel) = dcsr & ~DCSR_STOPIRQEN;
+	if (!((count++) % 100))
+		DPRINTK("int occure\n");
+	if (still_image_mode == 1) {
+		DPRINTK("pxa_ci_dma_irq_y interrupt,task_waiting =%d, still_image_rdy=%d\n",
+		       task_waiting, still_image_rdy);
+		if (task_waiting == 1) {
+			DPRINTK("task waiting");
+			wake_up_interruptible(&camera_wait_q);
+			task_waiting = 0;
+		}
+		still_image_rdy = 1;
+	} else if (dma_repeated == 0 && (cam_ctx->block_tail == ((cam_ctx->block_header + 2) % cam_ctx->block_number))) {
+		dma_repeated = 1;
+		pxa_dma_repeat(cam_ctx);
+		cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+	} else if (dma_repeated == 1 && (cam_ctx->block_tail != ((cam_ctx->block_header + 1) % cam_ctx->block_number))
+		   && (cam_ctx->block_tail != ((cam_ctx->block_header + 2) % cam_ctx->block_number))) {
+		pxa_dma_continue(cam_ctx);
+		dma_repeated = 0;
+	} else if (dma_repeated == 0) {
+		cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+	}
+	if (task_waiting == 1 && !(cam_ctx->block_header == cam_ctx->block_tail)) {
+		wake_up_interruptible(&camera_wait_q);
+		task_waiting = 0;
+	}
+}
+
+void pxa_ci_dma_irq_cb(int channel, void *data, struct pt_regs *regs)
+{
+	return;
+}
+
+void pxa_ci_dma_irq_cr(int channel, void *data, struct pt_regs *regs)
+{
+	return;
+}
+
+inline static void pxa_ci_dma_stop(camera_context_t * cam_ctx)
+{
+	int ch0, ch1, ch2;
+
+	ch0 = cam_ctx->dma_channels[0];
+	ch1 = cam_ctx->dma_channels[1];
+	ch2 = cam_ctx->dma_channels[2];
+	DCSR(ch0) &= ~DCSR_RUN;
+	DCSR(ch1) &= ~DCSR_RUN;
+	DCSR(ch2) &= ~DCSR_RUN;
+}
+
+
+void pxa_dma_start(camera_context_t * cam_ctx)
+{
+	unsigned char cnt_blk;
+	pxa_dma_desc *cnt_desc;
+
+	cam_ctx->block_header = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+	cnt_blk = (unsigned char) cam_ctx->block_header;
+
+	cnt_desc = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_physical + cnt_blk * cam_ctx->fifo0_num_descriptors;
+
+	DDADR(cam_ctx->dma_channels[0]) = cnt_desc;
+	DCSR(cam_ctx->dma_channels[0]) |= DCSR_RUN;
+
+	if (cam_ctx->fifo1_num_descriptors) {
+		cnt_desc =
+		    (pxa_dma_desc *) cam_ctx->fifo1_descriptors_physical + cnt_blk * cam_ctx->fifo1_num_descriptors;
+		DDADR(cam_ctx->dma_channels[1]) = cnt_desc;
+		DCSR(cam_ctx->dma_channels[1]) |= DCSR_RUN;
+	}
+
+	if (cam_ctx->fifo2_num_descriptors) {
+		cnt_desc =
+		    (pxa_dma_desc *) cam_ctx->fifo2_descriptors_physical + cnt_blk * cam_ctx->fifo2_num_descriptors;
+		DDADR(cam_ctx->dma_channels[2]) = cnt_desc;
+		DCSR(cam_ctx->dma_channels[2]) |= DCSR_RUN;
+	}
+
+	return;
+}
+
+
+void pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs)
+{
+	int cisr;
+	static int dma_started = 0;
+
+	disable_irq(IRQ_CAMERA);
+
+	cisr = CISR;
+	if (cisr & CI_CISR_SOF) {
+		DPRINTK("CI_CISR_SOF \n");
+		if (dma_started == 0) {
+			dma_started = 1;
+		}
+		CISR |= CI_CISR_SOF;
+	}
+	if (cisr & CI_CISR_EOF) {
+		DPRINTK("CI_CISR_EOF\n");
+		CISR |= CI_CISR_EOF;
+		//wake_up_interruptible(&camera_wait_q);
+	}
+	enable_irq(IRQ_CAMERA);
+}
+
+void pxa_dma_repeat(camera_context_t * cam_ctx)
+{
+	pxa_dma_desc *cnt_head, *cnt_tail;
+	int cnt_block;
+
+	cnt_block = (cam_ctx->block_header + 1) % cam_ctx->block_number;
+// FIFO0
+	(pxa_dma_desc *) cnt_head =
+	    (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + cnt_block * cam_ctx->fifo0_num_descriptors;
+	cnt_tail = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+	cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+// FIFO1
+	if (cam_ctx->fifo1_transfer_size) {
+		cnt_head =
+		    (pxa_dma_desc *) cam_ctx->fifo1_descriptors_virtual + cnt_block * cam_ctx->fifo1_num_descriptors;
+		cnt_tail = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+// FIFO2
+	if (cam_ctx->fifo2_transfer_size) {
+		cnt_head =
+		    (pxa_dma_desc *) cam_ctx->fifo2_descriptors_virtual + cnt_block * cam_ctx->fifo2_num_descriptors;
+		cnt_tail = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+		cnt_tail->ddadr = cnt_head->ddadr - sizeof(pxa_dma_desc);
+	}
+	return;
+}
+
+void pxa_dma_continue(camera_context_t * cam_ctx)
+{
+	pxa_dma_desc *cnt_head, *cnt_tail;
+	pxa_dma_desc *next_head;
+	int cnt_block, next_block;
+
+	cnt_block = cam_ctx->block_header;
+	next_block = (cnt_block + 1) % cam_ctx->block_number;
+// FIFO0        
+	cnt_head = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + cnt_block * cam_ctx->fifo0_num_descriptors;
+	cnt_tail = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
+	next_head = (pxa_dma_desc *) cam_ctx->fifo0_descriptors_virtual + next_block * cam_ctx->fifo0_num_descriptors;
+	cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+// FIFO1
+	if (cam_ctx->fifo1_transfer_size) {
+		cnt_head =
+		    (pxa_dma_desc *) cam_ctx->fifo1_descriptors_virtual + cnt_block * cam_ctx->fifo1_num_descriptors;
+		cnt_tail = cnt_head + cam_ctx->fifo1_num_descriptors - 1;
+		next_head =
+		    (pxa_dma_desc *) cam_ctx->fifo1_descriptors_virtual + next_block * cam_ctx->fifo1_num_descriptors;
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+// FIFO2
+	if (cam_ctx->fifo2_transfer_size) {
+		cnt_head =
+		    (pxa_dma_desc *) cam_ctx->fifo2_descriptors_virtual + cnt_block * cam_ctx->fifo2_num_descriptors;
+		cnt_tail = cnt_head + cam_ctx->fifo2_num_descriptors - 1;
+		next_head =
+		    (pxa_dma_desc *) cam_ctx->fifo2_descriptors_virtual + next_block * cam_ctx->fifo2_num_descriptors;
+		cnt_tail->ddadr = next_head->ddadr - sizeof(pxa_dma_desc);
+	}
+	return;
+
+}
+
+void ci_dump(void)
+{
+	DPRINTK("CICR0 = 0x%8x \n", CICR0);
+	DPRINTK("CICR1 = 0x%8x \n", CICR1);
+	DPRINTK("CICR2 = 0x%8x \n", CICR2);
+	DPRINTK("CICR3 = 0x%8x \n", CICR3);
+	DPRINTK("CICR4 = 0x%8x \n", CICR4);
+	DPRINTK("CISR  = 0x%8x \n", CISR);
+	DPRINTK("CITOR = 0x%8x \n", CITOR);
+	DPRINTK("CIFR  = 0x%8x \n", CIFR);
+}
+
+module_init(pxa_camera_init);
+module_exit(pxa_camera_exit);
+
+MODULE_DESCRIPTION("Bulverde Camera Interface driver");
+MODULE_LICENSE("GPL");
+EXPORT_NO_SYMBOLS;
diff -Nru --exclude-from=/sunbeam/home/laforge/scripts/dontdiff linux-2.6.16.5/include/linux/pxa_camera.h linux-2.6.16.5-exz/include/linux/pxa_camera.h
--- linux-2.6.16.5/include/linux/pxa_camera.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.5-exz/include/linux/pxa_camera.h	2006-04-16 18:49:29.000000000 +0200
@@ -0,0 +1,445 @@
+/*================================================================================
+                                                                               
+                     Module Name:  pxa-camera.h 
+
+General Description: E680/A780 camera driver header
+
+==================================================================================
+                      Motorola Confidential Proprietary
+                  Advanced Technology and Software Operations
+                (c) Copyright Motorola 1999, All Rights Reserved
+  
+Revision History:
+                            Modification     Tracking
+Author                 Date          Number     Description of Changes
+----------------   ------------    ----------   -------------------------
+Wang Fei/w20239     12/19/2003      LIBdd35749   Created
+Wang Fei/w20239     02/05/2004      LIBdd74309   Set frame rate in video mode
+Wang Fei/w20239     03/08/2004      LIBdd84578   Photo effects setting
+Wang Fei/w20239     11/01/2004      LIBxxxxxxx   Change to SDK style
+
+==================================================================================
+                                 INCLUDE FILES
+================================================================================*/
+#ifndef __PXA_CAMERA_H__ 
+#define __PXA_CAMERA_H__ 
+
+/*!
+ *  General description of the Motorola A780/E680 video device driver:
+ *
+ *  The Motorola A780/E680 video device is based on V4L (video for linux) 1.0, however not 
+ *  all V4L features are supported. 
+ *  There are also some additional extensions included for specific requirements beyond V4L.
+ *   
+ *  The video device driver has a "character special" file named /dev/video0. Developers can 
+ *  access the video device via the file operator interfaces.
+ *  Six file operator interfaces are supported:
+ *     open
+ *     ioctl
+ *     mmap
+ *     poll/select
+ *     read
+ *     close
+ *  For information on using these fuctions, please refer to the standard linux 
+ *  development documents.
+ *  
+ *  These four ioctl interfaces are important for getting the video device to work properly:
+ *     VIDIOCGCAP       Gets the video device capability
+ *     VIDIOCCAPTURE    Starts/stops the video capture 
+ *     VIDIOCGMBUF      Gets the image frame buffer map info
+ *     VIDIOCSWIN       Sets the picture size    
+ *  These interfaces are compatible with V4L 1.0. Please refer to V4L documents for more details.
+ *  sample.c demonstrates their use.
+ * 
+ *  The following ioctl interfaces are Motorola-specific extensions. These are not compatible with V4L 1.0.   
+ *   WCAM_VIDIOCSCAMREG   	
+ *   WCAM_VIDIOCGCAMREG   	
+ *   WCAM_VIDIOCSCIREG    	
+ *   WCAM_VIDIOCGCIREG    	
+ *   WCAM_VIDIOCSINFOR	    
+ *   WCAM_VIDIOCGINFOR
+ *   WCAM_VIDIOCSSSIZE
+ *   WCAM_VIDIOCSOSIZE
+ *   WCAM_VIDIOCGSSIZE
+ *   WCAM_VIDIOCGOSIZE
+ *   WCAM_VIDIOCSFPS
+ *   WCAM_VIDIOCSNIGHTMODE
+ *   WCAM_VIDIOCSSTYLE      
+ *   WCAM_VIDIOCSLIGHT      
+ *   WCAM_VIDIOCSBRIGHT     
+ *   WCAM_VIDIOCSBUFCOUNT   
+ *   WCAM_VIDIOCGCURFRMS    
+ *   WCAM_VIDIOCGSTYPE      
+ *   WCAM_VIDIOCSCONTRAST   
+ *   WCAM_VIDIOCSFLICKER 
+ *   Detailed information about these constants are described below.   
+ * 
+ *  sample.c demonstrates most features of the Motorola A780/E680 video device driver.
+ *    - Opening/closing the video device
+ *    - Initializing the video device driver
+ *    - Displaying the video image on a A780/E680 LCD screen     
+ *    - Changing the image size
+ *    - Changing the style
+ *    - Changing the light mode
+ *    - Changing the brightness
+ *    - Capturing and saving a still picture
+ */
+
+/*!
+ * These are the registers for the read/write camera module and the CIF 
+ * (Intel PXA27x processer quick capture interface)
+ * The following 4 ioctl interfaces are used for debugging and are not open to developers
+ */
+#define WCAM_VIDIOCSCAMREG   	211
+#define WCAM_VIDIOCGCAMREG   	212
+#define WCAM_VIDIOCSCIREG    	213
+#define WCAM_VIDIOCGCIREG    	214
+
+/*!
+ * WCAM_VIDIOCSINFOR Sets the image data format
+ *  
+ * The following code sets the image format to YCbCr422_planar
+ *
+ *   struct {int val1, val2;}format;
+ *   format.val1 = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+ *   format.val2 = CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
+ *   //dev is the video device handle 
+ *   ioctl(dev, WCAM_VIDIOCSINFOR, &format);
+ *
+ * Remarks:
+ *   val1 is the output format of the camera module, val2 is the output format of the CIF (capture  
+ *   interface). Image data from the camera module can be converted to other formats through
+ *   the CIF. val2 specifies the final output format of the video device.
+ *   
+ *   For more description on CIF please refer to the Intel PXA27x processor family developer's manual.
+ *     http://www.intel.com/design/pca/prodbref/253820.html 
+ */
+#define WCAM_VIDIOCSINFOR	    215
+
+/*
+ * WCAM_VIDIOCGINFOR Gets the image data format
+ *
+ *  struct {int val1, val2;}format;
+ *  ioctl(dev, WCAM_VIDIOCGINFOR, &format);
+ */
+#define WCAM_VIDIOCGINFOR	    216
+ 
+/*! 
+ *  WCAM_VIDIOCSSSIZE Sets the sensor window size
+ *
+ *   The following code sets the sensor size to 640 X 480:
+ *
+ *   struct {unsigned short w, h;}sensor_size;
+ *   sensor_size.w = 640;
+ *   sensor_size.h = 480;
+ *   //dev is the video device handle 
+ *   ioctl(dev, WCAM_VIDIOCSSSIZE, &sensor_size);
+ *
+ *  Remarks:
+ *    The sensor size is restricted by the video device capability. 
+ *    VIDIOCGCAP can get the video device capability.
+ *    The sensor size must be an even of multiple of 8. If not, the driver changes the sensor size to a multiple of 8.
+ */
+#define WCAM_VIDIOCSSSIZE        217
+
+/*!
+ * WCAM_VIDIOCSOSIZE Sets output size of the video device
+ *
+ *   The following code segment shows how to set the output size to 240 X 320:
+ *
+ *   struct {unsigned short w, h;}out_size;
+ *   out_size.w = 240;
+ *   out_size.h = 320;
+ *   //dev is the video device handle 
+ *   ioctl(dev, WCAM_VIDIOCSSSIZE, &out_size);
+ *
+ *  Remarks:
+ *   In video mode, the output size must be less than 240X320. However, in still mode, the output  
+ *   size is restricted by the video device capability and the sensor size.
+ *   The output size must always be less than the sensor size, so if the developer changes the output size  
+ *   to be greater than the sensor size, the video device driver may work abnormally.
+ *   The width and height must also be a multiple of 8. If it is not, the driver changes the width and height size to a multiple of 8.
+ *   The developer can modify the sensor size and the output size to create a digital zoom. 
+ */
+#define WCAM_VIDIOCSOSIZE        218 
+
+/*!
+ * WCAM_VIDIOCGSSIZE Gets the current sensor size.
+ * 
+ * The following code segment shows how to use this function:
+ *
+ *   struct {unsigned short w, h;}sensor_size;
+ *   //dev is the video device handle 
+ *   ioctl(dev, WCAM_VIDIOCGSSIZE, &sensor_size); 
+ *   printf("sensor width is %d, sensor_height is %d\n", sensor_size.w, sensor_size.h);
+ *
+ */
+#define WCAM_VIDIOCGSSIZE        219
+
+/*!
+ * WCAM_VIDIOCGOSIZE Gets the current output size.
+ * 
+ * The following code segment shows how to use this function:
+ *
+ *   struct {unsigned short w, h;}out_size;
+ *   //dev is the video device handle 
+ *   ioctl(dev, WCAM_VIDIOCGOSIZE, &out_size); 
+ *   printf("output width is %d, output height is %d\n", out_size.w, out_size.h);
+ *
+ */
+#define WCAM_VIDIOCGOSIZE        220 
+
+/*!
+ * WCAM_VIDIOCSFPS Sets the output frame rate (fps- frames per second) of the video device
+ *
+ * The following code segment shows how to use this function:
+ *
+ *   struct {int maxfps, minfps;}fps;
+ *   fps.maxfps  = 15;
+ *   fps.minfps  = 12;
+ *   ioctl(dev, WCAM_VIDIOCSFPS, &fps);
+ *
+ * Remarks:
+ *   The minimum value of maxfps is 1; the maximum value is 15.  minfps must not exceed maxfps. 
+ *   The default value of fps is [15, 10].
+ *   minfps and maxfps only suggest a fps range. The video device driver will select 
+ *   an appropriate value automatically. The actual fps depends on environmental circumstances  
+ *   such as brightness, illumination, etc. 
+ *   sample.c illustrates how to calculate actual frame rate.
+ *   
+ */
+#define WCAM_VIDIOCSFPS          221 
+
+/*!
+ * WCAM_VIDIOCSNIGHTMODE Sets the video device capture mode. 
+ *
+ * The capture mode can use the following values
+ *
+ *   V4l_NM_AUTO     Auto mode(default value)
+ *   V4l_NM_NIGHT    Night mode
+ *   V4l_NM_ACTION   Action mode
+ *  
+ * The following code segment shows how to set the video device to night mode:
+ *
+ *   ioctl(dev, WCAM_VIDIOCSNIGHTMODE, V4l_NM_NIGHT);
+ *
+ * Remarks:
+ *   Different capture modes represent different sensor exposure times. Night mode represents a longer 
+ *   exposure time. Setting the video device to night mode can capture high quality image data in low light environments.
+ *   Action mode represents a shorter exposure time. This is used for capture moving objects. When working in auto mode, the 
+ *   video device will select an appropriate exposure time automatically.
+ *
+ *   Not all camera modules support this interface. Developers can also use WCAM_VIDIOCSFPS to achieve similar results.
+ *   Smaller minfps represent longer exposure times.
+ *
+ */
+#define WCAM_VIDIOCSNIGHTMODE    222 
+
+/*!
+ * WCAM_VIDIOCSSTYLE Sets the image style.
+ *
+ * The following styles are supported:
+ *
+ *   V4l_STYLE_NORMAL        Normal (default value)
+ *   V4l_STYLE_BLACK_WHITE   Black and white 
+ *   V4l_STYLE_SEPIA         Sepia
+ *   V4l_STYLE_SOLARIZE      Solarized (not supported by all camera modules)
+ *   V4l_STYLE_NEG_ART       Negative (not supported by all camera modules)
+ *
+ * The following code segment demonstrates how to set the image style to black and white:
+ *
+ *   ioctl(dev, WCAM_VIDIOCSSTYLE, V4l_STYLE_BLACK_WHITE);
+ *
+ */
+#define WCAM_VIDIOCSSTYLE        250  
+
+/*!
+ * WCAM_VIDIOCSLIGHT Sets the image light mode
+ * 
+ * The following light modes are supported:
+ *   V4l_WB_AUTO           Auto mode(default)
+ *   V4l_WB_DIRECT_SUN     Direct sun
+ *   V4l_WB_INCANDESCENT   Incandescent
+ *   V4l_WB_FLUORESCENT    Fluorescent
+ * 
+ * The following code sets the image light mode to incandescent:
+ *   ioctl(dev, WCAM_VIDIOCSLIGHT, V4l_WB_INCANDESCENT);
+ */
+#define WCAM_VIDIOCSLIGHT        251
+
+/*!
+ * WCAM_VIDIOCSBRIGHT Sets the brightness of the image (exposure compensation value)
+ *  
+ *  parameter value      exposure value
+ *   -4                     -2.0 EV
+ *   -3                     -1.5 EV
+ *   -2                     -1.0 EV
+ *   -1                     -0.5 EV
+ *    0                      0.0 EV(default value)
+ *    1                     +0.5 EV
+ *    2                     +1.0 EV
+ *    3                     +1.5 EV
+ *    4                     +2.0 EV
+ *
+ * The following code segment sets the brightness to 2.0 EV
+ *   ioctl(dev, WCAM_VIDIOCSBRIGHT, 4);
+ */
+#define WCAM_VIDIOCSBRIGHT       252
+
+/*!
+ * Sets the frame buffer count for video mode. The default value is 3.
+ *
+ * Remarks:
+ * The video device driver maintains some memory for buffering image data in the kernel space. When working in video mode,
+ * there are at least 3 frame buffers in the driver.  In still mode, there is only 1 frame buffer.
+ * This interface is not open to SDK developers.
+ * 
+ */
+#define WCAM_VIDIOCSBUFCOUNT     253  
+
+/*!
+ * Gets the current available frames
+ *
+ * The following code demonstrates getting the current available frames:
+ *
+ *   struct {int first, last;}cur_frms;
+ *   ioctl(dev, WCAM_VIDIOCGCURFRMS, &cur_frms);
+ *
+ * Remarks:
+ *   cur_frms.first represents the earliest frame in frame buffer  
+ *   cur_frms.last  represents the latest or most recent frame in frame buffer.
+ */
+#define WCAM_VIDIOCGCURFRMS      254  
+
+/*!
+ * Gets the camera sensor type
+ *
+ *  unsigned int sensor_type
+ *  ioctl(dev, WCAM_VIDIOCGSTYPE, &sensor_type);
+ *  if(sensor_type == CAMERA_TYPE_ADCM_2700)
+ *  {
+ *     printf("Agilent ADCM2700");
+ *  }
+ *
+ * Remarks:
+ *   For all possible values of sensor_type please refer to the sensor definitions below.
+ */
+#define WCAM_VIDIOCGSTYPE        255 
+
+/*!
+ * Sets the image contrast
+ * Not open to SDK developers
+ */
+#define WCAM_VIDIOCSCONTRAST     256
+
+/*!
+ * Sets the flicker frequency(50hz/60hz)
+ * Not open to SDK developers
+ */
+#define WCAM_VIDIOCSFLICKER      257
+
+
+
+typedef enum V4l_NIGHT_MODE
+{
+   V4l_NM_AUTO,
+   V4l_NM_NIGHT,
+   V4l_NM_ACTION
+}V4l_NM;
+
+typedef enum V4l_PIC_STYLE
+{
+   V4l_STYLE_NORMAL,
+   V4l_STYLE_BLACK_WHITE,
+   V4l_STYLE_SEPIA,
+   V4l_STYLE_SOLARIZE,
+   V4l_STYLE_NEG_ART
+}V4l_PIC_STYLE;
+
+typedef enum V4l_PIC_WB
+{
+   V4l_WB_AUTO,
+   V4l_WB_DIRECT_SUN,
+   V4l_WB_INCANDESCENT,
+   V4l_WB_FLUORESCENT
+}V4l_PIC_WB;
+
+
+
+/*!
+ *Image format definitions
+ *Remarks:
+ *  Although not all formats are supported by all camera modules, YCBCR422_PLANAR is widely supported. 
+ *  For detailed information on each format please refer to the Intel PXA27x processor family developer's manual. 
+ *     http://www.intel.com/design/pca/prodbref/253820.html
+ * 
+ */
+#define CAMERA_IMAGE_FORMAT_RAW8                0
+#define CAMERA_IMAGE_FORMAT_RAW9                1
+#define CAMERA_IMAGE_FORMAT_RAW10               2
+                                                                                                                             
+#define CAMERA_IMAGE_FORMAT_RGB444              3
+#define CAMERA_IMAGE_FORMAT_RGB555              4
+#define CAMERA_IMAGE_FORMAT_RGB565              5
+#define CAMERA_IMAGE_FORMAT_RGB666_PACKED       6
+#define CAMERA_IMAGE_FORMAT_RGB666_PLANAR       7
+#define CAMERA_IMAGE_FORMAT_RGB888_PACKED       8
+#define CAMERA_IMAGE_FORMAT_RGB888_PLANAR       9
+#define CAMERA_IMAGE_FORMAT_RGBT555_0          10  //RGB+Transparent bit 0
+#define CAMERA_IMAGE_FORMAT_RGBT888_0          11
+#define CAMERA_IMAGE_FORMAT_RGBT555_1          12  //RGB+Transparent bit 1
+#define CAMERA_IMAGE_FORMAT_RGBT888_1          13
+                                                                                                                             
+#define CAMERA_IMAGE_FORMAT_YCBCR400           14
+#define CAMERA_IMAGE_FORMAT_YCBCR422_PACKED    15
+#define CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR    16
+#define CAMERA_IMAGE_FORMAT_YCBCR444_PACKED    17
+#define CAMERA_IMAGE_FORMAT_YCBCR444_PLANAR    18
+
+/*!
+ *VIDIOCCAPTURE arguments
+ */
+#define STILL_IMAGE				1
+#define VIDEO_START				0
+#define VIDEO_STOP				-1
+
+/*!
+ *Sensor type definitions
+ */
+#define CAMERA_TYPE_ADCM_2650               1
+#define CAMERA_TYPE_ADCM_2670               2
+#define CAMERA_TYPE_ADCM_2700               3
+#define CAMERA_TYPE_OMNIVISION_9640         4
+#define CAMERA_TYPE_MT9M111                 5
+#define CAMERA_TYPE_MT9V111                 6
+#define CAMERA_TYPE_ADCM3800                7
+#define CAMERA_TYPE_OV9650                  8
+#define CAMERA_TYPE_MAX                     CAMERA_TYPE_OV9650
+
+
+/*
+ * Definitions of the camera's i2c device
+ */
+#define CAMERA_I2C_WRITEW    101
+#define CAMERA_I2C_WRITEB    102
+#define CAMERA_I2C_READW     103
+#define CAMERA_I2C_READB     104
+#define CAMERA_I2C_DETECTID  105
+
+struct camera_i2c_register {
+    unsigned short  addr;
+    union {
+        unsigned short w;
+        unsigned char b;
+    } value;
+};
+
+struct camera_i2c_detectid {
+    int buflen;
+    char data[256];
+};
+
+//End of the camera's i2c device
+
+#endif // __PXA_CAMERA_H__ 
+