summaryrefslogtreecommitdiff
path: root/target/device/Atmel/misc-patches/linux-2.6.24-500-v4l-avr32-isi.patch
blob: f79ab82a2c94bb978a5e995331d98c07660e0b9b (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
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 441b877..3a85a5e 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -298,6 +298,9 @@ struct v4l2_pix_format
 #define V4L2_PIX_FMT_PWC2     v4l2_fourcc('P','W','C','2') /* pwc newer webcam */
 #define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E','6','2','5') /* ET61X251 compression */
 
+/* Byte-swapped YUYV */
+#define V4L2_PIX_FMT_VYUY     v4l2_fourcc('V','Y','U','Y') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_YVYU     v4l2_fourcc('Y','V','Y','U') /* 16 YUV 4:2:2 */
 /*
  *	F O R M A T   E N U M E R A T I O N
  */
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 44ccaed..78e38d0 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
 obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
 obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
 obj-$(CONFIG_TUNER_3036) += tuner-3036.o
+obj-$(CONFIG_VIDEO_AVR32_ISI) += atmel-isi.o
 
 obj-$(CONFIG_VIDEO_TUNER) += tuner.o
 obj-$(CONFIG_VIDEO_BUF)   += video-buf.o
diff --git a/drivers/media/video/atmel-isi.c b/drivers/media/video/atmel-isi.c
new file mode 100644
index 0000000..a53a3c0
--- /dev/null
+++ b/drivers/media/video/atmel-isi.c
@@ -0,0 +1,1868 @@
+/*
+ * Copyright (c) 2007 Atmel Corporation
+ *
+ * Based on the bttv driver for Bt848 with respective copyright holders
+ *
+ * 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.
+ */
+#define DEBUG
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/dma-mapping.h>
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/ioctl.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/version.h>
+#include <linux/videodev2.h>
+#include <linux/wait.h>
+
+#include <linux/kfifo.h>
+
+#include <asm/io.h>
+
+#include <media/v4l2-common.h>
+
+#include "atmel-isi.h"
+
+#define ATMEL_ISI_VERSION	KERNEL_VERSION(0, 1, 0)
+#define ISI_CODEC 0
+
+/* Default ISI capture buffer size */
+#define ISI_CAPTURE_BUFFER_SIZE 800*600*2
+/* Default ISI video frame size */
+#define ISI_VIDEO_BUFFER_SIZE 320*240*2
+/* Default number of ISI video buffers */
+#define ISI_VIDEO_BUFFERS 4
+/* Maximum number of video buffers */
+#define ISI_VIDEO_BUFFERS_MAX 8
+
+/* Interrupt mask for a single capture */
+#define ISI_CAPTURE_MASK (ISI_BIT(SOF) | ISI_BIT(FO_C_EMP))
+
+/* ISI capture buffer size */
+static int capture_buffer_size = ISI_CAPTURE_BUFFER_SIZE;
+/* Number of buffers used for streaming video */
+static int video_buffers = 4;
+static int video_buffer_size = ISI_VIDEO_BUFFER_SIZE;
+
+/* Preview path horizontal size */
+static int prev_hsize = 320;
+/* Preview path vertical size */
+static int prev_vsize = 240;
+/* Scaling factor of the preview path */
+static int prev_decimation_factor = 1;
+
+/* Input image horizontal size */
+static int image_hsize = 320;
+
+/* Input image vertical size */
+static int image_vsize = 240;
+
+/* Frame rate scaler 
+ * 1 = capture every second frame
+ * 2 = capture every third frame
+ * ...
+ * */
+static int frame_rate_scaler = 2;
+
+/* Set this value if we want to pretend a specific V4L2 output format 
+ *  This format is for the capturing interface
+ */ 
+static int capture_v4l2_fmt = V4L2_PIX_FMT_YUYV;
+/* Set this value if we want to pretend a specific V4L2 output format 
+ *  This format is for the streaming interface
+ */
+static int streaming_v4l2_fmt = V4L2_PIX_FMT_YUYV;
+
+MODULE_PARM_DESC(video_buffers,"Number of frame buffers used for streaming");
+module_param(video_buffers, int, 0664);
+MODULE_PARM_DESC(capture_buffer_size,"Capture buffer size");
+module_param(capture_buffer_size, int, 0664);
+MODULE_PARM_DESC(image_hsize,"Horizontal size of input image");
+module_param(image_hsize, int, 0664);
+MODULE_PARM_DESC(image_vsize,"Vertical size of input image");
+module_param(image_vsize, int, 0664);
+MODULE_PARM_DESC(frame_rate_scaler, "Frame rate scaler");
+module_param(frame_rate_scaler, int, 0664);
+MODULE_PARM_DESC(prev_hsize, "Horizontal image size of preview path output");
+module_param(prev_hsize, int, 0664);
+MODULE_PARM_DESC(prev_vsize, "Vertical image size of preview path output");
+module_param(prev_vsize, int, 0664);
+MODULE_PARM_DESC(prev_decimation_factor, "Preview path decimaion factor");
+module_param(prev_decimation_factor, int, 0664);
+/* Single frame capturing states */
+enum {
+	STATE_IDLE = 0,
+	STATE_CAPTURE_READY,
+	STATE_CAPTURE_WAIT_SOF,
+	STATE_CAPTURE_IN_PROGRESS,
+	STATE_CAPTURE_DONE,
+	STATE_CAPTURE_ERROR,
+};
+
+/* Frame buffer states
+ *  FRAME_UNUSED Frame(buffer) is not used by the ISI module -> an application
+ *  can usually read out data in this state
+ *  FRAME_QUEUED An application has queued the buffer in the incoming queue 
+ *  FRAME_DONE The ISI module has filled the buffer with data and placed is on
+ *  the outgoing queue
+ *  FRAME_ERROR Not used at the moment
+ *  */
+enum frame_status {
+	FRAME_UNUSED,
+	FRAME_QUEUED,
+	FRAME_DONE,
+	FRAME_ERROR,
+};
+/* Frame buffer descriptor 
+ *  Used by the ISI module as a linked list for the DMA controller.
+ */
+struct fbd {
+	/* Physical address of the frame buffer */
+	dma_addr_t fb_address;
+	/* Physical address of the next fbd */
+	dma_addr_t next_fbd_address;
+};
+
+/* Frame buffer data
+ */
+struct frame_buffer {
+	/*  Frame buffer descriptor
+	 *  Used by the ISI DMA controller to provide linked list DMA operation
+	 */
+	struct fbd fb_desc;
+	/* Pointer to the start of the frame buffer */
+	void *frame_buffer;
+	/* Timestamp of the captured frame */
+	struct timeval timestamp;
+	/* Frame number of the frame  */
+	unsigned long sequence;
+	/* Buffer number*/
+	int index;
+	/* Bytes used in the buffer for data, needed as buffers are always
+	 *  aligned to pages and thus may be bigger than the amount of data*/
+	int bytes_used;
+	/* Mmap count
+	 *  Counter to measure how often this buffer is mmapped 
+	 */
+	int mmap_count;
+	/* Buffer status */
+	enum frame_status status;
+};
+
+struct atmel_isi {
+	/* ISI module spin lock. Protects against concurrent access of variables
+	 * that are shared with the ISR */
+	spinlock_t			lock;
+	void __iomem			*regs;
+	/* Pointer to the start of the fbd list */
+	dma_addr_t			fbd_list_start;
+	/* Frame buffers */
+	struct frame_buffer 		video_buffer[ISI_VIDEO_BUFFERS_MAX];
+	/* Frame buffer currently used by the ISI module */
+	struct frame_buffer		*current_buffer;
+	/* Size of a frame buffer */
+	size_t				capture_buffer_size;
+	/* Streaming status 
+	 *  If set ISI is in streaming mode */
+	int				streaming;
+	/* Queue for incoming buffers
+	 *  The buffer number (index) is stored in the fifo as reference 
+	 */
+	struct kfifo 			*grabq;
+	/* Spinlock for the incoming queue */
+	spinlock_t 			grabq_lock;
+	/* Queue for outgoing buffers
+	 *  Buffer number is stored in the fifo as reference
+	 */
+	struct kfifo			*doneq;
+	/* Spinlock for the incoming queue */
+	spinlock_t			doneq_lock;
+
+	/* State of the ISI module in capturing mode */
+	int				state;
+	/* Pointer to ISI buffer */
+	void				*capture_buf;
+	/* Physical address of the capture buffer */
+	dma_addr_t			capture_phys;
+	/* Size of the ISI buffer */
+	size_t				capture_buf_size;
+	/* Capture/streaming wait queue */
+	wait_queue_head_t		capture_wq;
+
+	struct atmel_isi_camera		*camera;
+	struct atmel_isi_format		format;
+	struct atmel_isi_format		streaming_format;
+
+	struct mutex			mutex;
+	/* User counter for the streaming interface */
+	int				stream_users;
+	/* User counter of the capture interface */
+	int				capture_users;
+	/* Video device for capturing (Codec path) */
+	struct video_device		cdev;
+	/* Video device for streaming (Preview path) */
+	struct video_device		vdev;
+	struct completion		reset_complete;
+	struct clk			*pclk;
+	struct clk			*hclk;
+	struct platform_device		*pdev;
+	unsigned int			irq;
+};
+
+#define to_atmel_isi(vdev) container_of(vdev, struct atmel_isi, vdev)
+
+struct atmel_isi_fh {
+	struct atmel_isi		*isi;
+	unsigned int			read_off;
+};
+
+/*-----------------------------------------------------------------------------
+ * Interface to the actual camera.
+ */
+static LIST_HEAD(camera_list);
+static DEFINE_MUTEX(camera_list_mutex);
+
+static void avr32_isi_release_camera(struct atmel_isi *isi,
+				     struct atmel_isi_camera *cam)
+{
+	mutex_lock(&camera_list_mutex);
+	cam->isi = NULL;
+	isi->camera = NULL;
+	module_put(cam->owner);
+	mutex_unlock(&camera_list_mutex);
+}
+
+int atmel_isi_register_camera(struct atmel_isi_camera *cam)
+{
+	pr_debug("atmel_isi: register camera %s\n", cam->name);
+
+	mutex_lock(&camera_list_mutex);
+	list_add_tail(&cam->list, &camera_list);
+	mutex_unlock(&camera_list_mutex);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(atmel_isi_register_camera);
+
+void atmel_isi_unregister_camera(struct atmel_isi_camera *cam)
+{
+	pr_debug("atmel_isi: unregister camera %s\n", cam->name);
+
+	mutex_lock(&camera_list_mutex);
+	if (cam->isi)
+		cam->isi->camera = NULL;
+	list_del(&cam->list);
+	mutex_unlock(&camera_list_mutex);
+}
+EXPORT_SYMBOL_GPL(atmel_isi_unregister_camera);
+
+static struct atmel_isi_camera * avr32_isi_grab_camera(struct atmel_isi *isi)
+{
+	struct atmel_isi_camera *entry, *cam = NULL;
+
+	mutex_lock(&camera_list_mutex);
+	list_for_each_entry(entry, &camera_list, list) {
+		/* Just grab the first camera available */
+		if (!entry->isi) {
+			if (!try_module_get(entry->owner))
+				continue;
+
+			cam = entry;
+			cam->isi = isi;
+			pr_debug("%s: got camera: %s\n",
+				 isi->vdev.name, cam->name);
+			break;
+		}
+	}
+	mutex_unlock(&camera_list_mutex);
+
+	return cam;
+}
+
+static int avr32_isi_set_camera_input(struct atmel_isi *isi)
+{
+	struct atmel_isi_camera *cam = isi->camera;
+	int ret;
+	u32 cr1;
+	u32 cr2;
+
+	isi->format.pix.width = image_hsize;
+	isi->format.pix.height = image_vsize;
+	isi->format.pix.bytesperline = 0;
+
+	ret = cam->set_format(cam, &isi->format);
+	if (ret)
+		return ret;
+
+
+	switch (isi->format.input_format) {
+	case ATMEL_ISI_PIXFMT_GREY:
+		cr2 = ISI_BIT(GRAYSCALE);
+		break;
+	case ATMEL_ISI_PIXFMT_CbYCrY:
+		cr2 = ISI_BF(YCC_SWAP, 0);
+		break;
+	case ATMEL_ISI_PIXFMT_CrYCbY:
+		cr2 = ISI_BF(YCC_SWAP, 1);
+		break;
+	case ATMEL_ISI_PIXFMT_YCbYCr:
+		cr2 = ISI_BF(YCC_SWAP, 2);
+		break;
+	case ATMEL_ISI_PIXFMT_YCrYCb:
+		cr2 = ISI_BF(YCC_SWAP, 3);
+		break;
+	case ATMEL_ISI_PIXFMT_RGB24:
+		cr2 = ISI_BIT(COL_SPACE) | ISI_BF(RGB_CFG, 0);
+		break;
+	case ATMEL_ISI_PIXFMT_BGR24:
+		cr2 = ISI_BIT(COL_SPACE) | ISI_BF(RGB_CFG, 1);
+		break;
+	case ATMEL_ISI_PIXFMT_RGB16:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_MODE)
+		       | ISI_BF(RGB_CFG, 0));
+		break;
+	case ATMEL_ISI_PIXFMT_BGR16:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_MODE)
+		       | ISI_BF(RGB_CFG, 1));
+		break;
+	case ATMEL_ISI_PIXFMT_GRB16:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_MODE)
+		       | ISI_BF(RGB_CFG, 2));
+		break;
+	case ATMEL_ISI_PIXFMT_GBR16:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_MODE)
+		       | ISI_BF(RGB_CFG, 3));
+		break;
+	case ATMEL_ISI_PIXFMT_RGB24_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BF(RGB_CFG, 0));
+		break;
+	case ATMEL_ISI_PIXFMT_BGR24_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BF(RGB_CFG, 1));
+		break;
+	case ATMEL_ISI_PIXFMT_RGB16_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BIT(RGB_MODE) | ISI_BF(RGB_CFG, 0));
+		break;
+	case ATMEL_ISI_PIXFMT_BGR16_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BIT(RGB_MODE) | ISI_BF(RGB_CFG, 1));
+		break;
+	case ATMEL_ISI_PIXFMT_GRB16_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BIT(RGB_MODE) | ISI_BF(RGB_CFG, 2));
+		break;
+	case ATMEL_ISI_PIXFMT_GBR16_REV:
+		cr2 = (ISI_BIT(COL_SPACE) | ISI_BIT(RGB_SWAP)
+		       | ISI_BIT(RGB_MODE) | ISI_BF(RGB_CFG, 3));
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	
+	cr1 = ISI_BF(EMB_SYNC, cam->has_emb_sync)
+		| ISI_BF(HSYNC_POL, cam->hsync_act_low)
+		| ISI_BF(VSYNC_POL, cam->vsync_act_low)
+		| ISI_BF(PIXCLK_POL, cam->pclk_act_falling)
+		| ISI_BIT(DIS);
+
+	isi_writel(isi, CR1, cr1);
+	isi_writel(isi, CR2, cr2);
+
+	return 0;
+}
+
+static int avr32_isi_capture_set_format(struct atmel_isi *isi,
+				struct atmel_isi_format *fmt)
+{
+	u32 cr2;
+
+	fmt->pix.width = min(2048U, fmt->pix.width);
+	fmt->pix.height = min(2048U, fmt->pix.height);
+	fmt->pix.bytesperline = 0;
+
+	/* Set format if we have specified one */
+	if(capture_v4l2_fmt){
+		fmt->pix.pixelformat = capture_v4l2_fmt;
+	}
+	else {
+		/* Codec path output format */
+		fmt->pix.pixelformat = V4L2_PIX_FMT_YVYU;
+	}
+
+	/* The ISI module outputs either YUV 4:2:2 (codec path)
+	 * or RGB 5:5:5 (preview path) (ISI grayscale mode is not supported 
+	 * by V4L2). Therefore two pixels will be in a 32bit word */
+	fmt->pix.bytesperline = ALIGN(fmt->pix.width * 2, 4);
+	fmt->pix.sizeimage = fmt->pix.bytesperline * fmt->pix.height;
+	
+	cr2 = isi_readl(isi, CR2);
+	cr2 = ISI_BFINS(IM_VSIZE, fmt->pix.height - 1, cr2);
+	cr2 = ISI_BFINS(IM_HSIZE, fmt->pix.width - 1, cr2);
+	isi_writel(isi, CR2, cr2);
+
+	pr_debug("set capture format: width=%d height=%d\n",
+		fmt->pix.width, fmt->pix.height);
+
+	return 0;
+}
+
+static int avr32_isi_streaming_set_format(struct atmel_isi *isi,
+				struct atmel_isi_format *fmt)
+{
+	memcpy(&isi->streaming_format, &isi->format, 
+		sizeof(struct atmel_isi_format)); 
+#ifndef ISI_CODEC
+	fmt->pix.width = min(640U, prev_hsize);
+	fmt->pix.height = min(480U, prev_vsize);
+	fmt->pix.bytesperline = 0;
+
+	/* Set format if we have specified one */
+	if(streaming_v4l2_fmt){
+		fmt->pix.pixelformat = streaming_v4l2_fmt;
+	}
+	else {
+		/* Preview path output format
+		 * Would be logically V4L2_PIX_FMT_BGR555X 
+		 * but this format does not exist in the specification
+		 * So for now we pretend V4L2_PIX_FMT_RGB555X 
+		 */
+		fmt->pix.pixelformat = V4L2_PIX_FMT_RGB555X;
+	}
+
+	/* The ISI module outputs either YUV 4:2:2 (codec path) 
+	 * or RGB 5:5:5 (preview path) (ISI grayscale mode is not 
+	 * supported yet. Therefore two pixels will be in a 32bit word 
+	 */
+	fmt->pix.bytesperline = ALIGN(fmt->pix.width * 2, 4);
+	fmt->pix.sizeimage = fmt->pix.bytesperline * fmt->pix.height;
+	
+	/* These values depend on the sensor output image size */
+	isi_writel(isi, PDECF, prev_decimation_factor);/* 1/16 * 16 = 1*/
+	isi_writel(isi,PSIZE , ISI_BF(PREV_HSIZE,prev_hsize - 1)
+		| ISI_BF(PREV_VSIZE, prev_vsize - 1));
+
+	pr_debug("set_format: cr1=0x%08x cr2=0x%08x\n",
+		 isi_readl(isi, CR1), isi_readl(isi, CR2));
+#else
+	avr32_isi_capture_set_format(isi, &isi->streaming_format);
+#endif
+	return 0;
+}
+
+static int avr32_isi_start_capture(struct atmel_isi *isi)
+{
+	u32 cr1;
+	int ret;
+
+	spin_lock_irq(&isi->lock);
+	isi->state = STATE_IDLE;
+	isi_readl(isi, SR); /* clear any pending SOF interrupt */
+	isi_writel(isi, IER, ISI_BIT(SOF));
+	isi_writel(isi, CR1, isi_readl(isi, CR1) & ~ISI_BIT(DIS));	
+	spin_unlock_irq(&isi->lock);
+
+	pr_debug("isi: waiting for SOF\n");
+	ret = wait_event_interruptible(isi->capture_wq,
+				       isi->state != STATE_IDLE);
+	if (ret)
+		return ret;
+	if (isi->state != STATE_CAPTURE_READY)
+		return -EIO;
+
+	/*
+	 * Do a codec request. Next SOF indicates start of capture,
+	 * the one after that indicates end of capture.
+	 */
+	pr_debug("isi: starting capture\n");
+	isi_writel(isi, CDBA, isi->capture_phys);
+
+	spin_lock_irq(&isi->lock);
+	isi->state = STATE_CAPTURE_WAIT_SOF;
+	cr1 = isi_readl(isi, CR1);
+	cr1 |= ISI_BIT(CODEC_ON);
+	isi_writel(isi, CR1, cr1);
+	isi_writel(isi, IER, ISI_CAPTURE_MASK);
+	spin_unlock_irq(&isi->lock);
+
+	return 0;
+}
+
+static void avr32_isi_capture_done(struct atmel_isi *isi,
+				   int state)
+{
+	u32 cr1;
+
+	cr1 = isi_readl(isi, CR1);
+	cr1 &= ~ISI_BIT(CODEC_ON);
+	isi_writel(isi, CR1, cr1);
+
+	isi->state = state;
+	wake_up_interruptible(&isi->capture_wq);
+	isi_writel(isi, IDR, ISI_CAPTURE_MASK);
+}
+
+static irqreturn_t avr32_isi_handle_streaming(struct atmel_isi *isi, 
+	int sequence){
+	
+	int reqnr;
+
+	if(kfifo_get(isi->grabq, (unsigned char *) &reqnr,
+			sizeof(int)) != sizeof(int)){
+			
+		/* as no new buffer is available we keep the
+		* current one
+		*/
+		pr_debug("isi: dropping frame\n");
+#ifdef ISI_CODEC
+		isi_writel(isi, CDBA, 
+			isi->current_buffer->fb_desc.fb_address);
+
+		isi_writel(isi, CR1, ISI_BIT(CODEC_ON) | 
+			isi_readl(isi, CR1));
+#else
+		/* TEST this has to be tested if it messes up the ISI
+		 * streaming process */
+		isi_writel(isi, PPFBD, (unsigned long) 
+			&isi->video_buffer[isi->current_buffer->index]);
+#endif
+	}
+	else{
+		isi->current_buffer->status = FRAME_DONE;
+		isi->current_buffer->sequence = sequence;
+			
+		do_gettimeofday(&isi->current_buffer->timestamp);
+			
+		/*isi->current_buffer->bytes_used = 
+			ISI_VIDEO_MAX_FRAME_SIZE; */
+			
+		kfifo_put(isi->doneq, (unsigned char *) 
+			&(isi->current_buffer->index), sizeof(int));
+			
+		isi->current_buffer = &(isi->video_buffer[reqnr]);
+#ifdef ISI_CODEC
+		isi_writel(isi, CDBA, 
+			isi->current_buffer->fb_desc.fb_address);
+		isi_writel(isi, CR1, ISI_BIT(CODEC_ON) | 
+			isi_readl(isi, CR1));
+#else
+		/*TODO check if fbd corresponds to frame buffer */
+#endif
+		wake_up_interruptible(&isi->capture_wq);
+	}
+	return IRQ_HANDLED;
+}
+
+/* FIXME move code from ISR here
+static irqreturn_t avr32_isi_handle_capturing(struct atmel_isi *isi){
+
+}*/
+/* isi interrupt service routine */
+static irqreturn_t isi_interrupt(int irq, void *dev_id)
+{
+	struct atmel_isi *isi = dev_id;
+	u32 status, mask, pending;
+	irqreturn_t ret = IRQ_NONE;
+	static int sequence = 0;
+
+	spin_lock(&isi->lock);
+
+	status = isi_readl(isi, SR);
+	mask = isi_readl(isi, IMR);
+	pending = status & mask;
+
+	pr_debug("isi: interrupt status %x pending %x\n",
+		 status, pending);
+	if(isi->streaming){
+		if(likely(pending & (ISI_BIT(FO_C_EMP) | ISI_BIT(FO_P_EMP)))){
+		
+			sequence++;
+		 	ret = avr32_isi_handle_streaming(isi, sequence);
+		}
+	}
+	else{
+	while (pending) {
+		if (pending & (ISI_BIT(FO_C_OVF) | ISI_BIT(FR_OVR))) {
+			avr32_isi_capture_done(isi, STATE_CAPTURE_ERROR);
+			pr_debug("%s: FIFO overrun (status=0x%x)\n",
+				 isi->vdev.name, status);
+		} else if (pending & ISI_BIT(SOF)) {
+			switch (isi->state) {
+			case STATE_IDLE:
+				isi->state = STATE_CAPTURE_READY;
+				wake_up_interruptible(&isi->capture_wq);
+				break;
+			case STATE_CAPTURE_READY:
+				break;
+			case STATE_CAPTURE_WAIT_SOF:
+				isi->state = STATE_CAPTURE_IN_PROGRESS;
+				break;
+			/*
+			case STATE_CAPTURE_IN_PROGRESS:
+				avr32_isi_capture_done(isi, STATE_CAPTURE_DONE);
+				break;
+				*/
+			}
+		}
+		if (pending & ISI_BIT(FO_C_EMP)){
+			if( isi->state == STATE_CAPTURE_IN_PROGRESS)
+				avr32_isi_capture_done(isi, STATE_CAPTURE_DONE);
+		}
+
+		if (pending & ISI_BIT(SOFTRST)) {
+			complete(&isi->reset_complete);
+			isi_writel(isi, IDR, ISI_BIT(SOFTRST));
+		}
+
+		status = isi_readl(isi, SR);
+		mask = isi_readl(isi, IMR);
+		pending = status & mask;
+		ret = IRQ_HANDLED;
+	}
+	}
+	spin_unlock(&isi->lock);
+
+	return ret;
+}
+
+/* ------------------------------------------------------------------------
+ *  IOCTL videoc handling
+ *  ----------------------------------------------------------------------*/
+
+/* --------Capture ioctls ------------------------------------------------*/
+/* Device capabilities callback function.
+ */
+static int avr32_isi_capture_querycap(struct file *file, void *priv,
+			      struct v4l2_capability *cap)
+{
+	strcpy(cap->driver, "atmel-isi");
+	strcpy(cap->card, "Atmel Image Sensor Interface");
+	cap->version = ATMEL_ISI_VERSION;
+	/* V4L2_CAP_VIDEO_CAPTURE -> This is a capture device
+	 * V4L2_CAP_READWRITE -> read/write interface used
+	 */
+	cap->capabilities = (V4L2_CAP_VIDEO_CAPTURE 
+			     | V4L2_CAP_READWRITE
+			     );
+	return 0;
+}
+
+/*  Input enumeration callback function. 
+ *  Enumerates available input devices.
+ *  This can be called many times from the V4L2-layer by 
+ *  incrementing the index to get all avaliable input devices.
+ */
+static int avr32_isi_capture_enum_input(struct file *file, void *priv,
+				struct v4l2_input *input)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/* Just one input (ISI) is available */
+	if (input->index != 0)
+		return -EINVAL;
+
+	/* Set input name as camera name */
+	strlcpy(input->name, isi->camera->name, sizeof(input->name));
+	input->type = V4L2_INPUT_TYPE_CAMERA;
+	
+	/* Set to this value just because this should be set to a 
+	 * defined value
+	 */
+	input->std = V4L2_STD_PAL;
+
+	return 0;
+}
+/* Selects an input device.
+ *  One input device (ISI) currently supported.
+ */
+static int avr32_isi_capture_s_input(struct file *file, void *priv,
+			     unsigned int index)
+{
+	if (index != 0)
+		return -EINVAL;
+	return 0;
+}
+
+/* Gets current input device.
+ */
+static int avr32_isi_capture_g_input(struct file *file, void *priv,
+			     unsigned int *index)
+{
+	*index = 0;
+	return 0;
+}
+
+/* Format callback function 
+ * Returns a v4l2_fmtdesc structure with according values to a
+ * index.
+ * This function is called from user space until it returns 
+ * -EINVAL.
+ */
+static int avr32_isi_capture_enum_fmt_cap(struct file *file, void *priv,
+				  struct v4l2_fmtdesc *fmt)
+{
+	if (fmt->index != 0)
+		return -EINVAL;
+
+	/* if we want to pretend another ISI output 
+	 * this is usefull if we input an other input format from a camera
+	 * than specified in the ISI -> makes it possible to swap bytes 
+	 * in the ISI output format but messes up the preview path output
+	 */ 
+	if(capture_v4l2_fmt){
+		fmt->pixelformat = capture_v4l2_fmt;
+	}
+	else {
+		/* This is the format the ISI tries to output */
+		strcpy(fmt->description, "YCbYCr (YUYV) 4:2:2");
+		fmt->pixelformat = V4L2_PIX_FMT_YUYV;
+	}
+
+	return 0;
+}
+
+static int avr32_isi_capture_try_fmt_cap(struct file *file, void *priv,
+			struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/* Just return the current format for now */
+	memcpy(&vfmt->fmt.pix, &isi->format.pix,
+		sizeof(struct v4l2_pix_format));
+
+	return 0;
+}
+
+/* Gets current hardware configuration
+ *  For capture devices the pixel format settings are 
+ *  important.
+ */
+static int avr32_isi_capture_g_fmt_cap(struct file *file, void *priv,
+			       struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/* Return current pixel format */
+	memcpy(&vfmt->fmt.pix, &isi->format.pix,
+	       sizeof(struct v4l2_pix_format));
+
+	return 0;
+}
+
+static int avr32_isi_capture_s_fmt_cap(struct file *file, void *priv,
+			       struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+	int ret = 0;
+	
+	/* We have a fixed format so just copy the current format 
+	 * back
+	 */
+	memcpy(&vfmt->fmt.pix, &isi->format.pix,
+		sizeof(struct v4l2_pix_format));
+
+	return ret;
+}
+
+/* ------------ Preview path ioctls ------------------------------*/
+/* Device capabilities callback function.
+ */
+static int avr32_isi_querycap(struct file *file, void *priv,
+			      struct v4l2_capability *cap)
+{
+	strcpy(cap->driver, "atmel-isi");
+	strcpy(cap->card, "Atmel Image Sensor Interface");
+	cap->version = ATMEL_ISI_VERSION;
+	/* V4L2_CAP_VIDEO_CAPTURE -> This is a capture device
+	 * V4L2_CAP_READWRITE -> read/write interface used
+	 * V4L2_CAP_STREAMING -> ioctl + mmap interface used
+	 */
+	cap->capabilities = (V4L2_CAP_VIDEO_CAPTURE 
+			     | V4L2_CAP_READWRITE
+			     | V4L2_CAP_STREAMING
+			     );
+	return 0;
+}
+
+/* Input enumeration callback function. 
+ *  Enumerates available input devices.
+ *  This can be called many times from the V4L2-layer by 
+ *  incrementing the index to get all avaliable input devices.
+ */
+static int avr32_isi_enum_input(struct file *file, void *priv,
+				struct v4l2_input *input)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/* Just one input (ISI) is available */
+	if (input->index != 0)
+		return -EINVAL;
+
+	/* Set input name as camera name */
+	strlcpy(input->name, isi->camera->name, sizeof(input->name));
+	input->type = V4L2_INPUT_TYPE_CAMERA;
+	
+	/* Set to this value just because this should be set to a 
+	 * defined value
+	 */
+	input->std = V4L2_STD_PAL;
+
+	return 0;
+}
+
+/* Selects an input device.
+ *  One input device (ISI) currently supported.
+ */
+static int avr32_isi_s_input(struct file *file, void *priv,
+			     unsigned int index)
+{
+	if (index != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+/* Gets current input device.
+ */
+static int avr32_isi_g_input(struct file *file, void *priv,
+			     unsigned int *index)
+{
+	*index = 0;
+	return 0;
+}
+
+/* Format callback function 
+ * Returns a v4l2_fmtdesc structure with according values to a
+ * index.
+ * This function is called from user space until it returns 
+ * -EINVAL.
+ */
+static int avr32_isi_enum_fmt_cap(struct file *file, void *priv,
+				  struct v4l2_fmtdesc *fmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	if (fmt->index != 0)
+		return -EINVAL;
+
+	/* TODO: Return all possible formats 
+	* This depends on ISI and camera.
+	* A enum_fmt function or a data structure should be 
+	* added to the camera driver.
+	* For now just one format supported 
+	*/
+	if(streaming_v4l2_fmt){
+		strcpy(fmt->description, "Pretended format");
+	}
+	else{
+		strcpy(fmt->description, "Normal format");
+	}
+	fmt->pixelformat = isi->streaming_format.pix.pixelformat;//V4L2_PIX_FMT_UYVY;
+
+	return 0;
+}
+
+static int avr32_isi_try_fmt_cap(struct file *file, void *priv,
+			struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/* FIXME For now we just return the current format*/
+	memcpy(&vfmt->fmt.pix, &isi->streaming_format.pix,
+		sizeof(struct v4l2_pix_format));
+	return 0;
+}
+
+/* Gets current hardware configuration
+ *  For capture devices the pixel format settings are 
+ *  important.
+ */
+static int avr32_isi_g_fmt_cap(struct file *file, void *priv,
+			       struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+
+	/*Copy current pixel format structure to user space*/
+	memcpy(&vfmt->fmt.pix, &isi->streaming_format.pix,
+	       sizeof(struct v4l2_pix_format));
+
+	return 0;
+}
+
+static int avr32_isi_s_fmt_cap(struct file *file, void *priv,
+			       struct v4l2_format *vfmt)
+{
+	struct atmel_isi_fh *fh = priv;
+	struct atmel_isi *isi = fh->isi;
+	int ret = 0;
+	
+	/* Just return the current format as we do not support
+	* format switching */
+	memcpy(&vfmt->fmt.pix, &isi->streaming_format.pix,
+		sizeof(struct v4l2_pix_format));
+
+	return ret;
+}
+
+/* Checks if control is supported in driver
+ * No controls currently supported yet
+ */
+static int avr32_isi_queryctrl(struct file *file, void *priv,
+			   struct v4l2_queryctrl *qc)
+{
+	switch(qc->id){
+	case V4L2_CID_BRIGHTNESS:
+		strcpy(qc->name, "Brightness");
+		qc->minimum = 0;
+		qc->maximum = 100;
+		qc->step = 1;
+		qc->default_value = 50;
+		qc->flags = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int avr32_isi_g_ctrl(struct file *file, void *priv,
+			struct v4l2_control *ctrl)
+{
+	switch(ctrl->id){
+	case V4L2_CID_BRIGHTNESS:
+		ctrl->value = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int avr32_isi_s_ctrl(struct file *file, void *priv,
+			struct v4l2_control *ctrl)
+{
+	switch(ctrl->id){
+	case V4L2_CID_BRIGHTNESS:
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int avr32_isi_reqbufs(struct file *file, void *private_data, 
+			struct v4l2_requestbuffers *req)
+{
+	/* Only memory mapped buffers supported*/
+	if(req->memory != V4L2_MEMORY_MMAP){
+		pr_debug("atmel_isi: buffer format not supported\n");
+		return -EINVAL;
+	}
+	pr_debug("atmel_isi: Requested %d buffers. Using %d buffers\n",
+		req->count, video_buffers);
+	/* buffer number is fixed for now as it is difficult to get 
+	 * that memory at runtime */	
+	req->count = video_buffers;
+	memset(&req->reserved, 0, sizeof(req->reserved));
+	return 0;
+}
+
+static int avr32_isi_querybuf(struct file *file, void *private_data, 
+			struct v4l2_buffer *buf)
+{
+	struct atmel_isi_fh *fh = private_data;
+	struct atmel_isi *isi = fh->isi;
+	struct frame_buffer *buffer; 
+
+	if(unlikely(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+		return -EINVAL;
+	if(unlikely(buf->index >= video_buffers))
+		return -EINVAL;
+
+	buffer = &(isi->video_buffer[buf->index]);
+
+	buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	buf->length = video_buffer_size;
+	buf->memory = V4L2_MEMORY_MMAP;
+
+	/* set index as mmap reference to the buffer */
+	buf->m.offset = buf->index << PAGE_SHIFT;
+	
+	switch(buffer->status){
+	case FRAME_UNUSED:
+	case FRAME_ERROR:
+	case FRAME_QUEUED:
+		buf->flags |= V4L2_BUF_FLAG_QUEUED;
+		buf->bytesused = buffer->bytes_used;
+		break;
+	case FRAME_DONE:
+		buf->flags |= V4L2_BUF_FLAG_DONE;
+		buf->bytesused = buffer->bytes_used;
+		buf->sequence = buffer->sequence;
+		buf->timestamp = buffer->timestamp;
+		break;
+	}
+
+	buf->field = V4L2_FIELD_NONE; /* no interlacing stuff */
+
+	if(buffer->mmap_count)
+		buf->flags |= V4L2_BUF_FLAG_MAPPED;
+	else 
+		buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
+
+	pr_debug("atmel_isi: querybuf index:%d offset:%d\n",
+		buf->index, buf->m.offset);
+
+	return 0;
+}
+
+static int avr32_isi_qbuf(struct file *file, void *private_data,
+			struct v4l2_buffer *buf)
+{
+	struct atmel_isi_fh *fh = private_data;
+	struct atmel_isi *isi = fh->isi;
+	struct frame_buffer *buffer;
+	
+	if(unlikely(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+		return -EINVAL;
+	if(unlikely(buf->index >= video_buffers || buf->index < 0))
+		return -EINVAL;
+	if(unlikely(buf->memory != V4L2_MEMORY_MMAP))
+		return -EINVAL;
+
+	buffer = &(isi->video_buffer[buf->index]);
+	if(unlikely(buffer->status != FRAME_UNUSED))
+		return -EINVAL;
+
+	mutex_lock(&isi->mutex);
+	buf->flags |= V4L2_BUF_FLAG_QUEUED;
+	buf->flags &= ~V4L2_BUF_FLAG_DONE;
+	buffer->status = FRAME_QUEUED;
+	kfifo_put(isi->grabq, (unsigned char*) &buf->index, sizeof(int));
+	mutex_unlock(&isi->mutex);
+
+	return 0;
+}
+
+static int avr32_isi_dqbuf(struct file *file, void *private_data,
+			struct v4l2_buffer *buf)
+{
+	struct atmel_isi_fh *fh = private_data;
+	struct atmel_isi *isi = fh->isi;
+	struct frame_buffer *buffer;
+	int reqnr = 0;
+
+	if(unlikely(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+		return -EINVAL;
+	/* Mencoder does not set this flag
+	 *
+	if(unlikely(buf->memory != V4L2_MEMORY_MMAP)){
+		pr_debug("isi: dequeue failed buffer not of mmapped type\n");
+		return -EINVAL;
+	}*/
+	if((kfifo_len(isi->doneq) == 0) && (file->f_flags & O_NONBLOCK)){
+		pr_debug("Done-queue is empty\n");
+		return -EAGAIN;
+	}
+	/*
+	if(wait_event_interruptible(isi->capture_wq, 
+		kfifo_len(isi->doneq) != 0) < 0){
+		pr_debug("Done-queue interrupted\n");
+		return -EINTR;
+	}
+	*/
+	if(!kfifo_get(isi->doneq, (unsigned char*) &reqnr, sizeof(int))){
+		return -EBUSY;
+	}
+	buffer = &(isi->video_buffer[reqnr]);
+
+	if(unlikely(buffer->status != FRAME_DONE)){
+		pr_debug("isi: error, dequeued buffer not ready\n");
+		return -EINVAL;
+	}
+	buf->index = reqnr;
+	buf->bytesused = buffer->bytes_used;
+	buf->timestamp = buffer->timestamp;
+	buf->sequence = buffer->sequence;
+	buf->m.offset = reqnr << PAGE_SHIFT;
+	buffer->status = FRAME_UNUSED;
+	buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
+
+	buf->length = isi->capture_buffer_size;
+	buf->field = V4L2_FIELD_NONE;
+	buf->memory = V4L2_MEMORY_MMAP;
+	return 0;
+}
+
+static int avr32_isi_streamon(struct file *file, void *private_data,
+			enum v4l2_buf_type type)
+{
+	struct atmel_isi_fh *fh = private_data;
+	struct atmel_isi *isi = fh->isi;
+	int reqnr;
+	struct frame_buffer *buffer;
+	u32 cr1;
+
+	if(unlikely(type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+		return -EINVAL;
+	
+	if(!kfifo_get(isi->grabq, (unsigned char*) &reqnr, sizeof(int))){
+		mutex_unlock(&isi->mutex);
+		pr_debug("atmel_isi: No buffer in IN-Queue, start of streaming\
+			aborted (one buffer is required in IN-Queue)\n"); 
+		return -EINVAL;
+	}
+	buffer = &(isi->video_buffer[reqnr]);
+	
+
+	spin_lock_irq(isi->lock);
+	isi->streaming = 1;
+	isi->current_buffer = buffer;
+	cr1 = isi_readl(isi, CR1);
+#ifdef ISI_CODEC
+	isi_writel(isi, CDBA, buffer->fb_desc.fb_address);
+	/* Enable codec path */
+	cr1 |= ISI_BIT(CODEC_ON) | ISI_BIT(DIS);
+#else
+	isi_writel(isi, PPFBD, isi->fbd_list_start);
+#endif
+	/* Enable interrupts */
+	isi_readl(isi, SR);
+	/* FIXME enable codec/preview path according to setup */
+	isi_writel(isi, IER, ISI_BIT(FO_C_EMP) | ISI_BIT(FO_P_EMP));
+
+	cr1 |= ISI_BF(FRATE, frame_rate_scaler);
+
+	/* Enable ISI module*/
+	cr1 &= ~ISI_BIT(DIS);
+	isi_writel(isi, CR1, cr1);
+	spin_unlock_irq(isi->lock);
+
+	isi->camera->start_capture(isi->camera);
+
+	return 0;
+}
+
+static int avr32_isi_streamoff(struct file *file, void *private_data,
+			enum v4l2_buf_type type)
+{
+	struct atmel_isi_fh *fh = private_data;
+	struct atmel_isi *isi = fh->isi;
+
+	if(unlikely(type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
+		return -EINVAL;
+
+	spin_lock_irq(isi->lock);
+	isi->streaming = 0;
+#ifdef ISI_CODEC
+	/* Disble codec path */
+	isi_writel(isi, CR1, isi_readl(isi, CR1) & (~ISI_BIT(CODEC_ON)));
+#endif
+	/* Disable interrupts */
+	isi_writel(isi, IDR, ISI_BIT(FO_C_EMP) | ISI_BIT(FO_P_EMP));
+	
+	/* Disable ISI module*/
+	isi_writel(isi, CR1, isi_readl(isi, CR1) | ISI_BIT(DIS));
+	spin_unlock_irq(isi->lock);
+
+	isi->camera->stop_capture(isi->camera);
+	pr_debug("atmel_isi: Stream off\n");
+
+	return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+static int avr32_isi_capture_close (struct inode *inode, struct file *file)
+{
+	struct atmel_isi_fh *fh = file->private_data;
+	struct atmel_isi *isi = fh->isi;
+	u32 cr1;
+
+	mutex_lock(&isi->mutex);
+
+	isi->capture_users--;
+	kfree(fh);
+
+	/* Stop camera and ISI  if driver has no users */
+	if(!isi->stream_users) {
+		isi->camera->stop_capture(isi->camera);
+
+		spin_lock_irq(&isi->lock);
+		cr1 = isi_readl(isi, CR1);
+		cr1 |= ISI_BIT(DIS);
+		isi_writel(isi, CR1, cr1);
+		spin_unlock_irq(&isi->lock);
+	}
+	mutex_unlock(&isi->mutex);
+
+	return 0;
+}
+
+static int avr32_isi_capture_open (struct inode *inode, struct file *file)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct atmel_isi *isi = to_atmel_isi(vdev);
+	struct atmel_isi_fh *fh;
+	int ret = -EBUSY;
+	unsigned long timeout;
+
+	mutex_lock(&isi->mutex);
+	
+
+	if (isi->capture_users) {
+		pr_debug("%s: open(): device busy\n", vdev->name);
+		goto out;
+	}
+
+	if (!isi->camera) {
+
+		ret = -ENODEV;
+		isi->camera = avr32_isi_grab_camera(isi);
+		if (!isi->camera)
+			goto out;
+
+		ret = avr32_isi_set_camera_input(isi);
+		if(ret)
+			goto out;
+	}
+
+	avr32_isi_capture_set_format(isi, &isi->format);
+
+	/*
+	 * Reset the controller and wait for completion. The
+	 * reset will only succeed if we have a pixel clock
+	 * from the camera.
+	 */
+	if(isi->stream_users == 0){
+		
+		init_completion(&isi->reset_complete);
+		isi_writel(isi, IER, ISI_BIT(SOFTRST));
+		isi_writel(isi, CR1, ISI_BIT(RST));
+
+		timeout = wait_for_completion_timeout(&isi->reset_complete,
+			msecs_to_jiffies(100));
+
+		isi_writel(isi, IDR, ~0UL);
+		if (timeout == 0) {
+			ret = -ETIMEDOUT;
+			goto out;
+		}
+	}
+	
+	ret = -ENOMEM;
+	fh = kzalloc(sizeof(struct atmel_isi_fh), GFP_KERNEL);
+	if (!fh) {
+		pr_debug("%s: open(): out of memory\n", vdev->name);
+		goto out;
+	}
+
+	fh->isi = isi;
+	file->private_data = fh;
+	isi->capture_users++;
+
+	ret = 0;
+
+out:
+	mutex_unlock(&isi->mutex);
+	return ret;
+}
+
+static ssize_t avr32_isi_capture_read(struct file *file, char __user *data,
+			      size_t count, loff_t *ppos)
+{
+	struct atmel_isi_fh *fh = file->private_data;
+	struct atmel_isi *isi = fh->isi;
+	int state;
+	int ret;
+
+	state = STATE_IDLE;
+
+	pr_debug("isi: read %zu bytes read_off=%u state=%u sizeimage=%u\n",
+		count, fh->read_off, state, isi->format.pix.sizeimage);
+	isi->camera->start_capture(isi->camera);
+	
+
+	avr32_isi_start_capture(isi);
+
+	ret = wait_event_interruptible( isi->capture_wq,
+			(isi->state == STATE_CAPTURE_DONE)
+			|| (isi->state == STATE_CAPTURE_ERROR));
+	if (ret)
+		return ret;
+	if (isi->state == STATE_CAPTURE_ERROR) {
+		isi->state = STATE_IDLE;
+		return -EIO;
+	}
+
+	fh->read_off = 0;
+
+	count = min(count, (size_t)isi->format.pix.sizeimage - fh->read_off);
+	ret = copy_to_user(data, isi->capture_buf + fh->read_off, count);
+	if (ret)
+		return -EFAULT;
+
+	fh->read_off += count;
+	if (fh->read_off >= isi->format.pix.sizeimage)
+		isi->state = STATE_IDLE;
+
+	return count;
+}
+
+static void avr32_isi_capture_release (struct video_device *vdev)
+{
+	pr_debug("%s: release\n", vdev->name);
+}
+
+/* ----------------- Streaming interface -------------------------------------*/
+static void avr32_isi_vm_open(struct vm_area_struct *vma){
+	struct frame_buffer *buffer = 
+		(struct frame_buffer *) vma->vm_private_data;
+	buffer->mmap_count++;
+	pr_debug("atmel_isi: vm_open count=%d\n",buffer->mmap_count);
+}
+
+static void avr32_isi_vm_close(struct vm_area_struct *vma){
+	struct frame_buffer *buffer = 
+		(struct frame_buffer *) vma->vm_private_data;
+	pr_debug("atmel_isi: vm_close count=%d\n",buffer->mmap_count);	
+	buffer->mmap_count--;
+	if(buffer->mmap_count < 0)
+		printk("atmel_isi: mmap_count went negative\n");
+}
+
+/* FIXME remove this function 
+struct page *avr32_isi_vm_nopage( struct vm_area_struct *vma, 
+	unsigned long address, int *type )
+{
+    return NOPAGE_SIGBUS;
+}
+*/
+
+static struct vm_operations_struct avr32_isi_vm_ops = {
+	.open = avr32_isi_vm_open,
+	.close = avr32_isi_vm_close,
+	//.nopage = avr32_isi_vm_nopage,
+};
+
+static int avr32_isi_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	unsigned long pfn;
+	int ret;
+	struct atmel_isi_fh *fh = file->private_data;
+	struct atmel_isi * isi = fh->isi;
+	struct frame_buffer *buffer = &(isi->video_buffer[vma->vm_pgoff]);
+	unsigned long size = vma->vm_end - vma->vm_start;
+
+	pr_debug("atmel_isi: mmap called pgoff=%ld size=%ld \n", 
+		vma->vm_pgoff, size);
+
+	if(size > video_buffer_size){
+		pr_debug("atmel_isi: mmap requested buffer is to large\n");
+		return -EINVAL;
+	}
+	if(vma->vm_pgoff > video_buffers){
+		pr_debug("atmel_isi: invalid mmap page offset\n");
+		return -EINVAL;
+	}
+	pfn = isi->video_buffer[vma->vm_pgoff].fb_desc.fb_address >> PAGE_SHIFT;
+
+	ret = remap_pfn_range(vma, vma->vm_start, pfn,
+		vma->vm_end - vma->vm_start, vma->vm_page_prot);
+	if(ret){
+		return ret;
+	}
+	
+	vma->vm_ops = &avr32_isi_vm_ops;
+	vma->vm_flags = VM_DONTEXPAND; /* fixed size */
+	vma->vm_flags |= VM_RESERVED;/* do not swap out */
+	vma->vm_flags |= VM_DONTCOPY;
+	vma->vm_flags |= VM_SHARED;
+	vma->vm_private_data = (void *) buffer;
+	avr32_isi_vm_open(vma);
+
+	pr_debug("atmel_isi: vma start=0x%08lx, size=%ld phys=%ld \n",
+		(unsigned long) vma->vm_start,
+		(unsigned long) vma->vm_end - (unsigned long) vma->vm_start,
+		pfn << PAGE_SHIFT);
+	return 0;
+}
+
+static unsigned int avr32_isi_poll(struct file *file, poll_table *wait)
+{
+	struct atmel_isi_fh *fh = file->private_data;
+	struct atmel_isi *isi = fh->isi;
+	unsigned int ret = 0;
+
+	mutex_lock(&isi->mutex);
+	poll_wait(file, &isi->capture_wq, wait);
+	if(kfifo_len(isi->doneq))
+		ret = POLLIN | POLLRDNORM;
+	mutex_unlock(&isi->mutex);
+
+	return ret;
+}
+
+static int avr32_isi_stream_close (struct inode *inode, struct file *file)
+{
+	struct atmel_isi_fh *fh = file->private_data;
+	struct atmel_isi *isi = fh->isi;
+	u32 cr1;
+
+	mutex_lock(&isi->mutex);
+
+	isi->stream_users--;
+	kfree(fh);
+
+	/* Stop camera and ISI if driver has no users */
+	if(!isi->capture_users) {
+		isi->camera->stop_capture(isi->camera);
+
+		spin_lock_irq(&isi->lock);
+		cr1 = isi_readl(isi, CR1);
+		cr1 |= ISI_BIT(DIS);
+		isi_writel(isi, CR1, cr1);
+		spin_unlock_irq(&isi->lock);
+	}
+
+	mutex_unlock(&isi->mutex);
+
+	return 0;
+}
+
+static int avr32_isi_stream_open (struct inode *inode, struct file *file)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct atmel_isi *isi = to_atmel_isi(vdev);
+	struct atmel_isi_fh *fh;
+	int ret = -EBUSY;
+	unsigned long timeout;
+
+	mutex_lock(&isi->mutex);
+	
+
+	if (isi->stream_users) {
+		pr_debug("%s: open(): device busy\n", vdev->name);
+		goto out;
+	}
+
+	if (!isi->camera) {
+		ret = -ENODEV;
+		isi->camera = avr32_isi_grab_camera(isi);
+		if (!isi->camera)
+			goto out;
+		ret = -EINVAL;
+		ret = avr32_isi_set_camera_input(isi);
+		if(ret)
+			goto out;
+	}
+	avr32_isi_streaming_set_format(isi, &isi->format);
+	kfifo_reset(isi->grabq);
+	kfifo_reset(isi->doneq);
+
+	/*
+	 * Reset the controller and wait for completion. The
+	 * reset will only succeed if we have a pixel clock
+	 * from the camera.
+	 */
+	if(isi->stream_users == 0){
+		
+		init_completion(&isi->reset_complete);
+		isi_writel(isi, IER, ISI_BIT(SOFTRST));
+		isi_writel(isi, CR1, ISI_BIT(RST));
+
+		timeout = wait_for_completion_timeout(&isi->reset_complete,
+			msecs_to_jiffies(100));
+
+		if (timeout == 0) {
+			ret = -ETIMEDOUT;
+			goto out;
+		}
+		isi_writel(isi, IDR, ~0UL);
+	}
+
+	ret = -ENOMEM;
+	fh = kzalloc(sizeof(struct atmel_isi_fh), GFP_KERNEL);
+	if (!fh) {
+		pr_debug("%s: open(): out of memory\n", vdev->name);
+		goto out;
+	}
+
+	fh->isi = isi;
+	file->private_data = fh;
+	isi->stream_users++;
+
+	ret = 0;
+
+out:
+	mutex_unlock(&isi->mutex);
+	return ret;
+}
+
+static void avr32_isi_stream_release (struct video_device *vdev)
+{
+	struct atmel_isi *isi = to_atmel_isi(vdev);
+	pr_debug("%s: release\n", vdev->name);
+	kfree(isi);
+}
+
+/* -----------------------------------------------------------------------*/
+
+/* Streaming v4l2 device file operations */
+static struct file_operations avr32_isi_streaming_fops = {
+	.owner		= THIS_MODULE,
+	.ioctl		= video_ioctl2,
+	.open		= avr32_isi_stream_open,
+	.release	= avr32_isi_stream_close,
+	.mmap		= avr32_isi_mmap,
+	.poll		= avr32_isi_poll,
+};
+
+/* Capture v4l2 device file operations */
+static struct file_operations avr32_isi_capture_fops = {
+	.owner		= THIS_MODULE,
+	.open		= avr32_isi_capture_open,
+	.release	= avr32_isi_capture_close,
+	.read		= avr32_isi_capture_read,
+	.ioctl		= video_ioctl2,
+};
+
+static int __exit avr32_isi_remove(struct platform_device *pdev)
+{
+	struct atmel_isi *isi = platform_get_drvdata(pdev);
+	int i;
+
+	if (isi->camera)
+		isi->camera->stop_capture(isi->camera);
+
+	if (isi->camera)
+		avr32_isi_release_camera(isi, isi->camera);
+	video_unregister_device(&isi->cdev);
+	video_unregister_device(&isi->vdev);
+
+	platform_set_drvdata(pdev, NULL);
+
+	/* release capture buffer */
+	dma_free_coherent(&pdev->dev, capture_buffer_size,
+			  isi->capture_buf, isi->capture_phys);
+
+	/* release frame buffers */
+	for(i = 0; i < video_buffers; i++){
+		dma_free_coherent(&pdev->dev, 
+			video_buffer_size,
+			isi->video_buffer[i].frame_buffer,
+			isi->video_buffer[i].fb_desc.fb_address);
+	}
+
+	kfifo_free(isi->doneq);
+	kfifo_free(isi->grabq);
+	
+	free_irq(isi->irq, isi);
+	iounmap(isi->regs);
+	clk_disable(isi->hclk);
+	clk_disable(isi->pclk);
+	clk_put(isi->hclk);
+	clk_put(isi->pclk);
+
+	/*
+	 * Don't free isi here -- it will be taken care of by the
+	 * release() callback.
+	 */
+
+	return 0;
+}
+
+
+static int __init avr32_isi_probe(struct platform_device *pdev)
+{
+	unsigned int irq;
+	struct atmel_isi *isi;
+	struct clk *pclk, *hclk;
+	struct resource *regs;
+	int ret;
+	int i;
+	int video_bytes_used = video_buffer_size;
+
+	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if(!regs)
+		return -ENXIO;
+
+	pclk = clk_get(&pdev->dev, "pclk");
+	if (IS_ERR(pclk))
+		return PTR_ERR(pclk);
+	hclk = clk_get(&pdev->dev, "hclk");
+	if (IS_ERR(hclk)) {
+		ret = PTR_ERR(hclk);
+		goto err_hclk;
+	}
+	clk_enable(pclk);
+	clk_enable(hclk);
+
+	isi = kzalloc(sizeof(struct atmel_isi), GFP_KERNEL);
+	if(!isi){
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "can't allocate interface!\n");
+		goto err_alloc_isi;
+	}
+
+	isi->pclk = pclk;
+	isi->hclk = hclk;
+
+	/* Round up buffer sizes to the next page if needed */
+	video_buffer_size = PAGE_ALIGN(video_buffer_size);
+	capture_buffer_size = PAGE_ALIGN(capture_buffer_size);
+
+	spin_lock_init(&isi->lock);
+	mutex_init(&isi->mutex);
+	init_waitqueue_head(&isi->capture_wq);
+	
+	/* Initialize v4l2 capture device */
+	isi->cdev.fops = &avr32_isi_capture_fops;
+	strcpy(isi->cdev.name, "atmel_isi_capture");
+	isi->cdev.type = VFL_TYPE_GRABBER;
+	isi->cdev.type2 = VID_TYPE_CAPTURE;
+	isi->cdev.minor = -1;
+	isi->cdev.release =avr32_isi_capture_release;
+	isi->cdev.vidioc_querycap = avr32_isi_capture_querycap;
+	isi->cdev.vidioc_enum_fmt_cap = avr32_isi_capture_enum_fmt_cap;
+	isi->cdev.vidioc_try_fmt_cap = avr32_isi_capture_try_fmt_cap;
+	isi->cdev.vidioc_g_fmt_cap = avr32_isi_capture_g_fmt_cap;
+	isi->cdev.vidioc_s_fmt_cap = avr32_isi_capture_s_fmt_cap;
+	isi->cdev.vidioc_enum_input = avr32_isi_capture_enum_input;
+	isi->cdev.vidioc_g_input = avr32_isi_capture_g_input;
+	isi->cdev.vidioc_s_input = avr32_isi_capture_s_input;
+#ifdef DEBUG
+	isi->cdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
+#endif
+
+	/* Initialize v4l2 streaming device */
+	isi->vdev.fops = &avr32_isi_streaming_fops;
+	strcpy(isi->vdev.name, "atmel-isi");
+	isi->vdev.type = VFL_TYPE_GRABBER;
+	isi->vdev.type2 = VID_TYPE_CAPTURE;
+	isi->vdev.minor = -1;
+	isi->vdev.release = avr32_isi_stream_release;
+#ifdef DEBUG
+	isi->vdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
+#endif
+
+	isi->vdev.vidioc_querycap = avr32_isi_querycap;
+	isi->vdev.vidioc_enum_fmt_cap = avr32_isi_enum_fmt_cap;
+	isi->vdev.vidioc_try_fmt_cap = avr32_isi_try_fmt_cap;
+	isi->vdev.vidioc_g_fmt_cap = avr32_isi_g_fmt_cap;
+	isi->vdev.vidioc_s_fmt_cap = avr32_isi_s_fmt_cap;
+	isi->vdev.vidioc_enum_input = avr32_isi_enum_input;
+	isi->vdev.vidioc_g_input = avr32_isi_g_input;
+	isi->vdev.vidioc_s_input = avr32_isi_s_input;
+	isi->vdev.vidioc_queryctrl = avr32_isi_queryctrl;
+	isi->vdev.vidioc_g_ctrl = avr32_isi_g_ctrl;
+	isi->vdev.vidioc_s_ctrl = avr32_isi_s_ctrl;
+	isi->vdev.vidioc_querybuf = avr32_isi_querybuf;
+	isi->vdev.vidioc_reqbufs = avr32_isi_reqbufs;
+	isi->vdev.vidioc_qbuf = avr32_isi_qbuf;
+	isi->vdev.vidioc_dqbuf = avr32_isi_dqbuf;
+	isi->vdev.vidioc_streamon = avr32_isi_streamon;
+	isi->vdev.vidioc_streamoff = avr32_isi_streamoff;
+
+	isi->regs = ioremap(regs->start, regs->end - regs->start + 1);
+        if (!isi->regs) {
+		ret = -ENOMEM;
+		goto err_ioremap;
+	}
+
+	irq = platform_get_irq(pdev,0);
+	ret = request_irq(irq, isi_interrupt, 0, "isi", isi);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to request irq %d\n", irq);
+		goto err_req_irq;
+	}
+	isi->irq = irq;
+
+	/* Allocate ISI capture buffer */
+	isi->capture_buf = dma_alloc_coherent(&pdev->dev,
+					      capture_buffer_size,
+					      &isi->capture_phys,
+					      GFP_KERNEL);
+	if (!isi->capture_buf) {
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "failed to allocate capture buffer\n");
+		goto err_alloc_cbuf;
+	}
+
+	/* Allocate and initialize video buffers */
+	for(i=0;i < video_buffers; i++){
+		memset(&isi->video_buffer[i], 0, sizeof(struct frame_buffer));
+		isi->video_buffer[i].frame_buffer = 
+			dma_alloc_coherent(&pdev->dev,
+				video_buffer_size,
+				(dma_addr_t *)
+				&(isi->video_buffer[i].fb_desc.fb_address),
+				GFP_KERNEL);
+		if(!isi->video_buffer[i].frame_buffer){
+			ret = -ENOMEM;
+			dev_err(&pdev->dev, 
+				"failed to allocate video buffer\n");
+			goto err_alloc_vbuf;
+		}
+		
+		isi->video_buffer[i].bytes_used = video_bytes_used;
+		isi->video_buffer[i].status = FRAME_UNUSED;
+		isi->video_buffer[i].index = i;
+
+#ifdef DEBUG
+	/* Put some color into the buffers */
+	/*
+		memset(isi->video_buffer[i].frame_buffer, (i*4)%0xFF, 
+			video_buffer_size); 
+			*/
+#endif
+	}
+	/* set up frame buffer descriptor list for ISI module*/
+	/* FIXME 
+	isi->fbd_list_start = dma_map_single(&pdev->dev,
+		&isi->video_buffer[0].fb_desc,
+		sizeof(struct fbd),
+		DMA_NONE);
+		*/
+	isi->fbd_list_start = __pa(&isi->video_buffer[0].fb_desc);
+	for(i=0; i < (video_buffers - 1); i++){
+		isi->video_buffer[i].fb_desc.next_fbd_address =
+		/*
+			dma_map_single(&pdev->dev, 
+				&isi->video_buffer[i+1].fb_desc,
+				sizeof(struct fbd),
+				DMA_NONE);*/
+			__pa(&isi->video_buffer[i+1]);
+	}
+	/* FIXME
+	 * isi->video_buffer[i].fb_desc.next_fbd_address =
+	 * 	isi->fbd_list_start;
+	 */
+	isi->video_buffer[i].fb_desc.next_fbd_address = 
+		__pa(&isi->video_buffer[0]);
+	
+#ifdef DEBUG
+	for(i=0;i < video_buffers; i++){
+		pr_debug("atmel_isi: fbd at %08lx video buffer at \
+phys addr %08lx \n", __pa(&isi->video_buffer[i]),
+		(unsigned long) isi->video_buffer[i].fb_desc.fb_address);
+	}
+#endif
+	dev_info(&pdev->dev,
+		 "capture buffer: %d bytes at %p (phys 0x%08x)\n",
+		 capture_buffer_size, isi->capture_buf,
+		 isi->capture_phys);
+	
+	spin_lock_init(&isi->grabq_lock);
+	isi->grabq = kfifo_alloc(sizeof(int) * video_buffers, GFP_KERNEL,
+		&isi->grabq_lock);
+	if(IS_ERR(isi->grabq)){
+		dev_err(&pdev->dev, "fifo allocation failed\n");
+		goto err_fifo_alloc1;
+	}
+	spin_lock_init(&isi->doneq_lock);
+	isi->doneq = kfifo_alloc(sizeof(int) * video_buffers, GFP_KERNEL,
+		&isi->doneq_lock);
+	if(IS_ERR(isi->doneq)){
+		dev_err(&pdev->dev, "fifo allocation failed\n");
+		goto err_fifo_alloc2;
+	}
+
+	isi_writel(isi, CR1, ISI_BIT(DIS));
+	
+	ret = video_register_device(&isi->cdev, VFL_TYPE_GRABBER, -1);
+	if(ret)
+		goto err_register1;
+
+	ret = video_register_device(&isi->vdev, VFL_TYPE_GRABBER, -1);
+	if (ret)
+		goto err_register2;
+
+	platform_set_drvdata(pdev, isi);
+
+	dev_info(&pdev->dev, "Atmel ISI V4L2 device at 0x%08lx\n",
+		 (unsigned long)regs->start);
+
+	return 0;
+
+err_register2:
+	video_unregister_device(&isi->cdev);
+err_register1:
+	kfifo_free(isi->doneq);
+err_fifo_alloc2:
+	kfifo_free(isi->grabq);
+err_fifo_alloc1:
+err_alloc_vbuf:
+	while(i--)
+		dma_free_coherent(&pdev->dev, video_buffer_size,
+				isi->video_buffer[i].frame_buffer,
+				isi->video_buffer[i].fb_desc.fb_address);
+	dma_free_coherent(&pdev->dev, capture_buffer_size,
+				isi->capture_buf,
+				isi->capture_phys);
+err_alloc_cbuf:
+        free_irq(isi->irq, isi);
+err_req_irq:
+	iounmap(isi->regs);
+err_ioremap:
+	kfree(isi);
+err_alloc_isi:
+	clk_disable(hclk);
+	clk_disable(pclk);
+	clk_put(hclk);
+err_hclk:
+	clk_put(pclk);
+
+	return ret;
+
+}
+
+static struct platform_driver avr32_isi_driver = {
+	.probe		= avr32_isi_probe,
+	.remove		= __exit_p(avr32_isi_remove),
+	.driver		= {
+		.name = "atmel_isi",
+		.owner = THIS_MODULE,
+	},
+};
+
+static int __init avr32_isi_init(void)
+{
+	return platform_driver_probe(&avr32_isi_driver, &avr32_isi_probe);
+
+/*FIXME	return  platform_driver_register(&avr32_isi_driver);*/
+}
+
+
+static void __exit avr32_isi_exit(void)
+{
+	platform_driver_unregister(&avr32_isi_driver);
+}
+
+
+module_init(avr32_isi_init);
+module_exit(avr32_isi_exit);
+
+MODULE_AUTHOR("Lars Häring <lharing@atmel.com>");
+MODULE_DESCRIPTION("The V4L2 driver for AVR32 Linux");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("video");
diff --git a/drivers/media/video/atmel-isi.h b/drivers/media/video/atmel-isi.h
new file mode 100644
index 0000000..2aa3c14
--- /dev/null
+++ b/drivers/media/video/atmel-isi.h
@@ -0,0 +1,252 @@
+/*
+ * Register definitions for the Atmel Image Sensor Interface.
+ *
+ * Copyright (C) 2006 Atmel Corporation
+ *
+ * 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 __ASM_AVR32_ISI_H__
+#define __ASM_AVR32_ISI_H__
+
+#include <linux/videodev2.h>
+
+/* ISI register offsets */
+#define ISI_CR1					0x0000
+#define ISI_CR2					0x0004
+#define ISI_SR					0x0008
+#define ISI_IER					0x000c
+#define ISI_IDR					0x0010
+#define ISI_IMR					0x0014
+#define ISI_PSIZE				0x0020
+#define ISI_PDECF				0x0024
+#define ISI_PPFBD				0x0028
+#define ISI_CDBA				0x002c
+#define ISI_Y2R_SET0				0x0030
+#define ISI_Y2R_SET1				0x0034
+#define ISI_R2Y_SET0				0x0038
+#define ISI_R2Y_SET1				0x003c
+#define ISI_R2Y_SET2				0x0040
+
+/* Bitfields in CR1 */
+#define ISI_RST_OFFSET				0
+#define ISI_RST_SIZE				1
+#define ISI_DIS_OFFSET				1
+#define ISI_DIS_SIZE				1
+#define ISI_HSYNC_POL_OFFSET			2
+#define ISI_HSYNC_POL_SIZE			1
+#define ISI_VSYNC_POL_OFFSET			3
+#define ISI_VSYNC_POL_SIZE			1
+#define ISI_PIXCLK_POL_OFFSET			4
+#define ISI_PIXCLK_POL_SIZE			1
+#define ISI_EMB_SYNC_OFFSET			6
+#define ISI_EMB_SYNC_SIZE			1
+#define ISI_CRC_SYNC_OFFSET			7
+#define ISI_CRC_SYNC_SIZE			1
+#define ISI_FRATE_OFFSET			8
+#define ISI_FRATE_SIZE				3
+#define ISI_FULL_OFFSET				12
+#define ISI_FULL_SIZE				1
+#define ISI_THMASK_OFFSET			13
+#define ISI_THMASK_SIZE				2
+#define ISI_CODEC_ON_OFFSET			15
+#define ISI_CODEC_ON_SIZE			1
+#define ISI_SLD_OFFSET				16
+#define ISI_SLD_SIZE				8
+#define ISI_SFD_OFFSET				24
+#define ISI_SFD_SIZE				8
+
+/* Bitfields in CR2 */
+#define ISI_IM_VSIZE_OFFSET			0
+#define ISI_IM_VSIZE_SIZE			11
+#define ISI_GS_MODE_OFFSET			11
+#define ISI_GS_MODE_SIZE			1
+#define ISI_RGB_MODE_OFFSET			12
+#define ISI_RGB_MODE_SIZE			1
+#define ISI_GRAYSCALE_OFFSET			13
+#define ISI_GRAYSCALE_SIZE			1
+#define ISI_RGB_SWAP_OFFSET			14
+#define ISI_RGB_SWAP_SIZE			1
+#define ISI_COL_SPACE_OFFSET			15
+#define ISI_COL_SPACE_SIZE			1
+#define ISI_IM_HSIZE_OFFSET			16
+#define ISI_IM_HSIZE_SIZE			11
+#define ISI_YCC_SWAP_OFFSET			28
+#define ISI_YCC_SWAP_SIZE			2
+#define ISI_RGB_CFG_OFFSET			30
+#define ISI_RGB_CFG_SIZE			2
+
+/* Bitfields in SR */
+#define ISI_CDC_STATUS_OFFSET			3
+#define ISI_CDC_STATUS_SIZE			1
+
+/* Bitfields in SR/IER/IDR/IMR */
+#define ISI_SOF_OFFSET				0
+#define ISI_SOF_SIZE				1
+#define ISI_SOFTRST_OFFSET			2
+#define ISI_SOFTRST_SIZE			1
+#define ISI_CRC_ERR_OFFSET			4
+#define ISI_CRC_ERR_SIZE			1
+#define ISI_FO_C_OVF_OFFSET			5
+#define ISI_FO_C_OVF_SIZE			1
+#define ISI_FO_P_OVF_OFFSET			6
+#define ISI_FO_P_OVF_SIZE			1
+#define ISI_FO_P_EMP_OFFSET			7
+#define ISI_FO_P_EMP_SIZE			1
+#define ISI_FO_C_EMP_OFFSET			8
+#define ISI_FO_C_EMP_SIZE			1
+#define ISI_FR_OVR_OFFSET			9
+#define ISI_FR_OVR_SIZE				1
+
+/* Bitfields in PSIZE */
+#define ISI_PREV_VSIZE_OFFSET			0
+#define ISI_PREV_VSIZE_SIZE			10
+#define ISI_PREV_HSIZE_OFFSET			16
+#define ISI_PREV_HSIZE_SIZE			10
+
+/* Bitfields in PCDEF */
+#define ISI_DEC_FACTOR_OFFSET			0
+#define ISI_DEC_FACTOR_SIZE			8
+
+/* Bitfields in PPFBD */
+#define ISI_PREV_FBD_ADDR_OFFSET		0
+#define ISI_PREV_FBD_ADDR_SIZE			32
+
+/* Bitfields in CDBA */
+#define ISI_CODEC_DMA_ADDR_OFFSET		0
+#define ISI_CODEC_DMA_ADDR_SIZE			32
+
+/* Bitfields in Y2R_SET0 */
+#define ISI_Y2R_SET0_C3_OFFSET			24
+#define ISI_Y2R_SET0_C3_SIZE			8
+
+/* Bitfields in Y2R_SET1 */
+#define ISI_Y2R_SET1_C4_OFFSET			0
+#define ISI_Y2R_SET1_C4_SIZE			9
+#define ISI_YOFF_OFFSET				12
+#define ISI_YOFF_SIZE				1
+#define ISI_CROFF_OFFSET			13
+#define ISI_CROFF_SIZE				1
+#define ISI_CBOFF_OFFSET			14
+#define ISI_CBOFF_SIZE				1
+
+/* Bitfields in R2Y_SET0 */
+#define ISI_C0_OFFSET				0
+#define ISI_C0_SIZE				8
+#define ISI_C1_OFFSET				8
+#define ISI_C1_SIZE				8
+#define ISI_C2_OFFSET				16
+#define ISI_C2_SIZE				8
+#define ISI_ROFF_OFFSET				24
+#define ISI_ROFF_SIZE				1
+
+/* Bitfields in R2Y_SET1 */
+#define ISI_R2Y_SET1_C3_OFFSET			0
+#define ISI_R2Y_SET1_C3_SIZE			8
+#define ISI_R2Y_SET1_C4_OFFSET			8
+#define ISI_R2Y_SET1_C4_SIZE			8
+#define ISI_C5_OFFSET				16
+#define ISI_C5_SIZE				8
+#define ISI_GOFF_OFFSET				24
+#define ISI_GOFF_SIZE				1
+
+/* Bitfields in R2Y_SET2 */
+#define ISI_C6_OFFSET				0
+#define ISI_C6_SIZE				8
+#define ISI_C7_OFFSET				8
+#define ISI_C7_SIZE				8
+#define ISI_C8_OFFSET				16
+#define ISI_C8_SIZE				8
+#define ISI_BOFF_OFFSET				24
+#define ISI_BOFF_SIZE				1
+
+/* Constants for FRATE */
+#define ISI_FRATE_CAPTURE_ALL			0
+
+/* Constants for YCC_SWAP */
+#define ISI_YCC_SWAP_DEFAULT			0
+#define ISI_YCC_SWAP_MODE_1			1
+#define ISI_YCC_SWAP_MODE_2			2
+#define ISI_YCC_SWAP_MODE_3			3
+
+/* Constants for RGB_CFG */
+#define ISI_RGB_CFG_DEFAULT			0
+#define ISI_RGB_CFG_MODE_1			1
+#define ISI_RGB_CFG_MODE_2			2
+#define ISI_RGB_CFG_MODE_3			3
+
+/* Bit manipulation macros */
+#define ISI_BIT(name)					\
+	(1 << ISI_##name##_OFFSET)
+#define ISI_BF(name,value)				\
+	(((value) & ((1 << ISI_##name##_SIZE) - 1))	\
+	 << ISI_##name##_OFFSET)
+#define ISI_BFEXT(name,value)				\
+	(((value) >> ISI_##name##_OFFSET)		\
+	 & ((1 << ISI_##name##_SIZE) - 1))
+#define ISI_BFINS(name,value,old)			\
+	(((old) & ~(((1 << ISI_##name##_SIZE) - 1)	\
+		    << ISI_##name##_OFFSET))\
+	 | ISI_BF(name,value))
+
+/* Register access macros */
+#define isi_readl(port,reg)				\
+	__raw_readl((port)->regs + ISI_##reg)
+#define isi_writel(port,reg,value)			\
+	__raw_writel((value), (port)->regs + ISI_##reg)
+
+#define ATMEL_V4L2_VID_FLAGS ( V4L2_CAP_VIDEO_OUTPUT )
+
+struct atmel_isi;
+
+enum atmel_isi_pixfmt {
+	ATMEL_ISI_PIXFMT_GREY,		/* Greyscale */
+	ATMEL_ISI_PIXFMT_CbYCrY,
+	ATMEL_ISI_PIXFMT_CrYCbY,
+	ATMEL_ISI_PIXFMT_YCbYCr,
+	ATMEL_ISI_PIXFMT_YCrYCb,
+	ATMEL_ISI_PIXFMT_RGB24,
+	ATMEL_ISI_PIXFMT_BGR24,
+	ATMEL_ISI_PIXFMT_RGB16,
+	ATMEL_ISI_PIXFMT_BGR16,
+	ATMEL_ISI_PIXFMT_GRB16,		/* G[2:0] R[4:0]/B[4:0] G[5:3] */
+	ATMEL_ISI_PIXFMT_GBR16,		/* G[2:0] B[4:0]/R[4:0] G[5:3] */
+	ATMEL_ISI_PIXFMT_RGB24_REV,
+	ATMEL_ISI_PIXFMT_BGR24_REV,
+	ATMEL_ISI_PIXFMT_RGB16_REV,
+	ATMEL_ISI_PIXFMT_BGR16_REV,
+	ATMEL_ISI_PIXFMT_GRB16_REV,	/* G[2:0] R[4:0]/B[4:0] G[5:3] */
+	ATMEL_ISI_PIXFMT_GBR16_REV,	/* G[2:0] B[4:0]/R[4:0] G[5:3] */
+};
+
+struct atmel_isi_format {
+	struct v4l2_pix_format pix;
+	enum atmel_isi_pixfmt input_format;
+};
+
+struct atmel_isi_camera {
+	const char		*name;
+	struct module		*owner;
+	struct list_head	list;
+	unsigned int		hsync_act_low:1;
+	unsigned int		vsync_act_low:1;
+	unsigned int		pclk_act_falling:1;
+	unsigned int		has_emb_sync:1;
+	/* ISI supports up to 17 formats */
+	unsigned int		pixelformats[17];
+	int (*get_format)(struct atmel_isi_camera *cam,
+			  struct atmel_isi_format *fmt);
+	int (*set_format)(struct atmel_isi_camera *cam,
+			  struct atmel_isi_format *fmt);
+	int (*start_capture)(struct atmel_isi_camera *cam);
+	int (*stop_capture)(struct atmel_isi_camera *cam);
+	struct atmel_isi	*isi;
+};
+
+extern int atmel_isi_register_camera(struct atmel_isi_camera *cam);
+extern void atmel_isi_unregister_camera(struct atmel_isi_camera *cam);
+
+
+#endif /* __ASM_AVR32_ISI_H__ */
+
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 7558484..a8cdf42 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -13,6 +13,20 @@ menuconfig VIDEO_CAPTURE_DRIVERS
 
 if VIDEO_CAPTURE_DRIVERS && VIDEO_DEV
 
+config VIDEO_AVR32_ISI
+	tristate "AVR32 video support"
+	depends on VIDEO_DEV
+	---help---
+	  This module makes the AVR32 Image Sensor Interface available 
+
+config VIDEO_MT9M112
+	tristate "Micron MT9M112 camera"
+	default n
+	depends on VIDEO_AVR32_ISI && I2C
+	---help---
+	 This will add support for the Micron MT9M112 camera.
+	  as a v4l2 device.
+
 config VIDEO_ADV_DEBUG
 	bool "Enable advanced debug functionality"
 	default n
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 78e38d0..3156969 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -77,7 +77,8 @@ obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
 obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
 obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
 obj-$(CONFIG_TUNER_3036) += tuner-3036.o
 obj-$(CONFIG_VIDEO_AVR32_ISI) += atmel-isi.o
+obj-$(CONFIG_VIDEO_MT9M112) += tm13m3.o
 
 obj-$(CONFIG_VIDEO_TUNER) += tuner.o
 obj-$(CONFIG_VIDEO_BUF)   += video-buf.o
diff --git a/drivers/media/video/tm13m3.c b/drivers/media/video/tm13m3.c
new file mode 100644
index 0000000..42f0fd3
--- /dev/null
+++ b/drivers/media/video/tm13m3.c
@@ -0,0 +1,631 @@
+/*
+ * Micron Mt9M112 camera driver.
+ *
+ * Copyright (C) 2005-2007 Atmel Corporation
+ *
+ * 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.
+ */
+//#define DEBUG
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+
+#include <linux/err.h>
+#include <asm/gpio.h>
+#include <asm/arch/board.h>
+#include <asm/arch/at32ap700x.h>
+
+#include "atmel-isi.h"
+
+/* camera standby pin */
+#define CAM_STANDBY GPIO_PIN_PA(9) 
+/* camera reset pin */
+#define CAM_RESET GPIO_PIN_PA(8)
+
+/*! Maximum number of pixels in a row */
+#define TM13M3_MAX_WIDTH	1280
+/*! Maximum number of rows */
+#define TM13M3_MAX_HEIGHT	1024
+
+/*! Clock for image sensor CLKIN signal */
+static char mclk_name[32] = "gclk0";
+/*! Parent clock of gclk0 
+ *  Either osc0 or pll0
+ *  We use osc0 with 20MHz quarz.
+ */
+static char mclk_parent_name[32] = "osc0";
+
+static struct clk *mclk;
+static struct clk *mclk_parent;
+module_param_string(mclk, mclk_name, sizeof(mclk_name), 0644);
+MODULE_PARM_DESC(mclk, "Name of the clock used as camera clock input");
+
+module_param_string(mclk_parent, mclk_parent_name,
+		    sizeof(mclk_parent_name), 0644);
+MODULE_PARM_DESC(mclk, "Name of mclk parent clock");
+
+
+/* Register adresses */
+#define CHIP_VERSION		0x0
+#define PROGRAM_CONTROL		0x2CC
+#define READ_MODE_CONTEXT_B	0x20
+#define CONTEXT_CONTROL		0xC8
+#define COLUMN_WIDTH		0x4
+#define HORIZONTAL_OUTPUT_SIZE_B	0x1A1
+#define VERTICAL_OUTPUT_SIZE_B	0x1A4
+#define ROW_WIDTH		0x3
+#define PAGE_MAP		0xF0
+#define OUTPUT_FORMAT_CONTROL_A	0x13A
+#define HORIZONTAL_ZOOM	0x1A6
+#define VERTICAL_ZOOM	0x1A9
+#define PLL_CONTROL_1	0x66
+#define PLL_CONTROL_2	0x67
+#define CLOCK_CONTROL	0x65
+
+/* Chip ID stored in CHIP_VERSION register */
+#define MT9M112_CHIP_ID 0x148C
+/* I2C address of camera module */
+#define I2C_TM13M3	0x5D
+
+static unsigned short normal_i2c[] = {
+	I2C_TM13M3,
+	I2C_CLIENT_END
+};
+I2C_CLIENT_INSMOD;
+
+#ifdef CONFIG_DEBUG_FS
+struct reg_dbg {
+	struct tm13m3 *is;
+	struct dentry *dentry;
+	unsigned int offset;
+};
+#endif
+
+struct tm13m3 {
+	struct mutex		mutex;
+	u16			current_page;
+	u32			current_format;
+	u16			pll_avr_ctrl;
+	struct clk		*mclk;
+	struct i2c_client	client;
+	struct atmel_isi_camera	cam;
+#ifdef CONFIG_DEBUG_FS
+	struct dentry		*debugfs_root;
+	struct reg_dbg		debugfs_reg[37];
+#endif
+};
+
+
+#define to_tm13m3(cam) container_of(cam, struct tm13m3, cam)
+
+static struct i2c_driver tm13m3_driver;
+
+static int tm13m3_write_16(struct tm13m3 *is, u16 reg, u16 value)
+{
+	int ret = 0;
+	u16 register_page = 0;
+
+	register_page = reg >> 8;
+
+	if ((register_page  !=  is->current_page)
+		&& (reg != PAGE_MAP)){
+
+		if( 0 <= (ret = i2c_smbus_write_word_data(&is->client, PAGE_MAP, cpu_to_le16(register_page))))
+			is->current_page = register_page;
+	} 
+
+	if(ret >= 0){
+		ret = i2c_smbus_write_word_data(&is->client, (u8) reg, cpu_to_le16(value));
+	}
+	return ret;
+}
+
+static int tm13m3_read_16(struct tm13m3 *is, u16 reg)
+{
+	int ret = 0;
+	u16 register_page = 0;
+
+	register_page = reg >> 8;
+
+	if ((register_page  !=  is->current_page)
+		&& (reg != PAGE_MAP)){
+
+		if( 0 <= (ret = i2c_smbus_write_word_data(&is->client, PAGE_MAP, cpu_to_le16(register_page))))
+			is->current_page = register_page;
+	} 
+
+if(ret >=  0){
+		ret = i2c_smbus_read_word_data(&is->client, (u8) reg);
+	}
+
+	if (ret < 0)
+		return -EIO;
+
+	return le16_to_cpu(ret);
+}
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+
+struct tm13m3_reg {
+	u16 address;
+	const char *name;
+};
+
+static struct tm13m3_reg tm13m3_registers[38] = {
+	{ .address = CHIP_VERSION, .name = "chip_version"},
+	{ .address = 0x1, .name = "row_start"},
+	{ .address = 0x2, .name = "column_start"},
+	{ .address = 0x3, .name = "row_width"},
+	{ .address = 0x4, .name = "column_width"},
+	{ .address = 0x5, .name = "horizontal_blanking_b"},
+	{ .address = 0x6, .name = "vertical_blanking_b"},
+	{ .address = 0x7, .name = "horizontal_blanking_a"},
+	{ .address = 0x8, .name = "vertical_blanking_a"},
+	{ .address = 0x0D, .name = "reset"},
+	{ .address = 0x20, .name = "read_mode_context_b"},
+	{ .address = 0x21, .name = "read_mode_context_a"},
+	{ .address = 0x22, .name = "dark_col_row"},
+	{ .address = 0x65, .name = "clock_control"},
+	{ .address = 0x66, .name = "pll_control_1"},
+	{ .address = 0x67, .name = "pll_control_2"},
+	{ .address = 0xC8, .name = "context_control"},
+	{ .address = 0x106, .name = "mode_control"},
+	{ .address = 0x108, .name = "format_control"},
+	{ .address = 0x13A, .name = "output_format_control_a"},
+	{ .address = 0x148, .name = "test_pattern_generator"},
+	{ .address = 0x19B, .name = "output_format_control_b"},
+	{ .address = 0x1A1, .name = "horizontal_output_size_b"},
+	{ .address = 0x1A4, .name = "vertical_output_size_b"},
+	{ .address = 0x1A5, .name = "horizontal_pan"},
+	{ .address = 0x1A6, .name = "horizontal_zoom"},
+	{ .address = 0x1A7, .name = "horizontal_output_size_a"},
+	{ .address = 0x1A8, .name = "vertical_pan"},
+	{ .address = 0x1A9, .name = "vertical_zoom"},
+	{ .address = 0x1AA, .name = "vertical_output_size_a"},
+	{ .address = 240,  .name = "page_map"},
+	{ .address = 0x2C8, .name = "global_context_control"},
+	{ .address = 0x2CB, .name = "program_advance"},
+	{ .address = 0x2CC, .name = "program_control"},
+	{ .address = 0x2D2, .name = "default_program_conf"},
+	{ .address = 0x2D3, .name = "user_global_context_control"},
+	{ .address = (0x100 | 0), .name = "module_id"},
+	{ .address = (0x200 | 2), .name = "mode_control"},
+};
+
+static u64 reg_dbg_get(void *data)
+{
+	struct reg_dbg *reg = data;
+	int ret = 0;
+
+	mutex_lock(&reg->is->mutex);	
+	ret = tm13m3_read_16(reg->is, tm13m3_registers[reg->offset].address);
+	mutex_unlock(&reg->is->mutex);
+
+	if (ret < 0) {
+		printk("%s: failed to read reg 0x%02x: %d\n",
+		       reg->is->cam.name, 
+		       tm13m3_registers[reg->offset].address, ret);
+		return ~0ULL;
+	}
+	return ret;
+}
+
+static void reg_dbg_set(void *data, u64 val)
+{
+	struct reg_dbg *reg = data;
+	int ret = 0;
+	
+	mutex_lock(&reg->is->mutex);
+	ret = tm13m3_write_16(reg->is, tm13m3_registers[reg->offset].address, (u16) val);
+	mutex_unlock(&reg->is->mutex);
+
+	if (ret < 0){
+		printk("%s: failed to write reg 0x%02x: %d\n",
+			reg->is->cam.name,
+			tm13m3_registers[reg->offset].address, ret);
+	}
+}
+DEFINE_SIMPLE_ATTRIBUTE(reg_dbg_fops, reg_dbg_get, reg_dbg_set, "%04llx\n");
+
+static void tm13m3_init_debugfs(struct tm13m3 *is)
+{
+	struct dentry *root, *reg;
+	unsigned int i;
+
+	root = debugfs_create_dir(is->cam.name, NULL);
+	if (IS_ERR(root) || !root)
+		goto err_root;
+	is->debugfs_root = root;
+
+	for (i = 0; i < ARRAY_SIZE(is->debugfs_reg); i++) {
+		if (!tm13m3_registers[i].name)
+			continue;
+
+		is->debugfs_reg[i].is = is;
+		is->debugfs_reg[i].offset = i;
+
+		reg = debugfs_create_file(tm13m3_registers[i].name, S_IRUGO | S_IWUSR,
+					  root, &is->debugfs_reg[i],
+					  &reg_dbg_fops);
+		if (!reg)
+			goto err_reg;
+		is->debugfs_reg[i].dentry = reg;
+	}
+
+	return;
+
+err_reg:
+	while (i--)
+		debugfs_remove(is->debugfs_reg[i].dentry);
+	debugfs_remove(root);
+err_root:
+	is->debugfs_root = NULL;
+	printk(KERN_ERR "%s: failed to initialize debugfs\n",
+	       is->cam.name);
+}
+
+static void tm13m3_cleanup_debugfs(struct tm13m3 *is)
+{
+	unsigned int i;
+
+	if (is->debugfs_root) {
+		for (i = 0; i < ARRAY_SIZE(is->debugfs_reg); i++)
+			debugfs_remove(is->debugfs_reg[i].dentry);
+		debugfs_remove(is->debugfs_root);
+	}
+}
+#else
+static inline void tm13m3_init_debugfs(struct tm13m3 *is)
+{
+
+}
+
+static inline void tm13m3_cleanup_debugfs(struct tm13m3 *is)
+{
+
+}
+#endif /* CONFIG_DEBUG_FS */
+
+static int tm13m3_get_format(struct atmel_isi_camera *cam,
+			   struct atmel_isi_format *fmt)
+{
+	struct tm13m3 *is = to_tm13m3(cam);
+	int ret = 0;
+
+	fmt->pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
+	fmt->input_format = ATMEL_ISI_PIXFMT_CbYCrY;
+	fmt->input_format = is->current_format;
+
+	fmt->pix.width = 320;
+	fmt->pix.height = 240;
+
+	return ret;
+}
+
+static int tm13m3_set_format(struct atmel_isi_camera *cam,
+			   struct atmel_isi_format *fmt)
+{
+	struct tm13m3 *is = to_tm13m3(cam);
+	int ret = 0;
+
+	fmt->pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
+/*
+	switch(fmt->input_format){
+	case ATMEL_ISI_PIXFMT_CbYCrY:
+		is->current_format = ATMEL_ISI_PIXFMT_CbYCrY;
+		break;	
+	case ATMEL_ISI_PIXFMT_YCbYCr:
+		is->current_format = ATMEL_ISI_PIXFMT_YCbYCr;
+		break;
+	case ATMEL_ISI_PIXFMT_CrYCbY:
+		is->current_format = ATMEL_ISI_PIXFMT_CrYCbY;
+		break;
+	case ATMEL_ISI_PIXFMT_YCrYCb:
+		is->current_format = ATMEL_ISI_PIXFMT_YCrYCb;
+		break;
+	default:
+		// force a valid format
+		fmt->input_format = ATMEL_ISI_PIXFMT_CbYCrY;
+		is->current_format = ATMEL_ISI_PIXFMT_CbYCrY;
+		pr_debug("%s: Not supported format, forcing default format\n",
+			cam->name);
+		break;
+	}
+*/
+	fmt->input_format = ATMEL_ISI_PIXFMT_CrYCbY;
+	is->current_format = ATMEL_ISI_PIXFMT_CrYCbY;
+
+	/* adjust picture width and height */
+	if (fmt->pix.width > TM13M3_MAX_WIDTH)
+		fmt->pix.width = TM13M3_MAX_WIDTH;
+	if (fmt->pix.height > TM13M3_MAX_HEIGHT)
+		fmt->pix.height = TM13M3_MAX_HEIGHT;
+
+	//tm13m3_write_16(is, COLUMN_WIDTH, fmt->pix.width);
+	//tm13m3_write_16(is, ROW_WIDTH, fmt->pix.height);
+	//tm13m3_write_16(is, HORIZONTAL_ZOOM, fmt->pix.width);
+	//tm13m3_write_16(is, VERTICAL_ZOOM, fmt->pix.height);
+
+	//tm13m3_write_16(is, HORIZONTAL_OUTPUT_SIZE_B, fmt->pix.width);
+	//tm13m3_write_16(is, VERTICAL_OUTPUT_SIZE_B, fmt->pix.height);
+
+	/* FIXME Set context output width needed ??*/
+
+	pr_debug("%s: set_format %ux%u\n", cam->name,
+		 fmt->pix.width, fmt->pix.height);
+	return ret;
+}
+
+static void tm13m3_reset_soft(struct tm13m3 *is)
+{
+	tm13m3_write_16(is, 0x0D, 0x0001);
+	/*FIXME test if toggling is really needed */
+	tm13m3_write_16(is, 0x0D, 0x0000);
+}
+
+static void tm13m3_reset_hardware(struct tm13m3 *is)
+{
+	gpio_set_value(CAM_RESET, 0);
+	//FIXME : set correct reset interval usleep();
+	gpio_set_value(CAM_RESET, 1);
+}
+
+static int tm13m3_start_capture(struct atmel_isi_camera *cam)
+{
+	struct tm13m3 *is = to_tm13m3(cam);
+	int ret = 0;
+
+	return ret;
+}
+
+static int tm13m3_stop_capture(struct atmel_isi_camera *cam)
+{
+	struct tm13m3 *is = to_tm13m3(cam);
+	int ret = 0;
+
+
+	return ret;
+}
+
+static int tm13m3_init_hardware(struct tm13m3 *is)
+{
+	int chip_id;
+
+	tm13m3_reset_hardware(is);
+	/* set register page to reset value*/
+	is->current_page = 0;
+	is->current_format = ATMEL_ISI_PIXFMT_CbYCrY;
+
+	pr_debug("tm13m3: Init sensor\n");
+	/* Try to identify the camera */
+	chip_id = tm13m3_read_16(is, CHIP_VERSION);
+	if (chip_id < 0)
+		return -EIO;
+
+	if (chip_id != MT9M112_CHIP_ID) {
+		printk(KERN_ERR "%s: Unknown chip ID 0x%04x\n",
+		       is->cam.name, chip_id);
+		return -ENODEV;
+	}
+#if 0
+	/* Configure pll for 36,8 MHz with CLKIN = 20MHz
+	 * fout = fclkin * M * 1 /( 2* (N+1) * (P+1))
+	 */
+	/* Set P = 2  */
+	tm13m3_write_16(is, PLL_CONTROL_2, 0x0502);
+	/* M = 22, N = 1*/
+	tm13m3_write_16(is, PLL_CONTROL_1, 0x1601);
+	/* wake up pll*/
+	tm13m3_write_16(is, CLOCK_CONTROL, 0x8000);
+	/* wait until pll has stabilized */
+	mdelay(1);
+	/* set pll as master clock*/
+	tm13m3_write_16(is, CLOCK_CONTROL, 0x0000);
+
+#endif
+	/* Set semi-auto mode program mode*/
+	tm13m3_write_16(is, PROGRAM_CONTROL, 0x0010);
+	/* set context B read mode */
+	tm13m3_write_16(is, READ_MODE_CONTEXT_B, 0x0100);
+	/* switch to read+resize context B */
+	tm13m3_write_16(is, CONTEXT_CONTROL, 0x0408);
+	/* set ITU-R BT.656 codes */
+	tm13m3_write_16(is, OUTPUT_FORMAT_CONTROL_A, 0x0A00);
+	/* set sensor image size */ 
+	tm13m3_write_16(is, HORIZONTAL_ZOOM, 320);
+	tm13m3_write_16(is, VERTICAL_ZOOM, 240);
+	tm13m3_write_16(is, HORIZONTAL_OUTPUT_SIZE_B, 320);
+	tm13m3_write_16(is, VERTICAL_OUTPUT_SIZE_B, 240);
+	tm13m3_write_16(is, COLUMN_WIDTH, 320);
+	tm13m3_write_16(is, ROW_WIDTH, 240);
+	return 0;
+}
+static int tm13m3_detect_client(struct i2c_adapter *adapter,
+			      int address, int kind)
+{
+	struct i2c_client *client;
+	struct tm13m3 *is;
+	int ret;
+
+	pr_debug("tm13m3: detecting client on address 0x%x\n", address);
+
+	/* Check if the adapter supports the needed features */
+	if (!i2c_check_functionality(adapter,
+				     (I2C_FUNC_SMBUS_READ_BYTE_DATA
+				      | I2C_FUNC_SMBUS_WRITE_BYTE_DATA
+				      | I2C_FUNC_SMBUS_READ_WORD_DATA
+				      | I2C_FUNC_SMBUS_WRITE_WORD_DATA)))
+		return 0;
+
+	is = kzalloc(sizeof(struct tm13m3), GFP_KERNEL);
+	if (!is)
+		return -ENOMEM;
+
+	client = &is->client;
+	client->addr = address;
+	client->adapter = adapter;
+	client->driver = &tm13m3_driver;
+	strcpy(client->name, "tm13m3");
+
+	is->cam.name = client->name;
+	is->cam.hsync_act_low = 0;
+	is->cam.vsync_act_low = 0;
+	is->cam.pclk_act_falling = 0;
+	/* no SAV/EAV sync -> HSYNC and VSYNC used */
+	/*is->cam.has_emb_sync = 0;*/
+	is->cam.has_emb_sync = 1;
+
+	is->cam.get_format = tm13m3_get_format;
+	is->cam.set_format = tm13m3_set_format;
+	is->cam.start_capture = tm13m3_start_capture;
+	is->cam.stop_capture = tm13m3_stop_capture;
+
+	mutex_init(&is->mutex);
+
+	is->mclk = clk_get(NULL, mclk_name);
+	if (IS_ERR(is->mclk)) {
+		ret = PTR_ERR(is->mclk);
+		goto err_clk;
+	}
+	clk_enable(is->mclk);
+
+	ret = i2c_attach_client(client);
+	if (ret)
+		goto err_attach;
+
+	i2c_set_clientdata(client, is);
+
+	ret = tm13m3_init_hardware(is);
+	if (ret)
+		goto err_init_hw;
+
+	/* We're up and running. Notify the ISI driver */
+	ret = atmel_isi_register_camera(&is->cam);
+	if (ret)
+		goto err_register;
+
+	printk(KERN_INFO "TM13M3 Image Sensor at %s:0x%02x\n",
+	       adapter->name, address);
+
+	tm13m3_init_debugfs(is);
+
+	return 0;
+
+err_register:
+err_init_hw:
+//	at76_reset_hardware(is);
+	i2c_detach_client(client);
+err_attach:
+	clk_disable(is->mclk);
+	clk_put(is->mclk);
+err_clk:
+	kfree(is);
+	return ret;
+}
+
+static int tm13m3_attach_adapter(struct i2c_adapter *adapter)
+{
+	pr_debug("tm13m3: starting probe for adapter %s (%u)\n",
+		 adapter->name, adapter->id);
+	return i2c_probe(adapter, &addr_data, &tm13m3_detect_client);
+}
+
+static int tm13m3_detach_client(struct i2c_client *client)
+{
+	struct tm13m3 *is = i2c_get_clientdata(client);
+	int ret;
+
+	tm13m3_cleanup_debugfs(is);
+	atmel_isi_unregister_camera(&is->cam);
+
+	tm13m3_reset_hardware(is);
+
+	ret = i2c_detach_client(client);
+	if (ret)
+		return ret;
+
+	clk_disable(is->mclk);
+	clk_put(is->mclk);
+	kfree(is);
+
+	return 0;
+}
+
+static struct i2c_driver tm13m3_driver = {
+	.driver = {
+		.name	= "tm13m3",
+	},
+	.id		= I2C_DRIVERID_TM13M3,
+	.attach_adapter	= &tm13m3_attach_adapter,
+	.detach_client	= &tm13m3_detach_client,
+};
+
+static int __init tm13m3_init(void)
+{
+	        /*
+         * Set up the master clock, if available. If clk_get() fails,
+         * this hopefully means that the board generates a suitable
+         * master clock some other way, which is fine by us.
+         *
+         * We need to do this before probing the i2c bus, as the
+         * camera won't ack any messages when it doesn't have a clock.
+         */
+        mclk_parent = clk_get(NULL, mclk_parent_name);
+        if (!IS_ERR(mclk_parent))
+                clk_enable(mclk_parent);
+        else {
+                mclk_parent = NULL;
+		pr_debug("tm13m3: No parent clock available\n");
+	}
+
+        mclk = clk_get(NULL, mclk_name);
+        if (!IS_ERR(mclk)) {
+                if (mclk_parent)
+                        clk_set_parent(mclk, mclk_parent);
+
+                clk_set_rate(mclk, 27000000);
+                clk_enable(mclk);
+        } else {
+                mclk = NULL;
+		pr_debug("tm13m3: No clock set\n");
+        }
+
+	gpio_direction_output(CAM_STANDBY, 0);
+	/* Reset sequence */
+	gpio_direction_output(CAM_RESET, 0);
+	udelay(4);
+	gpio_set_value(CAM_RESET, 1);
+
+	return i2c_add_driver(&tm13m3_driver);
+
+}
+module_init(tm13m3_init);
+
+static void __exit tm13m3_exit(void)
+{
+	if (mclk) {
+		clk_disable(mclk);
+		clk_put(mclk);
+	}
+	if (mclk_parent) {
+		clk_disable(mclk_parent);
+		clk_put(mclk_parent);
+	}
+	i2c_del_driver(&tm13m3_driver);
+}
+module_exit(tm13m3_exit);
+
+MODULE_DESCRIPTION("Atmel Image Sensor Interface Driver");
+MODULE_AUTHOR("Lars Häring <lharing@atmel.com>");
+MODULE_LICENSE("GPL");
>From dc4286f6020df0bf791228cdfe7d4ea58e2f46ef Mon Sep 17 00:00:00 2001
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
Date: Wed, 17 Jan 2007 13:47:40 +0100
Subject: [PATCH] AP7000: Add platform_device for ISI

Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
---
 arch/avr32/mach-at32ap/at32ap700x.c   |   47 +++++++++++++++++++++++++++++++++
 include/asm-avr32/arch-at32ap/board.h |    1 +
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c
index 1130c8a..4184296 100644
--- a/arch/avr32/mach-at32ap/at32ap700x.c
+++ b/arch/avr32/mach-at32ap/at32ap700x.c
@@ -1396,6 +1396,51 @@ at32_add_device_abdac(unsigned int id)
 }
 
 /* --------------------------------------------------------------------
+ *  ISI
+ * -------------------------------------------------------------------- */
+static struct resource atmel_isi0_resource[] = {
+	PBMEM(0xfff02c00),
+	IRQ(30),
+};
+DEFINE_DEV(atmel_isi, 0);
+DEV_CLK(hclk, atmel_isi0, hsb, 5);
+DEV_CLK(pclk, atmel_isi0, pbb, 11);
+
+struct platform_device *__init
+at32_add_device_isi(unsigned int id)
+{
+	struct platform_device *pdev;
+
+	switch (id) {
+	case 0:
+		pdev = &atmel_isi0_device;
+		select_peripheral(PB(0),  PERIPH_A, 0);	/* DATA0  */
+		select_peripheral(PB(1),  PERIPH_A, 0);	/* DATA1  */
+		select_peripheral(PB(2),  PERIPH_A, 0);	/* DATA2  */
+		select_peripheral(PB(3),  PERIPH_A, 0);	/* DATA3  */
+		select_peripheral(PB(4),  PERIPH_A, 0);	/* DATA4  */
+		select_peripheral(PB(5),  PERIPH_A, 0);	/* DATA5  */
+		select_peripheral(PB(6),  PERIPH_A, 0);	/* DATA6  */
+		select_peripheral(PB(7),  PERIPH_A, 0);	/* DATA7  */
+		select_peripheral(PB(11), PERIPH_B, 0);	/* DATA8  */
+		select_peripheral(PB(12), PERIPH_B, 0);	/* DATA9  */
+		select_peripheral(PB(13), PERIPH_B, 0);	/* DATA10 */
+		select_peripheral(PB(14), PERIPH_B, 0);	/* DATA11 */
+		select_peripheral(PB(8),  PERIPH_A, 0);	/* HSYNC  */
+		select_peripheral(PB(9),  PERIPH_A, 0);	/* VSYNC  */
+		select_peripheral(PB(10), PERIPH_A, 0);	/* PCLK	  */
+		break;
+
+	default:
+		return NULL;
+	}
+
+	platform_device_register(pdev);
+
+	return pdev;
+}
+
+/* --------------------------------------------------------------------
  *  GCLK
  * -------------------------------------------------------------------- */
 static struct clk gclk0 = {
@@ -1493,6 +1538,8 @@ struct clk *at32_clock_list[] = {
 	&gclk2,
 	&gclk3,
 	&gclk4,
+	&atmel_isi0_hclk,
+	&atmel_isi0_pclk,
 };
 unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
 
diff --git a/include/asm-avr32/arch-at32ap/board.h b/include/asm-avr32/arch-at32ap/board.h
index 9b36eb8..931f5af 100644
--- a/include/asm-avr32/arch-at32ap/board.h
+++ b/include/asm-avr32/arch-at32ap/board.h
@@ -55,6 +55,7 @@ at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
 
 struct platform_device *at32_add_device_ac97c(unsigned int id);
 struct platform_device *at32_add_device_abdac(unsigned int id);
+struct platform_device *at32_add_device_isi(unsigned int id);
 
 /* depending on what's hooked up, not all SSC pins will be used */
 #define	ATMEL_SSC_TK		0x01
-- 
1.5.2.3

>From 6bac229e6999ce8e761baf97975fc5db774721fa Mon Sep 17 00:00:00 2001
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
Date: Wed, 21 Feb 2007 15:35:44 +0100
Subject: [PATCH] NGW100: Wire up the ISI

Since the NGW100 doesn't actually have a camera on board, this patch
merely serves as an example on how you might wire up the ISI on a
board that does have a camera.
---
 arch/avr32/boards/atngw100/setup.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
index d649974..6ca98bb 100644
--- a/arch/avr32/boards/atngw100/setup.c
+++ b/arch/avr32/boards/atngw100/setup.c
@@ -178,6 +178,11 @@ static int __init atngw100_init(void)
 	at32_add_device_twi(0);
 #endif
 
+	at32_add_device_isi(0);
+
+	/* Master clock for the camera (GCLK0) */
+	at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
+
 	return 0;
 }
 postcore_initcall(atngw100_init);
-- 
1.5.2.3